From 1cd2046b3cce264a3d13481652868fd1c31537fc Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Thu, 15 Mar 2018 11:55:06 +0100 Subject: Add simple fonts with 8-bit greek and cyrillic encodings. Use KOI8-U for Cyrillic, and ISO 8859-7 for Greek. Use with 'mutool create' using an extra argument to the %%Font directive: %%Font TmRmC Times-Roman Cyrillic BT /TmRmC 16 Tf 10 10 Td Tj ET The alternatives are "Latin", "Greek", and "Cyrillic". --- source/tools/murun.c | 10 ++++++++-- source/tools/pdfcreate.c | 19 ++++++++++++++----- source/tools/pdfportfolio.c | 2 +- 3 files changed, 23 insertions(+), 8 deletions(-) (limited to 'source/tools') diff --git a/source/tools/murun.c b/source/tools/murun.c index 911fcf35..8b9cd29d 100644 --- a/source/tools/murun.c +++ b/source/tools/murun.c @@ -3251,10 +3251,16 @@ static void ffi_PDFDocument_addSimpleFont(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 *encname = js_tostring(J, 2); pdf_obj *ind = NULL; + int enc = PDF_SIMPLE_ENCODING_LATIN; + + if (!strcmp(encname, "Latin")) enc = PDF_SIMPLE_ENCODING_LATIN; + else if (!strcmp(encname, "Greek")) enc = PDF_SIMPLE_ENCODING_GREEK; + else if (!strcmp(encname, "Cyrillic")) enc = PDF_SIMPLE_ENCODING_CYRILLIC; fz_try(ctx) - ind = pdf_add_simple_font(ctx, pdf, font); + ind = pdf_add_simple_font(ctx, pdf, font, enc); fz_catch(ctx) rethrow(J); @@ -4697,7 +4703,7 @@ int murun_main(int argc, char **argv) jsB_propfun(J, "PDFDocument.addObject", ffi_PDFDocument_addObject, 1); 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.addSimpleFont", ffi_PDFDocument_addSimpleFont, 2); 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); diff --git a/source/tools/pdfcreate.c b/source/tools/pdfcreate.c index 93dff5fb..032f32d5 100644 --- a/source/tools/pdfcreate.c +++ b/source/tools/pdfcreate.c @@ -32,10 +32,10 @@ static void usage(void) static fz_context *ctx = NULL; static pdf_document *doc = NULL; -static void add_font_res(pdf_obj *resources, char *name, char *path) +static void add_font_res(pdf_obj *resources, char *name, char *path, char *encname) { const unsigned char *data; - int size; + int size, enc; fz_font *font; pdf_obj *subres, *ref; @@ -52,7 +52,15 @@ static void add_font_res(pdf_obj *resources, char *name, char *path) pdf_dict_put_drop(ctx, resources, PDF_NAME_Font, subres); } - ref = pdf_add_simple_font(ctx, doc, font); + enc = PDF_SIMPLE_ENCODING_LATIN; + if (encname) + { + if (!strcmp(encname, "Latin")) enc = PDF_SIMPLE_ENCODING_LATIN; + else if (!strcmp(encname, "Greek")) enc = PDF_SIMPLE_ENCODING_GREEK; + else if (!strcmp(encname, "Cyrillic")) enc = PDF_SIMPLE_ENCODING_CYRILLIC; + } + + ref = pdf_add_simple_font(ctx, doc, font, enc); pdf_dict_puts(ctx, subres, name, ref); pdf_drop_obj(ctx, ref); @@ -125,7 +133,7 @@ static void create_page(char *input) int rotate = 0; char line[4096]; - char *s, *p; + char *s, *t, *p; fz_stream *stm; fz_buffer *contents; @@ -156,7 +164,8 @@ static void create_page(char *input) else if (!strcmp(s, "%%Font")) { s = fz_strsep(&p, " "); - add_font_res(resources, s, p); + t = fz_strsep(&p, " "); + add_font_res(resources, s, t, p); } else if (!strcmp(s, "%%CJKFont")) { diff --git a/source/tools/pdfportfolio.c b/source/tools/pdfportfolio.c index 9a0efc01..8e252d43 100644 --- a/source/tools/pdfportfolio.c +++ b/source/tools/pdfportfolio.c @@ -255,7 +255,7 @@ int pdfportfolio_main(int argc, char **argv) data = fz_lookup_base14_font(ctx, "Times-Roman", &size); font = fz_new_font_from_memory(ctx, "Times-Roman", data, size, 0, 0); - font_obj = pdf_add_simple_font(ctx, doc, font); + font_obj = pdf_add_simple_font(ctx, doc, font, PDF_SIMPLE_ENCODING_LATIN); fz_drop_font(ctx, font); resources = pdf_add_object_drop(ctx, doc, pdf_new_dict(ctx, doc, 1)); -- cgit v1.2.3