libosmscout  1.1.1
MapPainterSVG.h
Go to the documentation of this file.
1 #ifndef OSMSCOUT_MAP_MAPPAINTERSVG_H
2 #define OSMSCOUT_MAP_MAPPAINTERSVG_H
3 
4 /*
5  This source is part of the libosmscout-map library
6  Copyright (C) 2011 Tim Teulings
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Lesser General Public
10  License as published by the Free Software Foundation; either
11  version 2.1 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public
19  License along with this library; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22 
23 #include <map>
24 #include <mutex>
25 #include <optional>
26 #include <ostream>
27 #include <set>
28 #include <unordered_map>
29 
30 #include <osmscout/MapSVGFeatures.h>
31 
32 #if defined(OSMSCOUT_MAP_SVG_HAVE_LIB_PANGO)
33  #include <pango/pangoft2.h>
34 #endif
35 
37 
38 #include <osmscout/MapPainter.h>
39 
40 namespace osmscout {
41 
43  {
44 #if defined(OSMSCOUT_MAP_SVG_HAVE_LIB_PANGO)
45  public:
46  using NativeLabel = std::shared_ptr<PangoLayout>;
47  struct StandaloneGlyph {
48  std::shared_ptr<PangoFont> font;
49  std::shared_ptr<PangoGlyphString> glyphString;
50  std::string character;
51  };
52 
53  using NativeGlyph = StandaloneGlyph;
54 
55  private:
56  using FontMap = std::unordered_map<size_t,PangoFontDescription*> ;
57  PangoFontMap *pangoFontMap;
58  PangoContext *pangoContext;
59  FontMap fonts;
60 
61 #else
62  public:
63  using NativeLabel = std::wstring;
64  struct NativeGlyph {
65  std::string character;
66  double width;
67  double height;
68  };
69  static constexpr double AverageCharacterWidth = 0.75;
70 #endif
71 
72  public:
74 
75  private:
79  friend SvgLabelLayouter;
80 
81  SvgLabelLayouter labelLayouter;
82 
83  std::map<FillStyle,std::string> fillStyleNameMap;
84  std::map<BorderStyle,std::string> borderStyleNameMap;
85  std::map<LineStyle,std::string> lineStyleNameMap;
86 
87  std::ostream stream;
88  TypeConfigRef typeConfig;
89  std::mutex mutex;
90 
91  std::vector<std::string> images;
92 
93  private:
94  std::string GetColorValue(const Color& color);
95 
96  osmscout::DoubleRectangle GlyphBoundingBox(const NativeGlyph &glyph) const;
97 
98  std::shared_ptr<SvgLabel> Layout(const Projection& projection,
99  const MapParameter& parameter,
100  const std::string& text,
101  double fontSize,
102  double objectWidth,
103  bool enableWrapping = false,
104  bool contourLabel = false);
105 
106  void DrawLabel(const Projection& projection,
107  const MapParameter& parameter,
108  const DoubleRectangle& labelRectangle,
109  const LabelData& label,
110  const NativeLabel& layout);
111 
112  void DrawGlyphs(const Projection &projection,
113  const MapParameter &parameter,
114  const osmscout::PathTextStyleRef style,
115  const std::vector<SvgGlyph> &glyphs);
116 
117 #if defined(OSMSCOUT_MAP_SVG_HAVE_LIB_PANGO)
118  PangoFontDescription* GetFont(const Projection& projection,
119  const MapParameter& parameter,
120  double fontSize);
121 
122 #endif
123 
124  void SetupFillAndStroke(const FillStyleRef &fillStyle,
125  const BorderStyleRef &borderStyle);
126 
127  void WriteHeader(size_t width,size_t height);
128  void DumpStyles(const StyleConfig& styleConfig,
129  const MapParameter& parameter,
130  const Projection& projection);
131  void WriteFooter();
132 
133  void StartMainGroup();
134  void FinishMainGroup();
135 
136  std::string StrEscape(const std::string &str) const;
137 
138  void IconData(const Projection& projection,
139  const MapParameter& parameter);
140 
141  protected:
142  void AfterPreprocessing(const StyleConfig& styleConfig,
143  const Projection& projection,
144  const MapParameter& parameter,
145  const MapData& data) override;
146 
147  void BeforeDrawing(const StyleConfig& styleConfig,
148  const Projection& projection,
149  const MapParameter& parameter,
150  const MapData& data) override;
151 
152  void AfterDrawing(const StyleConfig& styleConfig,
153  const Projection& projection,
154  const MapParameter& parameter,
155  const MapData& data) override;
156 
157  bool HasIcon(const StyleConfig& styleConfig,
158  const Projection& projection,
159  const MapParameter& parameter,
160  IconStyle& style) override;
161 
162  double GetFontHeight(const Projection& projection,
163  const MapParameter& parameter,
164  double fontSize) override;
165 
166  void DrawGround(const Projection& projection,
167  const MapParameter& parameter,
168  const FillStyle& style) override;
169 
174  virtual void RegisterRegularLabel(const Projection &projection,
175  const MapParameter &parameter,
176  const std::vector<LabelData> &labels,
177  const Vertex2D &position,
178  double objectWidth) override;
179 
183  virtual void RegisterContourLabel(const Projection &projection,
184  const MapParameter &parameter,
185  const PathLabelData &label,
186  const LabelPath &labelPath) override;
187 
188  virtual void DrawLabels(const Projection& projection,
189  const MapParameter& parameter,
190  const MapData& data) override;
191 
192  void DrawSymbol(const Projection& projection,
193  const MapParameter& parameter,
194  const Symbol& style,
195  double x, double y) override;
196 
197  void DrawIcon(const IconStyle* style,
198  double centerX, double centerY,
199  double width, double height) override;
200 
201  void DrawPath(const Projection& projection,
202  const MapParameter& parameter,
203  const Color& color,
204  double width,
205  const std::vector<double>& dash,
206  LineStyle::CapStyle startCap,
207  LineStyle::CapStyle endCap,
208  size_t transStart, size_t transEnd) override;
209 
210  void DrawPath(const Projection& projection,
211  const MapParameter& parameter,
212  const std::string& styleName,
213  const std::optional<Color> &colorOverride,
214  double width,
215  LineStyle::CapStyle startCap,
216  LineStyle::CapStyle endCap,
217  size_t transStart, size_t transEnd);
218 
219  void DrawWayOutline(const StyleConfig& styleConfig,
220  const Projection& projection,
221  const MapParameter& parameter,
222  const WayData& data);
223 
224  void DrawWay(const StyleConfig& styleConfig,
225  const Projection& projection,
226  const MapParameter& parameter,
227  const WayData& data) override;
228 
229  void DrawContourSymbol(const Projection& projection,
230  const MapParameter& parameter,
231  const Symbol& symbol,
232  double space,
233  size_t transStart, size_t transEnd) override;
234 
235  void DrawArea(const Projection& projection,
236  const MapParameter& parameter,
237  const AreaData& area) override;
238 
239  public:
240  explicit MapPainterSVG(const StyleConfigRef& styleConfig);
241  ~MapPainterSVG() override;
242 
243 
244  bool DrawMap(const Projection& projection,
245  const MapParameter& parameter,
246  const MapData& data,
247  std::ostream& stream);
248  };
249 }
250 
251 #endif
Definition: LabelLayouter.h:144
std::shared_ptr< FillStyle > FillStyleRef
Definition: Styles.h:349
Definition: Styles.h:884
Index selectors by type and level.
Definition: StyleConfig.h:553
Definition: LabelLayouter.h:87
std::string character
Definition: MapPainterSVG.h:65
Definition: LabelLayouter.h:172
std::shared_ptr< BorderStyle > BorderStyleRef
Definition: Styles.h:458
double height
Definition: MapPainterSVG.h:67
Definition: Projection.h:43
Definition: MapPainter.h:75
std::shared_ptr< PathTextStyle > PathTextStyleRef
Definition: Styles.h:877
Definition: Area.h:38
Definition: Styles.h:1135
Definition: LabelPath.h:42
Definition: LabelLayouter.h:98
std::shared_ptr< StyleConfig > StyleConfigRef
Definition: StyleConfig.h:849
Definition: MapPainter.h:87
Definition: LabelLayouter.h:129
Definition: MapPainter.h:114
#define OSMSCOUT_MAP_SVG_API
Definition: MapSVGImportExport.h:45
Definition: Styles.h:280
Definition: MapPainterSVG.h:64
std::wstring NativeLabel
Definition: MapPainterSVG.h:63
std::shared_ptr< TypeConfig > TypeConfigRef
Definition: TypeConfig.h:1227
Definition: MapPainter.h:179
double width
Definition: MapPainterSVG.h:66
CapStyle
Definition: Styles.h:69
Definition: MapPainterSVG.h:42