dc01ed7
=== modified file 'filter/pdf.cxx'
dc01ed7
--- filter/pdf.cxx	2017-08-15 18:32:47 +0000
dc01ed7
+++ filter/pdf.cxx	2017-09-07 16:02:01 +0000
dc01ed7
@@ -129,64 +129,125 @@
dc01ed7
     Object array;
dc01ed7
     Ref r;
dc01ed7
 
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+    pageobj = xref->fetch(pageref->num, pageref->gen);
dc01ed7
+#else
dc01ed7
     xref->fetch(pageref->num, pageref->gen, &pageobj);
dc01ed7
-    if (!pageobj.isDict() || !pageobj.dictLookupNF("Contents", &contents)) {
dc01ed7
+#endif
dc01ed7
+    if (!pageobj.isDict() ||
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+        (contents = pageobj.dictLookupNF("Contents")).isNull()
dc01ed7
+#else
dc01ed7
+        !pageobj.dictLookupNF("Contents", &contents)
dc01ed7
+#endif
dc01ed7
+    ) {
dc01ed7
         fprintf(stderr, "Error: malformed pdf\n");
dc01ed7
         return;
dc01ed7
     }
dc01ed7
 
dc01ed7
-    if (contents.isRef())
dc01ed7
+    if (contents.isRef()) {
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+        contents = xref->fetch(contents.getRefNum(), contents.getRefGen());
dc01ed7
+#else
dc01ed7
         xref->fetch(contents.getRefNum(), contents.getRefGen(), &contents);
dc01ed7
+#endif
dc01ed7
+    }
dc01ed7
 
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+    (void) lenobj;
dc01ed7
+    dict = Object(new Dict(xref));
dc01ed7
+    dict.dictSet("Length", Object(static_cast<int>(len)));
dc01ed7
+    stream = Object(static_cast<Stream *>(new MemStream(buf, 0, len, std::move(dict))));
dc01ed7
+#else
dc01ed7
     lenobj.initInt(len);
dc01ed7
     dict.initDict(xref);
dc01ed7
     dict.dictSet("Length", &lenobj);
dc01ed7
     stream.initStream(new MemStream(buf, 0, len, &dict));
dc01ed7
+#endif
dc01ed7
 
dc01ed7
     r = xref->addIndirectObject(&stream);
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+    streamrefobj = Object(r.num, r.gen);
dc01ed7
+#else
dc01ed7
     streamrefobj.initRef(r.num, r.gen);
dc01ed7
+#endif
dc01ed7
 
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+    array = Object(new Array(xref));
dc01ed7
+    array.arrayAdd(std::move(streamrefobj));
dc01ed7
+#else
dc01ed7
     array.initArray(xref);
dc01ed7
     array.arrayAdd(&streamrefobj);
dc01ed7
+#endif
dc01ed7
 
dc01ed7
     if (contents.isStream()) {
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+        contents = pageobj.dictLookupNF("Contents"); // streams must be indirect, i.e. not fetch()-ed
dc01ed7
+        array.arrayAdd(std::move(contents));
dc01ed7
+#else
dc01ed7
         pageobj.dictLookupNF("Contents", &contents); // streams must be indirect, i.e. not fetch()-ed
dc01ed7
         array.arrayAdd(&contents);
dc01ed7
+#endif
dc01ed7
     }
dc01ed7
     else if (contents.isArray()) {
dc01ed7
         int i, len = contents.arrayGetLength();
dc01ed7
         Object obj;
dc01ed7
         for (i = 0; i < len; i++) {
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+            obj = contents.arrayGetNF(i);
dc01ed7
+            array.arrayAdd(std::move(obj));
dc01ed7
+#else
dc01ed7
             contents.arrayGetNF(i, &obj);
dc01ed7
             array.arrayAdd(&obj);
dc01ed7
+#endif
dc01ed7
         }
dc01ed7
     }
dc01ed7
     else
dc01ed7
         fprintf(stderr, "Error: malformed pdf\n");
dc01ed7
 
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+    pageobj.dictSet("Contents", std::move(array));
dc01ed7
+#else
dc01ed7
     pageobj.dictSet("Contents", &array);
dc01ed7
+#endif
dc01ed7
 
dc01ed7
     xref->setModifiedObject(&pageobj, *pageref);
dc01ed7
+#if POPPLER_VERSION_MAJOR <= 0 && POPPLER_VERSION_MINOR < 58
dc01ed7
     pageobj.free();
dc01ed7
-}
dc01ed7
-
dc01ed7
-
dc01ed7
+#endif
dc01ed7
+}
dc01ed7
+
dc01ed7
+
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+static Object name_object(const char *s)
dc01ed7
+{
dc01ed7
+    return Object(new GooString(s));
dc01ed7
+}
dc01ed7
+#else
dc01ed7
 static Object * name_object(const char *s)
dc01ed7
 {
dc01ed7
     Object *o = new Object();
dc01ed7
     o->initName((char *)s);
dc01ed7
     return o;
dc01ed7
 }
dc01ed7
+#endif
dc01ed7
 
dc01ed7
 /*
dc01ed7
  * Create new PDF integer type object.
dc01ed7
  */
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+static Object int_object(int i)
dc01ed7
+{
dc01ed7
+    return Object(i);
dc01ed7
+}
dc01ed7
+#else
dc01ed7
 static Object * int_object(int i)
dc01ed7
 {
dc01ed7
     Object *o = new Object();
dc01ed7
     o->initInt(i);
dc01ed7
     return o;
dc01ed7
 }
dc01ed7
+#endif
dc01ed7
 
dc01ed7
 static Object * get_resource_dict(XRef *xref,
dc01ed7
                                   Dict *pagedict,
dc01ed7
@@ -196,21 +257,36 @@
dc01ed7
     Object res;
dc01ed7
 
dc01ed7
     /* TODO resource dict can also be inherited */
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+    res = pagedict->lookupNF("Resources");
dc01ed7
+    if (res.isNull())
dc01ed7
+#else
dc01ed7
     if (!pagedict->lookupNF("Resources", &res))
dc01ed7
+#endif
dc01ed7
         return NULL;
dc01ed7
 
dc01ed7
     if (res.isRef()) {
dc01ed7
         *resref = res.getRef();
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+        *resdict = xref->fetch(resref->num, resref->gen);
dc01ed7
+#else
dc01ed7
         xref->fetch(resref->num, resref->gen, resdict);
dc01ed7
+#endif
dc01ed7
     }
dc01ed7
     else if (res.isDict()) {
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+        *resdict = res.copy();
dc01ed7
+#else
dc01ed7
         res.copy(resdict);
dc01ed7
+#endif
dc01ed7
         resref->num = 0;
dc01ed7
     }
dc01ed7
     else
dc01ed7
         resdict = NULL;
dc01ed7
 
dc01ed7
+#if POPPLER_VERSION_MAJOR <= 0 && POPPLER_VERSION_MINOR < 58
dc01ed7
     res.free();
dc01ed7
+#endif
dc01ed7
     return resdict;
dc01ed7
 }
dc01ed7
 
dc01ed7
@@ -226,7 +302,11 @@
dc01ed7
     Object resdict;
dc01ed7
     Ref resref;
dc01ed7
 
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+    pageobj = xref->fetch(pageref->num, pageref->gen);
dc01ed7
+#else
dc01ed7
     xref->fetch(pageref->num, pageref->gen, &pageobj);
dc01ed7
+#endif
dc01ed7
     if (!pageobj.isDict()) {
dc01ed7
         fprintf(stderr, "Error: malformed pdf\n");
dc01ed7
         return;
dc01ed7
@@ -234,21 +314,35 @@
dc01ed7
 
dc01ed7
     if (!get_resource_dict(xref, pageobj.getDict(), &resdict, &resref)) {
dc01ed7
         fprintf(stderr, "Error: malformed pdf\n");
dc01ed7
+#if POPPLER_VERSION_MAJOR <= 0 && POPPLER_VERSION_MINOR < 58
dc01ed7
         pageobj.free();
dc01ed7
+#endif
dc01ed7
         return;
dc01ed7
     }
dc01ed7
 
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+    font = Object(new Dict(xref));
dc01ed7
+#else
dc01ed7
     font.initDict(xref);
dc01ed7
+#endif
dc01ed7
     font.dictSet("Type", name_object("Font"));
dc01ed7
     font.dictSet("Subtype", name_object("Type1"));
dc01ed7
     font.dictSet("BaseFont", name_object(name));
dc01ed7
     xref->addIndirectObject(&font);
dc01ed7
 
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+    fonts = resdict.dictLookupNF("Font");
dc01ed7
+#else
dc01ed7
     resdict.dictLookupNF("Font", &fonts);
dc01ed7
+#endif
dc01ed7
     if (fonts.isNull()) {
dc01ed7
         /* Create new font dic obj in page's resources */
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+        resdict.dictSet("Font", Object(new Dict(xref)));
dc01ed7
+#else
dc01ed7
         fonts.initDict(xref);
dc01ed7
         resdict.dictSet("Font", &fonts);
dc01ed7
+#endif
dc01ed7
     }
dc01ed7
 
dc01ed7
     Object *fonts_dic;
dc01ed7
@@ -259,7 +353,11 @@
dc01ed7
         fonts_dic = &fonts;
dc01ed7
     } else if ( fonts.isRef() ) {
dc01ed7
         /* "Font" resource is indirect reference object */
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+        dereferenced_obj = xref->fetch(fonts.getRefNum(), fonts.getRefGen());
dc01ed7
+#else
dc01ed7
         xref->fetch(fonts.getRefNum(), fonts.getRefGen(), &dereferenced_obj);
dc01ed7
+#endif
dc01ed7
         fonts_dic = &dereferenced_obj;
dc01ed7
     }
dc01ed7
 
dc01ed7
@@ -269,7 +367,11 @@
dc01ed7
     }
dc01ed7
 
dc01ed7
     /* Add new entry to "Font" resource */
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+    fonts_dic->dictSet("bannertopdf-font", std::move(font));
dc01ed7
+#else
dc01ed7
     fonts_dic->dictSet("bannertopdf-font", &font);
dc01ed7
+#endif
dc01ed7
 
dc01ed7
     /* Notify poppler about changes */
dc01ed7
     if ( fonts.isRef() ) {
dc01ed7
@@ -281,7 +383,9 @@
dc01ed7
     else
dc01ed7
         xref->setModifiedObject(&resdict, resref);
dc01ed7
 
dc01ed7
+#if POPPLER_VERSION_MAJOR <= 0 && POPPLER_VERSION_MINOR < 58
dc01ed7
     pageobj.free();
dc01ed7
+#endif
dc01ed7
 }
dc01ed7
 
dc01ed7
 
dc01ed7
@@ -293,23 +397,38 @@
dc01ed7
     Array *array;
dc01ed7
     int i;
dc01ed7
 
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+    o = dict->dictLookup(key);
dc01ed7
+    if (o.isNull())
dc01ed7
+#else
dc01ed7
     if (!dict->dictLookup(key, &o))
dc01ed7
+#endif
dc01ed7
         return false;
dc01ed7
 
dc01ed7
     if (!o.isArray()) {
dc01ed7
+#if POPPLER_VERSION_MAJOR <= 0 && POPPLER_VERSION_MINOR < 58
dc01ed7
         o.free();
dc01ed7
+#endif
dc01ed7
         return false;
dc01ed7
     }
dc01ed7
 
dc01ed7
     array = o.getArray();
dc01ed7
     for (i = 0; i < 4; i++) {
dc01ed7
         Object el;
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+        el = array->get(i);
dc01ed7
+        if (el.isNum())
dc01ed7
+            rect[i] = el.getNum();
dc01ed7
+#else
dc01ed7
         if (array->get(i, &el) && el.isNum())
dc01ed7
             rect[i] = el.getNum();
dc01ed7
         el.free();
dc01ed7
+#endif
dc01ed7
     }
dc01ed7
 
dc01ed7
+#if POPPLER_VERSION_MAJOR <= 0 && POPPLER_VERSION_MINOR < 58
dc01ed7
     o.free();
dc01ed7
+#endif
dc01ed7
     return i == 4;
dc01ed7
 }
dc01ed7
 
dc01ed7
@@ -322,6 +441,15 @@
dc01ed7
     Object array;
dc01ed7
     int i;
dc01ed7
 
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+    array = Object(new Array(xref));
dc01ed7
+
dc01ed7
+    for (i = 0; i < 4; i++) {
dc01ed7
+        array.arrayAdd(Object(static_cast<double>(rect[i])));
dc01ed7
+    }
dc01ed7
+
dc01ed7
+    dict->dictSet(key, std::move(array));
dc01ed7
+#else
dc01ed7
     array.initArray(xref);
dc01ed7
 
dc01ed7
     for (i = 0; i < 4; i++) {
dc01ed7
@@ -331,6 +459,7 @@
dc01ed7
     }
dc01ed7
 
dc01ed7
     dict->dictSet(key, &array);
dc01ed7
+#endif
dc01ed7
 }
dc01ed7
 
dc01ed7
 
dc01ed7
@@ -361,7 +490,11 @@
dc01ed7
     float mediabox[4] = { 0.0, 0.0, width, length };
dc01ed7
     float old_mediabox[4];
dc01ed7
 
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+    pageobj = xref->fetch(pageref->num, pageref->gen);
dc01ed7
+#else
dc01ed7
     xref->fetch(pageref->num, pageref->gen, &pageobj);
dc01ed7
+#endif
dc01ed7
     if (!pageobj.isDict()) {
dc01ed7
         fprintf(stderr, "Error: malformed pdf\n");
dc01ed7
         return;
dc01ed7
@@ -381,7 +514,9 @@
dc01ed7
     dict_set_rect (xref, &pageobj, "BleedBox", mediabox);
dc01ed7
 
dc01ed7
     xref->setModifiedObject(&pageobj, *pageref);
dc01ed7
+#if POPPLER_VERSION_MAJOR <= 0 && POPPLER_VERSION_MINOR < 58
dc01ed7
     pageobj.free();
dc01ed7
+#endif
dc01ed7
 }
dc01ed7
 
dc01ed7
 
dc01ed7
@@ -394,21 +529,34 @@
dc01ed7
     Object page, parentref, parent, kids, ref, countobj;
dc01ed7
     int i;
dc01ed7
 
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+    page = xref->fetch(pageref->num, pageref->gen);
dc01ed7
+#else
dc01ed7
     xref->fetch(pageref->num, pageref->gen, &page);
dc01ed7
+#endif
dc01ed7
     if (!page.isDict("Page")) {
dc01ed7
         fprintf(stderr, "Error: malformed pdf (invalid Page object)\n");
dc01ed7
         return;
dc01ed7
     }
dc01ed7
 
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+    parentref = page.dictLookupNF("Parent");
dc01ed7
+    parent = parentref.fetch(xref);
dc01ed7
+#else
dc01ed7
     page.dictLookupNF("Parent", &parentref);
dc01ed7
     parentref.fetch(xref, &parent);
dc01ed7
+#endif
dc01ed7
     if (!parent.isDict("Pages")) {
dc01ed7
         fprintf(stderr, "Error: malformed pdf (Page.Parent must point to a "
dc01ed7
                         "Pages object)\n");
dc01ed7
         return;
dc01ed7
     }
dc01ed7
 
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+    kids = parent.dictLookup("Kids");
dc01ed7
+#else
dc01ed7
     parent.dictLookup("Kids", &kids);
dc01ed7
+#endif
dc01ed7
     if (!kids.isArray()) {
dc01ed7
         fprintf(stderr, "Error: malformed pdf (Pages.Kids must be an array)\n");
dc01ed7
         return;
dc01ed7
@@ -420,14 +568,22 @@
dc01ed7
     // the pages tree (not supported by major pdf implementations).
dc01ed7
     for (i = 1; i < count; i++) {
dc01ed7
         Ref r = xref->addIndirectObject(&page);
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+        kids.arrayAdd(Object(r.num, r.gen));
dc01ed7
+#else
dc01ed7
         ref.initRef(r.num, r.gen);
dc01ed7
         kids.arrayAdd(&ref;;
dc01ed7
         ref.free();
dc01ed7
+#endif
dc01ed7
     }
dc01ed7
 
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+    parent.dictSet("Count", Object(count));
dc01ed7
+#else
dc01ed7
     countobj.initInt(count);
dc01ed7
     parent.dictSet("Count", &countobj);
dc01ed7
     countobj.free();
dc01ed7
+#endif
dc01ed7
 
dc01ed7
     xref->setModifiedObject(&parent, parentref.getRef());
dc01ed7
 }
dc01ed7
@@ -523,7 +679,11 @@
dc01ed7
     }
dc01ed7
     Object pageobj;
dc01ed7
     Ref pageref = page->getRef();
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+    pageobj = xref->fetch(pageref.num, pageref.gen);
dc01ed7
+#else
dc01ed7
     xref->fetch(pageref.num, pageref.gen, &pageobj);
dc01ed7
+#endif
dc01ed7
 
dc01ed7
     const char *font_size = lookup_opt(opt, "banner-font-size");
dc01ed7
     if ( ! font_size ) {
dc01ed7
@@ -614,8 +774,12 @@
dc01ed7
 
dc01ed7
         /* Modify field's appearance */
dc01ed7
         Object appearance_obj;
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+        field_obj->getDict()->set("DA", Object(appearance));
dc01ed7
+#else
dc01ed7
         appearance_obj.initString(appearance);
dc01ed7
         field_obj->getDict()->set("DA", &appearance_obj);
dc01ed7
+#endif
dc01ed7
 
dc01ed7
         /*
dc01ed7
          * Create /AP - entry stuff.
dc01ed7
@@ -653,7 +817,11 @@
dc01ed7
         appearance_stream->append("EMC\n");
dc01ed7
 
dc01ed7
         Object appearance_stream_dic;
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+        appearance_stream_dic = Object(new Dict(xref));
dc01ed7
+#else
dc01ed7
         appearance_stream_dic.initDict(xref);
dc01ed7
+#endif
dc01ed7
 
dc01ed7
         /*
dc01ed7
          * Appearance stream dic.
dc01ed7
@@ -663,12 +831,46 @@
dc01ed7
         appearance_stream_dic.dictSet("Type", name_object("XObject"));
dc01ed7
         appearance_stream_dic.dictSet("Subtype", name_object("Form"));
dc01ed7
         appearance_stream_dic.dictSet("FormType", int_object(1));
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+        appearance_stream_dic.dictSet("Resources", Object(resref.num, resref.gen));
dc01ed7
+#else
dc01ed7
         Object obj_ref_x;
dc01ed7
         obj_ref_x.initRef(resref.num, resref.gen);
dc01ed7
         appearance_stream_dic.dictSet("Resources", &obj_ref_x);
dc01ed7
+#endif
dc01ed7
 
dc01ed7
         /* BBox array: TODO. currently out of the head. */
dc01ed7
         Object array;
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+        array = Object(new Array(xref));
dc01ed7
+        array.arrayAdd(Object(0.0));
dc01ed7
+        array.arrayAdd(Object(0.0));
dc01ed7
+        array.arrayAdd(Object(237.0));
dc01ed7
+        array.arrayAdd(Object(25.0));
dc01ed7
+
dc01ed7
+        appearance_stream_dic.dictSet("BBox", std::move(array));
dc01ed7
+        appearance_stream_dic.dictSet("Length", Object(appearance_stream->getLength()));
dc01ed7
+
dc01ed7
+        MemStream *mem_stream = new MemStream(appearance_stream->getCString(),
dc01ed7
+                0, appearance_stream->getLength(), std::move(appearance_stream_dic));
dc01ed7
+
dc01ed7
+        /* Make obj stream */
dc01ed7
+        Object stream = Object(static_cast<Stream *>(mem_stream));
dc01ed7
+
dc01ed7
+        Ref r = xref->addIndirectObject(&stream);
dc01ed7
+
dc01ed7
+        /* Update Xref table */
dc01ed7
+        Object obj_ref = Object(r.num, r.gen);
dc01ed7
+
dc01ed7
+        /*
dc01ed7
+         * Fill Annotation's appearance streams dic /AP
dc01ed7
+         * See: 8.4.4 Appearance Streams
dc01ed7
+         */
dc01ed7
+        Object appearance_streams_dic = Object(new Dict(xref));
dc01ed7
+        appearance_streams_dic.dictSet("N", std::move(obj_ref));
dc01ed7
+
dc01ed7
+        field_obj->getDict()->set("AP", std::move(appearance_streams_dic));
dc01ed7
+#else
dc01ed7
         array.initArray(xref);
dc01ed7
         Object el;
dc01ed7
         el.initReal(0);
dc01ed7
@@ -705,6 +907,7 @@
dc01ed7
         appearance_streams_dic.dictSet("N", &obj_ref);
dc01ed7
 
dc01ed7
         field_obj->getDict()->set("AP", &appearance_streams_dic);
dc01ed7
+#endif
dc01ed7
 
dc01ed7
         /* Notify poppler about changes */
dc01ed7
         xref->setModifiedObject(field_obj, field_ref);
dc01ed7
@@ -721,24 +924,38 @@
dc01ed7
      * OpenOffice - by default sets it to 'true'.
dc01ed7
      */
dc01ed7
     Object *obj_form = catalog->getAcroForm();
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+    obj_form->dictSet("NeedAppearances", Object(gFalse));
dc01ed7
+#else
dc01ed7
     Object obj1;
dc01ed7
     obj1.initBool(gFalse);
dc01ed7
     obj_form->dictSet("NeedAppearances", &obj1);
dc01ed7
+#endif
dc01ed7
+
dc01ed7
     /* Add AccroForm as indirect obj */
dc01ed7
     Ref ref_form = xref->addIndirectObject(obj_form);
dc01ed7
 
dc01ed7
     /*
dc01ed7
      * So update Catalog object.
dc01ed7
      */
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+    Object catObj = xref->getCatalog();
dc01ed7
+#else
dc01ed7
     Object* catObj = new Object();
dc01ed7
     catObj = xref->getCatalog(catObj);
dc01ed7
+#endif
dc01ed7
     Ref catRef;
dc01ed7
     catRef.gen = xref->getRootGen();
dc01ed7
     catRef.num = xref->getRootNum();
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+    catObj.dictSet("AcroForm", Object(ref_form.num, ref_form.gen));
dc01ed7
+    xref->setModifiedObject(&catObj, catRef);
dc01ed7
+#else
dc01ed7
     Object obj2;
dc01ed7
     obj2.initRef(ref_form.num, ref_form.gen);
dc01ed7
     catObj->dictSet("AcroForm", &obj2);
dc01ed7
     xref->setModifiedObject(catObj, catRef);
dc01ed7
+#endif
dc01ed7
 
dc01ed7
     /* Success */
dc01ed7
     return 1;
dc01ed7
@@ -780,7 +997,11 @@
dc01ed7
 
dc01ed7
     /* Font dictionary object for embeded font */
dc01ed7
     Object f_dic;
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+    f_dic = Object(new Dict(xref));
dc01ed7
+#else
dc01ed7
     f_dic.initDict(xref);
dc01ed7
+#endif
dc01ed7
     f_dic.dictSet("Type", name_object("Font"));
dc01ed7
 
dc01ed7
     /* Stream lenght */
dc01ed7
@@ -798,12 +1019,18 @@
dc01ed7
     }
dc01ed7
 
dc01ed7
     /* Create memory stream font. Add it to font dic. */
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+    MemStream *mem_stream = new MemStream(font_stream->getCString(),
dc01ed7
+            0, outlen, std::move(f_dic));
dc01ed7
+    Object stream = Object(static_cast<Stream *>(mem_stream));
dc01ed7
+#else
dc01ed7
     MemStream *mem_stream = new MemStream(font_stream->getCString(),
dc01ed7
             0, outlen, &f_dic);
dc01ed7
 
dc01ed7
     /* Make obj stream */
dc01ed7
     Object stream;
dc01ed7
     stream.initStream(mem_stream);
dc01ed7
+#endif
dc01ed7
 
dc01ed7
     Ref r;
dc01ed7
 
dc01ed7
@@ -813,7 +1040,11 @@
dc01ed7
     /* Get page object */
dc01ed7
     Object pageobj;
dc01ed7
     Ref pageref = page->getRef();
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+    pageobj = xref->fetch(pageref.num, pageref.gen);
dc01ed7
+#else
dc01ed7
     xref->fetch(pageref.num, pageref.gen, &pageobj);
dc01ed7
+#endif
dc01ed7
     if (!pageobj.isDict()) {
dc01ed7
         fprintf(stderr, "Error: malformed pdf.\n");
dc01ed7
         return 0;
dc01ed7
@@ -825,18 +1056,29 @@
dc01ed7
     Object *ret = get_resource_dict(xref, pageobj.getDict(), &resdict, &resref);
dc01ed7
     if ( !ret ) {
dc01ed7
         fprintf(stderr, "Error: malformed pdf\n");
dc01ed7
+#if POPPLER_VERSION_MAJOR <= 0 && POPPLER_VERSION_MINOR < 58
dc01ed7
         pageobj.free();
dc01ed7
+#endif
dc01ed7
         return 0;
dc01ed7
     }
dc01ed7
 
dc01ed7
     /* Dictionary for all fonts in page's resources */
dc01ed7
     Object fonts;
dc01ed7
 
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+    fonts = resdict.dictLookupNF("Font");
dc01ed7
+#else
dc01ed7
     resdict.dictLookupNF("Font", &fonts);
dc01ed7
+#endif
dc01ed7
     if (fonts.isNull()) {
dc01ed7
         /* Create new one, if doesn't exists */
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+        resdict.dictSet("Font", Object(new Dict(xref)));
dc01ed7
+        fonts = resdict.dictLookupNF("Font");
dc01ed7
+#else
dc01ed7
         fonts.initDict(xref);
dc01ed7
         resdict.dictSet("Font", &fonts);
dc01ed7
+#endif
dc01ed7
         fprintf(stderr, "Create new font dict in page's resources.\n");
dc01ed7
     }
dc01ed7
 
dc01ed7
@@ -866,7 +1108,11 @@
dc01ed7
 
dc01ed7
     /* r - cid resource dic */
dc01ed7
     Object font_res_obj_ref;
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+    font_res_obj_ref = Object(r.num, r.gen);
dc01ed7
+#else
dc01ed7
     font_res_obj_ref.initRef(r.num, r.gen);
dc01ed7
+#endif
dc01ed7
 
dc01ed7
     Object *fonts_dic;
dc01ed7
     Object dereferenced_obj;
dc01ed7
@@ -876,7 +1122,11 @@
dc01ed7
         fonts_dic = &fonts;
dc01ed7
     } else if ( fonts.isRef() ) {
dc01ed7
         /* "Font" resource is indirect reference object */
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+        dereferenced_obj = xref->fetch(fonts.getRefNum(), fonts.getRefGen());
dc01ed7
+#else
dc01ed7
         xref->fetch(fonts.getRefNum(), fonts.getRefGen(), &dereferenced_obj);
dc01ed7
+#endif
dc01ed7
         fonts_dic = &dereferenced_obj;
dc01ed7
     }
dc01ed7
 
dc01ed7
@@ -886,7 +1136,11 @@
dc01ed7
     }
dc01ed7
 
dc01ed7
     /* Add to fonts dic new font */
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+    fonts_dic->dictSet("stanv_font", std::move(font_res_obj_ref));
dc01ed7
+#else
dc01ed7
     fonts_dic->dictSet("stanv_font", &font_res_obj_ref);
dc01ed7
+#endif
dc01ed7
 
dc01ed7
     /* Notify poppler about changes in fonts dic */
dc01ed7
     if ( fonts.isRef() ) {
dc01ed7
@@ -897,7 +1151,9 @@
dc01ed7
     xref->setModifiedObject(&resdict, resref);
dc01ed7
     fprintf(stderr, "Resource dict was changed.\n");
dc01ed7
 
dc01ed7
+#if POPPLER_VERSION_MAJOR <= 0 && POPPLER_VERSION_MINOR < 58
dc01ed7
     pageobj.free();
dc01ed7
+#endif
dc01ed7
 
dc01ed7
     /* Success */
dc01ed7
     return 1;
dc01ed7
@@ -1104,8 +1360,12 @@
dc01ed7
     XRef *xref = doc->getXRef();
dc01ed7
 
dc01ed7
     /* Font dictionary for embeded font */
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+    Object *dic = new Object(new Dict(xref));
dc01ed7
+#else
dc01ed7
     Object *dic = new Object();
dc01ed7
     dic->initDict(xref);
dc01ed7
+#endif
dc01ed7
 
dc01ed7
     dic->dictSet("Type", name_object("FontDescriptor"));
dc01ed7
     dic->dictSet(
dc01ed7
@@ -1119,6 +1379,15 @@
dc01ed7
     dic->dictSet("StemV", int_object(fdes->stemV));
dc01ed7
 
dc01ed7
     /* FontBox array */
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+    Object array = Object(new Array(xref));
dc01ed7
+    array.arrayAdd(Object(static_cast<double>(fdes->bbxmin)));
dc01ed7
+    array.arrayAdd(Object(static_cast<double>(fdes->bbymin)));
dc01ed7
+    array.arrayAdd(Object(static_cast<double>(fdes->bbxmax)));
dc01ed7
+    array.arrayAdd(Object(static_cast<double>(fdes->bbymax)));
dc01ed7
+
dc01ed7
+    dic->dictSet("FontBBox", std::move(array));
dc01ed7
+#else
dc01ed7
     Object array;
dc01ed7
     array.initArray(xref);
dc01ed7
 
dc01ed7
@@ -1137,6 +1406,7 @@
dc01ed7
     array.arrayAdd(&el);
dc01ed7
 
dc01ed7
     dic->dictSet("FontBBox", &array);
dc01ed7
+#endif
dc01ed7
 
dc01ed7
     if (fdes->xHeight) {
dc01ed7
         dic->dictSet("XHeight", int_object(fdes->xHeight));
dc01ed7
@@ -1149,20 +1419,34 @@
dc01ed7
     if (fdes->panose) {
dc01ed7
         /* Font dictionary for embeded font */
dc01ed7
         Object style_dic;
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+        style_dic = Object(new Dict(xref));
dc01ed7
+#else
dc01ed7
         style_dic.initDict(xref);
dc01ed7
-
dc01ed7
+#endif
dc01ed7
+
dc01ed7
+        GooString *panose_str = new GooString(fdes->panose, 12);
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+        style_dic.dictSet("Panose", Object(panose_str));
dc01ed7
+
dc01ed7
+        dic->dictSet("Style", std::move(style_dic));
dc01ed7
+#else
dc01ed7
         Object panose;
dc01ed7
 
dc01ed7
-        GooString *panose_str = new GooString(fdes->panose, 12);
dc01ed7
         panose.initString(panose_str);
dc01ed7
         style_dic.dictSet("Panose", &panose);
dc01ed7
 
dc01ed7
         dic->dictSet("Style", &style_dic);
dc01ed7
+#endif
dc01ed7
     }
dc01ed7
 
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+    dic->dictSet(emb_pdf_get_fontfile_key(emb), Object(fontfile_obj_ref.num, fontfile_obj_ref.gen));
dc01ed7
+#else
dc01ed7
     Object ref_obj;
dc01ed7
     ref_obj.initRef(fontfile_obj_ref.num, fontfile_obj_ref.gen);
dc01ed7
     dic->dictSet(emb_pdf_get_fontfile_key(emb), &ref_obj);
dc01ed7
+#endif
dc01ed7
 
dc01ed7
     return dic;
dc01ed7
 }
dc01ed7
@@ -1181,8 +1465,12 @@
dc01ed7
     /* Get XREF table */
dc01ed7
     XRef *xref = doc->getXRef();
dc01ed7
 
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+    Object *dic = new Object(new Dict(xref));
dc01ed7
+#else
dc01ed7
     Object *dic = new Object();
dc01ed7
     dic->initDict(xref);
dc01ed7
+#endif
dc01ed7
 
dc01ed7
     dic->dictSet("Type", name_object("Font"));
dc01ed7
     dic->dictSet(
dc01ed7
@@ -1192,15 +1480,23 @@
dc01ed7
             "BaseFont",
dc01ed7
             name_object(copyString(emb_pdf_escape_name(fdes->fontname,-1))));
dc01ed7
 
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+    dic->dictSet("FontDescriptor", Object(fontdescriptor_obj_ref.num, fontdescriptor_obj_ref.gen));
dc01ed7
+#else
dc01ed7
     Object ref_obj;
dc01ed7
     ref_obj.initRef(fontdescriptor_obj_ref.num, fontdescriptor_obj_ref.gen);
dc01ed7
     dic->dictSet("FontDescriptor", &ref_obj);
dc01ed7
+#endif
dc01ed7
 
dc01ed7
     if ( emb->plan & EMB_A_MULTIBYTE ) {
dc01ed7
         assert(fwid->warray);
dc01ed7
 
dc01ed7
         Object CIDSystemInfo_dic;
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+        CIDSystemInfo_dic = Object(new Dict(xref));
dc01ed7
+#else
dc01ed7
         CIDSystemInfo_dic.initDict(xref);
dc01ed7
+#endif
dc01ed7
 
dc01ed7
         Object registry;
dc01ed7
         Object ordering;
dc01ed7
@@ -1208,16 +1504,28 @@
dc01ed7
         GooString *str;
dc01ed7
 
dc01ed7
         str = new GooString(copyString(fdes->registry));
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+        CIDSystemInfo_dic.dictSet("Registry", Object(str));
dc01ed7
+#else
dc01ed7
         registry.initString(str);
dc01ed7
         CIDSystemInfo_dic.dictSet("Registry", &registry);
dc01ed7
+#endif
dc01ed7
 
dc01ed7
         str = new GooString(copyString(fdes->ordering));
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+        CIDSystemInfo_dic.dictSet("Ordering", Object(str));
dc01ed7
+#else
dc01ed7
         ordering.initString(str);
dc01ed7
         CIDSystemInfo_dic.dictSet("Ordering", &ordering);
dc01ed7
+#endif
dc01ed7
 
dc01ed7
         CIDSystemInfo_dic.dictSet("Supplement", int_object(fdes->supplement));
dc01ed7
 
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+        dic->dictSet("CIDSystemInfo", std::move(CIDSystemInfo_dic));
dc01ed7
+#else
dc01ed7
         dic->dictSet("CIDSystemInfo", &CIDSystemInfo_dic);
dc01ed7
+#endif
dc01ed7
 
dc01ed7
         dic->dictSet("DW", int_object(fwid->default_width));
dc01ed7
     }
dc01ed7
@@ -1249,8 +1557,12 @@
dc01ed7
     /* Get XREF table */
dc01ed7
     XRef *xref = doc->getXRef();
dc01ed7
 
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+    Object *dic = new Object(new Dict(xref));
dc01ed7
+#else
dc01ed7
     Object *dic = new Object();
dc01ed7
     dic->initDict(xref);
dc01ed7
+#endif
dc01ed7
 
dc01ed7
     dic->dictSet("Type", name_object("Font"));
dc01ed7
     dic->dictSet("Subtype", name_object("Type0"));
dc01ed7
@@ -1267,13 +1579,24 @@
dc01ed7
     dic->dictSet("Encoding", name_object(copyString(encoding)));
dc01ed7
 
dc01ed7
     Object obj;
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+    obj = Object(fontdescriptor_obj_ref.num, fontdescriptor_obj_ref.gen);
dc01ed7
+#else
dc01ed7
     obj.initRef(fontdescriptor_obj_ref.num, fontdescriptor_obj_ref.gen);
dc01ed7
+#endif
dc01ed7
 
dc01ed7
     Object array;
dc01ed7
+#if POPPLER_VERSION_MAJOR > 0 || POPPLER_VERSION_MINOR >= 58
dc01ed7
+    array = Object(new Array(xref));
dc01ed7
+    array.arrayAdd(std::move(obj));
dc01ed7
+
dc01ed7
+    dic->dictSet("DescendantFonts", std::move(array));
dc01ed7
+#else
dc01ed7
     array.initArray(xref);
dc01ed7
     array.arrayAdd(&obj);
dc01ed7
 
dc01ed7
     dic->dictSet("DescendantFonts", &array);
dc01ed7
+#endif
dc01ed7
 
dc01ed7
     return dic;
dc01ed7
 }
dc01ed7