summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile5
-rw-r--r--fitz/fitz.h2
-rw-r--r--fitz/res_font.c13
-rw-r--r--fonts/droid/DroidSans.ttfbin0 -> 190044 bytes
-rw-r--r--pdf/mupdf.h3
-rw-r--r--pdf/pdf_font.c109
-rw-r--r--pdf/pdf_fontfile.c41
-rw-r--r--win32/generate.bat2
8 files changed, 98 insertions, 77 deletions
diff --git a/Makefile b/Makefile
index bea67d58..38b49c5a 100644
--- a/Makefile
+++ b/Makefile
@@ -84,6 +84,7 @@ CMAP_GB_SRC := $(wildcard cmaps/gb/*)
CMAP_JAPAN_SRC := $(wildcard cmaps/japan/*)
CMAP_KOREA_SRC := $(wildcard cmaps/korea/*)
FONT_BASE14_SRC := $(wildcard fonts/*.cff)
+FONT_DROID_SRC := fonts/droid/DroidSans.ttf
FONT_CJK_SRC := fonts/droid/DroidSansFallback.ttf
$(GEN)/cmap_cns.h : $(CMAP_CNS_SRC)
@@ -97,11 +98,13 @@ $(GEN)/cmap_korea.h : $(CMAP_KOREA_SRC)
$(GEN)/font_base14.h : $(FONT_BASE14_SRC)
$(QUIET_GEN) ./$(FONTDUMP) $@ $(FONT_BASE14_SRC)
+$(GEN)/font_droid.h : $(FONT_DROID_SRC)
+ $(QUIET_GEN) ./$(FONTDUMP) $@ $(FONT_DROID_SRC)
$(GEN)/font_cjk.h : $(FONT_CJK_SRC)
$(QUIET_GEN) ./$(FONTDUMP) $@ $(FONT_CJK_SRC)
CMAP_HDR := $(addprefix $(GEN)/, cmap_cns.h cmap_gb.h cmap_japan.h cmap_korea.h)
-FONT_HDR := $(GEN)/font_base14.h $(GEN)/font_cjk.h
+FONT_HDR := $(GEN)/font_base14.h $(GEN)/font_droid.h $(GEN)/font_cjk.h
$(CMAP_HDR) : $(CMAPDUMP) | $(GEN)
$(FONT_HDR) : $(FONTDUMP) | $(GEN)
diff --git a/fitz/fitz.h b/fitz/fitz.h
index 7f35c417..3e08a680 100644
--- a/fitz/fitz.h
+++ b/fitz/fitz.h
@@ -715,6 +715,8 @@ struct fz_font_s
void *ft_face; /* has an FT_Face if used */
int ft_substitute; /* ... substitute metrics */
+ int ft_bold; /* ... synthesize bold */
+ int ft_italic; /* ... synthesize italic */
int ft_hint; /* ... force hinting for DynaLab fonts */
/* origin of font data */
diff --git a/fitz/res_font.c b/fitz/res_font.c
index fdcfb77b..b564b45b 100644
--- a/fitz/res_font.c
+++ b/fitz/res_font.c
@@ -7,16 +7,18 @@
static void fz_finalize_freetype(void);
static fz_font *
-fz_new_font(void)
+fz_new_font(char *name)
{
fz_font *font;
font = fz_malloc(sizeof(fz_font));
font->refs = 1;
- strcpy(font->name, "<unknown>");
+ fz_strlcpy(font->name, name, sizeof font->name);
font->ft_face = NULL;
font->ft_substitute = 0;
+ font->ft_bold = 0;
+ font->ft_italic = 0;
font->ft_hint = 0;
font->ft_file = NULL;
@@ -189,7 +191,7 @@ fz_new_font_from_file(fz_font **fontp, char *path, int index)
if (fterr)
return fz_throw("freetype: cannot load font: %s", ft_error_string(fterr));
- font = fz_new_font();
+ font = fz_new_font(face->family_name);
font->ft_face = face;
font->bbox.x0 = face->bbox.xMin * 1000 / face->units_per_EM;
font->bbox.y0 = face->bbox.yMin * 1000 / face->units_per_EM;
@@ -216,7 +218,7 @@ fz_new_font_from_memory(fz_font **fontp, unsigned char *data, int len, int index
if (fterr)
return fz_throw("freetype: cannot load font: %s", ft_error_string(fterr));
- font = fz_new_font();
+ font = fz_new_font(face->family_name);
font->ft_face = face;
font->bbox.x0 = face->bbox.xMin * 1000 / face->units_per_EM;
font->bbox.y0 = face->bbox.yMin * 1000 / face->units_per_EM;
@@ -478,11 +480,10 @@ fz_new_type3_font(char *name, fz_matrix matrix)
fz_font *font;
int i;
- font = fz_new_font();
+ font = fz_new_font(name);
font->t3procs = fz_calloc(256, sizeof(fz_buffer*));
font->t3widths = fz_calloc(256, sizeof(float));
- fz_strlcpy(font->name, name, sizeof(font->name));
font->t3matrix = matrix;
for (i = 0; i < 256; i++)
{
diff --git a/fonts/droid/DroidSans.ttf b/fonts/droid/DroidSans.ttf
new file mode 100644
index 00000000..767c63ad
--- /dev/null
+++ b/fonts/droid/DroidSans.ttf
Binary files differ
diff --git a/pdf/mupdf.h b/pdf/mupdf.h
index d9d6355d..30032798 100644
--- a/pdf/mupdf.h
+++ b/pdf/mupdf.h
@@ -388,7 +388,8 @@ fz_error pdf_load_to_unicode(pdf_font_desc *font, pdf_xref *xref, char **strings
int pdf_font_cid_to_gid(pdf_font_desc *fontdesc, int cid);
unsigned char *pdf_find_builtin_font(char *name, unsigned int *len);
-unsigned char *pdf_find_builtin_cjk_font(int ros, int gothic, unsigned int *len);
+unsigned char *pdf_find_substitute_font(int mono, int serif, int bold, int italic, unsigned int *len);
+unsigned char *pdf_find_substitute_cjk_font(int ros, int serif, unsigned int *len);
fz_error pdf_load_type3_font(pdf_font_desc **fontp, pdf_xref *xref, fz_obj *rdb, fz_obj *obj);
fz_error pdf_load_font(pdf_font_desc **fontp, pdf_xref *xref, fz_obj *rdb, fz_obj *obj);
diff --git a/pdf/pdf_font.c b/pdf/pdf_font.c
index fc3d42fe..d0a67b31 100644
--- a/pdf/pdf_font.c
+++ b/pdf/pdf_font.c
@@ -169,14 +169,12 @@ pdf_load_builtin_font(pdf_font_desc *fontdesc, char *fontname)
data = pdf_find_builtin_font(fontname, &len);
if (!data)
- return fz_throw("cannot find font: '%s'", fontname);
+ return fz_throw("cannot find builtin font: '%s'", fontname);
error = fz_new_font_from_memory(&fontdesc->font, data, len, 0);
if (error)
return fz_rethrow(error, "cannot load freetype font from memory");
- fz_strlcpy(fontdesc->font->name, fontname, sizeof fontdesc->font->name);
-
if (!strcmp(fontname, "Symbol") || !strcmp(fontname, "ZapfDingbats"))
fontdesc->flags |= PDF_FD_SYMBOLIC;
@@ -184,13 +182,34 @@ pdf_load_builtin_font(pdf_font_desc *fontdesc, char *fontname)
}
static fz_error
-pdf_load_builtin_cjk_font(pdf_font_desc *fontdesc, int ros, int gothic)
+pdf_load_substitute_font(pdf_font_desc *fontdesc, int mono, int serif, int bold, int italic)
{
fz_error error;
unsigned char *data;
unsigned int len;
- data = pdf_find_builtin_cjk_font(ros, gothic, &len);
+ data = pdf_find_substitute_font(mono, serif, bold, italic, &len);
+ if (!data)
+ return fz_throw("cannot find substitute font");
+
+ error = fz_new_font_from_memory(&fontdesc->font, data, len, 0);
+ if (error)
+ return fz_rethrow(error, "cannot load freetype font from memory");
+
+ fontdesc->font->ft_substitute = 1;
+ fontdesc->font->ft_bold = bold;
+ fontdesc->font->ft_italic = italic;
+ return fz_okay;
+}
+
+static fz_error
+pdf_load_substitute_cjk_font(pdf_font_desc *fontdesc, int ros, int serif)
+{
+ fz_error error;
+ unsigned char *data;
+ unsigned int len;
+
+ data = pdf_find_substitute_cjk_font(ros, serif, &len);
if (!data)
return fz_throw("cannot find builtin CJK font");
@@ -206,89 +225,43 @@ static fz_error
pdf_load_system_font(pdf_font_desc *fontdesc, char *fontname, char *collection)
{
fz_error error;
- char *name;
-
- int isbold = 0;
- int isitalic = 0;
- int isserif = 0;
- int isscript = 0;
- int isfixed = 0;
+ int bold = 0;
+ int italic = 0;
+ int serif = 0;
+ int mono = 0;
if (strstr(fontname, "Bold"))
- isbold = 1;
+ bold = 1;
if (strstr(fontname, "Italic"))
- isitalic = 1;
+ italic = 1;
if (strstr(fontname, "Oblique"))
- isitalic = 1;
+ italic = 1;
if (fontdesc->flags & PDF_FD_FIXED_PITCH)
- isfixed = 1;
+ mono = 1;
if (fontdesc->flags & PDF_FD_SERIF)
- isserif = 1;
+ serif = 1;
if (fontdesc->flags & PDF_FD_ITALIC)
- isitalic = 1;
- if (fontdesc->flags & PDF_FD_SCRIPT)
- isscript = 1;
+ italic = 1;
if (fontdesc->flags & PDF_FD_FORCE_BOLD)
- isbold = 1;
+ bold = 1;
if (collection)
{
if (!strcmp(collection, "Adobe-CNS1"))
- return pdf_load_builtin_cjk_font(fontdesc, PDF_ROS_CNS, !isserif);
+ return pdf_load_substitute_cjk_font(fontdesc, PDF_ROS_CNS, serif);
else if (!strcmp(collection, "Adobe-GB1"))
- return pdf_load_builtin_cjk_font(fontdesc, PDF_ROS_GB, !isserif);
+ return pdf_load_substitute_cjk_font(fontdesc, PDF_ROS_GB, serif);
else if (!strcmp(collection, "Adobe-Japan1"))
- return pdf_load_builtin_cjk_font(fontdesc, PDF_ROS_JAPAN, !isserif);
- else if (!strcmp(collection, "Adobe-Japan2"))
- return pdf_load_builtin_cjk_font(fontdesc, PDF_ROS_JAPAN, !isserif);
+ return pdf_load_substitute_cjk_font(fontdesc, PDF_ROS_JAPAN, serif);
else if (!strcmp(collection, "Adobe-Korea1"))
- return pdf_load_builtin_cjk_font(fontdesc, PDF_ROS_KOREA, !isserif);
+ return pdf_load_substitute_cjk_font(fontdesc, PDF_ROS_KOREA, serif);
return fz_throw("unknown cid collection: %s", collection);
}
- else if (isfixed)
- {
- if (isitalic) {
- if (isbold) name = "Courier-BoldOblique";
- else name = "Courier-Oblique";
- }
- else {
- if (isbold) name = "Courier-Bold";
- else name = "Courier";
- }
- }
-
- else if (isserif)
- {
- if (isitalic) {
- if (isbold) name = "Times-BoldItalic";
- else name = "Times-Italic";
- }
- else {
- if (isbold) name = "Times-Bold";
- else name = "Times-Roman";
- }
- }
-
- else
- {
- if (isitalic) {
- if (isbold) name = "Helvetica-BoldOblique";
- else name = "Helvetica-Oblique";
- }
- else {
- if (isbold) name = "Helvetica-Bold";
- else name = "Helvetica";
- }
- }
-
- error = pdf_load_builtin_font(fontdesc, name);
+ error = pdf_load_substitute_font(fontdesc, mono, serif, bold, italic);
if (error)
- return fz_throw("cannot load builtin substitute font: %s", name);
-
- /* it's a substitute font: override the metrics */
- fontdesc->font->ft_substitute = 1;
+ return fz_throw("cannot load substitute font");
return fz_okay;
}
diff --git a/pdf/pdf_fontfile.c b/pdf/pdf_fontfile.c
index 59a30594..55f883f1 100644
--- a/pdf/pdf_fontfile.c
+++ b/pdf/pdf_fontfile.c
@@ -7,6 +7,10 @@
#include "../generated/font_base14.h"
+#ifndef NODROIDFONT
+#include "../generated/font_droid.h"
+#endif
+
#ifndef NOCJKFONT
#include "../generated/font_cjk.h"
#endif
@@ -83,7 +87,42 @@ pdf_find_builtin_font(char *name, unsigned int *len)
}
unsigned char *
-pdf_find_builtin_cjk_font(int ros, int gothic, unsigned int *len)
+pdf_find_substitute_font(int mono, int serif, int bold, int italic, unsigned int *len)
+{
+#ifdef NODROIDFONT
+ if (mono) {
+ if (bold) {
+ if (italic) return pdf_find_builtin_font("Courier-BoldOblique", len);
+ else return pdf_find_builtin_font("Courier-Bold", len);
+ } else {
+ if (italic) return pdf_find_builtin_font("Courier-Oblique", len);
+ else return pdf_find_builtin_font("Courier", len);
+ }
+ } else if (serif) {
+ if (bold) {
+ if (italic) return pdf_find_builtin_font("Times-BoldItalic", len);
+ else return pdf_find_builtin_font("Times-Bold", len);
+ } else {
+ if (italic) return pdf_find_builtin_font("Times-Italic", len);
+ else return pdf_find_builtin_font("Times-Roman", len);
+ }
+ } else {
+ if (bold) {
+ if (italic) return pdf_find_builtin_font("Helvetica-BoldOblique", len);
+ else return pdf_find_builtin_font("Helvetica-Bold", len);
+ } else {
+ if (italic) return pdf_find_builtin_font("Helvetica-Oblique", len);
+ else return pdf_find_builtin_font("Helvetica", len);
+ }
+ }
+#else
+ *len = sizeof pdf_font_DroidSans;
+ return (unsigned char*) pdf_font_DroidSans;
+#endif
+}
+
+unsigned char *
+pdf_find_substitute_cjk_font(int ros, int serif, unsigned int *len)
{
#ifndef NOCJKFONT
*len = sizeof pdf_font_DroidSansFallback;
diff --git a/win32/generate.bat b/win32/generate.bat
index c9db9393..9ca71eb6 100644
--- a/win32/generate.bat
+++ b/win32/generate.bat
@@ -11,6 +11,8 @@ if not exist cmapdump.exe goto usage
if not exist generated/font_base14.h fontdump.exe generated/font_base14.h fonts/Dingbats.cff fonts/NimbusMonL-Bold.cff fonts/NimbusMonL-BoldObli.cff fonts/NimbusMonL-Regu.cff fonts/NimbusMonL-ReguObli.cff fonts/NimbusRomNo9L-Medi.cff fonts/NimbusRomNo9L-MediItal.cff fonts/NimbusRomNo9L-Regu.cff fonts/NimbusRomNo9L-ReguItal.cff fonts/NimbusSanL-Bold.cff fonts/NimbusSanL-BoldItal.cff fonts/NimbusSanL-Regu.cff fonts/NimbusSanL-ReguItal.cff fonts/StandardSymL.cff
+if not exist generated/font_droid.h fontdump.exe generated/font_droid.h fonts/droid/DroidSans.ttf
+
if not exist generated/font_cjk.h fontdump.exe generated/font_cjk.h fonts/droid/DroidSansFallback.ttf
if not exist generated/cmap_cns.h cmapdump.exe generated/cmap_cns.h cmaps/cns/Adobe-CNS1-UCS2 cmaps/cns/Adobe-CNS1-0 cmaps/cns/Adobe-CNS1-1 cmaps/cns/Adobe-CNS1-2 cmaps/cns/Adobe-CNS1-3 cmaps/cns/Adobe-CNS1-4 cmaps/cns/Adobe-CNS1-5 cmaps/cns/Adobe-CNS1-6 cmaps/cns/B5-H cmaps/cns/B5-V cmaps/cns/B5pc-H cmaps/cns/B5pc-V cmaps/cns/CNS-EUC-H cmaps/cns/CNS-EUC-V cmaps/cns/CNS1-H cmaps/cns/CNS1-V cmaps/cns/CNS2-H cmaps/cns/CNS2-V cmaps/cns/ETen-B5-H cmaps/cns/ETen-B5-V cmaps/cns/ETenms-B5-H cmaps/cns/ETenms-B5-V cmaps/cns/ETHK-B5-H cmaps/cns/ETHK-B5-V cmaps/cns/HKdla-B5-H cmaps/cns/HKdla-B5-V cmaps/cns/HKdlb-B5-H cmaps/cns/HKdlb-B5-V cmaps/cns/HKgccs-B5-H cmaps/cns/HKgccs-B5-V cmaps/cns/HKm314-B5-H cmaps/cns/HKm314-B5-V cmaps/cns/HKm471-B5-H cmaps/cns/HKm471-B5-V cmaps/cns/HKscs-B5-H cmaps/cns/HKscs-B5-V cmaps/cns/UniCNS-UCS2-H cmaps/cns/UniCNS-UCS2-V cmaps/cns/UniCNS-UTF16-H cmaps/cns/UniCNS-UTF16-V