diff options
Diffstat (limited to 'src/svg.gleam')
| -rw-r--r-- | src/svg.gleam | 58 |
1 files changed, 33 insertions, 25 deletions
diff --git a/src/svg.gleam b/src/svg.gleam index 884d6cf..0178dbd 100644 --- a/src/svg.gleam +++ b/src/svg.gleam @@ -1,5 +1,4 @@ import cache -import gleam/bit_array import gleam/int import gleam/list import gleam/option.{Some} @@ -10,16 +9,20 @@ type XmlImages { XmlImages(xml: String, width: Int, height: Int) } -fn image(data, image: image.ImageInformation, width) { - "<image - height=\"" <> int.to_string(image.height) <> "\" - width=\"" <> int.to_string(image.width) <> "\" - x=\"" <> int.to_string(width) <> "\" - y=\"0\" - xlink:href=\"data:image/" <> image.extension <> ";base64," <> bit_array.base64_encode( - data, - False, - ) <> "\"/>" +fn image(base64, image: image.ImageInformation, width) { + string_builder.new() + |> string_builder.append("<image height=\"") + |> string_builder.append(int.to_string(image.height)) + |> string_builder.append("\" width=\"") + |> string_builder.append(int.to_string(image.width)) + |> string_builder.append("\" x=\"") + |> string_builder.append(int.to_string(width)) + |> string_builder.append("\" y=\"0\" xlink:href=\"data:image/") + |> string_builder.append(image.extension) + |> string_builder.append(";base64,") + |> string_builder.append(base64) + |> string_builder.append("\"/>") + |> string_builder.to_string() } fn images(image_cache, theme, digits, width, height, svgs) { @@ -34,7 +37,10 @@ fn images(image_cache, theme, digits, width, height, svgs) { rest, width + cached.info.width, int.max(height, cached.info.height), - string_builder.append(svgs, image(cached.data, cached.info, width)), + string_builder.append( + svgs, + image(cached.base64, cached.info, width), + ), ) _ -> images(image_cache, theme, rest, width, height, svgs) } @@ -60,17 +66,19 @@ pub fn xml(image_cache, theme, number, padding) { string_builder.new(), ) - "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> - <svg - height=\"" <> int.to_string(xml.height) <> "\" - style=\"image-rendering: pixelated;\" - version=\"1.1\" - width=\"" <> int.to_string(xml.width) <> "\" - xmlns=\"http://www.w3.org/2000/svg\" - xmlns:xlink=\"http://www.w3.org/1999/xlink\" - > - <title>Mayu</title> - - <g>" <> xml.xml <> "</g> - </svg>" + string_builder.new() + |> string_builder.append( + "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><svg height=\"", + ) + |> string_builder.append(int.to_string(xml.height)) + |> string_builder.append( + "\" style=\"image-rendering: pixelated;\" version=\"1.1\" width=\"", + ) + |> string_builder.append(int.to_string(xml.width)) + |> string_builder.append( + "\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"><title>Mayu</title><g>", + ) + |> string_builder.append(xml.xml) + |> string_builder.append("</g></svg>") + |> string_builder.to_string() } |