@@ -45,6 +45,48 @@ const applyPreset = () => {
4545 }
4646}
4747
48+ onst fontImage = new Image ()
49+ fontImage .src = ' ascii.png'
50+
51+ let charWidths = {}
52+
53+ const charToIndex = char => {
54+ const code = char .charCodeAt (0 )
55+ return code >= 32 && code <= 127 ? code - 32 : 0
56+ }
57+
58+ const analyzeCharWidths = () => {
59+ const offCanvas = document .createElement (' canvas' )
60+ offCanvas .width = 128
61+ offCanvas .height = 128
62+ const ctx = offCanvas .getContext (' 2d' )
63+ ctx .drawImage (fontImage, 0 , 0 )
64+
65+ for (let i = 0 ; i < 96 ; i++ ) {
66+ const sx = (i % 16 ) * tileSize
67+ const sy = Math .floor (i / 16 ) * tileSize
68+ const imageData = ctx .getImageData (sx, sy, tileSize, tileSize)
69+ const data = imageData .data
70+
71+ let minX = tileSize
72+ let maxX = 0
73+
74+ for (let y = 0 ; y < tileSize; y++ ) {
75+ for (let x = 0 ; x < tileSize; x++ ) {
76+ const idx = (y * tileSize + x) * 4
77+ const alpha = data[idx + 3 ]
78+ if (alpha > 0 ) {
79+ if (x < minX) minX = x
80+ if (x > maxX) maxX = x
81+ }
82+ }
83+ }
84+
85+ const width = maxX >= minX ? maxX - minX + 1 : 0
86+ charWidths[i] = { width, offsetX: minX }
87+ }
88+ }
89+
4890// Текст ранга
4991const text = ref (' Rank' )
5092// Ссылка на canvas
@@ -146,47 +188,7 @@ function adjustHSL(colorHex, lightnessAdjustment) {
146188}
147189 </script >
148190
149- const fontImage = new Image()
150- fontImage.src = 'ascii.png'
151-
152- let charWidths = {}
153-
154- const charToIndex = char => {
155- const code = char.charCodeAt(0)
156- return code >= 32 && code <= 127 ? code - 32 : 0
157- }
158-
159- const analyzeCharWidths = () => {
160- const offCanvas = document.createElement('canvas')
161- offCanvas.width = 128
162- offCanvas.height = 128
163- const ctx = offCanvas.getContext('2d')
164- ctx.drawImage(fontImage, 0, 0)
165-
166- for (let i = 0; i < 96; i++) {
167- const sx = (i % 16) * tileSize
168- const sy = Math.floor(i / 16) * tileSize
169- const imageData = ctx.getImageData(sx, sy, tileSize, tileSize)
170- const data = imageData.data
171-
172- let minX = tileSize
173- let maxX = 0
174-
175- for (let y = 0; y < tileSize; y++) {
176- for (let x = 0; x < tileSize; x++) {
177- const idx = (y * tileSize + x) * 4
178- const alpha = data[idx + 3]
179- if (alpha > 0) {
180- if (x < minX) minX = x
181- if (x > maxX) maxX = x
182- }
183- }
184- }
185-
186- const width = maxX >= minX ? maxX - minX + 1 : 0
187- charWidths[i] = { width, offsetX: minX }
188- }
189- }
191+ c
190192
191193const draw = () => {
192194 const ctx = canvas.value.getContext('2d')
0 commit comments