Skip to content

Commit

Permalink
Create a new subset font with box drawing characters from NimbusMono.
Browse files Browse the repository at this point in the history
Use this as a fallback font for the U+2500 and U+2600 unicode blocks.
  • Loading branch information
ccxvii committed Oct 9, 2023
1 parent a598c5f commit 2569560
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/mupdf/fitz/font.h
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ const unsigned char *fz_lookup_noto_music_font(fz_context *ctx, int *len);
const unsigned char *fz_lookup_noto_symbol1_font(fz_context *ctx, int *len);
const unsigned char *fz_lookup_noto_symbol2_font(fz_context *ctx, int *len);
const unsigned char *fz_lookup_noto_emoji_font(fz_context *ctx, int *len);
const unsigned char *fz_lookup_noto_boxes_font(fz_context *ctx, int *len);

/**
Try to load a fallback font for the
Expand Down
Binary file added resources/fonts/urw/NimbusBoxes-Regular.cff
Binary file not shown.
Binary file added resources/fonts/urw/input/NimbusBoxes.t1
Binary file not shown.
1 change: 1 addition & 0 deletions resources/fonts/urw/subset.box
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SF100000,SF110000,SF010000,SF030000,SF020000,SF040000,SF080000,SF090000,SF060000,SF070000,SF050000,SF430000,SF240000,SF510000,SF520000,SF390000,SF220000,SF210000,SF250000,SF500000,SF490000,SF380000,SF280000,SF270000,SF260000,SF360000,SF370000,SF420000,SF190000,SF200000,SF230000,SF470000,SF480000,SF410000,SF450000,SF460000,SF400000,SF540000,SF530000,SF440000,upblock,dnblock,block,lfblock,rtblock,ltshade,shadelight,shade,shademedium,dkshade,shadedark,blacksquare,filledbox,H22073,whitesquare,squarewhitewithsmallblack,squarehorizontalfill,squareverticalfill,squareorthogonalcrosshatchfill,squareupperlefttolowerrightfill,squareupperrighttolowerleftfill,squarediagonalcrosshatchfill,H18543,blacksmallsquare,H18551,whitesmallsquare,blackrectangle,filledrect,blackuppointingtriangle,triagup,whiteuppointingtriangle,blackuppointingsmalltriangle,whiteuppointingsmalltriangle,blackrightpointingtriangle,whiterightpointingtriangle,whiterightpointingsmalltriangle,blackrightpointingpointer,triagrt,blackdownpointingtriangle,triagdn,whitedownpointingtriangle,whitedownpointingsmalltriangle,blackleftpointingtriangle,whiteleftpointingtriangle,whiteleftpointingsmalltriangle,blackleftpointingpointer,triaglf,blackdiamond,whitediamond,whitediamondcontainingblacksmalldiamond,fisheye,lozenge,circle,whitecircle,dottedcircle,bullseye,H18533,blackcircle,circlewithlefthalfblack,circlewithrighthalfblack,bulletinverse,invbullet,invcircle,whitecircleinverse,blacklowerrighttriangle,blacklowerlefttriangle,blackupperlefttriangle,blackupperrighttriangle,openbullet,whitebullet,largecircle,blackstar,whitestar,telephoneblack,whitetelephone,pointingindexleftwhite,pointingindexupwhite,pointingindexrightwhite,pointingindexdownwhite,yinyang,smileface,whitesmilingface,blacksmilingface,invsmileface,compass,sun,female,venus,earth,male,mars,spade,spadesuitblack,heartsuitwhite,diamondsuitwhite,club,clubsuitblack,spadesuitwhite,heart,heartsuitblack,diamond,clubsuitwhite,hotsprings,quarternote,musicalnote,eighthnotebeamed,musicalnotedbl,beamedsixteenthnotes,musicflatsign,musicsharpsign,checkmark,onecircleinversesansserif,twocircleinversesansserif,threecircleinversesansserif,fourcircleinversesansserif,fivecircleinversesansserif,sixcircleinversesansserif,sevencircleinversesansserif,eightcircleinversesansserif,ninecircleinversesansserif,arrowrightheavy
4 changes: 3 additions & 1 deletion resources/fonts/urw/tocff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
# python3 scripts/makesubset.py -lig scripts/SECS.TXT > resources/fonts/urw/subset.secs
# python3 scripts/makesubset.py -lig scripts/WGL4.TXT > resources/fonts/urw/subset.wgl

for f in input/Nimbus*.t1
tx -cff +S +T -b -n -g $(cat subset.box) -A input/NimbusBoxes.t1

for f in input/NimbusMono*.t1 input/NimbusRoman*.t1 input/NimbusSans*.t1
do
tx -cff +S +T -b -n -g $(cat subset.mes) -A $f
done
Expand Down
8 changes: 8 additions & 0 deletions scripts/fontdump.nmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,19 @@ generated\resources\fonts\sil:
mkdir generated\resources\fonts\sil
generated\resources\fonts\urw:
mkdir generated\resources\fonts\urw

generate: generated\resources\fonts\urw\Dingbats.cff.obj generated\resources\fonts\urw\Dingbats.cff.x64.obj
generated\resources\fonts\urw\Dingbats.cff.obj: resources\fonts\urw\Dingbats.cff generated\resources\fonts\urw bin2coff.exe
bin2coff.exe resources\fonts\urw\Dingbats.cff generated\resources\fonts\urw\Dingbats.cff.obj _binary_Dingbats_cff
generated\resources\fonts\urw\Dingbats.cff.x64.obj: resources\fonts\urw\Dingbats.cff generated\resources\fonts\urw bin2coff.exe
bin2coff.exe resources\fonts\urw\Dingbats.cff generated\resources\fonts\urw\Dingbats.cff.x64.obj _binary_Dingbats_cff 64bit

generate: generated\resources\fonts\urw\NimbusBoxes-Regular.cff.obj generated\resources\fonts\urw\NimbusBoxes-Regular.cff.x64.obj
generated\resources\fonts\urw\NimbusBoxes-Regular.cff.obj: resources\fonts\urw\NimbusBoxes-Regular.cff generated\resources\fonts\urw bin2coff.exe
bin2coff.exe resources\fonts\urw\NimbusBoxes-Regular.cff generated\resources\fonts\urw\NimbusBoxes-Regular.cff.obj _binary_NimbusBoxes_Regular_cff
generated\resources\fonts\urw\NimbusBoxes-Regular.cff.x64.obj: resources\fonts\urw\NimbusBoxes-Regular.cff generated\resources\fonts\urw bin2coff.exe
bin2coff.exe resources\fonts\urw\NimbusBoxes-Regular.cff generated\resources\fonts\urw\NimbusBoxes-Regular.cff.x64.obj _binary_NimbusBoxes_Regular_cff 64bit

generate: generated\resources\fonts\urw\NimbusMonoPS-Bold.cff.obj generated\resources\fonts\urw\NimbusMonoPS-Bold.cff.x64.obj
generated\resources\fonts\urw\NimbusMonoPS-Bold.cff.obj: resources\fonts\urw\NimbusMonoPS-Bold.cff generated\resources\fonts\urw bin2coff.exe
bin2coff.exe resources\fonts\urw\NimbusMonoPS-Bold.cff generated\resources\fonts\urw\NimbusMonoPS-Bold.cff.obj _binary_NimbusMonoPS_Bold_cff
Expand Down
2 changes: 2 additions & 0 deletions source/fitz/font-table.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ FONT(sil, CharisSIL_BoldItalic_cff, "Charis SIL", ANY_SCRIPT, FZ_LANG_UNSET, NO
#endif

#ifndef TOFU_NOTO
FONT(urw, NimbusBoxes_Regular_cff, "Nimbus Boxes", ANY_SCRIPT, FZ_LANG_UNSET, NO_SUBFONT, REGULAR)

FONT(noto, NotoSerif_Regular_otf, "Noto Serif", UCDN_SCRIPT_LATIN, FZ_LANG_UNSET, NO_SUBFONT, REGULAR)
ALIAS(noto, NotoSerif_Regular_otf, "Noto Serif", UCDN_SCRIPT_GREEK, FZ_LANG_UNSET, NO_SUBFONT, REGULAR)
ALIAS(noto, NotoSerif_Regular_otf, "Noto Serif", UCDN_SCRIPT_CYRILLIC, FZ_LANG_UNSET, NO_SUBFONT, REGULAR)
Expand Down
23 changes: 22 additions & 1 deletion source/fitz/font.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ struct fz_font_context
fz_font *base14[14];
fz_font *cjk[4];
struct { fz_font *serif, *sans; } fallback[256];
fz_font *symbol1, *symbol2, *math, *music;
fz_font *symbol1, *symbol2, *math, *music, *boxes;
fz_font *emoji;
};

Expand Down Expand Up @@ -630,6 +630,19 @@ static fz_font *fz_load_fallback_emoji_font(fz_context *ctx)
return ctx->font->emoji;
}

static fz_font *fz_load_fallback_boxes_font(fz_context *ctx)
{
const unsigned char *data;
int size;
if (!ctx->font->boxes)
{
data = fz_lookup_noto_boxes_font(ctx, &size);
if (data)
ctx->font->boxes = fz_new_font_from_memory(ctx, NULL, data, size, 0, 0);
}
return ctx->font->boxes;
}

static const struct ft_error ft_errors[] =
{
#include FT_ERRORS_H
Expand Down Expand Up @@ -2119,6 +2132,14 @@ fz_encode_character_with_fallback(fz_context *ctx, fz_font *user_font, int unico
return *out_font = font, gid;
}

font = fz_load_fallback_boxes_font(ctx);
if (font)
{
gid = fz_encode_character(ctx, font, unicode);
if (gid > 0)
return *out_font = font, gid;
}

font = fz_new_base14_font(ctx, "Symbol");
if (font)
{
Expand Down
6 changes: 6 additions & 0 deletions source/fitz/noto.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,9 @@ fz_lookup_noto_emoji_font(fz_context *ctx, int *size)
{
return search_by_script_lang(size, NULL, MUPDF_SCRIPT_EMOJI, FZ_LANG_UNSET);
}

const unsigned char *
fz_lookup_noto_boxes_font(fz_context *ctx, int *size)
{
return search_by_family(size, "Nimbus Boxes", REGULAR);
}

0 comments on commit 2569560

Please sign in to comment.