diff options
Diffstat (limited to 'src/libnrtype')
| -rw-r--r-- | src/libnrtype/CMakeLists.txt | 4 | ||||
| -rw-r--r-- | src/libnrtype/FontFactory.cpp | 224 | ||||
| -rw-r--r-- | src/libnrtype/FontFactory.h | 3 | ||||
| -rw-r--r-- | src/libnrtype/FontInstance.cpp | 4 | ||||
| -rw-r--r-- | src/libnrtype/Layout-TNG-Output.cpp | 3 | ||||
| -rw-r--r-- | src/libnrtype/Makefile_insert | 4 | ||||
| -rw-r--r-- | src/libnrtype/font-lister.cpp | 9 | ||||
| -rw-r--r-- | src/libnrtype/font-style-to-pos.cpp | 120 | ||||
| -rw-r--r-- | src/libnrtype/font-style-to-pos.h | 21 | ||||
| -rw-r--r-- | src/libnrtype/nr-type-pos-def.cpp | 268 | ||||
| -rw-r--r-- | src/libnrtype/nr-type-pos-def.h | 102 |
11 files changed, 172 insertions, 590 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 6859a4a5c..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; } } @@ -636,9 +668,133 @@ 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; + + 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; + } - // That was a hatchet job... so we need to check if this font exists!! + 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); + + // We now find closest match to this font: Glib::ustring fontSpec = font_factory::Default()->ConstructFontSpecification(font); Glib::ustring newFontSpec = FontSpecificationBestMatch( fontSpec ); if( fontSpec != newFontSpec ) { @@ -831,70 +987,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 ) { diff --git a/src/libnrtype/FontFactory.h b/src/libnrtype/FontFactory.h index 513ee4bf7..bb3a8fa25 100644 --- a/src/libnrtype/FontFactory.h +++ b/src/libnrtype/FontFactory.h @@ -21,8 +21,6 @@ #include <pango/pango.h> #include "nr-type-primitives.h" -#include "nr-type-pos-def.h" -#include "font-style-to-pos.h" #include "../style.h" /* Freetype */ @@ -138,7 +136,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); diff --git a/src/libnrtype/FontInstance.cpp b/src/libnrtype/FontInstance.cpp index 20eca6740..ce4c99ef7 100644 --- a/src/libnrtype/FontInstance.cpp +++ b/src/libnrtype/FontInstance.cpp @@ -311,6 +311,10 @@ unsigned int font_instance::Attribute(const gchar *key, gchar *str, unsigned int res=(char*)"200"; } else if ( v <= PANGO_WEIGHT_LIGHT ) { res=(char*)"300"; +#if PANGO_VERSION_CHECK(1,36,6) + } else if ( v <= PANGO_WEIGHT_SEMILIGHT ) { + res=(char*)"350"; +#endif } else if ( v <= PANGO_WEIGHT_BOOK ) { res=(char*)"380"; } else if ( v <= PANGO_WEIGHT_NORMAL ) { 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-lister.cpp b/src/libnrtype/font-lister.cpp index 43c3045b1..6727cdda6 100644 --- a/src/libnrtype/font-lister.cpp +++ b/src/libnrtype/font-lister.cpp @@ -623,6 +623,11 @@ std::pair<Glib::ustring, Glib::ustring> FontLister::new_font_family (Glib::ustri 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; @@ -791,7 +796,7 @@ std::pair<Glib::ustring, Glib::ustring> FontLister::new_font_family (Glib::ustri 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: @@ -980,7 +985,7 @@ std::pair<Glib::ustring, Glib::ustring> FontLister::new_font_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__ */ |
