summaryrefslogtreecommitdiff
path: root/source/fitz
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2016-03-22 13:24:23 +0100
committerTor Andersson <tor.andersson@artifex.com>2016-03-23 15:58:47 +0100
commitb2c3d9e7ca40e001d3ee18975427224b726dc4d1 (patch)
treed113ff85ce07dbd81ae45f8f18b303e8787d26cf /source/fitz
parent81109bf17aada37f678b6adbdb9fa8eca1cd3163 (diff)
downloadmupdf-b2c3d9e7ca40e001d3ee18975427224b726dc4d1.tar.xz
Compile embedded fonts in separate C files.
Also change unsigned char into const char for embedded data.
Diffstat (limited to 'source/fitz')
-rw-r--r--source/fitz/buffer.c4
-rw-r--r--source/fitz/font.c14
-rw-r--r--source/fitz/noto.c175
3 files changed, 69 insertions, 124 deletions
diff --git a/source/fitz/buffer.c b/source/fitz/buffer.c
index d1609ef1..6f0e7057 100644
--- a/source/fitz/buffer.c
+++ b/source/fitz/buffer.c
@@ -41,13 +41,13 @@ fz_new_buffer_from_data(fz_context *ctx, unsigned char *data, int size)
}
fz_buffer *
-fz_new_buffer_from_shared_data(fz_context *ctx, unsigned char *data, int size)
+fz_new_buffer_from_shared_data(fz_context *ctx, const char *data, int size)
{
fz_buffer *b;
b = fz_malloc_struct(ctx, fz_buffer);
b->refs = 1;
- b->data = data;
+ b->data = (unsigned char *)data; /* cast away const */
b->cap = size;
b->len = size;
b->unused_bits = 0;
diff --git a/source/fitz/font.c b/source/fitz/font.c
index 56cfecbf..385803ea 100644
--- a/source/fitz/font.c
+++ b/source/fitz/font.c
@@ -290,8 +290,8 @@ fz_font *fz_load_system_cjk_font(fz_context *ctx, const char *name, int ros, int
fz_font *fz_load_fallback_font(fz_context *ctx, int script, int serif, int bold, int italic)
{
- unsigned char *data;
- unsigned int size;
+ const char *data;
+ int size;
if (script < 0 || script > nelem(ctx->font->fallback))
return NULL;
@@ -324,8 +324,8 @@ fz_font *fz_load_fallback_font(fz_context *ctx, int script, int serif, int bold,
fz_font *fz_load_fallback_symbol_font(fz_context *ctx)
{
- unsigned char *data;
- unsigned int size;
+ const char *data;
+ int size;
if (!ctx->font->symbol)
{
data = fz_lookup_noto_symbol_font(ctx, &size);
@@ -337,8 +337,8 @@ fz_font *fz_load_fallback_symbol_font(fz_context *ctx)
fz_font *fz_load_fallback_emoji_font(fz_context *ctx)
{
- unsigned char *data;
- unsigned int size;
+ const char *data;
+ int size;
if (!ctx->font->emoji)
{
data = fz_lookup_noto_emoji_font(ctx, &size);
@@ -463,7 +463,7 @@ fz_new_font_from_buffer(fz_context *ctx, const char *name, fz_buffer *buffer, in
}
fz_font *
-fz_new_font_from_memory(fz_context *ctx, const char *name, unsigned char *data, int len, int index, int use_glyph_bbox)
+fz_new_font_from_memory(fz_context *ctx, const char *name, const char *data, int len, int index, int use_glyph_bbox)
{
fz_buffer *buffer = fz_new_buffer_from_shared_data(ctx, data, len);
fz_font *font;
diff --git a/source/fitz/noto.c b/source/fitz/noto.c
index f02bc524..681a67da 100644
--- a/source/fitz/noto.c
+++ b/source/fitz/noto.c
@@ -22,8 +22,6 @@
#define TOFU_SYMBOL
#endif
-#include "gen_font_base14.h"
-
#ifdef NOCJK
#define TOFU_CJK
#endif
@@ -34,120 +32,70 @@
#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
+#define DEC_FONT(NAME) \
+ extern const int fz_font_ ## NAME ## _size; \
+ extern const char fz_font_ ## NAME []
-#ifndef TOFU
-#include "gen_font_noto.h"
-#endif
+#define RET_FONT(NAME) \
+ return *size = fz_font_ ## NAME ## _size, fz_font_ ## NAME
+
+#define BASE14(NAME, FONT) \
+ DEC_FONT(FONT); if (!strcmp(NAME, name)) RET_FONT(FONT)
-unsigned char *
-fz_lookup_base14_font(fz_context *ctx, const char *name, unsigned int *len)
+const char *
+fz_lookup_base14_font(fz_context *ctx, const char *name, int *size)
{
- 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;
+ BASE14("Courier", NimbusMono_Regular_cff);
+ BASE14("Courier-Bold", NimbusMono_Bold_cff);
+ BASE14("Courier-Oblique", NimbusMono_Oblique_cff);
+ BASE14("Courier-BoldOblique", NimbusMono_BoldOblique_cff);
+ BASE14("Helvetica", NimbusSanL_Reg_cff);
+ BASE14("Helvetica-Bold", NimbusSanL_Bol_cff);
+ BASE14("Helvetica-Oblique", NimbusSanL_RegIta_cff);
+ BASE14("Helvetica-BoldOblique", NimbusSanL_BolIta_cff);
+ BASE14("Times-Roman", NimbusRomNo9L_Reg_cff);
+ BASE14("Times-Bold", NimbusRomNo9L_Med_cff);
+ BASE14("Times-Italic", NimbusRomNo9L_RegIta_cff);
+ BASE14("Times-BoldItalic", NimbusRomNo9L_MedIta_cff);
+ BASE14("Symbol", StandardSymL_cff);
+ BASE14("ZapfDingbats", Dingbats_cff);
+ return *size = 0, NULL;
}
-unsigned char *
-fz_lookup_cjk_font(fz_context *ctx, int registry, int serif, int wmode, unsigned int *len, int *index)
+const char *
+fz_lookup_cjk_font(fz_context *ctx, int registry, int serif, int wmode, int *size, int *index)
{
+ if (index) *index = wmode;
#ifndef TOFU_CJK
#ifndef TOFU_CJK_EXT
- if (index) *index = wmode;
- *len = sizeof fz_font_DroidSansFallbackFull;
- return (unsigned char*) fz_font_DroidSansFallbackFull;
+ DEC_FONT(DroidSansFallbackFull_ttc);
+ RET_FONT(DroidSansFallbackFull_ttc);
#else
- if (index) *index = wmode;
- *len = sizeof fz_font_DroidSansFallback;
- return (unsigned char*) fz_font_DroidSansFallback;
+ DEC_FONT(DroidSansFallback_ttc);
+ RET_FONT(DroidSansFallback_ttc);
#endif
#else
- *len = 0;
- return NULL;
+ return *size = 0, NULL;
#endif
}
-#define Noto(SANS) \
- *len = sizeof fz_font_Noto ## SANS ## _Regular; \
- return (unsigned char*) fz_font_Noto ## SANS ## _Regular; \
- break
+#define Noto(SANS) { \
+ DEC_FONT(Noto ## SANS ## _Regular_ttf); \
+ RET_FONT(Noto ## SANS ## _Regular_ttf); \
+ } 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 Noto2(SANS,SERIF) { \
+ DEC_FONT(Noto ## SANS ## _Regular_ttf); \
+ DEC_FONT(Noto ## SERIF ## _Regular_ttf); \
+ if (serif) RET_FONT(Noto ## SERIF ## _Regular_ttf); \
+ else RET_FONT(Noto ## SANS ## _Regular_ttf); \
+ } 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)
+const char *
+fz_lookup_noto_font(fz_context *ctx, int script, int serif, int *size)
{
/* Unused Noto fonts: NastaliqUrdu, SansSyriacEstrangela */
@@ -160,14 +108,14 @@ fz_lookup_noto_font(fz_context *ctx, int script, int serif, unsigned int *len)
break;
case UCDN_SCRIPT_HANGUL:
- return fz_lookup_cjk_font(ctx, FZ_ADOBE_KOREA_1, serif, 0, len, NULL);
+ return fz_lookup_cjk_font(ctx, FZ_ADOBE_KOREA_1, serif, 0, size, NULL);
case UCDN_SCRIPT_HIRAGANA:
case UCDN_SCRIPT_KATAKANA:
- return fz_lookup_cjk_font(ctx, FZ_ADOBE_JAPAN_1, serif, 0, len, NULL);
+ return fz_lookup_cjk_font(ctx, FZ_ADOBE_JAPAN_1, serif, 0, size, NULL);
case UCDN_SCRIPT_BOPOMOFO:
- return fz_lookup_cjk_font(ctx, FZ_ADOBE_GB_1, serif, 0, len, NULL);
+ return fz_lookup_cjk_font(ctx, FZ_ADOBE_GB_1, serif, 0, size, NULL);
case UCDN_SCRIPT_HAN:
- return fz_lookup_cjk_font(ctx, FZ_ADOBE_GB_1, serif, 0, len, NULL);
+ return fz_lookup_cjk_font(ctx, FZ_ADOBE_GB_1, serif, 0, size, NULL);
#ifndef TOFU
@@ -306,30 +254,27 @@ fz_lookup_noto_font(fz_context *ctx, int script, int serif, unsigned int *len)
#endif
}
- *len = 0;
- return NULL;
+ return *size = 0, NULL;
}
-unsigned char *
-fz_lookup_noto_symbol_font(fz_context *ctx, unsigned int *len)
+const char *
+fz_lookup_noto_symbol_font(fz_context *ctx, int *size)
{
#ifndef TOFU_SYMBOL
- *len = sizeof fz_font_NotoSansSymbols_Regular;
- return (unsigned char*) fz_font_NotoSansSymbols_Regular;
+ DEC_FONT(NotoSansSymbols_Regular_ttf);
+ RET_FONT(NotoSansSymbols_Regular_ttf);
#else
- *len = 0;
- return NULL;
+ return *size = 0, NULL;
#endif
}
-unsigned char *
-fz_lookup_noto_emoji_font(fz_context *ctx, unsigned int *len)
+const char *
+fz_lookup_noto_emoji_font(fz_context *ctx, int *size)
{
#ifndef TOFU_EMOJI
- *len = sizeof fz_font_NotoEmoji_Regular;
- return (unsigned char*) fz_font_NotoEmoji_Regular;
+ DEC_FONT(NotoEmoji_Regular_ttf);
+ RET_FONT(NotoEmoji_Regular_ttf);
#else
- *len = 0;
- return NULL;
+ return *size = 0, NULL;
#endif
}