# Weird Graphics font behavior...

**URL:** <https://forum.xojo.com/t/weird-graphics-font-behavior/34195>\
**Category:** General\
**Created:** [October 27, 2016, 11:33am UTC](https://forum.xojo.com/t/weird-graphics-font-behavior/34195 "2016-10-27T11:33:31Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Edwin\_van\_den\_Akker](https://forum.xojo.com/user_avatar/forum.xojo.com/edwin_van_den_akker/32/1063_2.png) [@Edwin\_van\_den\_Akker](https://forum.xojo.com/u/Edwin_van_den_Akker)\
**Post date:** [October 27, 2016, 11:33am UTC](https://forum.xojo.com/t/weird-graphics-font-behavior/34195/1 "2016-10-27T11:33:31Z")

</div>

Maybe I am doing something wrong. But it seems that the g.StringWidth and g.StringHeight are doing some weird things.  
The string height does not seem to be correct, somehow. And I can’t wrap my head around the problem.

I created a simple app to demonstrate the problem.  
 ![](http://1816media.nl/xojo/test/GraphicsFonts.jpg)

The demo app can be found [here](http://1816media.nl/xojo/test/GraphicsFonts.xojo_binary_project)

The funny thing is, that if there is only one character to display, the correct heights are displayed. As soon as I change the text, the StringHeight doubles…

What am I doing wrong???  
Or is it simply a bug 🙂

---

<div class="post-metadata">

**Author:** ![Edwin\_van\_den\_Akker](https://forum.xojo.com/user_avatar/forum.xojo.com/edwin_van_den_akker/32/1063_2.png) [@Edwin\_van\_den\_Akker](https://forum.xojo.com/u/Edwin_van_den_Akker)\
**Post date:** [October 27, 2016, 11:41am UTC](https://forum.xojo.com/t/weird-graphics-font-behavior/34195/2 "2016-10-27T11:41:38Z")

</div>

I might end up doing the calculations for StringHeight myself.  
The TextHeight function actually does seem to work, as I used it to draw the baseline lines.  
I used t.CountFields( chr(13) ) to count the number of lines.  
I multiplied it with the TextHeight to calculate the Y positions of the base line.

Using this method I can calculate the stringheight myself. But what I wanted to say is that I find it quite weird that the build in method gives me the incorrect values.

---

<div class="post-metadata">

**Author:** ![Ulrich\_Bogun](https://forum.xojo.com/user_avatar/forum.xojo.com/ulrich_bogun/32/1864_2.png) [@Ulrich\_Bogun](https://forum.xojo.com/u/Ulrich_Bogun)\
**Post date:** [October 27, 2016, 11:58am UTC](https://forum.xojo.com/t/weird-graphics-font-behavior/34195/3 "2016-10-27T11:58:58Z")

</div>

Make the second line a bit shorter and your method will show the right bounds, not only if one character is present. Your text is too long so that it breaks and appends a blank third line  I have no clue why currently. Is the EOL at the end of the string a part of the string length calculation?

---

<div class="post-metadata">

**Author:** ![Edwin\_van\_den\_Akker](https://forum.xojo.com/user_avatar/forum.xojo.com/edwin_van_den_akker/32/1063_2.png) [@Edwin\_van\_den\_Akker](https://forum.xojo.com/u/Edwin_van_den_Akker)\
**Post date:** [October 27, 2016, 12:03pm UTC](https://forum.xojo.com/t/weird-graphics-font-behavior/34195/4 "2016-10-27T12:03:18Z")

</div>

Yeah, I noticed that, too.  
When calculating the StringHeight I added 1 to the StringWidth. That seemed to stop the auto-linebreaking problem.  
You think it might be bug?

---

<div class="post-metadata">

**Author:** ![Edwin\_van\_den\_Akker](https://forum.xojo.com/user_avatar/forum.xojo.com/edwin_van_den_akker/32/1063_2.png) [@Edwin\_van\_den\_Akker](https://forum.xojo.com/u/Edwin_van_den_Akker)\
**Post date:** [October 27, 2016, 12:04pm UTC](https://forum.xojo.com/t/weird-graphics-font-behavior/34195/5 "2016-10-27T12:04:58Z")

</div>

> [@295150:@Ulrich Bogun](#):
>
> Is the EOL at the end of the string a part of the string length calculation?

Apparently not. Try my demo app. When typing the EOL doesn’t change the box around the text

---

<div class="post-metadata">

**Author:** ![Ulrich\_Bogun](https://forum.xojo.com/user_avatar/forum.xojo.com/ulrich_bogun/32/1864_2.png) [@Ulrich\_Bogun](https://forum.xojo.com/u/Ulrich_Bogun)\
**Post date:** [October 27, 2016, 12:05pm UTC](https://forum.xojo.com/t/weird-graphics-font-behavior/34195/6 "2016-10-27T12:05:28Z")

</div>

I think its rather a weirdness in the typesetting algorithm, but I am completely unsure.  
Another piece of fun? Remove the trim and insert a return after the second line. Now it can be as long as it wants and the bounds are ok 😃

---

<div class="post-metadata">

**Author:** ![Edwin\_van\_den\_Akker](https://forum.xojo.com/user_avatar/forum.xojo.com/edwin_van_den_akker/32/1063_2.png) [@Edwin\_van\_den\_Akker](https://forum.xojo.com/u/Edwin_van_den_Akker)\
**Post date:** [October 27, 2016, 12:08pm UTC](https://forum.xojo.com/t/weird-graphics-font-behavior/34195/7 "2016-10-27T12:08:33Z")

</div>

> [@295155:@Ulrich Bogun](#):
>
> Remove the trim and insert a return after the second line. Now it can be as long as it wants and the bounds are ok 😃

Ha, you beat me to it!  
I just tried that. And the EOLs appear. But by adding the StringWith with 1 pixel still puzzles me. Seems a 0-based or 1-based width problem.

---

<div class="post-metadata">

**Author:** ![Edwin\_van\_den\_Akker](https://forum.xojo.com/user_avatar/forum.xojo.com/edwin_van_den_akker/32/1063_2.png) [@Edwin\_van\_den\_Akker](https://forum.xojo.com/u/Edwin_van_den_Akker)\
**Post date:** [October 27, 2016, 12:12pm UTC](https://forum.xojo.com/t/weird-graphics-font-behavior/34195/9 "2016-10-27T12:12:59Z")

</div>

[quote=295159:@Ulrich Bogun]Try this:

```auto
g.DrawString t, x, y + g.TextAscent+g.TextHeight
```

Why do I want to add the g.TextHeight to the g.TextAscent? Doesn’t that move the text too far down?

---

<div class="post-metadata">

**Author:** ![Edwin\_van\_den\_Akker](https://forum.xojo.com/user_avatar/forum.xojo.com/edwin_van_den_akker/32/1063_2.png) [@Edwin\_van\_den\_Akker](https://forum.xojo.com/u/Edwin_van_den_Akker)\
**Post date:** [October 27, 2016, 12:13pm UTC](https://forum.xojo.com/t/weird-graphics-font-behavior/34195/10 "2016-10-27T12:13:57Z")

</div>

> [@295159:@Ulrich Bogun](#):
>
> I think its no weirdness but the WrapWidth was a bit too short.

Adding one pixel seemed to fix the problem. And that might be a bug… and that’s what I find weird 😉

---

<div class="post-metadata">

**Author:** ![Ulrich\_Bogun](https://forum.xojo.com/user_avatar/forum.xojo.com/ulrich_bogun/32/1864_2.png) [@Ulrich\_Bogun](https://forum.xojo.com/u/Ulrich_Bogun)\
**Post date:** [October 27, 2016, 12:19pm UTC](https://forum.xojo.com/t/weird-graphics-font-behavior/34195/11 "2016-10-27T12:19:17Z")

</div>

Sorry, I had it wrong and didnt see the extra line at the top. After looking a bit more at it, I wonder if the wrap algorithm is ok? It looks to me like whenever the last line exceeds the previous length, the wrapping algorithm adds an invisible new line. I am still uncertain about this but I think it would be worth filing a bug report. Playing with WrapWidth didnt help (and without one it is supposed not to wrap anyway.)  
Good you found a workaround!

---

<div class="post-metadata">

**Author:** ![Edwin\_van\_den\_Akker](https://forum.xojo.com/user_avatar/forum.xojo.com/edwin_van_den_akker/32/1063_2.png) [@Edwin\_van\_den\_Akker](https://forum.xojo.com/u/Edwin_van_den_Akker)\
**Post date:** [October 27, 2016, 12:28pm UTC](https://forum.xojo.com/t/weird-graphics-font-behavior/34195/12 "2016-10-27T12:28:57Z")

</div>

> [@295162:@Ulrich Bogun](#):
>
> … it would be worth filing a bug report…

As a matter of fact, I just did. I updated the demo app a little, and attached it to the Bug Report. It’s case #45644 🙂

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 6:31pm UTC](https://forum.xojo.com/t/weird-graphics-font-behavior/34195/13 "2020-10-29T18:31:59Z")

</div>


