From a07ce814eb7c8d5aa435f534755544ba102db132 Mon Sep 17 00:00:00 2001 From: jules Date: Tue, 18 Dec 2012 18:06:01 +0000 Subject: [PATCH] win32 font point size fixes. --- .../native/juce_win32_DirectWriteTypeface.cpp | 12 ++++++++---- modules/juce_graphics/native/juce_win32_Fonts.cpp | 7 ++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/modules/juce_graphics/native/juce_win32_DirectWriteTypeface.cpp b/modules/juce_graphics/native/juce_win32_DirectWriteTypeface.cpp index 4eeb42db55..366e4f07a2 100644 --- a/modules/juce_graphics/native/juce_win32_DirectWriteTypeface.cpp +++ b/modules/juce_graphics/native/juce_win32_DirectWriteTypeface.cpp @@ -130,7 +130,7 @@ class WindowsDirectWriteTypeface : public Typeface public: WindowsDirectWriteTypeface (const Font& font, IDWriteFontCollection* fontCollection) : Typeface (font.getTypefaceName(), font.getTypefaceStyle()), - ascent (0.0f) + unitsToHeightScaleFactor (1.0f), heightToPointsFactor (1.0f), ascent (0.0f) { jassert (fontCollection != nullptr); @@ -175,6 +175,10 @@ public: ascent /= totalSize; unitsToHeightScaleFactor = designUnitsPerEm / totalSize; + HDC tempDC = GetDC (0); + heightToPointsFactor = (72.0f / GetDeviceCaps (tempDC, LOGPIXELSY)) * unitsToHeightScaleFactor; + ReleaseDC (0, tempDC); + const float pathAscent = (1024.0f * dwFontMetrics.ascent) / designUnitsPerEm; const float pathDescent = (1024.0f * dwFontMetrics.descent) / designUnitsPerEm; const float pathScale = 1.0f / (std::abs (pathAscent) + std::abs (pathDescent)); @@ -183,7 +187,7 @@ public: float getAscent() const { return ascent; } float getDescent() const { return 1.0f - ascent; } - float getHeightToPointsFactor() const { return unitsToHeightScaleFactor; } + float getHeightToPointsFactor() const { return heightToPointsFactor; } float getStringWidth (const String& text) { @@ -254,14 +258,14 @@ public: private: ComSmartPtr dwFontFace; - float unitsToHeightScaleFactor, ascent; + float unitsToHeightScaleFactor, heightToPointsFactor, ascent; int designUnitsPerEm; AffineTransform pathTransform; class PathGeometrySink : public ComBaseClassHelper { public: - PathGeometrySink() { resetReferenceCount(); } + PathGeometrySink() : ComBaseClassHelper (0) {} void __stdcall AddBeziers (const D2D1_BEZIER_SEGMENT *beziers, UINT beziersCount) { diff --git a/modules/juce_graphics/native/juce_win32_Fonts.cpp b/modules/juce_graphics/native/juce_win32_Fonts.cpp index 599dae6d3a..ef6f773f55 100644 --- a/modules/juce_graphics/native/juce_win32_Fonts.cpp +++ b/modules/juce_graphics/native/juce_win32_Fonts.cpp @@ -217,7 +217,7 @@ public: if (GetTextMetrics (dc, &tm)) { - heightToPointsFactor = 256.0f / tm.tmHeight; + heightToPointsFactor = (72.0f / GetDeviceCaps (dc, LOGPIXELSY)) * heightInPoints / (float) tm.tmHeight; ascent = tm.tmAscent / (float) tm.tmHeight; defaultGlyph = getGlyphForChar (dc, tm.tmDefaultChar); createKerningPairs (dc, (float) tm.tmHeight); @@ -355,7 +355,7 @@ private: HDC dc; TEXTMETRIC tm; float ascent, heightToPointsFactor; - int defaultGlyph; + int defaultGlyph, heightInPoints; struct KerningPair { @@ -403,7 +403,8 @@ private: OUTLINETEXTMETRIC otm; if (GetOutlineTextMetrics (dc, sizeof (otm), &otm) != 0) { - lf.lfHeight = -(int) otm.otmEMSquare; + heightInPoints = otm.otmEMSquare; + lf.lfHeight = -(int) heightInPoints; fontH = CreateFontIndirect (&lf); SelectObject (dc, fontH);