|
4 | 4 | namespace WAS |
5 | 5 | { |
6 | 6 |
|
| 7 | +static const float SafetyTextRatio = 1.05f; |
| 8 | + |
7 | 9 | template<class Interface> |
8 | 10 | static void SafeRelease (Interface** interfaceToRelease) |
9 | 11 | { |
@@ -238,7 +240,6 @@ void Direct2DContext::FillEllipse (const NUIE::Rect& rect, const NUIE::Color& co |
238 | 240 |
|
239 | 241 | 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) |
240 | 242 | { |
241 | | - ID2D1SolidColorBrush* d2Brush = CreateBrush (renderTarget, textColor); |
242 | 243 | IDWriteTextFormat* textFormat = CreateTextFormat (renderTarget, font); |
243 | 244 |
|
244 | 245 | IDWriteTextLayout* textLayout = nullptr; |
@@ -268,24 +269,24 @@ void Direct2DContext::DrawFormattedText (const NUIE::Rect& rect, const NUIE::Fon |
268 | 269 | break; |
269 | 270 | } |
270 | 271 |
|
| 272 | + ID2D1SolidColorBrush* d2Brush = CreateBrush (renderTarget, textColor); |
271 | 273 | renderTarget->DrawTextLayout (CreatePoint (rect.GetTopLeft ()), textLayout, d2Brush); |
| 274 | + SafeRelease (&d2Brush); |
| 275 | + |
272 | 276 | SafeRelease (&textLayout); |
273 | 277 | SafeRelease (&textFormat); |
274 | | - SafeRelease (&d2Brush); |
275 | 278 | } |
276 | 279 |
|
277 | 280 | NUIE::Size Direct2DContext::MeasureText (const NUIE::Font& font, const std::wstring& text) |
278 | 281 | { |
279 | | - static const float SafetyPadding = 1.05f; |
280 | | - |
281 | 282 | IDWriteTextLayout* textLayout = nullptr; |
282 | 283 | IDWriteTextFormat* textFormat = CreateTextFormat (renderTarget, font); |
283 | 284 | direct2DHandler.directWriteFactory->CreateTextLayout (text.c_str (), (UINT32) text.length (), textFormat, 1000.0, 1000.0, &textLayout); |
284 | 285 | DWRITE_TEXT_METRICS metrics; |
285 | 286 | textLayout->GetMetrics (&metrics); |
286 | | - SafeRelease (&textFormat); |
287 | 287 | 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); |
289 | 290 | } |
290 | 291 |
|
291 | 292 | } |
0 commit comments