~ubuntu-branches/ubuntu/quantal/cairo/quantal-proposed

« back to all changes in this revision

Viewing changes to src/cairo-type1-subset.c

  • Committer: Stéphane Graber
  • Author(s): Till Kamppeter
  • Date: 2012-10-17 13:11:27 UTC
  • Revision ID: stgraber@ubuntu.com-20121017131127-e4mfz19w2e799v6p
Tags: 1.12.2-1ubuntu2.1
debian/patches/font-handling-fixes.patch: Fix several font handling bugs
in the PDF generator (LP: #1063618).

Show diffs side-by-side

added added

removed removed

Lines of Context:
114
114
 
115
115
    const char *rd, *nd, *np;
116
116
 
 
117
    int lenIV;
 
118
 
117
119
    char *type1_data;
118
120
    unsigned int type1_length;
119
121
    char *type1_end;
754
756
                                                charstring);
755
757
    end = charstring + encrypted_charstring_length;
756
758
 
757
 
    p = charstring + 4;
 
759
    p = charstring + font->lenIV;
758
760
 
759
761
    last_op_was_integer = FALSE;
760
762
 
778
780
                    font->build_stack.top_value < font->num_subrs)
779
781
                {
780
782
                    subr_num = font->build_stack.top_value;
 
783
                    font->build_stack.sp--;
781
784
                    font->subrs[subr_num].used = TRUE;
782
785
                    last_op_was_integer = FALSE;
783
786
                    status = cairo_type1_font_subset_parse_charstring (font,
1137
1140
{
1138
1141
    cairo_status_t status;
1139
1142
    const char *p, *subrs, *charstrings, *array_start, *array_end, *dict_start, *dict_end;
1140
 
    const char *closefile_token;
1141
 
    char buffer[32], *subr_count_end, *glyph_count_end;
1142
 
    int length;
 
1143
    const char *lenIV_start, *lenIV_end, *closefile_token;
 
1144
    char buffer[32], *lenIV_str, *subr_count_end, *glyph_count_end;
 
1145
    int ret, lenIV, length;
1143
1146
    const cairo_scaled_font_backend_t *backend;
1144
1147
    unsigned int i;
1145
1148
    int glyph, j;
1161
1164
     * subroutines and charstrings not required.
1162
1165
     */
1163
1166
 
 
1167
    /* Determine lenIV, the number of random characters at the start of
 
1168
       each encrypted charstring. The defaults is 4, but this can be
 
1169
       overridden in the private dict. */
 
1170
    font->lenIV = 4;
 
1171
    if ((lenIV_start = find_token (font->cleartext, font->cleartext_end, "/lenIV")) != NULL) {
 
1172
        lenIV_start += 6;
 
1173
        lenIV_end = find_token (lenIV_start, font->cleartext_end, "def");
 
1174
        if (lenIV_end == NULL)
 
1175
            return CAIRO_INT_STATUS_UNSUPPORTED;
 
1176
 
 
1177
        lenIV_str = malloc (lenIV_end - lenIV_start + 1);
 
1178
        if (unlikely (lenIV_str == NULL))
 
1179
            return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
1180
 
 
1181
        strncpy (lenIV_str, lenIV_start, lenIV_end - lenIV_start);
 
1182
        lenIV_str[lenIV_end - lenIV_start] = 0;
 
1183
 
 
1184
        ret = sscanf(lenIV_str, "%d", &lenIV);
 
1185
        free(lenIV_str);
 
1186
 
 
1187
        if (unlikely (ret <= 0))
 
1188
            return CAIRO_INT_STATUS_UNSUPPORTED;
 
1189
 
 
1190
        /* Apparently some fonts signal unencrypted charstrings with a negative lenIV,
 
1191
           though this is not part of the Type 1 Font Format specification.  See, e.g.
 
1192
           http://lists.gnu.org/archive/html/freetype-devel/2000-06/msg00064.html. */
 
1193
        if (unlikely (lenIV < 0))
 
1194
            return CAIRO_INT_STATUS_UNSUPPORTED;
 
1195
 
 
1196
        font->lenIV = lenIV;
 
1197
    }
 
1198
 
1164
1199
    /* Find start of Subrs */
1165
1200
    subrs = find_token (font->cleartext, font->cleartext_end, "/Subrs");
1166
1201
    if (subrs == NULL) {
1274
1309
            return status;
1275
1310
    }
1276
1311
 
 
1312
    /* Always include the first four subroutines in case the Flex/hint mechanism is
 
1313
     * being used. */
 
1314
    for (j = 0; j < MIN(font->num_subrs, 4); j++) {
 
1315
        font->subrs[j].used = TRUE;
 
1316
    }
 
1317
 
1277
1318
    closefile_token = find_token (dict_end, font->cleartext_end, "closefile");
1278
1319
    if (closefile_token == NULL)
1279
1320
        return CAIRO_INT_STATUS_UNSUPPORTED;