summaryrefslogtreecommitdiff
path: root/Build/source/texk/web2c/xetexdir/pdfimage.cpp
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2020-04-26 17:49:07 +0000
committerKarl Berry <karl@freefriends.org>2020-04-26 17:49:07 +0000
commitdf977d08809720abcaaca4fd60c90be5da5696e5 (patch)
tree1dd0b1ca94578dc8a71c5262aab677cc4edcceb7 /Build/source/texk/web2c/xetexdir/pdfimage.cpp
parent125c39ffcc5f6dacdbae6a87fd3061af41acf92a (diff)
xetex: use our own pplib instead of poppler
git-svn-id: svn://tug.org/texlive/trunk@54889 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/web2c/xetexdir/pdfimage.cpp')
-rw-r--r--Build/source/texk/web2c/xetexdir/pdfimage.cpp99
1 files changed, 60 insertions, 39 deletions
diff --git a/Build/source/texk/web2c/xetexdir/pdfimage.cpp b/Build/source/texk/web2c/xetexdir/pdfimage.cpp
index 99d916430f3..38d51d1ce61 100644
--- a/Build/source/texk/web2c/xetexdir/pdfimage.cpp
+++ b/Build/source/texk/web2c/xetexdir/pdfimage.cpp
@@ -36,9 +36,13 @@ authorization from the copyright holders.
#include "pdfimage.h"
-#include "PDFDoc.h"
-#include "Catalog.h"
-#include "Page.h"
+/*
+ * From TeX Live 2021, we use pplib by Pawe\l Jackowski instead of
+ * libpoppler
+ */
+extern "C" {
+#include "ppapi.h"
+}
#include "XeTeX_ext.h"
@@ -53,22 +57,14 @@ int
pdf_get_rect(char* filename, int page_num, int pdf_box, realrect* box)
/* return the box converted to TeX points */
{
- GooString* name = new GooString(filename);
- PDFDoc* doc = new PDFDoc(name);
+ ppdoc* doc = ppdoc_load(filename);
if (!doc) {
- delete name;
return -1;
}
- /* if the doc got created, it now owns name, so we mustn't delete it! */
-
- if (!doc->isOk()) {
- delete doc;
- return -1;
- }
+ int pages = ppdoc_page_count(doc);
- int pages = doc->getNumPages();
if (page_num > pages)
page_num = pages;
if (page_num < 0)
@@ -76,43 +72,74 @@ pdf_get_rect(char* filename, int page_num, int pdf_box, realrect* box)
if (page_num < 1)
page_num = 1;
- Page* page = doc->getCatalog()->getPage(page_num);
+ ppref* page = ppdoc_page(doc, page_num);
+ ppdict* pdict = page->object.dict;
+
+ pprect Rect;
+ pprect* r;
- const PDFRectangle* r;
switch (pdf_box) {
default:
case pdfbox_crop:
- r = page->getCropBox();
+ r = ppdict_get_box(pdict, "CropBox", &Rect);
break;
case pdfbox_media:
- r = page->getMediaBox();
+ r = ppdict_get_box(pdict, "MediaBox", &Rect);
break;
case pdfbox_bleed:
- r = page->getBleedBox();
+ r = ppdict_get_box(pdict, "BleedBox", &Rect);
break;
case pdfbox_trim:
- r = page->getTrimBox();
+ r = ppdict_get_box(pdict, "TrimBox", &Rect);
break;
case pdfbox_art:
- r = page->getArtBox();
+ r = ppdict_get_box(pdict, "ArtBox", &Rect);
break;
}
- int RotAngle = 0;
- RotAngle = (int)page->getRotate() % 360;
+/*
+ * In pplib, r can be NULL. If r == NULL, we try "CropBox",
+ * "MediaBox", "BleedBox", "TrimBox", "ArtBox" in this order.
+ */
+ if (!r) {
+ r = ppdict_get_box(pdict, "CropBox", &Rect);
+ }
+ if (!r) {
+ r = ppdict_get_box(pdict, "MediaBox", &Rect);
+ }
+ if (!r) {
+ r = ppdict_get_box(pdict, "BleedBox", &Rect);
+ }
+ if (!r) {
+ r = ppdict_get_box(pdict, "TrimBox", &Rect);
+ }
+ if (!r) {
+ r = ppdict_get_box(pdict, "ArtBox", &Rect);
+ }
+
+/*
+ * If r == NULL, return error.
+ */
+ if (!r) {
+ return -1;
+ }
+
+ ppint RotAngle = 0;
+ (void)ppdict_get_int(pdict, "Rotate", &RotAngle);
+ RotAngle = RotAngle % 360;
if (RotAngle < 0)
RotAngle += 360;
if (RotAngle == 90 || RotAngle == 270) {
- box->wd = 72.27 / 72 * fabs(r->y2 - r->y1);
- box->ht = 72.27 / 72 * fabs(r->x2 - r->x1);
+ box->wd = 72.27 / 72 * fabs(r->ry - r->ly);
+ box->ht = 72.27 / 72 * fabs(r->rx - r->lx);
} else {
- box->wd = 72.27 / 72 * fabs(r->x2 - r->x1);
- box->ht = 72.27 / 72 * fabs(r->y2 - r->y1);
+ box->wd = 72.27 / 72 * fabs(r->rx - r->lx);
+ box->ht = 72.27 / 72 * fabs(r->ry - r->ly);
}
- box->x = 72.27 / 72 * my_fmin(r->x1, r->x2);
- box->y = 72.27 / 72 * my_fmin(r->y1, r->y2);
+ box->x = 72.27 / 72 * my_fmin(r->lx, r->rx);
+ box->y = 72.27 / 72 * my_fmin(r->ly, r->ry);
- delete doc;
+ ppdoc_free(doc);
return 0;
}
@@ -120,21 +147,15 @@ pdf_get_rect(char* filename, int page_num, int pdf_box, realrect* box)
int
pdf_count_pages(char* filename)
{
- int pages = 0;
- GooString* name = new GooString(filename);
- PDFDoc* doc = new PDFDoc(name);
+ int pages = 0;
+ ppdoc* doc = ppdoc_load(filename);
if (!doc) {
- delete name;
return 0;
}
- /* if the doc got created, it now owns name, so we mustn't delete it! */
-
- if (doc->isOk())
- pages = doc->getNumPages();
-
- delete doc;
+ pages = ppdoc_page_count(doc);
+ if (doc) ppdoc_free(doc);
return pages;
}