summaryrefslogtreecommitdiff
path: root/source/tools/pdfcreate.c
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2018-03-14 17:52:17 +0100
committerTor Andersson <tor.andersson@artifex.com>2018-03-16 14:51:41 +0100
commit2612c20b725319833caeef36ccf4240f34e0e24b (patch)
treeeb58090f9a78187690bc5197b11284576a50b8c3 /source/tools/pdfcreate.c
parent5a2b234c8e93a2c3acdb21e79da684dbcfe677c7 (diff)
downloadmupdf-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/pdfcreate.c')
-rw-r--r--source/tools/pdfcreate.c37
1 files changed, 37 insertions, 0 deletions
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, " ");