libosmscout  1.1.1
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 <osmscout/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 
41 #include <osmscout/MapPainter.h>
42 
43 
44 namespace 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:
110  bool HasIcon(const StyleConfig& styleConfig,
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 
134  osmscout::DoubleRectangle GlyphBoundingBox(const CairoNativeGlyph &glyph) const;
135 
136  void DrawLabel(const Projection& projection,
137  const MapParameter& parameter,
138  const DoubleRectangle& 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 
147  void BeforeDrawing(const StyleConfig& styleConfig,
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 std::vector<LabelData>& labels,
159  const Vertex2D& position,
160  double objectWidth) override;
161 
165  void RegisterContourLabel(const Projection& projection,
166  const MapParameter& parameter,
167  const PathLabelData& label,
168  const LabelPath& labelPath) override;
169 
170  void DrawLabels(const Projection& projection,
171  const MapParameter& parameter,
172  const MapData& data) override;
173 
174  void DrawPrimitivePath(const Projection& projection,
175  const MapParameter& parameter,
176  const DrawPrimitiveRef& primitive,
177  double x, double y,
178  double minX,
179  double minY,
180  double maxX,
181  double maxY);
182 
183  void DrawSymbol(const Projection& projection,
184  const MapParameter& parameter,
185  const Symbol& symbol,
186  double x, double y) override;
187 
188  void DrawIcon(const IconStyle* style,
189  double centerX, double centerY,
190  double width, double height) override;
191 
192  void DrawPath(const Projection& projection,
193  const MapParameter& parameter,
194  const Color& color,
195  double width,
196  const std::vector<double>& dash,
197  LineStyle::CapStyle startCap,
198  LineStyle::CapStyle endCap,
199  size_t transStart, size_t transEnd) override;
200 
201  void DrawContourSymbol(const Projection& projection,
202  const MapParameter& parameter,
203  const Symbol& symbol,
204  double space,
205  size_t transStart, size_t transEnd) override;
206 
207  void DrawArea(const Projection& projection,
208  const MapParameter& parameter,
209  const AreaData& area) override;
210 
211  public:
212  explicit MapPainterCairo(const StyleConfigRef& styleConfig);
213  ~MapPainterCairo() override;
214 
215 
216  bool DrawMap(const Projection& projection,
217  const MapParameter& parameter,
218  const MapData& data,
219  cairo_t *draw);
220  };
221 }
222 
223 #endif
Definition: LabelLayouter.h:144
Definition: MapPainterCairo.h:67
std::wstring wstr
Definition: MapPainterCairo.h:61
double width
Definition: MapPainterCairo.h:69
std::shared_ptr< FillStyle > FillStyleRef
Definition: Styles.h:349
Definition: Styles.h:884
Index selectors by type and level.
Definition: StyleConfig.h:553
double height
Definition: MapPainterCairo.h:70
Definition: LabelLayouter.h:87
Definition: LabelLayouter.h:172
std::shared_ptr< BorderStyle > BorderStyleRef
Definition: Styles.h:458
#define OSMSCOUT_MAP_CAIRO_API
Definition: MapCairoImportExport.h:45
cairo_scaled_font_t * CairoFont
Definition: MapPainterCairo.h:59
Definition: Projection.h:43
Definition: MapPainter.h:75
std::shared_ptr< PathTextStyle > PathTextStyleRef
Definition: Styles.h:877
Definition: Area.h:38
cairo_text_extents_t textExtents
Definition: MapPainterCairo.h:63
CairoFont font
Definition: MapPainterCairo.h:62
Definition: Styles.h:1135
friend CairoLabelLayouter
Definition: MapPainterCairo.h:79
cairo_font_extents_t fontExtents
Definition: MapPainterCairo.h:64
Definition: LabelPath.h:42
Definition: LabelLayouter.h:98
Definition: MapPainterCairo.h:60
std::shared_ptr< StyleConfig > StyleConfigRef
Definition: StyleConfig.h:849
Definition: MapPainter.h:87
Definition: MapPainterCairo.h:46
Definition: LabelLayouter.h:129
Definition: Styles.h:280
std::shared_ptr< DrawPrimitive > DrawPrimitiveRef
Definition: Styles.h:1021
Definition: MapPainter.h:179
std::string character
Definition: MapPainterCairo.h:68
CapStyle
Definition: Styles.h:69