I know the font and size (bold or normal), and know how wide the field is on the sign.
My wish is to know if the printout is too long before printing.
One way is to measure the width of each character, and make a sum of all character, and check the result.
Measuring the width of each character is not difficult.
Maybe it is possible to find a formula for a font, with different sizes.
One disadvantage of this is that each font / size and attribute
must be measured characters for characters, that should be allowed.
Question 1
Are there any easier way to automatically know the width of a font?
Question 2
Calculation of the width of a text can be done in this way
Code: Select all
SetBatchLines -1
#SingleInstance Force
#NoEnv
TestString = It works!
StringSplit NumberOfCharacters_, TestString
; Font .: Arial, 12dpi, Normal (An attempt to measure characters - Iun = I upper normal - tln = t lower normal)
Length_Iu = 1.176 ; mm/pcs I -> 8,5 pcs/10mm -> 1,176 mm/pcs
Length_tl = 1.176 ; mm/pcs t -> 8,5 pcs/10mm -> 1,176 mm/pcs
Length_Space = 1.176 ; mm/pcs Space -> 8,5 pcs/10mm -> 1,176 mm/pcs
Length_wl = 1.176 ; mm/pcs w -> 3,3 pcs/10mm -> 2,070 mm/pcs
Length_ol = 1.176 ; mm/pcs o -> 4,35 pcs/10mm -> 2,299 mm/pcs
Length_rl = 1.176 ; mm/pcs r -> 7,1 pcs/10mm -> 1,408 mm/pcs
Length_kl = 1.176 ; mm/pcs k -> 4,83 pcs/10mm -> 2,070 mm/pcs
Length_sl = 1.176 ; mm/pcs s -> 4,83 pcs/10mm -> 2,070 mm/pcs
Length_exclamation = 1.176 ; mm/pcs ! -> 8,5 pcs/10mm -> 1,176 mm/pcs
Loop %NumberOfCharacters_0%
{ If NumberOfCharacters_%A_Index% = I
TxtLength += Length_Iu
If NumberOfCharacters_%A_Index% = t
TxtLength += Length_tl
If NumberOfCharacters_%A_Index% = %A_Space%
TxtLength += Length_Space
If NumberOfCharacters_%A_Index% = w
TxtLength += Length_wl
If NumberOfCharacters_%A_Index% = o
TxtLength += Length_ol
If NumberOfCharacters_%A_Index% = r
TxtLength += Length_rl
If NumberOfCharacters_%A_Index% = k
TxtLength += Length_kl
If NumberOfCharacters_%A_Index% = s
TxtLength += Length_sl
If NumberOfCharacters_%A_Index% = !
TxtLength += Length_exclamation
}
MsgBox 64, Rad %A_LineNumber% -> %A_ScriptName%, Text .: %TestString% `nLength .: %TxtLength%