summaryrefslogtreecommitdiffstats
path: root/src/libnrtype
diff options
context:
space:
mode:
authorLiam P. White <inkscapebrony@gmail.com>2014-10-08 02:22:03 +0000
committerLiam P. White <inkscapebrony@gmail.com>2014-10-08 02:22:03 +0000
commitf3840fe9d0d423f6ddf5a68d776a903d57ffb7b5 (patch)
treec8e28b27f5885928ccf866a69eb6cbc99fde599c /src/libnrtype
parentUpdate to experimental r13565 (diff)
parentSome template cleanup... (diff)
downloadinkscape-f3840fe9d0d423f6ddf5a68d776a903d57ffb7b5.tar.gz
inkscape-f3840fe9d0d423f6ddf5a68d776a903d57ffb7b5.zip
Update to experimental r13598
(bzr r13341.5.17)
Diffstat (limited to 'src/libnrtype')
-rw-r--r--src/libnrtype/CMakeLists.txt4
-rw-r--r--src/libnrtype/FontFactory.cpp675
-rw-r--r--src/libnrtype/FontFactory.h43
-rw-r--r--src/libnrtype/FontInstance.cpp145
-rw-r--r--src/libnrtype/Layout-TNG-Output.cpp3
-rw-r--r--src/libnrtype/Makefile_insert4
-rw-r--r--src/libnrtype/font-instance.h6
-rw-r--r--src/libnrtype/font-lister.cpp9
-rw-r--r--src/libnrtype/font-style-to-pos.cpp120
-rw-r--r--src/libnrtype/font-style-to-pos.h21
-rw-r--r--src/libnrtype/nr-type-pos-def.cpp268
-rw-r--r--src/libnrtype/nr-type-pos-def.h102
12 files changed, 217 insertions, 1183 deletions
diff --git a/src/libnrtype/CMakeLists.txt b/src/libnrtype/CMakeLists.txt
index 84979d7ea..05fd01a03 100644
--- a/src/libnrtype/CMakeLists.txt
+++ b/src/libnrtype/CMakeLists.txt
@@ -3,14 +3,12 @@ set(nrtype_SRC
FontFactory.cpp
FontInstance.cpp
font-lister.cpp
- font-style-to-pos.cpp
Layout-TNG.cpp
Layout-TNG-Compute.cpp
Layout-TNG-Input.cpp
Layout-TNG-OutIter.cpp
Layout-TNG-Output.cpp
Layout-TNG-Scanline-Makers.cpp
- nr-type-pos-def.cpp
nr-type-primitives.cpp
TextWrapper.cpp
@@ -25,9 +23,7 @@ set(nrtype_SRC
font-glyph.h
font-instance.h
font-lister.h
- font-style-to-pos.h
font-style.h
- nr-type-pos-def.h
nr-type-primitives.h
one-box.h
one-glyph.h
diff --git a/src/libnrtype/FontFactory.cpp b/src/libnrtype/FontFactory.cpp
index c5e68e264..c8f5e1fef 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),
@@ -129,13 +130,6 @@ font_factory::~font_factory(void)
delete tmp;
loadedPtr = 0;
}
-
- // Delete the pango font pointers in the string to instance map
- PangoStringToDescrMap::iterator it = fontInstanceMap.begin();
- while (it != fontInstanceMap.end()) {
- pango_font_description_free((*it).second);
- ++it;
- }
}
@@ -248,248 +242,6 @@ Glib::ustring font_factory::GetUIStyleString(PangoFontDescription const *fontDes
return style;
}
-/**
- Replace font family leaving style alone (if possible).
- @param fontSpec the given font
- @param newFamily
- @return the changed fontspec, if the property can not be set return an empty string
- The routine first searches for an exact match.
- If no exact match found, calls FontSpecificationBestMatch().
-*/
-Glib::ustring font_factory::ReplaceFontSpecificationFamily(const Glib::ustring & fontSpec, const Glib::ustring & newFamily)
-{
- Glib::ustring newFontSpec;
-
- // Although we are using the string from pango_font_description_to_string for the
- // font specification, we definitely cannot just set the new family in the
- // PangoFontDescription structure and ask for a new string. This is because
- // what constitutes a "family" in our own UI may be different from how Pango
- // sees it.
-
- // Find the PangoFontDescription associated with the old font specification string.
- PangoStringToDescrMap::iterator it = fontInstanceMap.find(fontSpec);
-
-
- if (it != fontInstanceMap.end()) {
- // Description found!
-
- // Make copy
- PangoFontDescription *descr = pango_font_description_copy((*it).second);
-
- // Grab the old UI Family string from the descr
- Glib::ustring uiFamily = GetUIFamilyString(descr);
-
- // Replace the UI Family name with the new family name
- std::size_t found = fontSpec.find(uiFamily);
- if (found != Glib::ustring::npos) {
-
- // Add comma to end of newFamily... commas at end don't hurt but are
- // required if the last part of a family name is a valid font style
- // (e.g. "Arial Black").
- Glib::ustring newFamilyComma = newFamily;
- if( *newFamilyComma.rbegin() != ',' ) {
- newFamilyComma += ",";
- }
- newFontSpec = fontSpec;
- newFontSpec.erase(found, uiFamily.size());
- newFontSpec.insert(found, newFamilyComma);
-
- // If the new font specification does not exist in the reference maps,
- // search for the next best match for the faces in that style
- it = fontInstanceMap.find(newFontSpec);
- if (it == fontInstanceMap.end()) {
-
- // Search for best match, empty string returned if not found.
- newFontSpec = FontSpecificationBestMatch( newFontSpec );
-
- }
- }
-
- pango_font_description_free(descr);
- }
-
- return newFontSpec;
-}
-
-/**
- Apply style property to the given font
- @param fontSpec the given font
- @param turnOn true to set italic style
- @return the changed fontspec, if the property can not be set return an empty string
- The routine first searches for an exact match to "FontFamily Italic" or
- "Font Family Oblique" (turnOn is true) or "FontFamily" (turnOn is false).
- If no exact match found, calls FontSpecificationBestMatch().
-*/
-Glib::ustring font_factory::FontSpecificationSetItalic(const Glib::ustring & fontSpec, bool turnOn)
-{
- Glib::ustring newFontSpec;
-
- // Find the PangoFontDescription associated with the font specification string.
- PangoStringToDescrMap::iterator it = fontInstanceMap.find(fontSpec);
-
- if (it != fontInstanceMap.end()) {
- // Description found!
-
- // Make copy.
- PangoFontDescription *descr = pango_font_description_copy((*it).second);
-
- PangoStyle style;
- if (turnOn) {
- // First try Oblique, we'll try Italic later
- style = PANGO_STYLE_OBLIQUE;
- } else {
- style = PANGO_STYLE_NORMAL;
- }
-
- pango_font_description_set_style(descr, style);
-
- newFontSpec = ConstructFontSpecification(descr);
-
- bool exactMatchFound = true;
- if (fontInstanceMap.find(newFontSpec) == fontInstanceMap.end()) {
-
- exactMatchFound = false;
- if (turnOn) {
- // Next try Italic
- style = PANGO_STYLE_ITALIC;
- pango_font_description_set_style(descr, style);
-
- exactMatchFound = true;
- if (fontInstanceMap.find(newFontSpec) == fontInstanceMap.end()) {
- exactMatchFound = false;
- }
- }
- }
-
- // Search for best match, empty string returned if not found.
- if( !exactMatchFound ) {
- newFontSpec = FontSpecificationBestMatch( newFontSpec );
- }
-
- pango_font_description_free(descr);
- }
-
- return newFontSpec; // Empty if not found.
-}
-
-/**
- Apply weight property to the given font
- @param fontSpec the given font
- @param turnOn true to set bold
- @return the changed fontspec, if the property can not be set return an empty string
- This routine first searches for an exact match, if none found
- it calls FontSpecificationBestMatch().
-*/
-Glib::ustring font_factory::FontSpecificationSetBold(const Glib::ustring & fontSpec, bool turnOn)
-{
- Glib::ustring newFontSpec;
-
- // Find the PangoFontDescription associated with the font specification string.
- PangoStringToDescrMap::iterator it = fontInstanceMap.find(fontSpec);
-
- if (it != fontInstanceMap.end()) {
- // Description found!
-
- // Make copy.
- PangoFontDescription *descr = pango_font_description_copy((*it).second);
-
-
- PangoWeight weight;
- if (turnOn) {
- weight = PANGO_WEIGHT_BOLD;
- } else {
- weight = PANGO_WEIGHT_NORMAL;
- }
-
- pango_font_description_set_weight(descr, weight);
-
- newFontSpec = ConstructFontSpecification(descr);
-
- if (fontInstanceMap.find(newFontSpec) == fontInstanceMap.end()) {
- // Search for best match, empty string returned if not found.
- newFontSpec = FontSpecificationBestMatch( newFontSpec );
- }
-
- pango_font_description_free(descr);
- }
-
- return newFontSpec; // Empty if not found.
-}
-
-/**
- Use pango_font_description_better_match() to find best font match.
- This handles cases like Century Schoolbook L where the "normal"
- font is Century Schoolbook L Medium so just removing Italic
- from the font name doesn't yield the correct name.
- @param fontSpec the given font
- @return the changed fontspec, if the property can not be set return an empty string
-*/
-// http://library.gnome.org/devel/pango/1.28/pango-Fonts.html#pango-font-description-better-match
-Glib::ustring font_factory::FontSpecificationBestMatch(const Glib::ustring & fontSpec )
-{
-
- Glib::ustring newFontSpec;
-
- // Look for exact match
- PangoStringToDescrMap::iterator it = fontInstanceMap.find(fontSpec);
-
- // If there is no exact match, look for the best match.
- if (it != fontInstanceMap.end()) {
-
- newFontSpec = fontSpec;
-
- } else {
-
- PangoFontDescription *fontDescr = pango_font_description_from_string(fontSpec.c_str());
- PangoFontDescription *bestMatchDescr = NULL;
-
- // Grab the UI Family string from the descr
- Glib::ustring family = GetUIFamilyString(fontDescr);
- Glib::ustring bestMatchDescription;
-
- bool setFirstFamilyMatch = false;
- for (it = fontInstanceMap.begin(); it != fontInstanceMap.end(); ++it) {
-
- Glib::ustring currentFontSpec = (*it).first;
- Glib::ustring currentFamily = GetUIFamilyString((*it).second);
-
- // Save some time by only looking at the right family.
- // Must use family name rather than fontSpec
- // (otherwise DejaVu Sans matches DejaVu Sans Mono).
- if (currentFamily == family) {
- if (!setFirstFamilyMatch) {
- // This ensures that the closest match is at least within the correct
- // family rather than the first font in the list
- bestMatchDescr = pango_font_description_copy((*it).second);
- bestMatchDescription = currentFontSpec;
- setFirstFamilyMatch = true;
- } else {
- // Get the font description that corresponds, and
- // then see if we've found a better match
- PangoFontDescription *possibleMatch = pango_font_description_copy((*it).second);
-
- if (pango_font_description_better_match(
- fontDescr, bestMatchDescr, possibleMatch)) {
-
- pango_font_description_free(bestMatchDescr);
- bestMatchDescr = possibleMatch;
- bestMatchDescription = currentFontSpec;
- } else {
- pango_font_description_free(possibleMatch);
- }
- }
- }
- } // for
-
- newFontSpec = bestMatchDescription; // If NULL, then no match found
-
- pango_font_description_free(fontDescr);
- pango_font_description_free(bestMatchDescr);
-
- }
-
- return newFontSpec;
-}
/////
@@ -508,9 +260,15 @@ static int StyleNameValue( const Glib::ustring &style )
}
// Determines order in which styles are presented (sorted by CSS style values)
-static bool StyleNameCompareInternal(const StyleNames &style1, const StyleNames &style2)
+//static bool StyleNameCompareInternal(const StyleNames &style1, const StyleNames &style2)
+//{
+// return( StyleNameValue( style1.CssName ) < StyleNameValue( style2.CssName ) );
+//}
+
+static gint StyleNameCompareInternalGlib(gconstpointer a, gconstpointer b)
{
- return( StyleNameValue( style1.CssName ) < StyleNameValue( style2.CssName ) );
+ 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)
@@ -558,6 +316,7 @@ GList* font_factory::GetUIStyles(PangoFontFamily * in)
// If the face has a name, describe it, and then use the
// description to get the UI family and face strings
const gchar* displayName = pango_font_face_get_face_name(faces[currentFace]);
+ // std::cout << "Display Name: " << displayName << std::endl;
if (displayName == NULL || *displayName == '\0') {
continue;
}
@@ -566,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 &&
@@ -578,7 +337,48 @@ GList* font_factory::GetUIStyles(PangoFontFamily * in)
}
}
- if (!familyUIName.empty() && !styleUIName.empty()) {
+ // 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 ) {
+ exists = true;
+ std::cerr << "Warning: Font face with same CSS values already added: "
+ << familyUIName << " " << styleUIName
+ << " (" << ((StyleNames*)temp->data)->DisplayName
+ << ", " << displayName << ")" << std::endl;
+ break;
+ }
+ }
+
+ if (!exists && !familyUIName.empty() && !styleUIName.empty()) {
// Add the style information
ret = g_list_append(ret, new StyleNames(styleUIName, displayName));
}
@@ -586,112 +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;
}
-void font_factory::GetUIFamiliesAndStyles(FamilyToStylesMap *map)
-{
- g_assert(map);
-
- if (map) {
-
- // Gather the family names as listed by Pango
- PangoFontFamily** families = NULL;
- int numFamilies = 0;
- pango_font_map_list_families(fontServer, &families, &numFamilies);
-
- for (int currentFamily=0; currentFamily < numFamilies; currentFamily++) {
-
- // Gather the styles for this family
- PangoFontFace** faces = NULL;
- int numFaces = 0;
- pango_font_family_list_faces(families[currentFamily], &faces, &numFaces);
-
- for (int currentFace=0; currentFace < numFaces; currentFace++) {
-
- // If the face has a name, describe it, and then use the
- // description to get the UI family and face strings
-
- const gchar* displayName = pango_font_face_get_face_name(faces[currentFace]);
- if (displayName == NULL) {
- continue;
- }
-
- PangoFontDescription *faceDescr = pango_font_face_describe(faces[currentFace]);
- if (faceDescr) {
- Glib::ustring familyUIName = GetUIFamilyString(faceDescr);
- Glib::ustring styleUIName = GetUIStyleString(faceDescr);
-
- // Disable synthesized (faux) font faces except for CSS generic faces
- if (pango_font_face_is_synthesized(faces[currentFace]) ) {
- if( familyUIName.compare( "sans-serif" ) != 0 &&
- familyUIName.compare( "serif" ) != 0 &&
- familyUIName.compare( "monospace" ) != 0 &&
- familyUIName.compare( "fantasy" ) != 0 &&
- familyUIName.compare( "cursive" ) != 0 ) {
- //std::cout << "faux: " << familyUIName << " | " << styleUIName << std::endl;
- continue;
- }
- }
-
- if (!familyUIName.empty() && !styleUIName.empty()) {
-
- // Find the right place to put the style information, adding
- // a map entry for the family name if it doesn't yet exist
-
- FamilyToStylesMap::iterator iter = map->find(familyUIName);
-
- // Insert new family
- if (iter == map->end()) {
- map->insert(std::make_pair(familyUIName, std::list<StyleNames>()));
- }
-
- // Insert into the style list and save the info in the reference maps
- // only if the style does not yet exist
-
- bool exists = false;
- std::list<StyleNames> &styleList = (*map)[familyUIName];
-
- for (std::list<StyleNames>::iterator it=styleList.begin();
- it != styleList.end();
- ++it) {
- if ( (*it).CssName == styleUIName) {
- exists = true;
- break;
- }
- }
-
- if (!exists) {
- styleList.push_back( StyleNames(styleUIName,displayName) );
-
- // Add the string info needed in the reference maps
- fontStringMap.insert(
- std::make_pair(
- Glib::ustring(familyUIName) + Glib::ustring(styleUIName),
- ConstructFontSpecification(faceDescr)));
- fontInstanceMap.insert(
- std::make_pair(ConstructFontSpecification(faceDescr), faceDescr));
-
- } else {
- pango_font_description_free(faceDescr);
- }
- } else {
- pango_font_description_free(faceDescr);
- }
- }
- }
- g_free(faces);
- faces = 0;
- }
- g_free(families);
- families = 0;
-
- // Sort the style lists
- for (FamilyToStylesMap::iterator iter = map->begin() ; iter != map->end(); ++iter) {
- (*iter).second.sort(StyleNameCompareInternal);
- }
- }
-}
font_instance* font_factory::FaceFromStyle(SPStyle const *style)
{
@@ -712,15 +412,131 @@ font_instance* font_factory::FaceFromStyle(SPStyle const *style)
// If that failed, try using the CSS information in the style
if (!font) {
- font = Face(style->font_family.value, font_style_to_pos(*style));
+ PangoFontDescription *temp_descr = pango_font_description_new();
+
+ pango_font_description_set_family(temp_descr, style->font_family.value);
+
+ // This duplicates Layout::EnumConversionItem... perhaps we can share code?
+ switch ( style->font_style.computed ) {
+ case SP_CSS_FONT_STYLE_ITALIC:
+ pango_font_description_set_style(temp_descr, PANGO_STYLE_ITALIC);
+ break;
- // That was a hatchet job... so we need to check if this font exists!!
- Glib::ustring fontSpec = font_factory::Default()->ConstructFontSpecification(font);
- Glib::ustring newFontSpec = FontSpecificationBestMatch( fontSpec );
- if( fontSpec != newFontSpec ) {
- font->Unref();
- font = FaceFromFontSpecification( newFontSpec.c_str() );
+ case SP_CSS_FONT_STYLE_OBLIQUE:
+ pango_font_description_set_style(temp_descr, PANGO_STYLE_OBLIQUE);
+ break;
+
+ case SP_CSS_FONT_STYLE_NORMAL:
+ default:
+ pango_font_description_set_style(temp_descr, PANGO_STYLE_NORMAL);
+ break;
+ }
+
+ switch( style->font_weight.computed ) {
+ case SP_CSS_FONT_WEIGHT_100:
+ pango_font_description_set_weight(temp_descr, PANGO_WEIGHT_THIN);
+ break;
+
+ case SP_CSS_FONT_WEIGHT_200:
+ pango_font_description_set_weight(temp_descr, PANGO_WEIGHT_ULTRALIGHT);
+ break;
+
+ case SP_CSS_FONT_WEIGHT_300:
+ pango_font_description_set_weight(temp_descr, PANGO_WEIGHT_LIGHT);
+ break;
+
+ case SP_CSS_FONT_WEIGHT_400:
+ case SP_CSS_FONT_WEIGHT_NORMAL:
+ pango_font_description_set_weight(temp_descr, PANGO_WEIGHT_NORMAL);
+ break;
+
+ case SP_CSS_FONT_WEIGHT_500:
+ pango_font_description_set_weight(temp_descr, PANGO_WEIGHT_MEDIUM);
+ break;
+
+ case SP_CSS_FONT_WEIGHT_600:
+ pango_font_description_set_weight(temp_descr, PANGO_WEIGHT_SEMIBOLD);
+ break;
+
+ case SP_CSS_FONT_WEIGHT_700:
+ case SP_CSS_FONT_WEIGHT_BOLD:
+ pango_font_description_set_weight(temp_descr, PANGO_WEIGHT_BOLD);
+ break;
+
+ case SP_CSS_FONT_WEIGHT_800:
+ pango_font_description_set_weight(temp_descr, PANGO_WEIGHT_ULTRABOLD);
+ break;
+
+ case SP_CSS_FONT_WEIGHT_900:
+ pango_font_description_set_weight(temp_descr, PANGO_WEIGHT_HEAVY);
+ break;
+
+ case SP_CSS_FONT_WEIGHT_LIGHTER:
+ case SP_CSS_FONT_WEIGHT_BOLDER:
+ default:
+ g_warning("FaceFromStyle: Unrecognized font_weight.computed value");
+ pango_font_description_set_weight(temp_descr, PANGO_WEIGHT_NORMAL);
+ break;
}
+ // PANGO_WIEGHT_ULTRAHEAVY not used (not CSS2)
+
+ switch (style->font_stretch.computed) {
+ case SP_CSS_FONT_STRETCH_ULTRA_CONDENSED:
+ pango_font_description_set_stretch(temp_descr, PANGO_STRETCH_ULTRA_CONDENSED);
+ break;
+
+ case SP_CSS_FONT_STRETCH_EXTRA_CONDENSED:
+ pango_font_description_set_stretch(temp_descr, PANGO_STRETCH_EXTRA_CONDENSED);
+ break;
+
+ case SP_CSS_FONT_STRETCH_CONDENSED:
+ pango_font_description_set_stretch(temp_descr, PANGO_STRETCH_CONDENSED);
+ break;
+
+ case SP_CSS_FONT_STRETCH_SEMI_CONDENSED:
+ pango_font_description_set_stretch(temp_descr, PANGO_STRETCH_SEMI_CONDENSED);
+ break;
+
+ case SP_CSS_FONT_STRETCH_NORMAL:
+ pango_font_description_set_stretch(temp_descr, PANGO_STRETCH_NORMAL);
+ break;
+
+ case SP_CSS_FONT_STRETCH_SEMI_EXPANDED:
+ pango_font_description_set_stretch(temp_descr, PANGO_STRETCH_SEMI_EXPANDED);
+ break;
+
+ case SP_CSS_FONT_STRETCH_EXPANDED:
+ pango_font_description_set_stretch(temp_descr, PANGO_STRETCH_EXPANDED);
+ break;
+
+ case SP_CSS_FONT_STRETCH_EXTRA_EXPANDED:
+ pango_font_description_set_stretch(temp_descr, PANGO_STRETCH_EXTRA_EXPANDED);
+ break;
+
+ case SP_CSS_FONT_STRETCH_ULTRA_EXPANDED:
+ pango_font_description_set_stretch(temp_descr, PANGO_STRETCH_ULTRA_EXPANDED);
+
+ case SP_CSS_FONT_STRETCH_WIDER:
+ case SP_CSS_FONT_STRETCH_NARROWER:
+ default:
+ g_warning("FaceFromStyle: Unrecognized font_stretch.computed value");
+ pango_font_description_set_stretch(temp_descr, PANGO_STRETCH_NORMAL);
+ break;
+ }
+
+ switch ( style->font_variant.computed ) {
+ case SP_CSS_FONT_VARIANT_SMALL_CAPS:
+ pango_font_description_set_variant(temp_descr, PANGO_VARIANT_SMALL_CAPS);
+ break;
+
+ case SP_CSS_FONT_VARIANT_NORMAL:
+ default:
+ pango_font_description_set_variant(temp_descr, PANGO_VARIANT_NORMAL);
+ break;
+ }
+
+ font = Face(temp_descr);
+ pango_font_description_free(temp_descr);
}
}
@@ -736,37 +552,6 @@ font_instance *font_factory::FaceFromDescr(char const *family, char const *style
return res;
}
-font_instance* font_factory::FaceFromUIStrings(char const *uiFamily, char const *uiStyle)
-{
- font_instance *fontInstance = NULL;
-
- g_assert(uiFamily && uiStyle);
- if (uiFamily && uiStyle) {
-
- // If font list, take only first font in list
- gchar** tokens = g_strsplit( uiFamily, ",", 0 );
- g_strstrip( tokens[0] );
-
- Glib::ustring uiString = Glib::ustring(tokens[0]) + Glib::ustring(uiStyle);
-
- g_strfreev( tokens );
-
- UIStringToPangoStringMap::iterator uiToPangoIter = fontStringMap.find(uiString);
-
- if (uiToPangoIter != fontStringMap.end ()) {
- PangoStringToDescrMap::iterator pangoToDescrIter = fontInstanceMap.find((*uiToPangoIter).second);
- if (pangoToDescrIter != fontInstanceMap.end()) {
- // We found the pango description - now we can make a font_instance
- PangoFontDescription *tempDescr = pango_font_description_copy((*pangoToDescrIter).second);
- fontInstance = Face(tempDescr);
- pango_font_description_free(tempDescr);
- }
- }
- }
-
- return fontInstance;
-}
-
font_instance* font_factory::FaceFromPangoString(char const *pangoString)
{
font_instance *fontInstance = NULL;
@@ -774,25 +559,15 @@ font_instance* font_factory::FaceFromPangoString(char const *pangoString)
g_assert(pangoString);
if (pangoString) {
- PangoFontDescription *descr = NULL;
- // First attempt to find the font specification in the reference map
- PangoStringToDescrMap::iterator it = fontInstanceMap.find(Glib::ustring(pangoString));
- if (it != fontInstanceMap.end()) {
- descr = pango_font_description_copy((*it).second);
- }
-
- // Or create a font description from the string - this may fail or
+ // Create a font description from the string - this may fail or
// produce unexpected results if the string does not have a good format
- if (!descr) {
- descr = pango_font_description_from_string(pangoString);
- }
-
- if (descr && (sp_font_description_get_family(descr) != NULL)) {
- fontInstance = Face(descr);
- }
+ PangoFontDescription *descr = pango_font_description_from_string(pangoString);
if (descr) {
+ if (sp_font_description_get_family(descr) != NULL) {
+ fontInstance = Face(descr);
+ }
pango_font_description_free(descr);
}
}
@@ -907,70 +682,6 @@ font_instance *font_factory::Face(char const *family, int variant, int style, in
return res;
}
-font_instance *font_factory::Face(char const *family, NRTypePosDef apos)
-{
- PangoFontDescription *temp_descr = pango_font_description_new();
-
- pango_font_description_set_family(temp_descr, family);
-
- if ( apos.variant == NR_POS_VARIANT_SMALLCAPS ) {
- pango_font_description_set_variant(temp_descr, PANGO_VARIANT_SMALL_CAPS);
- } else {
- pango_font_description_set_variant(temp_descr, PANGO_VARIANT_NORMAL);
- }
-
- if ( apos.italic ) {
- pango_font_description_set_style(temp_descr, PANGO_STYLE_ITALIC);
- } else if ( apos.oblique ) {
- pango_font_description_set_style(temp_descr, PANGO_STYLE_OBLIQUE);
- } else {
- pango_font_description_set_style(temp_descr, PANGO_STYLE_NORMAL);
- }
-
- if ( apos.weight <= NR_POS_WEIGHT_THIN ) {
- pango_font_description_set_weight(temp_descr, PANGO_WEIGHT_THIN);
- } else if ( apos.weight <= NR_POS_WEIGHT_ULTRA_LIGHT ) {
- pango_font_description_set_weight(temp_descr, PANGO_WEIGHT_ULTRALIGHT);
- } else if ( apos.weight <= NR_POS_WEIGHT_LIGHT ) {
- pango_font_description_set_weight(temp_descr, PANGO_WEIGHT_LIGHT);
- } else if ( apos.weight <= NR_POS_WEIGHT_BOOK ) {
- pango_font_description_set_weight(temp_descr, PANGO_WEIGHT_BOOK);
- } else if ( apos.weight <= NR_POS_WEIGHT_NORMAL ) {
- pango_font_description_set_weight(temp_descr, PANGO_WEIGHT_NORMAL);
- } else if ( apos.weight <= NR_POS_WEIGHT_MEDIUM ) {
- pango_font_description_set_weight(temp_descr, PANGO_WEIGHT_MEDIUM);
- } else if ( apos.weight <= NR_POS_WEIGHT_SEMIBOLD ) {
- pango_font_description_set_weight(temp_descr, PANGO_WEIGHT_SEMIBOLD);
- } else if ( apos.weight <= NR_POS_WEIGHT_BOLD ) {
- pango_font_description_set_weight(temp_descr, PANGO_WEIGHT_BOLD);
- } else if ( apos.weight <= NR_POS_WEIGHT_ULTRA_BOLD ) {
- pango_font_description_set_weight(temp_descr, PANGO_WEIGHT_ULTRABOLD);
- } else {
- pango_font_description_set_weight(temp_descr, PANGO_WEIGHT_HEAVY);
- }
- // PANGO_WIEGHT_ULTRAHEAVY not used (not CSS2)
-
- if ( apos.stretch <= NR_POS_STRETCH_ULTRA_CONDENSED ) {
- pango_font_description_set_stretch(temp_descr, PANGO_STRETCH_EXTRA_CONDENSED);
- } else if ( apos.stretch <= NR_POS_STRETCH_CONDENSED ) {
- pango_font_description_set_stretch(temp_descr, PANGO_STRETCH_CONDENSED);
- } else if ( apos.stretch <= NR_POS_STRETCH_SEMI_CONDENSED ) {
- pango_font_description_set_stretch(temp_descr, PANGO_STRETCH_SEMI_CONDENSED);
- } else if ( apos.stretch <= NR_POS_STRETCH_NORMAL ) {
- pango_font_description_set_stretch(temp_descr, PANGO_STRETCH_NORMAL);
- } else if ( apos.stretch <= NR_POS_STRETCH_SEMI_EXPANDED ) {
- pango_font_description_set_stretch(temp_descr, PANGO_STRETCH_SEMI_EXPANDED);
- } else if ( apos.stretch <= NR_POS_STRETCH_EXPANDED ) {
- pango_font_description_set_stretch(temp_descr, PANGO_STRETCH_EXPANDED);
- } else {
- pango_font_description_set_stretch(temp_descr, PANGO_STRETCH_EXTRA_EXPANDED);
- }
-
- font_instance *res = Face(temp_descr);
- pango_font_description_free(temp_descr);
- return res;
-}
-
void font_factory::UnrefFace(font_instance *who)
{
if ( who ) {
@@ -1022,24 +733,6 @@ void font_factory::AddInCache(font_instance *who)
}
/*
- {
- std::cout << " Printing out fontInstanceMap: " << std::endl;
- PangoStringToDescrMap::iterator it = fontInstanceMap.begin();
- while (it != fontInstanceMap.end()) {
-
- PangoFontDescription *descr = pango_font_description_copy((*it).second);
-
- // Grab the UI Family string from the descr
- Glib::ustring uiFamily = GetUIFamilyString(descr);
- Glib::ustring uiStyle = GetUIStyleString(descr);
- std::cout << " " << uiFamily << " " << uiStyle << std::endl;
-
- it++;
- }
- }
-*/
-
-/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
diff --git a/src/libnrtype/FontFactory.h b/src/libnrtype/FontFactory.h
index c48ae831a..46df0181a 100644
--- a/src/libnrtype/FontFactory.h
+++ b/src/libnrtype/FontFactory.h
@@ -21,9 +21,7 @@
#include <pango/pango.h>
#include "nr-type-primitives.h"
-#include "nr-type-pos-def.h"
-#include "font-style-to-pos.h"
-#include "style.h"
+#include "../style.h"
/* Freetype */
#ifdef USE_PANGO_WIN32
@@ -114,18 +112,6 @@ public:
Glib::ustring GetUIFamilyString(PangoFontDescription const *fontDescr);
Glib::ustring GetUIStyleString(PangoFontDescription const *fontDescr);
- /// Modifiers for the font specification (returns new font specification)
- Glib::ustring ReplaceFontSpecificationFamily(const Glib::ustring & fontSpec, const Glib::ustring & newFamily);
- Glib::ustring FontSpecificationSetItalic(const Glib::ustring & fontSpec, bool turnOn);
- Glib::ustring FontSpecificationSetBold(const Glib::ustring & fontSpec, bool turnOn);
-
- Glib::ustring FontSpecificationBestMatch(const Glib::ustring& fontSpec );
-
- // Gathers all strings needed for UI while storing pango information in
- // fontInstanceMap and fontStringMap
- // don't use this function, it's too slow
- void GetUIFamiliesAndStyles(FamilyToStylesMap *map);
-
// Helpfully inserts all font families into the provided vector
void GetUIFamilies(std::vector<PangoFontFamily *>& out);
// Retrieves style information about a family in a newly allocated GList.
@@ -144,7 +130,6 @@ public:
int variant=PANGO_VARIANT_NORMAL, int style=PANGO_STYLE_NORMAL,
int weight=PANGO_WEIGHT_NORMAL, int stretch=PANGO_STRETCH_NORMAL,
int size=10, int spacing=0);
- font_instance* Face(char const *family, NRTypePosDef apos);
/// Semi-private: tells the font_factory taht the font_instance 'who' has died and should be removed from loadedFaces
void UnrefFace(font_instance* who);
@@ -155,19 +140,37 @@ public:
private:
void* loadedPtr;
+
+ // The following two commented out maps were an attempt to allow Inkscape to use font faces
+ // that could not be distinguished by CSS values alone. In practice, they never were that
+ // useful as PangoFontDescription, which is used throughout our code, cannot distinguish
+ // between faces anymore than raw CSS values (with the exception of two additional weight
+ // values).
+ //
+ // During various works, for example to handle font-family lists and fonts that are not
+ // installed on the system, the code has become less reliant on these maps. And in the work to
+ // catch style information to speed up start up times, the maps were not being filled.
+ // I've removed all code that used these maps as of Oct 2014 in the experimental branch.
+ // The commented out maps are left here as a reminder of the path that was attempted.
+ //
+ // One possible method to keep track of font faces would be to use the 'display name', keeping
+ // pointers to the appropriate PangoFontFace. The font_factory loadedFaces map indexing would
+ // have to be changed to incorporate 'display name' (InkscapeFontDescription?).
+
+
// These two maps are used for translating between what's in the UI and a pango
// font description. This is necessary because Pango cannot always
// reproduce these structures from the names it gave us in the first place.
// Key: A string produced by font_factory::ConstructFontSpecification
// Value: The associated PangoFontDescription
- typedef std::map<Glib::ustring, PangoFontDescription *> PangoStringToDescrMap;
- PangoStringToDescrMap fontInstanceMap;
+ // typedef std::map<Glib::ustring, PangoFontDescription *> PangoStringToDescrMap;
+ // PangoStringToDescrMap fontInstanceMap;
// Key: Family name in UI + Style name in UI
// Value: The associated string that should be produced with font_factory::ConstructFontSpecification
- typedef std::map<Glib::ustring, Glib::ustring> UIStringToPangoStringMap;
- UIStringToPangoStringMap fontStringMap;
+ // typedef std::map<Glib::ustring, Glib::ustring> UIStringToPangoStringMap;
+ // UIStringToPangoStringMap fontStringMap;
};
diff --git a/src/libnrtype/FontInstance.cpp b/src/libnrtype/FontInstance.cpp
index 20eca6740..a5572c517 100644
--- a/src/libnrtype/FontInstance.cpp
+++ b/src/libnrtype/FontInstance.cpp
@@ -239,151 +239,6 @@ void font_instance::Unref(void)
}
}
-unsigned int font_instance::Name(gchar *str, unsigned int size)
-{
- return Attribute("name", str, size);
-}
-
-unsigned int font_instance::Family(gchar *str, unsigned int size)
-{
- return Attribute("family", str, size);
-}
-
-unsigned int font_instance::PSName(gchar *str, unsigned int size)
-{
- return Attribute("psname", str, size);
-}
-
-unsigned int font_instance::Attribute(const gchar *key, gchar *str, unsigned int size)
-{
- if ( descr == NULL ) {
- if ( size > 0 ) {
- str[0]=0;
- }
- return 0;
- }
- char* res=NULL;
- bool free_res=false;
-
- if ( strcmp(key,"name") == 0 ) {
- PangoFontDescription* td=pango_font_description_copy(descr);
- pango_font_description_unset_fields (td, PANGO_FONT_MASK_SIZE);
- res=pango_font_description_to_string (td);
- pango_font_description_free(td);
- free_res=true;
- } else if ( strcmp(key,"psname") == 0 ) {
-#ifndef USE_PANGO_WIN32
- res = (char *) FT_Get_Postscript_Name (theFace); // that's the main method, seems to always work
-#endif
- free_res=false;
- if (res == NULL) { // a very limited workaround, only bold, italic, and oblique will work
- PangoStyle style=pango_font_description_get_style(descr);
- bool i = (style == PANGO_STYLE_ITALIC);
- bool o = (style == PANGO_STYLE_OBLIQUE);
- PangoWeight weight=pango_font_description_get_weight(descr);
- bool b = (weight >= PANGO_WEIGHT_BOLD);
-
- res = g_strdup_printf ("%s%s%s%s",
- sp_font_description_get_family(descr),
- (b || i || o) ? "-" : "",
- (b) ? "Bold" : "",
- (i) ? "Italic" : ((o) ? "Oblique" : "") );
- free_res = true;
- }
- } else if ( strcmp(key,"family") == 0 ) {
- res=(char*)sp_font_description_get_family(descr);
- free_res=false;
- } else if ( strcmp(key,"style") == 0 ) {
- PangoStyle v=pango_font_description_get_style(descr);
- if ( v == PANGO_STYLE_ITALIC ) {
- res=(char*)"italic";
- } else if ( v == PANGO_STYLE_OBLIQUE ) {
- res=(char*)"oblique";
- } else {
- res=(char*)"normal";
- }
- free_res=false;
- } else if ( strcmp(key,"weight") == 0 ) {
- PangoWeight v=pango_font_description_get_weight(descr);
- if ( v <= PANGO_WEIGHT_THIN ) {
- res=(char*)"100";
- } else if ( v <= PANGO_WEIGHT_ULTRALIGHT ) {
- res=(char*)"200";
- } else if ( v <= PANGO_WEIGHT_LIGHT ) {
- res=(char*)"300";
- } else if ( v <= PANGO_WEIGHT_BOOK ) {
- res=(char*)"380";
- } else if ( v <= PANGO_WEIGHT_NORMAL ) {
- res=(char*)"normal";
- } else if ( v <= PANGO_WEIGHT_MEDIUM ) {
- res=(char*)"500";
- } else if ( v <= PANGO_WEIGHT_SEMIBOLD ) {
- res=(char*)"600";
- } else if ( v <= PANGO_WEIGHT_BOLD ) {
- res=(char*)"bold";
- } else if ( v <= PANGO_WEIGHT_ULTRABOLD ) {
- res=(char*)"800";
- } else { // HEAVY NB: Pango defines ULTRAHEAVY = 1000 but not CSS2
- res=(char*)"900";
- }
- free_res=false;
- } else if ( strcmp(key,"stretch") == 0 ) {
- PangoStretch v=pango_font_description_get_stretch(descr);
- if ( v <= PANGO_STRETCH_EXTRA_CONDENSED ) {
- res=(char*)"extra-condensed";
- } else if ( v <= PANGO_STRETCH_CONDENSED ) {
- res=(char*)"condensed";
- } else if ( v <= PANGO_STRETCH_SEMI_CONDENSED ) {
- res=(char*)"semi-condensed";
- } else if ( v <= PANGO_STRETCH_NORMAL ) {
- res=(char*)"normal";
- } else if ( v <= PANGO_STRETCH_SEMI_EXPANDED ) {
- res=(char*)"semi-expanded";
- } else if ( v <= PANGO_STRETCH_EXPANDED ) {
- res=(char*)"expanded";
- } else {
- res=(char*)"extra-expanded";
- }
- free_res=false;
- } else if ( strcmp(key,"variant") == 0 ) {
- PangoVariant v=pango_font_description_get_variant(descr);
- if ( v == PANGO_VARIANT_SMALL_CAPS ) {
- res=(char*)"small-caps";
- } else {
- res=(char*)"normal";
- }
- free_res=false;
- } else {
- res = NULL;
- free_res=false;
- }
- if ( res == NULL ) {
- if ( size > 0 ) {
- str[0] = 0;
- }
- return 0;
- }
-
- if (res) {
- unsigned int len=strlen(res);
- unsigned int rlen=(size-1<len)?size-1:len;
- if ( str ) {
- if ( rlen > 0 ) {
- memcpy(str, res, rlen);
- }
- if ( size > 0 ) {
- str[rlen] = 0;
- }
- }
- if (free_res) {
- g_free(res);
- res = 0;
- }
- return len;
- }
- return 0;
-}
-
void font_instance::InitTheFace()
{
if (theFace == NULL && pFont != NULL) {
diff --git a/src/libnrtype/Layout-TNG-Output.cpp b/src/libnrtype/Layout-TNG-Output.cpp
index 77534e706..61a141cc3 100644
--- a/src/libnrtype/Layout-TNG-Output.cpp
+++ b/src/libnrtype/Layout-TNG-Output.cpp
@@ -511,6 +511,9 @@ static char const *weight_to_text(PangoWeight w)
case PANGO_WEIGHT_THIN : return "thin";
case PANGO_WEIGHT_ULTRALIGHT: return "ultralight";
case PANGO_WEIGHT_LIGHT : return "light";
+#if PANGO_VERSION_CHECK(1,36,6)
+ case PANGO_WEIGHT_SEMILIGHT : return "semilight";
+#endif
case PANGO_WEIGHT_BOOK : return "book";
case PANGO_WEIGHT_NORMAL : return "normalweight";
case PANGO_WEIGHT_MEDIUM : return "medium";
diff --git a/src/libnrtype/Makefile_insert b/src/libnrtype/Makefile_insert
index 0ce8f1fd5..ab9465daa 100644
--- a/src/libnrtype/Makefile_insert
+++ b/src/libnrtype/Makefile_insert
@@ -2,13 +2,9 @@
ink_common_sources += \
libnrtype/boundary-type.h \
- libnrtype/font-style-to-pos.cpp \
- libnrtype/font-style-to-pos.h \
libnrtype/font-glyph.h \
libnrtype/font-instance.h \
libnrtype/font-style.h \
- libnrtype/nr-type-pos-def.cpp \
- libnrtype/nr-type-pos-def.h \
libnrtype/nr-type-primitives.cpp \
libnrtype/nr-type-primitives.h \
libnrtype/FontFactory.cpp \
diff --git a/src/libnrtype/font-instance.h b/src/libnrtype/font-instance.h
index 75106617b..2c7d1ce46 100644
--- a/src/libnrtype/font-instance.h
+++ b/src/libnrtype/font-instance.h
@@ -65,12 +65,6 @@ public:
// for generating slanted cursors for oblique fonts
Geom::OptRect BBox(int glyph_id);
- // attribute queries
- unsigned Name(gchar *str, unsigned size);
- unsigned PSName(gchar *str, unsigned size);
- unsigned Family(gchar *str, unsigned size);
- unsigned Attribute(gchar const *key, gchar *str, unsigned size);
-
private:
void FreeTheFace();
diff --git a/src/libnrtype/font-lister.cpp b/src/libnrtype/font-lister.cpp
index 6f25ab5f9..fad06cd00 100644
--- a/src/libnrtype/font-lister.cpp
+++ b/src/libnrtype/font-lister.cpp
@@ -648,6 +648,11 @@ void FontLister::fill_css(SPCSSAttr *css, Glib::ustring fontspec)
case PANGO_WEIGHT_LIGHT:
sp_repr_css_set_property(css, "font-weight", "300");
break;
+#if PANGO_VERSION_CHECK(1,36,6)
+ case PANGO_WEIGHT_SEMILIGHT:
+ sp_repr_css_set_property(css, "font-weight", "350");
+ break;
+#endif
case PANGO_WEIGHT_BOOK:
sp_repr_css_set_property(css, "font-weight", "380");
break;
@@ -814,7 +819,7 @@ Glib::ustring FontLister::fontspec_from_style(SPStyle *style)
switch (style->font_stretch.computed) {
case SP_CSS_FONT_STRETCH_ULTRA_CONDENSED:
- fontspec += " extra-condensed";
+ fontspec += " ultra-condensed";
break;
case SP_CSS_FONT_STRETCH_EXTRA_CONDENSED:
@@ -1004,7 +1009,7 @@ Glib::ustring FontLister::get_best_style_match(Glib::ustring family, Glib::ustri
}
GList *styles = row[FontList.styles];
for (GList *l = styles; l; l = l->next) {
- Glib::ustring fontspec = family + ", " + (char *)l->data;
+ Glib::ustring fontspec = family + ", " + ((StyleNames *)l->data)->CssName;
PangoFontDescription *candidate = pango_font_description_from_string(fontspec.c_str());
//font_description_dump( candidate );
//std::cout << " " << font_description_better_match( target, best, candidate ) << std::endl;
diff --git a/src/libnrtype/font-style-to-pos.cpp b/src/libnrtype/font-style-to-pos.cpp
deleted file mode 100644
index 02f5ef37c..000000000
--- a/src/libnrtype/font-style-to-pos.cpp
+++ /dev/null
@@ -1,120 +0,0 @@
-#include "font-style-to-pos.h"
-#include <style.h>
-
-/* 'lighter' and 'darker' have to be resolved earlier */
-/**
-Given a style struct (CSS representation), sets the corresponding fields in a NRTypePosDef.
- */
-NRTypePosDef
-font_style_to_pos (SPStyle const &style)
-{
- NRTypePosDef ret;
-
- switch (style.font_weight.computed) {
- case SP_CSS_FONT_WEIGHT_100:
- ret.weight = NR_POS_WEIGHT_CSS100;
- break;
-
- case SP_CSS_FONT_WEIGHT_200:
- ret.weight = NR_POS_WEIGHT_CSS200;
- break;
-
- case SP_CSS_FONT_WEIGHT_300:
- ret.weight = NR_POS_WEIGHT_CSS300;
- break;
-
- case SP_CSS_FONT_WEIGHT_400:
- case SP_CSS_FONT_WEIGHT_NORMAL:
- ret.weight = NR_POS_WEIGHT_CSS400;
- break;
-
- case SP_CSS_FONT_WEIGHT_500:
- ret.weight = NR_POS_WEIGHT_CSS500;
- break;
-
- case SP_CSS_FONT_WEIGHT_600:
- ret.weight = NR_POS_WEIGHT_CSS600;
- break;
-
- case SP_CSS_FONT_WEIGHT_700:
- case SP_CSS_FONT_WEIGHT_BOLD:
- ret.weight = NR_POS_WEIGHT_CSS700;
- break;
-
- case SP_CSS_FONT_WEIGHT_800:
- ret.weight = NR_POS_WEIGHT_CSS800;
- break;
-
- case SP_CSS_FONT_WEIGHT_900:
- ret.weight = NR_POS_WEIGHT_CSS900;
- break;
-
- case SP_CSS_FONT_WEIGHT_LIGHTER:
- case SP_CSS_FONT_WEIGHT_BOLDER:
- default:
- g_warning("Unrecognized font_weight.computed value");
- ret.weight = NR_POS_WEIGHT_NORMAL;
- break;
- }
-
- switch (style.font_style.computed) {
- case SP_CSS_FONT_STYLE_ITALIC:
- ret.italic = 1;
- break;
-
- case SP_CSS_FONT_STYLE_OBLIQUE:
- ret.oblique = 1;
- break;
-
- case SP_CSS_FONT_STYLE_NORMAL:
- default:
- ret.italic = 0;
- ret.oblique = 0;
- break;
- }
-
- switch (style.font_stretch.computed) {
- case SP_CSS_FONT_STRETCH_ULTRA_CONDENSED:
- case SP_CSS_FONT_STRETCH_EXTRA_CONDENSED:
- ret.stretch = NR_POS_STRETCH_EXTRA_CONDENSED;
- break;
-
- case SP_CSS_FONT_STRETCH_CONDENSED:
- case SP_CSS_FONT_STRETCH_NARROWER:
- ret.stretch = NR_POS_STRETCH_CONDENSED;
- break;
-
- case SP_CSS_FONT_STRETCH_SEMI_CONDENSED:
- ret.stretch = NR_POS_STRETCH_SEMI_CONDENSED;
- break;
-
- case SP_CSS_FONT_STRETCH_SEMI_EXPANDED:
- ret.stretch = NR_POS_STRETCH_SEMI_EXPANDED;
- break;
-
- case SP_CSS_FONT_STRETCH_EXPANDED:
- case SP_CSS_FONT_STRETCH_WIDER:
- ret.stretch = NR_POS_STRETCH_EXPANDED;
- break;
-
- case SP_CSS_FONT_STRETCH_EXTRA_EXPANDED:
- case SP_CSS_FONT_STRETCH_ULTRA_EXPANDED:
- ret.stretch = NR_POS_STRETCH_EXTRA_EXPANDED;
- break;
-
- default:
- ret.stretch = NR_POS_STRETCH_NORMAL;
- break;
- }
-
- switch (style.font_variant.computed) {
- case SP_CSS_FONT_VARIANT_SMALL_CAPS:
- ret.variant = NR_POS_VARIANT_SMALLCAPS;
- break;
- default:
- ret.variant = NR_POS_VARIANT_NORMAL;
- break;
- }
-
- return ret;
-}
diff --git a/src/libnrtype/font-style-to-pos.h b/src/libnrtype/font-style-to-pos.h
deleted file mode 100644
index 41ba6cf72..000000000
--- a/src/libnrtype/font-style-to-pos.h
+++ /dev/null
@@ -1,21 +0,0 @@
-#ifndef SEEN_FONT_STYLE_TO_POS_H
-#define SEEN_FONT_STYLE_TO_POS_H
-
-#include <libnrtype/nr-type-pos-def.h>
-
-class SPStyle;
-
-NRTypePosDef font_style_to_pos(SPStyle const &style);
-
-#endif // SEEN_FONT_STYLE_TO_POS_H
-
-/*
- Local Variables:
- mode:c++
- c-file-style:"stroustrup"
- c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
- indent-tabs-mode:nil
- fill-column:99
- End:
-*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
diff --git a/src/libnrtype/nr-type-pos-def.cpp b/src/libnrtype/nr-type-pos-def.cpp
deleted file mode 100644
index fef04039e..000000000
--- a/src/libnrtype/nr-type-pos-def.cpp
+++ /dev/null
@@ -1,268 +0,0 @@
-#include "nr-type-pos-def.h"
-#include <glib.h>
-#include <string.h>
-
-/**
- * Given a font name or style name, returns a constant describing its
- * apparent style (normal/italic/oblique).
-*/
-int
-parse_name_for_style (char const *cc)
-{
- g_assert ( cc != NULL );
- gchar *c = g_ascii_strdown (cc, -1);
-
- gint style;
- // first dab at i18n... french and german
- if (strstr (c, "italic") || strstr (c, "italique") || strstr (c, "kursiv")) {
- style = NR_POS_STYLE_ITALIC;
- } else if (strstr (c, "oblique")) {
- style = NR_POS_STYLE_OBLIQUE;
- } else {
- style = NR_POS_STYLE_NORMAL;
- }
-
- g_free (c);
- return style;
-}
-
-
-/**
- * Given a font name or style name, returns a constant describing its
- * apparent weight.
-*/
-int
-parse_name_for_weight (char const *cc)
-{
- g_assert ( cc != NULL );
- gchar *c = g_ascii_strdown (cc, -1);
-
- gint weight;
- if (strstr (c, "thin")) {
- weight = NR_POS_WEIGHT_THIN;
- } else if (strstr (c, "extra light")) {
- weight = NR_POS_WEIGHT_EXTRA_LIGHT;
- } else if (strstr (c, "ultra light")) {
- weight = NR_POS_WEIGHT_ULTRA_LIGHT;
- } else if (strstr (c, "light")) {
- weight = NR_POS_WEIGHT_LIGHT;
- } else if (strstr (c, "book")) {
- weight = NR_POS_WEIGHT_BOOK;
- } else if (strstr (c, "medium")) {
- weight = NR_POS_WEIGHT_MEDIUM;
- } else if (strstr (c, "semi bold")) {
- weight = NR_POS_WEIGHT_SEMIBOLD;
- } else if (strstr (c, "semibold")) {
- weight = NR_POS_WEIGHT_SEMIBOLD;
- } else if (strstr (c, "demi bold")) {
- weight = NR_POS_WEIGHT_DEMIBOLD;
- } else if (strstr (c, "demibold") || strstr (c, "demi")) {
- weight = NR_POS_WEIGHT_DEMIBOLD;
- } else if (strstr (c, "ultra bold")) {
- weight = NR_POS_WEIGHT_ULTRA_BOLD;
- } else if (strstr (c, "extra bold") || strstr (c, "xbold") || strstr (c, "xtrabold")) {
- weight = NR_POS_WEIGHT_EXTRA_BOLD;
- } else if (strstr (c, "black") || strstr (c, "heavy")) {
- weight = NR_POS_WEIGHT_BLACK;
- } else if (strstr (c, "bold")) {
- /* Must come after the checks for `blah bold'. */
- weight = NR_POS_WEIGHT_BOLD;
- } else {
- weight = NR_POS_WEIGHT_NORMAL;
- }
-
- g_free (c);
- return weight;
-}
-
-/**
- * Given a font name or style name, returns a constant describing its
- * apparent stretch.
-*/
-int
-parse_name_for_stretch (char const *cc)
-{
- g_assert ( cc != NULL );
- gchar *c = g_ascii_strdown (cc, -1);
-
- gint stretch;
- if (strstr (c, "ultra narrow") || strstr (c, "ultra condensed") || strstr (c, "extra condensed")) {
- stretch = NR_POS_STRETCH_EXTRA_CONDENSED;
- } else if (strstr (c, "ultra wide") || strstr (c, "ultra expanded") || strstr (c, "ultra extended") || strstr (c, "extra expanded")) {
- stretch = NR_POS_STRETCH_EXTRA_EXPANDED;
- } else if (strstr (c, "semi condensed") || strstr (c, "semicondensed")) {
- stretch = NR_POS_STRETCH_SEMI_CONDENSED;
- } else if (strstr (c, "semi extended") || strstr (c, "semiextended")) {
- stretch = NR_POS_STRETCH_SEMI_EXPANDED;
- } else if (strstr (c, "narrow") || strstr (c, "condensed")) {
- stretch = NR_POS_STRETCH_CONDENSED;
- } else if (strstr (c, "wide") || strstr (c, "expanded") || strstr (c, "extended")) {
- stretch = NR_POS_STRETCH_EXPANDED;
- } else {
- stretch = NR_POS_STRETCH_NORMAL;
- }
-
- g_free (c);
- return stretch;
-}
-
-/**
- * Given a font name or style name, returns a constant describing its
- * apparent variant (normal/smallcaps).
-*/
-int
-parse_name_for_variant (char const *cc)
-{
- g_assert ( cc != NULL );
- gchar *c = g_ascii_strdown (cc, -1);
-
- gint variant;
- if (strstr (c, "small caps") || strstr (c, "smallcaps") || strstr (c, "caps")) {
- variant = NR_POS_VARIANT_SMALLCAPS;
- } else {
- variant = NR_POS_VARIANT_NORMAL;
- }
-
- g_free (c);
- return variant;
-}
-
-/**
- * Given a style constant, returns the CSS value for font-style.
-*/
-const char *
-style_to_css (int style)
-{
- switch (style) {
- case NR_POS_STYLE_NORMAL:
- return "normal";
- break;
- case NR_POS_STYLE_ITALIC:
- return "italic";
- break;
- case NR_POS_STYLE_OBLIQUE:
- return "oblique";
- break;
- default:
- break;
- }
- return NULL;
-}
-
-
-/**
- * Given a weight constant, returns the CSS value for font-weight.
-*/
-const char *
-weight_to_css (int weight)
-{
- switch (weight) {
- case NR_POS_WEIGHT_THIN:
- return "100";
- break;
- case NR_POS_WEIGHT_EXTRA_LIGHT:
- return "200";
- break;
- case NR_POS_WEIGHT_LIGHT:
- return "300";
- break;
- case NR_POS_WEIGHT_BOOK:
- return "normal";
- break;
- case NR_POS_WEIGHT_MEDIUM:
- return "500";
- break;
- case NR_POS_WEIGHT_SEMIBOLD:
- return "600";
- break;
- case NR_POS_WEIGHT_BOLD:
- return "bold";
- break;
- case NR_POS_WEIGHT_EXTRA_BOLD:
- return "800";
- break;
- case NR_POS_WEIGHT_BLACK:
- return "900";
- break;
- default:
- break;
- }
- return NULL;
-}
-
-/**
- * Given a stretch constant, returns the CSS value for font-stretch.
-*/
-const char *
-stretch_to_css (int stretch)
-{
- switch (stretch) {
- case NR_POS_STRETCH_EXTRA_CONDENSED:
- return "extra-condensed";
- break;
- case NR_POS_STRETCH_CONDENSED:
- return "condensed";
- break;
- case NR_POS_STRETCH_SEMI_CONDENSED:
- return "semi-condensed";
- break;
- case NR_POS_STRETCH_NORMAL:
- return "normal";
- break;
- case NR_POS_STRETCH_SEMI_EXPANDED:
- return "semi-expanded";
- break;
- case NR_POS_STRETCH_EXPANDED:
- return "expanded";
- break;
- case NR_POS_STRETCH_EXTRA_EXPANDED:
- return "extra-expanded";
- break;
- default:
- break;
- }
- return NULL;
-}
-
-/**
- * Given a variant constant, returns the CSS value for font-variant.
-*/
-const char *
-variant_to_css (int stretch)
-{
- switch (stretch) {
- case NR_POS_VARIANT_SMALLCAPS:
- return "small-caps";
- break;
- case NR_POS_VARIANT_NORMAL:
- return "normal";
- break;
- default:
- break;
- }
- return NULL;
-}
-
-
-/**
- * Constructor for NRTypePostDef. Sets the italic, oblique, weight,
- * stretch, and variant.
- */
-NRTypePosDef::NRTypePosDef(char const *description) {
- // we cannot use strcasestr, it's linux only... so we must lowercase the string first
- g_assert ( description != NULL );
- gchar *c = g_ascii_strdown (description, -1);
-
- /* copied from nr-type-directory.cpp:nr_type_calculate_position. */
-
- italic = (strstr (c, "italic") != NULL);
- oblique = (strstr (c, "oblique") != NULL);
-
- weight = parse_name_for_weight (c);
-
- stretch = parse_name_for_stretch (c);
-
- variant = parse_name_for_variant (c);
-
- g_free (c);
-}
diff --git a/src/libnrtype/nr-type-pos-def.h b/src/libnrtype/nr-type-pos-def.h
deleted file mode 100644
index ab9f5b45c..000000000
--- a/src/libnrtype/nr-type-pos-def.h
+++ /dev/null
@@ -1,102 +0,0 @@
-#ifndef __NR_TYPE_POS_DEF_H__
-#define __NR_TYPE_POS_DEF_H__
-
-#define NR_POS_STYLE_NORMAL 0
-#define NR_POS_STYLE_ITALIC 1
-#define NR_POS_STYLE_OBLIQUE 2
-
-#define NR_POS_WEIGHT_THIN 32
-#define NR_POS_WEIGHT_EXTRA_LIGHT 64
-#define NR_POS_WEIGHT_ULTRA_LIGHT 64
-#define NR_POS_WEIGHT_LIGHT 96
-#define NR_POS_WEIGHT_BOOK 128
-#define NR_POS_WEIGHT_NORMAL 128
-#define NR_POS_WEIGHT_MEDIUM 144
-#define NR_POS_WEIGHT_SEMIBOLD 160
-#define NR_POS_WEIGHT_DEMIBOLD 160
-#define NR_POS_WEIGHT_BOLD 192
-#define NR_POS_WEIGHT_ULTRA_BOLD 224
-#define NR_POS_WEIGHT_EXTRA_BOLD 224
-#define NR_POS_WEIGHT_BLACK 255
-
-#define NR_POS_STRETCH_ULTRA_CONDENSED 48
-#define NR_POS_STRETCH_EXTRA_CONDENSED 48
-#define NR_POS_STRETCH_CONDENSED 88
-#define NR_POS_STRETCH_SEMI_CONDENSED 108
-#define NR_POS_STRETCH_NORMAL 128
-#define NR_POS_STRETCH_SEMI_EXPANDED 148
-#define NR_POS_STRETCH_EXPANDED 168
-#define NR_POS_STRETCH_EXTRA_EXPANDED 228
-#define NR_POS_STRETCH_ULTRA_EXPANDED 228
-
-// This is an enumerate, rather than on/off property,
-// for I sincerely hope the vocabulary of this property will be
-// extended by the W3C in the future to allow for more fancy fonts
-#define NR_POS_VARIANT_NORMAL 0
-#define NR_POS_VARIANT_SMALLCAPS 1
-
-/* Mapping from CSS weight numbers.
-
- for i in `seq 9`; do
- if [ $i -le 4 ]; then w=$((32 * $i));
- elif [ $i = 5 ]; then w=144;
- elif [ $i -lt 9 ]; then w=$((32 * $(($i - 1))));
- else w=255;
- fi;
- printf '#define NR_POS_WEIGHT_CSS%d00\t\t%3d\n' $i $w;
- done
-
- This calculation approximately matches the old to-and-from-text code,
- I don't claim it to be reasonable. ("approximately": some of the old
- code wrote strings like "semi" and "heavy" that weren't being parsed
- at the other end, and it had CSS100 darker than CSS200.)
- */
-#define NR_POS_WEIGHT_CSS100 32
-#define NR_POS_WEIGHT_CSS200 64
-#define NR_POS_WEIGHT_CSS300 96
-#define NR_POS_WEIGHT_CSS400 128
-#define NR_POS_WEIGHT_CSS500 144
-#define NR_POS_WEIGHT_CSS600 160
-#define NR_POS_WEIGHT_CSS700 192
-#define NR_POS_WEIGHT_CSS800 224
-#define NR_POS_WEIGHT_CSS900 255
-
-
-class NRTypePosDef {
-public:
- unsigned int italic : 1;
- unsigned int oblique : 1;
- unsigned int weight : 8;
- unsigned int stretch : 8;
- unsigned int variant : 8;
- /* These can probably be made sensible sizes rather than bitfields; for the moment we'll
- keep the old definition. */
-
-public:
- NRTypePosDef() :
- italic(0),
- oblique(0),
- weight(NR_POS_WEIGHT_NORMAL),
- stretch(NR_POS_STRETCH_NORMAL),
- variant(NR_POS_VARIANT_NORMAL)
- { }
-
- NRTypePosDef(char const *description);
-
- bool signature() {return this->italic +
- this->oblique * 255 +
- this->weight * 255 * 255 +
- this->stretch * 255 * 255 * 255 +
- this->variant * 255 * 255 * 255 * 255;};
-};
-
-int parse_name_for_style (char const *c);
-int parse_name_for_weight (char const *c);
-int parse_name_for_stretch (char const *c);
-int parse_name_for_variant (char const *c);
-const char *style_to_css (int style);
-const char *weight_to_css (int weight);
-const char *stretch_to_css (int stretch);
-const char *variant_to_css (int variant);
-
-#endif /* __NR_TYPE_POS_DEF_H__ */