• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Solved] Text width

Status
Not open for further replies.
Level 9
Joined
Jan 23, 2015
Messages
124
So, I was going to fix StringSize ([Snippet] StringSize - Blizzard Modding Information Center) this evening because it shows really bad results in my case for myself (width of "1" for example, is about 2 times smaller than it should), made a test script and started to work... but I noticed weird thing: in log and in game there were different widths for one kind of symbols.
JASS:
scope MyScope initializer onInit
    globals
        integer s
    endglobals
    private function callback takes nothing returns nothing
        local string l = Ascii2Char(s)
        local real i= 450 / StringSize.measureChar(l)
        local integer a = R2I(i)
        local string str = ""
        loop
            exitwhen a < 1.0
            set str = str + l
            set a = a - 1
        endloop
        call BJDebugMsg(str + "-|" + R2S(i) + " " + I2S(s))
        set s = s + 1
    endfunction
  
    private function onInit takes nothing returns nothing
        set s = 32
        call TimerStart(CreateTimer(), 1.0, true, function callback)
    endfunction
endscope
In-game
Без имени-3.jpg

Log
Без имени-2.jpg

The "-|" shows relative width of string, so as you can see it has really different relations with each other
Initially I need it for my multiboard, and since I guess it would have different text size from both game and logs... Uh. It seems there's no real way to get the string width without just huge amount of manual work including considering each type of string usage, right?
 
Last edited:
Level 7
Joined
Oct 19, 2015
Messages
286
The width of each character gets rounded to the nearest pixel, so different font sizes and/or different resolutions will result in different ratios between character widths. Even if you know at what font size a string will be used, you can't know what resolution the user has on their screen, so you can't know the exact width of a string.

Here is some more information on the subject, which I used in this script.
 
Level 9
Joined
Jan 23, 2015
Messages
124
The width of each character gets rounded to the nearest pixel, so different font sizes and/or different resolutions will result in different ratios between character widths. Even if you know at what font size a string will be used, you can't know what resolution the user has on their screen, so you can't know the exact width of a string.

Here is some more information on the subject, which I used in this script.

Thanks for your reply. I see much better values for each letter, so it's already could solve the problem for me... though, I assume nobody had ever come to possible solution of the mentioned problem.

I'm listening to MemoryHack thread and I remember that that library has function to get screen width, so one could update this algorithms to more precious through some research, but I believe memhack is not so save thing to use and it could be fixed soon if only Blizzard still care about it.
 
Status
Not open for further replies.
Top