This commit is contained in:
simon987 2020-08-16 14:09:50 -04:00
parent 0e4906bc40
commit baf39a8b1a
3 changed files with 15 additions and 1 deletions

View File

@ -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); 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}; 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, sws_scale(sws_ctx,
in_data, in_line_size, 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; return;
} }
APPEND_INT_META(doc, MetaPages, page_count)
if (ctx->tn_size > 0) { if (ctx->tn_size > 0) {
if (render_cover(ctx, fzctx, doc, fzdoc) == FALSE) { if (render_cover(ctx, fzctx, doc, fzdoc) == FALSE) {
fz_drop_stream(fzctx, stream); fz_drop_stream(fzctx, stream);

View File

@ -80,6 +80,7 @@ enum metakey {
MetaAuthor = META_STR(24), MetaAuthor = META_STR(24),
MetaModifiedBy = META_STR(25), MetaModifiedBy = META_STR(25),
MetaThumbnail = META_STR(26), MetaThumbnail = META_STR(26),
MetaPages = META_INT(27),
}; };
typedef struct meta_line { typedef struct meta_line {

View File

@ -185,6 +185,7 @@ TEST(Ebook, CandlePdf) {
ASSERT_NEAR(strlen(get_meta(&doc, MetaContent)->str_val), 500, 4); ASSERT_NEAR(strlen(get_meta(&doc, MetaContent)->str_val), 500, 4);
ASSERT_NE(get_meta(&doc, MetaContent)->str_val[0], ' '); ASSERT_NE(get_meta(&doc, MetaContent)->str_val[0], ' ');
ASSERT_NE(size_before, store_size); ASSERT_NE(size_before, store_size);
ASSERT_EQ(get_meta(&doc, MetaPages)->int_val, 16);
cleanup(&doc, &f); cleanup(&doc, &f);
} }
@ -200,6 +201,16 @@ TEST(Ebook, Utf8Pdf) {
cleanup(&doc, &f); 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) { TEST(Ebook, Epub1) {
vfile_t f; vfile_t f;
document_t doc; document_t doc;