Browse Source

Windows default font fix.

tags/2021-05-28
jules 12 years ago
parent
commit
e05393c36d
3 changed files with 39 additions and 6 deletions
  1. +31
    -3
      modules/juce_graphics/fonts/juce_Typeface.cpp
  2. +4
    -2
      modules/juce_graphics/native/juce_win32_DirectWriteTypeLayout.cpp
  3. +4
    -1
      modules/juce_graphics/native/juce_win32_DirectWriteTypeface.cpp

+ 31
- 3
modules/juce_graphics/fonts/juce_Typeface.cpp View File

@@ -57,10 +57,38 @@ struct FontStyleHelpers
|| family == Font::getDefaultMonospacedFontName();
}
static String getConcreteFamilyNameFromPlaceholder (const String& family)
struct ConcreteFamilyNames
{
const Font f (family, Font::getDefaultStyle(), 15.0f);
return Font::getDefaultTypefaceForFont (f)->getName();
ConcreteFamilyNames()
: sans (findName (Font::getDefaultSansSerifFontName())),
serif (findName (Font::getDefaultSerifFontName())),
mono (findName (Font::getDefaultMonospacedFontName()))
{
}
String lookUp (const String& placeholder)
{
if (placeholder == Font::getDefaultSansSerifFontName()) return sans;
if (placeholder == Font::getDefaultSerifFontName()) return serif;
if (placeholder == Font::getDefaultMonospacedFontName()) return mono;
return findName (placeholder);
}
private:
static String findName (const String& placeholder)
{
const Font f (placeholder, Font::getDefaultStyle(), 15.0f);
return Font::getDefaultTypefaceForFont (f)->getName();
}
String sans, serif, mono;
};
static String getConcreteFamilyNameFromPlaceholder (const String& placeholder)
{
static ConcreteFamilyNames names;
return names.lookUp (placeholder);
}
static String getConcreteFamilyName (const Font& font)


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

@@ -221,9 +221,11 @@ namespace DirectWriteTypeLayout
if (const Font* const font = attr.getFont())
{
const String familyName (FontStyleHelpers::getConcreteFamilyName (*font));
BOOL fontFound = false;
uint32 fontIndex;
fontCollection->FindFamilyName (FontStyleHelpers::getConcreteFamilyName (*font).toWideCharPointer(),
fontCollection->FindFamilyName (familyName.toWideCharPointer(),
&fontIndex, &fontFound);
if (! fontFound)
@@ -244,7 +246,7 @@ namespace DirectWriteTypeLayout
break;
}
textLayout->SetFontFamilyName (attr.getFont()->getTypefaceName().toWideCharPointer(), range);
textLayout->SetFontFamilyName (familyName.toWideCharPointer(), range);
textLayout->SetFontWeight (dwFont->GetWeight(), range);
textLayout->SetFontStretch (dwFont->GetStretch(), range);
textLayout->SetFontStyle (dwFont->GetStyle(), range);


+ 4
- 1
modules/juce_graphics/native/juce_win32_DirectWriteTypeface.cpp View File

@@ -153,10 +153,13 @@ public:
{
hr = dwFontFamily->GetFont (i, dwFont.resetAndGetPointerAddress());
if (i == 0)
break;
ComSmartPtr<IDWriteLocalizedStrings> faceNames;
hr = dwFont->GetFaceNames (faceNames.resetAndGetPointerAddress());
if (i == 0 || font.getTypefaceStyle() == getLocalisedName (faceNames))
if (font.getTypefaceStyle() == getLocalisedName (faceNames))
break;
}


Loading…
Cancel
Save