[cairo-commit] src/cairo-type1-subset.c

Adrian Johnson ajohnson at kemper.freedesktop.org
Sun Oct 7 06:22:14 PDT 2012


 src/cairo-type1-subset.c |   31 +++++++++++++++++++++++++++----
 1 file changed, 27 insertions(+), 4 deletions(-)

New commits:
commit 9c2a92c70836b8534ef8c26d943fa17f891da105
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sun Oct 7 23:50:54 2012 +1030

    type1: convert '.' to locale specific decimal point before using sscanf

diff --git a/src/cairo-type1-subset.c b/src/cairo-type1-subset.c
index 56e659a..4926cd8 100644
--- a/src/cairo-type1-subset.c
+++ b/src/cairo-type1-subset.c
@@ -53,6 +53,7 @@
 #include "cairo-output-stream-private.h"
 
 #include <ctype.h>
+#include <locale.h>
 
 #define TYPE1_STACKSIZE 24 /* Defined in Type 1 Font Format */
 
@@ -304,8 +305,17 @@ cairo_type1_font_subset_get_matrix (cairo_type1_font_subset_t *font,
 				    double                    *d)
 {
     const char *start, *end, *segment_end;
-    int ret;
+    int ret, s_max, i, j;
     char *s;
+    struct lconv *locale_data;
+    const char *decimal_point;
+    int decimal_point_len;
+
+    locale_data = localeconv ();
+    decimal_point = locale_data->decimal_point;
+    decimal_point_len = strlen (decimal_point);
+
+    assert (decimal_point_len != 0);
 
     segment_end = font->header_segment + font->header_segment_size;
     start = find_token (font->header_segment, segment_end, name);
@@ -316,12 +326,23 @@ cairo_type1_font_subset_get_matrix (cairo_type1_font_subset_t *font,
     if (end == NULL)
 	return CAIRO_INT_STATUS_UNSUPPORTED;
 
-    s = malloc (end - start + 1);
+    s_max = end - start + 5*decimal_point_len + 1;
+    s = malloc (s_max);
     if (unlikely (s == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
-    strncpy (s, start, end - start);
-    s[end - start] = 0;
+    i = 0;
+    j = 0;
+    while (i < end - start && j < s_max - decimal_point_len) {
+	if (start[i] == '.') {
+	    strncpy(s + j, decimal_point, decimal_point_len);
+	    i++;
+	    j += decimal_point_len;
+	} else {
+	    s[j++] = start[i++];
+	}
+    }
+    s[j] = 0;
 
     start = strpbrk (s, "{[");
     if (!start) {
@@ -357,11 +378,13 @@ cairo_type1_font_subset_get_bbox (cairo_type1_font_subset_t *font)
     if (unlikely (status))
 	return status;
 
+    printf("/FontBBox %f %f %f %f\n", x_min, y_min, x_max, y_max);
     status = cairo_type1_font_subset_get_matrix (font, "/FontMatrix",
 						 &xx, &yx, &xy, &yy);
     if (unlikely (status))
 	return status;
 
+    printf("/FontMatrix %f %f %f %f\n", xx, yx, xy, yy);
     if (yy == 0.0)
 	return CAIRO_INT_STATUS_UNSUPPORTED;
 


More information about the cairo-commit mailing list