1
Description: Cherry-pick upstream bugfixes for LP: #1030357
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
9
--- cairo-1.12.2.orig/src/cairo-cff-subset.c
10
+++ cairo-1.12.2/src/cairo-cff-subset.c
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
15
* Copyright © 2006 Adrian Johnson
17
#include "cairo-scaled-font-subsets-private.h"
18
#include "cairo-truetype-subset-private.h"
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 {
30
+ double default_width;
31
+ double nominal_width;
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;
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)
50
+ struct lconv *locale_data;
51
+ const char *decimal_point;
52
+ int decimal_point_len;
58
- char *buf_end = buffer + sizeof (buf);
59
+ char *buf_end = buffer + sizeof (buffer);
61
+ locale_data = localeconv ();
62
+ decimal_point = locale_data->decimal_point;
63
+ decimal_point_len = strlen (decimal_point);
65
+ assert (decimal_point_len != 0);
66
+ assert (sizeof(buffer) + decimal_point_len < sizeof(buffer2));
69
while (buf + 2 < buf_end) {
70
@@ -312,7 +326,18 @@ decode_real (unsigned char *p, double *r
74
- if (sscanf(buffer, "%lf", real) != 1)
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);
86
+ if (sscanf(buf, "%lf", real) != 1)
90
@@ -886,8 +911,8 @@ cairo_cff_font_read_private_dict (cairo_
91
cairo_array_t *local_sub_index,
93
cairo_bool_t **local_subs_used,
96
+ double *default_width,
97
+ double *nominal_width,
101
@@ -922,12 +947,12 @@ cairo_cff_font_read_private_dict (cairo_
103
operand = cff_dict_get_operands (private_dict, DEFAULTWIDTH_OP, &i);
105
- decode_integer (operand, default_width);
106
+ decode_number (operand, default_width);
109
operand = cff_dict_get_operands (private_dict, NOMINALWIDTH_OP, &i);
111
- decode_integer (operand, nominal_width);
112
+ decode_number (operand, nominal_width);
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_
118
font->num_glyphs = _cairo_array_num_elements (&font->charstrings_index);
120
- operand = cff_dict_get_operands (font->top_dict, CHARSET_OP, &size);
121
- if (font->is_cid && !operand)
122
- return CAIRO_INT_STATUS_UNSUPPORTED;
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);
131
+ return CAIRO_INT_STATUS_UNSUPPORTED;
133
+ decode_integer (operand, &offset);
134
+ font->charset = font->data + offset;
135
+ if (font->charset >= font->data_end)
136
+ return CAIRO_INT_STATUS_UNSUPPORTED;
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;
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]);
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;