From e454b92b3d16b0909892cddef064b745898c924d Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Sun, 3 Oct 2010 01:54:33 -0700 Subject: [PATCH] Applied patch and updated to address non-BMP Unicode charcters. Fixes bug #369861. --- .../internal/pdfinput/svg-builder.cpp | 35 ++++++++++--------- src/extension/internal/pdfinput/svg-builder.h | 7 ++-- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/extension/internal/pdfinput/svg-builder.cpp b/src/extension/internal/pdfinput/svg-builder.cpp index b9583545f..e343dbf33 100644 --- a/src/extension/internal/pdfinput/svg-builder.cpp +++ b/src/extension/internal/pdfinput/svg-builder.cpp @@ -1291,8 +1291,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 +1333,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 +1350,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 ) { diff --git a/src/extension/internal/pdfinput/svg-builder.h b/src/extension/internal/pdfinput/svg-builder.h index 3b9192d31..f0062bbe6 100644 --- a/src/extension/internal/pdfinput/svg-builder.h +++ b/src/extension/internal/pdfinput/svg-builder.h @@ -28,6 +28,7 @@ namespace Inkscape { #include <2geom/point.h> #include <2geom/matrix.h> +#include #include "CharTypes.h" class GooString; @@ -75,10 +76,10 @@ struct SvgGraphicsState { struct SvgGlyph { Geom::Point position; // Absolute glyph coords Geom::Point text_position; // Absolute glyph coords in text space - double dx, dy; // Advance values + double dx; // X advance value + double dy; // Y advance value double rise; // Text rise parameter - char code[8]; // UTF-8 coded character - int code_size; + Glib::ustring code; // UTF-8 coded character bool is_space; bool style_changed; // Set to true if style has to be reset -- 2.30.2