summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2014-10-15 18:38:31 +0000
committertavmjong-free <tavmjong@free.fr>2014-10-15 18:38:31 +0000
commit91741bf6f23e79c0c709e08b0ec0c0f8aad8139f (patch)
tree3ae5fad83e24b42753aa14e117d06ff810abc40d /src
parentMore direct way of finding font-family. One entry per unique style. (diff)
downloadinkscape-91741bf6f23e79c0c709e08b0ec0c0f8aad8139f.tar.gz
inkscape-91741bf6f23e79c0c709e08b0ec0c0f8aad8139f.zip
Various small font things.
(experimental r13577-13579) (bzr r13616.1.4)
Diffstat (limited to 'src')
-rw-r--r--src/libnrtype/FontFactory.cpp41
1 files changed, 39 insertions, 2 deletions
diff --git a/src/libnrtype/FontFactory.cpp b/src/libnrtype/FontFactory.cpp
index cb9602394..d052eeb42 100644
--- a/src/libnrtype/FontFactory.cpp
+++ b/src/libnrtype/FontFactory.cpp
@@ -265,6 +265,12 @@ static int StyleNameValue( const Glib::ustring &style )
// return( StyleNameValue( style1.CssName ) < StyleNameValue( style2.CssName ) );
//}
+static gint StyleNameCompareInternalGlib(gconstpointer a, gconstpointer b)
+{
+ return( StyleNameValue( ((StyleNames *)a)->CssName ) <
+ StyleNameValue( ((StyleNames *)b)->CssName ) ? -1 : 1 );
+}
+
static bool ustringPairSort(std::pair<PangoFontFamily*, Glib::ustring> const& first, std::pair<PangoFontFamily*, Glib::ustring> const& second)
{
// well, this looks weird.
@@ -319,7 +325,7 @@ GList* font_factory::GetUIStyles(PangoFontFamily * in)
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]) ) {
if (familyUIName.compare( "sans-serif" ) != 0 &&
@@ -331,6 +337,35 @@ GList* font_factory::GetUIStyles(PangoFontFamily * in)
}
}
+ // 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" );
+ }
+
bool exists = false;
for(GList *temp = ret; temp; temp = temp->next) {
if( ((StyleNames*)temp->data)->CssName.compare( styleUIName ) == 0 ) {
@@ -351,10 +386,12 @@ GList* font_factory::GetUIStyles(PangoFontFamily * in)
pango_font_description_free(faceDescr);
}
g_free(faces);
+
+ // Sort the style lists
+ ret = g_list_sort( ret, StyleNameCompareInternalGlib );
return ret;
}
-
font_instance* font_factory::FaceFromStyle(SPStyle const *style)
{
font_instance *font = NULL;