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

Collapse All | Expand All

(-)source.orig/texk/web2c/luatexdir/image/pdftoepdf.w (-35 / +19 lines)
Lines 224-230 Link Here
224
        free(checksum);
224
        free(checksum);
225
    }
225
    }
226
    if (pdf_doc->doc == NULL) {
226
    if (pdf_doc->doc == NULL) {
227
        docmemstream = new MemStream( docstream,0,streamsize, obj.initNull() );
227
        docmemstream = new MemStream( docstream,0,streamsize, Object(objNull) );
228
        doc = new PDFDoc(docmemstream); /* takes ownership of docmemstream */
228
        doc = new PDFDoc(docmemstream); /* takes ownership of docmemstream */
229
        pdf_doc->pc++;
229
        pdf_doc->pc++;
230
        if (!doc->isOk() || !doc->okToPrint()) {
230
        if (!doc->isOk() || !doc->okToPrint()) {
Lines 408-416 Link Here
408
    Object obj1;
408
    Object obj1;
409
    pdf_begin_array(pdf);
409
    pdf_begin_array(pdf);
410
    for (i = 0, l = array->getLength(); i < l; ++i) {
410
    for (i = 0, l = array->getLength(); i < l; ++i) {
411
        array->getNF(i, &obj1);
411
        obj1 = array->getNF(i);
412
        copyObject(pdf, pdf_doc, &obj1);
412
        copyObject(pdf, pdf_doc, &obj1);
413
        obj1.free();
414
    }
413
    }
415
    pdf_end_array(pdf);
414
    pdf_end_array(pdf);
416
}
415
}
Lines 422-430 Link Here
422
    pdf_begin_dict(pdf);
421
    pdf_begin_dict(pdf);
423
    for (i = 0, l = dict->getLength(); i < l; ++i) {
422
    for (i = 0, l = dict->getLength(); i < l; ++i) {
424
        copyName(pdf, dict->getKey(i));
423
        copyName(pdf, dict->getKey(i));
425
        dict->getValNF(i, &obj1);
424
        obj1 = dict->getValNF(i);
426
        copyObject(pdf, pdf_doc, &obj1);
425
        copyObject(pdf, pdf_doc, &obj1);
427
        obj1.free();
428
    }
426
    }
429
    pdf_end_dict(pdf);
427
    pdf_end_dict(pdf);
430
}
428
}
Lines 510-522 Link Here
510
    PDFDoc *doc = pdf_doc->doc;
508
    PDFDoc *doc = pdf_doc->doc;
511
    xref = doc->getXRef();
509
    xref = doc->getXRef();
512
    for (r = pdf_doc->inObjList; r != NULL;) {
510
    for (r = pdf_doc->inObjList; r != NULL;) {
513
        xref->fetch(r->ref.num, r->ref.gen, &obj1);
511
        obj1 = xref->fetch(r->ref.num, r->ref.gen);
514
        if (obj1.isStream())
512
        if (obj1.isStream())
515
            pdf_begin_obj(pdf, r->num, OBJSTM_NEVER);
513
            pdf_begin_obj(pdf, r->num, OBJSTM_NEVER);
516
        else
514
        else
517
            pdf_begin_obj(pdf, r->num, 2);
515
            pdf_begin_obj(pdf, r->num, 2);
518
        copyObject(pdf, pdf_doc, &obj1);
516
        copyObject(pdf, pdf_doc, &obj1);
519
        obj1.free();
520
        pdf_end_obj(pdf);
517
        pdf_end_obj(pdf);
521
        n = r->next;
518
        n = r->next;
522
        delete r;
519
        delete r;
Lines 740-746 Link Here
740
    catalog = doc->getCatalog();
737
    catalog = doc->getCatalog();
741
    page = catalog->getPage(img_pagenum(idict));
738
    page = catalog->getPage(img_pagenum(idict));
742
    pageref = catalog->getPageRef(img_pagenum(idict));
739
    pageref = catalog->getPageRef(img_pagenum(idict));
743
    doc->getXRef()->fetch(pageref->num, pageref->gen, &pageobj);
740
    pageobj = doc->getXRef()->fetch(pageref->num, pageref->gen);
744
    pageDict = pageobj.getDict();
741
    pageDict = pageobj.getDict();
745
    /* write the Page header */
742
    /* write the Page header */
746
    pdf_begin_obj(pdf, img_objnum(idict), OBJSTM_NEVER);
743
    pdf_begin_obj(pdf, img_objnum(idict), OBJSTM_NEVER);
Lines 757-768 Link Here
757
        pdf_dict_add_int(pdf, "PTEX.PageNumber", (int) img_pagenum(idict));
754
        pdf_dict_add_int(pdf, "PTEX.PageNumber", (int) img_pagenum(idict));
758
    }
755
    }
759
    if ((suppress_optional_info & 8) == 0) {
756
    if ((suppress_optional_info & 8) == 0) {
760
        doc->getDocInfoNF(&obj1);
757
        obj1 = doc->getDocInfoNF();
761
        if (obj1.isRef()) {
758
        if (obj1.isRef()) {
762
            /* the info dict must be indirect (PDF Ref p. 61) */
759
            /* the info dict must be indirect (PDF Ref p. 61) */
763
            pdf_dict_add_ref(pdf, "PTEX.InfoDict", addInObj(pdf, pdf_doc, obj1.getRef()));
760
            pdf_dict_add_ref(pdf, "PTEX.InfoDict", addInObj(pdf, pdf_doc, obj1.getRef()));
764
        }
761
        }
765
        obj1.free();
766
    }
762
    }
767
    if (img_is_bbox(idict)) {
763
    if (img_is_bbox(idict)) {
768
        bbox[0] = sp2bp(img_bbox(idict)[0]);
764
        bbox[0] = sp2bp(img_bbox(idict)[0]);
Lines 788-806 Link Here
788
        Now all relevant parts of the Page dictionary are copied. Metadata validity
784
        Now all relevant parts of the Page dictionary are copied. Metadata validity
789
        check is needed(as a stream it must be indirect).
785
        check is needed(as a stream it must be indirect).
790
    */
786
    */
791
    pageDict->lookupNF("Metadata", &obj1);
787
    obj1 = pageDict->lookupNF("Metadata");
792
    if (!obj1.isNull() && !obj1.isRef())
788
    if (!obj1.isNull() && !obj1.isRef())
793
        formatted_warning("pdf inclusion","/Metadata must be indirect object");
789
        formatted_warning("pdf inclusion","/Metadata must be indirect object");
794
    obj1.free();
795
    /* copy selected items in Page dictionary */
790
    /* copy selected items in Page dictionary */
796
    for (i = 0; pagedictkeys[i] != NULL; i++) {
791
    for (i = 0; pagedictkeys[i] != NULL; i++) {
797
        pageDict->lookupNF(pagedictkeys[i], &obj1);
792
        obj1 = pageDict->lookupNF(pagedictkeys[i]);
798
        if (!obj1.isNull()) {
793
        if (!obj1.isNull()) {
799
            pdf_add_name(pdf, pagedictkeys[i]);
794
            pdf_add_name(pdf, pagedictkeys[i]);
800
            /* preserves indirection */
795
            /* preserves indirection */
801
            copyObject(pdf, pdf_doc, &obj1);
796
            copyObject(pdf, pdf_doc, &obj1);
802
        }
797
        }
803
        obj1.free();
804
    }
798
    }
805
    /*
799
    /*
806
        If there are no Resources in the Page dict of the embedded page,
800
        If there are no Resources in the Page dict of the embedded page,
Lines 808-839 Link Here
808
        PDF file, climbing up the tree until the Resources are found.
802
        PDF file, climbing up the tree until the Resources are found.
809
        (This fixes a problem with Scribus 1.3.3.14.)
803
        (This fixes a problem with Scribus 1.3.3.14.)
810
    */
804
    */
811
    pageDict->lookupNF("Resources", &obj1);
805
    obj1 = pageDict->lookupNF("Resources");
812
    if (obj1.isNull()) {
806
    if (obj1.isNull()) {
813
        op1 = &pagesobj1;
807
        op1 = &pagesobj1;
814
        op2 = &pagesobj2;
808
        op2 = &pagesobj2;
815
        pageDict->lookup("Parent", op1);
809
        *op1 = pageDict->lookup("Parent");
816
        while (op1->isDict()) {
810
        while (op1->isDict()) {
817
            obj1.free();
811
            obj1 = op1->dictLookupNF("Resources");
818
            op1->dictLookupNF("Resources", &obj1);
819
            if (!obj1.isNull()) {
812
            if (!obj1.isNull()) {
820
                pdf_add_name(pdf, "Resources");
813
                pdf_add_name(pdf, "Resources");
821
                copyObject(pdf, pdf_doc, &obj1);
814
                copyObject(pdf, pdf_doc, &obj1);
822
                break;
815
                break;
823
            }
816
            }
824
            op1->dictLookup("Parent", op2);
817
            *op2 = op1->dictLookup("Parent");
825
            optmp = op1;
818
            optmp = op1;
826
            op1 = op2;
819
            op1 = op2;
827
            op2 = optmp;
820
            op2 = optmp;
828
            op2->free();
829
        };
821
        };
830
        if (!op1->isDict())
822
        if (!op1->isDict())
831
            formatted_warning("pdf inclusion","Page /Resources missing");
823
            formatted_warning("pdf inclusion","Page /Resources missing");
832
        op1->free();
833
    }
824
    }
834
    obj1.free();
835
    /* Write the Page contents. */
825
    /* Write the Page contents. */
836
    page->getContents(&contents);
826
    contents = page->getContents();
837
    if (contents.isStream()) {
827
    if (contents.isStream()) {
838
        /*
828
        /*
839
            Variant A: get stream and recompress under control of \pdfcompresslevel
829
            Variant A: get stream and recompress under control of \pdfcompresslevel
Lines 844-870 Link Here
844
834
845
            Variant B: copy stream without recompressing
835
            Variant B: copy stream without recompressing
846
        */
836
        */
847
        contents.streamGetDict()->lookup("F", &obj1);
837
        obj1 = contents.streamGetDict()->lookup("F");
848
        if (!obj1.isNull()) {
838
        if (!obj1.isNull()) {
849
            normal_error("pdf inclusion","unsupported external stream");
839
            normal_error("pdf inclusion","unsupported external stream");
850
        }
840
        }
851
        obj1.free();
841
        obj1 = contents.streamGetDict()->lookup("Length");
852
        contents.streamGetDict()->lookup("Length", &obj1);
853
        pdf_add_name(pdf, "Length");
842
        pdf_add_name(pdf, "Length");
854
        copyObject(pdf, pdf_doc, &obj1);
843
        copyObject(pdf, pdf_doc, &obj1);
855
        obj1.free();
844
        obj1 = contents.streamGetDict()->lookup("Filter");
856
        contents.streamGetDict()->lookup("Filter", &obj1);
857
        if (!obj1.isNull()) {
845
        if (!obj1.isNull()) {
858
            pdf_add_name(pdf, "Filter");
846
            pdf_add_name(pdf, "Filter");
859
            copyObject(pdf, pdf_doc, &obj1);
847
            copyObject(pdf, pdf_doc, &obj1);
860
            obj1.free();
848
            obj1 = contents.streamGetDict()->lookup("DecodeParms");
861
            contents.streamGetDict()->lookup("DecodeParms", &obj1);
862
            if (!obj1.isNull()) {
849
            if (!obj1.isNull()) {
863
                pdf_add_name(pdf, "DecodeParms");
850
                pdf_add_name(pdf, "DecodeParms");
864
                copyObject(pdf, pdf_doc, &obj1);
851
                copyObject(pdf, pdf_doc, &obj1);
865
            }
852
            }
866
        }
853
        }
867
        obj1.free();
868
        pdf_end_dict(pdf);
854
        pdf_end_dict(pdf);
869
        pdf_begin_stream(pdf);
855
        pdf_begin_stream(pdf);
870
        copyStreamStream(pdf, contents.getStream()->getUndecodedStream());
856
        copyStreamStream(pdf, contents.getStream()->getUndecodedStream());
Lines 875-882 Link Here
875
        pdf_end_dict(pdf);
861
        pdf_end_dict(pdf);
876
        pdf_begin_stream(pdf);
862
        pdf_begin_stream(pdf);
877
        for (i = 0, l = contents.arrayGetLength(); i < l; ++i) {
863
        for (i = 0, l = contents.arrayGetLength(); i < l; ++i) {
878
            copyStreamStream(pdf, (contents.arrayGet(i, &obj1))->getStream());
864
            obj1 = contents.arrayGet(i);
879
            obj1.free();
865
            copyStreamStream(pdf, obj1.getStream());
880
            if (i < (l - 1)) {
866
            if (i < (l - 1)) {
881
                /*
867
                /*
882
                    Put a space between streams to be on the safe side (streams
868
                    Put a space between streams to be on the safe side (streams
Lines 897-904 Link Here
897
    }
883
    }
898
    /* write out all indirect objects */
884
    /* write out all indirect objects */
899
    writeRefs(pdf, pdf_doc);
885
    writeRefs(pdf, pdf_doc);
900
    contents.free();
901
    pageobj.free();
902
    /*
886
    /*
903
        unrefPdfDocument() must come after contents.free() and pageobj.free()!
887
        unrefPdfDocument() must come after contents.free() and pageobj.free()!
904
        TH: The next line makes repeated pdf inclusion unacceptably slow
888
        TH: The next line makes repeated pdf inclusion unacceptably slow
(-)source.orig/texk/web2c/luatexdir/lua/lepdflib.cc (-52 / +49 lines)
Lines 538-544 Link Here
538
        pdfdoc_changed_error(L);                               \
538
        pdfdoc_changed_error(L);                               \
539
    uout = new_Object_userdata(L);                             \
539
    uout = new_Object_userdata(L);                             \
540
    uout->d = new Object();                                    \
540
    uout->d = new Object();                                    \
541
    ((in *) uin->d)->function((Object *) uout->d);             \
541
    *((Object *)uout->d) = ((in *) uin->d)->function();                  \
542
    uout->atype = ALLOC_LEPDF;                                 \
542
    uout->atype = ALLOC_LEPDF;                                 \
543
    uout->pc = uin->pc;                                        \
543
    uout->pc = uin->pc;                                        \
544
    uout->pd = uin->pd;                                        \
544
    uout->pd = uin->pd;                                        \
Lines 668-680 Link Here
668
668
669
static int m_Array_incRef(lua_State * L)
669
static int m_Array_incRef(lua_State * L)
670
{
670
{
671
    int i;
672
    udstruct *uin;
671
    udstruct *uin;
673
    uin = (udstruct *) luaL_checkudata(L, 1, M_Array);
672
    uin = (udstruct *) luaL_checkudata(L, 1, M_Array);
674
    if (uin->pd != NULL && uin->pd->pc != uin->pc)
673
    if (uin->pd != NULL && uin->pd->pc != uin->pc)
675
        pdfdoc_changed_error(L);
674
        pdfdoc_changed_error(L);
676
    i = ((Array *) uin->d)->incRef();
675
    lua_pushinteger(L, 1);
677
    lua_pushinteger(L, i);
678
    return 1;
676
    return 1;
679
}
677
}
680
678
Lines 685-692 Link Here
685
    uin = (udstruct *) luaL_checkudata(L, 1, M_Array);
683
    uin = (udstruct *) luaL_checkudata(L, 1, M_Array);
686
    if (uin->pd != NULL && uin->pd->pc != uin->pc)
684
    if (uin->pd != NULL && uin->pd->pc != uin->pc)
687
        pdfdoc_changed_error(L);
685
        pdfdoc_changed_error(L);
688
    i = ((Array *) uin->d)->decRef();
686
    lua_pushinteger(L, 1);
689
    lua_pushinteger(L, i);
690
    return 1;
687
    return 1;
691
}
688
}
692
689
Lines 702-708 Link Here
702
    if ((uin->pd != NULL && uin->pd->pc != uin->pc)
699
    if ((uin->pd != NULL && uin->pd->pc != uin->pc)
703
        || (uobj->pd != NULL && uobj->pd->pc != uobj->pc))
700
        || (uobj->pd != NULL && uobj->pd->pc != uobj->pc))
704
        pdfdoc_changed_error(L);
701
        pdfdoc_changed_error(L);
705
    ((Array *) uin->d)->add(((Object *) uobj->d));
702
    ((Array *) uin->d)->add(std::move(*((Object *) uobj->d)));
706
    return 0;
703
    return 0;
707
}
704
}
708
705
Lines 718-724 Link Here
718
    if (i > 0 && i <= len) {
715
    if (i > 0 && i <= len) {
719
        uout = new_Object_userdata(L);
716
        uout = new_Object_userdata(L);
720
        uout->d = new Object();
717
        uout->d = new Object();
721
        ((Array *) uin->d)->get(i - 1, (Object *) uout->d);
718
        *((Object *) uout->d) = ((Array *) uin->d)->get(i - 1);
722
        uout->atype = ALLOC_LEPDF;
719
        uout->atype = ALLOC_LEPDF;
723
        uout->pc = uin->pc;
720
        uout->pc = uin->pc;
724
        uout->pd = uin->pd;
721
        uout->pd = uin->pd;
Lines 739-745 Link Here
739
    if (i > 0 && i <= len) {
736
    if (i > 0 && i <= len) {
740
        uout = new_Object_userdata(L);
737
        uout = new_Object_userdata(L);
741
        uout->d = new Object();
738
        uout->d = new Object();
742
        ((Array *) uin->d)->getNF(i - 1, (Object *) uout->d);
739
        *((Object *) uout->d) = ((Array *) uin->d)->getNF(i - 1);
743
        uout->atype = ALLOC_LEPDF;
740
        uout->atype = ALLOC_LEPDF;
744
        uout->pc = uin->pc;
741
        uout->pc = uin->pc;
745
        uout->pd = uin->pd;
742
        uout->pd = uin->pd;
Lines 953-977 Link Here
953
950
954
static int m_Dict_incRef(lua_State * L)
951
static int m_Dict_incRef(lua_State * L)
955
{
952
{
956
    int i;
957
    udstruct *uin;
953
    udstruct *uin;
958
    uin = (udstruct *) luaL_checkudata(L, 1, M_Dict);
954
    uin = (udstruct *) luaL_checkudata(L, 1, M_Dict);
959
    if (uin->pd != NULL && uin->pd->pc != uin->pc)
955
    if (uin->pd != NULL && uin->pd->pc != uin->pc)
960
        pdfdoc_changed_error(L);
956
        pdfdoc_changed_error(L);
961
    i = ((Dict *) uin->d)->incRef();
957
    lua_pushinteger(L, 1);
962
    lua_pushinteger(L, i);
963
    return 1;
958
    return 1;
964
}
959
}
965
960
966
static int m_Dict_decRef(lua_State * L)
961
static int m_Dict_decRef(lua_State * L)
967
{
962
{
968
    int i;
969
    udstruct *uin;
963
    udstruct *uin;
970
    uin = (udstruct *) luaL_checkudata(L, 1, M_Dict);
964
    uin = (udstruct *) luaL_checkudata(L, 1, M_Dict);
971
    if (uin->pd != NULL && uin->pd->pc != uin->pc)
965
    if (uin->pd != NULL && uin->pd->pc != uin->pc)
972
        pdfdoc_changed_error(L);
966
        pdfdoc_changed_error(L);
973
    i = ((Dict *) uin->d)->decRef();
967
    lua_pushinteger(L, 1);
974
    lua_pushinteger(L, i);
975
    return 1;
968
    return 1;
976
}
969
}
977
970
Lines 986-992 Link Here
986
        pdfdoc_changed_error(L);
979
        pdfdoc_changed_error(L);
987
    s = copyString(luaL_checkstring(L, 2));
980
    s = copyString(luaL_checkstring(L, 2));
988
    uobj = (udstruct *) luaL_checkudata(L, 3, M_Object);
981
    uobj = (udstruct *) luaL_checkudata(L, 3, M_Object);
989
    ((Dict *) uin->d)->add(s, ((Object *) uobj->d));
982
    ((Dict *) uin->d)->add(s, std::move(*((Object *) uobj->d)));
990
    return 0;
983
    return 0;
991
}
984
}
992
985
Lines 999-1005 Link Here
999
        pdfdoc_changed_error(L);
992
        pdfdoc_changed_error(L);
1000
    s = luaL_checkstring(L, 2);
993
    s = luaL_checkstring(L, 2);
1001
    uobj = (udstruct *) luaL_checkudata(L, 3, M_Object);
994
    uobj = (udstruct *) luaL_checkudata(L, 3, M_Object);
1002
    ((Dict *) uin->d)->set(s, ((Object *) uobj->d));
995
    ((Dict *) uin->d)->set(s, std::move(*((Object *) uobj->d)));
1003
    return 0;
996
    return 0;
1004
}
997
}
1005
998
Lines 1027-1033 Link Here
1027
    s = luaL_checkstring(L, 2);
1020
    s = luaL_checkstring(L, 2);
1028
    uout = new_Object_userdata(L);
1021
    uout = new_Object_userdata(L);
1029
    uout->d = new Object();
1022
    uout->d = new Object();
1030
    ((Dict *) uin->d)->lookup(s, (Object *) uout->d);
1023
    *((Object *) uout->d) = ((Dict *) uin->d)->lookup(s);
1031
    uout->atype = ALLOC_LEPDF;
1024
    uout->atype = ALLOC_LEPDF;
1032
    uout->pc = uin->pc;
1025
    uout->pc = uin->pc;
1033
    uout->pd = uin->pd;
1026
    uout->pd = uin->pd;
Lines 1044-1050 Link Here
1044
    s = luaL_checkstring(L, 2);
1037
    s = luaL_checkstring(L, 2);
1045
    uout = new_Object_userdata(L);
1038
    uout = new_Object_userdata(L);
1046
    uout->d = new Object();
1039
    uout->d = new Object();
1047
    ((Dict *) uin->d)->lookupNF(s, (Object *) uout->d);
1040
    *((Object *) uout->d) = ((Dict *) uin->d)->lookupNF(s);
1048
    uout->atype = ALLOC_LEPDF;
1041
    uout->atype = ALLOC_LEPDF;
1049
    uout->pc = uin->pc;
1042
    uout->pc = uin->pc;
1050
    uout->pd = uin->pd;
1043
    uout->pd = uin->pd;
Lines 1096-1102 Link Here
1096
    if (i > 0 && i <= len) {
1089
    if (i > 0 && i <= len) {
1097
        uout = new_Object_userdata(L);
1090
        uout = new_Object_userdata(L);
1098
        uout->d = new Object();
1091
        uout->d = new Object();
1099
        ((Dict *) uin->d)->getVal(i - 1, (Object *) uout->d);
1092
        *((Object *) uout->d) = ((Dict *) uin->d)->getVal(i - 1);
1100
        uout->atype = ALLOC_LEPDF;
1093
        uout->atype = ALLOC_LEPDF;
1101
        uout->pc = uin->pc;
1094
        uout->pc = uin->pc;
1102
        uout->pd = uin->pd;
1095
        uout->pd = uin->pd;
Lines 1117-1123 Link Here
1117
    if (i > 0 && i <= len) {
1110
    if (i > 0 && i <= len) {
1118
        uout = new_Object_userdata(L);
1111
        uout = new_Object_userdata(L);
1119
        uout->d = new Object();
1112
        uout->d = new Object();
1120
        ((Dict *) uin->d)->getValNF(i - 1, (Object *) uout->d);
1113
        *((Object *) uout->d) = ((Dict *) uin->d)->getValNF(i - 1);
1121
        uout->atype = ALLOC_LEPDF;
1114
        uout->atype = ALLOC_LEPDF;
1122
        uout->pc = uin->pc;
1115
        uout->pc = uin->pc;
1123
        uout->pd = uin->pd;
1116
        uout->pd = uin->pd;
Lines 1381-1389 Link Here
1381
        pdfdoc_changed_error(L);
1374
        pdfdoc_changed_error(L);
1382
    luaL_checktype(L, 2, LUA_TBOOLEAN);
1375
    luaL_checktype(L, 2, LUA_TBOOLEAN);
1383
    if (lua_toboolean(L, 2) != 0)
1376
    if (lua_toboolean(L, 2) != 0)
1384
        ((Object *) uin->d)->initBool(gTrue);
1377
        *((Object *) uin->d) = Object(gTrue);
1385
    else
1378
    else
1386
        ((Object *) uin->d)->initBool(gFalse);
1379
        *((Object *) uin->d) = Object(gFalse);
1387
    return 0;
1380
    return 0;
1388
}
1381
}
1389
1382
Lines 1395-1401 Link Here
1395
    if (uin->pd != NULL && uin->pd->pc != uin->pc)
1388
    if (uin->pd != NULL && uin->pd->pc != uin->pc)
1396
        pdfdoc_changed_error(L);
1389
        pdfdoc_changed_error(L);
1397
    i = luaL_checkint(L, 2);
1390
    i = luaL_checkint(L, 2);
1398
    ((Object *) uin->d)->initInt(i);
1391
    *((Object *) uin->d) = Object(i);
1399
    return 0;
1392
    return 0;
1400
}
1393
}
1401
1394
Lines 1407-1413 Link Here
1407
    if (uin->pd != NULL && uin->pd->pc != uin->pc)
1400
    if (uin->pd != NULL && uin->pd->pc != uin->pc)
1408
        pdfdoc_changed_error(L);
1401
        pdfdoc_changed_error(L);
1409
    d = luaL_checknumber(L, 2);
1402
    d = luaL_checknumber(L, 2);
1410
    ((Object *) uin->d)->initReal(d);
1403
    *((Object *) uin->d) = Object(d);
1411
    return 0;
1404
    return 0;
1412
}
1405
}
1413
1406
Lines 1422-1428 Link Here
1422
        pdfdoc_changed_error(L);
1415
        pdfdoc_changed_error(L);
1423
    s = luaL_checklstring(L, 2, &len);
1416
    s = luaL_checklstring(L, 2, &len);
1424
    gs = new GooString(s, len);
1417
    gs = new GooString(s, len);
1425
    ((Object *) uin->d)->initString(gs);
1418
    *((Object *) uin->d) = Object(gs);
1426
    return 0;
1419
    return 0;
1427
}
1420
}
1428
1421
Lines 1434-1440 Link Here
1434
    if (uin->pd != NULL && uin->pd->pc != uin->pc)
1427
    if (uin->pd != NULL && uin->pd->pc != uin->pc)
1435
        pdfdoc_changed_error(L);
1428
        pdfdoc_changed_error(L);
1436
    s = luaL_checkstring(L, 2);
1429
    s = luaL_checkstring(L, 2);
1437
    ((Object *) uin->d)->initName(s);
1430
    *((Object *) uin->d) = Object(objName, s);
1438
    return 0;
1431
    return 0;
1439
}
1432
}
1440
1433
Lines 1444-1456 Link Here
1444
    uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
1437
    uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
1445
    if (uin->pd != NULL && uin->pd->pc != uin->pc)
1438
    if (uin->pd != NULL && uin->pd->pc != uin->pc)
1446
        pdfdoc_changed_error(L);
1439
        pdfdoc_changed_error(L);
1447
    ((Object *) uin->d)->initNull();
1440
    *((Object *) uin->d) = Object(objNull);
1448
    return 0;
1441
    return 0;
1449
}
1442
}
1450
1443
1451
static int m_Object_initArray(lua_State * L)
1444
static int m_Object_initArray(lua_State * L)
1452
{
1445
{
1453
    udstruct *uin, *uxref;
1446
    udstruct *uin, *uxref;
1447
    Array *a;
1454
    uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
1448
    uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
1455
    uxref = (udstruct *) luaL_checkudata(L, 2, M_XRef);
1449
    uxref = (udstruct *) luaL_checkudata(L, 2, M_XRef);
1456
    if (uin->pd != NULL && uxref->pd != NULL && uin->pd != uxref->pd)
1450
    if (uin->pd != NULL && uxref->pd != NULL && uin->pd != uxref->pd)
Lines 1458-1464 Link Here
1458
    if ((uin->pd != NULL && uin->pd->pc != uin->pc)
1452
    if ((uin->pd != NULL && uin->pd->pc != uin->pc)
1459
        || (uxref->pd != NULL && uxref->pd->pc != uxref->pc))
1453
        || (uxref->pd != NULL && uxref->pd->pc != uxref->pc))
1460
        pdfdoc_changed_error(L);
1454
        pdfdoc_changed_error(L);
1461
    ((Object *) uin->d)->initArray((XRef *) uxref->d);
1455
    a = new Array((XRef *) uxref->d);
1456
    *((Object *) uin->d) = Object(a);
1462
    return 0;
1457
    return 0;
1463
}
1458
}
1464
1459
Lines 1469-1474 Link Here
1469
static int m_Object_initDict(lua_State * L)
1464
static int m_Object_initDict(lua_State * L)
1470
{
1465
{
1471
    udstruct *uin, *uxref;
1466
    udstruct *uin, *uxref;
1467
    Dict *d;
1472
    uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
1468
    uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
1473
    uxref = (udstruct *) luaL_checkudata(L, 2, M_XRef);
1469
    uxref = (udstruct *) luaL_checkudata(L, 2, M_XRef);
1474
    if (uin->pd != NULL && uxref->pd != NULL && uin->pd != uxref->pd)
1470
    if (uin->pd != NULL && uxref->pd != NULL && uin->pd != uxref->pd)
Lines 1476-1482 Link Here
1476
    if ((uin->pd != NULL && uin->pd->pc != uin->pc)
1472
    if ((uin->pd != NULL && uin->pd->pc != uin->pc)
1477
        || (uxref->pd != NULL && uxref->pd->pc != uxref->pc))
1473
        || (uxref->pd != NULL && uxref->pd->pc != uxref->pc))
1478
        pdfdoc_changed_error(L);
1474
        pdfdoc_changed_error(L);
1479
    ((Object *) uin->d)->initDict((XRef *) uxref->d);
1475
    d = new Dict((XRef *) uxref->d);
1476
    *((Object *) uin->d) = Object(d);
1480
    return 0;
1477
    return 0;
1481
}
1478
}
1482
1479
Lines 1490-1496 Link Here
1490
    if ((uin->pd != NULL && uin->pd->pc != uin->pc)
1487
    if ((uin->pd != NULL && uin->pd->pc != uin->pc)
1491
        || (ustream->pd != NULL && ustream->pd->pc != ustream->pc))
1488
        || (ustream->pd != NULL && ustream->pd->pc != ustream->pc))
1492
        pdfdoc_changed_error(L);
1489
        pdfdoc_changed_error(L);
1493
    ((Object *) uin->d)->initStream((Stream *) ustream->d);
1490
    *((Object *) uin->d) = Object((Stream *) ustream->d);
1494
    return 0;
1491
    return 0;
1495
}
1492
}
1496
1493
Lines 1503-1509 Link Here
1503
        pdfdoc_changed_error(L);
1500
        pdfdoc_changed_error(L);
1504
    num = luaL_checkint(L, 2);
1501
    num = luaL_checkint(L, 2);
1505
    gen = luaL_checkint(L, 3);
1502
    gen = luaL_checkint(L, 3);
1506
    ((Object *) uin->d)->initRef(num, gen);
1503
    *((Object *) uin->d) = Object(num, gen);
1507
    return 0;
1504
    return 0;
1508
}
1505
}
1509
1506
Lines 1515-1521 Link Here
1515
    if (uin->pd != NULL && uin->pd->pc != uin->pc)
1512
    if (uin->pd != NULL && uin->pd->pc != uin->pc)
1516
        pdfdoc_changed_error(L);
1513
        pdfdoc_changed_error(L);
1517
    s = luaL_checkstring(L, 2);
1514
    s = luaL_checkstring(L, 2);
1518
    ((Object *) uin->d)->initCmd(CHARP_CAST s);
1515
    *((Object *) uin->d) = Object(objCmd, CHARP_CAST s);
1519
    return 0;
1516
    return 0;
1520
}
1517
}
1521
1518
Lines 1525-1531 Link Here
1525
    uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
1522
    uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
1526
    if (uin->pd != NULL && uin->pd->pc != uin->pc)
1523
    if (uin->pd != NULL && uin->pd->pc != uin->pc)
1527
        pdfdoc_changed_error(L);
1524
        pdfdoc_changed_error(L);
1528
    ((Object *) uin->d)->initError();
1525
    *((Object *) uin->d) = Object(objError);
1529
    return 0;
1526
    return 0;
1530
}
1527
}
1531
1528
Lines 1535-1541 Link Here
1535
    uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
1532
    uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
1536
    if (uin->pd != NULL && uin->pd->pc != uin->pc)
1533
    if (uin->pd != NULL && uin->pd->pc != uin->pc)
1537
        pdfdoc_changed_error(L);
1534
        pdfdoc_changed_error(L);
1538
    ((Object *) uin->d)->initEOF();
1535
    *((Object *) uin->d) = Object(objEOF);
1539
    return 0;
1536
    return 0;
1540
}
1537
}
1541
1538
Lines 1551-1557 Link Here
1551
        pdfdoc_changed_error(L);
1548
        pdfdoc_changed_error(L);
1552
    uout = new_Object_userdata(L);
1549
    uout = new_Object_userdata(L);
1553
    uout->d = new Object();
1550
    uout->d = new Object();
1554
    ((Object *) uin->d)->fetch((XRef *) uxref->d, (Object *) uout->d);
1551
    *((Object *) uout->d) = ((Object *) uin->d)->fetch((XRef *) uxref->d);
1555
    uout->atype = ALLOC_LEPDF;
1552
    uout->atype = ALLOC_LEPDF;
1556
    uout->pc = uin->pc;
1553
    uout->pc = uin->pc;
1557
    uout->pd = uin->pd;
1554
    uout->pd = uin->pd;
Lines 1816-1822 Link Here
1816
        pdfdoc_changed_error(L);
1813
        pdfdoc_changed_error(L);
1817
    if (!((Object *) uin->d)->isArray())
1814
    if (!((Object *) uin->d)->isArray())
1818
        luaL_error(L, "Object is not an Array");
1815
        luaL_error(L, "Object is not an Array");
1819
    ((Object *) uin->d)->arrayAdd((Object *) uobj->d);
1816
    ((Object *) uin->d)->arrayAdd(std::move(*((Object *) uobj->d)));
1820
    return 0;
1817
    return 0;
1821
}
1818
}
1822
1819
Lines 1833-1839 Link Here
1833
        if (i > 0 && i <= len) {
1830
        if (i > 0 && i <= len) {
1834
            uout = new_Object_userdata(L);
1831
            uout = new_Object_userdata(L);
1835
            uout->d = new Object();
1832
            uout->d = new Object();
1836
            ((Object *) uin->d)->arrayGet(i - 1, (Object *) uout->d);
1833
            *((Object *) uout->d) = ((Object *) uin->d)->arrayGet(i - 1);
1837
            uout->atype = ALLOC_LEPDF;
1834
            uout->atype = ALLOC_LEPDF;
1838
            uout->pc = uin->pc;
1835
            uout->pc = uin->pc;
1839
            uout->pd = uin->pd;
1836
            uout->pd = uin->pd;
Lines 1857-1863 Link Here
1857
        if (i > 0 && i <= len) {
1854
        if (i > 0 && i <= len) {
1858
            uout = new_Object_userdata(L);
1855
            uout = new_Object_userdata(L);
1859
            uout->d = new Object();
1856
            uout->d = new Object();
1860
            ((Object *) uin->d)->arrayGetNF(i - 1, (Object *) uout->d);
1857
            *((Object *) uout->d) = ((Object *) uin->d)->arrayGetNF(i - 1);
1861
            uout->atype = ALLOC_LEPDF;
1858
            uout->atype = ALLOC_LEPDF;
1862
            uout->pc = uin->pc;
1859
            uout->pc = uin->pc;
1863
            uout->pd = uin->pd;
1860
            uout->pd = uin->pd;
Lines 1897-1903 Link Here
1897
        pdfdoc_changed_error(L);
1894
        pdfdoc_changed_error(L);
1898
    if (!((Object *) uin->d)->isDict())
1895
    if (!((Object *) uin->d)->isDict())
1899
        luaL_error(L, "Object is not a Dict");
1896
        luaL_error(L, "Object is not a Dict");
1900
    ((Object *) uin->d)->dictAdd(copyString(s), (Object *) uobj->d);
1897
    ((Object *) uin->d)->dictAdd(copyString(s), std::move(*((Object *) uobj->d)));
1901
    return 0;
1898
    return 0;
1902
}
1899
}
1903
1900
Lines 1915-1921 Link Here
1915
        pdfdoc_changed_error(L);
1912
        pdfdoc_changed_error(L);
1916
    if (!((Object *) uin->d)->isDict())
1913
    if (!((Object *) uin->d)->isDict())
1917
        luaL_error(L, "Object is not a Dict");
1914
        luaL_error(L, "Object is not a Dict");
1918
    ((Object *) uin->d)->dictSet(s, (Object *) uobj->d);
1915
    ((Object *) uin->d)->dictSet(s, std::move(*((Object *) uobj->d)));
1919
    return 0;
1916
    return 0;
1920
}
1917
}
1921
1918
Lines 1930-1936 Link Here
1930
    if (((Object *) uin->d)->isDict()) {
1927
    if (((Object *) uin->d)->isDict()) {
1931
        uout = new_Object_userdata(L);
1928
        uout = new_Object_userdata(L);
1932
        uout->d = new Object();
1929
        uout->d = new Object();
1933
        ((Object *) uin->d)->dictLookup(s, (Object *) uout->d);
1930
        *((Object *) uout->d) = ((Object *) uin->d)->dictLookup(s);
1934
        uout->atype = ALLOC_LEPDF;
1931
        uout->atype = ALLOC_LEPDF;
1935
        uout->pc = uin->pc;
1932
        uout->pc = uin->pc;
1936
        uout->pd = uin->pd;
1933
        uout->pd = uin->pd;
Lines 1950-1956 Link Here
1950
    if (((Object *) uin->d)->isDict()) {
1947
    if (((Object *) uin->d)->isDict()) {
1951
        uout = new_Object_userdata(L);
1948
        uout = new_Object_userdata(L);
1952
        uout->d = new Object();
1949
        uout->d = new Object();
1953
        ((Object *) uin->d)->dictLookupNF(s, (Object *) uout->d);
1950
        *((Object *) uout->d) = ((Object *) uin->d)->dictLookupNF(s);
1954
        uout->atype = ALLOC_LEPDF;
1951
        uout->atype = ALLOC_LEPDF;
1955
        uout->pc = uin->pc;
1952
        uout->pc = uin->pc;
1956
        uout->pd = uin->pd;
1953
        uout->pd = uin->pd;
Lines 1991-1997 Link Here
1991
        if (i > 0 && i <= len) {
1988
        if (i > 0 && i <= len) {
1992
            uout = new_Object_userdata(L);
1989
            uout = new_Object_userdata(L);
1993
            uout->d = new Object();
1990
            uout->d = new Object();
1994
            ((Object *) uin->d)->dictGetVal(i - 1, (Object *) uout->d);
1991
	    *((Object *) uout->d) = ((Object *) uin->d)->dictGetVal(i - 1);
1995
            uout->atype = ALLOC_LEPDF;
1992
            uout->atype = ALLOC_LEPDF;
1996
            uout->pc = uin->pc;
1993
            uout->pc = uin->pc;
1997
            uout->pd = uin->pd;
1994
            uout->pd = uin->pd;
Lines 2015-2021 Link Here
2015
        if (i > 0 && i <= len) {
2012
        if (i > 0 && i <= len) {
2016
            uout = new_Object_userdata(L);
2013
            uout = new_Object_userdata(L);
2017
            uout->d = new Object();
2014
            uout->d = new Object();
2018
            ((Object *) uin->d)->dictGetValNF(i - 1, (Object *) uout->d);
2015
            *((Object *) uout->d) = ((Object *) uin->d)->dictGetValNF(i - 1);
2019
            uout->atype = ALLOC_LEPDF;
2016
            uout->atype = ALLOC_LEPDF;
2020
            uout->pc = uin->pc;
2017
            uout->pc = uin->pc;
2021
            uout->pd = uin->pd;
2018
            uout->pd = uin->pd;
Lines 2243-2249 Link Here
2243
m_poppler_get_poppler(Page, Dict, getPieceInfo);
2240
m_poppler_get_poppler(Page, Dict, getPieceInfo);
2244
m_poppler_get_poppler(Page, Dict, getSeparationInfo);
2241
m_poppler_get_poppler(Page, Dict, getSeparationInfo);
2245
m_poppler_get_poppler(Page, Dict, getResourceDict);
2242
m_poppler_get_poppler(Page, Dict, getResourceDict);
2246
m_poppler_get_OBJECT(Page, getAnnots);
2243
m_poppler_get_OBJECT(Page, getAnnotsObject);
2247
2244
2248
m_poppler_get_OBJECT(Page, getContents);
2245
m_poppler_get_OBJECT(Page, getContents);
2249
2246
Lines 2270-2276 Link Here
2270
    {"getPieceInfo", m_Page_getPieceInfo},
2267
    {"getPieceInfo", m_Page_getPieceInfo},
2271
    {"getSeparationInfo", m_Page_getSeparationInfo},
2268
    {"getSeparationInfo", m_Page_getSeparationInfo},
2272
    {"getResourceDict", m_Page_getResourceDict},
2269
    {"getResourceDict", m_Page_getResourceDict},
2273
    {"getAnnots", m_Page_getAnnots},
2270
    {"getAnnots", m_Page_getAnnotsObject},
2274
    {"getContents", m_Page_getContents},
2271
    {"getContents", m_Page_getContents},
2275
    {"__tostring", m_Page__tostring},
2272
    {"__tostring", m_Page__tostring},
2276
    {NULL, NULL}                // sentinel
2273
    {NULL, NULL}                // sentinel
Lines 2520-2526 Link Here
2520
    if (((PdfDocument *) uin->d)->doc->getXRef()->isOk()) {
2517
    if (((PdfDocument *) uin->d)->doc->getXRef()->isOk()) {
2521
        uout = new_Object_userdata(L);
2518
        uout = new_Object_userdata(L);
2522
        uout->d = new Object();
2519
        uout->d = new Object();
2523
        ((PdfDocument *) uin->d)->doc->getDocInfo((Object *) uout->d);
2520
        *((Object *) uout->d) = ((PdfDocument *) uin->d)->doc->getDocInfo();
2524
        uout->atype = ALLOC_LEPDF;
2521
        uout->atype = ALLOC_LEPDF;
2525
        uout->pc = uin->pc;
2522
        uout->pc = uin->pc;
2526
        uout->pd = uin->pd;
2523
        uout->pd = uin->pd;
Lines 2538-2544 Link Here
2538
    if (((PdfDocument *) uin->d)->doc->getXRef()->isOk()) {
2535
    if (((PdfDocument *) uin->d)->doc->getXRef()->isOk()) {
2539
        uout = new_Object_userdata(L);
2536
        uout = new_Object_userdata(L);
2540
        uout->d = new Object();
2537
        uout->d = new Object();
2541
        ((PdfDocument *) uin->d)->doc->getDocInfoNF((Object *) uout->d);
2538
        *((Object *) uout->d) = ((PdfDocument *) uin->d)->doc->getDocInfoNF();
2542
        uout->atype = ALLOC_LEPDF;
2539
        uout->atype = ALLOC_LEPDF;
2543
        uout->pc = uin->pc;
2540
        uout->pc = uin->pc;
2544
        uout->pd = uin->pd;
2541
        uout->pd = uin->pd;
Lines 2841-2847 Link Here
2841
    uout = new_Object_userdata(L);
2838
    uout = new_Object_userdata(L);
2842
    uout->d = new Object();
2839
    uout->d = new Object();
2843
    origin = (Object *) (((Attribute *) uin->d)->getValue());
2840
    origin = (Object *) (((Attribute *) uin->d)->getValue());
2844
    origin->copy ( ((Object *)uout->d) );
2841
    *((Object *) uout->d) = origin->copy();
2845
    uout->atype = ALLOC_LEPDF;
2842
    uout->atype = ALLOC_LEPDF;
2846
    uout->pc = uin->pc;
2843
    uout->pc = uin->pc;
2847
    uout->pd = uin->pd;
2844
    uout->pd = uin->pd;
Lines 3320-3326 Link Here
3320
    parent = root->findParentElement(i-1);
3317
    parent = root->findParentElement(i-1);
3321
    if (parent != NULL) {
3318
    if (parent != NULL) {
3322
       uout = new_StructElement_userdata(L);
3319
       uout = new_StructElement_userdata(L);
3323
       uout->d = new StructElement( *parent );
3320
       uout->d = (StructElement *) parent;
3324
       uout->atype = ALLOC_LEPDF;
3321
       uout->atype = ALLOC_LEPDF;
3325
       uout->pc = uin->pc;
3322
       uout->pc = uin->pc;
3326
       uout->pd = uin->pd;
3323
       uout->pd = uin->pd;
Lines 3370-3376 Link Here
3370
    gen = luaL_checkint(L, 3);
3367
    gen = luaL_checkint(L, 3);
3371
    uout = new_Object_userdata(L);
3368
    uout = new_Object_userdata(L);
3372
    uout->d = new Object();
3369
    uout->d = new Object();
3373
    ((XRef *) uin->d)->fetch(num, gen, (Object *) uout->d);
3370
    *((Object *) uout->d) = ((XRef *) uin->d)->fetch(num, gen);
3374
    uout->atype = ALLOC_LEPDF;
3371
    uout->atype = ALLOC_LEPDF;
3375
    uout->pc = uin->pc;
3372
    uout->pc = uin->pc;
3376
    uout->pd = uin->pd;
3373
    uout->pd = uin->pd;
(-)source.orig/texk/web2c/luatexdir/lua/lpdfscannerlib.cc (-1 / +1 lines)
Lines 634-640 Link Here
634
      int i;
634
      int i;
635
      for (i=0;i<count;i++) {
635
      for (i=0;i<count;i++) {
636
	Object *val = new Object();
636
	Object *val = new Object();
637
	arrayref->get(i, val);
637
	*val = arrayref->get(i);
638
	if (val->isStream()) {
638
	if (val->isStream()) {
639
	  ObjectList *rover = self->_streams;
639
	  ObjectList *rover = self->_streams;
640
	  ObjectList *item = (ObjectList *)priv_xmalloc (sizeof(ObjectList));
640
	  ObjectList *item = (ObjectList *)priv_xmalloc (sizeof(ObjectList));
(-)source.orig/texk/web2c/pdftexdir/pdftoepdf.cc (-113 / +89 lines)
Lines 84-114 Link Here
84
#define MASK_SUPPRESS_PTEX_PAGENUMBER 0x04
84
#define MASK_SUPPRESS_PTEX_PAGENUMBER 0x04
85
#define MASK_SUPPRESS_PTEX_INFODICT   0x08
85
#define MASK_SUPPRESS_PTEX_INFODICT   0x08
86
86
87
// PdfObject encapsulates the xpdf Object type,
88
// and properly frees its resources on destruction.
89
// Use obj-> to access members of the Object,
90
// and &obj to get a pointer to the object.
91
// It is no longer necessary to call Object::free explicitely.
92
93
class PdfObject {
94
  public:
95
    PdfObject() {               // nothing
96
    } ~PdfObject() {
97
        iObject.free();
98
    }
99
    Object *operator->() {
100
        return &iObject;
101
    }
102
    Object *operator&() {
103
        return &iObject;
104
    }
105
  private:                     // no copying or assigning
106
    PdfObject(const PdfObject &);
107
    void operator=(const PdfObject &);
108
  public:
109
    Object iObject;
110
};
111
112
// When copying the Resources of the selected page, all objects are copied
87
// When copying the Resources of the selected page, all objects are copied
113
// recusively top-down. Indirect objects however are not fetched during
88
// recusively top-down. Indirect objects however are not fetched during
114
// copying, but get a new object number from pdfTeX and then will be
89
// copying, but get a new object number from pdfTeX and then will be
Lines 212-229 Link Here
212
    delete pdf_doc;
187
    delete pdf_doc;
213
}
188
}
214
189
215
// Replacement for
216
//      Object *initDict(Dict *dict1){ initObj(objDict); dict = dict1; return this; }
217
218
static void initDictFromDict(PdfObject & obj, Dict * dict)
219
{
220
    obj->initDict(xref);
221
    for (int i = 0, l = dict->getLength(); i < l; i++) {
222
        Object obj1;
223
        obj->dictAdd(copyString(dict->getKey(i)), dict->getValNF(i, &obj1));
224
    }
225
}
226
227
// --------------------------------------------------------------------
190
// --------------------------------------------------------------------
228
191
229
static int addEncoding(GfxFont * gfont)
192
static int addEncoding(GfxFont * gfont)
Lines 320-329 Link Here
320
283
321
static void copyDictEntry(Object * obj, int i)
284
static void copyDictEntry(Object * obj, int i)
322
{
285
{
323
    PdfObject obj1;
286
    Object obj1;
324
    copyName(obj->dictGetKey(i));
287
    copyName(obj->dictGetKey(i));
325
    pdf_puts(" ");
288
    pdf_puts(" ");
326
    obj->dictGetValNF(i, &obj1);
289
    obj1 = obj->dictGetValNF(i);
327
    copyObject(&obj1);
290
    copyObject(&obj1);
328
    pdf_puts("\n");
291
    pdf_puts("\n");
329
}
292
}
Lines 376-392 Link Here
376
static void copyProcSet(Object * obj)
339
static void copyProcSet(Object * obj)
377
{
340
{
378
    int i, l;
341
    int i, l;
379
    PdfObject procset;
342
    Object procset;
380
    if (!obj->isArray())
343
    if (!obj->isArray())
381
        pdftex_fail("PDF inclusion: invalid ProcSet array type <%s>",
344
        pdftex_fail("PDF inclusion: invalid ProcSet array type <%s>",
382
                    obj->getTypeName());
345
                    obj->getTypeName());
383
    pdf_puts("/ProcSet [ ");
346
    pdf_puts("/ProcSet [ ");
384
    for (i = 0, l = obj->arrayGetLength(); i < l; ++i) {
347
    for (i = 0, l = obj->arrayGetLength(); i < l; ++i) {
385
        obj->arrayGetNF(i, &procset);
348
        procset = obj->arrayGetNF(i);
386
        if (!procset->isName())
349
        if (!procset.isName())
387
            pdftex_fail("PDF inclusion: invalid ProcSet entry type <%s>",
350
            pdftex_fail("PDF inclusion: invalid ProcSet entry type <%s>",
388
                        procset->getTypeName());
351
                        procset.getTypeName());
389
        copyName(procset->getName());
352
        copyName(procset.getName());
390
        pdf_puts(" ");
353
        pdf_puts(" ");
391
    }
354
    }
392
    pdf_puts("]\n");
355
    pdf_puts("]\n");
Lines 396-402 Link Here
396
359
397
static void copyFont(char *tag, Object * fontRef)
360
static void copyFont(char *tag, Object * fontRef)
398
{
361
{
399
    PdfObject fontdict, subtype, basefont, fontdescRef, fontdesc, charset,
362
    Object fontdict, subtype, basefont, fontdescRef, fontdesc, charset,
400
        fontfile, ffsubtype, stemV;
363
        fontfile, ffsubtype, stemV;
401
    GfxFont *gfont;
364
    GfxFont *gfont;
402
    fd_entry *fd;
365
    fd_entry *fd;
Lines 413-445 Link Here
413
    }
376
    }
414
    // Only handle included Type1 (and Type1C) fonts; anything else will be copied.
377
    // Only handle included Type1 (and Type1C) fonts; anything else will be copied.
415
    // Type1C fonts are replaced by Type1 fonts, if REPLACE_TYPE1C is true.
378
    // Type1C fonts are replaced by Type1 fonts, if REPLACE_TYPE1C is true.
416
    if (!fixedinclusioncopyfont && fontRef->fetch(xref, &fontdict)->isDict()
379
    fontdict = fontRef->fetch(xref);
417
        && fontdict->dictLookup("Subtype", &subtype)->isName()
380
    if (fontdict.isDict()) {
418
        && !strcmp(subtype->getName(), "Type1")
381
        subtype = fontdict.dictLookup("Subtype");
419
        && fontdict->dictLookup("BaseFont", &basefont)->isName()
382
        basefont = fontdict.dictLookup("BaseFont");
420
        && fontdict->dictLookupNF("FontDescriptor", &fontdescRef)->isRef()
383
        fontdescRef = fontdict.dictLookupNF("FontDescriptor");
421
        && fontdescRef->fetch(xref, &fontdesc)->isDict()
384
        if (fontdescRef.isRef()) {
422
        && (fontdesc->dictLookup("FontFile", &fontfile)->isStream()
385
            fontdesc = fontdescRef.fetch(xref);
423
            || (REPLACE_TYPE1C
386
            if (fontdesc.isDict()) {
424
                && fontdesc->dictLookup("FontFile3", &fontfile)->isStream()
387
                fontfile = fontdesc.dictLookup("FontFile");
425
                && fontfile->streamGetDict()->lookup("Subtype",
388
                if (!fontfile.isStream() && REPLACE_TYPE1C) {
426
                                                     &ffsubtype)->isName()
389
                    fontfile = fontdesc.dictLookup("FontFile3");
427
                && !strcmp(ffsubtype->getName(), "Type1C")))
390
                    ffsubtype = fontfile.streamGetDict()->lookup("Subtype");
428
        && (fontmap = lookup_fontmap(basefont->getName())) != NULL) {
391
                    if (!(ffsubtype.isName() && !strcmp(ffsubtype.getName(), "Type1C"))) {
392
                        // not a Type1-C font.
393
                        fontfile = Object(objNull);
394
                    }
395
                }
396
            }
397
        }
398
    }
399
    if (!fixedinclusioncopyfont && fontdict.isDict()
400
        && subtype.isName()
401
        && !strcmp(subtype.getName(), "Type1")
402
        && basefont.isName()
403
        && fontdescRef.isRef()
404
        && fontdesc.isDict()
405
        && fontfile.isStream()
406
        && (fontmap = lookup_fontmap(basefont.getName())) != NULL) {
429
        // round /StemV value, since the PDF input is a float
407
        // round /StemV value, since the PDF input is a float
430
        // (see Font Descriptors in PDF reference), but we only store an
408
        // (see Font Descriptors in PDF reference), but we only store an
431
        // integer, since we don't want to change the struct.
409
        // integer, since we don't want to change the struct.
432
        fontdesc->dictLookup("StemV", &stemV);
410
        stemV = fontdesc.dictLookup("StemV");
433
        fd = epdf_create_fontdescriptor(fontmap, zround(stemV->getNum()));
411
        fd = epdf_create_fontdescriptor(fontmap, zround(stemV.getNum()));
434
        if (fontdesc->dictLookup("CharSet", &charset) &&
412
        charset = fontdesc.dictLookup("CharSet");
435
            charset->isString() && is_subsetable(fontmap))
413
        if (!charset.isNull() &&
436
            epdf_mark_glyphs(fd, charset->getString()->getCString());
414
            charset.isString() && is_subsetable(fontmap))
415
            epdf_mark_glyphs(fd, charset.getString()->getCString());
437
        else
416
        else
438
            embed_whole_font(fd);
417
            embed_whole_font(fd);
439
        addFontDesc(fontdescRef->getRef(), fd);
418
        addFontDesc(fontdescRef.getRef(), fd);
440
        copyName(tag);
419
        copyName(tag);
441
        gfont = GfxFont::makeFont(xref, tag, fontRef->getRef(),
420
        gfont = GfxFont::makeFont(xref, tag, fontRef->getRef(),
442
                                  fontdict->getDict());
421
                                  fontdict.getDict());
443
        pdf_printf(" %d 0 R ", addFont(fontRef->getRef(), fd,
422
        pdf_printf(" %d 0 R ", addFont(fontRef->getRef(), fd,
444
                                       addEncoding(gfont)));
423
                                       addEncoding(gfont)));
445
    } else {
424
    } else {
Lines 451-474 Link Here
451
430
452
static void copyFontResources(Object * obj)
431
static void copyFontResources(Object * obj)
453
{
432
{
454
    PdfObject fontRef;
433
    Object fontRef;
455
    int i, l;
434
    int i, l;
456
    if (!obj->isDict())
435
    if (!obj->isDict())
457
        pdftex_fail("PDF inclusion: invalid font resources dict type <%s>",
436
        pdftex_fail("PDF inclusion: invalid font resources dict type <%s>",
458
                    obj->getTypeName());
437
                    obj->getTypeName());
459
    pdf_puts("/Font << ");
438
    pdf_puts("/Font << ");
460
    for (i = 0, l = obj->dictGetLength(); i < l; ++i) {
439
    for (i = 0, l = obj->dictGetLength(); i < l; ++i) {
461
        obj->dictGetValNF(i, &fontRef);
440
        fontRef = obj->dictGetValNF(i);
462
        if (fontRef->isRef())
441
        if (fontRef.isRef())
463
            copyFont(obj->dictGetKey(i), &fontRef);
442
            copyFont(obj->dictGetKey(i), &fontRef);
464
        else if (fontRef->isDict()) {   // some programs generate pdf with embedded font object
443
        else if (fontRef.isDict()) {   // some programs generate pdf with embedded font object
465
            copyName(obj->dictGetKey(i));
444
            copyName(obj->dictGetKey(i));
466
            pdf_puts(" ");
445
            pdf_puts(" ");
467
            copyObject(&fontRef);
446
            copyObject(&fontRef);
468
        }
447
        }
469
        else
448
        else
470
            pdftex_fail("PDF inclusion: invalid font in reference type <%s>",
449
            pdftex_fail("PDF inclusion: invalid font in reference type <%s>",
471
                        fontRef->getTypeName());
450
                        fontRef.getTypeName());
472
    }
451
    }
473
    pdf_puts(">>\n");
452
    pdf_puts(">>\n");
474
}
453
}
Lines 557-563 Link Here
557
536
558
static void copyObject(Object * obj)
537
static void copyObject(Object * obj)
559
{
538
{
560
    PdfObject obj1;
539
    Object obj1;
561
    int i, l, c;
540
    int i, l, c;
562
    Ref ref;
541
    Ref ref;
563
    char *p;
542
    char *p;
Lines 601-608 Link Here
601
    } else if (obj->isArray()) {
580
    } else if (obj->isArray()) {
602
        pdf_puts("[");
581
        pdf_puts("[");
603
        for (i = 0, l = obj->arrayGetLength(); i < l; ++i) {
582
        for (i = 0, l = obj->arrayGetLength(); i < l; ++i) {
604
            obj->arrayGetNF(i, &obj1);
583
            obj1 = obj->arrayGetNF(i);
605
            if (!obj1->isName())
584
            if (!obj1.isName())
606
                pdf_puts(" ");
585
                pdf_puts(" ");
607
            copyObject(&obj1);
586
            copyObject(&obj1);
608
        }
587
        }
Lines 612-618 Link Here
612
        copyDict(obj);
591
        copyDict(obj);
613
        pdf_puts(">>");
592
        pdf_puts(">>");
614
    } else if (obj->isStream()) {
593
    } else if (obj->isStream()) {
615
        initDictFromDict(obj1, obj->streamGetDict());
594
        obj1 = Object(obj->streamGetDict());
616
        pdf_puts("<<\n");
595
        pdf_puts("<<\n");
617
        copyDict(&obj1);
596
        copyDict(&obj1);
618
        pdf_puts(">>\n");
597
        pdf_puts(">>\n");
Lines 638-646 Link Here
638
    InObj *r;
617
    InObj *r;
639
    for (r = inObjList; r != 0; r = r->next) {
618
    for (r = inObjList; r != 0; r = r->next) {
640
        if (!r->written) {
619
        if (!r->written) {
641
            Object obj1;
642
            r->written = 1;
620
            r->written = 1;
643
            xref->fetch(r->ref.num, r->ref.gen, &obj1);
621
            Object obj1 = xref->fetch(r->ref.num, r->ref.gen);
644
            if (r->type == objFont) {
622
            if (r->type == objFont) {
645
                assert(!obj1.isStream());
623
                assert(!obj1.isStream());
646
                pdfbeginobj(r->num, 2);         // \pdfobjcompresslevel = 2 is for this
624
                pdfbeginobj(r->num, 2);         // \pdfobjcompresslevel = 2 is for this
Lines 656-662 Link Here
656
                pdf_puts("\n");
634
                pdf_puts("\n");
657
                pdfendobj();
635
                pdfendobj();
658
            }
636
            }
659
            obj1.free();
660
        }
637
        }
661
    }
638
    }
662
}
639
}
Lines 839-846 Link Here
839
    Page *page;
816
    Page *page;
840
    Ref *pageRef;
817
    Ref *pageRef;
841
    Dict *pageDict;
818
    Dict *pageDict;
842
    PdfObject contents, obj1, obj2, pageObj, dictObj;
819
    Object contents, obj1, obj2, pageObj, dictObj;
843
    PdfObject groupDict;
820
    Object groupDict;
844
    bool writeSepGroup = false;
821
    bool writeSepGroup = false;
845
    Object info;
822
    Object info;
846
    char *key;
823
    char *key;
Lines 867-874 Link Here
867
    encodingList = 0;
844
    encodingList = 0;
868
    page = pdf_doc->doc->getCatalog()->getPage(epdf_selected_page);
845
    page = pdf_doc->doc->getCatalog()->getPage(epdf_selected_page);
869
    pageRef = pdf_doc->doc->getCatalog()->getPageRef(epdf_selected_page);
846
    pageRef = pdf_doc->doc->getCatalog()->getPageRef(epdf_selected_page);
870
    xref->fetch(pageRef->num, pageRef->gen, &pageObj);
847
    pageObj = xref->fetch(pageRef->num, pageRef->gen);
871
    pageDict = pageObj->getDict();
848
    pageDict = pageObj.getDict();
872
    rotate = page->getRotate();
849
    rotate = page->getRotate();
873
    PDFRectangle *pagebox;
850
    PDFRectangle *pagebox;
874
    // write the Page header
851
    // write the Page header
Lines 886-892 Link Here
886
        pdf_printf("/%s.PageNumber %i\n", pdfkeyprefix, (int) epdf_selected_page);
863
        pdf_printf("/%s.PageNumber %i\n", pdfkeyprefix, (int) epdf_selected_page);
887
    }
864
    }
888
    if ((suppress_ptex_info & MASK_SUPPRESS_PTEX_INFODICT) == 0) {
865
    if ((suppress_ptex_info & MASK_SUPPRESS_PTEX_INFODICT) == 0) {
889
        pdf_doc->doc->getDocInfoNF(&info);
866
        info = pdf_doc->doc->getDocInfoNF();
890
        if (info.isRef()) {
867
        if (info.isRef()) {
891
            // the info dict must be indirect (PDF Ref p. 61)
868
            // the info dict must be indirect (PDF Ref p. 61)
892
            pdf_printf("/%s.InfoDict ", pdfkeyprefix);
869
            pdf_printf("/%s.InfoDict ", pdfkeyprefix);
Lines 942-955 Link Here
942
    pdf_puts(stripzeros(s));
919
    pdf_puts(stripzeros(s));
943
920
944
    // Metadata validity check (as a stream it must be indirect)
921
    // Metadata validity check (as a stream it must be indirect)
945
    pageDict->lookupNF("Metadata", &dictObj);
922
    dictObj = pageDict->lookupNF("Metadata");
946
    if (!dictObj->isNull() && !dictObj->isRef())
923
    if (!dictObj.isNull() && !dictObj.isRef())
947
        pdftex_warn("PDF inclusion: /Metadata must be indirect object");
924
        pdftex_warn("PDF inclusion: /Metadata must be indirect object");
948
925
949
    // copy selected items in Page dictionary except Resources & Group
926
    // copy selected items in Page dictionary except Resources & Group
950
    for (i = 0; pageDictKeys[i] != NULL; i++) {
927
    for (i = 0; pageDictKeys[i] != NULL; i++) {
951
        pageDict->lookupNF(pageDictKeys[i], &dictObj);
928
        dictObj = pageDict->lookupNF(pageDictKeys[i]);
952
        if (!dictObj->isNull()) {
929
        if (!dictObj.isNull()) {
953
            pdf_newline();
930
            pdf_newline();
954
            pdf_printf("/%s ", pageDictKeys[i]);
931
            pdf_printf("/%s ", pageDictKeys[i]);
955
            copyObject(&dictObj); // preserves indirection
932
            copyObject(&dictObj); // preserves indirection
Lines 957-964 Link Here
957
    } 
934
    } 
958
935
959
    // handle page group
936
    // handle page group
960
    pageDict->lookupNF("Group", &dictObj);
937
    dictObj = pageDict->lookupNF("Group");
961
    if (!dictObj->isNull()) {
938
    if (!dictObj.isNull()) {
962
        if (pdfpagegroupval == 0) { 
939
        if (pdfpagegroupval == 0) { 
963
            // another pdf with page group was included earlier on the
940
            // another pdf with page group was included earlier on the
964
            // same page; copy the Group entry as is.  See manual for
941
            // same page; copy the Group entry as is.  See manual for
Lines 972-982 Link Here
972
            copyObject(&dictObj);
949
            copyObject(&dictObj);
973
        } else {
950
        } else {
974
            // write Group dict as a separate object, since the Page dict also refers to it
951
            // write Group dict as a separate object, since the Page dict also refers to it
975
            pageDict->lookup("Group", &dictObj);
952
            dictObj = pageDict->lookup("Group");
976
            if (!dictObj->isDict())
953
            if (!dictObj.isDict())
977
                pdftex_fail("PDF inclusion: /Group dict missing");
954
                pdftex_fail("PDF inclusion: /Group dict missing");
978
            writeSepGroup = true;
955
            writeSepGroup = true;
979
            initDictFromDict(groupDict, page->getGroup());
956
            groupDict = Object(page->getGroup());
980
            pdf_printf("/Group %ld 0 R\n", (long)pdfpagegroupval);
957
            pdf_printf("/Group %ld 0 R\n", (long)pdfpagegroupval);
981
        }
958
        }
982
    }
959
    }
Lines 989-1003 Link Here
989
        pdftex_warn
966
        pdftex_warn
990
            ("PDF inclusion: /Resources missing. 'This practice is not recommended' (PDF Ref)");
967
            ("PDF inclusion: /Resources missing. 'This practice is not recommended' (PDF Ref)");
991
    } else {
968
    } else {
992
        initDictFromDict(obj1, page->getResourceDict());
969
        obj1 = Object(page->getResourceDict());
993
        if (!obj1->isDict())
970
        if (!obj1.isDict())
994
            pdftex_fail("PDF inclusion: invalid resources dict type <%s>",
971
            pdftex_fail("PDF inclusion: invalid resources dict type <%s>",
995
                        obj1->getTypeName());
972
                        obj1.getTypeName());
996
        pdf_newline();
973
        pdf_newline();
997
        pdf_puts("/Resources <<\n");
974
        pdf_puts("/Resources <<\n");
998
        for (i = 0, l = obj1->dictGetLength(); i < l; ++i) {
975
        for (i = 0, l = obj1.dictGetLength(); i < l; ++i) {
999
            obj1->dictGetVal(i, &obj2);
976
            obj2 = obj1.dictGetVal(i);
1000
            key = obj1->dictGetKey(i);
977
            key = obj1.dictGetKey(i);
1001
            if (strcmp("Font", key) == 0)
978
            if (strcmp("Font", key) == 0)
1002
                copyFontResources(&obj2);
979
                copyFontResources(&obj2);
1003
            else if (strcmp("ProcSet", key) == 0)
980
            else if (strcmp("ProcSet", key) == 0)
Lines 1009-1016 Link Here
1009
    }
986
    }
1010
987
1011
    // write the page contents
988
    // write the page contents
1012
    page->getContents(&contents);
989
    contents = page->getContents();
1013
    if (contents->isStream()) {
990
    if (contents.isStream()) {
1014
991
1015
        // Variant A: get stream and recompress under control
992
        // Variant A: get stream and recompress under control
1016
        // of \pdfcompresslevel
993
        // of \pdfcompresslevel
Lines 1021-1056 Link Here
1021
998
1022
        // Variant B: copy stream without recompressing
999
        // Variant B: copy stream without recompressing
1023
        //
1000
        //
1024
        contents->streamGetDict()->lookup("F", &obj1);
1001
        obj1 = contents.streamGetDict()->lookup("F");
1025
        if (!obj1->isNull()) {
1002
        if (!obj1.isNull()) {
1026
            pdftex_fail("PDF inclusion: Unsupported external stream");
1003
            pdftex_fail("PDF inclusion: Unsupported external stream");
1027
        }
1004
        }
1028
        contents->streamGetDict()->lookup("Length", &obj1);
1005
        obj1 = contents.streamGetDict()->lookup("Length");
1029
        assert(!obj1->isNull());
1006
        assert(!obj1.isNull());
1030
        pdf_puts("/Length ");
1007
        pdf_puts("/Length ");
1031
        copyObject(&obj1);
1008
        copyObject(&obj1);
1032
        pdf_puts("\n");
1009
        pdf_puts("\n");
1033
        contents->streamGetDict()->lookup("Filter", &obj1);
1010
        obj1 = contents.streamGetDict()->lookup("Filter");
1034
        if (!obj1->isNull()) {
1011
        if (!obj1.isNull()) {
1035
            pdf_puts("/Filter ");
1012
            pdf_puts("/Filter ");
1036
            copyObject(&obj1);
1013
            copyObject(&obj1);
1037
            pdf_puts("\n");
1014
            pdf_puts("\n");
1038
            contents->streamGetDict()->lookup("DecodeParms", &obj1);
1015
            obj1 = contents.streamGetDict()->lookup("DecodeParms");
1039
            if (!obj1->isNull()) {
1016
            if (!obj1.isNull()) {
1040
                pdf_puts("/DecodeParms ");
1017
                pdf_puts("/DecodeParms ");
1041
                copyObject(&obj1);
1018
                copyObject(&obj1);
1042
                pdf_puts("\n");
1019
                pdf_puts("\n");
1043
            }
1020
            }
1044
        }
1021
        }
1045
        pdf_puts(">>\nstream\n");
1022
        pdf_puts(">>\nstream\n");
1046
        copyStream(contents->getStream()->getUndecodedStream());
1023
        copyStream(contents.getStream()->getUndecodedStream());
1047
        pdfendstream();
1024
        pdfendstream();
1048
    } else if (contents->isArray()) {
1025
    } else if (contents.isArray()) {
1049
        pdfbeginstream();
1026
        pdfbeginstream();
1050
        for (i = 0, l = contents->arrayGetLength(); i < l; ++i) {
1027
        for (i = 0, l = contents.arrayGetLength(); i < l; ++i) {
1051
            Object contentsobj;
1028
            Object contentsobj = contents.arrayGet(i);
1052
            copyStream((contents->arrayGet(i, &contentsobj))->getStream());
1029
            copyStream(contentsobj.getStream());
1053
            contentsobj.free();
1054
            if (i < l - 1)
1030
            if (i < l - 1)
1055
                pdf_newline();  // add a newline after each stream except the last
1031
                pdf_newline();  // add a newline after each stream except the last
1056
        }
1032
        }
(-)source.orig/texk/web2c/pdftexdir/pdftosrc.cc (-21 / +14 lines)
Lines 86-107 Link Here
86
            objgen = atoi(argv[3]);
86
            objgen = atoi(argv[3]);
87
    }
87
    }
88
    xref = doc->getXRef();
88
    xref = doc->getXRef();
89
    catalogDict.initNull();
89
    catalogDict = xref->getCatalog();
90
    xref->getCatalog(&catalogDict);
91
    if (!catalogDict.isDict("Catalog")) {
90
    if (!catalogDict.isDict("Catalog")) {
92
        fprintf(stderr, "No Catalog found\n");
91
        fprintf(stderr, "No Catalog found\n");
93
        exit(1);
92
        exit(1);
94
    }
93
    }
95
    srcStream.initNull();
94
    srcStream = Object(objNull);
96
    if (objnum == 0) {
95
    if (objnum == 0) {
97
        catalogDict.dictLookup("SourceObject", &srcStream);
96
        srcStream = catalogDict.dictLookup("SourceObject");
98
        static char const_SourceFile[] = "SourceFile";
97
        static char const_SourceFile[] = "SourceFile";
99
        if (!srcStream.isStream(const_SourceFile)) {
98
        if (!srcStream.isStream(const_SourceFile)) {
100
            fprintf(stderr, "No SourceObject found\n");
99
            fprintf(stderr, "No SourceObject found\n");
101
            exit(1);
100
            exit(1);
102
        }
101
        }
103
        srcName.initNull();
102
        srcName = srcStream.getStream()->getDict()->lookup("SourceName");
104
        srcStream.getStream()->getDict()->lookup("SourceName", &srcName);
105
        if (!srcName.isString()) {
103
        if (!srcName.isString()) {
106
            fprintf(stderr, "No SourceName found\n");
104
            fprintf(stderr, "No SourceName found\n");
107
            exit(1);
105
            exit(1);
Lines 110-116 Link Here
110
        // We cannot free srcName, as objname shares its string.
108
        // We cannot free srcName, as objname shares its string.
111
        // srcName.free();
109
        // srcName.free();
112
    } else if (objnum > 0) {
110
    } else if (objnum > 0) {
113
        xref->fetch(objnum, objgen, &srcStream);
111
        srcStream = xref->fetch(objnum, objgen);
114
        if (!srcStream.isStream()) {
112
        if (!srcStream.isStream()) {
115
            fprintf(stderr, "Not a Stream object\n");
113
            fprintf(stderr, "Not a Stream object\n");
116
            exit(1);
114
            exit(1);
Lines 159-187 Link Here
159
                int localOffset = 0;
157
                int localOffset = 0;
160
                Guint firstOffset;
158
                Guint firstOffset;
161
159
162
                assert(xref->fetch(e->offset, 0, &objStr)->isStream());
160
                objStr = xref->fetch(e->offset, 0);
163
                nObjects = objStr.streamGetDict()->lookup("N", &obj1)->getInt();
161
                assert(objStr.isStream());
164
                obj1.free();
162
                obj1 = objStr.streamGetDict()->lookup("N");
165
                first = objStr.streamGetDict()->lookup("First", &obj1)->getInt();
163
                nObjects = obj1.getInt();
166
                obj1.free();
164
                obj1 = objStr.streamGetDict()->lookup("First");
165
                first = obj1.getInt();
167
                firstOffset = objStr.getStream()->getBaseStream()->getStart() + first;
166
                firstOffset = objStr.getStream()->getBaseStream()->getStart() + first;
168
167
169
                // parse the header: object numbers and offsets
168
                // parse the header: object numbers and offsets
170
                objStr.streamReset();
169
                objStr.streamReset();
171
                obj1.initNull();
170
                str = new EmbedStream(objStr.getStream(), Object(objNull), gTrue, first);
172
                str = new EmbedStream(objStr.getStream(), &obj1, gTrue, first);
173
                parser = new Parser(xref, new Lexer(xref, str), gFalse);
171
                parser = new Parser(xref, new Lexer(xref, str), gFalse);
174
                for (n = 0; n < nObjects; ++n) {
172
                for (n = 0; n < nObjects; ++n) {
175
                    parser->getObj(&obj1);
173
                    obj1 = parser->getObj();
176
                    parser->getObj(&obj2);
174
                    obj2 = parser->getObj();
177
                    if (n == e->gen)
175
                    if (n == e->gen)
178
                        localOffset = obj2.getInt();
176
                        localOffset = obj2.getInt();
179
                    obj1.free();
180
                    obj2.free();
181
                }
177
                }
182
                while (str->getChar() != EOF) ;
178
                while (str->getChar() != EOF) ;
183
                delete parser;
179
                delete parser;
184
                objStr.free();
185
180
186
                fprintf(outfile, "%.10lu 00000 n\n",
181
                fprintf(outfile, "%.10lu 00000 n\n",
187
                        (long unsigned)(firstOffset + localOffset));
182
                        (long unsigned)(firstOffset + localOffset));
Lines 192-198 Link Here
192
        s->reset();
187
        s->reset();
193
        while ((c = s->getChar()) != EOF)
188
        while ((c = s->getChar()) != EOF)
194
            fputc(c, outfile);
189
            fputc(c, outfile);
195
        srcStream.free();
196
    }
190
    }
197
    if (objnum == 0)
191
    if (objnum == 0)
198
        fprintf(stderr, "Source file extracted to %s\n", outname);
192
        fprintf(stderr, "Source file extracted to %s\n", outname);
Lines 201-207 Link Here
201
    else
195
    else
202
        fprintf(stderr, "Cross-reference table extracted to %s\n", outname);
196
        fprintf(stderr, "Cross-reference table extracted to %s\n", outname);
203
    fclose(outfile);
197
    fclose(outfile);
204
    catalogDict.free();
205
    delete doc;
198
    delete doc;
206
    delete globalParams;
199
    delete globalParams;
207
}
200
}

Return to bug 629710