From 61a6fee0dbcd3217b32b9e6bfef9ab0f6bb05821 Mon Sep 17 00:00:00 2001 From: Torsten Dreyer Date: Wed, 10 Sep 2014 16:51:12 +0200 Subject: [PATCH] Canvas svg: use font-style and map LiberationFonts - interprete the font-style attribute for text - add a better font-mapper for Liberation Fonts --- Nasal/canvas/svg.nas | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Nasal/canvas/svg.nas b/Nasal/canvas/svg.nas index dae3605b0..b542b31c3 100644 --- a/Nasal/canvas/svg.nas +++ b/Nasal/canvas/svg.nas @@ -27,15 +27,26 @@ var parsesvg = func(group, path, options = nil) }; var custom_font_mapper = options['font-mapper']; - var font_mapper = func(family, weight) + var font_mapper = func(family, weight, style) { if( typeof(custom_font_mapper) == 'func' ) { - var font = custom_font_mapper(family, weight); + var font = custom_font_mapper(family, weight, style); if( font != nil ) return font; } + if( string.match(family,"Liberation*") ) { + style = style == "italic" ? "Italic" : ""; + weight = weight == "bold" ? "Bold" : ""; + + var s = weight ~ style; + if( s == "" ) s = "Regular"; + + return "LiberationFonts/" ~ string.replace(family," ", "") ~ "-" ~ s ~ ".ttf"; + } + + return "LiberationFonts/LiberationMono-Bold.ttf"; }; @@ -349,8 +360,9 @@ var parsesvg = func(group, path, options = nil) var font_family = style["font-family"]; var font_weight = style["font-weight"]; - if( font_family != nil or font_weight != nil ) - stack[-1].set("font", font_mapper(font_family, font_weight)); + var font_style = style["font-style"]; + if( font_family != nil or font_weight != nil or font_style != nil ) + stack[-1].set("font", font_mapper(font_family, font_weight, font_style)); var font_size = style["font-size"]; if( font_size != nil )