Sub Main
While "True"
If clicked Then
GraphicsWindow.BrushColor = "White"
GraphicsWindow.FillRectangle(0, yc, gw, gh - yc)
fs = Controls.GetTextBoxText(size)
GraphicsWindow.FontSize = fs
GraphicsWindow.FontName = Controls.GetTextBoxText(font)
GraphicsWindow.FontBold = Controls.GetTextBoxText(bold)
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.DrawText(0, yc, "||")
y0 = yc
y1 = yc + fs
x0 = 0
x1 = fs * 2
If gw < x1 Then
x1 = gw - 1
EndIf
Measure()
px0 = px
n = Array.GetItemCount(c)
index = Array.GetAllIndices(c)
cw = ""
For i = 1 To n
GraphicsWindow.BrushColor = "White"
GraphicsWindow.FillRectangle(0, yc, gw, gh - yc)
GraphicsWindow.BrushColor = "Gray"
GraphicsWindow.FillRectangle(0, yc + fs, gw, 1)
str = "|" + c[index[i]] + "|"
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.DrawText(0, yc, str)
x1 = fs * Text.GetLength(str)
If gw < x1 Then
x1 = gw - 1
EndIf
Measure()
cw[Text.GetCharacterCode(c[index[i]])] = px
EndFor
Format()
Controls.SetTextBoxText(width, output)
clicked = "False"
Else
Program.Delay(100)
EndIf
EndWhile
EndSub
Sub Format
' param cw - character width array
' param fontname - font name
' return output - output text
n = Array.GetItemCount(cw)
index = Array.GetAllIndices(cw)
header = "ratio = ratio + " + WQ
output = "' width/height [%] of each character in " + fontname + " font" + CRLF
output = output + "GraphicsWindow.FontName = " + WQ + fontname + WQ + CRLF
output = output + "ratio = " + WQ
ll = 9 ' length of line
For i = 1 To n
entry = index[i] + "=" + cw[index[i]] + ";"
le = Text.GetLength(entry) ' length of entry
If 70 < ll + le + 1 Then
output = output + WQ + CRLF + header
ll = Text.GetLength(header)
EndIf
output = output + entry
ll = ll + le
EndFor
output = output + WQ
EndSub
Sub Measure
' return px
y = Math.Floor((y0 + y1) / 2)
For x = x0 To x1
color = GraphicsWindow.GetPixel(x, y)
If Not[Text.EndsWith(color, "FFFFFF")] Then
left = x
x = x1 ' break
EndIf
EndFor
For x = x1 To x0 Step -1
color = GraphicsWindow.GetPixel(x, y)
If Not[Text.EndsWith(color, "FFFFFF")] Then
right = x
x = x0 ' break
EndIf
EndFor
For x = right To x0 Step -1
color = GraphicsWindow.GetPixel(x, y)
If Text.EndsWith(color, "FFFFFF") Then
right = x + 1
x = x0 ' break
EndIf
EndFor
px = right - left
EndSub