@@ -17,12 +17,9 @@ use std::{
1717
1818fn dom_new_canvas ( i : usize , width : usize , height : usize ) -> String {
1919 let mut out = String :: new ( ) ;
20- out += & format ! (
21- "const newCanvas{} = document.createElement(\" canvas\" );\n " ,
22- i
23- ) ;
24- out += & format ! ( "newCanvas{}.width = {};\n " , i, width) ;
25- out += & format ! ( "newCanvas{}.height = {};\n " , i, height) ;
20+ out += & format ! ( "const newCanvas{i} = document.createElement(\" canvas\" );\n " , ) ;
21+ out += & format ! ( "newCanvas{i}.width = {width};\n " ) ;
22+ out += & format ! ( "newCanvas{i}.height = {height};\n " ) ;
2623
2724 out
2825}
@@ -94,17 +91,14 @@ fn draw_glyph_to_canvas(glyph: &Glyph, key: usize) -> Result<String> {
9491 while i < points. len ( ) - 2 {
9592 if i == 0 {
9693 let ( ( x, y) , on_curve) = points[ 0 ] ;
97- out += & format ! ( "ctx{key}.moveTo({}, {});\n " , x , y ) ;
94+ out += & format ! ( "ctx{key}.moveTo({x }, {y });\n " ) ;
9895 assert ! ( on_curve, "First point should always be on curve." ) ;
9996 }
10097
10198 let ( mid_x, mid_y) = points[ i + 1 ] . 0 ;
10299 let ( next_x, next_y) = points[ i + 2 ] . 0 ;
103100
104- out += & format ! (
105- "ctx{key}.quadraticCurveTo({}, {}, {}, {});\n " ,
106- mid_x, mid_y, next_x, next_y,
107- ) ;
101+ out += & format ! ( "ctx{key}.quadraticCurveTo({mid_x}, {mid_y}, {next_x}, {next_y});\n " , ) ;
108102
109103 i += 2 ;
110104 }
@@ -162,9 +156,9 @@ fn main() -> Result<()> {
162156 }
163157
164158 render_js_code += & dom_new_canvas ( i, glyph. description . width ( ) , glyph. description . height ( ) ) ;
165- render_js_code += & format ! ( "const ctx{} = newCanvas{}.getContext(\" 2d\" );\n " , i , i ) ;
159+ render_js_code += & format ! ( "const ctx{i } = newCanvas{i }.getContext(\" 2d\" );\n " ) ;
166160 render_js_code += & draw_glyph_to_canvas ( glyph, i) ?;
167- render_js_code += & format ! ( "contentDiv.appendChild(newCanvas{});\n \n " , i ) ;
161+ render_js_code += & format ! ( "contentDiv.appendChild(newCanvas{i });\n \n " ) ;
168162 }
169163
170164 let dir_path = Path :: new ( "glyph_playground" ) ;
0 commit comments