Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 629708 | Differences between
and this patch

Collapse All | Expand All

(-)cups-filters-1.17.2/filter/pdf.cxx (-237 / +142 lines)
Lines 124-216 Link Here
124
{
124
{
125
    XRef *xref = doc->getXRef();
125
    XRef *xref = doc->getXRef();
126
    Ref *pageref = doc->getCatalog()->getPageRef(page);
126
    Ref *pageref = doc->getCatalog()->getPageRef(page);
127
    Object dict, lenobj, stream, streamrefobj;
127
    Object streamrefobj;
128
    Object pageobj, contents;
129
    Object array;
130
    Ref r;
128
    Ref r;
131
129
132
    xref->fetch(pageref->num, pageref->gen, &pageobj);
130
    Object pageobj = xref->fetch(pageref->num, pageref->gen);
133
    if (!pageobj.isDict() || !pageobj.dictLookupNF("Contents", &contents)) {
131
    Object contents = pageobj.dictLookupNF("Contents");
134
        fprintf(stderr, "Error: malformed pdf\n");
132
    if (!pageobj.isDict() || contents.isNull()) {
133
        fprintf(stderr, "Error: malformed pdf (in pdf_prepend_stream neither pageobj is a dict nor were Contents found)\n");
135
        return;
134
        return;
136
    }
135
    }
137
136
138
    if (contents.isRef())
137
    if (contents.isRef())
139
        xref->fetch(contents.getRefNum(), contents.getRefGen(), &contents);
138
        contents = xref->fetch(contents.getRefNum(), contents.getRefGen());
140
139
141
    lenobj.initInt(len);
140
    Dict *dict = new Dict(xref);
142
    dict.initDict(xref);
141
    dict->set("Length", Object((int)len));
143
    dict.dictSet("Length", &lenobj);
142
    MemStream *ms = new MemStream(buf, 0, len, Object(dict));
144
    stream.initStream(new MemStream(buf, 0, len, &dict));
143
    Object stream = Object(static_cast<Stream*>(ms));
145
144
146
    r = xref->addIndirectObject(&stream);
145
    r = xref->addIndirectObject(&stream);
147
    streamrefobj.initRef(r.num, r.gen);
148
146
149
    array.initArray(xref);
147
    Array *array = new Array(xref);
150
    array.arrayAdd(&streamrefobj);
148
    array->add(Object(r.num, r.gen));
151
149
152
    if (contents.isStream()) {
150
    if (contents.isStream()) {
153
        pageobj.dictLookupNF("Contents", &contents); // streams must be indirect, i.e. not fetch()-ed
151
	// streams must be indirect, i.e. not fetch()-ed
154
        array.arrayAdd(&contents);
152
        array->add(Object(pageobj.dictLookupNF("Contents")));
155
    }
153
    }
156
    else if (contents.isArray()) {
154
    else if (contents.isArray()) {
157
        int i, len = contents.arrayGetLength();
155
        int i, len = contents.arrayGetLength();
158
        Object obj;
159
        for (i = 0; i < len; i++) {
156
        for (i = 0; i < len; i++) {
160
            contents.arrayGetNF(i, &obj);
157
            array->add(Object(contents.arrayGetNF(i)));
161
            array.arrayAdd(&obj);
162
        }
158
        }
163
    }
159
    }
164
    else
160
    else
165
        fprintf(stderr, "Error: malformed pdf\n");
161
        fprintf(stderr, "Error: malformed pdf (not stream or array in pdf_prepend_stream)\n");
166
162
167
    pageobj.dictSet("Contents", &array);
163
    pageobj.dictSet("Contents", Object(array));
168
164
169
    xref->setModifiedObject(&pageobj, *pageref);
165
    xref->setModifiedObject(&pageobj, *pageref);
170
    pageobj.free();
166
//    pageobj.free();
171
}
167
}
172
168
173
174
static Object * name_object(const char *s)
175
{
176
    Object *o = new Object();
177
    o->initName((char *)s);
178
    return o;
179
}
180
181
/*
182
 * Create new PDF integer type object.
183
 */
184
static Object * int_object(int i)
185
{
186
    Object *o = new Object();
187
    o->initInt(i);
188
    return o;
189
}
190
169
191
static Object * get_resource_dict(XRef *xref,
170
static Object * get_resource_dict(XRef *xref,
192
                                  Dict *pagedict,
171
                                  Dict *pagedict,
193
                                  Object *resdict,
172
                                  Object *resdict,
194
                                  Ref *resref)
173
                                  Ref *resref)
195
{
174
{
196
    Object res;
197
175
198
    /* TODO resource dict can also be inherited */
176
    /* TODO resource dict can also be inherited */
199
    if (!pagedict->lookupNF("Resources", &res))
177
    Object res = pagedict->lookupNF("Resources");
200
        return NULL;
201
178
202
    if (res.isRef()) {
179
    if (res.isRef()) {
203
        *resref = res.getRef();
180
        *resref = res.getRef();
204
        xref->fetch(resref->num, resref->gen, resdict);
181
        *resdict = xref->fetch(resref->num, resref->gen);
205
    }
182
    }
206
    else if (res.isDict()) {
183
    else if (res.isDict()) {
207
        res.copy(resdict);
184
        *resdict = res.copy();
208
        resref->num = 0;
185
        resref->num = 0;
209
    }
186
    }
210
    else
187
    else
211
        resdict = NULL;
188
        resdict = NULL;
212
189
213
    res.free();
190
//    res.free();
214
    return resdict;
191
    return resdict;
215
}
192
}
216
193
Lines 221-254 Link Here
221
{
198
{
222
    XRef *xref = doc->getXRef();
199
    XRef *xref = doc->getXRef();
223
    Ref *pageref = doc->getCatalog()->getPageRef(page);
200
    Ref *pageref = doc->getCatalog()->getPageRef(page);
224
    Object pageobj, font, fonts;
225
201
226
    Object resdict;
202
    Object resdict;
227
    Ref resref;
203
    Ref resref;
228
204
229
    xref->fetch(pageref->num, pageref->gen, &pageobj);
205
    Object pageobj = xref->fetch(pageref->num, pageref->gen);
230
    if (!pageobj.isDict()) {
206
    if (!pageobj.isDict()) {
231
        fprintf(stderr, "Error: malformed pdf\n");
207
        fprintf(stderr, "Error: malformed pdf (not a dict in pdf_add_type1_font)\n");
232
        return;
208
        return;
233
    }
209
    }
234
210
235
    if (!get_resource_dict(xref, pageobj.getDict(), &resdict, &resref)) {
211
    if (!get_resource_dict(xref, pageobj.getDict(), &resdict, &resref)) {
236
        fprintf(stderr, "Error: malformed pdf\n");
212
        fprintf(stderr, "Error: malformed pdf (could not get resource dict in pdf_add_type1_font)\n");
237
        pageobj.free();
213
//        pageobj.free();
238
        return;
214
        return;
239
    }
215
    }
240
216
241
    font.initDict(xref);
217
    Object font = Object(new Dict(xref));
242
    font.dictSet("Type", name_object("Font"));
218
243
    font.dictSet("Subtype", name_object("Type1"));
219
    font.dictSet("Type", Object(objName,"Font"));
244
    font.dictSet("BaseFont", name_object(name));
220
    font.dictSet("Subtype", Object(objName,"Type1"));
221
    font.dictSet("BaseFont", Object(objName,name));
245
    xref->addIndirectObject(&font);
222
    xref->addIndirectObject(&font);
246
223
247
    resdict.dictLookupNF("Font", &fonts);
224
    Object fonts = resdict.dictLookupNF("Font");
248
    if (fonts.isNull()) {
225
    if (fonts.isNull()) {
249
        /* Create new font dic obj in page's resources */
226
        /* Create new font dic obj in page's resources */
250
        fonts.initDict(xref);
227
        resdict.dictSet("Font", Object(new Dict(xref)));
251
        resdict.dictSet("Font", &fonts);
252
    }
228
    }
253
229
254
    Object *fonts_dic;
230
    Object *fonts_dic;
Lines 259-265 Link Here
259
        fonts_dic = &fonts;
235
        fonts_dic = &fonts;
260
    } else if ( fonts.isRef() ) {
236
    } else if ( fonts.isRef() ) {
261
        /* "Font" resource is indirect reference object */
237
        /* "Font" resource is indirect reference object */
262
        xref->fetch(fonts.getRefNum(), fonts.getRefGen(), &dereferenced_obj);
238
        dereferenced_obj = xref->fetch(fonts.getRefNum(), fonts.getRefGen());
263
        fonts_dic = &dereferenced_obj;
239
        fonts_dic = &dereferenced_obj;
264
    }
240
    }
265
241
Lines 269-275 Link Here
269
    }
245
    }
270
246
271
    /* Add new entry to "Font" resource */
247
    /* Add new entry to "Font" resource */
272
    fonts_dic->dictSet("bannertopdf-font", &font);
248
//    TODO Malc - can't make this compile...
249
//    fonts_dic->dictSet("bannertopdf-font", &font);
273
250
274
    /* Notify poppler about changes */
251
    /* Notify poppler about changes */
275
    if ( fonts.isRef() ) {
252
    if ( fonts.isRef() ) {
Lines 281-287 Link Here
281
    else
258
    else
282
        xref->setModifiedObject(&resdict, resref);
259
        xref->setModifiedObject(&resdict, resref);
283
260
284
    pageobj.free();
261
//    pageobj.free();
285
}
262
}
286
263
287
264
Lines 289-315 Link Here
289
                             const char *key,
266
                             const char *key,
290
                             float rect[4])
267
                             float rect[4])
291
{
268
{
292
    Object o;
293
    Array *array;
269
    Array *array;
294
    int i;
270
    int i;
295
271
296
    if (!dict->dictLookup(key, &o))
272
    Object o = dict->dictLookup(key);
297
        return false;
298
273
299
    if (!o.isArray()) {
274
    if (!o.isArray()) {
300
        o.free();
301
        return false;
275
        return false;
302
    }
276
    }
303
277
304
    array = o.getArray();
278
    array = o.getArray();
305
    for (i = 0; i < 4; i++) {
279
    for (i = 0; i < 4; i++) {
306
        Object el;
280
        Object el = array->get(i);
307
        if (array->get(i, &el) && el.isNum())
281
        if (el.isNum())
308
            rect[i] = el.getNum();
282
            rect[i] = el.getNum();
309
        el.free();
310
    }
283
    }
311
284
312
    o.free();
313
    return i == 4;
285
    return i == 4;
314
}
286
}
315
287
Lines 319-336 Link Here
319
                          const char *key,
291
                          const char *key,
320
                          float rect[4])
292
                          float rect[4])
321
{
293
{
322
    Object array;
323
    int i;
294
    int i;
324
295
    Array *array = new Array(xref);
325
    array.initArray(xref);
326
296
327
    for (i = 0; i < 4; i++) {
297
    for (i = 0; i < 4; i++) {
328
        Object el;
298
        array->add(Object((double)rect[i]));
329
        el.initReal(rect[i]);
330
        array.arrayAdd(&el);
331
    }
299
    }
332
300
333
    dict->dictSet(key, &array);
301
    dict->dictSet(key, Object(array));
334
}
302
}
335
303
336
304
Lines 357-367 Link Here
357
{
325
{
358
    XRef *xref = doc->getXRef();
326
    XRef *xref = doc->getXRef();
359
    Ref *pageref = doc->getCatalog()->getPageRef(page);
327
    Ref *pageref = doc->getCatalog()->getPageRef(page);
360
    Object pageobj;
361
    float mediabox[4] = { 0.0, 0.0, width, length };
328
    float mediabox[4] = { 0.0, 0.0, width, length };
362
    float old_mediabox[4];
329
    float old_mediabox[4];
363
330
364
    xref->fetch(pageref->num, pageref->gen, &pageobj);
331
    Object pageobj = xref->fetch(pageref->num, pageref->gen);
365
    if (!pageobj.isDict()) {
332
    if (!pageobj.isDict()) {
366
        fprintf(stderr, "Error: malformed pdf\n");
333
        fprintf(stderr, "Error: malformed pdf\n");
367
        return;
334
        return;
Lines 381-387 Link Here
381
    dict_set_rect (xref, &pageobj, "BleedBox", mediabox);
348
    dict_set_rect (xref, &pageobj, "BleedBox", mediabox);
382
349
383
    xref->setModifiedObject(&pageobj, *pageref);
350
    xref->setModifiedObject(&pageobj, *pageref);
384
    pageobj.free();
385
}
351
}
386
352
387
353
Lines 391-414 Link Here
391
{
357
{
392
    XRef *xref = doc->getXRef();
358
    XRef *xref = doc->getXRef();
393
    Ref *pageref = doc->getCatalog()->getPageRef(pagenr);
359
    Ref *pageref = doc->getCatalog()->getPageRef(pagenr);
394
    Object page, parentref, parent, kids, ref, countobj;
395
    int i;
360
    int i;
396
361
397
    xref->fetch(pageref->num, pageref->gen, &page);
362
    Object page = xref->fetch(pageref->num, pageref->gen);
398
    if (!page.isDict("Page")) {
363
    if (!page.isDict("Page")) {
399
        fprintf(stderr, "Error: malformed pdf (invalid Page object)\n");
364
        fprintf(stderr, "Error: malformed pdf (invalid Page object)\n");
400
        return;
365
        return;
401
    }
366
    }
402
367
403
    page.dictLookupNF("Parent", &parentref);
368
    Object parentref = page.dictLookupNF("Parent");
404
    parentref.fetch(xref, &parent);
369
    Object parent = parentref.fetch(xref);
405
    if (!parent.isDict("Pages")) {
370
    if (!parent.isDict("Pages")) {
406
        fprintf(stderr, "Error: malformed pdf (Page.Parent must point to a "
371
        fprintf(stderr, "Error: malformed pdf (Page.Parent must point to a "
407
                        "Pages object)\n");
372
                        "Pages object)\n");
408
        return;
373
        return;
409
    }
374
    }
410
375
411
    parent.dictLookup("Kids", &kids);
376
    Object kids = parent.dictLookup("Kids");
412
    if (!kids.isArray()) {
377
    if (!kids.isArray()) {
413
        fprintf(stderr, "Error: malformed pdf (Pages.Kids must be an array)\n");
378
        fprintf(stderr, "Error: malformed pdf (Pages.Kids must be an array)\n");
414
        return;
379
        return;
Lines 418-433 Link Here
418
    // object to the end of the array
383
    // object to the end of the array
419
    // Note: We must make a (shallow) copy of the page object to avoid loops in
384
    // Note: We must make a (shallow) copy of the page object to avoid loops in
420
    // the pages tree (not supported by major pdf implementations).
385
    // the pages tree (not supported by major pdf implementations).
386
    Array *array = kids.getArray();
387
421
    for (i = 1; i < count; i++) {
388
    for (i = 1; i < count; i++) {
422
        Ref r = xref->addIndirectObject(&page);
389
        Ref r = xref->addIndirectObject(&page);
423
        ref.initRef(r.num, r.gen);
390
        array->add(Object(r.num,r.gen));
424
        kids.arrayAdd(&ref);
425
        ref.free();
426
    }
391
    }
427
392
428
    countobj.initInt(count);
393
    parent.dictSet("Count", Object((int)count));
429
    parent.dictSet("Count", &countobj);
430
    countobj.free();
431
394
432
    xref->setModifiedObject(&parent, parentref.getRef());
395
    xref->setModifiedObject(&parent, parentref.getRef());
433
}
396
}
Lines 521-529 Link Here
521
        fprintf(stderr, "Can't get page from PDF tamplate file.\n");
484
        fprintf(stderr, "Can't get page from PDF tamplate file.\n");
522
        return 0;
485
        return 0;
523
    }
486
    }
524
    Object pageobj;
525
    Ref pageref = page->getRef();
487
    Ref pageref = page->getRef();
526
    xref->fetch(pageref.num, pageref.gen, &pageobj);
488
    Object pageobj =  xref->fetch(pageref.num, pageref.gen);
527
489
528
    const char *font_size = lookup_opt(opt, "banner-font-size");
490
    const char *font_size = lookup_opt(opt, "banner-font-size");
529
    if ( ! font_size ) {
491
    if ( ! font_size ) {
Lines 613-621 Link Here
613
        appearance->append(" Tf");
575
        appearance->append(" Tf");
614
576
615
        /* Modify field's appearance */
577
        /* Modify field's appearance */
616
        Object appearance_obj;
578
        field_obj->getDict()->set("DA", Object(appearance));
617
        appearance_obj.initString(appearance);
618
        field_obj->getDict()->set("DA", &appearance_obj);
619
579
620
        /*
580
        /*
621
         * Create /AP - entry stuff.
581
         * Create /AP - entry stuff.
Lines 652-710 Link Here
652
        appearance_stream->append("ET\n");
612
        appearance_stream->append("ET\n");
653
        appearance_stream->append("EMC\n");
613
        appearance_stream->append("EMC\n");
654
614
655
        Object appearance_stream_dic;
615
        Dict *appearance_stream_dic = new Dict(xref);
656
        appearance_stream_dic.initDict(xref);
657
616
658
        /*
617
        /*
659
         * Appearance stream dic.
618
         * Appearance stream dic.
660
         * See: 4.9 Form XObjects
619
         * See: 4.9 Form XObjects
661
         * TABLE 4.41 Additional entries specific to a type 1 form dictionary
620
         * TABLE 4.41 Additional entries specific to a type 1 form dictionary
662
         */
621
         */
663
        appearance_stream_dic.dictSet("Type", name_object("XObject"));
622
        appearance_stream_dic->set("Type", Object(objName,"XObject"));
664
        appearance_stream_dic.dictSet("Subtype", name_object("Form"));
623
        appearance_stream_dic->set("Subtype", Object(objName,"Form"));
665
        appearance_stream_dic.dictSet("FormType", int_object(1));
624
        appearance_stream_dic->set("FormType", Object((int)1));
666
        Object obj_ref_x;
625
        appearance_stream_dic->set("Resources", Object(resref.num, resref.gen));
667
        obj_ref_x.initRef(resref.num, resref.gen);
668
        appearance_stream_dic.dictSet("Resources", &obj_ref_x);
669
626
670
        /* BBox array: TODO. currently out of the head. */
627
        /* BBox array: TODO. currently out of the head. */
671
        Object array;
628
	Array *array = new Array(xref);
672
        array.initArray(xref);
629
        array->add(Object((double)0));
673
        Object el;
630
        array->add(Object((double)0));
674
        el.initReal(0);
631
        array->add(Object((double)237));
675
        array.arrayAdd(&el);
632
        array->add(Object((double)25));
676
        el.initReal(0);
633
        appearance_stream_dic->set("BBox", Object(array));
677
        array.arrayAdd(&el);
634
        appearance_stream_dic->set("Length", Object((int)appearance_stream->getLength()));
678
        el.initReal(237);
679
        array.arrayAdd(&el);
680
        el.initReal(25);
681
        array.arrayAdd(&el);
682
        appearance_stream_dic.dictSet("BBox", &array);
683
        appearance_stream_dic.dictSet("Length", int_object(appearance_stream->getLength()));
684
635
685
        MemStream *mem_stream = new MemStream(appearance_stream->getCString(),
636
        MemStream *mem_stream = new MemStream(appearance_stream->getCString(),
686
                0, appearance_stream->getLength(), &appearance_stream_dic);
637
                0, appearance_stream->getLength(), Object(appearance_stream_dic));
687
638
688
        /* Make obj stream */
639
        /* Make obj stream */
689
        Object stream;
640
        Object stream = Object(static_cast<Stream*>(mem_stream));
690
        stream.initStream(mem_stream);
691
641
692
        Ref r;
642
        Ref r;
693
        r = xref->addIndirectObject(&stream);
643
        r = xref->addIndirectObject(&stream);
694
644
695
        /* Update Xref table */
645
        /* Update Xref table */
696
        Object obj_ref;
697
        obj_ref.initRef(r.num, r.gen);
698
646
699
        /* 
647
        /* 
700
         * Fill Annotation's appearance streams dic /AP
648
         * Fill Annotation's appearance streams dic /AP
701
         * See: 8.4.4 Appearance Streams
649
         * See: 8.4.4 Appearance Streams
702
         */
650
         */
703
        Object appearance_streams_dic;
651
        Dict *appearance_streams_dic = new Dict(xref);
704
        appearance_streams_dic.initDict(xref);
652
        appearance_streams_dic->set("N", Object(r.num, r.gen));
705
        appearance_streams_dic.dictSet("N", &obj_ref);
706
653
707
        field_obj->getDict()->set("AP", &appearance_streams_dic);
654
        field_obj->getDict()->set("AP", Object(appearance_streams_dic));
708
655
709
        /* Notify poppler about changes */
656
        /* Notify poppler about changes */
710
        xref->setModifiedObject(field_obj, field_ref);
657
        xref->setModifiedObject(field_obj, field_ref);
Lines 721-744 Link Here
721
     * OpenOffice - by default sets it to 'true'.
668
     * OpenOffice - by default sets it to 'true'.
722
     */
669
     */
723
    Object *obj_form = catalog->getAcroForm();
670
    Object *obj_form = catalog->getAcroForm();
724
    Object obj1;
671
    obj_form->dictSet("NeedAppearances", Object(gFalse));
725
    obj1.initBool(gFalse);
726
    obj_form->dictSet("NeedAppearances", &obj1);
727
    /* Add AccroForm as indirect obj */
672
    /* Add AccroForm as indirect obj */
728
    Ref ref_form = xref->addIndirectObject(obj_form);
673
    Ref ref_form = xref->addIndirectObject(obj_form);
729
674
730
    /*
675
    /*
731
     * So update Catalog object.
676
     * So update Catalog object.
732
     */
677
     */
733
    Object* catObj = new Object();
678
    Object catObj = xref->getCatalog();
734
    catObj = xref->getCatalog(catObj);
735
    Ref catRef;
679
    Ref catRef;
736
    catRef.gen = xref->getRootGen();
680
    catRef.gen = xref->getRootGen();
737
    catRef.num = xref->getRootNum();
681
    catRef.num = xref->getRootNum();
738
    Object obj2;
682
    catObj.dictSet("AcroForm", Object(ref_form.num, ref_form.gen));
739
    obj2.initRef(ref_form.num, ref_form.gen);
683
    xref->setModifiedObject(&catObj, catRef);
740
    catObj->dictSet("AcroForm", &obj2);
741
    xref->setModifiedObject(catObj, catRef);
742
684
743
    /* Success */
685
    /* Success */
744
    return 1;
686
    return 1;
Lines 779-809 Link Here
779
    XRef *xref = doc->getXRef();
721
    XRef *xref = doc->getXRef();
780
722
781
    /* Font dictionary object for embeded font */
723
    /* Font dictionary object for embeded font */
782
    Object f_dic;
724
    Dict *f_dic = new Dict(xref);
783
    f_dic.initDict(xref);
725
    f_dic->set("Type", Object(objName,"Font"));
784
    f_dic.dictSet("Type", name_object("Font"));
785
726
786
    /* Stream lenght */
727
    /* Stream lenght */
787
    f_dic.dictSet("Length", int_object(outlen));
728
    f_dic->set("Length", Object((int)outlen));
788
729
789
    /* Lenght for EMB_FMT_TTF font type */
730
    /* Lenght for EMB_FMT_TTF font type */
790
    if ( Font->outtype == EMB_FMT_TTF ) {
731
    if ( Font->outtype == EMB_FMT_TTF ) {
791
        f_dic.dictSet("Length1", int_object(outlen));
732
        f_dic->set("Length1", Object((int)outlen));
792
    }
733
    }
793
734
794
    /* Add font subtype */
735
    /* Add font subtype */
795
    const char *subtype = emb_pdf_get_fontfile_subtype(Font);
736
    const char *subtype = emb_pdf_get_fontfile_subtype(Font);
796
    if ( subtype ) {
737
    if ( subtype ) {
797
        f_dic.dictSet("Subtype", name_object(copyString(subtype)));
738
        f_dic->set("Subtype", Object(objName,copyString(subtype)));
798
    }
739
    }
799
740
800
    /* Create memory stream font. Add it to font dic. */
741
    /* Create memory stream font. Add it to font dic. */
801
    MemStream *mem_stream = new MemStream(font_stream->getCString(),
742
    MemStream *mem_stream = new MemStream(font_stream->getCString(),
802
            0, outlen, &f_dic);
743
            0, outlen, Object(f_dic));
803
744
804
    /* Make obj stream */
745
    /* Make obj stream */
805
    Object stream;
746
    Object stream = Object(static_cast<Stream*>(mem_stream));
806
    stream.initStream(mem_stream);
807
747
808
    Ref r;
748
    Ref r;
809
749
Lines 811-821 Link Here
811
    r = xref->addIndirectObject(&stream);
751
    r = xref->addIndirectObject(&stream);
812
752
813
    /* Get page object */
753
    /* Get page object */
814
    Object pageobj;
815
    Ref pageref = page->getRef();
754
    Ref pageref = page->getRef();
816
    xref->fetch(pageref.num, pageref.gen, &pageobj);
755
    Object pageobj = xref->fetch(pageref.num, pageref.gen);
817
    if (!pageobj.isDict()) {
756
    if (!pageobj.isDict()) {
818
        fprintf(stderr, "Error: malformed pdf.\n");
757
        fprintf(stderr, "Error: malformed pdf. (in pdf_embed_font pags is not a dict)\n");
819
        return 0;
758
        return 0;
820
    }
759
    }
821
760
Lines 824-842 Link Here
824
    Ref resref;
763
    Ref resref;
825
    Object *ret = get_resource_dict(xref, pageobj.getDict(), &resdict, &resref);
764
    Object *ret = get_resource_dict(xref, pageobj.getDict(), &resdict, &resref);
826
    if ( !ret ) {
765
    if ( !ret ) {
827
        fprintf(stderr, "Error: malformed pdf\n");
766
        fprintf(stderr, "Error: malformed pdf. (in pdf_embed_font could not get resource dict\n");
828
        pageobj.free();
829
        return 0;
767
        return 0;
830
    }
768
    }
831
769
832
    /* Dictionary for all fonts in page's resources */
770
    /* Dictionary for all fonts in page's resources */
833
    Object fonts;
771
    Object fonts = resdict.dictLookupNF("Font");
834
835
    resdict.dictLookupNF("Font", &fonts);
836
    if (fonts.isNull()) {
772
    if (fonts.isNull()) {
837
        /* Create new one, if doesn't exists */
773
        /* Create new one, if doesn't exists */
838
        fonts.initDict(xref);
774
	Dict* d = new Dict(xref);
839
        resdict.dictSet("Font", &fonts);
775
        resdict.dictSet("Font", Object(d));
776
	fonts = Object(d);
840
        fprintf(stderr, "Create new font dict in page's resources.\n");
777
        fprintf(stderr, "Create new font dict in page's resources.\n");
841
    }
778
    }
842
779
Lines 865-872 Link Here
865
    r = xref->addIndirectObject(cidfont_resource_dic);
802
    r = xref->addIndirectObject(cidfont_resource_dic);
866
803
867
    /* r - cid resource dic */
804
    /* r - cid resource dic */
868
    Object font_res_obj_ref;
869
    font_res_obj_ref.initRef(r.num, r.gen);
870
805
871
    Object *fonts_dic;
806
    Object *fonts_dic;
872
    Object dereferenced_obj;
807
    Object dereferenced_obj;
Lines 876-882 Link Here
876
        fonts_dic = &fonts;
811
        fonts_dic = &fonts;
877
    } else if ( fonts.isRef() ) {
812
    } else if ( fonts.isRef() ) {
878
        /* "Font" resource is indirect reference object */
813
        /* "Font" resource is indirect reference object */
879
        xref->fetch(fonts.getRefNum(), fonts.getRefGen(), &dereferenced_obj);
814
        dereferenced_obj = xref->fetch(fonts.getRefNum(), fonts.getRefGen());
880
        fonts_dic = &dereferenced_obj;
815
        fonts_dic = &dereferenced_obj;
881
    }
816
    }
882
817
Lines 886-892 Link Here
886
    }
821
    }
887
822
888
    /* Add to fonts dic new font */
823
    /* Add to fonts dic new font */
889
    fonts_dic->dictSet("stanv_font", &font_res_obj_ref);
824
    fonts_dic->dictSet("stanv_font", Object(r.num, r.gen));
890
825
891
    /* Notify poppler about changes in fonts dic */
826
    /* Notify poppler about changes in fonts dic */
892
    if ( fonts.isRef() ) {
827
    if ( fonts.isRef() ) {
Lines 897-904 Link Here
897
    xref->setModifiedObject(&resdict, resref);
832
    xref->setModifiedObject(&resdict, resref);
898
    fprintf(stderr, "Resource dict was changed.\n");
833
    fprintf(stderr, "Resource dict was changed.\n");
899
834
900
    pageobj.free();
901
902
    /* Success */
835
    /* Success */
903
    return 1;
836
    return 1;
904
}
837
}
Lines 1104-1168 Link Here
1104
    XRef *xref = doc->getXRef();
1037
    XRef *xref = doc->getXRef();
1105
1038
1106
    /* Font dictionary for embeded font */
1039
    /* Font dictionary for embeded font */
1107
    Object *dic = new Object();
1040
    Object *dic = new Object( new Dict(xref));
1108
    dic->initDict(xref);
1109
1041
1110
    dic->dictSet("Type", name_object("FontDescriptor"));
1042
    dic->dictSet("Type", Object(objName,"FontDescriptor"));
1111
    dic->dictSet(
1043
    dic->dictSet(
1112
            "FontName",
1044
            "FontName",
1113
            name_object(copyString(emb_pdf_escape_name(fdes->fontname,-1))));
1045
            Object(objName,copyString(emb_pdf_escape_name(fdes->fontname,-1))));
1114
    dic->dictSet("Flags", int_object(fdes->flags));
1046
    dic->dictSet("Flags", Object((int)fdes->flags));
1115
    dic->dictSet("ItalicAngle", int_object(fdes->italicAngle));
1047
    dic->dictSet("ItalicAngle", Object((int)fdes->italicAngle));
1116
    dic->dictSet("Ascent", int_object(fdes->ascent));
1048
    dic->dictSet("Ascent", Object((int)fdes->ascent));
1117
    dic->dictSet("Descent", int_object(fdes->descent));
1049
    dic->dictSet("Descent", Object((int)fdes->descent));
1118
    dic->dictSet("CapHeight", int_object(fdes->capHeight));
1050
    dic->dictSet("CapHeight", Object((int)fdes->capHeight));
1119
    dic->dictSet("StemV", int_object(fdes->stemV));
1051
    dic->dictSet("StemV", Object((int)fdes->stemV));
1120
1052
1121
    /* FontBox array */
1053
    /* FontBox array */
1122
    Object array;
1054
    Array *array = new Array(xref);
1123
    array.initArray(xref);
1055
1124
1056
    array->add(Object((double) fdes->bbxmin));
1125
    Object el;
1057
    array->add(Object((double) fdes->bbymin));
1126
1058
    array->add(Object((double) fdes->bbxmax));
1127
    el.initReal(fdes->bbxmin);
1059
    array->add(Object((double) fdes->bbymax));
1128
    array.arrayAdd(&el);
1060
1129
1061
    dic->dictSet("FontBBox", Object(array));
1130
    el.initReal(fdes->bbymin);
1131
    array.arrayAdd(&el);
1132
1133
    el.initReal(fdes->bbxmax);
1134
    array.arrayAdd(&el);
1135
1136
    el.initReal(fdes->bbymax);
1137
    array.arrayAdd(&el);
1138
1139
    dic->dictSet("FontBBox", &array);
1140
1062
1141
    if (fdes->xHeight) {
1063
    if (fdes->xHeight) {
1142
        dic->dictSet("XHeight", int_object(fdes->xHeight));
1064
        dic->dictSet("XHeight", Object((int)fdes->xHeight));
1143
    }
1065
    }
1144
1066
1145
    if (fdes->avgWidth) {
1067
    if (fdes->avgWidth) {
1146
        dic->dictSet("AvgWidth", int_object(fdes->avgWidth));
1068
        dic->dictSet("AvgWidth", Object((int)fdes->avgWidth));
1147
    }
1069
    }
1148
1070
1149
    if (fdes->panose) {
1071
    if (fdes->panose) {
1150
        /* Font dictionary for embeded font */
1072
        /* Font dictionary for embeded font */
1151
        Object style_dic;
1073
        Dict *style_dic = new Dict(xref);
1152
        style_dic.initDict(xref);
1153
1074
1154
        Object panose;
1075
        Object panose;
1155
1076
1156
        GooString *panose_str = new GooString(fdes->panose, 12);
1077
        GooString *panose_str = new GooString(fdes->panose, 12);
1157
        panose.initString(panose_str);
1078
        style_dic->set("Panose", Object(panose_str));
1158
        style_dic.dictSet("Panose", &panose);
1159
1079
1160
        dic->dictSet("Style", &style_dic);
1080
        dic->dictSet("Style", Object(style_dic));
1161
    }
1081
    }
1162
1082
1163
    Object ref_obj;
1083
    dic->dictSet(emb_pdf_get_fontfile_key(emb), Object(fontfile_obj_ref.num, fontfile_obj_ref.gen));
1164
    ref_obj.initRef(fontfile_obj_ref.num, fontfile_obj_ref.gen);
1165
    dic->dictSet(emb_pdf_get_fontfile_key(emb), &ref_obj);
1166
1084
1167
    return dic;
1085
    return dic;
1168
}
1086
}
Lines 1181-1225 Link Here
1181
    /* Get XREF table */
1099
    /* Get XREF table */
1182
    XRef *xref = doc->getXRef();
1100
    XRef *xref = doc->getXRef();
1183
1101
1184
    Object *dic = new Object();
1102
    Object *dic = new Object(new Dict(xref));
1185
    dic->initDict(xref);
1186
1103
1187
    dic->dictSet("Type", name_object("Font"));
1104
    dic->dictSet("Type", Object(objName,"Font"));
1188
    dic->dictSet(
1105
    dic->dictSet(
1189
            "Subtype",
1106
            "Subtype",
1190
            name_object(copyString(emb_pdf_get_font_subtype(emb))));
1107
            Object(objName,copyString(emb_pdf_get_font_subtype(emb))));
1191
    dic->dictSet(
1108
    dic->dictSet(
1192
            "BaseFont",
1109
            "BaseFont",
1193
            name_object(copyString(emb_pdf_escape_name(fdes->fontname,-1))));
1110
            Object(objName,copyString(emb_pdf_escape_name(fdes->fontname,-1))));
1194
1111
1195
    Object ref_obj;
1112
    dic->dictSet("FontDescriptor", Object(fontdescriptor_obj_ref.num, fontdescriptor_obj_ref.gen));
1196
    ref_obj.initRef(fontdescriptor_obj_ref.num, fontdescriptor_obj_ref.gen);
1197
    dic->dictSet("FontDescriptor", &ref_obj);
1198
1113
1199
    if ( emb->plan & EMB_A_MULTIBYTE ) {
1114
    if ( emb->plan & EMB_A_MULTIBYTE ) {
1200
        assert(fwid->warray);
1115
        assert(fwid->warray);
1201
1116
1202
        Object CIDSystemInfo_dic;
1117
        Dict * CIDSystemInfo_dic = new Dict(xref);
1203
        CIDSystemInfo_dic.initDict(xref);
1204
1205
        Object registry;
1206
        Object ordering;
1207
1118
1208
        GooString *str;
1119
        GooString *str;
1209
1120
1210
        str = new GooString(copyString(fdes->registry));
1121
        str = new GooString(copyString(fdes->registry));
1211
        registry.initString(str);
1122
        CIDSystemInfo_dic->set("Registry", Object(str));
1212
        CIDSystemInfo_dic.dictSet("Registry", &registry);
1213
1123
1214
        str = new GooString(copyString(fdes->ordering));
1124
        str = new GooString(copyString(fdes->ordering));
1215
        ordering.initString(str);
1125
        CIDSystemInfo_dic->set("Ordering", Object(str));
1216
        CIDSystemInfo_dic.dictSet("Ordering", &ordering);
1126
1217
1127
        CIDSystemInfo_dic->set("Supplement", Object((int)fdes->supplement));
1218
        CIDSystemInfo_dic.dictSet("Supplement", int_object(fdes->supplement));
1128
1219
1129
        dic->dictSet("CIDSystemInfo", Object(CIDSystemInfo_dic));
1220
        dic->dictSet("CIDSystemInfo", &CIDSystemInfo_dic);
1130
1221
1131
        dic->dictSet("DW", Object((int)fwid->default_width));
1222
        dic->dictSet("DW", int_object(fwid->default_width));
1223
    }
1132
    }
1224
1133
1225
    return dic;
1134
    return dic;
Lines 1249-1259 Link Here
1249
    /* Get XREF table */
1158
    /* Get XREF table */
1250
    XRef *xref = doc->getXRef();
1159
    XRef *xref = doc->getXRef();
1251
1160
1252
    Object *dic = new Object();
1161
    Object *dic = new Object(new Dict(xref));
1253
    dic->initDict(xref);
1254
1162
1255
    dic->dictSet("Type", name_object("Font"));
1163
    dic->dictSet("Type", Object(objName,("Font")));
1256
    dic->dictSet("Subtype", name_object("Type0"));
1164
    dic->dictSet("Subtype", Object(objName,("Type0")));
1257
1165
1258
1166
1259
    GooString * basefont = new GooString();
1167
    GooString * basefont = new GooString();
Lines 1262-1279 Link Here
1262
    basefont->append((addenc[0])?encoding:"");
1170
    basefont->append((addenc[0])?encoding:"");
1263
1171
1264
    dic->dictSet("BaseFont",
1172
    dic->dictSet("BaseFont",
1265
            name_object(copyString(basefont->getCString())));
1173
            Object(objName,(copyString(basefont->getCString()))));
1266
1174
1267
    dic->dictSet("Encoding", name_object(copyString(encoding)));
1175
    dic->dictSet("Encoding", Object(objName,(copyString(encoding))));
1268
1176
1269
    Object obj;
1177
1270
    obj.initRef(fontdescriptor_obj_ref.num, fontdescriptor_obj_ref.gen);
1178
    Array *array = new Array(xref);
1271
1179
    array->add(Object(fontdescriptor_obj_ref.num, fontdescriptor_obj_ref.gen));
1272
    Object array;
1180
1273
    array.initArray(xref);
1181
    dic->dictSet("DescendantFonts", Object(array));
1274
    array.arrayAdd(&obj);
1275
1276
    dic->dictSet("DescendantFonts", &array);
1277
1182
1278
    return dic;
1183
    return dic;
1279
}
1184
}

Return to bug 629708