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

Collapse All | Expand All

(-)luatex-beta-0.70.1.gentoo/source/texk/web2c/luatexdir/lua/lepdflib.cc (-120 / +67 lines)
Lines 1-7 Link Here
1
/* lepdflib.cc
1
/* lepdflib.cc
2
2
3
   Copyright 2009-2011 Taco Hoekwater <taco@luatex.org>
3
   Copyright 2009-2012 Taco Hoekwater <taco@luatex.org>
4
   Copyright 2009-2011 Hartmut Henkel <hartmut@luatex.org>
4
   Copyright 2009-2012 Hartmut Henkel <hartmut@luatex.org>
5
5
6
   This file is part of LuaTeX.
6
   This file is part of LuaTeX.
7
7
Lines 19-26 Link Here
19
   with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
19
   with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
20
20
21
static const char _svn_version[] =
21
static const char _svn_version[] =
22
    "$Id: lepdflib.cc 4134 2011-04-11 20:54:58Z hhenkel $ "
22
    "$Id: poppler022.patch,v 1.1 2013/03/10 12:51:59 dilfridge Exp $ "
23
    "$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.70.1/source/texk/web2c/luatexdir/lua/lepdflib.cc $";
23
    "$URL: https://foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/lepdflib.cc $";
24
24
25
#include "image/epdf.h"
25
#include "image/epdf.h"
26
26
Lines 49-63 Link Here
49
//**********************************************************************
49
//**********************************************************************
50
50
51
#define M_Annot            "Annot"
51
#define M_Annot            "Annot"
52
#define M_AnnotBorder      "AnnotBorder"
53
#define M_AnnotBorderStyle "AnnotBorderStyle"
54
#define M_Annots           "Annots"
52
#define M_Annots           "Annots"
55
#define M_Array            "Array"
53
#define M_Array            "Array"
56
#define M_Catalog          "Catalog"
54
#define M_Catalog          "Catalog"
57
#define M_EmbFile          "EmbFile"
58
#define M_Dict             "Dict"
55
#define M_Dict             "Dict"
59
#define M_GooString        "GooString"
56
#define M_GooString        "GooString"
60
#define M_LinkDest         "LinkDest"
57
#define M_LinkDest         "LinkDest"
58
#define M_Link             "Link"
61
#define M_Links            "Links"
59
#define M_Links            "Links"
62
#define M_Object           "Object"
60
#define M_Object           "Object"
63
#define M_Page             "Page"
61
#define M_Page             "Page"
Lines 65-72 Link Here
65
#define M_PDFRectangle     "PDFRectangle"
63
#define M_PDFRectangle     "PDFRectangle"
66
#define M_Ref              "Ref"
64
#define M_Ref              "Ref"
67
#define M_Stream           "Stream"
65
#define M_Stream           "Stream"
68
#define M_XRef             "XRef"
69
#define M_XRefEntry        "XRefEntry"
66
#define M_XRefEntry        "XRefEntry"
67
#define M_XRef             "XRef"
70
68
71
//**********************************************************************
69
//**********************************************************************
72
70
Lines 84-96 Link Here
84
new_poppler_userdata(PDFDoc);
82
new_poppler_userdata(PDFDoc);
85
83
86
new_poppler_userdata(Annot);
84
new_poppler_userdata(Annot);
87
new_poppler_userdata(AnnotBorder);
88
//new_poppler_userdata(AnnotBorderStyle);
89
new_poppler_userdata(Annots);
90
new_poppler_userdata(Array);
85
new_poppler_userdata(Array);
91
new_poppler_userdata(Catalog);
86
new_poppler_userdata(Catalog);
92
new_poppler_userdata(Dict);
87
new_poppler_userdata(Dict);
93
//new_poppler_userdata(GooString);
94
new_poppler_userdata(LinkDest);
88
new_poppler_userdata(LinkDest);
95
new_poppler_userdata(Links);
89
new_poppler_userdata(Links);
96
new_poppler_userdata(Object);
90
new_poppler_userdata(Object);
Lines 99-105 Link Here
99
new_poppler_userdata(Ref);
93
new_poppler_userdata(Ref);
100
new_poppler_userdata(Stream);
94
new_poppler_userdata(Stream);
101
new_poppler_userdata(XRef);
95
new_poppler_userdata(XRef);
102
//new_poppler_userdata(XRefEntry);
103
96
104
//**********************************************************************
97
//**********************************************************************
105
98
Lines 134-186 Link Here
134
    return 1;                   // doc path
127
    return 1;                   // doc path
135
}
128
}
136
129
137
static int l_new_Annot(lua_State * L)
138
{
139
    udstruct *uxref, *udict, *ucatalog, *uref, *uout;
140
    uxref = (udstruct *) luaL_checkudata(L, 1, M_XRef);
141
    udict = (udstruct *) luaL_checkudata(L, 2, M_Dict);
142
    ucatalog = (udstruct *) luaL_checkudata(L, 3, M_Catalog);
143
    uref = (udstruct *) luaL_checkudata(L, 4, M_Ref);
144
    if (uxref->pd != ucatalog->pd || uxref->pd != udict->pd
145
        || uxref->pd != uref->pd)
146
        pdfdoc_differs_error(L);
147
    if ((uxref->pd != NULL && uxref->pd->pc != uxref->pc) ||
148
        (ucatalog->pd != NULL && ucatalog->pd->pc != ucatalog->pc) ||
149
        (udict->pd != NULL && udict->pd->pc != udict->pc) ||
150
        (uref->pd != NULL && uref->pd->pc != uref->pc))
151
        pdfdoc_changed_error(L);
152
    uout = new_Annot_userdata(L);
153
    uout->d =
154
        new Annot(udict->pd->doc, (Dict *) udict->d,
155
                  (Object *) uref->d);
156
    uout->atype = ALLOC_LEPDF;
157
    uout->pc = uxref->pc;
158
    uout->pd = uxref->pd;
159
    return 1;
160
}
161
162
static int l_new_Annots(lua_State * L)
163
{
164
    udstruct *uxref, *ucatalog, *uannotsobj, *uout;
165
    uxref = (udstruct *) luaL_checkudata(L, 1, M_XRef);
166
    ucatalog = (udstruct *) luaL_checkudata(L, 2, M_Catalog);
167
    uannotsobj = (udstruct *) luaL_checkudata(L, 3, M_Object);
168
    if (uxref->pd != ucatalog->pd || uxref->pd != uannotsobj->pd)
169
        pdfdoc_differs_error(L);
170
    if ((uxref->pd != NULL && uxref->pd->pc != uxref->pc)
171
        || (ucatalog->pd != NULL && ucatalog->pd->pc != ucatalog->pc)
172
        || (uannotsobj->pd != NULL && uannotsobj->pd->pc != uannotsobj->pc))
173
        pdfdoc_changed_error(L);
174
    uout = new_Annots_userdata(L);
175
    uout->d =
176
        new Annots(uannotsobj->pd->doc,
177
                   (Object *) uannotsobj->d);
178
    uout->atype = ALLOC_LEPDF;
179
    uout->pc = uxref->pc;
180
    uout->pd = uxref->pd;
181
    return 1;
182
}
183
184
static int l_new_Array(lua_State * L)
130
static int l_new_Array(lua_State * L)
185
{
131
{
186
    udstruct *uxref, *uout;
132
    udstruct *uxref, *uout;
Lines 235-242 Link Here
235
181
236
static const struct luaL_Reg epdflib[] = {
182
static const struct luaL_Reg epdflib[] = {
237
    {"open", l_open_PDFDoc},
183
    {"open", l_open_PDFDoc},
238
    {"Annot", l_new_Annot},
239
    {"Annots", l_new_Annots},
240
    {"Array", l_new_Array},
184
    {"Array", l_new_Array},
241
    {"Dict", l_new_Dict},
185
    {"Dict", l_new_Dict},
242
    {"Object", l_new_Object},
186
    {"Object", l_new_Object},
Lines 359-370 Link Here
359
    return 1;                                                  \
303
    return 1;                                                  \
360
}
304
}
361
305
306
#define m_poppler_check_string(in, function)                   \
307
static int m_##in##_##function(lua_State * L)                  \
308
{                                                              \
309
    const char *s;                                             \
310
    udstruct *uin;                                             \
311
    uin = (udstruct *) luaL_checkudata(L, 1, M_##in);          \
312
    if (uin->pd != NULL && uin->pd->pc != uin->pc)             \
313
        pdfdoc_changed_error(L);                               \
314
    s = luaL_checkstring(L, 2);                                \
315
    if (((in *) uin->d)->function((char *) s))                 \
316
        lua_pushboolean(L, 1);                                 \
317
    else                                                       \
318
        lua_pushboolean(L, 0);                                 \
319
    return 1;                                                  \
320
}
321
362
//**********************************************************************
322
//**********************************************************************
363
// Annot
323
// Annot
364
324
365
m_poppler_get_BOOL(Annot, isOk);
325
m_poppler_get_BOOL(Annot, isOk);
366
m_poppler_get_OBJECT(Annot, getAppearanceResDict);
367
m_poppler_get_poppler(Annot, AnnotBorder, getBorder);
368
326
369
static int m_Annot_match(lua_State * L)
327
static int m_Annot_match(lua_State * L)
370
{
328
{
Lines 398-405 Link Here
398
356
399
static const struct luaL_Reg Annot_m[] = {
357
static const struct luaL_Reg Annot_m[] = {
400
    {"isOk", m_Annot_isOk},
358
    {"isOk", m_Annot_isOk},
401
    {"getAppearanceResDict", m_Annot_getAppearanceResDict},
402
    {"getBorder", m_Annot_getBorder},
403
    {"match", m_Annot_match},
359
    {"match", m_Annot_match},
404
    {"__tostring", m_Annot__tostring},
360
    {"__tostring", m_Annot__tostring},
405
    {"__gc", m_Annot__gc},
361
    {"__gc", m_Annot__gc},
Lines 654-659 Link Here
654
610
655
m_poppler_get_poppler(Catalog, Object, getDests);
611
m_poppler_get_poppler(Catalog, Object, getDests);
656
m_poppler_get_INT(Catalog, numEmbeddedFiles);
612
m_poppler_get_INT(Catalog, numEmbeddedFiles);
613
657
m_poppler_get_INT(Catalog, numJS);
614
m_poppler_get_INT(Catalog, numJS);
658
615
659
static int m_Catalog_getJS(lua_State * L)
616
static int m_Catalog_getJS(lua_State * L)
Lines 770-789 Link Here
770
    return 0;
727
    return 0;
771
}
728
}
772
729
773
static int m_Dict_is(lua_State * L)
730
m_poppler_check_string(Dict, is);
774
{
775
    const char *s;
776
    udstruct *uin;
777
    uin = (udstruct *) luaL_checkudata(L, 1, M_Dict);
778
    if (uin->pd != NULL && uin->pd->pc != uin->pc)
779
        pdfdoc_changed_error(L);
780
    s = luaL_checkstring(L, 2);
781
    if (((Dict *) uin->d)->is((char *) s))
782
        lua_pushboolean(L, 1);
783
    else
784
        lua_pushboolean(L, 0);
785
    return 1;
786
}
787
731
788
static int m_Dict_lookup(lua_State * L)
732
static int m_Dict_lookup(lua_State * L)
789
{
733
{
Lines 894-899 Link Here
894
    return 1;
838
    return 1;
895
}
839
}
896
840
841
m_poppler_check_string(Dict, hasKey);
842
897
m_poppler__tostring(Dict);
843
m_poppler__tostring(Dict);
898
844
899
static const struct luaL_Reg Dict_m[] = {
845
static const struct luaL_Reg Dict_m[] = {
Lines 910-915 Link Here
910
    {"getKey", m_Dict_getKey},
856
    {"getKey", m_Dict_getKey},
911
    {"getVal", m_Dict_getVal},
857
    {"getVal", m_Dict_getVal},
912
    {"getValNF", m_Dict_getValNF},
858
    {"getValNF", m_Dict_getValNF},
859
    {"hasKey", m_Dict_hasKey},
913
    {"__tostring", m_Dict__tostring},
860
    {"__tostring", m_Dict__tostring},
914
    {NULL, NULL}                // sentinel
861
    {NULL, NULL}                // sentinel
915
};
862
};
Lines 1017-1025 Link Here
1017
//**********************************************************************
964
//**********************************************************************
1018
// Links
965
// Links
1019
966
967
m_poppler_get_INT(Links, getNumLinks);
968
1020
m_poppler__tostring(Links);
969
m_poppler__tostring(Links);
1021
970
1022
static const struct luaL_Reg Links_m[] = {
971
static const struct luaL_Reg Links_m[] = {
972
    {"getNumLinks", m_Links_getNumLinks},
973
    //{"getLink", m_Links_getLink},
1023
    {"__tostring", m_Links__tostring},
974
    {"__tostring", m_Links__tostring},
1024
    {NULL, NULL}                // sentinel
975
    {NULL, NULL}                // sentinel
1025
};
976
};
Lines 1925-1952 Link Here
1925
m_poppler_get_poppler(Page, Dict, getResourceDict);
1876
m_poppler_get_poppler(Page, Dict, getResourceDict);
1926
m_poppler_get_OBJECT(Page, getAnnots);
1877
m_poppler_get_OBJECT(Page, getAnnots);
1927
1878
1928
static int m_Page_getLinks(lua_State * L)
1929
{
1930
    Links *links;
1931
    udstruct *uin, *ucat, *uout;
1932
    uin = (udstruct *) luaL_checkudata(L, 1, M_Page);
1933
    ucat = (udstruct *) luaL_checkudata(L, 2, M_Catalog);
1934
    if (uin->pd != NULL && ucat->pd != NULL && uin->pd != ucat->pd)
1935
        pdfdoc_differs_error(L);
1936
    if ((uin->pd != NULL && uin->pd->pc != uin->pc)
1937
        || (ucat->pd != NULL && ucat->pd->pc != ucat->pd->pc))
1938
        pdfdoc_changed_error(L);
1939
    links = ((Page *) uin->d)->getLinks();
1940
    if (links != NULL) {
1941
        uout = new_Links_userdata(L);
1942
        uout->d = links;
1943
        uout->pc = uin->pc;
1944
        uout->pd = uin->pd;
1945
    } else
1946
        lua_pushnil(L);
1947
    return 1;
1948
}
1949
1950
m_poppler_get_OBJECT(Page, getContents);
1879
m_poppler_get_OBJECT(Page, getContents);
1951
1880
1952
m_poppler__tostring(Page);
1881
m_poppler__tostring(Page);
Lines 1973-1979 Link Here
1973
    {"getSeparationInfo", m_Page_getSeparationInfo},
1902
    {"getSeparationInfo", m_Page_getSeparationInfo},
1974
    {"getResourceDict", m_Page_getResourceDict},
1903
    {"getResourceDict", m_Page_getResourceDict},
1975
    {"getAnnots", m_Page_getAnnots},
1904
    {"getAnnots", m_Page_getAnnots},
1976
    {"getLinks", m_Page_getLinks},
1977
    {"getContents", m_Page_getContents},
1905
    {"getContents", m_Page_getContents},
1978
    {"__tostring", m_Page__tostring},
1906
    {"__tostring", m_Page__tostring},
1979
    {NULL, NULL}                // sentinel
1907
    {NULL, NULL}                // sentinel
Lines 2158-2176 Link Here
2158
2086
2159
static int m_PDFDoc_getLinks(lua_State * L)
2087
static int m_PDFDoc_getLinks(lua_State * L)
2160
{
2088
{
2161
    int i;
2089
    int i, pages;
2162
    Links *links;
2090
    Links *links;
2163
    udstruct *uin, *uout;
2091
    udstruct *uin, *uout;
2164
    uin = (udstruct *) luaL_checkudata(L, 1, M_PDFDoc);
2092
    uin = (udstruct *) luaL_checkudata(L, 1, M_PDFDoc);
2165
    if (uin->pd != NULL && uin->pd->pc != uin->pc)
2093
    if (uin->pd != NULL && uin->pd->pc != uin->pc)
2166
        pdfdoc_changed_error(L);
2094
        pdfdoc_changed_error(L);
2167
    i = luaL_checkint(L, 2);
2095
    i = luaL_checkint(L, 2);
2168
    links = ((PdfDocument *) uin->d)->doc->getLinks(i);
2096
    pages = ((PdfDocument *) uin->d)->doc->getNumPages();
2169
    if (links != NULL) {
2097
    if (i > 0 && i <= pages) {
2170
        uout = new_Links_userdata(L);
2098
        links = ((PdfDocument *) uin->d)->doc->getLinks(i);
2171
        uout->d = links;
2099
        if (links != NULL) {
2172
        uout->pc = uin->pc;
2100
            uout = new_Links_userdata(L);
2173
        uout->pd = uin->pd;
2101
            uout->d = links;
2102
            uout->pc = uin->pc;
2103
            uout->pd = uin->pd;
2104
        } else
2105
            lua_pushnil(L);
2174
    } else
2106
    } else
2175
        lua_pushnil(L);
2107
        lua_pushnil(L);
2176
    return 1;
2108
    return 1;
Lines 2249-2254 Link Here
2249
m_PDFDoc_INT(getPDFMajorVersion);
2181
m_PDFDoc_INT(getPDFMajorVersion);
2250
m_PDFDoc_INT(getPDFMinorVersion);
2182
m_PDFDoc_INT(getPDFMinorVersion);
2251
2183
2184
m_poppler__tostring(PDFDoc);
2185
2252
static int m_PDFDoc__gc(lua_State * L)
2186
static int m_PDFDoc__gc(lua_State * L)
2253
{
2187
{
2254
    udstruct *uin;
2188
    udstruct *uin;
Lines 2292-2297 Link Here
2292
    {"getDocInfoNF", m_PDFDoc_getDocInfoNF},
2226
    {"getDocInfoNF", m_PDFDoc_getDocInfoNF},
2293
    {"getPDFMajorVersion", m_PDFDoc_getPDFMajorVersion},
2227
    {"getPDFMajorVersion", m_PDFDoc_getPDFMajorVersion},
2294
    {"getPDFMinorVersion", m_PDFDoc_getPDFMinorVersion},
2228
    {"getPDFMinorVersion", m_PDFDoc_getPDFMinorVersion},
2229
    {"__tostring", m_PDFDoc__tostring},
2295
    {"__gc", m_PDFDoc__gc},     // finalizer
2230
    {"__gc", m_PDFDoc__gc},     // finalizer
2296
    {NULL, NULL}                // sentinel
2231
    {NULL, NULL}                // sentinel
2297
};
2232
};
Lines 2437-2447 Link Here
2437
    "Flate", "JBIG2", "JPX", "Weird", NULL
2372
    "Flate", "JBIG2", "JPX", "Weird", NULL
2438
};
2373
};
2439
2374
2440
#if 0
2441
static const char *StreamColorSpaceModeNames[] =
2442
    { "CSNone", "CSDeviceGray", "CSDeviceRGB", "CSDeviceCMYK", NULL };
2443
#endif
2444
2445
m_poppler_get_INT(Stream, getKind);
2375
m_poppler_get_INT(Stream, getKind);
2446
2376
2447
static int m_Stream_getKindName(lua_State * L)
2377
static int m_Stream_getKindName(lua_State * L)
Lines 2527-2537 Link Here
2527
m_poppler_get_OBJECT(XRef, getDocInfo);
2457
m_poppler_get_OBJECT(XRef, getDocInfo);
2528
m_poppler_get_OBJECT(XRef, getDocInfoNF);
2458
m_poppler_get_OBJECT(XRef, getDocInfoNF);
2529
m_poppler_get_INT(XRef, getNumObjects);
2459
m_poppler_get_INT(XRef, getNumObjects);
2530
// getLastXRefPos
2531
m_poppler_get_INT(XRef, getRootNum);
2460
m_poppler_get_INT(XRef, getRootNum);
2532
m_poppler_get_INT(XRef, getRootGen);
2461
m_poppler_get_INT(XRef, getRootGen);
2533
// getStreamEnd
2462
// getStreamEnd
2534
// getEntry
2463
2464
static int m_XRef_getNumEntry(lua_State * L)
2465
{
2466
    int i, offset;
2467
    udstruct *uin;
2468
    uin = (udstruct *) luaL_checkudata(L, 1, M_XRef);
2469
    if (uin->pd != NULL && uin->pd->pc != uin->pc)
2470
        pdfdoc_changed_error(L);
2471
    offset = luaL_checkint(L, 2);
2472
    i = ((XRef *) uin->d)->getNumEntry(offset);
2473
    if (i >= 0)
2474
        lua_pushinteger(L, i);
2475
    else
2476
        lua_pushnil(L);
2477
    return 1;
2478
}
2479
2535
m_poppler_get_poppler(XRef, Object, getTrailerDict);
2480
m_poppler_get_poppler(XRef, Object, getTrailerDict);
2536
2481
2537
m_poppler__tostring(XRef);
2482
m_poppler__tostring(XRef);
Lines 2553-2562 Link Here
2553
    {"getDocInfo", m_XRef_getDocInfo},
2498
    {"getDocInfo", m_XRef_getDocInfo},
2554
    {"getDocInfoNF", m_XRef_getDocInfoNF},
2499
    {"getDocInfoNF", m_XRef_getDocInfoNF},
2555
    {"getNumObjects", m_XRef_getNumObjects},
2500
    {"getNumObjects", m_XRef_getNumObjects},
2556
    //
2557
    {"getRootNum", m_XRef_getRootNum},
2501
    {"getRootNum", m_XRef_getRootNum},
2558
    {"getRootGen", m_XRef_getRootGen},
2502
    {"getRootGen", m_XRef_getRootGen},
2559
    //
2503
    // {"getStreamEnd", m_XRef_getStreamEnd},
2504
    {"getNumEntry", m_XRef_getNumEntry},
2560
    {"getTrailerDict", m_XRef_getTrailerDict},
2505
    {"getTrailerDict", m_XRef_getTrailerDict},
2561
    {"__tostring", m_XRef__tostring},
2506
    {"__tostring", m_XRef__tostring},
2562
    {NULL, NULL}                // sentinel
2507
    {NULL, NULL}                // sentinel
Lines 2565-2571 Link Here
2565
//**********************************************************************
2510
//**********************************************************************
2566
// XRefEntry
2511
// XRefEntry
2567
2512
2513
m_poppler__tostring(XRefEntry);
2514
2568
static const struct luaL_Reg XRefEntry_m[] = {
2515
static const struct luaL_Reg XRefEntry_m[] = {
2516
    {"__tostring", m_XRefEntry__tostring},
2569
    {NULL, NULL}                // sentinel
2517
    {NULL, NULL}                // sentinel
2570
};
2518
};
2571
2519
Lines 2582-2588 Link Here
2582
int luaopen_epdf(lua_State * L)
2530
int luaopen_epdf(lua_State * L)
2583
{
2531
{
2584
    register_meta(Annot);
2532
    register_meta(Annot);
2585
    // TODO register_meta(AnnotBorder);
2586
    register_meta(Annots);
2533
    register_meta(Annots);
2587
    register_meta(Array);
2534
    register_meta(Array);
2588
    register_meta(Catalog);
2535
    register_meta(Catalog);

Return to bug 449538