libosmscout 1.1.1
Loading...
Searching...
No Matches
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
41
42namespace 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:
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:
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 const Vertex2D& centerPos,
132 double width, double height) override;
133
134 void DrawSymbol(const Projection& projection,
135 const MapParameter& parameter,
136 const Symbol& symbol,
137 const Vertex2D& screenPos,
138 double scaleFactor) override;
139
140 void DrawPath(const Projection& projection,
141 const MapParameter& parameter,
142 const Color& color,
143 double width,
144 const std::vector<double>& dash,
145 LineStyle::CapStyle startCap,
146 LineStyle::CapStyle endCap,
147 const CoordBufferRange& coordRange) override;
148
149 void DrawLabel(const Projection& projection,
150 const MapParameter& parameter,
151 const ScreenVectorRectangle& labelRectangle,
152 const LabelData& label,
153 const NativeLabel& layout);
154
155 void DrawGlyphs(const Projection &projection,
156 const MapParameter &parameter,
157 const osmscout::PathTextStyleRef style,
158 const std::vector<AggGlyph> &glyphs);
159
161
162 std::shared_ptr<AggLabel> Layout(const Projection& projection,
163 const MapParameter& parameter,
164 const std::string& text,
165 double fontSize,
166 double objectWidth,
167 bool enableWrapping = false,
168 bool contourLabel = false);
169
174 virtual void RegisterRegularLabel(const Projection &projection,
175 const MapParameter &parameter,
176 const ObjectFileRef& ref,
177 const std::vector<LabelData> &labels,
178 const Vertex2D &position,
179 double objectWidth) override;
180
184 virtual void RegisterContourLabel(const Projection &projection,
185 const MapParameter &parameter,
186 const ObjectFileRef& ref,
187 const PathLabelData &label,
188 const LabelPath &labelPath) override;
189
190 virtual void DrawLabels(const Projection& projection,
191 const MapParameter& parameter,
192 const MapData& data) override;
193
195 const Projection& projection,
196 const MapParameter& parameter,
197 const MapData& data) override;
198
199 void DrawContourSymbol(const Projection& projection,
200 const MapParameter& parameter,
201 const Symbol& symbol,
202 const ContourSymbolData& data) override;
203
204 void DrawArea(const Projection& projection,
205 const MapParameter& parameter,
206 const AreaData& area) override;
207
208 public:
210 ~MapPainterAgg() override;
211
212 bool DrawMap(const Projection& projection,
213 const MapParameter& parameter,
214 const MapData& data,
215 AggPixelFormat* pf,
218 };
219}
220
221#endif
#define OSMSCOUT_MAP_AGG_API
Definition MapAggImportExport.h:45
Definition LabelLayouter.h:103
Definition LabelLayouter.h:57
Definition LabelLayouter.h:119
Definition LabelLayouter.h:230
Definition LabelPath.h:44
virtual void RegisterContourLabel(const Projection &projection, const MapParameter &parameter, const ObjectFileRef &ref, const PathLabelData &label, const LabelPath &labelPath) override
void DrawArea(const Projection &projection, const MapParameter &parameter, const AreaData &area) override
agg::pixfmt_rgb24 AggPixelFormat
Definition MapPainterAgg.h:47
LabelLayouter< NativeGlyph, NativeLabel, MapPainterAgg > AggLabelLayouter
Definition MapPainterAgg.h:60
void DrawSymbol(const Projection &projection, const MapParameter &parameter, const Symbol &symbol, const Vertex2D &screenPos, double scaleFactor) override
void DrawGround(const Projection &projection, const MapParameter &parameter, const FillStyle &style) override
MapPainterAgg(const StyleConfigRef &styleConfig)
osmscout::ScreenVectorRectangle GlyphBoundingBox(const NativeGlyph &glyph) const
virtual void BeforeDrawing(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
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 DrawLabel(const Projection &projection, const MapParameter &parameter, const ScreenVectorRectangle &labelRectangle, const LabelData &label, const NativeLabel &layout)
virtual void DrawLabels(const Projection &projection, const MapParameter &parameter, const MapData &data) override
void DrawContourSymbol(const Projection &projection, const MapParameter &parameter, const Symbol &symbol, const ContourSymbolData &data) 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
std::shared_ptr< AggLabel > Layout(const Projection &projection, const MapParameter &parameter, const std::string &text, double fontSize, double objectWidth, bool enableWrapping=false, bool contourLabel=false)
void DrawIcon(const IconStyle *style, const Vertex2D &centerPos, double width, double height) override
bool DrawMap(const Projection &projection, const MapParameter &parameter, const MapData &data, AggPixelFormat *pf, RenderSteps startStep=RenderSteps::FirstStep, RenderSteps endStep=RenderSteps::LastStep)
void DrawGlyphs(const Projection &projection, const MapParameter &parameter, const osmscout::PathTextStyleRef style, const std::vector< AggGlyph > &glyphs)
Label< NativeGlyph, NativeLabel > AggLabel
Definition MapPainterAgg.h:58
Glyph< NativeGlyph > AggGlyph
Definition MapPainterAgg.h:59
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 MapPainterAgg.h:49
double x
Definition MapPainterAgg.h:50
const agg::glyph_cache * aggGlyph
Definition MapPainterAgg.h:52
double y
Definition MapPainterAgg.h:51
Definition MapPainterAgg.h:54
std::wstring text
Definition MapPainterAgg.h:55
std::vector< NativeGlyph > glyphs
Definition MapPainterAgg.h:56
Definition LabelLayouterHelper.h:73