2
0
mirror of https://github.com/koreader/koreader synced 2024-11-18 03:25:46 +00:00
koreader/mupdf.patch
2012-11-26 13:57:37 -05:00

170 lines
4.9 KiB
Diff

diff --git a/pdf/pdf_font.c b/pdf/pdf_font.c
index 33a1a65..c2fdee3 100644
--- a/pdf/pdf_font.c
+++ b/pdf/pdf_font.c
@@ -185,7 +185,12 @@ pdf_load_builtin_font(fz_context *ctx, pdf_font_desc *fontdesc, char *fontname)
if (!data)
fz_throw(ctx, "cannot find builtin font: '%s'", fontname);
+#ifndef NOBUILTINFONT
fontdesc->font = fz_new_font_from_memory(ctx, fontname, data, len, 0, 1);
+#else
+ fontdesc->font = fz_new_font_from_file(ctx, fontname, data, 0, 1);
+ free(data);
+#endif
if (!strcmp(fontname, "Symbol") || !strcmp(fontname, "ZapfDingbats"))
fontdesc->flags |= PDF_FD_SYMBOLIC;
@@ -201,7 +206,12 @@ pdf_load_substitute_font(fz_context *ctx, pdf_font_desc *fontdesc, char *fontnam
if (!data)
fz_throw(ctx, "cannot find substitute font");
+#ifndef NOBUILTINFONT
fontdesc->font = fz_new_font_from_memory(ctx, fontname, data, len, 0, 1);
+#else
+ fontdesc->font = fz_new_font_from_file(ctx, fontname, data, 0, 1);
+ free(data);
+#endif
fontdesc->font->ft_substitute = 1;
fontdesc->font->ft_bold = bold && !ft_is_bold(fontdesc->font->ft_face);
@@ -219,7 +229,12 @@ pdf_load_substitute_cjk_font(fz_context *ctx, pdf_font_desc *fontdesc, char *fon
fz_throw(ctx, "cannot find builtin CJK font");
/* a glyph bbox cache is too big for droid sans fallback (51k glyphs!) */
+#ifndef NOBUILTINFONT
fontdesc->font = fz_new_font_from_memory(ctx, fontname, data, len, 0, 0);
+#else
+ fontdesc->font = fz_new_font_from_file(ctx, fontname, data, 0, 1);
+ free(data);
+#endif
fontdesc->font->ft_substitute = 1;
}
diff --git a/pdf/pdf_fontfile.c b/pdf/pdf_fontfile.c
index 99565da..a91380f 100644
--- a/pdf/pdf_fontfile.c
+++ b/pdf/pdf_fontfile.c
@@ -15,6 +15,8 @@
Set NODROIDFONT to use the base 14 fonts as substitute fonts.
*/
+#ifndef NOBUILTINFONT
+
#ifdef NOCJK
#define NOCJKFONT
#endif
@@ -152,3 +154,112 @@ pdf_lookup_substitute_cjk_font(int ros, int serif, unsigned int *len)
return NULL;
#endif
}
+
+#else // NOBUILTINFONT
+
+unsigned char *
+get_font_file(char *name)
+{
+ char *fontdir;
+ char *filename;
+ int len;
+ fontdir = getenv("FONTDIR");
+ if(fontdir == NULL) {
+ fontdir = "./fonts";
+ }
+ len = strlen(fontdir) + strlen(name) + 2;
+ filename = malloc(len);
+ if(filename == NULL) {
+ return NULL;
+ }
+ snprintf(filename, len, "%s/%s", fontdir, name);
+ return filename;
+}
+
+unsigned char *
+pdf_lookup_builtin_font(char *name, unsigned int *len)
+{
+ *len = 0;
+ if (!strcmp("Courier", name)) {
+ return get_font_file("NimbusMonL-Regu.cff");
+ }
+ if (!strcmp("Courier-Bold", name)) {
+ return get_font_file("NimbusMonL-Bold.cff");
+ }
+ if (!strcmp("Courier-Oblique", name)) {
+ return get_font_file("NimbusMonL-ReguObli.cff");
+ }
+ if (!strcmp("Courier-BoldOblique", name)) {
+ return get_font_file("NimbusMonL-BoldObli.cff");
+ }
+ if (!strcmp("Helvetica", name)) {
+ return get_font_file("NimbusSanL-Regu.cff");
+ }
+ if (!strcmp("Helvetica-Bold", name)) {
+ return get_font_file("NimbusSanL-Bold.cff");
+ }
+ if (!strcmp("Helvetica-Oblique", name)) {
+ return get_font_file("NimbusSanL-ReguItal.cff");
+ }
+ if (!strcmp("Helvetica-BoldOblique", name)) {
+ return get_font_file("NimbusSanL-BoldItal.cff");
+ }
+ if (!strcmp("Times-Roman", name)) {
+ return get_font_file("NimbusRomNo9L-Regu.cff");
+ }
+ if (!strcmp("Times-Bold", name)) {
+ return get_font_file("NimbusRomNo9L-Medi.cff");
+ }
+ if (!strcmp("Times-Italic", name)) {
+ return get_font_file("NimbusRomNo9L-ReguItal.cff");
+ }
+ if (!strcmp("Times-BoldItalic", name)) {
+ return get_font_file("NimbusRomNo9L-MediItal.cff");
+ }
+ if (!strcmp("Symbol", name)) {
+ return get_font_file("StandardSymL.cff");
+ }
+ if (!strcmp("ZapfDingbats", name)) {
+ return get_font_file("Dingbats.cff");
+ }
+ return NULL;
+}
+
+unsigned char *
+pdf_lookup_substitute_font(int mono, int serif, int bold, int italic, unsigned int *len)
+{
+ if (mono) {
+ if (bold) {
+ if (italic) return pdf_lookup_builtin_font("Courier-BoldOblique", len);
+ else return pdf_lookup_builtin_font("Courier-Bold", len);
+ } else {
+ if (italic) return pdf_lookup_builtin_font("Courier-Oblique", len);
+ else return pdf_lookup_builtin_font("Courier", len);
+ }
+ } else if (serif) {
+ if (bold) {
+ if (italic) return pdf_lookup_builtin_font("Times-BoldItalic", len);
+ else return pdf_lookup_builtin_font("Times-Bold", len);
+ } else {
+ if (italic) return pdf_lookup_builtin_font("Times-Italic", len);
+ else return pdf_lookup_builtin_font("Times-Roman", len);
+ }
+ } else {
+ if (bold) {
+ if (italic) return pdf_lookup_builtin_font("Helvetica-BoldOblique", len);
+ else return pdf_lookup_builtin_font("Helvetica-Bold", len);
+ } else {
+ if (italic) return pdf_lookup_builtin_font("Helvetica-Oblique", len);
+ else return pdf_lookup_builtin_font("Helvetica", len);
+ }
+ }
+}
+
+unsigned char *
+pdf_lookup_substitute_cjk_font(int ros, int serif, unsigned int *len)
+{
+ *len = 0;
+ return get_font_file("droid/DroidSansFallback.ttf");
+}
+
+#endif // NOBUILTINFONT