diff options
author | Paul Gardiner <paul@Pauls-Mac.site> | 2018-02-23 14:36:14 +0000 |
---|---|---|
committer | Paul Gardiner <paul@Pauls-Mac.site> | 2018-02-23 14:36:14 +0000 |
commit | dd76e14575a9f9779197c8f0771cc4c19990eded (patch) | |
tree | aed61fd8940910d2cbdaa01f07e57ef96c884adf /source | |
parent | 02584b4f4f5a7fa3d13bf622beca3ccd4e08b1c6 (diff) | |
download | mupdf-dd76e14575a9f9779197c8f0771cc4c19990eded.tar.xz |
Include a font's style in its name.
We were previously using the font's family as its name. Now if only one
of family and style are defined we use that. If both are present we
concatenate family and style with an intervening space, unless style
already has family as a prefix, in which case we just use the style.
Better would be to use the font's full name, but that is more difficult
to obtain via the freetype API.
Diffstat (limited to 'source')
-rw-r--r-- | source/fitz/font.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/source/fitz/font.c b/source/fitz/font.c index e197fa1b..54378e55 100644 --- a/source/fitz/font.c +++ b/source/fitz/font.c @@ -524,6 +524,7 @@ fz_new_font_from_buffer(fz_context *ctx, const char *name, fz_buffer *buffer, in fz_font *font; int fterr; FT_ULong tag, size, i, n; + char namebuf[sizeof(font->name)]; fz_keep_freetype(ctx); @@ -537,7 +538,27 @@ fz_new_font_from_buffer(fz_context *ctx, const char *name, fz_buffer *buffer, in } if (!name) - name = face->family_name; + { + if (!face->family_name) + { + name = face->style_name; + } + else if (!face->style_name) + { + name = face->family_name; + } + else if (strstr(face->style_name, face->family_name) == face->style_name) + { + name = face->style_name; + } + else + { + fz_strlcpy(namebuf, face->family_name, sizeof(namebuf)); + fz_strlcat(namebuf, " ", sizeof(namebuf)); + fz_strlcat(namebuf, face->style_name, sizeof(namebuf)); + name = namebuf; + } + } font = fz_new_font(ctx, name, use_glyph_bbox, face->num_glyphs); font->ft_face = face; |