| 
									
										
										
										
											2018-10-03 22:02:46 +08:00
										 |  |  | // Copyright (c) 2016-2018 Easy2D - Nomango
 | 
					
						
							|  |  |  | // 
 | 
					
						
							|  |  |  | // Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
					
						
							|  |  |  | // of this software and associated documentation files (the "Software"), to deal
 | 
					
						
							|  |  |  | // in the Software without restriction, including without limitation the rights
 | 
					
						
							|  |  |  | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | 
					
						
							|  |  |  | // copies of the Software, and to permit persons to whom the Software is
 | 
					
						
							|  |  |  | // furnished to do so, subject to the following conditions:
 | 
					
						
							|  |  |  | // 
 | 
					
						
							|  |  |  | // The above copyright notice and this permission notice shall be included in
 | 
					
						
							|  |  |  | // all copies or substantial portions of the Software.
 | 
					
						
							|  |  |  | // 
 | 
					
						
							|  |  |  | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
					
						
							|  |  |  | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
					
						
							|  |  |  | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | 
					
						
							|  |  |  | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
					
						
							|  |  |  | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
					
						
							|  |  |  | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
					
						
							|  |  |  | // THE SOFTWARE.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-05 13:17:07 +08:00
										 |  |  | #include "..\e2dimpl.h"
 | 
					
						
							|  |  |  | #include "..\e2dmodule.h"
 | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | using namespace e2d; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-03 22:02:46 +08:00
										 |  |  | E2DTextRenderer::E2DTextRenderer() | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  | 	: cRefCount_(0) | 
					
						
							| 
									
										
										
										
											2018-05-24 17:19:54 +08:00
										 |  |  | 	, pD2DFactory_(nullptr) | 
					
						
							|  |  |  | 	, pRT_(nullptr) | 
					
						
							|  |  |  | 	, pBrush_(nullptr) | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  | 	, sFillColor_() | 
					
						
							|  |  |  | 	, sOutlineColor_() | 
					
						
							| 
									
										
										
										
											2018-04-22 00:33:20 +08:00
										 |  |  | 	, fOutlineWidth(1) | 
					
						
							|  |  |  | 	, bShowOutline_(TRUE) | 
					
						
							| 
									
										
										
										
											2018-05-24 17:19:54 +08:00
										 |  |  | 	, pCurrStrokeStyle_(nullptr) | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-03 22:02:46 +08:00
										 |  |  | E2DTextRenderer::~E2DTextRenderer() | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-22 12:24:43 +08:00
										 |  |  | 	SafeRelease(pD2DFactory_); | 
					
						
							|  |  |  | 	SafeRelease(pRT_); | 
					
						
							|  |  |  | 	SafeRelease(pBrush_); | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-03 22:02:46 +08:00
										 |  |  | HRESULT E2DTextRenderer::Create( | 
					
						
							|  |  |  | 	E2DTextRenderer** ppTextRenderer, | 
					
						
							| 
									
										
										
										
											2018-05-24 17:19:54 +08:00
										 |  |  | 	ID2D1Factory* pD2DFactory, | 
					
						
							|  |  |  | 	ID2D1HwndRenderTarget* pRT, | 
					
						
							|  |  |  | 	ID2D1SolidColorBrush* pBrush | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-10-03 22:02:46 +08:00
										 |  |  | 	*ppTextRenderer = new (std::nothrow) E2DTextRenderer(); | 
					
						
							| 
									
										
										
										
											2018-07-24 00:24:29 +08:00
										 |  |  | 	if (*ppTextRenderer) | 
					
						
							| 
									
										
										
										
											2018-05-24 17:19:54 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		pD2DFactory->AddRef(); | 
					
						
							|  |  |  | 		pRT->AddRef(); | 
					
						
							|  |  |  | 		pBrush->AddRef(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-24 00:24:29 +08:00
										 |  |  | 		(*ppTextRenderer)->pD2DFactory_ = pD2DFactory; | 
					
						
							|  |  |  | 		(*ppTextRenderer)->pRT_ = pRT; | 
					
						
							|  |  |  | 		(*ppTextRenderer)->pBrush_ = pBrush; | 
					
						
							|  |  |  | 		(*ppTextRenderer)->AddRef(); | 
					
						
							|  |  |  | 		return S_OK; | 
					
						
							| 
									
										
										
										
											2018-05-24 17:19:54 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-07-24 00:24:29 +08:00
										 |  |  | 	return E_FAIL; | 
					
						
							| 
									
										
										
										
											2018-05-24 17:19:54 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-03 22:02:46 +08:00
										 |  |  | STDMETHODIMP_(void) E2DTextRenderer::SetTextStyle( | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  | 	CONST D2D1_COLOR_F &fillColor, | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  | 	BOOL outline, | 
					
						
							|  |  |  | 	CONST D2D1_COLOR_F &outline_color, | 
					
						
							|  |  |  | 	FLOAT outline_width, | 
					
						
							| 
									
										
										
										
											2018-04-22 00:33:20 +08:00
										 |  |  | 	D2D1_LINE_JOIN outlineJoin | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	sFillColor_ = fillColor; | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  | 	bShowOutline_ = outline; | 
					
						
							|  |  |  | 	sOutlineColor_ = outline_color; | 
					
						
							|  |  |  | 	fOutlineWidth = 2 * outline_width; | 
					
						
							| 
									
										
										
										
											2018-05-24 17:19:54 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	switch (outlineJoin) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	case D2D1_LINE_JOIN_MITER: | 
					
						
							| 
									
										
										
										
											2018-10-03 18:04:04 +08:00
										 |  |  | 		pCurrStrokeStyle_ = Device::GetGraphics()->GetMiterStrokeStyle(); | 
					
						
							| 
									
										
										
										
											2018-05-24 17:19:54 +08:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case D2D1_LINE_JOIN_BEVEL: | 
					
						
							| 
									
										
										
										
											2018-10-03 18:04:04 +08:00
										 |  |  | 		pCurrStrokeStyle_ = Device::GetGraphics()->GetBevelStrokeStyle(); | 
					
						
							| 
									
										
										
										
											2018-05-24 17:19:54 +08:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case D2D1_LINE_JOIN_ROUND: | 
					
						
							| 
									
										
										
										
											2018-10-03 18:04:04 +08:00
										 |  |  | 		pCurrStrokeStyle_ = Device::GetGraphics()->GetRoundStrokeStyle(); | 
					
						
							| 
									
										
										
										
											2018-05-24 17:19:54 +08:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		pCurrStrokeStyle_ = nullptr; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-03 22:02:46 +08:00
										 |  |  | STDMETHODIMP E2DTextRenderer::DrawGlyphRun( | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  | 	__maybenull void* clientDrawingContext, | 
					
						
							|  |  |  | 	FLOAT baselineOriginX, | 
					
						
							|  |  |  | 	FLOAT baselineOriginY, | 
					
						
							|  |  |  | 	DWRITE_MEASURING_MODE measuringMode, | 
					
						
							|  |  |  | 	__in DWRITE_GLYPH_RUN const* glyphRun, | 
					
						
							|  |  |  | 	__in DWRITE_GLYPH_RUN_DESCRIPTION const* glyphRunDescription, | 
					
						
							|  |  |  | 	IUnknown* clientDrawingEffect | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	HRESULT hr = S_OK; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-17 15:22:14 +08:00
										 |  |  | 	ID2D1PathGeometry* pPathGeometry = nullptr; | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  | 	hr = pD2DFactory_->CreatePathGeometry( | 
					
						
							|  |  |  | 		&pPathGeometry | 
					
						
							|  |  |  | 	); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-17 15:22:14 +08:00
										 |  |  | 	ID2D1GeometrySink* pSink = nullptr; | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  | 	if (SUCCEEDED(hr)) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		hr = pPathGeometry->Open( | 
					
						
							|  |  |  | 			&pSink | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (SUCCEEDED(hr)) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		hr = glyphRun->fontFace->GetGlyphRunOutline( | 
					
						
							|  |  |  | 			glyphRun->fontEmSize, | 
					
						
							|  |  |  | 			glyphRun->glyphIndices, | 
					
						
							|  |  |  | 			glyphRun->glyphAdvances, | 
					
						
							|  |  |  | 			glyphRun->glyphOffsets, | 
					
						
							|  |  |  | 			glyphRun->glyphCount, | 
					
						
							|  |  |  | 			glyphRun->isSideways, | 
					
						
							|  |  |  | 			glyphRun->bidiLevel % 2, | 
					
						
							|  |  |  | 			pSink | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (SUCCEEDED(hr)) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		hr = pSink->Close(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	D2D1::Matrix3x2F const matrix = D2D1::Matrix3x2F( | 
					
						
							|  |  |  | 		1.0f, 0.0f, | 
					
						
							|  |  |  | 		0.0f, 1.0f, | 
					
						
							|  |  |  | 		baselineOriginX, baselineOriginY | 
					
						
							|  |  |  | 	); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-17 15:22:14 +08:00
										 |  |  | 	ID2D1TransformedGeometry* pTransformedGeometry = nullptr; | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  | 	if (SUCCEEDED(hr)) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		hr = pD2DFactory_->CreateTransformedGeometry( | 
					
						
							|  |  |  | 			pPathGeometry, | 
					
						
							|  |  |  | 			&matrix, | 
					
						
							|  |  |  | 			&pTransformedGeometry | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-17 15:22:14 +08:00
										 |  |  | 	if (SUCCEEDED(hr) && bShowOutline_) | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-05-24 17:19:54 +08:00
										 |  |  | 		pBrush_->SetColor(sOutlineColor_); | 
					
						
							| 
									
										
										
										
											2018-04-22 00:33:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-24 17:19:54 +08:00
										 |  |  | 		pRT_->DrawGeometry( | 
					
						
							|  |  |  | 			pTransformedGeometry, | 
					
						
							|  |  |  | 			pBrush_, | 
					
						
							|  |  |  | 			fOutlineWidth, | 
					
						
							|  |  |  | 			pCurrStrokeStyle_ | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-05-17 15:22:14 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-17 15:22:14 +08:00
										 |  |  | 	if (SUCCEEDED(hr)) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  | 		pBrush_->SetColor(sFillColor_); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		pRT_->FillGeometry( | 
					
						
							|  |  |  | 			pTransformedGeometry, | 
					
						
							|  |  |  | 			pBrush_ | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-22 12:24:43 +08:00
										 |  |  | 	SafeRelease(pPathGeometry); | 
					
						
							|  |  |  | 	SafeRelease(pSink); | 
					
						
							|  |  |  | 	SafeRelease(pTransformedGeometry); | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return hr; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-03 22:02:46 +08:00
										 |  |  | STDMETHODIMP E2DTextRenderer::DrawUnderline( | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  | 	__maybenull void* clientDrawingContext, | 
					
						
							|  |  |  | 	FLOAT baselineOriginX, | 
					
						
							|  |  |  | 	FLOAT baselineOriginY, | 
					
						
							|  |  |  | 	__in DWRITE_UNDERLINE const* underline, | 
					
						
							|  |  |  | 	IUnknown* clientDrawingEffect | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	HRESULT hr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	D2D1_RECT_F rect = D2D1::RectF( | 
					
						
							|  |  |  | 		0, | 
					
						
							|  |  |  | 		underline->offset, | 
					
						
							|  |  |  | 		underline->width, | 
					
						
							|  |  |  | 		underline->offset + underline->thickness | 
					
						
							|  |  |  | 	); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-17 15:22:14 +08:00
										 |  |  | 	ID2D1RectangleGeometry* pRectangleGeometry = nullptr; | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  | 	hr = pD2DFactory_->CreateRectangleGeometry( | 
					
						
							|  |  |  | 		&rect, | 
					
						
							|  |  |  | 		&pRectangleGeometry | 
					
						
							|  |  |  | 	); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	D2D1::Matrix3x2F const matrix = D2D1::Matrix3x2F( | 
					
						
							|  |  |  | 		1.0f, 0.0f, | 
					
						
							|  |  |  | 		0.0f, 1.0f, | 
					
						
							|  |  |  | 		baselineOriginX, baselineOriginY | 
					
						
							|  |  |  | 	); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-17 15:22:14 +08:00
										 |  |  | 	ID2D1TransformedGeometry* pTransformedGeometry = nullptr; | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  | 	if (SUCCEEDED(hr)) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		hr = pD2DFactory_->CreateTransformedGeometry( | 
					
						
							|  |  |  | 			pRectangleGeometry, | 
					
						
							|  |  |  | 			&matrix, | 
					
						
							|  |  |  | 			&pTransformedGeometry | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-17 15:22:14 +08:00
										 |  |  | 	if (SUCCEEDED(hr) && bShowOutline_) | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-05-24 17:19:54 +08:00
										 |  |  | 		pBrush_->SetColor(sOutlineColor_); | 
					
						
							| 
									
										
										
										
											2018-04-22 00:33:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-24 17:19:54 +08:00
										 |  |  | 		pRT_->DrawGeometry( | 
					
						
							|  |  |  | 			pTransformedGeometry, | 
					
						
							|  |  |  | 			pBrush_, | 
					
						
							|  |  |  | 			fOutlineWidth, | 
					
						
							|  |  |  | 			pCurrStrokeStyle_ | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-05-17 15:22:14 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-17 15:22:14 +08:00
										 |  |  | 	if (SUCCEEDED(hr)) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  | 		pBrush_->SetColor(sFillColor_); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		pRT_->FillGeometry( | 
					
						
							|  |  |  | 			pTransformedGeometry, | 
					
						
							|  |  |  | 			pBrush_ | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-22 12:24:43 +08:00
										 |  |  | 	SafeRelease(pRectangleGeometry); | 
					
						
							|  |  |  | 	SafeRelease(pTransformedGeometry); | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return S_OK; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-03 22:02:46 +08:00
										 |  |  | STDMETHODIMP E2DTextRenderer::DrawStrikethrough( | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  | 	__maybenull void* clientDrawingContext, | 
					
						
							|  |  |  | 	FLOAT baselineOriginX, | 
					
						
							|  |  |  | 	FLOAT baselineOriginY, | 
					
						
							|  |  |  | 	__in DWRITE_STRIKETHROUGH const* strikethrough, | 
					
						
							|  |  |  | 	IUnknown* clientDrawingEffect | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	HRESULT hr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	D2D1_RECT_F rect = D2D1::RectF( | 
					
						
							|  |  |  | 		0, | 
					
						
							|  |  |  | 		strikethrough->offset, | 
					
						
							|  |  |  | 		strikethrough->width, | 
					
						
							|  |  |  | 		strikethrough->offset + strikethrough->thickness | 
					
						
							|  |  |  | 	); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-17 15:22:14 +08:00
										 |  |  | 	ID2D1RectangleGeometry* pRectangleGeometry = nullptr; | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  | 	hr = pD2DFactory_->CreateRectangleGeometry( | 
					
						
							|  |  |  | 		&rect, | 
					
						
							|  |  |  | 		&pRectangleGeometry | 
					
						
							|  |  |  | 	); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	D2D1::Matrix3x2F const matrix = D2D1::Matrix3x2F( | 
					
						
							|  |  |  | 		1.0f, 0.0f, | 
					
						
							|  |  |  | 		0.0f, 1.0f, | 
					
						
							|  |  |  | 		baselineOriginX, baselineOriginY | 
					
						
							|  |  |  | 	); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-17 15:22:14 +08:00
										 |  |  | 	ID2D1TransformedGeometry* pTransformedGeometry = nullptr; | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  | 	if (SUCCEEDED(hr)) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		hr = pD2DFactory_->CreateTransformedGeometry( | 
					
						
							|  |  |  | 			pRectangleGeometry, | 
					
						
							|  |  |  | 			&matrix, | 
					
						
							|  |  |  | 			&pTransformedGeometry | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-17 15:22:14 +08:00
										 |  |  | 	if (SUCCEEDED(hr) && bShowOutline_) | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-05-24 17:19:54 +08:00
										 |  |  | 		pBrush_->SetColor(sOutlineColor_); | 
					
						
							| 
									
										
										
										
											2018-04-22 00:33:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-24 17:19:54 +08:00
										 |  |  | 		pRT_->DrawGeometry( | 
					
						
							|  |  |  | 			pTransformedGeometry, | 
					
						
							|  |  |  | 			pBrush_, | 
					
						
							|  |  |  | 			fOutlineWidth, | 
					
						
							|  |  |  | 			pCurrStrokeStyle_ | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-05-17 15:22:14 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-17 15:22:14 +08:00
										 |  |  | 	if (SUCCEEDED(hr)) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  | 		pBrush_->SetColor(sFillColor_); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		pRT_->FillGeometry( | 
					
						
							|  |  |  | 			pTransformedGeometry, | 
					
						
							|  |  |  | 			pBrush_ | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-22 12:24:43 +08:00
										 |  |  | 	SafeRelease(pRectangleGeometry); | 
					
						
							|  |  |  | 	SafeRelease(pTransformedGeometry); | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return S_OK; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-03 22:02:46 +08:00
										 |  |  | STDMETHODIMP E2DTextRenderer::DrawInlineObject( | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  | 	__maybenull void* clientDrawingContext, | 
					
						
							|  |  |  | 	FLOAT originX, | 
					
						
							|  |  |  | 	FLOAT originY, | 
					
						
							|  |  |  | 	IDWriteInlineObject* inlineObject, | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  | 	BOOL IsSideways, | 
					
						
							|  |  |  | 	BOOL IsRightToLeft, | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  | 	IUnknown* clientDrawingEffect | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return E_NOTIMPL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-03 22:02:46 +08:00
										 |  |  | STDMETHODIMP_(unsigned long) E2DTextRenderer::AddRef() | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  | { | 
					
						
							|  |  |  | 	return InterlockedIncrement(&cRefCount_); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-03 22:02:46 +08:00
										 |  |  | STDMETHODIMP_(unsigned long) E2DTextRenderer::Release() | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  | { | 
					
						
							|  |  |  | 	unsigned long newCount = InterlockedDecrement(&cRefCount_); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (newCount == 0) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		delete this; | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return newCount; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-03 22:02:46 +08:00
										 |  |  | STDMETHODIMP E2DTextRenderer::IsPixelSnappingDisabled( | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  | 	__maybenull void* clientDrawingContext, | 
					
						
							|  |  |  | 	__out BOOL* isDisabled | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	*isDisabled = FALSE; | 
					
						
							|  |  |  | 	return S_OK; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-03 22:02:46 +08:00
										 |  |  | STDMETHODIMP E2DTextRenderer::GetCurrentTransform( | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  | 	__maybenull void* clientDrawingContext, | 
					
						
							|  |  |  | 	__out DWRITE_MATRIX* transform | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	pRT_->GetTransform(reinterpret_cast<D2D1_MATRIX_3X2_F*>(transform)); | 
					
						
							|  |  |  | 	return S_OK; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-03 22:02:46 +08:00
										 |  |  | STDMETHODIMP E2DTextRenderer::GetPixelsPerDip( | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  | 	__maybenull void* clientDrawingContext, | 
					
						
							|  |  |  | 	__out FLOAT* pixelsPerDip | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	float x, yUnused; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	pRT_->GetDpi(&x, &yUnused); | 
					
						
							|  |  |  | 	*pixelsPerDip = x / 96; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return S_OK; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-03 22:02:46 +08:00
										 |  |  | STDMETHODIMP E2DTextRenderer::QueryInterface( | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  | 	IID const& riid, | 
					
						
							|  |  |  | 	void** ppvObject | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (__uuidof(IDWriteTextRenderer) == riid) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		*ppvObject = this; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else if (__uuidof(IDWritePixelSnapping) == riid) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		*ppvObject = this; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else if (__uuidof(IUnknown) == riid) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		*ppvObject = this; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-05-17 15:22:14 +08:00
										 |  |  | 		*ppvObject = nullptr; | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  | 		return E_FAIL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	AddRef(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return S_OK; | 
					
						
							|  |  |  | } |