Code

Merge and cleanup of GSoC C++-ification project.
[inkscape.git] / src / extension / internal / pdfinput / svg-builder.cpp
index b9583545fb3ed237f0b336769b625aa775e5f11f..8b414239a708d9c8e5a8a537491aeef07518801e 100644 (file)
@@ -3,6 +3,7 @@
  * 
  * Authors:
  *   miklos erdelyi
+ *   Jon A. Cruz <jon@joncruz.org>
  *
  * Copyright (C) 2007 Authors
  *
@@ -77,12 +78,13 @@ struct SvgTransparencyGroup {
  * 
  */
 
-SvgBuilder::SvgBuilder(SPDocument *document, gchar *docname, XRef *xref) {
+SvgBuilder::SvgBuilder(SPDocument *document, gchar *docname, XRef *xref)
+{
     _is_top_level = true;
     _doc = document;
     _docname = docname;
     _xref = xref;
-    _xml_doc = sp_document_repr_doc(_doc);
+    _xml_doc = _doc->getReprDoc();
     _container = _root = _doc->rroot;
     _root->setAttribute("xml:space", "preserve");
     _init();
@@ -1291,8 +1293,8 @@ void SvgBuilder::_flushText() {
         last_delta_pos = delta_pos;
 
         // Append the character to the text buffer
-       if (0 != glyph.code[0]) {
-            text_buffer.append((char *)&glyph.code, 1);
+       if ( !glyph.code.empty() ) {
+            text_buffer.append(1, glyph.code[0]);
        }
 
         glyphs_in_a_row++;
@@ -1333,8 +1335,8 @@ void SvgBuilder::addChar(GfxState *state, double x, double y,
          return;
     }
     // Allow only one space in a row
-    if ( is_space && _glyphs[_glyphs.size() - 1].code_size == 1 &&
-         _glyphs[_glyphs.size() - 1].code[0] == 32 ) {
+    if ( is_space && (_glyphs[_glyphs.size() - 1].code.size() == 1) &&
+         (_glyphs[_glyphs.size() - 1].code[0] == 32) ) {
         Geom::Point delta(dx, dy);
         _text_position += delta;
         return;
@@ -1350,18 +1352,21 @@ void SvgBuilder::addChar(GfxState *state, double x, double y,
     _text_position += delta;
 
     // Convert the character to UTF-8 since that's our SVG document's encoding
-    static UnicodeMap *u_map = NULL;
-    if ( u_map == NULL ) {
-        GooString *enc = new GooString("UTF-8");
-        u_map = globalParams->getUnicodeMap(enc);
-        u_map->incRefCnt();
-        delete enc;
-    }
-    int code_size = 0;
-    for ( int i = 0 ; i < uLen ; i++ ) {
-        code_size += u_map->mapUnicode(u[i], (char *)&new_glyph.code[code_size], sizeof(new_glyph.code) - code_size);
-    }
-    new_glyph.code_size = code_size;
+    {
+        gunichar2 uu[8] = {0};
+
+        for (int i = 0; i < uLen; i++) {
+            uu[i] = u[i];
+        }
+
+        gchar *tmp = g_utf16_to_utf8(uu, uLen, NULL, NULL, NULL);
+        if ( tmp && *tmp ) {
+            new_glyph.code = tmp;
+        } else {
+            new_glyph.code.clear();
+        }
+        g_free(tmp);
+    }
 
     // Copy current style if it has changed since the previous glyph
     if (_invalidated_style || _glyphs.size() == 0 ) {