~ubuntu-branches/ubuntu/raring/cairo/raring

« back to all changes in this revision

Viewing changes to debian/patches/lp-#1030357.patch

  • Committer: Package Import Robot
  • Author(s): Stéphane Graber
  • Date: 2012-09-28 15:20:19 UTC
  • Revision ID: package-import@ubuntu.com-20120928152019-cobqis5072pxxfe4
Tags: 1.12.2-1ubuntu2
* Cherry-pick fixes from upstream (LP: #1030357)
  Thanks to Edward Donovan for the patch.
  - cff subsetting: widths can be floating point
  - cff: initialise variable to prevent valgrind warning
  - cff: use correct size for buffer
  - cff: convert '.' to locale specific decimal point before using sscanf
  - cff-subsetting: Ignore charset for non cid fonts

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Description: Cherry-pick upstream bugfixes for LP: #1030357
 
2
 
 
3
 - cff subsetting: widths can be floating point
 
4
 - cff: initialise variable to prevent valgrind warning
 
5
 - cff: use correct size for buffer
 
6
 - cff: convert '.' to locale specific decimal point before using sscanf
 
7
 - cff-subsetting: Ignore charset for non cid fonts
 
8
 
 
9
--- cairo-1.12.2.orig/src/cairo-cff-subset.c
 
10
+++ cairo-1.12.2/src/cairo-cff-subset.c
 
11
@@ -1,3 +1,4 @@
 
12
+/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */
 
13
 /* cairo - a vector graphics library with display and print output
 
14
  *
 
15
  * Copyright © 2006 Adrian Johnson
 
16
@@ -51,6 +52,7 @@
 
17
 #include "cairo-scaled-font-subsets-private.h"
 
18
 #include "cairo-truetype-subset-private.h"
 
19
 #include <string.h>
 
20
+#include <locale.h>
 
21
 
 
22
 /* CFF Dict Operators. If the high byte is 0 the command is encoded
 
23
  * with a single byte. */
 
24
@@ -151,8 +153,8 @@ typedef struct _cairo_cff_font {
 
25
     int                 units_per_em;
 
26
     int                 global_sub_bias;
 
27
     int                         local_sub_bias;
 
28
-    int                  default_width;
 
29
-    int                  nominal_width;
 
30
+    double               default_width;
 
31
+    double               nominal_width;
 
32
 
 
33
     /* CID Font Data */
 
34
     int                 *fdselect;
 
35
@@ -161,8 +163,8 @@ typedef struct _cairo_cff_font {
 
36
     cairo_hash_table_t **fd_private_dict;
 
37
     cairo_array_t       *fd_local_sub_index;
 
38
     int                        *fd_local_sub_bias;
 
39
-    int                 *fd_default_width;
 
40
-    int                 *fd_nominal_width;
 
41
+    double              *fd_default_width;
 
42
+    double              *fd_nominal_width;
 
43
 
 
44
     /* Subsetted Font Data */
 
45
     char                *subset_font_name;
 
46
@@ -293,10 +295,22 @@ decode_nibble (int n, char *buf)
 
47
 static unsigned char *
 
48
 decode_real (unsigned char *p, double *real)
 
49
 {
 
50
+    struct lconv *locale_data;
 
51
+    const char *decimal_point;
 
52
+    int decimal_point_len;
 
53
     int n;
 
54
     char buffer[100];
 
55
+    char buffer2[200];
 
56
+    char *q;
 
57
     char *buf = buffer;
 
58
-    char *buf_end = buffer + sizeof (buf);
 
59
+    char *buf_end = buffer + sizeof (buffer);
 
60
+
 
61
+    locale_data = localeconv ();
 
62
+    decimal_point = locale_data->decimal_point;
 
63
+    decimal_point_len = strlen (decimal_point);
 
64
+
 
65
+    assert (decimal_point_len != 0);
 
66
+    assert (sizeof(buffer) + decimal_point_len < sizeof(buffer2));
 
67
 
 
68
     p++;
 
69
     while (buf + 2 < buf_end) {
 
70
@@ -312,7 +326,18 @@ decode_real (unsigned char *p, double *r
 
71
     };
 
72
     *buf = 0;
 
73
 
 
74
-    if (sscanf(buffer, "%lf", real) != 1)
 
75
+    buf = buffer;
 
76
+    if (strchr (buffer, '.')) {
 
77
+        q = strchr (buffer, '.');
 
78
+        strncpy (buffer2, buffer, q - buffer);
 
79
+        buf = buffer2 + (q - buffer);
 
80
+        strncpy (buf, decimal_point, decimal_point_len);
 
81
+        buf += decimal_point_len;
 
82
+        strcpy (buf, q + 1);
 
83
+        buf = buffer2;
 
84
+    }
 
85
+
 
86
+    if (sscanf(buf, "%lf", real) != 1)
 
87
         *real = 0.0;
 
88
 
 
89
     return p;
 
90
@@ -886,8 +911,8 @@ cairo_cff_font_read_private_dict (cairo_
 
91
                                   cairo_array_t      *local_sub_index,
 
92
                                   int                *local_sub_bias,
 
93
                                   cairo_bool_t      **local_subs_used,
 
94
-                                  int                *default_width,
 
95
-                                  int                *nominal_width,
 
96
+                                  double             *default_width,
 
97
+                                  double             *nominal_width,
 
98
                                   unsigned char      *ptr,
 
99
                                   int                 size)
 
100
 {
 
101
@@ -922,12 +947,12 @@ cairo_cff_font_read_private_dict (cairo_
 
102
     *default_width = 0;
 
103
     operand = cff_dict_get_operands (private_dict, DEFAULTWIDTH_OP, &i);
 
104
     if (operand)
 
105
-        decode_integer (operand, default_width);
 
106
+        decode_number (operand, default_width);
 
107
 
 
108
     *nominal_width = 0;
 
109
     operand = cff_dict_get_operands (private_dict, NOMINALWIDTH_OP, &i);
 
110
     if (operand)
 
111
-        decode_integer (operand, nominal_width);
 
112
+        decode_number (operand, nominal_width);
 
113
 
 
114
     num_subs = _cairo_array_num_elements (local_sub_index);
 
115
     *local_subs_used = calloc (num_subs, sizeof (cairo_bool_t));
 
116
@@ -1178,14 +1203,16 @@ cairo_cff_font_read_top_dict (cairo_cff_
 
117
         goto fail;
 
118
     font->num_glyphs = _cairo_array_num_elements (&font->charstrings_index);
 
119
 
 
120
-    operand = cff_dict_get_operands (font->top_dict, CHARSET_OP, &size);
 
121
-    if (font->is_cid && !operand)
 
122
-       return CAIRO_INT_STATUS_UNSUPPORTED;
 
123
-
 
124
-    decode_integer (operand, &offset);
 
125
-    font->charset = font->data + offset;
 
126
-    if (font->charset >= font->data_end)
 
127
-       return CAIRO_INT_STATUS_UNSUPPORTED;
 
128
+    if (font->is_cid) {
 
129
+        operand = cff_dict_get_operands (font->top_dict, CHARSET_OP, &size);
 
130
+        if (!operand)
 
131
+             return CAIRO_INT_STATUS_UNSUPPORTED;
 
132
+
 
133
+        decode_integer (operand, &offset);
 
134
+        font->charset = font->data + offset;
 
135
+        if (font->charset >= font->data_end)
 
136
+             return CAIRO_INT_STATUS_UNSUPPORTED;
 
137
+    }
 
138
 
 
139
     if (!font->is_opentype)
 
140
         cairo_cff_font_read_font_metrics (font, font->top_dict);
 
141
@@ -1442,9 +1469,8 @@ type2_decode_integer (unsigned char *p,
 
142
         *integer = -(p[0] - 251) * 256 - p[1] - 108;
 
143
         p += 2;
 
144
     } else { /* *p == 255 */
 
145
-    /* This actually a 16.16 fixed-point number however we are not interested in
 
146
-     * the value of fixed-point numbers. */
 
147
-        *integer = (p[1] << 24) | (p[2] << 16) | (p[3] << 8) | p[4];
 
148
+        /* 16.16 fixed-point number. The fraction is ignored. */
 
149
+        *integer = (int16_t)((p[1] << 8) | p[2]);
 
150
         p += 5;
 
151
     }
 
152
     return p;
 
153
@@ -3167,6 +3193,7 @@ _cairo_cff_font_fallback_create (cairo_s
 
154
     cff_index_init (&font->strings_subset_index);
 
155
     font->global_subs_used = NULL;
 
156
     font->local_subs_used = NULL;
 
157
+    font->subset_subroutines = FALSE;
 
158
     font->fdselect = NULL;
 
159
     font->fd_dict = NULL;
 
160
     font->fd_private_dict = NULL;