# \[BUG\] The result of Graphics::drawText is sometimes incorrect

**URL:** <https://forum.juce.com/t/bug-the-result-of-graphics-drawtext-is-sometimes-incorrect/61950>\
**Category:** Development\
**Created:** [June 21, 2024, 11:09pm UTC](https://forum.juce.com/t/bug-the-result-of-graphics-drawtext-is-sometimes-incorrect/61950 "2024-06-21T23:09:20Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![kbinani](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/kbinani/32/18777_2.png) [@kbinani](https://forum.juce.com/u/kbinani)\
**Post date:** [June 21, 2024, 11:09pm UTC](https://forum.juce.com/t/bug-the-result-of-graphics-drawtext-is-sometimes-incorrect/61950/1 "2024-06-21T23:09:20Z")

</div>

When displaying “1.19.0 [1]” using drawText(“1.19.0 [1]”, …) in JUCE 8, it appears as “1.19.0] 1]” like this:

![example](https://us1.discourse-cdn.com/flex026/uploads/juce/original/3X/4/4/44226fa3d3c9fe80d72acd133c3d668a9d932df9.png)

My environments are Windows 11 and MacOS Sonoma 14.1.1, and both experience a similar issue. The JUCE version is 8 (commit hash 61a03097ec9e01693c87ac71935e97b9714cff1a at the 8.0.0 tag).

This issue can be reproduced with the following steps:

1. Open examples\DemoRunner\Builds\VisualStudio2022\DemoRunner.sln, build, and run it.
2. From “Browse Demos,” select “GUI,” then “CodeEditorDemo.h,” and input “1.19.0 [1]” in the code editor.
3. It will be rendered as “1.19.0] 1]”.

I have determined that Graphics::ConfiguredArrangement::arrangement already contains glyphs in the incorrect order when rendered, but I could not identify the root cause.

Is anyone else experiencing a similar issue?

---

<div class="post-metadata">

**Author:** ![cvural](https://avatars.discourse-cdn.com/v4/letter/c/e19b73/32.png) [@cvural](https://forum.juce.com/u/cvural)\
**Post date:** [June 23, 2024, 5:51pm UTC](https://forum.juce.com/t/bug-the-result-of-graphics-drawtext-is-sometimes-incorrect/61950/2 "2024-06-23T17:51:55Z")

</div>

+1

MacOS 14.5 Sonoma , JUCE 8

Also : 1.19.0 (1) → 1.19.0 )1)

---

<div class="post-metadata">

**Author:** ![kbinani](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/kbinani/32/18777_2.png) [@kbinani](https://forum.juce.com/u/kbinani)\
**Post date:** [June 30, 2024, 4:50pm UTC](https://forum.juce.com/t/bug-the-result-of-graphics-drawtext-is-sometimes-incorrect/61950/3 "2024-06-30T16:50:17Z")

</div>

I think I’ve identified the cause of the problem. In the implementation of the Unicode Bidi Algorithm, when classifying characters within brackets, according to [UAX #9: Unicode Bidirectional Algorithm](https://www.unicode.org/reports/tr9/#N0)

> Note that EN and AN should be treated as a strong R type when searching within the brackets.

It seems that the implementation of this part in JUCE is incomplete.

Here is the patch to fix it: [Unicode: Categorize numerics as strong R type when searching within b… · kbinani/JUCE@6b10240 · GitHub](https://github.com/kbinani/JUCE/commit/6b102406d2d86ffd73af5993496eb96cb89aed78)

I hope this report can be helpful to someone.

---

<div class="post-metadata">

**Author:** ![AlexandreFrazao](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/alexandrefrazao/32/18245_2.png) [@AlexandreFrazao](https://forum.juce.com/u/AlexandreFrazao)\
**Post date:** [July 3, 2024, 9:02am UTC](https://forum.juce.com/t/bug-the-result-of-graphics-drawtext-is-sometimes-incorrect/61950/4 "2024-07-03T09:02:35Z")

</div>

Hi, thanks for the suggested fix.

This seems to fix the drawing issue at first glance but still some inconsistencies “1/8 (3)” if we delete the last “)” the other one will invert.  
This will also happen when writing “1/8 (3” will output “1/8) 3”.

May I ask if you can also reproduce this one?

Ended up just forcing `TextDirection::ltr` on `getEmbeddingDirection` and `resolveNeutralTypes`

---

<div class="post-metadata">

**Author:** ![oli1](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/oli1/32/15664_2.png) [@oli1](https://forum.juce.com/u/oli1)\
**Post date:** [July 3, 2024, 2:34pm UTC](https://forum.juce.com/t/bug-the-result-of-graphics-drawtext-is-sometimes-incorrect/61950/5 "2024-07-03T14:34:57Z")

</div>

Thanks for submitting this. I originally had a case for dealing with numbers but it would fail certain specification tests. It looks like I was doing it in the wrong place.

---

<div class="post-metadata">

**Author:** ![kbinani](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/kbinani/32/18777_2.png) [@kbinani](https://forum.juce.com/u/kbinani)\
**Post date:** [July 4, 2024, 2:14am UTC](https://forum.juce.com/t/bug-the-result-of-graphics-drawtext-is-sometimes-incorrect/61950/6 "2024-07-04T02:14:35Z")

</div>

> This will also happen when writing “1/8 (3” will output “1/8) 3”.

This can be reproduced even after applying the patch, and it seems my patch is still incomplete.  
Thank you for pointing that out!

---

<div class="post-metadata">

**Author:** ![kbinani](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/kbinani/32/18777_2.png) [@kbinani](https://forum.juce.com/u/kbinani)\
**Post date:** [July 4, 2024, 2:15am UTC](https://forum.juce.com/t/bug-the-result-of-graphics-drawtext-is-sometimes-incorrect/61950/7 "2024-07-04T02:15:51Z")

</div>

Thank you for your reply.  
I have two apps on the Microsoft Store that use JUCE. Before JUCE 8, I had to bundle large font files with my apps to render non-Latin text, but that’s no longer necessary.  
Although there are some minor issues like this one, overall, I’m very satisfied with JUCE 8 😘  
I hope this issue will be fixed in future releases.

---

<div class="post-metadata">

**Author:** ![attila](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/attila/32/11206_2.png) [@attila](https://forum.juce.com/u/attila)\
**Post date:** [July 22, 2024, 9:09am UTC](https://forum.juce.com/t/bug-the-result-of-graphics-drawtext-is-sometimes-incorrect/61950/8 "2024-07-22T09:09:30Z")

</div>

A fix has been released on `develop`

> <https://github.com/juce-framework/JUCE/commit/57d33150d3453709065a7609665a98399baf39d1>
>
> This addresses issues that could occur when re-ordering text that
> contained brac…kets or numerical separators.
