g.StringWidth return wrong results with non ASCII values included

I do not have the sources with me right now, but I saw a wrong result in an application.

I used g.StringWidth, etc. to get a ListBox column width / Set LB.ColumnWidths…

An entry had non ASCII characters in it and that column width is incorrect.
The entry is: <Nom de code “Cimeterre”>
(without < and >)

Do we know this (as a bug) ?
(27 entries returned by Feedback; search strins is “StringWidth”.)

Notes (after checking docs): I certainly use Integer instead of Double.

MacBook Pro 2011-11
OS X 10.9.5
Xojo 2014r2.1

I see only ASCII characters there. It would be more useful to post the entry returned that has higher Unicode points.

I just built a small test project that measures strings entered in a TextField and reports the StringWidth.

“ete” and “t” give exactly the same stringwidth.

Please to be more specific.

I used curly quotes (start-end). These are not in the ASCII values (0-127). To be sure of what I say, copy / paste the text in the question (far above) into Apple’s TextEdit and resize the text to say 36 and you will see what I wanted to tell. My glasses needs to be improved, so I just do that in case I’ve made a mistake.

On a second click (several minutes after, searches on www.cbs.com, save data, etc.), and a manual resize, another click in the resize button shows a different behavior.

So, now, I do not know.

I know: I close the window but keep the application running,
I re-open the window,
I open the original text file,
I clicked in the ToolBar’s Resize Columns button

and I get the same behavior. Worst, this also does not fit in the new column size:
Les vieux he?ros ne meurent jamais

The displays stop at “jama” leaving “is” lost in the space/time warp !

ete and été: try in a ListBox and with a far larger string like “La chanson de l’été dernier…” and you may see a discrepancy.

All of this is really queer.

I do not closed the window, but I changed the first column contents from an acronym to its full name, then I re-open the newly modified file and the ListBox width resize do correctly its job.

BTW: the other word to say Strange (last word of my previous entry have been changed. Why ?

That word is Q-U-E-E-R (Queen with an ending r instead of an ending n).

I found that word in some comic strips / newspaper of the 1930s and checked its meaning with Systran (I think).

[quote=140754:@Emile Schwarz]I do not closed the window, but I changed the first column contents from an acronym to its full name, then I re-open the newly modified file and the ListBox width resize do correctly its job.

BTW: the other word to say Strange (last word of my previous entry have been changed. Why ?

That word is Q-U-E-E-R (Queen with an ending r instead of an ending n).

I found that word in some comic strips / newspaper of the 1930s and checked its meaning with Systran (I think).[/quote]

Que-er is derogatory for gay. Then it is beeped like other profanities.

Back to your current issue of stringwidth, I cannot verify what you report.
With Arial at point 36,
ete or été = 50.04492
La chanson de l’ete dernier… or La chanson de l’été dernier… = 470.3027

My test program is awfully simple :

  • One TextField set to Arial, 36 points
  • OneTextArea for the results
  • In the TextField :

Function KeyDown(Key As String) As Boolean if key = chr(13) then dim p as new picture(me.width,me.height,32) p.graphics.textfont = me.textfont p.graphics.textsize = me.Textsize TextArea1.text = TextArea1.Text+str(p.graphics.stringwidth(me.text))+EndOfLine return true end if End Function

Are you sure you are setting the same textfont and textsize for the listbox as for stringwidth ? Are you using System ? If so, you may want to switch to Arial (cross platform).

same textfont and textsize for the listbox as for stringwidth
I probably used ListBox Text Size and ListBox TextFont.

Used font: probably system.

you may want to switch to Arial
Good idea.

Don’t shake your head. I will watch that carefully this afternoon with the project and after a shutdown / clean boot. I have some troubles with the rtf load (tabs are different from Apple’s TextEdit). I used declares to display those RTF files.

Here are the answers to the previous questions in the following code:

[code] // a. Get the number of Rows & Columns
ColCnt = LB.ColumnCount - 1
RowCnt = LB.ListCount - 1

// Get the selected Font Name & Size
FontName = LB.TextFont
FontSize = LB.TextSize

// Get a new Picture
PictTmp = New Picture(600,40)

// Set the default Text Font & Size
PictTmp.Graphics.TextFont = FontName
PictTmp.Graphics.TextSize = FontSize

// b. Loop thru all Columns
For ColIdx = 0 To ColCnt
  For RowIdx = 0 To RowCnt
    // Get one Cell contents
    CellStr = LB.Cell(RowIdx,ColIdx)
    
    // Get the width of the Cell String
    CellWidth = PictTmp.Graphics.StringWidth(CellStr) + 10
    
    // Get the highest width
    ColWidth = Max(ColWidth,CellWidth)
    
    // Clears some variables
    CellStr  = ""
  Next // Row Count[/code]

Note: PictTmp = New Picture(600,40) Yes, I know I can use PictTmp = New Picture(0,0)…

Note also that I add 10 pixels to the cell width !

PS: I do not have faith in Phantom or Ghost (Who Walks or fly), but sometimes I deep ly wonder…

PPS: Michel, don’t you recall the piece of code that was shared lately in this forum ?
(I wrote mine sometimes earlier, but I could use that one)

At last: I never clears any cache or whatever file between compilations. This may explain that ?