Allow creating link to font file, not only embedding it
kaminski kaminski@naew.nato.int
Sun, 04 Apr 2021 22:58:17 +0200
1 files changed,
10 insertions(+),
2 deletions(-)
jump to
M
src/hastyscribepkg/utils.nim
→
src/hastyscribepkg/utils.nim
@@ -10,6 +10,9 @@
proc style_tag*(css: string): string = result = "<style>$1</style>" % [css] +proc style_link_tag*(css: string): string = + result = "<link rel=\"stylesheet\" href=\"$1\"/>" % [css] + proc encode_image*(contents, format: string): string = let enc_contents = contents.encode return "data:image/$format;base64,$enc_contents" % ["format", format, "enc_contents", enc_contents]@@ -40,7 +43,12 @@ proc encode_font*(font, format: string): string =
let enc_contents = font.encode return "data:application/$format;charset=utf-8;base64,$enc_contents" % ["format", format, "enc_contents", enc_contents] -proc create_font_face*(font, family, style: string, weight: int): string= +proc create_font_face*(font, family, style: string, weight: int, embed=true): string= + var font_src = "" + if embed: + font_src = encode_font(font, "x-font-woff") + else: + font_src = font return """ @font-face { font-family:"$family";@@ -50,6 +58,6 @@ font-weight:$weight;
-webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } - """ % ["family", family, "font", encode_font(font, "x-font-woff"), "style", style, "weight", $weight] + """ % ["family", family, "font", font_src, "style", style, "weight", $weight]