summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/style-internal.cpp57
-rw-r--r--src/style-internal.h30
-rw-r--r--src/style.cpp2
-rw-r--r--src/style.h2
4 files changed, 53 insertions, 38 deletions
diff --git a/src/style-internal.cpp b/src/style-internal.cpp
index 2dc9df8ba..72574dddc 100644
--- a/src/style-internal.cpp
+++ b/src/style-internal.cpp
@@ -521,65 +521,84 @@ SPILengthOrNormal::operator==(const SPIBase& rhs) {
}
-// SPIVariableFontAxisOrNormal ----------------------------------------------------
+// SPIFontVariationSettings ----------------------------------------------------
void
-SPIVariableFontAxisOrNormal::read( gchar const *str ) {
+SPIFontVariationSettings::read( gchar const *str ) {
if( !str ) return;
if ( !strcmp(str, "normal") ) {
set = true;
inherit = false;
- value = 0.0;
normal = true;
+ axes.empty();
return;
}
- if (strlen(str) >= 8
- && (str[0] == '\"' || str[0] == '\'')
- && (str[5] == '\"' || str[5] == '\'')
- && str[6] == ' ') {
- strncpy(axis_name, &str[1], 4);
- axis_name[4] = '\0';
+ gchar ** strarray = g_strsplit(str, " ", 0);
+ unsigned int i=0;
+ while (strarray[i]){
+ char axis_name[5];
+ if (strlen(strarray[i]) >= 8
+ && (strarray[i][0] == '\"' || strarray[i][0] == '\'')
+ && (strarray[i][5] == '\"' || strarray[i][5] == '\'')
+ && strarray[i][6] == ' ') {
+ strncpy(axis_name, &strarray[i][1], 4);
+ axis_name[4] = '\0';
- SPIFloat::read(&str[7]);
- normal = false;
+ gfloat value;
+ if (sp_svg_number_read_f(&strarray[i][7], &value)) {
+ set = true;
+ inherit = false;
+ axes.insert(std::pair<char*,float>(axis_name,value));
+ } else {
+ //invalid syntax while parsing attribute
+ break;
+ }
+ normal = false;
+ }
}
+ g_strfreev (strarray);
};
const Glib::ustring
-SPIVariableFontAxisOrNormal::write( guint const flags, SPStyleSrc const &style_src_req, SPIBase const *const base) const {
+SPIFontVariationSettings::write( guint const flags, SPStyleSrc const &style_src_req, SPIBase const *const base) const {
- SPIFloat const *const my_base = dynamic_cast<const SPIFloat*>(base);
+ SPIFontVariationSettings const *const my_base = dynamic_cast<const SPIFontVariationSettings*>(base);
bool dfp = (!inherits || !my_base || (my_base != this)); // Different from parent
bool src = (style_src_req == style_src || !(flags & SP_STYLE_FLAG_IFSRC));
if (should_write(flags, set, dfp, src)) {
if (this->normal) {
return (name + ":normal;");
} else {
- return "\"" + Glib::ustring(axis_name) + "\" " + SPIFloat::write(flags, style_src_req, base);
+ Inkscape::CSSOStringStream os;
+ for (std::map<char*,float>::const_iterator it=axes.begin(); it!=axes.end(); ++it){
+ os << "\"" << it->first << "\" " << it->second << " ";
+ // FIXME: can we avoid the last space char ?
+ }
+ return os.str();
}
}
return Glib::ustring("");
}
void
-SPIVariableFontAxisOrNormal::cascade( const SPIBase* const parent ) {
+SPIFontVariationSettings::cascade( const SPIBase* const parent ) {
// std::cerr << "SPIVariableFontAxisOrNormal::cascade(): TODO: Implement-me!" << std::endl;
}
void
-SPIVariableFontAxisOrNormal::merge( const SPIBase* const parent ) {
+SPIFontVariationSettings::merge( const SPIBase* const parent ) {
// std::cerr << "SPIVariableFontAxisOrNormal::merge(): TODO: Implement-me!" << std::endl;
}
bool
-SPIVariableFontAxisOrNormal::operator==(const SPIBase& rhs) {
- if( const SPIVariableFontAxisOrNormal* r = dynamic_cast<const SPIVariableFontAxisOrNormal*>(&rhs) ) {
+SPIFontVariationSettings::operator==(const SPIBase& rhs) {
+ if( const SPIFontVariationSettings* r = dynamic_cast<const SPIFontVariationSettings*>(&rhs) ) {
if( normal && r->normal ) { return true; }
if( normal != r->normal ) { return false; }
- return SPIFloat::operator==(rhs) && !strncmp(axis_name, r->axis_name, 4);
+ return axes == r->axes;
} else {
return false;
}
diff --git a/src/style-internal.h b/src/style-internal.h
index 71d5f9c85..c0b2f3e72 100644
--- a/src/style-internal.h
+++ b/src/style-internal.h
@@ -29,6 +29,7 @@
#include "xml/repr.h"
#include <vector>
+#include <map>
struct SPStyleEnum;
@@ -449,25 +450,21 @@ public:
/// Extended length type internal to SPStyle.
// Used for: font-variation-settings
-class SPIVariableFontAxisOrNormal : public SPIFloat
+class SPIFontVariationSettings : public SPIBase
{
public:
- SPIVariableFontAxisOrNormal()
- : SPIFloat( "anonymous_float" ),
- axis_name( "" ),
+ SPIFontVariationSettings()
+ : SPIBase( "anonymous_fontvariationsettings" ),
normal(true)
{}
- SPIVariableFontAxisOrNormal( Glib::ustring const &name, gchar const *axis = NULL, float value = 0 )
- : SPIFloat( name, value ),
+ SPIFontVariationSettings( Glib::ustring const &name )
+ : SPIBase( name ),
normal(true)
- {
- if (axis) strncpy(axis_name, axis, 5);
- else axis_name[0] = '\0';
- }
+ {}
- virtual ~SPIVariableFontAxisOrNormal()
+ virtual ~SPIFontVariationSettings()
{}
virtual void read( gchar const *str );
@@ -475,17 +472,15 @@ public:
SPStyleSrc const &style_src_req = SP_STYLE_SRC_STYLE_PROP,
SPIBase const *const base = NULL ) const;
virtual void clear() {
- SPIFloat::clear();
- axis_name[0] = '\0';
+ axes.empty();
normal = true;
}
virtual void cascade( const SPIBase* const parent );
virtual void merge( const SPIBase* const parent );
- SPIVariableFontAxisOrNormal& operator=(const SPIVariableFontAxisOrNormal& rhs) {
- SPIFloat::operator=(rhs);
- strncpy(axis_name, rhs.axis_name, 5);
+ SPIFontVariationSettings& operator=(const SPIFontVariationSettings& rhs) {
+ axes = rhs.axes;
normal = rhs.normal;
return *this;
}
@@ -498,7 +493,8 @@ public:
// To do: make private
public:
bool normal : 1;
- gchar axis_name[5];
+ bool inherit : 1;
+ std::map<char*, float> axes;
};
diff --git a/src/style.cpp b/src/style.cpp
index 08dbcd38b..ca0eed6f7 100644
--- a/src/style.cpp
+++ b/src/style.cpp
@@ -116,7 +116,7 @@ SPStyle::SPStyle(SPDocument *document_in, SPObject *object_in) :
font_feature_settings( "font-feature-settings", "normal" ),
// Variable Fonts
- font_variation_settings( "font-variation-settings" ), // SPIVariableFontAxisOrNormal
+ font_variation_settings( "font-variation-settings" ), // SPIFontVariationSettings
// Text related properties
text_indent( "text-indent", 0.0 ), // SPILength
diff --git a/src/style.h b/src/style.h
index 66332a117..fc50c3580 100644
--- a/src/style.h
+++ b/src/style.h
@@ -129,7 +129,7 @@ public:
SPIString font_feature_settings;
/** Font variation settings (Low level access to OpenType variable font design-coordinate values) */
- SPIVariableFontAxisOrNormal font_variation_settings;
+ SPIFontVariationSettings font_variation_settings;
/* Text ----------------------------- */