# AttributedText on windows with Chinese Characters not working

**URL:** <https://forum.juce.com/t/attributedtext-on-windows-with-chinese-characters-not-working/56672>\
**Category:** General JUCE discussion\
**Created:** [June 15, 2023, 2:00pm UTC](https://forum.juce.com/t/attributedtext-on-windows-with-chinese-characters-not-working/56672 "2023-06-15T14:00:25Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![kunz](https://avatars.discourse-cdn.com/v4/letter/k/f19dbf/32.png) [@kunz](https://forum.juce.com/u/kunz)\
**Post date:** [June 15, 2023, 2:00pm UTC](https://forum.juce.com/t/attributedtext-on-windows-with-chinese-characters-not-working/56672/1 "2023-06-15T14:00:25Z")

</div>

Sorry for bringing up that topic again. Also one vote from me to make the fallback font work out of the box. Already spent too much time on this.

We try to show Chinese or Japanese filenames in a plugin. The filenames display correctly in the macOS finder and also in the Windows Explorer. Our plugin uses an embedded font that does not contain Chinese or Japanese symbols.

To make this work we replaced `g.drawText()` with an `AttributedText`. This worked on macOS. But it shows only an empty space on Windows.

I tried to set JUCE\_USE\_DIRECTWRITE=1 without any success. Embedding fallback fonts that contain all kinds of characters is no option for us because of their size.

What can we do to make this work?

---

<div class="post-metadata">

**Author:** ![anthony-nicholls](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/anthony-nicholls/32/1246_2.png) [@anthony-nicholls](https://forum.juce.com/u/anthony-nicholls)\
**Post date:** [June 16, 2023, 10:42am UTC](https://forum.juce.com/t/attributedtext-on-windows-with-chinese-characters-not-working/56672/2 "2023-06-16T10:42:26Z")

</div>

I’m afraid off the top of my head I don’t have an answer for what you can do right now, or why that isn’t working without taking a closer look. We are however currently working on full unicode support for a future release.

You said you can’t embed the fallback fonts due to the size. Have you considered alternative approaches such as downloading the font when required, or compressing the fonts before embedding them?

---

<div class="post-metadata">

**Author:** ![kunz](https://avatars.discourse-cdn.com/v4/letter/k/f19dbf/32.png) [@kunz](https://forum.juce.com/u/kunz)\
**Post date:** [June 16, 2023, 10:59am UTC](https://forum.juce.com/t/attributedtext-on-windows-with-chinese-characters-not-working/56672/3 "2023-06-16T10:59:48Z")

</div>

> [@anthony-nicholls](#):
>
> You said you can’t embed the fallback fonts due to the size. Have you considered alternative approaches such as downloading the font when required, or compressing the fonts before embedding them?

Great to hear that Unicode support is on the way. I’m trying to keep things as simple as possible and avoid any complicated installation process or network access. The font is still 15MB when compressed.

---

<div class="post-metadata">

**Author:** ![anthony-nicholls](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/anthony-nicholls/32/1246_2.png) [@anthony-nicholls](https://forum.juce.com/u/anthony-nicholls)\
**Post date:** [June 16, 2023, 11:16am UTC](https://forum.juce.com/t/attributedtext-on-windows-with-chinese-characters-not-working/56672/4 "2023-06-16T11:16:26Z")

</div>

If you haven’t already could you try using a [TextLayout](https://docs.juce.com/master/classTextLayout.html) to draw your `AttributedString`? Thanks.

---

<div class="post-metadata">

**Author:** ![anthony-nicholls](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/anthony-nicholls/32/1246_2.png) [@anthony-nicholls](https://forum.juce.com/u/anthony-nicholls)\
**Post date:** [June 16, 2023, 11:46am UTC](https://forum.juce.com/t/attributedtext-on-windows-with-chinese-characters-not-working/56672/5 "2023-06-16T11:46:23Z")

</div>

To be clear, to do this you probably just need some code like this…

```cpp
TextLayout layout;
layout.createLayout (attributedString, bounds.getWidth());
layout.draw (g, bounds);

```

---

<div class="post-metadata">

**Author:** ![otristan](https://avatars.discourse-cdn.com/v4/letter/o/f0a364/32.png) [@otristan](https://forum.juce.com/u/otristan)\
**Post date:** [June 16, 2023, 12:21pm UTC](https://forum.juce.com/t/attributedtext-on-windows-with-chinese-characters-not-working/56672/6 "2023-06-16T12:21:05Z")

</div>

AttributedString::draw does this FWIW

---

<div class="post-metadata">

**Author:** ![anthony-nicholls](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/anthony-nicholls/32/1246_2.png) [@anthony-nicholls](https://forum.juce.com/u/anthony-nicholls)\
**Post date:** [June 16, 2023, 12:52pm UTC](https://forum.juce.com/t/attributedtext-on-windows-with-chinese-characters-not-working/56672/7 "2023-06-16T12:52:18Z")

</div>

I think it only does that if `drawTextLayout` fails in the context. However looking deeper on Windows that’s only implemented in `Direct2DLowLevelGraphicsContext` so unless `JUCE_DIRECT2D` is enabled then you’re right that should already be happening. I had noticed another post that suggested this which is what made me think it might be worth trying.

---

<div class="post-metadata">

**Author:** ![kunz](https://avatars.discourse-cdn.com/v4/letter/k/f19dbf/32.png) [@kunz](https://forum.juce.com/u/kunz)\
**Post date:** [June 16, 2023, 1:04pm UTC](https://forum.juce.com/t/attributedtext-on-windows-with-chinese-characters-not-working/56672/8 "2023-06-16T13:04:09Z")

</div>

Yes, I also tried TextLayout with JUCE\_USE\_DIRECTWRITE=1 without any result. The same code works in macOS.

---

<div class="post-metadata">

**Author:** ![otristan](https://avatars.discourse-cdn.com/v4/letter/o/f0a364/32.png) [@otristan](https://forum.juce.com/u/otristan)\
**Post date:** [June 16, 2023, 1:15pm UTC](https://forum.juce.com/t/attributedtext-on-windows-with-chinese-characters-not-working/56672/9 "2023-06-16T13:15:30Z")

</div>

On Windows I have a special code for this as I don’t set the custom font if I need the fallback working otherwise it doesn’t  
The issue happen in juce internal if you don’t have a WindowsDirectWriteTypeface which is the case if you load a font from the HD.

```auto

    static bool canBeRepresented(juce::StringRef text)
    {
      for (auto t = text.text; !t.isEmpty();)
      {
        auto c = t.getAndAdvance();

        if (!(c < 0x024f || (c >= 0x2000 && c < 0x20d0))) // latin char and punctuation
          return false;
      }

      return true;
    }

```

---

<div class="post-metadata">

**Author:** ![otristan](https://avatars.discourse-cdn.com/v4/letter/o/f0a364/32.png) [@otristan](https://forum.juce.com/u/otristan)\
**Post date:** [June 16, 2023, 1:17pm UTC](https://forum.juce.com/t/attributedtext-on-windows-with-chinese-characters-not-working/56672/10 "2023-06-16T13:17:26Z")

</div>

Just tried to not set your custom font and you ll see that the fallback is working

---

<div class="post-metadata">

**Author:** ![otristan](https://avatars.discourse-cdn.com/v4/letter/o/f0a364/32.png) [@otristan](https://forum.juce.com/u/otristan)\
**Post date:** [June 16, 2023, 1:18pm UTC](https://forum.juce.com/t/attributedtext-on-windows-with-chinese-characters-not-working/56672/11 "2023-06-16T13:18:33Z")

</div>

In my case I don’t load the font using createSystemTypefaceFor so this is why… Maybe you do the same

---

<div class="post-metadata">

**Author:** ![kunz](https://avatars.discourse-cdn.com/v4/letter/k/f19dbf/32.png) [@kunz](https://forum.juce.com/u/kunz)\
**Post date:** [June 16, 2023, 1:37pm UTC](https://forum.juce.com/t/attributedtext-on-windows-with-chinese-characters-not-working/56672/12 "2023-06-16T13:37:45Z")

</div>

Ok, I see where this goes… Then I return getDefaultTypefaceForFont() in the LookAndFeel::getTypefaceForFont() method instead of one of my memory fonts in that case… I will try this.

---

<div class="post-metadata">

**Author:** ![kunz](https://avatars.discourse-cdn.com/v4/letter/k/f19dbf/32.png) [@kunz](https://forum.juce.com/u/kunz)\
**Post date:** [June 20, 2023, 8:09am UTC](https://forum.juce.com/t/attributedtext-on-windows-with-chinese-characters-not-working/56672/13 "2023-06-20T08:09:25Z")

</div>

Still working on this. I was able to make it work, but the whole thing is super fragile on Windows. I wanted to have a solution where I can have my own default font in `MyLookAndFeel::getTypefaceForFont()` and still have the fallback. At the moment I have no other idea than setting the font everywhere but not when I want the fallback.

Here are some problems with the Windows Direct Draw fallback when using embedded fonts:

- It does not work on windows out of the box.
- Fallback depends on the code in `MyLookAndFeel::getTypefaceForFont()`
- It needs the workaround @otristan mentioned above if you also want to use your own embedded fonts
- getStringWidth() also does not work without the workaround.
- The most important one: I would expect that it also works without the need for an `AttributedText`.

Edit: forgot almost the most important problem:

- TextEditor support for the fallback

@anthony-nicholls please also make this also work out of the box when you work on the Unicode support. I’m ready for testing 🙂

---

<div class="post-metadata">

**Author:** ![anthony-nicholls](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/anthony-nicholls/32/1246_2.png) [@anthony-nicholls](https://forum.juce.com/u/anthony-nicholls)\
**Post date:** [June 20, 2023, 8:21am UTC](https://forum.juce.com/t/attributedtext-on-windows-with-chinese-characters-not-working/56672/14 "2023-06-20T08:21:43Z")

</div>

Thanks for reporting, I’ll pass the feedback on to the team.
