diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2016-01-27 15:25:23 +0100 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2016-01-28 20:09:53 +0000 |
commit | 89559a410d5e79e0922128f90171935c6d55341a (patch) | |
tree | be969b16cb8af1a01134adc32ccbfc924a391991 | |
parent | dadef8ae9ca208d4c02516fd8e73606fd1e7863c (diff) | |
download | mupdf-89559a410d5e79e0922128f90171935c6d55341a.tar.xz |
Add Noto fallback fonts.
Look up fallback fonts by unicode script, with a flag to select the serif or
sans-serif font style where such variants exist.
Move all builtin fonts into fitz namespace.
-rw-r--r-- | Makefile | 7 | ||||
-rw-r--r-- | include/mupdf/fitz/font.h | 6 | ||||
-rw-r--r-- | include/mupdf/pdf/font.h | 2 | ||||
-rw-r--r-- | platform/gl/gl-font.c | 6 | ||||
-rw-r--r-- | platform/win32/generate.bat | 1 | ||||
-rw-r--r-- | platform/win32/generated.vcproj | 2 | ||||
-rw-r--r-- | platform/win32/libmupdf.vcproj | 8 | ||||
-rw-r--r-- | scripts/fontdump.c | 10 | ||||
-rw-r--r-- | source/fitz/noto.c | 335 | ||||
-rw-r--r-- | source/html/html-font.c | 30 | ||||
-rw-r--r-- | source/pdf/pdf-font.c | 34 | ||||
-rw-r--r-- | source/pdf/pdf-fontfile.c | 138 |
12 files changed, 414 insertions, 165 deletions
@@ -169,6 +169,7 @@ CMAP_JAPAN_SRC := $(wildcard resources/cmaps/japan/*) CMAP_KOREA_SRC := $(wildcard resources/cmaps/korea/*) FONT_BASE14_SRC := $(wildcard resources/fonts/urw/*.cff) +FONT_NOTO_SRC := $(wildcard resources/fonts/noto/*.ttf) FONT_CJK_SRC := resources/fonts/droid/DroidSansFallback.ttc FONT_CJK_FULL_SRC := resources/fonts/droid/DroidSansFallbackFull.ttc @@ -185,12 +186,14 @@ CMAP_GEN := $(addprefix $(GEN)/, gen_cmap_cns.h gen_cmap_gb.h gen_cmap_japan.h g $(GEN)/gen_font_base14.h : $(FONT_BASE14_SRC) $(QUIET_GEN) $(FONTDUMP) $@ $(FONT_BASE14_SRC) +$(GEN)/gen_font_noto.h : $(FONT_NOTO_SRC) + $(QUIET_GEN) $(FONTDUMP) $@ $(FONT_NOTO_SRC) $(GEN)/gen_font_cjk.h : $(FONT_CJK_SRC) $(QUIET_GEN) $(FONTDUMP) $@ $(FONT_CJK_SRC) $(GEN)/gen_font_cjk_full.h : $(FONT_CJK_FULL_SRC) $(QUIET_GEN) $(FONTDUMP) $@ $(FONT_CJK_FULL_SRC) -FONT_GEN := $(GEN)/gen_font_base14.h $(GEN)/gen_font_cjk.h $(GEN)/gen_font_cjk_full.h +FONT_GEN := $(GEN)/gen_font_base14.h $(GEN)/gen_font_noto.h $(GEN)/gen_font_cjk.h $(GEN)/gen_font_cjk_full.h include/mupdf/pdf.h : include/mupdf/pdf/name-table.h NAME_GEN := include/mupdf/pdf/name-table.h source/pdf/pdf-name-table.h @@ -217,8 +220,8 @@ endif generate: $(CMAP_GEN) $(FONT_GEN) $(JAVASCRIPT_GEN) $(ADOBECA_GEN) $(NAME_GEN) +$(OUT)/fitz/noto.o : $(FONT_GEN) $(OUT)/pdf/pdf-cmap-table.o : $(CMAP_GEN) -$(OUT)/pdf/pdf-fontfile.o : $(FONT_GEN) $(OUT)/pdf/pdf-pkcs7.o : $(ADOBECA_GEN) $(OUT)/pdf/js/pdf-js.o : $(JAVASCRIPT_GEN) $(OUT)/pdf/pdf-object.o : source/pdf/pdf-name-table.h diff --git a/include/mupdf/fitz/font.h b/include/mupdf/fitz/font.h index 313f5ac8..236e1514 100644 --- a/include/mupdf/fitz/font.h +++ b/include/mupdf/fitz/font.h @@ -87,6 +87,12 @@ void fz_install_load_system_font_funcs(fz_context *ctx, fz_load_system_font_func fz_font *fz_load_system_font(fz_context *ctx, const char *name, int bold, int italic, int needs_exact_metrics); fz_font *fz_load_system_cjk_font(fz_context *ctx, const char *name, int ros, int serif); +unsigned char *fz_lookup_base14_font(fz_context *ctx, const char *name, unsigned int *len); +unsigned char *fz_lookup_cjk_font(fz_context *ctx, int registry, int serif, int wmode, unsigned int *len, int *index); +unsigned char *fz_lookup_noto_font(fz_context *ctx, int script, int serif, unsigned int *len); +unsigned char *fz_lookup_noto_symbol_font(fz_context *ctx, unsigned int *len); +unsigned char *fz_lookup_noto_emoji_font(fz_context *ctx, unsigned int *len); + fz_font *fz_new_type3_font(fz_context *ctx, const char *name, const fz_matrix *matrix); fz_font *fz_new_font_from_memory(fz_context *ctx, const char *name, unsigned char *data, int len, int index, int use_glyph_bbox); diff --git a/include/mupdf/pdf/font.h b/include/mupdf/pdf/font.h index 9bd8d913..17902198 100644 --- a/include/mupdf/pdf/font.h +++ b/include/mupdf/pdf/font.h @@ -103,9 +103,7 @@ void pdf_load_to_unicode(fz_context *ctx, pdf_document *doc, pdf_font_desc *font int pdf_font_cid_to_gid(fz_context *ctx, pdf_font_desc *fontdesc, int cid); -unsigned char *pdf_lookup_builtin_font(fz_context *ctx, const char *name, unsigned int *len); unsigned char *pdf_lookup_substitute_font(fz_context *ctx, int mono, int serif, int bold, int italic, unsigned int *len); -unsigned char *pdf_lookup_substitute_cjk_font(fz_context *ctx, int ros, int serif, int wmode, unsigned int *len, int *index); pdf_font_desc *pdf_load_type3_font(fz_context *ctx, pdf_document *doc, pdf_obj *rdb, pdf_obj *obj); void pdf_load_type3_glyphs(fz_context *ctx, pdf_document *doc, pdf_font_desc *fontdesc, int nestedDepth); diff --git a/platform/gl/gl-font.c b/platform/gl/gl-font.c index efba4d98..80d0d27e 100644 --- a/platform/gl/gl-font.c +++ b/platform/gl/gl-font.c @@ -14,8 +14,6 @@ #include "gl-app.h" -#include "mupdf/pdf.h" /* for builtin fonts */ - #include <ft2build.h> #include FT_FREETYPE_H #include FT_ADVANCES_H @@ -101,12 +99,12 @@ void ui_init_fonts(fz_context *ctx, float pixelsize) clear_font_cache(); - data = pdf_lookup_builtin_font(ctx, "Times-Roman", &size); + data = fz_lookup_base14_font(ctx, "Times-Roman", &size); code = FT_New_Memory_Face(g_freetype_lib, data, size, 0, &g_font); if (code) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot load ui font"); - data = pdf_lookup_substitute_cjk_font(ctx, 0, 0, 0, &size, &index); + data = fz_lookup_cjk_font(ctx, 0, 0, 0, &size, &index); code = FT_New_Memory_Face(g_freetype_lib, data, size, 0, &g_fallback_font); if (code) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot load ui fallback font"); diff --git a/platform/win32/generate.bat b/platform/win32/generate.bat index e7fcadae..e1461269 100644 --- a/platform/win32/generate.bat +++ b/platform/win32/generate.bat @@ -22,6 +22,7 @@ if not exist cquote.exe goto usage if not exist bin2hex.exe goto usage if not exist generated/gen_font_base14.h fontdump.exe generated/gen_font_base14.h resources/fonts/urw/*.cff +if not exist generated/gen_font_noto.h fontdump.exe generated/gen_font_noto.h resources/fonts/noto/*.ttf if not exist generated/gen_font_cjk.h fontdump.exe generated/gen_font_cjk.h resources/fonts/droid/DroidSansFallback.ttc if not exist generated/gen_font_cjk_full.h fontdump.exe generated/gen_font_cjk_full.h resources/fonts/droid/DroidSansFallbackFull.ttc diff --git a/platform/win32/generated.vcproj b/platform/win32/generated.vcproj index 063f997c..6e00ba9c 100644 --- a/platform/win32/generated.vcproj +++ b/platform/win32/generated.vcproj @@ -206,7 +206,7 @@ > </File> <File - RelativePath="..\..\generated\gen_font_droid.h" + RelativePath="..\..\generated\gen_font_noto.h" > </File> <File diff --git a/platform/win32/libmupdf.vcproj b/platform/win32/libmupdf.vcproj index 460a7442..038d77e6 100644 --- a/platform/win32/libmupdf.vcproj +++ b/platform/win32/libmupdf.vcproj @@ -947,6 +947,10 @@ > </File> <File + RelativePath="..\..\source\fitz\noto.c" + > + </File> + <File RelativePath="..\..\source\fitz\outline.c" > </File> @@ -1155,10 +1159,6 @@ > </File> <File - RelativePath="..\..\source\pdf\pdf-fontfile.c" - > - </File> - <File RelativePath="..\..\source\pdf\pdf-form.c" > </File> diff --git a/scripts/fontdump.c b/scripts/fontdump.c index 49c48bbc..568a6e64 100644 --- a/scripts/fontdump.c +++ b/scripts/fontdump.c @@ -94,16 +94,16 @@ main(int argc, char **argv) fseek(fi, 0, SEEK_SET); if (getenv("verbose")) - printf("\t{\"%s\",pdf_font_%s,%d},\n", origname, fontname, len); + printf("\t{\"%s\",fz_font_%s,%d},\n", origname, fontname, len); fprintf(fo, "\n#ifdef HAVE_INCBIN\n"); - fprintf(fo, "extern const unsigned char pdf_font_%s[%d];\n", fontname, len); - fprintf(fo, "asm(\".globl pdf_font_%s\");\n", fontname); + fprintf(fo, "extern const unsigned char fz_font_%s[%d];\n", fontname, len); + fprintf(fo, "asm(\".globl fz_font_%s\");\n", fontname); fprintf(fo, "asm(\".balign 8\");\n"); - fprintf(fo, "asm(\"pdf_font_%s:\");\n", fontname); + fprintf(fo, "asm(\"fz_font_%s:\");\n", fontname); fprintf(fo, "asm(\".incbin \\\"%s\\\"\");\n", argv[i]); fprintf(fo, "#else\n"); - fprintf(fo, "static const unsigned char pdf_font_%s[%d] = {\n", fontname, len); + fprintf(fo, "static const unsigned char fz_font_%s[%d] = {\n", fontname, len); hexdump(fo, fi); fprintf(fo, "};\n"); fprintf(fo, "#endif\n"); diff --git a/source/fitz/noto.c b/source/fitz/noto.c new file mode 100644 index 00000000..f02bc524 --- /dev/null +++ b/source/fitz/noto.c @@ -0,0 +1,335 @@ +#include "mupdf/fitz.h" + +/* + Base 14 PDF fonts from URW. + Noto fonts from Google. + DroidSansFallback from Android for CJK. + + Define TOFU to skip all the Noto fonts except CJK. + + Define TOFU_CJK to skip CJK font. + Define TOFU_CJK_EXT to skip CJK Extension A support. + + Define TOFU_EMOJI to skip emoji font. + Define TOFU_HISTORIC to skip ancient/historic scripts. + Define TOFU_SYMBOL to skip symbol font. +*/ + +#ifdef NOTO_SMALL +#define TOFU_CJK_EXT +#define TOFU_EMOJI +#define TOFU_HISTORIC +#define TOFU_SYMBOL +#endif + +#include "gen_font_base14.h" + +#ifdef NOCJK +#define TOFU_CJK +#endif + +#ifdef TOFU +#define TOFU_EMOJI +#define TOFU_HISTORIC +#define TOFU_SYMBOL +#endif + +#ifndef TOFU_CJK +#ifndef TOFU_CJK_EXT +#include "gen_font_cjk_full.h" +#else +#include "gen_font_cjk.h" +#endif +#endif + +#ifndef TOFU +#include "gen_font_noto.h" +#endif + +unsigned char * +fz_lookup_base14_font(fz_context *ctx, const char *name, unsigned int *len) +{ + if (!strcmp("Courier", name)) { + *len = sizeof fz_font_NimbusMono_Regular; + return (unsigned char*) fz_font_NimbusMono_Regular; + } + if (!strcmp("Courier-Bold", name)) { + *len = sizeof fz_font_NimbusMono_Bold; + return (unsigned char*) fz_font_NimbusMono_Bold; + } + if (!strcmp("Courier-Oblique", name)) { + *len = sizeof fz_font_NimbusMono_Oblique; + return (unsigned char*) fz_font_NimbusMono_Oblique; + } + if (!strcmp("Courier-BoldOblique", name)) { + *len = sizeof fz_font_NimbusMono_BoldOblique; + return (unsigned char*) fz_font_NimbusMono_BoldOblique; + } + if (!strcmp("Helvetica", name)) { + *len = sizeof fz_font_NimbusSanL_Reg; + return (unsigned char*) fz_font_NimbusSanL_Reg; + } + if (!strcmp("Helvetica-Bold", name)) { + *len = sizeof fz_font_NimbusSanL_Bol; + return (unsigned char*) fz_font_NimbusSanL_Bol; + } + if (!strcmp("Helvetica-Oblique", name)) { + *len = sizeof fz_font_NimbusSanL_RegIta; + return (unsigned char*) fz_font_NimbusSanL_RegIta; + } + if (!strcmp("Helvetica-BoldOblique", name)) { + *len = sizeof fz_font_NimbusSanL_BolIta; + return (unsigned char*) fz_font_NimbusSanL_BolIta; + } + if (!strcmp("Times-Roman", name)) { + *len = sizeof fz_font_NimbusRomNo9L_Reg; + return (unsigned char*) fz_font_NimbusRomNo9L_Reg; + } + if (!strcmp("Times-Bold", name)) { + *len = sizeof fz_font_NimbusRomNo9L_Med; + return (unsigned char*) fz_font_NimbusRomNo9L_Med; + } + if (!strcmp("Times-Italic", name)) { + *len = sizeof fz_font_NimbusRomNo9L_RegIta; + return (unsigned char*) fz_font_NimbusRomNo9L_RegIta; + } + if (!strcmp("Times-BoldItalic", name)) { + *len = sizeof fz_font_NimbusRomNo9L_MedIta; + return (unsigned char*) fz_font_NimbusRomNo9L_MedIta; + } + if (!strcmp("Symbol", name)) { + *len = sizeof fz_font_StandardSymL; + return (unsigned char*) fz_font_StandardSymL; + } + if (!strcmp("ZapfDingbats", name)) { + *len = sizeof fz_font_Dingbats; + return (unsigned char*) fz_font_Dingbats; + } + *len = 0; + return NULL; +} + +unsigned char * +fz_lookup_cjk_font(fz_context *ctx, int registry, int serif, int wmode, unsigned int *len, int *index) +{ +#ifndef TOFU_CJK +#ifndef TOFU_CJK_EXT + if (index) *index = wmode; + *len = sizeof fz_font_DroidSansFallbackFull; + return (unsigned char*) fz_font_DroidSansFallbackFull; +#else + if (index) *index = wmode; + *len = sizeof fz_font_DroidSansFallback; + return (unsigned char*) fz_font_DroidSansFallback; +#endif +#else + *len = 0; + return NULL; +#endif +} + +#define Noto(SANS) \ + *len = sizeof fz_font_Noto ## SANS ## _Regular; \ + return (unsigned char*) fz_font_Noto ## SANS ## _Regular; \ + break + +#define Noto2(SANS,SERIF) \ + if (serif) { \ + *len = sizeof fz_font_Noto ## SERIF ## _Regular; \ + return (unsigned char*) fz_font_Noto ## SERIF ## _Regular; \ + } else { \ + *len = sizeof fz_font_Noto ## SANS ## _Regular; \ + return (unsigned char*) fz_font_Noto ## SANS ## _Regular; \ + } \ + break + +#define Noto3(SANS,SERIF,UNUSED) \ + Noto2(SANS,SERIF) + +unsigned char * +fz_lookup_noto_font(fz_context *ctx, int script, int serif, unsigned int *len) +{ + /* Unused Noto fonts: NastaliqUrdu, SansSyriacEstrangela */ + + switch (script) + { + default: + case UCDN_SCRIPT_COMMON: + case UCDN_SCRIPT_INHERITED: + case UCDN_SCRIPT_UNKNOWN: + break; + + case UCDN_SCRIPT_HANGUL: + return fz_lookup_cjk_font(ctx, FZ_ADOBE_KOREA_1, serif, 0, len, NULL); + case UCDN_SCRIPT_HIRAGANA: + case UCDN_SCRIPT_KATAKANA: + return fz_lookup_cjk_font(ctx, FZ_ADOBE_JAPAN_1, serif, 0, len, NULL); + case UCDN_SCRIPT_BOPOMOFO: + return fz_lookup_cjk_font(ctx, FZ_ADOBE_GB_1, serif, 0, len, NULL); + case UCDN_SCRIPT_HAN: + return fz_lookup_cjk_font(ctx, FZ_ADOBE_GB_1, serif, 0, len, NULL); + +#ifndef TOFU + +#ifndef TOFU_HISTORIC + case UCDN_SCRIPT_IMPERIAL_ARAMAIC: Noto(SansImperialAramaic); + case UCDN_SCRIPT_AVESTAN: Noto(SansAvestan); + case UCDN_SCRIPT_CARIAN: Noto(SansCarian); + case UCDN_SCRIPT_CYPRIOT: Noto(SansCypriot); + case UCDN_SCRIPT_EGYPTIAN_HIEROGLYPHS: Noto(SansEgyptianHieroglyphs); + case UCDN_SCRIPT_GLAGOLITIC: Noto(SansGlagolitic); + case UCDN_SCRIPT_GOTHIC: Noto(SansGothic); + case UCDN_SCRIPT_OLD_ITALIC: Noto(SansOldItalic); + case UCDN_SCRIPT_KHAROSHTHI: Noto(SansKharoshthi); + case UCDN_SCRIPT_KAITHI: Noto(SansKaithi); + case UCDN_SCRIPT_LINEAR_B: Noto(SansLinearB); + case UCDN_SCRIPT_LYCIAN: Noto(SansLycian); + case UCDN_SCRIPT_LYDIAN: Noto(SansLydian); + case UCDN_SCRIPT_OGHAM: Noto(SansOgham); + case UCDN_SCRIPT_OLD_TURKIC: Noto(SansOldTurkic); + case UCDN_SCRIPT_PHAGS_PA: Noto(SansPhagsPa); + case UCDN_SCRIPT_INSCRIPTIONAL_PAHLAVI: Noto(SansInscriptionalPahlavi); + case UCDN_SCRIPT_INSCRIPTIONAL_PARTHIAN: Noto(SansInscriptionalParthian); + case UCDN_SCRIPT_RUNIC: Noto(SansRunic); + case UCDN_SCRIPT_OLD_SOUTH_ARABIAN: Noto(SansOldSouthArabian); + case UCDN_SCRIPT_UGARITIC: Noto(SansUgaritic); + case UCDN_SCRIPT_OLD_PERSIAN: Noto(SansOldPersian); + case UCDN_SCRIPT_CUNEIFORM: Noto(SansCuneiform); + case UCDN_SCRIPT_COPTIC: Noto(SansCoptic); +#endif + + case UCDN_SCRIPT_LATIN: Noto2(Sans, Serif); + case UCDN_SCRIPT_GREEK: Noto2(Sans, Serif); + case UCDN_SCRIPT_CYRILLIC: Noto2(Sans, Serif); + case UCDN_SCRIPT_ARMENIAN: Noto2(SansArmenian, SerifArmenian); + case UCDN_SCRIPT_HEBREW: Noto(SansHebrew); + case UCDN_SCRIPT_ARABIC: Noto3(KufiArabic, NaskhArabic, NastaliqUrdu); + case UCDN_SCRIPT_SYRIAC: Noto3(SansSyriacEastern, SansSyriacWestern, SansSyriacEstrangela); + case UCDN_SCRIPT_THAANA: Noto(SansThaana); + case UCDN_SCRIPT_DEVANAGARI: Noto(SansDevanagari); + case UCDN_SCRIPT_BENGALI: Noto2(SansBengali, SerifBengali); + case UCDN_SCRIPT_GURMUKHI: Noto(SansGurmukhi); + case UCDN_SCRIPT_GUJARATI: Noto2(SansGujarati, SerifGujarati); + case UCDN_SCRIPT_ORIYA: Noto(SansOriya); + case UCDN_SCRIPT_TAMIL: Noto2(SansTamil, SerifTamil); + case UCDN_SCRIPT_TELUGU: Noto2(SansTelugu, SerifTelugu); + case UCDN_SCRIPT_KANNADA: Noto2(SansKannada, SerifKannada); + case UCDN_SCRIPT_MALAYALAM: Noto2(SansMalayalam, SerifMalayalam); + case UCDN_SCRIPT_SINHALA: Noto(SansSinhala); + case UCDN_SCRIPT_THAI: Noto2(SansThai, SerifThai); + case UCDN_SCRIPT_LAO: Noto2(SansLao, SerifLao); + case UCDN_SCRIPT_TIBETAN: Noto(SansTibetan); + case UCDN_SCRIPT_MYANMAR: Noto(SansMyanmar); + case UCDN_SCRIPT_GEORGIAN: Noto2(SansGeorgian, SerifGeorgian); + case UCDN_SCRIPT_ETHIOPIC: Noto(SansEthiopic); + case UCDN_SCRIPT_CHEROKEE: Noto(SansCherokee); + case UCDN_SCRIPT_CANADIAN_ABORIGINAL: Noto(SansCanadianAboriginal); + case UCDN_SCRIPT_KHMER: Noto2(SansKhmer, SerifKhmer); + case UCDN_SCRIPT_MONGOLIAN: Noto(SansMongolian); + case UCDN_SCRIPT_YI: Noto(SansYi); + case UCDN_SCRIPT_DESERET: Noto(SansDeseret); + case UCDN_SCRIPT_TAGALOG: Noto(SansTagalog); + case UCDN_SCRIPT_HANUNOO: Noto(SansHanunoo); + case UCDN_SCRIPT_BUHID: Noto(SansBuhid); + case UCDN_SCRIPT_TAGBANWA: Noto(SansTagbanwa); + case UCDN_SCRIPT_LIMBU: Noto(SansLimbu); + case UCDN_SCRIPT_TAI_LE: Noto(SansTaiLe); + case UCDN_SCRIPT_SHAVIAN: Noto(SansShavian); + case UCDN_SCRIPT_OSMANYA: Noto(SansOsmanya); + case UCDN_SCRIPT_BUGINESE: Noto(SansBuginese); + case UCDN_SCRIPT_NEW_TAI_LUE: Noto(SansNewTaiLue); + case UCDN_SCRIPT_TIFINAGH: Noto(SansTifinagh); + case UCDN_SCRIPT_SYLOTI_NAGRI: Noto(SansSylotiNagri); + case UCDN_SCRIPT_BALINESE: Noto(SansBalinese); + case UCDN_SCRIPT_PHOENICIAN: Noto(SansPhoenician); + case UCDN_SCRIPT_NKO: Noto(SansNKo); + case UCDN_SCRIPT_SUNDANESE: Noto(SansSundanese); + case UCDN_SCRIPT_LEPCHA: Noto(SansLepcha); + case UCDN_SCRIPT_OL_CHIKI: Noto(SansOlChiki); + case UCDN_SCRIPT_VAI: Noto(SansVai); + case UCDN_SCRIPT_SAURASHTRA: Noto(SansSaurashtra); + case UCDN_SCRIPT_KAYAH_LI: Noto(SansKayahLi); + case UCDN_SCRIPT_REJANG: Noto(SansRejang); + case UCDN_SCRIPT_CHAM: Noto(SansCham); + case UCDN_SCRIPT_TAI_THAM: Noto(SansTaiTham); + case UCDN_SCRIPT_TAI_VIET: Noto(SansTaiViet); + case UCDN_SCRIPT_SAMARITAN: Noto(SansSamaritan); + case UCDN_SCRIPT_LISU: Noto(SansLisu); + case UCDN_SCRIPT_BAMUM: Noto(SansBamum); + case UCDN_SCRIPT_JAVANESE: Noto(SansJavanese); + case UCDN_SCRIPT_MEETEI_MAYEK: Noto(SansMeeteiMayek); + case UCDN_SCRIPT_BATAK: Noto(SansBatak); + case UCDN_SCRIPT_BRAHMI: Noto(SansBrahmi); + case UCDN_SCRIPT_MANDAIC: Noto(SansMandaic); + + /* No fonts available for these scripts: */ +#ifndef TOFU_HISTORIC + case UCDN_SCRIPT_AHOM: break; + case UCDN_SCRIPT_BASSA_VAH: break; + case UCDN_SCRIPT_ELBASAN: break; + case UCDN_SCRIPT_GRANTHA: break; + case UCDN_SCRIPT_HATRAN: break; + case UCDN_SCRIPT_ANATOLIAN_HIEROGLYPHS: break; + case UCDN_SCRIPT_OLD_HUNGARIAN: break; + case UCDN_SCRIPT_KHOJKI: break; + case UCDN_SCRIPT_LINEAR_A: break; + case UCDN_SCRIPT_MAHAJANI: break; + case UCDN_SCRIPT_MANICHAEAN: break; + case UCDN_SCRIPT_MEROITIC_CURSIVE: break; + case UCDN_SCRIPT_MEROITIC_HIEROGLYPHS: break; + case UCDN_SCRIPT_MODI: break; + case UCDN_SCRIPT_MULTANI: break; + case UCDN_SCRIPT_OLD_NORTH_ARABIAN: break; + case UCDN_SCRIPT_NABATAEAN: break; + case UCDN_SCRIPT_PALMYRENE: break; + case UCDN_SCRIPT_OLD_PERMIC: break; + case UCDN_SCRIPT_PSALTER_PAHLAVI: break; + case UCDN_SCRIPT_SIDDHAM: break; +#endif + case UCDN_SCRIPT_BRAILLE: break; /* no dedicated font */ + case UCDN_SCRIPT_CHAKMA: break; + case UCDN_SCRIPT_MIAO: break; + case UCDN_SCRIPT_SHARADA: break; + case UCDN_SCRIPT_SORA_SOMPENG: break; + case UCDN_SCRIPT_TAKRI: break; + case UCDN_SCRIPT_CAUCASIAN_ALBANIAN: break; + case UCDN_SCRIPT_DUPLOYAN: break; + case UCDN_SCRIPT_KHUDAWADI: break; + case UCDN_SCRIPT_MENDE_KIKAKUI: break; + case UCDN_SCRIPT_MRO: break; + case UCDN_SCRIPT_PAHAWH_HMONG: break; + case UCDN_SCRIPT_PAU_CIN_HAU: break; + case UCDN_SCRIPT_TIRHUTA: break; + case UCDN_SCRIPT_WARANG_CITI: break; + case UCDN_SCRIPT_SIGNWRITING: break; + +#endif + } + + *len = 0; + return NULL; +} + +unsigned char * +fz_lookup_noto_symbol_font(fz_context *ctx, unsigned int *len) +{ +#ifndef TOFU_SYMBOL + *len = sizeof fz_font_NotoSansSymbols_Regular; + return (unsigned char*) fz_font_NotoSansSymbols_Regular; +#else + *len = 0; + return NULL; +#endif +} + +unsigned char * +fz_lookup_noto_emoji_font(fz_context *ctx, unsigned int *len) +{ +#ifndef TOFU_EMOJI + *len = sizeof fz_font_NotoEmoji_Regular; + return (unsigned char*) fz_font_NotoEmoji_Regular; +#else + *len = 0; + return NULL; +#endif +} diff --git a/source/html/html-font.c b/source/html/html-font.c index 0880563a..bca1625e 100644 --- a/source/html/html-font.c +++ b/source/html/html-font.c @@ -1,8 +1,5 @@ #include "mupdf/html.h" -unsigned char *pdf_lookup_builtin_font(fz_context *ctx, const char *name, unsigned int *len); -unsigned char *pdf_lookup_substitute_cjk_font(fz_context *ctx, int ros, int serif, int wmode, unsigned int *len, int *index); - static const char *font_names[16] = { "Times-Roman", "Times-Italic", "Times-Bold", "Times-BoldItalic", @@ -14,16 +11,35 @@ static const char *font_names[16] = static fz_font * fz_load_html_fallback_font(fz_context *ctx, fz_html_font_set *set) { + fz_font *font; + + /* TODO: Use set->fallback[script] instead of font->fallback chain */ if (!set->fallback) { unsigned char *data; unsigned int size; - int index; + int script; - data = pdf_lookup_substitute_cjk_font(ctx, FZ_ADOBE_GB_1, 0, 0, &size, &index); + data = fz_lookup_noto_symbol_font(ctx, &size); if (data) - set->fallback = fz_new_font_from_memory(ctx, "fallback", data, size, index, 0); + { + font = fz_new_font_from_memory(ctx, NULL, data, size, 0, 0); + font->fallback = set->fallback; + set->fallback = font; + } + + for (script = UCDN_SCRIPT_LATIN; script < UCDN_SCRIPT_SIGNWRITING; ++script) + { + data = fz_lookup_noto_font(ctx, script, 1, &size); + if (data) + { + font = fz_new_font_from_memory(ctx, NULL, data, size, 0, 0); + font->fallback = set->fallback; + set->fallback = font; + } + } } + return set->fallback; } @@ -38,7 +54,7 @@ fz_load_html_builtin_font(fz_context *ctx, fz_html_font_set *set, const char *fa unsigned char *data; unsigned int size; - data = pdf_lookup_builtin_font(ctx, font_names[idx], &size); + data = fz_lookup_base14_font(ctx, font_names[idx], &size); if (!data) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot load html font: %s", font_names[idx]); set->fonts[idx] = fz_new_font_from_memory(ctx, font_names[idx], data, size, 0, 1); diff --git a/source/pdf/pdf-font.c b/source/pdf/pdf-font.c index 542393fc..41a4c279 100644 --- a/source/pdf/pdf-font.c +++ b/source/pdf/pdf-font.c @@ -37,6 +37,36 @@ static const char *base_font_names[][10] = { "ZapfDingbats", NULL } }; +unsigned char * +pdf_lookup_substitute_font(fz_context *ctx, int mono, int serif, int bold, int italic, unsigned int *len) +{ + if (mono) { + if (bold) { + if (italic) return fz_lookup_base14_font(ctx, "Courier-BoldOblique", len); + else return fz_lookup_base14_font(ctx, "Courier-Bold", len); + } else { + if (italic) return fz_lookup_base14_font(ctx, "Courier-Oblique", len); + else return fz_lookup_base14_font(ctx, "Courier", len); + } + } else if (serif) { + if (bold) { + if (italic) return fz_lookup_base14_font(ctx, "Times-BoldItalic", len); + else return fz_lookup_base14_font(ctx, "Times-Bold", len); + } else { + if (italic) return fz_lookup_base14_font(ctx, "Times-Italic", len); + else return fz_lookup_base14_font(ctx, "Times-Roman", len); + } + } else { + if (bold) { + if (italic) return fz_lookup_base14_font(ctx, "Helvetica-BoldOblique", len); + else return fz_lookup_base14_font(ctx, "Helvetica-Bold", len); + } else { + if (italic) return fz_lookup_base14_font(ctx, "Helvetica-Oblique", len); + else return fz_lookup_base14_font(ctx, "Helvetica", len); + } + } +} + static int is_dynalab(char *name) { if (strstr(name, "HuaTian")) @@ -184,7 +214,7 @@ pdf_load_builtin_font(fz_context *ctx, pdf_font_desc *fontdesc, char *fontname, unsigned char *data; unsigned int len; - data = pdf_lookup_builtin_font(ctx, clean_name, &len); + data = fz_lookup_base14_font(ctx, clean_name, &len); if (!data) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find builtin font: '%s'", fontname); @@ -231,7 +261,7 @@ pdf_load_substitute_cjk_font(fz_context *ctx, pdf_font_desc *fontdesc, char *fon unsigned int len; int index; - data = pdf_lookup_substitute_cjk_font(ctx, ros, serif, fontdesc->wmode, &len, &index); + data = fz_lookup_cjk_font(ctx, ros, serif, fontdesc->wmode, &len, &index); if (!data) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find builtin CJK font"); diff --git a/source/pdf/pdf-fontfile.c b/source/pdf/pdf-fontfile.c deleted file mode 100644 index 86b6682b..00000000 --- a/source/pdf/pdf-fontfile.c +++ /dev/null @@ -1,138 +0,0 @@ -#include "mupdf/pdf.h" - -/* - Which fonts are embedded is based on a few preprocessor definitions. - - The base 14 fonts are always embedded. - For CJK font substitution we embed DroidSansFallback. - - Set NOCJK to skip all CJK support (this also omits embedding the CJK CMaps) - Set NOCJKFONT to skip the embedded CJK font. - Set NOCJKFULL to embed a smaller CJK font without CJK Extension A support. -*/ - -#ifdef NOCJK -#define NOCJKFONT -#endif - -#include "gen_font_base14.h" - -#ifndef NOCJKFONT -#ifndef NOCJKFULL -#include "gen_font_cjk_full.h" -#else -#include "gen_font_cjk.h" -#endif -#endif - -unsigned char * -pdf_lookup_builtin_font(fz_context *ctx, const char *name, unsigned int *len) -{ - if (!strcmp("Courier", name)) { - *len = sizeof pdf_font_NimbusMono_Regular; - return (unsigned char*) pdf_font_NimbusMono_Regular; - } - if (!strcmp("Courier-Bold", name)) { - *len = sizeof pdf_font_NimbusMono_Bold; - return (unsigned char*) pdf_font_NimbusMono_Bold; - } - if (!strcmp("Courier-Oblique", name)) { - *len = sizeof pdf_font_NimbusMono_Oblique; - return (unsigned char*) pdf_font_NimbusMono_Oblique; - } - if (!strcmp("Courier-BoldOblique", name)) { - *len = sizeof pdf_font_NimbusMono_BoldOblique; - return (unsigned char*) pdf_font_NimbusMono_BoldOblique; - } - if (!strcmp("Helvetica", name)) { - *len = sizeof pdf_font_NimbusSanL_Reg; - return (unsigned char*) pdf_font_NimbusSanL_Reg; - } - if (!strcmp("Helvetica-Bold", name)) { - *len = sizeof pdf_font_NimbusSanL_Bol; - return (unsigned char*) pdf_font_NimbusSanL_Bol; - } - if (!strcmp("Helvetica-Oblique", name)) { - *len = sizeof pdf_font_NimbusSanL_RegIta; - return (unsigned char*) pdf_font_NimbusSanL_RegIta; - } - if (!strcmp("Helvetica-BoldOblique", name)) { - *len = sizeof pdf_font_NimbusSanL_BolIta; - return (unsigned char*) pdf_font_NimbusSanL_BolIta; - } - if (!strcmp("Times-Roman", name)) { - *len = sizeof pdf_font_NimbusRomNo9L_Reg; - return (unsigned char*) pdf_font_NimbusRomNo9L_Reg; - } - if (!strcmp("Times-Bold", name)) { - *len = sizeof pdf_font_NimbusRomNo9L_Med; - return (unsigned char*) pdf_font_NimbusRomNo9L_Med; - } - if (!strcmp("Times-Italic", name)) { - *len = sizeof pdf_font_NimbusRomNo9L_RegIta; - return (unsigned char*) pdf_font_NimbusRomNo9L_RegIta; - } - if (!strcmp("Times-BoldItalic", name)) { - *len = sizeof pdf_font_NimbusRomNo9L_MedIta; - return (unsigned char*) pdf_font_NimbusRomNo9L_MedIta; - } - if (!strcmp("Symbol", name)) { - *len = sizeof pdf_font_StandardSymL; - return (unsigned char*) pdf_font_StandardSymL; - } - if (!strcmp("ZapfDingbats", name)) { - *len = sizeof pdf_font_Dingbats; - return (unsigned char*) pdf_font_Dingbats; - } - *len = 0; - return NULL; -} - -unsigned char * -pdf_lookup_substitute_font(fz_context *ctx, int mono, int serif, int bold, int italic, unsigned int *len) -{ - if (mono) { - if (bold) { - if (italic) return pdf_lookup_builtin_font(ctx, "Courier-BoldOblique", len); - else return pdf_lookup_builtin_font(ctx, "Courier-Bold", len); - } else { - if (italic) return pdf_lookup_builtin_font(ctx, "Courier-Oblique", len); - else return pdf_lookup_builtin_font(ctx, "Courier", len); - } - } else if (serif) { - if (bold) { - if (italic) return pdf_lookup_builtin_font(ctx, "Times-BoldItalic", len); - else return pdf_lookup_builtin_font(ctx, "Times-Bold", len); - } else { - if (italic) return pdf_lookup_builtin_font(ctx, "Times-Italic", len); - else return pdf_lookup_builtin_font(ctx, "Times-Roman", len); - } - } else { - if (bold) { - if (italic) return pdf_lookup_builtin_font(ctx, "Helvetica-BoldOblique", len); - else return pdf_lookup_builtin_font(ctx, "Helvetica-Bold", len); - } else { - if (italic) return pdf_lookup_builtin_font(ctx, "Helvetica-Oblique", len); - else return pdf_lookup_builtin_font(ctx, "Helvetica", len); - } - } -} - -unsigned char * -pdf_lookup_substitute_cjk_font(fz_context *ctx, int ros, int serif, int wmode, unsigned int *len, int *index) -{ -#ifndef NOCJKFONT -#ifndef NOCJKFULL - *index = wmode; - *len = sizeof pdf_font_DroidSansFallbackFull; - return (unsigned char*) pdf_font_DroidSansFallbackFull; -#else - *index = wmode; - *len = sizeof pdf_font_DroidSansFallback; - return (unsigned char*) pdf_font_DroidSansFallback; -#endif -#else - *len = 0; - return NULL; -#endif -} |