From b18437b5f1de6a0b9579eb1d51dee61bad8e0eb2 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Wed, 9 Aug 2017 13:59:29 +0200 Subject: Use font name in HTML output. --- source/fitz/stext-output.c | 60 +++++++++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 22 deletions(-) diff --git a/source/fitz/stext-output.c b/source/fitz/stext-output.c index 4400494e..0fe6be4f 100644 --- a/source/fitz/stext-output.c +++ b/source/fitz/stext-output.c @@ -16,23 +16,46 @@ detect_super_script(fz_stext_line *line, fz_stext_char *ch) return 0; } +static const char * +font_full_name(fz_context *ctx, fz_font *font) +{ + const char *name = fz_font_name(ctx, font); + const char *s = strchr(name, '+'); + return s ? s + 1 : name; +} + +static void +font_family_name(fz_context *ctx, fz_font *font, char *buf, int size, int is_mono, int is_serif) +{ + const char *name = font_full_name(ctx, font); + char *s; + fz_strlcpy(buf, name, size); + s = strrchr(buf, '-'); + if (s) + *s = 0; + if (is_mono) + fz_strlcat(buf, ",monospace", size); + else + fz_strlcat(buf, is_serif ? ",serif" : ",sans-serif", size); +} + static void fz_print_style_begin_html(fz_context *ctx, fz_output *out, fz_font *font, float size, int sup) { + char family[80]; + int is_bold = fz_font_is_bold(ctx, font); int is_italic = fz_font_is_italic(ctx, font); int is_serif = fz_font_is_serif(ctx, font); int is_mono = fz_font_is_monospaced(ctx, font); - fz_write_printf(ctx, out, "", is_serif ? "serif" : "sans-serif", size); - if (sup) - fz_write_string(ctx, out, ""); - if (is_mono) - fz_write_string(ctx, out, ""); - if (is_bold) - fz_write_string(ctx, out, ""); - if (is_italic) - fz_write_string(ctx, out, ""); + font_family_name(ctx, font, family, sizeof family, is_mono, is_serif); + + if (sup) fz_write_string(ctx, out, ""); + if (is_mono) fz_write_string(ctx, out, ""); + if (is_bold) fz_write_string(ctx, out, ""); + if (is_italic) fz_write_string(ctx, out, ""); + fz_write_printf(ctx, out, "", family, size); } static void @@ -42,15 +65,11 @@ fz_print_style_end_html(fz_context *ctx, fz_output *out, fz_font *font, float si int is_bold = fz_font_is_bold(ctx,font); int is_italic = fz_font_is_italic(ctx, font); - if (is_italic) - fz_write_string(ctx, out, ""); - if (is_bold) - fz_write_string(ctx, out, ""); - if (is_mono) - fz_write_string(ctx, out, ""); - if (sup) - fz_write_string(ctx, out, ""); fz_write_string(ctx, out, ""); + if (is_italic) fz_write_string(ctx, out, ""); + if (is_bold) fz_write_string(ctx, out, ""); + if (is_mono) fz_write_string(ctx, out, ""); + if (sup) fz_write_string(ctx, out, ""); } static void @@ -330,7 +349,6 @@ fz_print_stext_page_as_xml(fz_context *ctx, fz_output *out, fz_stext_page *page) fz_font *font = NULL; float size = 0; const char *name = NULL; - const char *s; fz_rect rect; fz_write_printf(ctx, out, "\n", @@ -346,10 +364,8 @@ fz_print_stext_page_as_xml(fz_context *ctx, fz_output *out, fz_stext_page *page) fz_write_string(ctx, out, "\n"); font = ch->font; size = ch->size; - name = fz_font_name(ctx, font); - s = strchr(name, '+'); - s = s ? s + 1 : name; - fz_write_printf(ctx, out, "\n", s, size); + name = font_full_name(ctx, font); + fz_write_printf(ctx, out, "\n", name, size); } fz_stext_char_bbox(ctx, &rect, line, ch); fz_write_printf(ctx, out, "