D2D: Undo recent W/H calculations and revert back to 37fd105 calculations

This commit is contained in:
Brian Ferguson 2013-08-02 15:42:37 -06:00
parent bb53ddf71c
commit 1e82a1659f
3 changed files with 6 additions and 13 deletions

View File

@ -350,9 +350,8 @@ bool CanvasD2D::MeasureTextW(const WCHAR* str, UINT strLen, const TextFormat& fo
textLayout.GetAddressOf()); textLayout.GetAddressOf());
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
std::wstring s = str;
const DWRITE_TEXT_METRICS metrics = const DWRITE_TEXT_METRICS metrics =
Util::GetAdjustedDWriteTextLayoutMetrics(textLayout.Get(), !m_AccurateText, s.rfind(L"\n") != std::wstring::npos); Util::GetAdjustedDWriteTextLayoutMetrics(textLayout.Get(), !m_AccurateText);
rect.Width = metrics.width; rect.Width = metrics.width;
rect.Height = metrics.height; rect.Height = metrics.height;
return true; return true;
@ -376,7 +375,7 @@ bool CanvasD2D::MeasureTextLinesW(const WCHAR* str, UINT strLen, const TextForma
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
const DWRITE_TEXT_METRICS metrics = const DWRITE_TEXT_METRICS metrics =
Util::GetAdjustedDWriteTextLayoutMetrics(textLayout.Get(), !m_AccurateText, false); Util::GetAdjustedDWriteTextLayoutMetrics(textLayout.Get(), !m_AccurateText);
rect.Width = metrics.width; rect.Width = metrics.width;
lines = metrics.lineCount; lines = metrics.lineCount;

View File

@ -24,7 +24,7 @@ namespace Gfx {
namespace Util { namespace Util {
DWRITE_TEXT_METRICS GetAdjustedDWriteTextLayoutMetrics( DWRITE_TEXT_METRICS GetAdjustedDWriteTextLayoutMetrics(
IDWriteTextLayout* textLayout, bool gdiEmulation, bool containsNewLine) IDWriteTextLayout* textLayout, bool gdiEmulation)
{ {
DWRITE_TEXT_METRICS metrics; DWRITE_TEXT_METRICS metrics;
textLayout->GetMetrics(&metrics); textLayout->GetMetrics(&metrics);
@ -33,14 +33,8 @@ DWRITE_TEXT_METRICS GetAdjustedDWriteTextLayoutMetrics(
{ {
float size = 0.0f; float size = 0.0f;
textLayout->GetFontSize(0, &size); textLayout->GetFontSize(0, &size);
metrics.width = floor(metrics.width + ((size / 3.0f) * 2.0f) + ((size * 3.0f / 4.0f) / 17.5f) + 0.255f); metrics.width = floor(metrics.width + (size / 2.05f) + (metrics.width / 55.0f) - 0.5f);
metrics.height = floor(metrics.height + (size / 9.25f) + 0.3f);
if (containsNewLine)
{
metrics.width -= ((size * 3.0f / 4.0f) / 4.0f);
}
metrics.height = floor(metrics.height + (size / 9.25f) + 0.3f);
} }
return metrics; return metrics;

View File

@ -27,7 +27,7 @@ namespace Util {
// If |gdiEmulation| is true, the returns metrics have similar characteristics to those provided // If |gdiEmulation| is true, the returns metrics have similar characteristics to those provided
// by GDI+. // by GDI+.
DWRITE_TEXT_METRICS GetAdjustedDWriteTextLayoutMetrics( DWRITE_TEXT_METRICS GetAdjustedDWriteTextLayoutMetrics(
IDWriteTextLayout* textLayout, bool gdiEmulation, bool containsNewLine); IDWriteTextLayout* textLayout, bool gdiEmulation);
// Maps the GDI family name and italic/bold flags to the DirectWrite family name, weight, style, // Maps the GDI family name and italic/bold flags to the DirectWrite family name, weight, style,
// and stretch. // and stretch.