Minsky
SVGItem.cc
Go to the documentation of this file.
1 /*
2  @copyright Steve Keen 2012
3  @author Russell Standish
4  This file is part of Minsky.
5 
6  Minsky is free software: you can redistribute it and/or modify it
7  under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Minsky is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with Minsky. If not, see <http://www.gnu.org/licenses/>.
18 */
19 // Implementations of canvas items representing operations and variables.
20 
21 /*
22  @copyright Steve Keen 2014
23  @author Russell Standish
24  This file is part of Minsky.
25 
26  Minsky is free software: you can redistribute it and/or modify it
27  under the terms of the GNU General Public License as published by
28  the Free Software Foundation, either version 3 of the License, or
29  (at your option) any later version.
30 
31  Minsky is distributed in the hope that it will be useful,
32  but WITHOUT ANY WARRANTY; without even the implied warranty of
33  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34  GNU General Public License for more details.
35 
36  You should have received a copy of the GNU General Public License
37  along with Minsky. If not, see <http://www.gnu.org/licenses/>.
38 */
39 #include "SVGItem.h"
40 #include "SVGItem.rcd"
41 #include "cairo_base.h"
42 #include "minsky_epilogue.h"
43 #include <librsvg-2.0/librsvg/rsvg.h>
44 
45 // if not #ifdef protected, you get a deprecated warning, which is
46 // made fatal by -Werror
47 #ifndef RSVG_CAIRO_H
48 #include <librsvg-2.0/librsvg/rsvg-cairo.h>
49 #endif
50 
51 #include <stdexcept>
52 using namespace std;
53 
54 namespace minsky
55 {
56 
57  void SVGRenderer::setResource(const std::string& resource)
58  {
59  if (svg) /*rsvg_handle_free*/ g_object_unref(svg);
60  GError* err=nullptr;
61  svg=rsvg_handle_new_from_file(resource.c_str(),&err);
62  if (err)
63  {
64  std::string msg="SVGRenderer failed to initialise: ";
65  msg+=err->message;
66  g_error_free(err);
67  throw runtime_error(msg);
68  }
69  RsvgDimensionData dims;
70  rsvg_handle_get_dimensions(svg, &dims);
71  m_width=dims.width;
72  m_height=dims.height;
73  }
74 
75 
76  SVGRenderer::~SVGRenderer()
77  {
78  if (svg)
79  /*rsvg_handle_free*/ g_object_unref(svg);
80  }
81 
82  void SVGRenderer::render(cairo_t* cairo) const
83  {
84  if (svg)
85  rsvg_handle_render_cairo(svg,cairo);
86  }
87 
88 }
STL namespace.
CLASSDESC_ACCESS_EXPLICIT_INSTANTIATION(minsky::SVGRenderer)
Creation and access to the minskyTCL_obj object, which has code to record whenever Minsky&#39;s state cha...
Definition: constMap.h:22