View Issue Details

IDProjectCategoryView StatusLast Update
0008589Multi Theft Auto : San AndreasScriptingpublic2015-07-26 02:33
ReporterFecheAssigned Tosbx320 
PrioritynormalSeveritytweakReproducibilityalways
Status resolvedResolutionfixed 
Product Version1.1 
Target Version1.5Fixed in Version1.5 
Summary0008589: outputChatBox returns with space if using color codes
Description

If you use true on 'colorCoded' argument you get a nice big space, I don't really know how to explain it, here is the code to reproduce it.. tested both client and server.

As you can see string is only 75 characters long, a picture is worth a thousand words:

http://i.imgur.com/rgVGCau.png

Steps To Reproduce

addCommandHandler("asd",
function()
outputChatBox"Server"
outputChatBox("#80808011111111111111111111111111111111111111111111111111: #FFFFFFhiiiiiiii", root, 255, 255, 255, true)
end
)

/asd

TagsNo tags attached.

Relationships

has duplicate 0008952 closed New issues outputChatBox wrong characters width when using colorcodes 

Activities

sbx320

2015-06-28 11:09

administrator   ~~0023464

GetTextExtentPoint32W (used in CGraphics::GetDXTextExtent which in turn is used to determine the width of a to be colorfully printed substring) returns the amount of pixels in width and height required to display the substring. However GetTextExtendPoint32W does not consider font kerning.

Because some devices kern characters, the sum of the extents of the characters in a string may not be equal to the extent of the string.

Some information about font kerning can be found here :https://en.wikipedia.org/wiki/Kerning

I've fixed this issue by using DT_CALCRECT to get the exact width required to render the substring in https://github.com/multitheftauto/mtasa-blue/commit/3865fbae53b9a1d6a72afde48b0e5695d2d1c790.

arranTuna

2015-07-15 15:09

manager   ~~0023610

Last edited: 2015-07-15 15:56

View 2 revisions

srun outputChatBox("#FF0000Test: #FFFFFFHello", root, 0, 0, 0, true)
In console there is 1 space, in chatbox there is 2 spaces (between Test: and Hello)

See the screenshot I've attached to this bug report: |#FFFFFF| Should look like || but it's looking like | |

sbx320

2015-07-16 14:49

administrator   ~~0023627

It's not actually two spaces, but actually the width of an undescore (_) which is a bit more than a space. DT_CALCRECT ignores trailing spaces, so I needed something to substitue the space with. Not an optimal solution but it should work for most purposes.

Properly fixing this is a likely to be a bit more complicated.

arranTuna

2015-07-16 16:56

manager   ~~0023630

Can't you use the width of - instead of _?

ccw

2015-07-18 21:52

administrator   ~~0023682

ID3DXFont::DrawText docs says it modifies the rect. Not sure if it would make any difference, but we don't initialize rect.

ccw

2015-07-19 09:05

administrator   ~~0023691

It looks like moving trailing spaces to the front improves width calculation

sbx320

2015-07-26 02:33

administrator   ~~0023720

https://github.com/multitheftauto/mtasa-blue/commit/258ec69f44dd35f0b05c12246858ad56179580d6

Moving spaces to the front caused issues when passing a space-only string.

Issue History

Date Modified Username Field Change