libosmscout  1.1.1
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 <osmscout/MapDirectXFeatures.h>
26 
28 
29 #include <osmscout/MapPainter.h>
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 
43 namespace 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:
69  DirectXTextLayout(IDWriteFactory* m_pWriteFactory, double fontSize, IDWriteTextFormat* font, std::string text);
71  };
72 
74 
75  private:
77  friend DirectXLabelLayouter;
78 
79  private:
80  typedef std::unordered_map<uint32_t, IDWriteTextFormat*> FontMap;
81  FontMap m_Fonts;
82  typedef std::unordered_map<uint32_t, ID2D1SolidColorBrush*> BrushMap;
83  BrushMap m_Brushs;
84  typedef std::unordered_map<uint64_t, ID2D1PathGeometry*> GeometryMap;
85  GeometryMap m_Geometries;
86  GeometryMap m_Polygons;
87  typedef std::unordered_map<uint64_t, ID2D1Bitmap*> BitmapMap;
88  BitmapMap m_Bitmaps;
89  typedef std::unordered_map<uint64_t, ID2D1StrokeStyle*> StrokeStyleMap;
90  StrokeStyleMap m_StrokeStyles;
91  ID2D1StrokeStyle* m_dashLessStrokeStyle;
92 
93  ID2D1Factory* m_pDirect2dFactory;
94  IDWriteFactory* m_pWriteFactory;
95  ID2D1RenderTarget* m_pRenderTarget;
96  IWICImagingFactory* m_pImagingFactory;
97  IDWriteRenderingParams* m_pRenderingParams;
98  PathTextRenderer* m_pPathTextRenderer;
99  FLOAT dpiX, dpiY;
100  std::map<double, double> fontHeightMap;
101  TypeConfigRef typeConfig;
102 
103  DirectXLabelLayouter m_LabelLayouter;
104 
105  private:
106  D2D1_COLOR_F GetColorValue(const Color& color);
107  ID2D1SolidColorBrush* GetColorBrush(const Color& color);
108  ID2D1SolidColorBrush* GetColorBrush(D2D1_COLOR_F& color);
109  ID2D1StrokeStyle* GetStrokeStyle(const std::vector<double>& dash);
110  void _DrawText(double x, double y, const Color& color, const DirectXTextLayout& textLayout);
111  bool LoadBitmapFromFile(PCWSTR uri, ID2D1Bitmap **ppBitmap);
112  IDWriteTextFormat* GetFont(const Projection& projection, const MapParameter& parameter, double fontSize);
113 
114  protected:
115  virtual void AfterPreprocessing(const StyleConfig& styleConfig,
116  const Projection& projection,
117  const MapParameter& parameter,
118  const MapData& data);
119 
120  virtual void BeforeDrawing(const StyleConfig& styleConfig,
121  const Projection& projection,
122  const MapParameter& parameter,
123  const MapData& data);
124 
125  virtual void AfterDrawing(const StyleConfig& styleConfig,
126  const Projection& projection,
127  const MapParameter& parameter,
128  const MapData& data);
129 
130  virtual bool HasIcon(const StyleConfig& styleConfig,
131  const Projection& projection,
132  const MapParameter& parameter,
133  IconStyle& style);
134 
135 
136  virtual double GetFontHeight(const Projection& projection,
137  const MapParameter& parameter,
138  double fontSize);
139 
140  DoubleRectangle GetTextDimension(const Projection& projection,
141  const MapParameter& parameter,
142  double objectWidth,
143  double fontSize,
144  const std::string& text);
145 
146  virtual void DrawGround(const Projection& projection,
147  const MapParameter& parameter,
148  const FillStyle& style);
149 
150  void DrawLabel(const Projection& projection,
151  const MapParameter& parameter,
152  const DoubleRectangle& labelRectangle,
153  const LabelData& label,
154  const DirectXTextLayout& textLayout);
155 
156  void DrawGlyphs(const Projection &projection,
157  const MapParameter &parameter,
158  const osmscout::PathTextStyleRef style,
159  const std::vector<osmscout::Glyph<DirectXNativeGlyph>> &glyphs);
160 
165  virtual void RegisterRegularLabel(const Projection &projection,
166  const MapParameter &parameter,
167  const std::vector<LabelData> &labels,
168  const Vertex2D &position,
169  double objectWidth);
170 
174  virtual void RegisterContourLabel(const Projection &projection,
175  const MapParameter &parameter,
176  const PathLabelData &label,
177  const LabelPath &labelPath);
178 
179  virtual void DrawLabels(const Projection& projection,
180  const MapParameter& parameter,
181  const MapData& data);
182 
183  virtual void DrawIcon(const IconStyle* style,
184  double centerX, double centerY,
185  double width, double height);
186 
187  virtual void DrawSymbol(const Projection& projection,
188  const MapParameter& parameter,
189  const Symbol& symbol,
190  double x, double y);
191 
192  virtual 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);
200 
201  std::shared_ptr<DirectXLabel> Layout(const Projection& projection,
202  const MapParameter& parameter,
203  const std::string& text,
204  double fontSize,
205  double objectWidth,
206  bool enableWrapping = false,
207  bool contourLabel = false);
208 
209  osmscout::DoubleRectangle GlyphBoundingBox(const DirectXNativeGlyph &glyph) const;
210 
211  /*
212  virtual void DrawContourLabel(const Projection& projection,
213  const MapParameter& parameter,
214  const PathTextStyle& style,
215  const std::string& text,
216  size_t transStart, size_t transEnd,
217  ContourLabelHelper& helper);
218  */
219 
220  virtual void DrawContourSymbol(const Projection& projection,
221  const MapParameter& parameter,
222  const Symbol& symbol,
223  double space,
224  size_t transStart, size_t transEnd);
225 
226  virtual void DrawArea(const Projection& projection,
227  const MapParameter& parameter,
228  const AreaData& area);
229 
230  public:
231  MapPainterDirectX(const StyleConfigRef& styleConfig,
232  ID2D1Factory* pDirect2dFactory,
233  IDWriteFactory* pWriteFactory);
234  virtual ~MapPainterDirectX();
235 
236  void DiscardDeviceResources();
237 
238  bool DrawMap(const Projection& projection,
239  const MapParameter& parameter,
240  const MapData& data,
241  ID2D1RenderTarget* renderTarget);
242  };
243 }
244 
245 #endif
Definition: MapPainterDirectX.h:45
Definition: LabelLayouter.h:144
Definition: Styles.h:884
Index selectors by type and level.
Definition: StyleConfig.h:553
FLOAT m_fSize
Definition: MapPainterDirectX.h:64
Definition: LabelLayouter.h:87
#define OSMSCOUT_MAP_DIRECTX_API
Definition: MapDirectXImportExport.h:45
IDWriteTextLayout * m_pDWriteTextLayout
Definition: MapPainterDirectX.h:65
Definition: MapPainterDirectX.h:60
std::string character
Definition: MapPainterDirectX.h:52
IDWriteFactory * m_pWriteFactory
Definition: MapPainterDirectX.h:63
Definition: Projection.h:43
Definition: MapPainter.h:75
std::shared_ptr< PathTextStyle > PathTextStyleRef
Definition: Styles.h:877
Definition: Area.h:38
double height
Definition: MapPainterDirectX.h:55
Definition: Styles.h:1135
double width
Definition: MapPainterDirectX.h:54
Definition: LabelPath.h:42
Definition: LabelLayouter.h:98
Definition: PathTextRenderer.h:67
std::shared_ptr< StyleConfig > StyleConfigRef
Definition: StyleConfig.h:849
Definition: MapPainterDirectX.h:48
Definition: MapPainter.h:87
DWRITE_TEXT_METRICS m_TextMetrics
Definition: MapPainterDirectX.h:66
Definition: LabelLayouter.h:129
Definition: Styles.h:280
std::shared_ptr< TypeConfig > TypeConfigRef
Definition: TypeConfig.h:1227
Definition: MapPainter.h:179
CapStyle
Definition: Styles.h:69