move fontmapper function from svg.nas to api/text.nas so it is generally avail
This commit is contained in:
parent
e996f4c8c6
commit
3892d2eddd
3 changed files with 26 additions and 24 deletions
|
@ -3,9 +3,32 @@
|
|||
#-------------------------------------------------------------------------------
|
||||
# Class for a text element on a canvas
|
||||
#
|
||||
var font_mapper = func(family = "LiberationSans", weight = "", style = "", custom_mapper=nil)
|
||||
{
|
||||
if (isfunc(custom_mapper)) {
|
||||
var font = custom_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";
|
||||
};
|
||||
|
||||
var Text = {
|
||||
new: func(ghost) {
|
||||
return { parents: [Text, Element.new(ghost)] };
|
||||
var obj = {
|
||||
parents: [Text, Element.new(ghost)],
|
||||
};
|
||||
return obj;
|
||||
},
|
||||
|
||||
# Set the text
|
||||
|
|
|
@ -93,6 +93,7 @@ CompassRose.draw = func(cgroup, radius, style=nil) {
|
|||
labels[i]
|
||||
.setText(txt)
|
||||
.setFontSize(fontsize)
|
||||
.setFont(font_mapper("LiberationSans","bold"))
|
||||
.setColor(style.label_color)
|
||||
.setAlignment("center-"~(style.mark_offset < 0 ? "top" : "bottom"))
|
||||
.setTranslation(0,-radius-offset)
|
||||
|
|
|
@ -29,28 +29,6 @@ var parsesvg = func(group, path, options = nil)
|
|||
};
|
||||
|
||||
var custom_font_mapper = options['font-mapper'];
|
||||
var font_mapper = func(family, weight, style)
|
||||
{
|
||||
if( typeof(custom_font_mapper) == 'func' )
|
||||
{
|
||||
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";
|
||||
};
|
||||
|
||||
# Helper to get number without unit (eg. px)
|
||||
var evalCSSNum = func(css_num)
|
||||
|
@ -345,7 +323,7 @@ var parsesvg = func(group, path, options = nil)
|
|||
var font_weight = style["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));
|
||||
stack[-1].set("font", font_mapper(font_family, font_weight, font_style, custom_font_mapper));
|
||||
|
||||
var font_size = style["font-size"];
|
||||
if( font_size != nil )
|
||||
|
|
Loading…
Add table
Reference in a new issue