Skip to content

Commit

Permalink
Report in --version if PDF rendering does not provide --auto-crop
Browse files Browse the repository at this point in the history
  • Loading branch information
hzeller committed Jan 25, 2024
1 parent 1e86275 commit 661ee21
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
12 changes: 8 additions & 4 deletions src/pdf-image-source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion src/timg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 661ee21

Please sign in to comment.