From 661ee21ca52f3da3fe4ba14edecb4677146d3d5f Mon Sep 17 00:00:00 2001 From: Henner Zeller Date: Wed, 24 Jan 2024 16:46:09 -0800 Subject: [PATCH] Report in --version if PDF rendering does not provide --auto-crop --- src/pdf-image-source.cc | 12 ++++++++---- src/timg.cc | 7 ++++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/pdf-image-source.cc b/src/pdf-image-source.cc index 5a59d57..b7528a8 100644 --- a/src/pdf-image-source.cc +++ b/src/pdf-image-source.cc @@ -60,16 +60,21 @@ bool PDFImageSource::LoadAndScale(const DisplayOptions &opts, int frame_offset, success = false; break; } - poppler_page_get_size(page, &orig_width_, &orig_height_); - bounding_box = PopplerRectangle{ - .x1 = 0, .y1 = 0, .x2 = orig_width_, .y2 = orig_height_}; + #if POPPLER_CHECK_VERSION(0, 88, 0) if (opts.auto_crop) { poppler_page_get_bounding_box(page, &bounding_box); orig_width_ = bounding_box.x2 - bounding_box.x1; orig_height_ = bounding_box.y2 - bounding_box.y1; } + else #endif + { + poppler_page_get_size(page, &orig_width_, &orig_height_); + bounding_box = PopplerRectangle{ + .x1 = 0, .y1 = 0, .x2 = orig_width_, .y2 = orig_height_}; + } + int target_width; int target_height; CalcScaleToFitDisplay(orig_width_, orig_height_, opts, false, @@ -110,7 +115,6 @@ bool PDFImageSource::LoadAndScale(const DisplayOptions &opts, int frame_offset, std::swap(pixel.r, pixel.b); } - // TODO: implement auto-crop and crop-border pages_.emplace_back(std::move(image)); } g_object_unref(document); diff --git a/src/timg.cc b/src/timg.cc index 20b9036..57c367b 100644 --- a/src/timg.cc +++ b/src/timg.cc @@ -450,9 +450,14 @@ static int PrintVersion(FILE *stream) { CAIRO_VERSION_MAJOR, CAIRO_VERSION_MINOR, CAIRO_VERSION_MICRO); #endif #ifdef WITH_TIMG_POPPLER - fprintf(stream, "PDF rendering with poppler %s + cairo %d.%d.%d\n", + fprintf(stream, "PDF rendering with poppler %s + cairo %d.%d.%d", poppler_get_version(), CAIRO_VERSION_MAJOR, CAIRO_VERSION_MINOR, CAIRO_VERSION_MICRO); +# if not POPPLER_CHECK_VERSION(0, 88, 0) + // Too old versions of poppler don't have a bounding-box function + fprintf(stream, " (no --auto-crop)"); +# endif + fprintf(stream, "\n"); #endif #ifdef WITH_TIMG_QOI fprintf(stream, "QOI image loading\n");