diff options
-rw-r--r-- | include/mupdf/fitz/context.h | 12 | ||||
-rw-r--r-- | platform/x11/pdfapp.c | 8 | ||||
-rw-r--r-- | platform/x11/pdfapp.h | 1 | ||||
-rw-r--r-- | platform/x11/x11_main.c | 3 | ||||
-rw-r--r-- | source/fitz/context.c | 50 | ||||
-rw-r--r-- | source/html/epub-doc.c | 2 | ||||
-rw-r--r-- | source/html/html-doc.c | 4 | ||||
-rw-r--r-- | source/html/html-layout.c | 4 | ||||
-rw-r--r-- | source/tools/mudraw.c | 13 |
9 files changed, 90 insertions, 7 deletions
diff --git a/include/mupdf/fitz/context.h b/include/mupdf/fitz/context.h index 10e28e0c..02bd6eaa 100644 --- a/include/mupdf/fitz/context.h +++ b/include/mupdf/fitz/context.h @@ -15,6 +15,7 @@ typedef struct fz_warn_context_s fz_warn_context; typedef struct fz_font_context_s fz_font_context; typedef struct fz_colorspace_context_s fz_colorspace_context; typedef struct fz_aa_context_s fz_aa_context; +typedef struct fz_style_context_s fz_style_context; typedef struct fz_locks_context_s fz_locks_context; typedef struct fz_store_s fz_store; typedef struct fz_glyph_cache_s fz_glyph_cache; @@ -108,6 +109,7 @@ struct fz_context_s fz_font_context *font; fz_colorspace_context *colorspace; fz_aa_context *aa; + fz_style_context *style; fz_store *store; fz_glyph_cache *glyph_cache; fz_document_handler_context *handler; @@ -202,6 +204,16 @@ int fz_aa_level(fz_context *ctx); void fz_set_aa_level(fz_context *ctx, int bits); /* + fz_user_css: Get the user stylesheet source text. +*/ +const char *fz_user_css(fz_context *ctx); + +/* + fz_set_user_css: Set the user stylesheet source text for use with HTML and EPUB. +*/ +void fz_set_user_css(fz_context *ctx, const char *text); + +/* Locking functions MuPDF is kept deliberately free of any knowledge of particular diff --git a/platform/x11/pdfapp.c b/platform/x11/pdfapp.c index 3d727ed1..1fb2f2d4 100644 --- a/platform/x11/pdfapp.c +++ b/platform/x11/pdfapp.c @@ -302,6 +302,14 @@ void pdfapp_open_progressive(pdfapp_t *app, char *filename, int reload, int bps) { fz_register_document_handlers(ctx); + if (app->layout_css) + { + fz_buffer *buf = fz_read_file(ctx, app->layout_css); + fz_write_buffer_byte(ctx, buf, 0); + fz_set_user_css(ctx, (char*)buf->data); + fz_drop_buffer(ctx, buf); + } + #ifdef HAVE_CURL if (!strncmp(filename, "http://", 7)) { diff --git a/platform/x11/pdfapp.h b/platform/x11/pdfapp.h index 46f09640..1bac5872 100644 --- a/platform/x11/pdfapp.h +++ b/platform/x11/pdfapp.h @@ -57,6 +57,7 @@ struct pdfapp_s float layout_w; float layout_h; float layout_em; + char *layout_css; int pagecount; diff --git a/platform/x11/x11_main.c b/platform/x11/x11_main.c index 80c86a23..9fe3b955 100644 --- a/platform/x11/x11_main.c +++ b/platform/x11/x11_main.c @@ -835,7 +835,7 @@ int main(int argc, char **argv) pdfapp_init(ctx, &gapp); - while ((c = fz_getopt(argc, argv, "p:r:A:C:W:H:S:")) != -1) + while ((c = fz_getopt(argc, argv, "p:r:A:C:W:H:S:U:")) != -1) { switch (c) { @@ -852,6 +852,7 @@ int main(int argc, char **argv) case 'W': gapp.layout_w = fz_atof(fz_optarg); break; case 'H': gapp.layout_h = fz_atof(fz_optarg); break; case 'S': gapp.layout_em = fz_atof(fz_optarg); break; + case 'U': gapp.layout_css = fz_optarg; break; default: usage(); } } diff --git a/source/fitz/context.c b/source/fitz/context.c index 7a2076b7..f6edcee7 100644 --- a/source/fitz/context.c +++ b/source/fitz/context.c @@ -31,6 +31,52 @@ fz_keep_id_context(fz_context *ctx) return fz_keep_imp(ctx, ctx->id, &ctx->id->refs); } +struct fz_style_context_s +{ + int refs; + char *user_css; +}; + +static void fz_new_style_context(fz_context *ctx) +{ + if (ctx) + { + ctx->style = fz_malloc_struct(ctx, fz_style_context); + ctx->style->user_css = NULL; + } +} + +static fz_style_context *fz_keep_style_context(fz_context *ctx) +{ + if (!ctx) + return NULL; + return fz_keep_imp(ctx, ctx->style, &ctx->style->refs); +} + +static void fz_drop_style_context(fz_context *ctx) +{ + if (!ctx) + return; + if (fz_drop_imp(ctx, ctx->style, &ctx->style->refs)) + { + fz_free(ctx, ctx->style->user_css); + fz_free(ctx, ctx->style); + } +} + +void fz_set_user_css(fz_context *ctx, const char *user_css) +{ + fz_lock(ctx, FZ_LOCK_ALLOC); + fz_free(ctx, ctx->style->user_css); + ctx->style->user_css = fz_strdup(ctx, user_css); + fz_unlock(ctx, FZ_LOCK_ALLOC); +} + +const char *fz_user_css(fz_context *ctx) +{ + return ctx->style->user_css; +} + void fz_drop_context(fz_context *ctx) { @@ -42,6 +88,7 @@ fz_drop_context(fz_context *ctx) fz_drop_glyph_cache_context(ctx); fz_drop_store_context(ctx); fz_drop_aa_context(ctx); + fz_drop_style_context(ctx); fz_drop_colorspace_context(ctx); fz_drop_font_context(ctx); fz_drop_id_context(ctx); @@ -96,6 +143,7 @@ new_context_phase1(fz_alloc_context *alloc, fz_locks_context *locks) fz_try(ctx) { fz_new_aa_context(ctx); + fz_new_style_context(ctx); } fz_catch(ctx) { @@ -184,6 +232,8 @@ fz_clone_context_internal(fz_context *ctx) new_ctx->colorspace = fz_keep_colorspace_context(new_ctx); new_ctx->font = ctx->font; new_ctx->font = fz_keep_font_context(new_ctx); + new_ctx->style = ctx->style; + new_ctx->style = fz_keep_style_context(new_ctx); new_ctx->id = ctx->id; new_ctx->id = fz_keep_id_context(new_ctx); new_ctx->handler = ctx->handler; diff --git a/source/html/epub-doc.c b/source/html/epub-doc.c index 712d5804..a2871889 100644 --- a/source/html/epub-doc.c +++ b/source/html/epub-doc.c @@ -195,7 +195,7 @@ epub_parse_chapter(fz_context *ctx, epub_document *doc, const char *path) fz_write_buffer_byte(ctx, buf, 0); ch = fz_malloc_struct(ctx, epub_chapter); - ch->box = fz_parse_html(ctx, doc->set, zip, base_uri, buf, NULL); + ch->box = fz_parse_html(ctx, doc->set, zip, base_uri, buf, fz_user_css(ctx)); ch->next = NULL; fz_drop_buffer(ctx, buf); diff --git a/source/html/html-doc.c b/source/html/html-doc.c index 04286f7c..366a7378 100644 --- a/source/html/html-doc.c +++ b/source/html/html-doc.c @@ -120,7 +120,7 @@ htdoc_open_document_with_stream(fz_context *ctx, fz_stream *file) buf = fz_read_all(ctx, file, 0); fz_write_buffer_byte(ctx, buf, 0); - doc->box = fz_parse_html(ctx, doc->set, doc->zip, ".", buf, NULL); + doc->box = fz_parse_html(ctx, doc->set, doc->zip, ".", buf, fz_user_css(ctx)); fz_drop_buffer(ctx, buf); return (fz_document*)doc; @@ -146,7 +146,7 @@ htdoc_open_document(fz_context *ctx, const char *filename) buf = fz_read_file(ctx, filename); fz_write_buffer_byte(ctx, buf, 0); - doc->box = fz_parse_html(ctx, doc->set, doc->zip, ".", buf, NULL); + doc->box = fz_parse_html(ctx, doc->set, doc->zip, ".", buf, fz_user_css(ctx)); fz_drop_buffer(ctx, buf); return (fz_document*)doc; diff --git a/source/html/html-layout.c b/source/html/html-layout.c index dd48485b..3bb1789c 100644 --- a/source/html/html-layout.c +++ b/source/html/html-layout.c @@ -1241,9 +1241,9 @@ fz_parse_html(fz_context *ctx, fz_html_font_set *set, fz_archive *zip, const cha xml = fz_parse_xml(ctx, buf->data, buf->len, 1); css = fz_parse_css(ctx, NULL, default_css, "<default>"); - if (user_css) - css = fz_parse_css(ctx, NULL, user_css, "<user>"); css = html_load_css(ctx, zip, base_uri, css, xml); + if (user_css) + css = fz_parse_css(ctx, css, user_css, "<user>"); // print_rules(css); diff --git a/source/tools/mudraw.c b/source/tools/mudraw.c index 1d83eed3..882ce660 100644 --- a/source/tools/mudraw.c +++ b/source/tools/mudraw.c @@ -116,6 +116,7 @@ static int fit = 0; static float layout_w = 450; static float layout_h = 600; static float layout_em = 12; +static char *layout_css = NULL; static int showfeatures = 0; static int showtime = 0; @@ -181,6 +182,7 @@ static void usage(void) "\t-W -\tpage width for EPUB layout\n" "\t-H -\tpage height for EPUB layout\n" "\t-S -\tfont size for EPUB layout\n" + "\t-U -\tfile name of user stylesheet for EPUB layout\n" "\n" "\t-c -\tcolorspace (mono, gray, grayalpha, rgb, rgba, cmyk, cmykalpha)\n" "\t-G -\tapply gamma correction\n" @@ -855,7 +857,7 @@ int main(int argc, char **argv) fz_var(doc); - while ((c = fz_getopt(argc, argv, "po:F:R:r:w:h:fB:c:G:I:s:A:DiW:H:S:v")) != -1) + while ((c = fz_getopt(argc, argv, "po:F:R:r:w:h:fB:c:G:I:s:A:DiW:H:S:U:v")) != -1) { switch (c) { @@ -880,6 +882,7 @@ int main(int argc, char **argv) case 'W': layout_w = atof(fz_optarg); break; case 'H': layout_h = atof(fz_optarg); break; case 'S': layout_em = atof(fz_optarg); break; + case 'U': layout_css = fz_optarg; break; case 's': if (strchr(fz_optarg, 't')) ++showtime; @@ -908,6 +911,14 @@ int main(int argc, char **argv) fz_set_aa_level(ctx, alphabits); + if (layout_css) + { + fz_buffer *buf = fz_read_file(ctx, layout_css); + fz_write_buffer_byte(ctx, buf, 0); + fz_set_user_css(ctx, (char*)buf->data); + fz_drop_buffer(ctx, buf); + } + /* Determine output type */ if (bandheight < 0) { |