Code

support for <rect> tag (Bug 657289)
[inkscape.git] / src / sp-glyph-kerning.cpp
index a8609f5ee3b7b0bdb0605a2193bf6fb7e71e8dd2..7a9f9b2ff1372307f6227fdb030252e42c5c78cf 100644 (file)
@@ -1,3 +1,8 @@
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#ifdef ENABLE_SVG_FONTS
 #define __SP_ANCHOR_C__
 
 /*
@@ -5,7 +10,8 @@
  * W3C SVG 1.1 spec, page 476, section 20.7
  *
  * Author:
- *   Felipe C. da S. Sanches <felipe.sanches@gmail.com>
+ *   Felipe C. da S. Sanches <juca@members.fsf.org>
+ *   Abhishek Sharma
  *
  * Copyright (C) 2008, Felipe C. da S. Sanches
  *
@@ -17,7 +23,7 @@
 #include "sp-glyph-kerning.h"
 
 #include "document.h"
-#include "helper-fns.h"
+#include <string>
 
 static void sp_glyph_kerning_class_init(SPGlyphKerningClass *gc);
 static void sp_glyph_kerning_init(SPGlyphKerning *glyph);
@@ -25,29 +31,52 @@ static void sp_glyph_kerning_init(SPGlyphKerning *glyph);
 static void sp_glyph_kerning_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
 static void sp_glyph_kerning_release(SPObject *object);
 static void sp_glyph_kerning_set(SPObject *object, unsigned int key, const gchar *value);
-static Inkscape::XML::Node *sp_glyph_kerning_write(SPObject *object, Inkscape::XML::Node *repr, guint flags);
+static Inkscape::XML::Node *sp_glyph_kerning_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
 static void sp_glyph_kerning_update(SPObject *object, SPCtx *ctx, guint flags);
 
 static SPObjectClass *parent_class;
 
-GType sp_glyph_kerning_get_type(void)
+GType sp_glyph_kerning_h_get_type(void)
 {
     static GType type = 0;
 
     if (!type) {
         GTypeInfo info = {
             sizeof(SPGlyphKerningClass),
-            NULL,      /* base_init */
-            NULL,      /* base_finalize */
+            NULL,       /* base_init */
+            NULL,       /* base_finalize */
             (GClassInitFunc) sp_glyph_kerning_class_init,
-            NULL,      /* class_finalize */
-            NULL,      /* class_data */
-            sizeof(SPGlyphKerning),
-            16,        /* n_preallocs */
+            NULL,       /* class_finalize */
+            NULL,       /* class_data */
+            sizeof(SPHkern),
+            16, /* n_preallocs */
             (GInstanceInitFunc) sp_glyph_kerning_init,
-            NULL,      /* value_table */
+            NULL,       /* value_table */
         };
-        type = g_type_register_static(SP_TYPE_OBJECT, "SPGlyphKerning", &info, (GTypeFlags) 0);
+        type = g_type_register_static(SP_TYPE_OBJECT, "SPHkern", &info, (GTypeFlags) 0);
+    }
+
+    return type;
+}
+
+GType sp_glyph_kerning_v_get_type(void)
+{
+    static GType type = 0;
+
+    if (!type) {
+        GTypeInfo info = {
+            sizeof(SPGlyphKerningClass),
+            NULL,       /* base_init */
+            NULL,       /* base_finalize */
+            (GClassInitFunc) sp_glyph_kerning_class_init,
+            NULL,       /* class_finalize */
+            NULL,       /* class_data */
+            sizeof(SPVkern),
+            16, /* n_preallocs */
+            (GInstanceInitFunc) sp_glyph_kerning_init,
+            NULL,       /* value_table */
+        };
+        type = g_type_register_static(SP_TYPE_OBJECT, "SPVkern", &info, (GTypeFlags) 0);
     }
 
     return type;
@@ -82,11 +111,11 @@ static void sp_glyph_kerning_build(SPObject *object, SPDocument *document, Inksc
         ((SPObjectClass *) (parent_class))->build(object, document, repr);
     }
 
-    sp_object_read_attr(object, "u1");
-    sp_object_read_attr(object, "g1");
-    sp_object_read_attr(object, "u2");
-    sp_object_read_attr(object, "g2");
-    sp_object_read_attr(object, "k");
+    object->readAttr( "u1" );
+    object->readAttr( "g1" );
+    object->readAttr( "u2" );
+    object->readAttr( "g2" );
+    object->readAttr( "k" );
 }
 
 static void sp_glyph_kerning_release(SPObject *object)
@@ -98,49 +127,82 @@ static void sp_glyph_kerning_release(SPObject *object)
     }
 }
 
+GlyphNames::GlyphNames(const gchar* value){
+        if (value) this->names = strdup(value);
+}
+
+GlyphNames::~GlyphNames(){
+    if (this->names) g_free(this->names);
+}
+
+bool GlyphNames::contains(const char* name){
+    if (!(this->names) || !name) return false;
+    std::istringstream is(this->names);
+    std::string str;
+    std::string s(name);
+    while (is >> str){
+        if (str == s) return true;
+    }
+    return false;
+}
+
 static void sp_glyph_kerning_set(SPObject *object, unsigned int key, const gchar *value)
 {
-    SPGlyphKerning *glyphkern = SP_GLYPH_KERNING(object);
-    double number;
+    SPGlyphKerning * glyphkern = (SPGlyphKerning*) object; //even if it is a VKern this will work. I did it this way just to avoind warnings.
 
     switch (key) {
         case SP_ATTR_U1:
-            if (glyphkern->u1) g_free(glyphkern->u1);
-            glyphkern->u1 = g_strdup(value);//todo: 
+        {
+            if (glyphkern->u1) {
+                delete glyphkern->u1;
+            }
+            glyphkern->u1 = new UnicodeRange(value);
             object->requestModified(SP_OBJECT_MODIFIED_FLAG);
-g_warning("<glyph-kerning>: SP_ATTR_U1: %s", value);
-             break;
+            break;
+        }
         case SP_ATTR_U2:
-            if (glyphkern->u2) g_free(glyphkern->u2);
-            glyphkern->u2 = g_strdup(value);//todo: 
+        {
+            if (glyphkern->u2) {
+                delete glyphkern->u2;
+            }
+            glyphkern->u2 = new UnicodeRange(value);
             object->requestModified(SP_OBJECT_MODIFIED_FLAG);
-g_warning("<glyph-kerning>: SP_ATTR_U2: %s", value);
-             break;
+            break;
+        }
         case SP_ATTR_G1:
-            if (glyphkern->g1) g_free(glyphkern->g1);
-            glyphkern->g1 = g_strdup(value);//todo: 
+        {
+            if (glyphkern->g1) {
+                delete glyphkern->g1;
+            }
+            glyphkern->g1 = new GlyphNames(value);
             object->requestModified(SP_OBJECT_MODIFIED_FLAG);
-g_warning("<glyph-kerning>: SP_ATTR_G1: %s", value);
-             break;
+            break;
+        }
         case SP_ATTR_G2:
-            if (glyphkern->g2) g_free(glyphkern->g2);
-            glyphkern->g2 = g_strdup(value);//todo: 
+        {
+            if (glyphkern->g2) {
+                delete glyphkern->g2;
+            }
+            glyphkern->g2 = new GlyphNames(value);
             object->requestModified(SP_OBJECT_MODIFIED_FLAG);
-g_warning("<glyph-kerning>: SP_ATTR_G2: %s", value);
              break;
-       case SP_ATTR_K:
-            number = helperfns_read_number(value);
+        }
+        case SP_ATTR_K:
+        {
+            double number = value ? g_ascii_strtod(value, 0) : 0;
             if (number != glyphkern->k){
                 glyphkern->k = number;
-g_warning("<glyph-kerning>: SP_ATTR_K: %f", number);
                 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
             }
             break;
-       default:
+        }
+        default:
+        {
             if (((SPObjectClass *) (parent_class))->set) {
                 ((SPObjectClass *) (parent_class))->set(object, key, value);
             }
             break;
+        }
     }
 }
 
@@ -150,16 +212,15 @@ g_warning("<glyph-kerning>: SP_ATTR_K: %f", number);
 static void
 sp_glyph_kerning_update(SPObject *object, SPCtx *ctx, guint flags)
 {
-    SPGlyphKerning *glyph = SP_GLYPH_KERNING(object);
+    SPGlyphKerning *glyph = (SPGlyphKerning *)object;
     (void)glyph;
 
     if (flags & SP_OBJECT_MODIFIED_FLAG) {
         /* do something to trigger redisplay, updates? */
-            sp_object_read_attr(object, "u1");
-            sp_object_read_attr(object, "g1");
-            sp_object_read_attr(object, "u2");
-            sp_object_read_attr(object, "g2");
-            sp_object_read_attr(object, "k");
+            object->readAttr( "u1" );
+            object->readAttr( "u2" );
+            object->readAttr( "g2" );
+            object->readAttr( "k" );
     }
 
     if (((SPObjectClass *) parent_class)->update) {
@@ -169,12 +230,11 @@ sp_glyph_kerning_update(SPObject *object, SPCtx *ctx, guint flags)
 
 #define COPY_ATTR(rd,rs,key) (rd)->setAttribute((key), rs->attribute(key));
 
-static Inkscape::XML::Node *sp_glyph_kerning_write(SPObject *object, Inkscape::XML::Node *repr, guint flags)
+static Inkscape::XML::Node *sp_glyph_kerning_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
 {
 //    SPGlyphKerning *glyph = SP_GLYPH_KERNING(object);
 
     if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
-        Inkscape::XML::Document *xml_doc = sp_document_repr_doc(SP_OBJECT_DOCUMENT(object));
         repr = xml_doc->createElement("svg:glyphkerning");//fix this!
     }
 
@@ -191,20 +251,22 @@ static Inkscape::XML::Node *sp_glyph_kerning_write(SPObject *object, Inkscape::X
     sp_repr_set_svg_double(repr, "vert-adv-y", glyph->vert_adv_y);
 */
     if (repr != SP_OBJECT_REPR(object)) {
-        COPY_ATTR(repr, object->repr, "u1");
-        COPY_ATTR(repr, object->repr, "g1");
-        COPY_ATTR(repr, object->repr, "u2");
-        COPY_ATTR(repr, object->repr, "g2");
-        COPY_ATTR(repr, object->repr, "k");
+        // All the COPY_ATTR functions below use
+        //   XML Tree directly, while they shouldn't.
+        COPY_ATTR(repr, object->getRepr(), "u1");
+        COPY_ATTR(repr, object->getRepr(), "g1");
+        COPY_ATTR(repr, object->getRepr(), "u2");
+        COPY_ATTR(repr, object->getRepr(), "g2");
+        COPY_ATTR(repr, object->getRepr(), "k");
     }
 
     if (((SPObjectClass *) (parent_class))->write) {
-        ((SPObjectClass *) (parent_class))->write(object, repr, flags);
+        ((SPObjectClass *) (parent_class))->write(object, xml_doc, repr, flags);
     }
 
     return repr;
 }
-
+#endif //#ifdef ENABLE_SVG_FONTS
 /*
   Local Variables:
   mode:c++