summaryrefslogtreecommitdiff
path: root/source/html/font.c
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2014-11-11 17:03:25 +0100
committerTor Andersson <tor.andersson@artifex.com>2014-12-03 12:25:51 +0100
commit7cb2a64e678f0179cb75d2de0321d5d4ca35183f (patch)
tree310f125b9235904feccde7b08f41bb59978c78f5 /source/html/font.c
parent36667a0003cc5ac230d94f3483bcc77e8cfc600e (diff)
downloadmupdf-7cb2a64e678f0179cb75d2de0321d5d4ca35183f.tar.xz
html: Draw text and shade padding boxes.
Diffstat (limited to 'source/html/font.c')
-rw-r--r--source/html/font.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/source/html/font.c b/source/html/font.c
new file mode 100644
index 00000000..102bb8df
--- /dev/null
+++ b/source/html/font.c
@@ -0,0 +1,40 @@
+#include "mupdf/html.h"
+#include "mupdf/pdf.h" /* for pdf_lookup_substitute_font */
+
+#include <ft2build.h>
+#include FT_FREETYPE_H
+
+static int ft_is_bold(FT_Face face)
+{
+ return face->style_flags & FT_STYLE_FLAG_BOLD;
+}
+
+static int ft_is_italic(FT_Face face)
+{
+ return face->style_flags & FT_STYLE_FLAG_ITALIC;
+}
+
+fz_font *
+html_load_font(fz_context *ctx,
+ const char *family, const char *variant, const char *style, const char *weight)
+{
+ unsigned char *data;
+ unsigned int size;
+ fz_font *font;
+
+ int is_bold = !strcmp(weight, "bold");
+ int is_italic = !strcmp(style, "italic");
+
+ int is_mono = !strcmp(family, "monospace");
+ int is_sans = !strcmp(family, "sans-serif");
+
+ // TODO: keep a cache of loaded fonts
+
+ data = pdf_lookup_substitute_font(is_mono, !is_sans, is_bold, is_italic, &size);
+
+ font = fz_new_font_from_memory(ctx, family, data, size, 0, 1);
+ font->ft_bold = is_bold && !ft_is_bold(font->ft_face);
+ font->ft_italic = is_italic && !ft_is_italic(font->ft_face);
+
+ return font;
+}