libosmscout 1.1.1
Loading...
Searching...
No Matches
PathTextRenderer.h
Go to the documentation of this file.
1#pragma once
2
3#define NOMINMAX 1
4
5#include <d2d1.h>
6#include <dwrite.h>
7
9
16{
17private:
18 double contourLabelOffset;
19 double contourLabelSpace;
20 double pathLength;
21 double textWidth;
22 double currentOffset;
23public:
24 explicit ContourLabelHelper(double contourLabelOffset, double contourLabelSpace);
25
26 bool Init(double pathLength,
27 double textWidth);
28
29 inline bool ContinueDrawing() const
30 {
31 return currentOffset<pathLength;
32 }
33
34 inline double GetCurrentOffset() const
35 {
36 return currentOffset;
37 }
38
39 inline void AdvancePartial(double width)
40 {
41 currentOffset+=width;
42 }
43
44 inline void AdvanceText()
45 {
46 currentOffset+=textWidth;
47 }
48
49 inline void AdvanceSpace()
50 {
51 currentOffset+=contourLabelSpace;
52 }
53};
54
55/*
56 * This structure is needed to hold the renderer context. It is passed around as a void* pointer,
57 * typically the clientDrawingContext in the methods below.
58 */
60{
62 ID2D1RenderTarget* d2DContext;
63 ID2D1Geometry* geometry;
64 ID2D1Brush* brush;
65};
66
67class PathTextRenderer final : public IDWriteTextRenderer
68{
69public:
70 // Static creation method that takes care of allocating a renderer
71 // AND registering it as a COM component.
72 static void CreatePathTextRenderer(float pixelsPerDip, PathTextRenderer **textRenderer);
73
74 //
75 // Public destruction method for PathTextRenderer. This method
76 // does the exact opposite of CreatePathTextRenderer.
77 //
78 static void DestroyPathTextRenderer(PathTextRenderer *textRenderer);
79
80 // All the STDMETHOD have been lifted from the IDWriteTextRenderer interface
81 STDMETHOD(DrawGlyphRun)(
82 _In_opt_ void* clientDrawingContext,
83 FLOAT baselineOriginX,
84 FLOAT baselineOriginY,
85 DWRITE_MEASURING_MODE measuringMode,
86 _In_ DWRITE_GLYPH_RUN const* glyphRun,
87 _In_ DWRITE_GLYPH_RUN_DESCRIPTION const* glyphRunDescription,
88 _In_opt_ IUnknown* clientDrawingEffect
89 ) override;
90
91 STDMETHOD(DrawUnderline)(
92 _In_opt_ void* clientDrawingContext,
93 FLOAT baselineOriginX,
94 FLOAT baselineOriginY,
95 _In_ DWRITE_UNDERLINE const* underline,
96 _In_opt_ IUnknown* clientDrawingEffect
97 ) override;
98
100 _In_opt_ void* clientDrawingContext,
101 FLOAT baselineOriginX,
102 FLOAT baselineOriginY,
103 _In_ DWRITE_STRIKETHROUGH const* strikethrough,
104 _In_opt_ IUnknown* clientDrawingEffect
105 ) override;
106
108 _In_opt_ void* clientDrawingContext,
109 FLOAT originX,
110 FLOAT originY,
111 IDWriteInlineObject* inlineObject,
112 BOOL isSideways,
113 BOOL isRightToLeft,
114 _In_opt_ IUnknown* clientDrawingEffect
115 ) override;
116
118 _In_opt_ void* clientDrawingContext,
119 _Out_ BOOL* isDisabled
120 ) override;
121
123 _In_opt_ void* clientDrawingContext,
124 _Out_ DWRITE_MATRIX* transform
125 ) override;
126
127 STDMETHOD(GetPixelsPerDip)(
128 _In_opt_ void* clientDrawingContext,
129 _Out_ FLOAT* pixelsPerDip
130 ) override;
131
132 STDMETHOD(QueryInterface)(
133 REFIID riid,
134 _Outptr_ void** object
135 ) override;
136
137 STDMETHOD_(ULONG, AddRef)() override;
138
139 STDMETHOD_(ULONG, Release)() override;
140
141private:
142 float m_pixelsPerDip; // Number of pixels per DIP.
143 UINT m_ref; // Reference count for AddRef and Release.
144
145 PathTextRenderer(float pixelsPerDip);
146};
Definition PathTextRenderer.h:16
bool Init(double pathLength, double textWidth)
void AdvanceText()
Definition PathTextRenderer.h:44
double GetCurrentOffset() const
Definition PathTextRenderer.h:34
void AdvanceSpace()
Definition PathTextRenderer.h:49
ContourLabelHelper(double contourLabelOffset, double contourLabelSpace)
void AdvancePartial(double width)
Definition PathTextRenderer.h:39
bool ContinueDrawing() const
Definition PathTextRenderer.h:29
STDMETHOD DrawGlyphRun(_In_opt_ void *clientDrawingContext, FLOAT baselineOriginX, FLOAT baselineOriginY, DWRITE_MEASURING_MODE measuringMode, _In_ DWRITE_GLYPH_RUN const *glyphRun, _In_ DWRITE_GLYPH_RUN_DESCRIPTION const *glyphRunDescription, _In_opt_ IUnknown *clientDrawingEffect) override
STDMETHOD QueryInterface(REFIID riid, _Outptr_ void **object) override
STDMETHOD DrawInlineObject(_In_opt_ void *clientDrawingContext, FLOAT originX, FLOAT originY, IDWriteInlineObject *inlineObject, BOOL isSideways, BOOL isRightToLeft, _In_opt_ IUnknown *clientDrawingEffect) override
STDMETHOD IsPixelSnappingDisabled(_In_opt_ void *clientDrawingContext, _Out_ BOOL *isDisabled) override
STDMETHOD GetCurrentTransform(_In_opt_ void *clientDrawingContext, _Out_ DWRITE_MATRIX *transform) override
static void CreatePathTextRenderer(float pixelsPerDip, PathTextRenderer **textRenderer)
STDMETHOD DrawStrikethrough(_In_opt_ void *clientDrawingContext, FLOAT baselineOriginX, FLOAT baselineOriginY, _In_ DWRITE_STRIKETHROUGH const *strikethrough, _In_opt_ IUnknown *clientDrawingEffect) override
static void DestroyPathTextRenderer(PathTextRenderer *textRenderer)
STDMETHOD_(ULONG, AddRef)() override
STDMETHOD GetPixelsPerDip(_In_opt_ void *clientDrawingContext, _Out_ FLOAT *pixelsPerDip) override
STDMETHOD DrawUnderline(_In_opt_ void *clientDrawingContext, FLOAT baselineOriginX, FLOAT baselineOriginY, _In_ DWRITE_UNDERLINE const *underline, _In_opt_ IUnknown *clientDrawingEffect) override
STDMETHOD_(ULONG, Release)() override
Definition PathTextRenderer.h:60
ID2D1Geometry * geometry
Definition PathTextRenderer.h:63
ContourLabelHelper * helper
Definition PathTextRenderer.h:61
ID2D1Brush * brush
Definition PathTextRenderer.h:64
ID2D1RenderTarget * d2DContext
Definition PathTextRenderer.h:62