Browse Source

OSX/win32 typeface fixes.

tags/2021-05-28
jules 13 years ago
parent
commit
cd7cdacfd1
3 changed files with 20 additions and 10 deletions
  1. +8
    -0
      modules/juce_graphics/fonts/juce_Typeface.cpp
  2. +9
    -8
      modules/juce_graphics/native/juce_mac_Fonts.mm
  3. +3
    -2
      modules/juce_graphics/native/juce_win32_DirectWriteTypeLayout.cpp

+ 8
- 0
modules/juce_graphics/fonts/juce_Typeface.cpp View File

@@ -57,6 +57,14 @@ namespace FontStyleHelpers
const Font f (family, Font::getDefaultStyle(), 15.0f); const Font f (family, Font::getDefaultStyle(), 15.0f);
return Font::getDefaultTypefaceForFont (f)->getName(); return Font::getDefaultTypefaceForFont (f)->getName();
} }
static String getConcreteFamilyName (const Font& font)
{
const String& family = font.getTypefaceName();
return isPlaceholderFamilyName (family) ? getConcreteFamilyNameFromPlaceholder (family)
: family;
}
} }
//============================================================================== //==============================================================================


+ 9
- 8
modules/juce_graphics/native/juce_mac_Fonts.mm View File

@@ -46,7 +46,7 @@ namespace CoreTextTypeLayout
static CTFontRef createCTFont (const Font& font, const float fontSize, static CTFontRef createCTFont (const Font& font, const float fontSize,
const bool applyScaleFactor) const bool applyScaleFactor)
{ {
CFStringRef cfFontFamily = font.getTypefaceName().toCFString();
CFStringRef cfFontFamily = FontStyleHelpers::getConcreteFamilyName (font).toCFString();
CFStringRef cfFontStyle = findBestAvailableStyle (font.getTypefaceName(), CFStringRef cfFontStyle = findBestAvailableStyle (font.getTypefaceName(),
font.getTypefaceStyle()).toCFString(); font.getTypefaceStyle()).toCFString();
CFStringRef keys[] = { kCTFontFamilyNameAttribute, kCTFontStyleNameAttribute }; CFStringRef keys[] = { kCTFontFamilyNameAttribute, kCTFontStyleNameAttribute };
@@ -312,10 +312,9 @@ namespace CoreTextTypeLayout
CTFontRef ctRunFont; CTFontRef ctRunFont;
if (CFDictionaryGetValueIfPresent (runAttributes, kCTFontAttributeName, (const void **) &ctRunFont)) if (CFDictionaryGetValueIfPresent (runAttributes, kCTFontAttributeName, (const void **) &ctRunFont))
{ {
CTFontDescriptorRef ctFontDescRef = CTFontCopyFontDescriptor (ctRunFont);
CFDictionaryRef fontDescAttributes = CTFontDescriptorCopyAttributes (ctFontDescRef);
CTFontRef ctFontRef = CTFontCreateWithFontDescriptor (ctFontDescRef, 1024, nullptr);
CFRelease (ctFontDescRef);
CFStringRef cfsFontName = CTFontCopyPostScriptName (ctRunFont);
CTFontRef ctFontRef = CTFontCreateWithName (cfsFontName, 1024, nullptr);
CFRelease (cfsFontName);
CGFontRef cgFontRef = CTFontCopyGraphicsFont (ctFontRef, nullptr); CGFontRef cgFontRef = CTFontCopyGraphicsFont (ctFontRef, nullptr);
CFRelease (ctFontRef); CFRelease (ctFontRef);
@@ -323,13 +322,15 @@ namespace CoreTextTypeLayout
const float fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (cgFontRef) / (float) totalHeight; const float fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (cgFontRef) / (float) totalHeight;
CGFontRelease (cgFontRef); CGFontRelease (cgFontRef);
CFStringRef cfsFontFamily = (CFStringRef) CFDictionaryGetValue (fontDescAttributes, kCTFontFamilyNameAttribute);
CFStringRef cfsFontStyle = (CFStringRef) CFDictionaryGetValue (fontDescAttributes, kCTFontStyleNameAttribute);
CFStringRef cfsFontFamily = (CFStringRef) CTFontCopyAttribute (ctRunFont, kCTFontFamilyNameAttribute);
CFStringRef cfsFontStyle = (CFStringRef) CTFontCopyAttribute (ctRunFont, kCTFontStyleNameAttribute);
glyphRun->font = Font (String::fromCFString (cfsFontFamily), glyphRun->font = Font (String::fromCFString (cfsFontFamily),
String::fromCFString (cfsFontStyle), String::fromCFString (cfsFontStyle),
CTFontGetSize (ctRunFont) / fontHeightToCGSizeFactor); CTFontGetSize (ctRunFont) / fontHeightToCGSizeFactor);
CFRelease (fontDescAttributes);
CFRelease (cfsFontStyle);
CFRelease (cfsFontFamily);
} }
CGColorRef cgRunColor; CGColorRef cgRunColor;


+ 3
- 2
modules/juce_graphics/native/juce_win32_DirectWriteTypeLayout.cpp View File

@@ -220,7 +220,8 @@ namespace DirectWriteTypeLayout
{ {
BOOL fontFound = false; BOOL fontFound = false;
uint32 fontIndex; uint32 fontIndex;
fontCollection->FindFamilyName (font->getTypefaceName().toWideCharPointer(), &fontIndex, &fontFound);
fontCollection->FindFamilyName (FontStyleHelpers::getConcreteFamilyName (*font).toWideCharPointer(),
&fontIndex, &fontFound);
if (! fontFound) if (! fontFound)
fontIndex = 0; fontIndex = 0;
@@ -236,7 +237,7 @@ namespace DirectWriteTypeLayout
{ {
hr = fontFamily->GetFont (i, dwFont.resetAndGetPointerAddress()); hr = fontFamily->GetFont (i, dwFont.resetAndGetPointerAddress());
if (attr.getFont()->getTypefaceStyle() == getFontFaceName (dwFont))
if (font->getTypefaceStyle() == getFontFaceName (dwFont))
break; break;
} }


Loading…
Cancel
Save