| 
									
										
										
										
											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 18:04:04 +08:00
										 |  |  | E2DTextRender::E2DTextRender() | 
					
						
							| 
									
										
										
										
											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 18:04:04 +08:00
										 |  |  | E2DTextRender::~E2DTextRender() | 
					
						
							| 
									
										
										
										
											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 18:04:04 +08:00
										 |  |  | HRESULT E2DTextRender::Create( | 
					
						
							|  |  |  | 	E2DTextRender** ppTextRenderer, | 
					
						
							| 
									
										
										
										
											2018-05-24 17:19:54 +08:00
										 |  |  | 	ID2D1Factory* pD2DFactory, | 
					
						
							|  |  |  | 	ID2D1HwndRenderTarget* pRT, | 
					
						
							|  |  |  | 	ID2D1SolidColorBrush* pBrush | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-10-03 18:04:04 +08:00
										 |  |  | 	*ppTextRenderer = new (std::nothrow) E2DTextRender(); | 
					
						
							| 
									
										
										
										
											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 18:04:04 +08:00
										 |  |  | STDMETHODIMP_(void) E2DTextRender::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 18:04:04 +08:00
										 |  |  | STDMETHODIMP E2DTextRender::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 18:04:04 +08:00
										 |  |  | STDMETHODIMP E2DTextRender::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 18:04:04 +08:00
										 |  |  | STDMETHODIMP E2DTextRender::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 18:04:04 +08:00
										 |  |  | STDMETHODIMP E2DTextRender::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 18:04:04 +08:00
										 |  |  | STDMETHODIMP_(unsigned long) E2DTextRender::AddRef() | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  | { | 
					
						
							|  |  |  | 	return InterlockedIncrement(&cRefCount_); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-03 18:04:04 +08:00
										 |  |  | STDMETHODIMP_(unsigned long) E2DTextRender::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 18:04:04 +08:00
										 |  |  | STDMETHODIMP E2DTextRender::IsPixelSnappingDisabled( | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  | 	__maybenull void* clientDrawingContext, | 
					
						
							|  |  |  | 	__out BOOL* isDisabled | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	*isDisabled = FALSE; | 
					
						
							|  |  |  | 	return S_OK; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-03 18:04:04 +08:00
										 |  |  | STDMETHODIMP E2DTextRender::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 18:04:04 +08:00
										 |  |  | STDMETHODIMP E2DTextRender::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 18:04:04 +08:00
										 |  |  | STDMETHODIMP E2DTextRender::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; | 
					
						
							|  |  |  | } |