summaryrefslogtreecommitdiff
path: root/source/tools/pdfcreate.c
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2018-04-18 11:49:03 +0200
committerTor Andersson <tor.andersson@artifex.com>2018-04-25 12:26:33 +0200
commit26697653468e91d609896eadfe95bb3027eadd5b (patch)
tree810d3ea2868f4d0cda015dd01bd9637b41739f36 /source/tools/pdfcreate.c
parent333bdae9b44165297bfb7206b0bd0e6e02274ebc (diff)
downloadmupdf-26697653468e91d609896eadfe95bb3027eadd5b.tar.xz
Support creating both serif and sans-serif CJK fonts in mutool create.
Also support Vertical WMode.
Diffstat (limited to 'source/tools/pdfcreate.c')
-rw-r--r--source/tools/pdfcreate.c53
1 files changed, 34 insertions, 19 deletions
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