diff options
| -rw-r--r-- | src/desktop-style.cpp | 37 | ||||
| -rw-r--r-- | src/style-enums.h | 24 | ||||
| -rw-r--r-- | src/style-internal.cpp | 5 | ||||
| -rw-r--r-- | src/style-test.h | 8 | ||||
| -rw-r--r-- | src/ui/dialog/text-edit.cpp | 2 | ||||
| -rw-r--r-- | src/ui/widget/font-variants.cpp | 121 | ||||
| -rw-r--r-- | src/ui/widget/font-variants.h | 19 |
7 files changed, 183 insertions, 33 deletions
diff --git a/src/desktop-style.cpp b/src/desktop-style.cpp index 118f983bb..f25ce8fa8 100644 --- a/src/desktop-style.cpp +++ b/src/desktop-style.cpp @@ -1176,10 +1176,19 @@ objects_query_fontvariants (const std::vector<SPItem*> &objects, SPStyle *style_ int texts = 0; SPILigatures* ligatures_res = &(style_res->font_variant_ligatures); - ligatures_res->computed = - SP_CSS_FONT_VARIANT_LIGATURES_COMMON | - SP_CSS_FONT_VARIANT_LIGATURES_CONTEXTUAL; + SPIEnum* position_res = &(style_res->font_variant_position); + SPIEnum* caps_res = &(style_res->font_variant_caps); + + // Stores 'and' of all values + ligatures_res->computed = SP_CSS_FONT_VARIANT_LIGATURES_NORMAL; + position_res->computed = SP_CSS_FONT_VARIANT_POSITION_NORMAL; + caps_res->computed = SP_CSS_FONT_VARIANT_CAPS_NORMAL; + + // Stores only differences ligatures_res->value = 0; + position_res->value = 0; + caps_res->value = 0; + for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) { SPObject *obj = *i; @@ -1195,20 +1204,36 @@ objects_query_fontvariants (const std::vector<SPItem*> &objects, SPStyle *style_ texts ++; SPILigatures* ligatures_in = &(style->font_variant_ligatures); + SPIEnum* position_in = &(style->font_variant_position); + SPIEnum* caps_in = &(style->font_variant_caps); // computed stores which bits are on/off, only valid if same between all selected objects. // value stores which bits are different between objects. This is a bit of an abuse of // the values but then we don't need to add new variables to class. if (set) { ligatures_res->value |= (ligatures_res->computed ^ ligatures_in->computed ); ligatures_res->computed &= ligatures_in->computed; + + position_res->value |= (position_res->computed ^ position_in->computed ); + position_res->computed &= position_in->computed; + + caps_res->value |= (caps_res->computed ^ caps_in->computed ); + caps_res->computed &= caps_in->computed; + } else { - set = true; ligatures_res->computed = ligatures_in->computed; + position_res->computed = position_in->computed; + caps_res->computed = caps_in->computed; } + + set = true; } - bool different = (style_res->font_variant_position.value != - style_res->font_variant_position.computed ); + bool different = (style_res->font_variant_ligatures.value != + style_res->font_variant_ligatures.computed || + style_res->font_variant_position.value != + style_res->font_variant_position.computed || + style_res->font_variant_caps.value != + style_res->font_variant_caps.computed ); if (texts == 0 || !set) return QUERY_STYLE_NOTHING; diff --git a/src/style-enums.h b/src/style-enums.h index 36eab216d..dca7e246d 100644 --- a/src/style-enums.h +++ b/src/style-enums.h @@ -79,6 +79,7 @@ enum SPCSSFontVariantLigatures { SP_CSS_FONT_VARIANT_LIGATURES_DISCRETIONARY = 2, SP_CSS_FONT_VARIANT_LIGATURES_HISTORICAL = 4, SP_CSS_FONT_VARIANT_LIGATURES_CONTEXTUAL = 8, + SP_CSS_FONT_VARIANT_LIGATURES_NORMAL = 9, // Special case SP_CSS_FONT_VARIANT_LIGATURES_NOCOMMON = 16, SP_CSS_FONT_VARIANT_LIGATURES_NODISCRETIONARY = 32, SP_CSS_FONT_VARIANT_LIGATURES_NOHISTORICAL = 64, @@ -86,19 +87,19 @@ enum SPCSSFontVariantLigatures { }; enum SPCSSFontVariantPosition { - SP_CSS_FONT_VARIANT_POSITION_NORMAL, - SP_CSS_FONT_VARIANT_POSITION_SUB, - SP_CSS_FONT_VARIANT_POSITION_SUPER + SP_CSS_FONT_VARIANT_POSITION_NORMAL = 1, + SP_CSS_FONT_VARIANT_POSITION_SUB = 2, + SP_CSS_FONT_VARIANT_POSITION_SUPER = 4 }; enum SPCSSFontVariantCaps { - SP_CSS_FONT_VARIANT_CAPS_NORMAL, - SP_CSS_FONT_VARIANT_CAPS_SMALL, - SP_CSS_FONT_VARIANT_CAPS_ALL_SMALL, - SP_CSS_FONT_VARIANT_CAPS_PETITE, - SP_CSS_FONT_VARIANT_CAPS_ALL_PETITE, - SP_CSS_FONT_VARIANT_CAPS_UNICASE, - SP_CSS_FONT_VARIANT_CAPS_TITLING, + SP_CSS_FONT_VARIANT_CAPS_NORMAL = 1, + SP_CSS_FONT_VARIANT_CAPS_SMALL = 2, + SP_CSS_FONT_VARIANT_CAPS_ALL_SMALL = 4, + SP_CSS_FONT_VARIANT_CAPS_PETITE = 8, + SP_CSS_FONT_VARIANT_CAPS_ALL_PETITE = 16, + SP_CSS_FONT_VARIANT_CAPS_UNICASE = 32, + SP_CSS_FONT_VARIANT_CAPS_TITLING = 64 }; // Can select more than one (see spec) @@ -381,6 +382,7 @@ static SPStyleEnum const enum_font_variant_ligatures[] = { {"discretionary-ligatures", SP_CSS_FONT_VARIANT_LIGATURES_DISCRETIONARY}, {"historical-ligatures", SP_CSS_FONT_VARIANT_LIGATURES_HISTORICAL}, {"contextual", SP_CSS_FONT_VARIANT_LIGATURES_CONTEXTUAL}, + {"normal", SP_CSS_FONT_VARIANT_LIGATURES_NORMAL}, {"no-common-ligatures", SP_CSS_FONT_VARIANT_LIGATURES_NOCOMMON}, {"no-discretionary-ligatures", SP_CSS_FONT_VARIANT_LIGATURES_NODISCRETIONARY}, {"no-historical-ligatures", SP_CSS_FONT_VARIANT_LIGATURES_NOHISTORICAL}, @@ -400,7 +402,7 @@ static SPStyleEnum const enum_font_variant_caps[] = { {"small-caps", SP_CSS_FONT_VARIANT_CAPS_SMALL}, {"all-small-caps", SP_CSS_FONT_VARIANT_CAPS_ALL_SMALL}, {"petite-caps", SP_CSS_FONT_VARIANT_CAPS_PETITE}, - {"all_petite-caps", SP_CSS_FONT_VARIANT_CAPS_ALL_PETITE}, + {"all-petite-caps", SP_CSS_FONT_VARIANT_CAPS_ALL_PETITE}, {"unicase", SP_CSS_FONT_VARIANT_CAPS_UNICASE}, {"titling", SP_CSS_FONT_VARIANT_CAPS_TITLING}, {NULL, -1} diff --git a/src/style-internal.cpp b/src/style-internal.cpp index 7f6f6400d..3b76e5ab1 100644 --- a/src/style-internal.cpp +++ b/src/style-internal.cpp @@ -726,7 +726,7 @@ SPILigatures::read( gchar const *str ) { if( !str ) return; - value = SP_CSS_FONT_VARIANT_LIGATURES_COMMON | SP_CSS_FONT_VARIANT_LIGATURES_CONTEXTUAL; + value = SP_CSS_FONT_VARIANT_LIGATURES_NORMAL; if( !strcmp(str, "inherit") ) { set = true; inherit = true; @@ -775,8 +775,7 @@ SPILigatures::write( guint const flags, SPIBase const *const base) const { if (value == SP_CSS_FONT_VARIANT_LIGATURES_NONE ) { return (name + ":none;"); } - if (value == (SP_CSS_FONT_VARIANT_LIGATURES_COMMON + - SP_CSS_FONT_VARIANT_LIGATURES_CONTEXTUAL) ) { + if (value == SP_CSS_FONT_VARIANT_LIGATURES_NORMAL ) { return (name + ":normal;"); } diff --git a/src/style-test.h b/src/style-test.h index fec0da0f8..1d821312b 100644 --- a/src/style-test.h +++ b/src/style-test.h @@ -147,7 +147,13 @@ public: TestCase("font-variant-ligatures:contextual", "font-variant-ligatures:normal"), TestCase("font-variant-ligatures:no-common-ligatures historical-ligatures"), TestCase("font-variant-ligatures:historical-ligatures no-contextual"), - + TestCase("font-variant-position:normal"), + TestCase("font-variant-position:sub"), + TestCase("font-variant-position:super"), + TestCase("font-variant-caps:normal"), + TestCase("font-variant-caps:small-caps"), + TestCase("font-variant-caps:all-small-caps"), + // Should be moved down TestCase("text-indent:12em"), // SPILength? TestCase("text-align:center"), // SPIEnum diff --git a/src/ui/dialog/text-edit.cpp b/src/ui/dialog/text-edit.cpp index 2726d979c..4fd227f01 100644 --- a/src/ui/dialog/text-edit.cpp +++ b/src/ui/dialog/text-edit.cpp @@ -389,7 +389,7 @@ void TextEdit::onReadSelection ( gboolean dostyle, gboolean /*docontent*/ ) // Update font variant widget //int result_variants = sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONTVARIANTS); - vari_vbox.update( query.font_variant_ligatures.computed, query.font_variant_ligatures.value ); + vari_vbox.update( &query ); } blocked = false; diff --git a/src/ui/widget/font-variants.cpp b/src/ui/widget/font-variants.cpp index 7da7662e2..8ca926d8f 100644 --- a/src/ui/widget/font-variants.cpp +++ b/src/ui/widget/font-variants.cpp @@ -66,8 +66,12 @@ namespace Widget { _numeric_stacked ( Glib::ustring(_("Stacked" )) ), _numeric_default_fractions( Glib::ustring(_("Default Fractions")) ), _numeric_ordinal ( Glib::ustring(_("Ordinal" )) ), - _numeric_slashed_zero ( Glib::ustring(_("Slashed Zero" )) ) + _numeric_slashed_zero ( Glib::ustring(_("Slashed Zero" )) ), + _ligatures_changed( false ), + _position_changed( false ), + _caps_changed( false ), + _numeric_changed( false ) { @@ -183,6 +187,7 @@ namespace Widget { void FontVariants::ligatures_callback() { // std::cout << "FontVariants::ligatures_callback()" << std::endl; + _ligatures_changed = true; } void @@ -193,6 +198,7 @@ namespace Widget { void FontVariants::position_callback() { // std::cout << "FontVariants::position_callback()" << std::endl; + _position_changed = true; } void @@ -203,6 +209,7 @@ namespace Widget { void FontVariants::caps_callback() { // std::cout << "FontVariants::caps_callback()" << std::endl; + _caps_changed = true; } void @@ -214,21 +221,61 @@ namespace Widget { void FontVariants::numeric_callback() { // std::cout << "FontVariants::numeric_callback()" << std::endl; + _numeric_changed = true; } + // Update GUI based on query. void - FontVariants::update( unsigned all, unsigned mix ) { + FontVariants::update( SPStyle const *query ) { // std::cout << "FontVariants::update" << std::endl; - _ligatures_common.set_active( all & SP_CSS_FONT_VARIANT_LIGATURES_COMMON ); - _ligatures_discretionary.set_active( all & SP_CSS_FONT_VARIANT_LIGATURES_DISCRETIONARY ); - _ligatures_historical.set_active( all & SP_CSS_FONT_VARIANT_LIGATURES_HISTORICAL ); - _ligatures_contextual.set_active( all & SP_CSS_FONT_VARIANT_LIGATURES_CONTEXTUAL ); + _ligatures_all = query->font_variant_ligatures.computed; + _ligatures_mix = query->font_variant_ligatures.value; + + _ligatures_common.set_active( _ligatures_all & SP_CSS_FONT_VARIANT_LIGATURES_COMMON ); + _ligatures_discretionary.set_active(_ligatures_all & SP_CSS_FONT_VARIANT_LIGATURES_DISCRETIONARY ); + _ligatures_historical.set_active( _ligatures_all & SP_CSS_FONT_VARIANT_LIGATURES_HISTORICAL ); + _ligatures_contextual.set_active( _ligatures_all & SP_CSS_FONT_VARIANT_LIGATURES_CONTEXTUAL ); + + _ligatures_common.set_inconsistent( _ligatures_mix & SP_CSS_FONT_VARIANT_LIGATURES_COMMON ); + _ligatures_discretionary.set_inconsistent( _ligatures_mix & SP_CSS_FONT_VARIANT_LIGATURES_DISCRETIONARY ); + _ligatures_historical.set_inconsistent( _ligatures_mix & SP_CSS_FONT_VARIANT_LIGATURES_HISTORICAL ); + _ligatures_contextual.set_inconsistent( _ligatures_mix & SP_CSS_FONT_VARIANT_LIGATURES_CONTEXTUAL ); + + _position_all = query->font_variant_position.computed; + _position_mix = query->font_variant_position.value; - _ligatures_common.set_inconsistent( mix & SP_CSS_FONT_VARIANT_LIGATURES_COMMON ); - _ligatures_discretionary.set_inconsistent( mix & SP_CSS_FONT_VARIANT_LIGATURES_DISCRETIONARY ); - _ligatures_historical.set_inconsistent( mix & SP_CSS_FONT_VARIANT_LIGATURES_HISTORICAL ); - _ligatures_contextual.set_inconsistent( mix & SP_CSS_FONT_VARIANT_LIGATURES_CONTEXTUAL ); + _position_normal.set_active( _position_all & SP_CSS_FONT_VARIANT_POSITION_NORMAL ); + _position_sub.set_active( _position_all & SP_CSS_FONT_VARIANT_POSITION_SUB ); + _position_super.set_active( _position_all & SP_CSS_FONT_VARIANT_POSITION_SUPER ); + + _position_normal.set_inconsistent( _position_mix & SP_CSS_FONT_VARIANT_POSITION_NORMAL ); + _position_sub.set_inconsistent( _position_mix & SP_CSS_FONT_VARIANT_POSITION_SUB ); + _position_super.set_inconsistent( _position_mix & SP_CSS_FONT_VARIANT_POSITION_SUPER ); + + unsigned _caps_all = query->font_variant_caps.computed; + unsigned _caps_mix = query->font_variant_caps.value; + + _caps_normal.set_active( _caps_all & SP_CSS_FONT_VARIANT_CAPS_NORMAL ); + _caps_small.set_active( _caps_all & SP_CSS_FONT_VARIANT_CAPS_SMALL ); + _caps_all_small.set_active( _caps_all & SP_CSS_FONT_VARIANT_CAPS_ALL_SMALL ); + _caps_petite.set_active( _caps_all & SP_CSS_FONT_VARIANT_CAPS_PETITE ); + _caps_all_petite.set_active( _caps_all & SP_CSS_FONT_VARIANT_CAPS_ALL_PETITE ); + _caps_unicase.set_active( _caps_all & SP_CSS_FONT_VARIANT_CAPS_UNICASE ); + _caps_titling.set_active( _caps_all & SP_CSS_FONT_VARIANT_CAPS_TITLING ); + + _caps_normal.set_inconsistent( _caps_mix & SP_CSS_FONT_VARIANT_CAPS_NORMAL ); + _caps_small.set_inconsistent( _caps_mix & SP_CSS_FONT_VARIANT_CAPS_SMALL ); + _caps_all_small.set_inconsistent( _caps_mix & SP_CSS_FONT_VARIANT_CAPS_ALL_SMALL ); + _caps_petite.set_inconsistent( _caps_mix & SP_CSS_FONT_VARIANT_CAPS_PETITE ); + _caps_all_petite.set_inconsistent( _caps_mix & SP_CSS_FONT_VARIANT_CAPS_ALL_PETITE ); + _caps_unicase.set_inconsistent( _caps_mix & SP_CSS_FONT_VARIANT_CAPS_UNICASE ); + _caps_titling.set_inconsistent( _caps_mix & SP_CSS_FONT_VARIANT_CAPS_TITLING ); + + _ligatures_changed = false; + _position_changed = false; + _caps_changed = false; + _numeric_changed = false; } void @@ -256,6 +303,60 @@ namespace Widget { css_string += "no-contextual "; sp_repr_css_set_property(css, "font-variant-ligatures", css_string.c_str() ); } + + // Position + { + unsigned position_new = SP_CSS_FONT_VARIANT_POSITION_NORMAL; + Glib::ustring css_string; + if( _position_normal.get_active() ) { + css_string = "normal"; + } else if( _position_sub.get_active() ) { + css_string = "sub"; + position_new = SP_CSS_FONT_VARIANT_POSITION_SUB; + } else if( _position_super.get_active() ) { + css_string = "super"; + position_new = SP_CSS_FONT_VARIANT_POSITION_SUPER; + } + + // 'if' may not be necessary... need to test. + if( (_position_all != position_new) || ((_position_mix != 0) && _position_changed) ) { + sp_repr_css_set_property(css, "font-variant-position", css_string.c_str() ); + } + } + + // Caps + { + unsigned caps_new = SP_CSS_FONT_VARIANT_CAPS_NORMAL; + Glib::ustring css_string; + if( _caps_normal.get_active() ) { + css_string = "normal"; + caps_new = SP_CSS_FONT_VARIANT_CAPS_NORMAL; + } else if( _caps_small.get_active() ) { + css_string = "small-caps"; + caps_new = SP_CSS_FONT_VARIANT_CAPS_SMALL; + } else if( _caps_all_small.get_active() ) { + css_string = "all-small-caps"; + caps_new = SP_CSS_FONT_VARIANT_CAPS_ALL_SMALL; + } else if( _caps_all_petite.get_active() ) { + css_string = "petite"; + caps_new = SP_CSS_FONT_VARIANT_CAPS_PETITE; + } else if( _caps_all_petite.get_active() ) { + css_string = "all-petite"; + caps_new = SP_CSS_FONT_VARIANT_CAPS_ALL_PETITE; + } else if( _caps_unicase.get_active() ) { + css_string = "unicase"; + caps_new = SP_CSS_FONT_VARIANT_CAPS_UNICASE; + } else if( _caps_titling.get_active() ) { + css_string = "titling"; + caps_new = SP_CSS_FONT_VARIANT_CAPS_TITLING; + } + + // May not be necessary... need to test. + //if( (_caps_all != caps_new) || ((_caps_mix != 0) && _caps_changed) ) { + sp_repr_css_set_property(css, "font-variant-caps", css_string.c_str() ); + //} + } + } } // namespace Widget diff --git a/src/ui/widget/font-variants.h b/src/ui/widget/font-variants.h index f58b80f34..04c05d3c6 100644 --- a/src/ui/widget/font-variants.h +++ b/src/ui/widget/font-variants.h @@ -18,6 +18,7 @@ class SPDesktop; class SPObject; +class SPStyle; class SPCSSAttr; namespace Inkscape { @@ -95,8 +96,24 @@ private: void numeric_init(); void numeric_callback(); + // To determine if we need to write out property (may not be necessary) + unsigned _ligatures_all; + unsigned _position_all; + unsigned _caps_all; + unsigned _numeric_all; + + unsigned _ligatures_mix; + unsigned _position_mix; + unsigned _caps_mix; + unsigned _numeric_mix; + + bool _ligatures_changed; + bool _position_changed; + bool _caps_changed; + bool _numeric_changed; + public: - void update( unsigned all, unsigned mix ); + void update( SPStyle const *query ); void fill_css( SPCSSAttr* css ); }; |
