libosmscout 1.1.1
Loading...
Searching...
No Matches
MapPainterDirectX.h
Go to the documentation of this file.
1#ifndef OSMSCOUT_MAP_MAPPAINTERDIRECTX_H
2#define OSMSCOUT_MAP_MAPPAINTERDIRECTX_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 <unordered_map>
24
25#include <osmscoutmapdirectx/MapDirectXFeatures.h>
26
28
30
32
33#define NOMINMAX 1
34
35#include <d2d1.h>
36#include <dwrite.h>
37#include <Wincodec.h>
38
39#if defined(UNICODE) || defined(_UNICODE) || defined(_MBCS) || defined(MBCS)
40#define MBUC
41#endif
42
43namespace osmscout {
44
46 {
47 public:
49#ifdef MBUC
50 std::wstring character;
51#else
52 std::string character;
53#endif
54 double width;
55 double height;
56 };
57
59
61 {
62 public:
63 IDWriteFactory* m_pWriteFactory;
64 FLOAT m_fSize;
65 IDWriteTextLayout* m_pDWriteTextLayout;
66 DWRITE_TEXT_METRICS m_TextMetrics;
67
68 public:
70 double fontSize,
71 IDWriteTextFormat* font,
72 const std::string& text);
74 };
75
77
78 private:
80 friend DirectXLabelLayouter;
81
82 private:
83 using FontMap = std::unordered_map<uint32_t, IDWriteTextFormat *>;
84 FontMap m_Fonts;
85 using BrushMap = std::unordered_map<uint32_t, ID2D1SolidColorBrush *>;
86 BrushMap m_Brushs;
87 using GeometryMap = std::unordered_map<uint64_t, ID2D1PathGeometry *>;
88 GeometryMap m_Geometries;
89 GeometryMap m_Polygons;
90 using BitmapMap = std::unordered_map<uint64_t, ID2D1Bitmap *>;
91 BitmapMap m_Bitmaps;
92 using StrokeStyleMap = std::unordered_map<uint64_t, ID2D1StrokeStyle *>;
93 StrokeStyleMap m_StrokeStyles;
94 ID2D1StrokeStyle* m_dashLessStrokeStyle;
95
96 ID2D1Factory* m_pDirect2dFactory;
97 IDWriteFactory* m_pWriteFactory;
98 ID2D1RenderTarget* m_pRenderTarget;
99 IWICImagingFactory* m_pImagingFactory;
100 IDWriteRenderingParams* m_pRenderingParams;
101 PathTextRenderer* m_pPathTextRenderer;
102 FLOAT dpiX, dpiY;
103 std::map<double, double> fontHeightMap;
104 TypeConfigRef typeConfig;
105
106 DirectXLabelLayouter m_LabelLayouter;
107
108 private:
109 D2D1_COLOR_F GetColorValue(const Color& color);
110 ID2D1SolidColorBrush* GetColorBrush(const Color& color);
111 ID2D1SolidColorBrush* GetColorBrush(D2D1_COLOR_F& color);
112 ID2D1StrokeStyle* GetStrokeStyle(const std::vector<double>& dash);
113 void _DrawText(double x, double y, const Color& color, const DirectXTextLayout& textLayout);
114 bool LoadBitmapFromFile(PCWSTR uri, ID2D1Bitmap **ppBitmap);
115 IDWriteTextFormat* GetFont(const Projection& projection, const MapParameter& parameter, double fontSize);
116
117 protected:
119 const Projection &projection,
120 const MapParameter &parameter,
121 const MapData &data) override;
122
124 const Projection &projection,
125 const MapParameter &parameter,
126 const MapData &data) override;
127
129 const Projection &projection,
130 const MapParameter &parameter,
131 const MapData &data) override;
132
134 const Projection &projection,
135 const MapParameter &parameter,
136 IconStyle &style) override;
137
138
139 double GetFontHeight(const Projection &projection,
140 const MapParameter &parameter,
141 double fontSize) override;
142
144 const MapParameter& parameter,
145 double objectWidth,
146 double fontSize,
147 const std::string& text);
148
149 void DrawGround(const Projection &projection,
150 const MapParameter &parameter,
151 const FillStyle &style) override;
152
153 void DrawLabel(const Projection& projection,
154 const MapParameter& parameter,
155 const ScreenVectorRectangle& labelRectangle,
156 const LabelData& label,
157 const DirectXTextLayout& textLayout);
158
159 void DrawGlyphs(const Projection &projection,
160 const MapParameter &parameter,
161 const osmscout::PathTextStyleRef& style,
162 const std::vector<osmscout::Glyph<DirectXNativeGlyph>> &glyphs);
163
168 void RegisterRegularLabel(const Projection &projection,
169 const MapParameter &parameter,
170 const ObjectFileRef& ref,
171 const std::vector<LabelData> &labels,
172 const Vertex2D &position,
173 double objectWidth) override;
174
178 void RegisterContourLabel(const Projection &projection,
179 const MapParameter &parameter,
180 const ObjectFileRef& ref,
181 const PathLabelData &label,
182 const LabelPath &labelPath) override;
183
184 void DrawLabels(const Projection &projection,
185 const MapParameter &parameter,
186 const MapData &data) override;
187
188 void DrawIcon(const IconStyle *style,
189 const Vertex2D& centerPos,
190 double width, double height) override;
191
192 void DrawSymbol(const Projection &projection,
193 const MapParameter &parameter,
194 const Symbol &symbol,
195 const Vertex2D& screenPos,
196 double scaleFactor) override;
197
198 void DrawPath(const Projection &projection,
199 const MapParameter &parameter,
200 const Color &color,
201 double width,
202 const std::vector<double> &dash,
203 LineStyle::CapStyle startCap,
204 LineStyle::CapStyle endCap,
205 const CoordBufferRange& coordRange) override;
206
207 std::shared_ptr<DirectXLabel> Layout(const Projection& projection,
208 const MapParameter& parameter,
209 const std::string& text,
210 double fontSize,
211 double objectWidth,
212 bool enableWrapping = false,
213 bool contourLabel = false);
214
216
217 /*
218 virtual void DrawContourLabel(const Projection& projection,
219 const MapParameter& parameter,
220 const PathTextStyle& style,
221 const std::string& text,
222 size_t transStart, size_t transEnd,
223 ContourLabelHelper& helper);
224 */
225
226 void DrawContourSymbol(const Projection &projection,
227 const MapParameter &parameter,
228 const Symbol &symbol,
229 const ContourSymbolData& data) override;
230
231 void DrawArea(const Projection &projection,
232 const MapParameter &parameter,
233 const AreaData &area) override;
234
235 public:
237 ID2D1Factory *pDirect2dFactory,
238 IDWriteFactory *pWriteFactory);
239
241
243
244 bool DrawMap(const Projection& projection,
245 const MapParameter& parameter,
246 const MapData& data,
247 ID2D1RenderTarget* renderTarget);
248 };
249}
250
251#endif
#define OSMSCOUT_MAP_DIRECTX_API
Definition MapDirectXImportExport.h:45
Definition PathTextRenderer.h:68
Definition LabelLayouter.h:103
Definition LabelLayouter.h:57
Definition LabelLayouter.h:119
Definition LabelLayouter.h:230
Definition LabelPath.h:44
Definition MapPainterDirectX.h:61
FLOAT m_fSize
Definition MapPainterDirectX.h:64
DirectXTextLayout(IDWriteFactory *m_pWriteFactory, double fontSize, IDWriteTextFormat *font, const std::string &text)
IDWriteFactory * m_pWriteFactory
Definition MapPainterDirectX.h:63
IDWriteTextLayout * m_pDWriteTextLayout
Definition MapPainterDirectX.h:65
DWRITE_TEXT_METRICS m_TextMetrics
Definition MapPainterDirectX.h:66
bool DrawMap(const Projection &projection, const MapParameter &parameter, const MapData &data, ID2D1RenderTarget *renderTarget)
void RegisterContourLabel(const Projection &projection, const MapParameter &parameter, const ObjectFileRef &ref, const PathLabelData &label, const LabelPath &labelPath) override
void BeforeDrawing(const StyleConfig &styleConfig, const Projection &projection, const MapParameter &parameter, const MapData &data) override
double GetFontHeight(const Projection &projection, const MapParameter &parameter, double fontSize) override
osmscout::ScreenVectorRectangle GlyphBoundingBox(const DirectXNativeGlyph &glyph) const
Glyph< DirectXNativeGlyph > DirectXGlyph
Definition MapPainterDirectX.h:58
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
bool HasIcon(const StyleConfig &styleConfig, const Projection &projection, const MapParameter &parameter, IconStyle &style) override
void DrawGlyphs(const Projection &projection, const MapParameter &parameter, const osmscout::PathTextStyleRef &style, const std::vector< osmscout::Glyph< DirectXNativeGlyph > > &glyphs)
void AfterDrawing(const StyleConfig &styleConfig, 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 DrawSymbol(const Projection &projection, const MapParameter &parameter, const Symbol &symbol, const Vertex2D &screenPos, double scaleFactor) override
ScreenVectorRectangle GetTextDimension(const Projection &projection, const MapParameter &parameter, double objectWidth, double fontSize, const std::string &text)
MapPainterDirectX(const StyleConfigRef &styleConfig, ID2D1Factory *pDirect2dFactory, IDWriteFactory *pWriteFactory)
void RegisterRegularLabel(const Projection &projection, const MapParameter &parameter, const ObjectFileRef &ref, const std::vector< LabelData > &labels, const Vertex2D &position, double objectWidth) override
void DrawArea(const Projection &projection, const MapParameter &parameter, const AreaData &area) override
std::shared_ptr< DirectXLabel > Layout(const Projection &projection, const MapParameter &parameter, const std::string &text, double fontSize, double objectWidth, bool enableWrapping=false, bool contourLabel=false)
void DrawGround(const Projection &projection, const MapParameter &parameter, const FillStyle &style) override
void AfterPreprocessing(const StyleConfig &styleConfig, const Projection &projection, const MapParameter &parameter, const MapData &data) override
Label< DirectXNativeGlyph, DirectXTextLayout > DirectXLabel
Definition MapPainterDirectX.h:76
void DrawIcon(const IconStyle *style, const Vertex2D &centerPos, double width, double height) override
void DrawLabels(const Projection &projection, const MapParameter &parameter, const MapData &data) override
void DrawLabel(const Projection &projection, const MapParameter &parameter, const ScreenVectorRectangle &labelRectangle, const LabelData &label, const DirectXTextLayout &textLayout)
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
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
Definition MapPainter.h:174
Definition MapPainter.h:200
Definition MapPainterDirectX.h:48
double height
Definition MapPainterDirectX.h:55
double width
Definition MapPainterDirectX.h:54
std::string character
Definition MapPainterDirectX.h:52
Definition LabelLayouterHelper.h:73