From baf39a8b1ac7521ecdd79b274980d07c82c329fc Mon Sep 17 00:00:00 2001 From: simon987 Date: Sun, 16 Aug 2020 14:09:50 -0400 Subject: [PATCH] Fix #92 --- libscan/ebook/ebook.c | 4 +++- libscan/scan.h | 1 + test/main.cpp | 11 +++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/libscan/ebook/ebook.c b/libscan/ebook/ebook.c index 9c0f2f0..f77a12c 100644 --- a/libscan/ebook/ebook.c +++ b/libscan/ebook/ebook.c @@ -135,7 +135,7 @@ int render_cover(scan_ebook_ctx_t *ctx, fz_context *fzctx, document_t *doc, fz_d av_image_fill_arrays(scaled_frame->data, scaled_frame->linesize, dst_buf, AV_PIX_FMT_YUV420P, pixmap->w, pixmap->h, 1); const uint8_t *in_data[1] = {pixmap->samples}; - int in_line_size[1] = {3 * pixmap->w}; + int in_line_size[1] = {pixmap->stride}; sws_scale(sws_ctx, in_data, in_line_size, @@ -328,6 +328,8 @@ void parse_ebook_mem(scan_ebook_ctx_t *ctx, void *buf, size_t buf_len, const cha return; } + APPEND_INT_META(doc, MetaPages, page_count) + if (ctx->tn_size > 0) { if (render_cover(ctx, fzctx, doc, fzdoc) == FALSE) { fz_drop_stream(fzctx, stream); diff --git a/libscan/scan.h b/libscan/scan.h index fcf31f6..802ae77 100644 --- a/libscan/scan.h +++ b/libscan/scan.h @@ -80,6 +80,7 @@ enum metakey { MetaAuthor = META_STR(24), MetaModifiedBy = META_STR(25), MetaThumbnail = META_STR(26), + MetaPages = META_INT(27), }; typedef struct meta_line { diff --git a/test/main.cpp b/test/main.cpp index 5607fb2..d7882af 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -185,6 +185,7 @@ TEST(Ebook, CandlePdf) { ASSERT_NEAR(strlen(get_meta(&doc, MetaContent)->str_val), 500, 4); ASSERT_NE(get_meta(&doc, MetaContent)->str_val[0], ' '); ASSERT_NE(size_before, store_size); + ASSERT_EQ(get_meta(&doc, MetaPages)->int_val, 16); cleanup(&doc, &f); } @@ -200,6 +201,16 @@ TEST(Ebook, Utf8Pdf) { cleanup(&doc, &f); } +TEST(Ebook, Pdf2) { + vfile_t f; + document_t doc; + load_doc_file("libscan-test-files/test_files/ebook/pdf2.pdf", &f, &doc); + + parse_ebook(&ebook_500_ctx, &f, "application/pdf", &doc); + + cleanup(&doc, &f); +} + TEST(Ebook, Epub1) { vfile_t f; document_t doc;