libosmscout  1.1.1
MapPainterAgg.h
Go to the documentation of this file.
1 #ifndef OSMSCOUT_MAP_MAPPAINTERAGG_H
2 #define OSMSCOUT_MAP_MAPPAINTERAGG_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 <mutex>
24 
25 #include <agg2/agg_conv_curve.h>
26 #include <agg2/agg_conv_contour.h>
27 #include <agg2/agg_path_storage.h>
28 #include <agg2/agg_pixfmt_rgb.h>
29 #include <agg2/agg_rasterizer_scanline_aa.h>
30 #include <agg2/agg_renderer_base.h>
31 #include <agg2/agg_rendering_buffer.h>
32 #include <agg2/agg_renderer_scanline.h>
33 #include <agg2/agg_scanline_p.h>
34 
35 // TODO: This one is likely not available under Windows!
36 #include <agg2/agg_font_freetype.h>
37 
39 
40 #include <osmscout/MapPainter.h>
41 
42 namespace osmscout {
43 
45  {
46  public:
47  typedef agg::pixfmt_rgb24 AggPixelFormat;
48 
49  struct NativeGlyph {
50  double x;
51  double y;
52  const agg::glyph_cache* aggGlyph;
53  };
54  struct NativeLabel {
55  std::wstring text;
56  std::vector<NativeGlyph> glyphs;
57  };
62 
63  private:
64  typedef agg::renderer_base<AggPixelFormat> AggRenderBase;
65  typedef agg::rasterizer_scanline_aa<> AggScanlineRasterizer;
66  typedef agg::scanline_p8 AggScanline;
67  typedef agg::renderer_scanline_aa_solid<AggRenderBase> AggScanlineRendererAA;
68  typedef agg::renderer_scanline_bin_solid<AggRenderBase> AggScanlineRendererBin;
69 
70  typedef agg::font_engine_freetype_int32 AggFontEngine;
71  typedef agg::font_cache_manager<AggFontEngine> AggFontManager;
72  typedef agg::conv_curve<AggFontManager::path_adaptor_type> AggTextCurveConverter;
73  typedef agg::conv_contour<AggTextCurveConverter> AggTextContourConverter;
74 
75  AggLabelLayouter labelLayouter;
76 
77  private:
78  AggPixelFormat *pf;
79  AggRenderBase *renderer_base;
80  AggScanlineRasterizer *rasterizer;
81  AggScanline *scanlineP8;
82  AggScanlineRendererAA *renderer_aa;
83  AggScanlineRendererBin *renderer_bin;
84  AggFontEngine *fontEngine;
85  AggFontManager *fontCacheManager;
86  AggTextCurveConverter *convTextCurves;
87  AggTextContourConverter *convTextContours;
88 
89  std::mutex mutex;
90 
91  private:
92  void SetFont(const Projection& projection,
93  const MapParameter& parameter,
94  double size,
95  agg::glyph_rendering ren_type = agg::glyph_ren_native_gray8);
96 
97  void GetTextDimension(const std::wstring& text,
98  double& width,
99  double& height);
100  void DrawText(double x,
101  double y,
102  const std::wstring& text);
103 
104  void DrawGlyph(double x, double y,
105  const agg::glyph_cache* glyph);
106 
107  void DrawGlyphVector(double x, double baselineY,
108  const std::vector<MapPainterAgg::NativeGlyph> &glyphs);
109 
110  void DrawFill(const Projection& projection,
111  const MapParameter& parameter,
112  const FillStyleRef& fillStyle,
113  const BorderStyleRef& borderStyle,
114  agg::path_storage& path);
115 
116  protected:
117  bool HasIcon(const StyleConfig& styleConfig,
118  const Projection& projection,
119  const MapParameter& parameter,
120  IconStyle& style) override;
121 
122  double GetFontHeight(const Projection& projection,
123  const MapParameter& parameter,
124  double fontSize) override;
125 
126  void DrawGround(const Projection& projection,
127  const MapParameter& parameter,
128  const FillStyle& style) override;
129 
130  void DrawIcon(const IconStyle* style,
131  double centerX, double centerY,
132  double width, double height) override;
133 
134  void DrawSymbol(const Projection& projection,
135  const MapParameter& parameter,
136  const Symbol& symbol,
137  double x, double y) override;
138 
139  void DrawPath(const Projection& projection,
140  const MapParameter& parameter,
141  const Color& color,
142  double width,
143  const std::vector<double>& dash,
144  LineStyle::CapStyle startCap,
145  LineStyle::CapStyle endCap,
146  size_t transStart, size_t transEnd) override;
147 
148  void DrawLabel(const Projection& projection,
149  const MapParameter& parameter,
150  const DoubleRectangle& labelRectangle,
151  const LabelData& label,
152  const NativeLabel& layout);
153 
154  void DrawGlyphs(const Projection &projection,
155  const MapParameter &parameter,
156  const osmscout::PathTextStyleRef style,
157  const std::vector<AggGlyph> &glyphs);
158 
159  osmscout::DoubleRectangle GlyphBoundingBox(const NativeGlyph &glyph) const;
160 
161  std::shared_ptr<AggLabel> Layout(const Projection& projection,
162  const MapParameter& parameter,
163  const std::string& text,
164  double fontSize,
165  double objectWidth,
166  bool enableWrapping = false,
167  bool contourLabel = false);
168 
173  virtual void RegisterRegularLabel(const Projection &projection,
174  const MapParameter &parameter,
175  const std::vector<LabelData> &labels,
176  const Vertex2D &position,
177  double objectWidth) override;
178 
182  virtual void RegisterContourLabel(const Projection &projection,
183  const MapParameter &parameter,
184  const PathLabelData &label,
185  const LabelPath &labelPath) override;
186 
187  virtual void DrawLabels(const Projection& projection,
188  const MapParameter& parameter,
189  const MapData& data) override;
190 
191  virtual void BeforeDrawing(const StyleConfig& styleConfig,
192  const Projection& projection,
193  const MapParameter& parameter,
194  const MapData& data) override;
195 
196  void DrawContourSymbol(const Projection& projection,
197  const MapParameter& parameter,
198  const Symbol& symbol,
199  double space,
200  size_t transStart, size_t transEnd) override;
201 
202  void DrawArea(const Projection& projection,
203  const MapParameter& parameter,
204  const AreaData& area) override;
205 
206  public:
207  explicit MapPainterAgg(const StyleConfigRef& styleConfig);
208  ~MapPainterAgg() override;
209 
210  bool DrawMap(const Projection& projection,
211  const MapParameter& parameter,
212  const MapData& data,
213  AggPixelFormat* pf);
214  };
215 }
216 
217 #endif
Definition: LabelLayouter.h:144
std::shared_ptr< FillStyle > FillStyleRef
Definition: Styles.h:349
double x
Definition: MapPainterAgg.h:50
Definition: Styles.h:884
Index selectors by type and level.
Definition: StyleConfig.h:553
Definition: LabelLayouter.h:87
std::shared_ptr< BorderStyle > BorderStyleRef
Definition: Styles.h:458
std::wstring text
Definition: MapPainterAgg.h:55
const agg::glyph_cache * aggGlyph
Definition: MapPainterAgg.h:52
Definition: Projection.h:43
Definition: MapPainter.h:75
std::shared_ptr< PathTextStyle > PathTextStyleRef
Definition: Styles.h:877
Definition: Area.h:38
std::vector< NativeGlyph > glyphs
Definition: MapPainterAgg.h:56
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: MapPainterAgg.h:49
Definition: LabelLayouter.h:129
Definition: Styles.h:280
agg::pixfmt_rgb24 AggPixelFormat
Definition: MapPainterAgg.h:47
friend AggLabelLayouter
Definition: MapPainterAgg.h:61
double y
Definition: MapPainterAgg.h:51
Definition: MapPainterAgg.h:54
Definition: MapPainter.h:179
Definition: MapPainterAgg.h:44
#define OSMSCOUT_MAP_AGG_API
Definition: MapAggImportExport.h:45
CapStyle
Definition: Styles.h:69