diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2018-03-14 17:52:17 +0100 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2018-03-16 14:51:41 +0100 |
commit | 2612c20b725319833caeef36ccf4240f34e0e24b (patch) | |
tree | eb58090f9a78187690bc5197b11284576a50b8c3 /source/tools | |
parent | 5a2b234c8e93a2c3acdb21e79da684dbcfe677c7 (diff) | |
download | mupdf-2612c20b725319833caeef36ccf4240f34e0e24b.tar.xz |
Add simple CJK font creation.
Create a non-embedded CJK font using UTF-16 encoding. This can be used
in mutool create like so:
%%CJKFont Ming GB1
BT
/Ming 10 Tf
100 100 Td
<4F60 597D> Tj
ET
Diffstat (limited to 'source/tools')
-rw-r--r-- | source/tools/murun.c | 23 | ||||
-rw-r--r-- | source/tools/pdfcreate.c | 37 |
2 files changed, 60 insertions, 0 deletions
diff --git a/source/tools/murun.c b/source/tools/murun.c index bed686a7..911fcf35 100644 --- a/source/tools/murun.c +++ b/source/tools/murun.c @@ -3261,6 +3261,28 @@ static void ffi_PDFDocument_addSimpleFont(js_State *J) ffi_pushobj(J, ind); } +static void ffi_PDFDocument_addCJKFont(js_State *J) +{ + fz_context *ctx = js_getcontext(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); + int ord = FZ_ADOBE_JAPAN_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; + 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; + + fz_try(ctx) + ind = pdf_add_cjk_font(ctx, pdf, font, ord); + fz_catch(ctx) + rethrow(J); + + ffi_pushobj(J, ind); +} + static void ffi_PDFDocument_addFont(js_State *J) { fz_context *ctx = js_getcontext(J); @@ -4676,6 +4698,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, 1); + jsB_propfun(J, "PDFDocument.addCJKFont", ffi_PDFDocument_addCJKFont, 2); 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 b1649500..93dff5fb 100644 --- a/source/tools/pdfcreate.c +++ b/source/tools/pdfcreate.c @@ -22,6 +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%%%%Image Name Filename\n\n" ); fputs(fz_pdf_write_options_usage, stderr); @@ -58,6 +59,36 @@ static void add_font_res(pdf_obj *resources, char *name, char *path) fz_drop_font(ctx, font); } +static void add_cjkfont_res(pdf_obj *resources, char *name, char *on) +{ + const unsigned char *data; + int size, index, ordering; + 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; + 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); + font = fz_new_font_from_memory(ctx, NULL, data, size, index, 0); + + subres = pdf_dict_get(ctx, resources, PDF_NAME_Font); + if (!subres) + { + subres = pdf_new_dict(ctx, doc, 10); + pdf_dict_put_drop(ctx, resources, PDF_NAME_Font, subres); + } + + ref = pdf_add_cjk_font(ctx, doc, font, ordering); + pdf_dict_puts(ctx, subres, name, ref); + pdf_drop_obj(ctx, ref); + + fz_drop_font(ctx, font); +} + static void add_image_res(pdf_obj *resources, char *name, char *path) { fz_image *image; @@ -85,6 +116,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) +%%CJKFont Name Ordering (CNS1, GB1, Japan1, or Korea1) %%Image Name Filename */ static void create_page(char *input) @@ -126,6 +158,11 @@ static void create_page(char *input) s = fz_strsep(&p, " "); add_font_res(resources, s, p); } + else if (!strcmp(s, "%%CJKFont")) + { + s = fz_strsep(&p, " "); + add_cjkfont_res(resources, s, p); + } else if (!strcmp(s, "%%Image")) { s = fz_strsep(&p, " "); |