2
0
mirror of https://github.com/koreader/koreader synced 2024-10-31 21:20:20 +00:00
koreader/mupdf.patch

170 lines
4.9 KiB
Diff
Raw Normal View History

diff --git a/pdf/pdf_font.c b/pdf/pdf_font.c
2012-11-03 16:15:12 +00:00
index 33a1a65..c2fdee3 100644
--- a/pdf/pdf_font.c
+++ b/pdf/pdf_font.c
2012-11-03 16:15:12 +00:00
@@ -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);
2012-11-03 16:15:12 +00:00
+#ifndef NOBUILTINFONT
2012-11-03 16:15:12 +00:00
fontdesc->font = fz_new_font_from_memory(ctx, fontname, data, len, 0, 1);
+#else
2012-11-03 16:15:12 +00:00
+ fontdesc->font = fz_new_font_from_file(ctx, fontname, data, 0, 1);
+ free(data);
+#endif
2012-11-03 16:15:12 +00:00
if (!strcmp(fontname, "Symbol") || !strcmp(fontname, "ZapfDingbats"))
fontdesc->flags |= PDF_FD_SYMBOLIC;
2012-11-03 16:15:12 +00:00
@@ -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");
2012-11-03 16:15:12 +00:00
+#ifndef NOBUILTINFONT
2012-11-03 16:15:12 +00:00
fontdesc->font = fz_new_font_from_memory(ctx, fontname, data, len, 0, 1);
+#else
2012-11-03 16:15:12 +00:00
+ fontdesc->font = fz_new_font_from_file(ctx, fontname, data, 0, 1);
+ free(data);
+#endif
2012-11-03 16:15:12 +00:00
fontdesc->font->ft_substitute = 1;
fontdesc->font->ft_bold = bold && !ft_is_bold(fontdesc->font->ft_face);
2012-11-03 16:15:12 +00:00
@@ -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");
2012-11-03 16:15:12 +00:00
/* a glyph bbox cache is too big for droid sans fallback (51k glyphs!) */
+#ifndef NOBUILTINFONT
2012-11-03 16:15:12 +00:00
fontdesc->font = fz_new_font_from_memory(ctx, fontname, data, len, 0, 0);
+#else
2012-11-03 16:15:12 +00:00
+ fontdesc->font = fz_new_font_from_file(ctx, fontname, data, 0, 1);
+ free(data);
+#endif
2012-11-03 16:15:12 +00:00
fontdesc->font->ft_substitute = 1;
2012-11-03 16:15:12 +00:00
}
diff --git a/pdf/pdf_fontfile.c b/pdf/pdf_fontfile.c
2012-11-03 16:15:12 +00:00
index 99565da..a91380f 100644
--- a/pdf/pdf_fontfile.c
+++ b/pdf/pdf_fontfile.c
2012-11-03 16:15:12 +00:00
@@ -15,6 +15,8 @@
Set NODROIDFONT to use the base 14 fonts as substitute fonts.
*/
+#ifndef NOBUILTINFONT
+
#ifdef NOCJK
#define NOCJKFONT
#endif
2012-11-03 16:15:12 +00:00
@@ -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