summaryrefslogtreecommitdiff
path: root/source/pdf
diff options
context:
space:
mode:
Diffstat (limited to 'source/pdf')
-rw-r--r--source/pdf/pdf-font.c89
-rw-r--r--source/pdf/pdf-resources.c3
2 files changed, 89 insertions, 3 deletions
diff --git a/source/pdf/pdf-font.c b/source/pdf/pdf-font.c
index 9e8a50dc..6be72250 100644
--- a/source/pdf/pdf-font.c
+++ b/source/pdf/pdf-font.c
@@ -2099,7 +2099,7 @@ pdf_add_cid_font(fz_context *ctx, pdf_document *doc, fz_font *font)
/* Before we add this font as a resource check if the same font
* already exists in our resources for this doc. If yes, then
* hand back that reference */
- fref = pdf_find_font_resource(ctx, doc, PDF_CID_FONT_RESOURCE, font->buffer, digest);
+ fref = pdf_find_font_resource(ctx, doc, PDF_CID_FONT_RESOURCE, 0, font->buffer, digest);
if (fref == NULL)
{
/* Set up desc, width, and font file */
@@ -2174,7 +2174,7 @@ pdf_add_simple_font(fz_context *ctx, pdf_document *doc, fz_font *font)
/* Before we add this font as a resource check if the same font
* already exists in our resources for this doc. If yes, then
* hand back that reference */
- fref = pdf_find_font_resource(ctx, doc, PDF_SIMPLE_FONT_RESOURCE, font->buffer, digest);
+ fref = pdf_find_font_resource(ctx, doc, PDF_SIMPLE_FONT_RESOURCE, 0, font->buffer, digest);
if (fref == NULL)
{
fobj = pdf_new_dict(ctx, doc, 10);
@@ -2247,3 +2247,88 @@ pdf_font_writing_supported(fz_font *font)
}
return 0;
}
+
+/* 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_obj *fref, *font, *subfont, *fontdesc;
+ pdf_obj *dfonts, *ros;
+ fz_rect bbox = { -200, -200, 1200, 1200 };
+ unsigned char digest[16];
+
+ const char *basefont, *encoding, *ordering;
+ int supplement;
+
+ switch (script)
+ {
+ case FZ_ADOBE_CNS_1:
+ basefont = "Song";
+ encoding = "UniCNS-UTF16-H";
+ ordering = "CNS1";
+ supplement = 7;
+ break;
+ case FZ_ADOBE_GB_1:
+ basefont = "Ming";
+ encoding = "UniGB-UTF16-H";
+ ordering = "GB1";
+ supplement = 5;
+ break;
+ default:
+ script = FZ_ADOBE_JAPAN_1;
+ /* fall through */
+ case FZ_ADOBE_JAPAN_1:
+ basefont = "Mincho";
+ encoding = "UniJIS-UTF16-H";
+ ordering = "Japan1";
+ supplement = 6;
+ break;
+ case FZ_ADOBE_KOREA_1:
+ basefont = "Batang";
+ encoding = "UniKS-UTF16-H";
+ ordering = "Korea1";
+ supplement = 2;
+ break;
+ }
+
+ fref = pdf_find_font_resource(ctx, doc, PDF_CJK_FONT_RESOURCE, script, fzfont->buffer, digest);
+ if (fref)
+ return fref;
+
+ font = pdf_new_dict(ctx, doc, 5);
+ pdf_dict_put(ctx, font, PDF_NAME_Type, PDF_NAME_Font);
+ pdf_dict_put(ctx, font, PDF_NAME_Subtype, PDF_NAME_Type0);
+ pdf_dict_put_name(ctx, font, PDF_NAME_BaseFont, basefont);
+ pdf_dict_put_name(ctx, font, PDF_NAME_Encoding, encoding);
+ pdf_dict_put_drop(ctx, font, PDF_NAME_DescendantFonts, dfonts = pdf_new_array(ctx, doc, 1));
+ subfont = pdf_new_dict(ctx, doc, 5);
+ {
+ pdf_dict_put(ctx, subfont, PDF_NAME_Type, PDF_NAME_Font);
+ pdf_dict_put(ctx, subfont, PDF_NAME_Subtype, PDF_NAME_CIDFontType0);
+ pdf_dict_put_name(ctx, subfont, PDF_NAME_BaseFont, basefont);
+ pdf_dict_put_drop(ctx, subfont, PDF_NAME_CIDSystemInfo, ros = pdf_new_dict(ctx, doc, 3));
+ pdf_dict_put_text_string(ctx, ros, PDF_NAME_Registry, "Adobe");
+ pdf_dict_put_text_string(ctx, ros, PDF_NAME_Ordering, ordering);
+ pdf_dict_put_int(ctx, ros, PDF_NAME_Supplement, supplement);
+ fontdesc = pdf_new_dict(ctx, doc, 8);
+ {
+ 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_ItalicAngle, 0);
+ pdf_dict_put_int(ctx, fontdesc, PDF_NAME_Ascent, 1000);
+ pdf_dict_put_int(ctx, fontdesc, PDF_NAME_Descent, -200);
+ pdf_dict_put_int(ctx, fontdesc, PDF_NAME_StemV, 80);
+ }
+ pdf_dict_put_drop(ctx, subfont, PDF_NAME_FontDescriptor, pdf_add_object_drop(ctx, doc, fontdesc));
+ }
+ pdf_array_push_drop(ctx, dfonts, pdf_add_object_drop(ctx, doc, subfont));
+
+ fref = pdf_add_object_drop(ctx, doc, font);
+
+ /* Add ref to our font resource hash table. */
+ fref = pdf_insert_font_resource(ctx, doc, digest, fref);
+
+ return fref;
+}
diff --git a/source/pdf/pdf-resources.c b/source/pdf/pdf-resources.c
index 72adf081..720ee2b1 100644
--- a/source/pdf/pdf-resources.c
+++ b/source/pdf/pdf-resources.c
@@ -109,7 +109,7 @@ pdf_insert_image_resource(fz_context *ctx, pdf_document *doc, unsigned char dige
* it may be more problematic. */
pdf_obj *
-pdf_find_font_resource(fz_context *ctx, pdf_document *doc, int type, fz_buffer *item, unsigned char digest[16])
+pdf_find_font_resource(fz_context *ctx, pdf_document *doc, int type, int encoding, fz_buffer *item, unsigned char digest[16])
{
fz_md5 state;
unsigned char *data;
@@ -124,6 +124,7 @@ pdf_find_font_resource(fz_context *ctx, pdf_document *doc, int type, fz_buffer *
/* Create md5 and see if we have the item in our table */
fz_md5_init(&state);
fz_md5_update(&state, (unsigned char*)&type, sizeof type);
+ fz_md5_update(&state, (unsigned char*)&encoding, sizeof encoding);
fz_md5_update(&state, data, size);
fz_md5_final(&state, digest);