libosmscout 1.1.1
Loading...
Searching...
No Matches
MapPainterCairo.h
Go to the documentation of this file.
1#ifndef OSMSCOUT_MAP_MAPPAINTERCAIRO_H
2#define OSMSCOUT_MAP_MAPPAINTERCAIRO_H
3
4/*
5 This source is part of the libosmscout-map library
6 Copyright (C) 2009 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 <osmscoutmapcairo/MapCairoFeatures.h>
24
25#include <mutex>
26#include <unordered_map>
27
28#if defined(__WIN32__) || defined(WIN32)
29 #include <cairo.h>
30#else
31 #include <cairo/cairo.h>
32#endif
33
34#if defined(OSMSCOUT_MAP_CAIRO_HAVE_LIB_PANGO)
35 #include <pango/pangocairo.h>
36 #include <pango/pango-glyph.h>
37#endif
38
40
42
43
44namespace osmscout {
45
47 {
48 public:
49#if defined(OSMSCOUT_MAP_CAIRO_HAVE_LIB_PANGO)
50 using CairoFont = PangoFontDescription*;
51 using CairoNativeLabel = std::shared_ptr<PangoLayout>;
52 struct PangoStandaloneGlyph {
53 std::shared_ptr<PangoFont> font;
54 std::shared_ptr<PangoGlyphString> glyphString;
55 };
56
57 using CairoNativeGlyph = PangoStandaloneGlyph;
58#else
59 using CairoFont = cairo_scaled_font_t*;
61 std::wstring wstr;
63 cairo_text_extents_t textExtents;
64 cairo_font_extents_t fontExtents;
65 };
66
68 std::string character;
69 double width;
70 double height;
71 };
72 //static constexpr double AverageCharacterWidth = 0.75;
73#endif
74
80
81 private:
82 CairoLabelLayouter labelLayouter;
83
84 using FontMap = std::unordered_map<size_t,CairoFont>;
85
86 cairo_t *draw;
87 std::vector<cairo_surface_t*> images;
88 std::vector<cairo_surface_t*> patternImages;
89 std::vector<cairo_pattern_t*> patterns;
90 FontMap fonts;
91 double minimumLineWidth;
92
93 std::mutex mutex;
94
95 private:
96 CairoFont GetFont(const Projection& projection,
97 const MapParameter& parameter,
98 double fontSize);
99
100 void SetLineAttributes(const Color& color,
101 double width,
102 const std::vector<double>& dash);
103
104 void DrawFillStyle(const Projection& projection,
105 const MapParameter& parameter,
106 const FillStyleRef& fill,
107 const BorderStyleRef& border);
108
109 protected:
111 const Projection& projection,
112 const MapParameter& parameter,
113 IconStyle& style) override;
114
115 bool HasPattern(const MapParameter& parameter,
116 const FillStyle& style);
117
118 double GetFontHeight(const Projection& projection,
119 const MapParameter& parameter,
120 double fontSize) override;
121
122 void DrawGround(const Projection& projection,
123 const MapParameter& parameter,
124 const FillStyle& style) override;
125
126 std::shared_ptr<CairoLabel> Layout(const Projection& projection,
127 const MapParameter& parameter,
128 const std::string& text,
129 double fontSize,
130 double objectWidth,
131 bool enableWrapping = false,
132 bool contourLabel = false);
133
135
136 void DrawLabel(const Projection& projection,
137 const MapParameter& parameter,
138 const ScreenVectorRectangle& labelRectangle,
139 const LabelData& label,
140 const CairoNativeLabel& layout);
141
142 void DrawGlyphs(const Projection &projection,
143 const MapParameter &parameter,
144 const osmscout::PathTextStyleRef& style,
145 const std::vector<CairoGlyph> &glyphs);
146
148 const Projection& projection,
149 const MapParameter& parameter,
150 const MapData& data) override;
151
156 void RegisterRegularLabel(const Projection& projection,
157 const MapParameter& parameter,
158 const ObjectFileRef& ref,
159 const std::vector<LabelData>& labels,
160 const Vertex2D& position,
161 double objectWidth) override;
162
166 void RegisterContourLabel(const Projection& projection,
167 const MapParameter& parameter,
168 const ObjectFileRef& ref,
169 const PathLabelData& label,
170 const LabelPath& labelPath) override;
171
172 void DrawLabels(const Projection& projection,
173 const MapParameter& parameter,
174 const MapData& data) override;
175
176 void DrawSymbol(const Projection& projection,
177 const MapParameter& parameter,
178 const Symbol& symbol,
179 const Vertex2D& screenPos,
180 double scaleFactor) override;
181
182 void DrawIcon(const IconStyle* style,
183 const Vertex2D& centerPos,
184 double width, double height) override;
185
186 void DrawPath(const Projection& projection,
187 const MapParameter& parameter,
188 const Color& color,
189 double width,
190 const std::vector<double>& dash,
191 LineStyle::CapStyle startCap,
192 LineStyle::CapStyle endCap,
193 const CoordBufferRange& coordRange) override;
194
195 void DrawContourSymbol(const Projection& projection,
196 const MapParameter& parameter,
197 const Symbol& symbol,
198 const ContourSymbolData& data) override;
199
200 void DrawArea(const Projection& projection,
201 const MapParameter& parameter,
202 const AreaData& area) override;
203
204 public:
207
208
209 bool DrawMap(const Projection& projection,
210 const MapParameter& parameter,
211 const MapData& data,
212 cairo_t *draw,
215 };
216}
217
218#endif
#define OSMSCOUT_MAP_CAIRO_API
Definition MapCairoImportExport.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
void DrawSymbol(const Projection &projection, const MapParameter &parameter, const Symbol &symbol, const Vertex2D &screenPos, double scaleFactor) override
cairo_scaled_font_t * CairoFont
Definition MapPainterCairo.h:59
osmscout::ScreenVectorRectangle GlyphBoundingBox(const CairoNativeGlyph &glyph) const
void RegisterRegularLabel(const Projection &projection, const MapParameter &parameter, const ObjectFileRef &ref, const std::vector< LabelData > &labels, const Vertex2D &position, double objectWidth) override
void DrawGlyphs(const Projection &projection, const MapParameter &parameter, const osmscout::PathTextStyleRef &style, const std::vector< CairoGlyph > &glyphs)
MapPainterCairo(const StyleConfigRef &styleConfig)
bool HasIcon(const StyleConfig &styleConfig, const Projection &projection, const MapParameter &parameter, IconStyle &style) override
Label< CairoNativeGlyph, CairoNativeLabel > CairoLabel
Definition MapPainterCairo.h:75
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 DrawArea(const Projection &projection, const MapParameter &parameter, const AreaData &area) override
void DrawLabel(const Projection &projection, const MapParameter &parameter, const ScreenVectorRectangle &labelRectangle, const LabelData &label, const CairoNativeLabel &layout)
void RegisterContourLabel(const Projection &projection, const MapParameter &parameter, const ObjectFileRef &ref, const PathLabelData &label, const LabelPath &labelPath) override
double GetFontHeight(const Projection &projection, const MapParameter &parameter, double fontSize) override
void DrawGround(const Projection &projection, const MapParameter &parameter, const FillStyle &style) 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
std::shared_ptr< CairoLabel > Layout(const Projection &projection, const MapParameter &parameter, const std::string &text, double fontSize, double objectWidth, bool enableWrapping=false, bool contourLabel=false)
Glyph< CairoNativeGlyph > CairoGlyph
Definition MapPainterCairo.h:76
void DrawIcon(const IconStyle *style, const Vertex2D &centerPos, double width, double height) override
bool DrawMap(const Projection &projection, const MapParameter &parameter, const MapData &data, cairo_t *draw, RenderSteps startStep=RenderSteps::FirstStep, RenderSteps endStep=RenderSteps::LastStep)
void DrawLabels(const Projection &projection, const MapParameter &parameter, const MapData &data) override
LabelInstance< CairoNativeGlyph, CairoNativeLabel > CairoLabelInstance
Definition MapPainterCairo.h:77
LabelLayouter< CairoNativeGlyph, CairoNativeLabel, MapPainterCairo > CairoLabelLayouter
Definition MapPainterCairo.h:78
bool HasPattern(const MapParameter &parameter, const FillStyle &style)
MapPainter(const StyleConfigRef &styleConfig)
StyleConfigRef styleConfig
Reference to the style configuration to be used.
Definition MapPainter.h:250
Definition LabelLayouter.h:46
Definition Projection.h:46
Index selectors by type and level.
Definition StyleConfig.h:552
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
RenderSteps
Definition MapPainter.h:64
@ LastStep
Definition MapPainter.h:92
@ FirstStep
Definition MapPainter.h:65
std::shared_ptr< FillStyle > FillStyleRef
Definition Styles.h:356
Definition MapPainter.h:174
Definition MapPainter.h:200
Definition MapPainterCairo.h:67
double height
Definition MapPainterCairo.h:70
std::string character
Definition MapPainterCairo.h:68
double width
Definition MapPainterCairo.h:69
Definition MapPainterCairo.h:60
cairo_text_extents_t textExtents
Definition MapPainterCairo.h:63
cairo_font_extents_t fontExtents
Definition MapPainterCairo.h:64
std::wstring wstr
Definition MapPainterCairo.h:61
CairoFont font
Definition MapPainterCairo.h:62
Definition LabelLayouterHelper.h:73