From 3400f9ac91627d6344cb4aa461c6513f6922b86a Mon Sep 17 00:00:00 2001 From: JucaBlues Date: Mon, 12 May 2008 00:49:01 +0000 Subject: [PATCH] * implemented handling of font-style, font-variant, font-weight, and font-stretch attributes on font-face tags * fixed typo on v-ideographic attribute on attributes.cpp * fixed typo on src/sp-font-face.h --- src/attributes.cpp | 14 +- src/attributes.h | 12 +- src/sp-font-face.cpp | 347 ++++++++++++++++++++++++++++++++++++++++++- src/sp-font-face.h | 20 +-- 4 files changed, 369 insertions(+), 24 deletions(-) diff --git a/src/attributes.cpp b/src/attributes.cpp index de505236f..cfadab9c6 100644 --- a/src/attributes.cpp +++ b/src/attributes.cpp @@ -333,12 +333,12 @@ static SPStyleProp const props[] = { {SP_ATTR_K, "k"}, /**/ - {SP_ATTR_FONT_FAMILY, "font-family"}, - {SP_ATTR_FONT_STYLE, "font-style"}, - {SP_ATTR_FONT_VARIANT, "font-variant"}, - {SP_ATTR_FONT_WEIGHT, "font-weight"}, - {SP_ATTR_FONT_STRETCH, "font-stretch"}, - {SP_ATTR_FONT_SIZE, "font-size"}, + //{SP_ATTR_FONT_FAMILY, "font-family"}, these are already set for CSS2 (SP_PROP_FONT_FAMILY, SP_PROP_FONT_STYLE, SP_PROP_FONT_VARIANT etc...) + //{SP_ATTR_FONT_STYLE, "font-style"}, + //{SP_ATTR_FONT_VARIANT, "font-variant"}, + //{SP_ATTR_FONT_WEIGHT, "font-weight"}, + //{SP_ATTR_FONT_STRETCH, "font-stretch"}, + //{SP_ATTR_FONT_SIZE, "font-size"}, {SP_ATTR_UNICODE_RANGE, "unicode-range"}, {SP_ATTR_UNITS_PER_EM, "units-per-em"}, {SP_ATTR_PANOSE_1, "panose-1"}, @@ -356,7 +356,7 @@ static SPStyleProp const props[] = { {SP_ATTR_ALPHABETIC, "alphabetic"}, {SP_ATTR_MATHEMATICAL, "mathematical"}, {SP_ATTR_HANGING, "hanging"}, - {SP_ATTR_V_IDEOGRAPHIC, "ideographic"}, + {SP_ATTR_V_IDEOGRAPHIC, "v-ideographic"}, {SP_ATTR_V_ALPHABETIC, "v-alphabetic"}, {SP_ATTR_V_MATHEMATICAL, "v-mathematical"}, {SP_ATTR_V_HANGING, "v-hanging"}, diff --git a/src/attributes.h b/src/attributes.h index 52694eda2..7291b0166 100644 --- a/src/attributes.h +++ b/src/attributes.h @@ -332,12 +332,12 @@ enum SPAttributeEnum { SP_ATTR_K, /**/ - SP_ATTR_FONT_FAMILY, - SP_ATTR_FONT_STYLE, - SP_ATTR_FONT_VARIANT, - SP_ATTR_FONT_WEIGHT, - SP_ATTR_FONT_STRETCH, - SP_ATTR_FONT_SIZE, +// SP_ATTR_FONT_FAMILY, +// SP_ATTR_FONT_STYLE, +// SP_ATTR_FONT_VARIANT, +// SP_ATTR_FONT_WEIGHT, +// SP_ATTR_FONT_STRETCH, +// SP_ATTR_FONT_SIZE, SP_ATTR_UNICODE_RANGE, SP_ATTR_UNITS_PER_EM, SP_ATTR_PANOSE_1, diff --git a/src/sp-font-face.cpp b/src/sp-font-face.cpp index 23fc1f200..f4eb8be4c 100644 --- a/src/sp-font-face.cpp +++ b/src/sp-font-face.cpp @@ -52,6 +52,240 @@ private: bool isset; }; +static std::vector sp_read_fontFaceStyleType(gchar const *value){ + std::vector v; + + if (!value){ + v.push_back(SP_FONTFACE_STYLE_ALL); + return v; + } + + if (strncmp(value, "all", 3) == 0){ + value += 3; + while(value[0]==',' || value[0]==' ') + value++; + v.push_back(SP_FONTFACE_STYLE_ALL); + return v; + } + + while(value[0]!='\0'){ + switch(value[0]){ + case 'n': + if (strncmp(value, "normal", 6) == 0){ + v.push_back(SP_FONTFACE_STYLE_NORMAL); + value += 6; + } + break; + case 'i': + if (strncmp(value, "italic", 6) == 0){ + v.push_back(SP_FONTFACE_STYLE_ITALIC); + value += 6; + } + break; + case 'o': + if (strncmp(value, "oblique", 7) == 0){ + v.push_back(SP_FONTFACE_STYLE_OBLIQUE); + value += 7; + } + break; + } + while(value[0]==',' || value[0]==' ') + value++; + } + return v; +} + +static std::vector sp_read_fontFaceVariantType(gchar const *value){ + std::vector v; + + if (!value){ + v.push_back(SP_FONTFACE_VARIANT_NORMAL); + return v; + } + + while(value[0]!='\0'){ + switch(value[0]){ + case 'n': + if (strncmp(value, "normal", 6) == 0){ + v.push_back(SP_FONTFACE_VARIANT_NORMAL); + value += 6; + } + break; + case 's': + if (strncmp(value, "small-caps", 10) == 0){ + v.push_back(SP_FONTFACE_VARIANT_SMALL_CAPS); + value += 10; + } + break; + } + while(value[0]==',' || value[0]==' ') + value++; + } + return v; +} + +static std::vector sp_read_fontFaceWeightType(gchar const *value){ + std::vector v; + + if (!value){ + v.push_back(SP_FONTFACE_WEIGHT_ALL); + return v; + } + + if (strncmp(value, "all", 3) == 0){ + value += 3; + while(value[0]==',' || value[0]==' ') + value++; + v.push_back(SP_FONTFACE_WEIGHT_ALL); + return v; + } + + while(value[0]!='\0'){ + switch(value[0]){ + case 'n': + if (strncmp(value, "normal", 6) == 0){ + v.push_back(SP_FONTFACE_WEIGHT_NORMAL); + value += 6; + } + break; + case 'b': + if (strncmp(value, "bold", 4) == 0){ + v.push_back(SP_FONTFACE_WEIGHT_BOLD); + value += 4; + } + break; + case '1': + if (strncmp(value, "100", 3) == 0){ + v.push_back(SP_FONTFACE_WEIGHT_100); + value += 3; + } + break; + case '2': + if (strncmp(value, "200", 3) == 0){ + v.push_back(SP_FONTFACE_WEIGHT_200); + value += 3; + } + break; + case '3': + if (strncmp(value, "300", 3) == 0){ + v.push_back(SP_FONTFACE_WEIGHT_300); + value += 3; + } + break; + case '4': + if (strncmp(value, "400", 3) == 0){ + v.push_back(SP_FONTFACE_WEIGHT_400); + value += 3; + } + break; + case '5': + if (strncmp(value, "500", 3) == 0){ + v.push_back(SP_FONTFACE_WEIGHT_500); + value += 3; + } + break; + case '6': + if (strncmp(value, "600", 3) == 0){ + v.push_back(SP_FONTFACE_WEIGHT_600); + value += 3; + } + break; + case '7': + if (strncmp(value, "700", 3) == 0){ + v.push_back(SP_FONTFACE_WEIGHT_700); + value += 3; + } + break; + case '8': + if (strncmp(value, "800", 3) == 0){ + v.push_back(SP_FONTFACE_WEIGHT_800); + value += 3; + } + break; + case '9': + if (strncmp(value, "900", 3) == 0){ + v.push_back(SP_FONTFACE_WEIGHT_900); + value += 3; + } + break; + } + while(value[0]==',' || value[0]==' ') + value++; + } + return v; +} + +static std::vector sp_read_fontFaceStretchType(gchar const *value){ + std::vector v; + + if (!value){ + v.push_back(SP_FONTFACE_STRETCH_NORMAL); + return v; + } + + if (strncmp(value, "all", 3) == 0){ + value += 3; + while(value[0]==',' || value[0]==' ') + value++; + v.push_back(SP_FONTFACE_STRETCH_ALL); + return v; + } + + while(value[0]!='\0'){ + switch(value[0]){ + case 'n': + if (strncmp(value, "normal", 6) == 0){ + v.push_back(SP_FONTFACE_STRETCH_NORMAL); + value += 6; + } + break; + case 'u': + if (strncmp(value, "ultra-condensed", 15) == 0){ + v.push_back(SP_FONTFACE_STRETCH_ULTRA_CONDENSED); + value += 15; + } + if (strncmp(value, "ultra-expanded", 14) == 0){ + v.push_back(SP_FONTFACE_STRETCH_ULTRA_EXPANDED); + value += 14; + } + break; + case 'e': + if (strncmp(value, "expanded", 8) == 0){ + v.push_back(SP_FONTFACE_STRETCH_EXPANDED); + value += 8; + } + if (strncmp(value, "extra-condensed", 15) == 0){ + v.push_back(SP_FONTFACE_STRETCH_EXTRA_CONDENSED); + value += 15; + } + if (strncmp(value, "extra-expanded", 14) == 0){ + v.push_back(SP_FONTFACE_STRETCH_EXTRA_EXPANDED); + value += 14; + } + break; + case 'c': + if (strncmp(value, "condensed", 9) == 0){ + v.push_back(SP_FONTFACE_STRETCH_CONDENSED); + value += 9; + } + break; + case 's': + if (strncmp(value, "semi-condensed", 14) == 0){ + v.push_back(SP_FONTFACE_STRETCH_SEMI_CONDENSED); + value += 14; + } + if (strncmp(value, "semi-expanded", 13) == 0){ + v.push_back(SP_FONTFACE_STRETCH_SEMI_EXPANDED); + value += 13; + } + break; + } + while(value[0]==',' || value[0]==' ') + value++; + } + return v; +} + static void sp_fontface_class_init(SPFontFaceClass *fc); static void sp_fontface_init(SPFontFace *font); @@ -104,8 +338,23 @@ static void sp_fontface_class_init(SPFontFaceClass *fc) sp_object_class->update = sp_fontface_update; } -static void sp_fontface_init(SPFontFace *font) +static void sp_fontface_init(SPFontFace *face) { + std::vector style; + style.push_back(SP_FONTFACE_STYLE_ALL); + face->font_style = style; + + std::vector variant; + variant.push_back(SP_FONTFACE_VARIANT_NORMAL); + face->font_variant = variant; + + std::vector weight; + weight.push_back(SP_FONTFACE_WEIGHT_ALL); + face->font_weight = weight; + + std::vector stretch; + stretch.push_back(SP_FONTFACE_STRETCH_NORMAL); + face->font_stretch = stretch; /* face->font_family = NULL; //face->font_style = ; @@ -232,8 +481,104 @@ static void sp_fontface_set(SPObject *object, unsigned int key, const gchar *val { SPFontFace *face = SP_FONTFACE(object); double number; + std::vector style; + std::vector variant; + std::vector weight; + std::vector stretch; switch (key) { + case SP_PROP_FONT_STYLE: + style = sp_read_fontFaceStyleType(value); + if (face->font_style.size() != style.size()){ + face->font_style = style; +g_warning(": SP_ATTR_FONT_STYLE:"); + for (unsigned int i=0;irequestModified(SP_OBJECT_MODIFIED_FLAG); + } else { + for (unsigned int i=0;ifont_style[i]){ + face->font_style = style; +g_warning(": SP_ATTR_FONT_STYLE:"); + for (unsigned int i=0;irequestModified(SP_OBJECT_MODIFIED_FLAG); + break; + } + } + } + break; + case SP_PROP_FONT_VARIANT: + variant = sp_read_fontFaceVariantType(value); + if (face->font_variant.size() != variant.size()){ + face->font_variant = variant; +g_warning(": SP_ATTR_FONT_VARIANT:"); + for (unsigned int i=0;irequestModified(SP_OBJECT_MODIFIED_FLAG); + } else { + for (unsigned int i=0;ifont_variant[i]){ + face->font_variant = variant; +g_warning(": SP_ATTR_FONT_VARIANT:"); + for (unsigned int i=0;irequestModified(SP_OBJECT_MODIFIED_FLAG); + break; + } + } + } + break; + case SP_PROP_FONT_WEIGHT: + weight = sp_read_fontFaceWeightType(value); + if (face->font_weight.size() != weight.size()){ + face->font_weight = weight; +g_warning(": SP_ATTR_FONT_WEIGHT:"); + for (unsigned int i=0;irequestModified(SP_OBJECT_MODIFIED_FLAG); + } else { + for (unsigned int i=0;ifont_weight[i]){ + face->font_weight = weight; +g_warning(": SP_ATTR_FONT_WEIGHT:"); + for (unsigned int i=0;irequestModified(SP_OBJECT_MODIFIED_FLAG); + break; + } + } + } + break; + case SP_PROP_FONT_STRETCH: + stretch = sp_read_fontFaceStretchType(value); + if (face->font_stretch.size() != stretch.size()){ + face->font_stretch = stretch; +g_warning(": SP_ATTR_FONT_STRETCH:"); + for (unsigned int i=0;irequestModified(SP_OBJECT_MODIFIED_FLAG); + } else { + for (unsigned int i=0;ifont_stretch[i]){ + face->font_stretch = stretch; +g_warning(": SP_ATTR_FONT_STRETCH:"); + for (unsigned int i=0;irequestModified(SP_OBJECT_MODIFIED_FLAG); + break; + } + } + } + break; case SP_ATTR_UNITS_PER_EM: number = helperfns_read_number(value); if (number != face->units_per_em){ diff --git a/src/sp-font-face.h b/src/sp-font-face.h index aaf092083..b095e6b04 100644 --- a/src/sp-font-face.h +++ b/src/sp-font-face.h @@ -52,16 +52,16 @@ enum FontFaceWeightType{ }; enum FontFaceStretchType{ - SP_FONTFACE_SRTETCH_ALL, - SP_FONTFACE_SRTETCH_NORMAL, - SP_FONTFACE_SRTETCH_ULTRA_CONDENSED, - SP_FONTFACE_SRTETCH_EXTRA_CONDENSED, - SP_FONTFACE_SRTETCH_CONDENSED, - SP_FONTFACE_SRTETCH_SEMI_CONDENSED, - SP_FONTFACE_SRTETCH_SEMI_EXPANDED, - SP_FONTFACE_SRTETCH_EXPANDED, - SP_FONTFACE_SRTETCH_EXTRA_EXPANDED, - SP_FONTFACE_SRTETCH_ULTRA_EXPANDED + SP_FONTFACE_STRETCH_ALL, + SP_FONTFACE_STRETCH_NORMAL, + SP_FONTFACE_STRETCH_ULTRA_CONDENSED, + SP_FONTFACE_STRETCH_EXTRA_CONDENSED, + SP_FONTFACE_STRETCH_CONDENSED, + SP_FONTFACE_STRETCH_SEMI_CONDENSED, + SP_FONTFACE_STRETCH_SEMI_EXPANDED, + SP_FONTFACE_STRETCH_EXPANDED, + SP_FONTFACE_STRETCH_EXTRA_EXPANDED, + SP_FONTFACE_STRETCH_ULTRA_EXPANDED }; enum FontFaceUnicodeRangeType{ -- 2.30.2