Skip to content

Commit de93daf

Browse files
committed
Minor modifications.
1 parent 520ff4b commit de93daf

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

Sources/WindowsAppSupport/WAS_Direct2DContext.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
namespace WAS
55
{
66

7+
static const float SafetyTextRatio = 1.05f;
8+
79
template<class Interface>
810
static void SafeRelease (Interface** interfaceToRelease)
911
{
@@ -238,7 +240,6 @@ void Direct2DContext::FillEllipse (const NUIE::Rect& rect, const NUIE::Color& co
238240

239241
void Direct2DContext::DrawFormattedText (const NUIE::Rect& rect, const NUIE::Font& font, const std::wstring& text, NUIE::HorizontalAnchor hAnchor, NUIE::VerticalAnchor vAnchor, const NUIE::Color& textColor)
240242
{
241-
ID2D1SolidColorBrush* d2Brush = CreateBrush (renderTarget, textColor);
242243
IDWriteTextFormat* textFormat = CreateTextFormat (renderTarget, font);
243244

244245
IDWriteTextLayout* textLayout = nullptr;
@@ -268,24 +269,24 @@ void Direct2DContext::DrawFormattedText (const NUIE::Rect& rect, const NUIE::Fon
268269
break;
269270
}
270271

272+
ID2D1SolidColorBrush* d2Brush = CreateBrush (renderTarget, textColor);
271273
renderTarget->DrawTextLayout (CreatePoint (rect.GetTopLeft ()), textLayout, d2Brush);
274+
SafeRelease (&d2Brush);
275+
272276
SafeRelease (&textLayout);
273277
SafeRelease (&textFormat);
274-
SafeRelease (&d2Brush);
275278
}
276279

277280
NUIE::Size Direct2DContext::MeasureText (const NUIE::Font& font, const std::wstring& text)
278281
{
279-
static const float SafetyPadding = 1.05f;
280-
281282
IDWriteTextLayout* textLayout = nullptr;
282283
IDWriteTextFormat* textFormat = CreateTextFormat (renderTarget, font);
283284
direct2DHandler.directWriteFactory->CreateTextLayout (text.c_str (), (UINT32) text.length (), textFormat, 1000.0, 1000.0, &textLayout);
284285
DWRITE_TEXT_METRICS metrics;
285286
textLayout->GetMetrics (&metrics);
286-
SafeRelease (&textFormat);
287287
SafeRelease (&textLayout);
288-
return NUIE::Size (metrics.width * SafetyPadding, metrics.height * SafetyPadding);
288+
SafeRelease (&textFormat);
289+
return NUIE::Size (metrics.width * SafetyTextRatio, metrics.height * SafetyTextRatio);
289290
}
290291

291292
}

0 commit comments

Comments
 (0)