Swiftray  1.0
base-context.h
Go to the documentation of this file.
1 
6 
7 #pragma once
8 namespace Parser {
9 
11 public:
12  BaseContext(SVGPPDoc &svgpp_doc, double resolutionDPI) : doc_(svgpp_doc) {
13  qInfo() << "<base>";
14  id_ = "";
15  class_name_ = "";
16  length_factory_.set_absolute_units_coefficient(resolutionDPI,
17  tag::length_units::in());
18  }
19 
20  using ObjectContext::set;
22 
23 
24  template<class Range>
25  void set_text(Range const &text) {
26  std::string str;
27  str.append(boost::begin(text), boost::end(text));
28  if (svgpp_active_layer_ != nullptr) {
29  qInfo() << "[SVGPP] Set Active Layer's Name to " << QString::fromStdString(str);
30  svgpp_active_layer_->setName(QString::fromStdString(str));
31  }
32  }
33 
34  void set(tag::attribute::id, RangedChar id) {
35  std::string str;
36  str.append(boost::begin(id), boost::end(id));
37  id_ = QString::fromStdString(str);
38  }
39 
40  void set(tag::attribute::class_, RangedChar class_) {
41  std::string str;
42  str.append(boost::begin(class_), boost::end(class_));
43  class_name_ = QString::fromStdString(str);
44  }
45 
46  // Called by Context Factory
47  void on_exit_element() {
48  qInfo() << "</base>";
49  }
50 
51  // Viewport Events Policy
52  void set_viewport(double viewport_x, double viewport_y, double viewport_width,
53  double viewport_height) {
54  length_factory_.set_viewport_size(viewport_width, viewport_height);
55  }
56 
57  void set_viewbox_size(double viewbox_width, double viewbox_height) {
58  length_factory_.set_viewport_size(viewbox_width, viewbox_height);
59  }
60 
62 
63  static bool unknown_attribute_error(std::string name) {
64  qInfo() << "[SVGPP] Unknown attribute" << QString::fromStdString(name);
65  return true;
66  }
67 
68  // Length Policy interface
69  typedef factory::length::unitless<> length_factory_type;
70 
71  length_factory_type const &length_factory() const { return length_factory_; }
72 
73  SVGPPDoc &svgppDoc() const { return doc_; }
74 
75  virtual string type() {
76  return "svg";
77  }
78 
79  QString id_;
80  QString class_name_;
81 
82 private:
83  length_factory_type length_factory_;
84  SVGPPDoc &doc_;
85 
86 };
87 
88 }
Definition: base-context.h:10
BaseContext(SVGPPDoc &svgpp_doc, double resolutionDPI)
Definition: base-context.h:12
void set(tag::attribute::class_, RangedChar class_)
Definition: base-context.h:40
QString id_
Definition: base-context.h:79
factory::length::unitless length_factory_type
Definition: base-context.h:69
void set_viewport(double viewport_x, double viewport_y, double viewport_width, double viewport_height)
Definition: base-context.h:52
void on_exit_element()
Definition: base-context.h:47
void set(tag::attribute::id, RangedChar id)
Definition: base-context.h:34
virtual string type()
Definition: base-context.h:75
QString class_name_
Definition: base-context.h:80
void set_viewbox_size(double viewbox_width, double viewbox_height)
Definition: base-context.h:57
void disable_rendering()
Definition: base-context.h:61
length_factory_type const & length_factory() const
Definition: base-context.h:71
void set_text(Range const &text)
Definition: base-context.h:25
SVGPPDoc & svgppDoc() const
Definition: base-context.h:73
static bool unknown_attribute_error(std::string name)
Definition: base-context.h:63
Definition: object-context.h:7
void set(tag::attribute::width, double val)
Definition: object-context.h:9
Definition: svgpp-doc.h:10
Definition: stylable-context.h:135
void set(svgpp::tag::attribute::display, svgpp::tag::value::none)
Definition: stylable-context.h:150
Definition: transformable-context.h:17
Definition: base-context.h:8
LayerPtr svgpp_active_layer_
Definition: svgpp-impl.cpp:219
boost::iterator_range< const char * > RangedChar
Definition: svgpp-defs.h:13