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