summaryrefslogtreecommitdiffstats
path: root/src/libnrtype
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2014-10-02 12:46:09 +0000
committertavmjong-free <tavmjong@free.fr>2014-10-02 12:46:09 +0000
commit65915368e41196b54e18d707320422b185f47d6b (patch)
tree522bbda5e055b180c915ea893fc4ff09ded080b8 /src/libnrtype
parenti18n. Fix for Bug #380522 (strings that need to be fixed for translation). (diff)
downloadinkscape-65915368e41196b54e18d707320422b185f47d6b.tar.gz
inkscape-65915368e41196b54e18d707320422b185f47d6b.zip
Work-around for Pango 1.36.7 which introduced 'Semi-Light' font weight,
bug #1364937. (bzr r13577)
Diffstat (limited to 'src/libnrtype')
-rw-r--r--src/libnrtype/FontFactory.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/libnrtype/FontFactory.cpp b/src/libnrtype/FontFactory.cpp
index fa452dd77..e11fed20c 100644
--- a/src/libnrtype/FontFactory.cpp
+++ b/src/libnrtype/FontFactory.cpp
@@ -97,6 +97,7 @@ font_factory::font_factory(void) :
fontSize(512),
loadedPtr(new FaceMapType())
{
+ // std::cout << pango_version_string() << std::endl;
#ifdef USE_PANGO_WIN32
#else
pango_ft2_font_map_set_resolution(PANGO_FT2_FONT_MAP(fontServer),
@@ -545,6 +546,7 @@ void font_factory::GetUIFamiliesAndStyles(FamilyToStylesMap *map)
if (faceDescr) {
Glib::ustring familyUIName = GetUIFamilyString(faceDescr);
Glib::ustring styleUIName = GetUIStyleString(faceDescr);
+ // std::cout << familyUIName << " " << styleUIName << " (" << displayName << ")" << std::endl;
// Disable synthesized (faux) font faces except for CSS generic faces
if (pango_font_face_is_synthesized(faces[currentFace]) ) {
@@ -558,6 +560,35 @@ void font_factory::GetUIFamiliesAndStyles(FamilyToStylesMap *map)
}
}
+ // Pango breaks the 1 to 1 mapping between Pango weights and CSS weights by
+ // adding Semi-Light (as of 1.36.7), Book (as of 1.24), and Ultra-Heavy (as of
+ // 1.24). We need to map these weights to CSS weights. Book and Ultra-Heavy
+ // are rarely used. Semi-Light (350) is problematic as it is halfway between
+ // Light (300) and Normal (400) and if care is not taken it is converted to
+ // Normal, rather than Light.
+ //
+ // Note: The ultimate solution to handling various weight in the same
+ // font family is to support the @font rules from CSS.
+ //
+ // Additional notes, helpful for debugging:
+ // Pango's FC backend:
+ // Weights defined in fontconfig/fontconfig.h
+ // String equivalents in src/fcfreetype.c
+ // Weight set from os2->usWeightClass
+ // Use Fontforge: Element->Font Info...->OS/2->Misc->Weight Class to check font weight
+ size_t f = styleUIName.find( "Book" );
+ if( f != Glib::ustring::npos ) {
+ styleUIName.replace( f, 4, "Normal" );
+ }
+ f = styleUIName.find( "Semi-Light" );
+ if( f != Glib::ustring::npos ) {
+ styleUIName.replace( f, 10, "Light" );
+ }
+ f = styleUIName.find( "Ultra-Heavy" );
+ if( f != Glib::ustring::npos ) {
+ styleUIName.replace( f, 11, "Heavy" );
+ }
+
if (!familyUIName.empty() && !styleUIName.empty()) {
// Find the right place to put the style information, adding
@@ -581,6 +612,7 @@ void font_factory::GetUIFamiliesAndStyles(FamilyToStylesMap *map)
++it) {
if ( (*it).CssName == styleUIName) {
exists = true;
+ std::cerr << "Warning: Font face with same CSS values already added: " << familyUIName << " " << styleUIName << " (" << (*it).DisplayName << ", " << displayName << ")" << std::endl;
break;
}
}