Gfx: Make AccurateText=0 more consistent with GDI+ for D2D

The height is now based on a formula that should be exactly equal to that provided by GDI+. The padding should now be equal on the left and right sides now. There may be some discrepancies in overall width, but it should always be reasonably to close to GDI+.

In addition, this makes D2D behavior match GDI+ when a newline character is the last character of the text.
This commit is contained in:
Birunthan Mohanathas
2013-08-10 13:54:53 +03:00
parent 63f5eed742
commit 6e04fd983f
5 changed files with 140 additions and 89 deletions

View File

@ -23,31 +23,6 @@
namespace Gfx {
namespace Util {
DWRITE_TEXT_METRICS GetAdjustedDWriteTextLayoutMetrics(
IDWriteTextLayout* textLayout, bool gdiEmulation)
{
DWRITE_TEXT_METRICS metrics;
textLayout->GetMetrics(&metrics);
if (metrics.width > 0.0f)
{
if (gdiEmulation)
{
float size = 0.0f;
textLayout->GetFontSize(0, &size);
metrics.width = floor(metrics.width + (size / 2.05f) + (metrics.width / 55.0f) - 0.5f);
metrics.height = floor(metrics.height + (size / 9.25f) + 0.3f);
}
}
else
{
// Get rid of the height that DirectWrite assigns to zero-width strings.
metrics.height = 0.0f;
}
return metrics;
}
HRESULT GetDWritePropertiesFromGDIProperties(
IDWriteFactory* factory, const WCHAR* gdiFamilyName, const bool gdiBold, const bool gdiItalic,
DWRITE_FONT_WEIGHT& dwriteFontWeight, DWRITE_FONT_STYLE& dwriteFontStyle,

View File

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