diff options
-rw-r--r-- | include/mupdf/pdf/font.h | 2 | ||||
-rw-r--r-- | source/fitz/noto.c | 2 | ||||
-rw-r--r-- | source/pdf/pdf-font.c | 29 | ||||
-rw-r--r-- | source/tools/murun.c | 17 | ||||
-rw-r--r-- | source/tools/pdfcreate.c | 53 |
5 files changed, 66 insertions, 37 deletions
diff --git a/include/mupdf/pdf/font.h b/include/mupdf/pdf/font.h index 323c4ee7..9c1fe066 100644 --- a/include/mupdf/pdf/font.h +++ b/include/mupdf/pdf/font.h @@ -131,7 +131,7 @@ void pdf_run_glyph(fz_context *ctx, pdf_document *doc, pdf_obj *resources, fz_bu pdf_obj *pdf_add_simple_font(fz_context *ctx, pdf_document *doc, fz_font *font, int encoding); pdf_obj *pdf_add_cid_font(fz_context *ctx, pdf_document *doc, fz_font *font); -pdf_obj *pdf_add_cjk_font(fz_context *ctx, pdf_document *doc, fz_font *font, int script); +pdf_obj *pdf_add_cjk_font(fz_context *ctx, pdf_document *doc, fz_font *font, int script, int wmode, int serif); int pdf_font_writing_supported(fz_font *font); diff --git a/source/fitz/noto.c b/source/fitz/noto.c index ee1dadcc..1d039794 100644 --- a/source/fitz/noto.c +++ b/source/fitz/noto.c @@ -188,7 +188,7 @@ fz_lookup_noto_font(fz_context *ctx, int script, int language, int serif, int *s case UCDN_SCRIPT_KATAKANA: return fz_lookup_cjk_font(ctx, FZ_ADOBE_JAPAN_1, serif, 0, size, NULL); case UCDN_SCRIPT_BOPOMOFO: - return fz_lookup_cjk_font(ctx, FZ_ADOBE_GB_1, serif, 0, size, NULL); + return fz_lookup_cjk_font(ctx, FZ_ADOBE_CNS_1, serif, 0, size, NULL); case UCDN_SCRIPT_HAN: switch (language) { diff --git a/source/pdf/pdf-font.c b/source/pdf/pdf-font.c index b00fe18f..3ed8cbb9 100644 --- a/source/pdf/pdf-font.c +++ b/source/pdf/pdf-font.c @@ -2158,27 +2158,28 @@ pdf_font_writing_supported(fz_font *font) /* Add a non-embedded UTF16-encoded CID-font for the CJK scripts: CNS1, GB1, Japan1, or Korea1 */ pdf_obj * -pdf_add_cjk_font(fz_context *ctx, pdf_document *doc, fz_font *fzfont, int script) +pdf_add_cjk_font(fz_context *ctx, pdf_document *doc, fz_font *fzfont, int script, int wmode, int serif) { pdf_obj *fref, *font, *subfont, *fontdesc; pdf_obj *dfonts; fz_rect bbox = { -200, -200, 1200, 1200 }; unsigned char digest[16]; + int flags; const char *basefont, *encoding, *ordering; int supplement; switch (script) { - case FZ_ADOBE_CNS_1: - basefont = "Song"; - encoding = "UniCNS-UTF16-H"; + case FZ_ADOBE_CNS_1: /* traditional chinese */ + basefont = serif ? "Ming" : "Fangti"; + encoding = wmode ? "UniCNS-UTF16-V" : "UniCNS-UTF16-H"; ordering = "CNS1"; supplement = 7; break; - case FZ_ADOBE_GB_1: - basefont = "Ming"; - encoding = "UniGB-UTF16-H"; + case FZ_ADOBE_GB_1: /* simplified chinese */ + basefont = serif ? "Song" : "Heiti"; + encoding = wmode ? "UniGB-UTF16-V" : "UniGB-UTF16-H"; ordering = "GB1"; supplement = 5; break; @@ -2186,19 +2187,23 @@ pdf_add_cjk_font(fz_context *ctx, pdf_document *doc, fz_font *fzfont, int script script = FZ_ADOBE_JAPAN_1; /* fall through */ case FZ_ADOBE_JAPAN_1: - basefont = "Mincho"; - encoding = "UniJIS-UTF16-H"; + basefont = serif ? "Mincho" : "Gothic"; + encoding = wmode ? "UniJIS-UTF16-V" : "UniJIS-UTF16-H"; ordering = "Japan1"; supplement = 6; break; case FZ_ADOBE_KOREA_1: - basefont = "Batang"; - encoding = "UniKS-UTF16-H"; + basefont = serif ? "Batang" : "Dotum"; + encoding = wmode ? "UniKS-UTF16-V" : "UniKS-UTF16-H"; ordering = "Korea1"; supplement = 2; break; } + flags = PDF_FD_SYMBOLIC; + if (serif) + flags |= PDF_FD_SERIF; + fref = pdf_find_font_resource(ctx, doc, PDF_CJK_FONT_RESOURCE, script, fzfont->buffer, digest); if (fref) return fref; @@ -2222,8 +2227,8 @@ pdf_add_cjk_font(fz_context *ctx, pdf_document *doc, fz_font *fzfont, int script { pdf_dict_put(ctx, fontdesc, PDF_NAME(Type), PDF_NAME(FontDescriptor)); pdf_dict_put_text_string(ctx, fontdesc, PDF_NAME(FontName), basefont); - pdf_dict_put_int(ctx, fontdesc, PDF_NAME(Flags), 0); pdf_dict_put_rect(ctx, fontdesc, PDF_NAME(FontBBox), &bbox); + pdf_dict_put_int(ctx, fontdesc, PDF_NAME(Flags), flags); pdf_dict_put_int(ctx, fontdesc, PDF_NAME(ItalicAngle), 0); pdf_dict_put_int(ctx, fontdesc, PDF_NAME(Ascent), 1000); pdf_dict_put_int(ctx, fontdesc, PDF_NAME(Descent), -200); diff --git a/source/tools/murun.c b/source/tools/murun.c index e051be44..d9b5412e 100644 --- a/source/tools/murun.c +++ b/source/tools/murun.c @@ -3264,16 +3264,25 @@ static void ffi_PDFDocument_addCJKFont(js_State *J) pdf_document *pdf = js_touserdata(J, 0, "pdf_document"); fz_font *font = js_touserdata(J, 1, "fz_font"); const char *on = js_tostring(J, 2); + const char *wm = js_tostring(J, 3); + const char *ss = js_tostring(J, 4); int ord = FZ_ADOBE_JAPAN_1; + int wmode = 0; + int serif = 1; pdf_obj *ind = NULL; - if (!strcmp(on, "CNS1") || !strcmp(on, "CN")) ord = FZ_ADOBE_CNS_1; - else if (!strcmp(on, "GB1") || !strcmp(on, "TW")) ord = FZ_ADOBE_GB_1; + if (!strcmp(on, "CNS1") || !strcmp(on, "TW") || !strcmp(on, "TC") || !strcmp(on, "Hant")) ord = FZ_ADOBE_CNS_1; + else if (!strcmp(on, "GB1") || !strcmp(on, "CN") || !strcmp(on, "SC") || !strcmp(on, "Hans")) ord = FZ_ADOBE_GB_1; else if (!strcmp(on, "Korea1") || !strcmp(on, "KR") || !strcmp(on, "KO")) ord = FZ_ADOBE_KOREA_1; else if (!strcmp(on, "Japan1") || !strcmp(on, "JP") || !strcmp(on, "JA")) ord = FZ_ADOBE_JAPAN_1; + if (!strcmp(wm, "V")) + wmode = 1; + if (!strcmp(ss, "sans") || !strcmp(ss, "sans-serif")) + serif = 0; + fz_try(ctx) - ind = pdf_add_cjk_font(ctx, pdf, font, ord); + ind = pdf_add_cjk_font(ctx, pdf, font, ord, wmode, serif); fz_catch(ctx) rethrow(J); @@ -4676,7 +4685,7 @@ int murun_main(int argc, char **argv) jsB_propfun(J, "PDFDocument.addStream", ffi_PDFDocument_addStream, 2); jsB_propfun(J, "PDFDocument.addRawStream", ffi_PDFDocument_addRawStream, 2); jsB_propfun(J, "PDFDocument.addSimpleFont", ffi_PDFDocument_addSimpleFont, 2); - jsB_propfun(J, "PDFDocument.addCJKFont", ffi_PDFDocument_addCJKFont, 2); + jsB_propfun(J, "PDFDocument.addCJKFont", ffi_PDFDocument_addCJKFont, 4); jsB_propfun(J, "PDFDocument.addFont", ffi_PDFDocument_addFont, 1); jsB_propfun(J, "PDFDocument.addImage", ffi_PDFDocument_addImage, 1); jsB_propfun(J, "PDFDocument.addPage", ffi_PDFDocument_addPage, 4); diff --git a/source/tools/pdfcreate.c b/source/tools/pdfcreate.c index 33892b45..f89bc2e4 100644 --- a/source/tools/pdfcreate.c +++ b/source/tools/pdfcreate.c @@ -22,7 +22,7 @@ static void usage(void) "\t%%%%MediaBox LLX LLY URX URY\n" "\t%%%%Rotate Angle\n" "\t%%%%Font Name Filename (or base 14 font name)\n" - "\t%%%%CJKFont Name Ordering (CNS1, GB1, Japan1, or Korea1)\n" + "\t%%%%CJKFont Name Ordering WMode Style (Ordering=CNS1|GB1|Japan1|Korea1, WMode=H|V, Style=serif|sans)\n" "\t%%%%Image Name Filename\n\n" ); fputs(fz_pdf_write_options_usage, stderr); @@ -67,20 +67,30 @@ static void add_font_res(pdf_obj *resources, char *name, char *path, char *encna fz_drop_font(ctx, font); } -static void add_cjkfont_res(pdf_obj *resources, char *name, char *on) +static void add_cjkfont_res(pdf_obj *resources, char *name, char *on, char *wm, char *style) { const unsigned char *data; - int size, index, ordering; + int size, index, ordering, wmode, serif; fz_font *font; pdf_obj *subres, *ref; - if (!strcmp(on, "CNS1") || !strcmp(on, "CN")) ordering = FZ_ADOBE_CNS_1; - else if (!strcmp(on, "GB1") || !strcmp(on, "TW")) ordering = FZ_ADOBE_GB_1; + if (!strcmp(on, "CNS1") || !strcmp(on, "TW") || !strcmp(on, "TC") || !strcmp(on, "Hant")) ordering = FZ_ADOBE_CNS_1; + else if (!strcmp(on, "GB1") || !strcmp(on, "CN") || !strcmp(on, "SC") || !strcmp(on, "Hans")) ordering = FZ_ADOBE_GB_1; else if (!strcmp(on, "Japan1") || !strcmp(on, "JP") || !strcmp(on, "JA")) ordering = FZ_ADOBE_JAPAN_1; else if (!strcmp(on, "Korea1") || !strcmp(on, "KR") || !strcmp(on, "KO")) ordering = FZ_ADOBE_KOREA_1; else ordering = FZ_ADOBE_JAPAN_1; - data = fz_lookup_cjk_font(ctx, ordering, 0, 0, &size, &index); + if (wm && !strcmp(wm, "V")) + wmode = 1; + else + wmode = 0; + + if (style && (!strcmp(style, "sans") || !strcmp(style, "sans-serif"))) + serif = 0; + else + serif = 1; + + data = fz_lookup_cjk_font(ctx, ordering, serif, wmode, &size, &index); font = fz_new_font_from_memory(ctx, NULL, data, size, index, 0); subres = pdf_dict_get(ctx, resources, PDF_NAME(Font)); @@ -90,7 +100,7 @@ static void add_cjkfont_res(pdf_obj *resources, char *name, char *on) pdf_dict_put_drop(ctx, resources, PDF_NAME(Font), subres); } - ref = pdf_add_cjk_font(ctx, doc, font, ordering); + ref = pdf_add_cjk_font(ctx, doc, font, ordering, wmode, serif); pdf_dict_puts(ctx, subres, name, ref); pdf_drop_obj(ctx, ref); @@ -124,7 +134,7 @@ The input is a raw content stream, with commands embedded in comments: %%MediaBox LLX LLY URX URY %%Rotate Angle %%Font Name Filename (or base 14 font name) [Encoding (Latin, Greek or Cyrillic)] -%%CJKFont Name Ordering (CNS1, GB1, Japan1, or Korea1) +%%CJKFont Name Ordering WMode Style (Ordering=CNS1|GB1|Japan1|Korea1, WMode=H|V, Style=serif|sans) %%Image Name Filename */ static void create_page(char *input) @@ -133,7 +143,7 @@ static void create_page(char *input) int rotate = 0; char line[4096]; - char *s, *t, *p; + char *s, *p; fz_stream *stm; fz_buffer *contents; @@ -163,25 +173,30 @@ static void create_page(char *input) } else if (!strcmp(s, "%%Font")) { - s = fz_strsep(&p, " "); - t = fz_strsep(&p, " "); - if (!s || !t) + char *name = fz_strsep(&p, " "); + char *path = fz_strsep(&p, " "); + char *enc = fz_strsep(&p, " "); + if (!name || !path) fz_throw(ctx, FZ_ERROR_GENERIC, "Font directive missing arguments"); - add_font_res(resources, s, t, p); + add_font_res(resources, name, path, enc); } else if (!strcmp(s, "%%CJKFont")) { - s = fz_strsep(&p, " "); - if (!s || !p) + char *name = fz_strsep(&p, " "); + char *ordering = fz_strsep(&p, " "); + char *wmode = fz_strsep(&p, " "); + char *style = fz_strsep(&p, " "); + if (!name || !ordering) fz_throw(ctx, FZ_ERROR_GENERIC, "CJKFont directive missing arguments"); - add_cjkfont_res(resources, s, p); + add_cjkfont_res(resources, name, ordering, wmode, style); } else if (!strcmp(s, "%%Image")) { - s = fz_strsep(&p, " "); - if (!s || !p) + char *name = fz_strsep(&p, " "); + char *path = fz_strsep(&p, " "); + if (!name || !path) fz_throw(ctx, FZ_ERROR_GENERIC, "Image directive missing arguments"); - add_image_res(resources, s, p); + add_image_res(resources, name, path); } } else |