# String Arrays with LTR and RTL languages

**URL:** <https://discourse.processing.org/t/string-arrays-with-ltr-and-rtl-languages/45314>\
**Category:** Beginners\
**Created:** [November 10, 2024, 12:54pm UTC](https://discourse.processing.org/t/string-arrays-with-ltr-and-rtl-languages/45314 "2024-11-10T12:54:40Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bingo\_dan](https://avatars.discourse-cdn.com/v4/letter/b/e47774/32.png) [@Bingo\_dan](https://discourse.processing.org/u/Bingo_dan)\
**Post date:** [November 10, 2024, 12:54pm UTC](https://discourse.processing.org/t/string-arrays-with-ltr-and-rtl-languages/45314/1 "2024-11-10T12:54:40Z")

</div>

myJasonarray.json

```auto
[{ "animalsEnglish": ["dog", "cat", "fish", "horse"] }
  { "animalsHebrew": ["כלב", "חתול", "דג", "סוס"] } ]

```

Which is the zero’th index for animalsEnglish?  
Which is the Zero’th index for animalsHebrew?  
How does jre handle unicode in arrays?  
Will jre determine a RTL language and likewise count the zero’th index from RTL?  
Will I have to utilize unicode hex values in the array instead of strings?

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [November 10, 2024, 2:01pm UTC](https://discourse.processing.org/t/string-arrays-with-ltr-and-rtl-languages/45314/2 "2024-11-10T14:01:33Z")

</div>

Hello @Bingo_dan,

I was asked the other day if I use ChatGPT and for what?

It is useful for explaining code and code snippets and a potential starting point for pointing one in the right direction (or left!) with a caveat:  
_It can also be wrong at times !_

I do not often use ChatGPT but it has potential as a learning tool if used wisely.  
You still need to know what you are doing and be able to scrutinize responses.

\*\*\* _I did not glean through the response below and can’t comment on it._ \*\*\*

This was the response from ChatGPT simply pasting your question in:

> **ChatGPT response**
>
> Let’s go step by step to address your questions based on your `myJasonarray.json` file.
> 
> ### The JSON Format:
> 
> It appears that your JSON array is malformed, but assuming you meant to write it like this:
> 
> ```json
> [
> { "animalsEnglish": ["dog", "cat", "fish", "horse"] },
> { "animalsHebrew": ["כלב", "חתול", "דג", "סוס"] }
> ]
> 
> ```
> 
> ### Answering Your Questions:
> 
> 1. **Which is the 0th index for `animalsEnglish`?**  
> In the array `animalsEnglish`, the first (0th) element is `"dog"`. In JSON, indexing starts from 0. So:
> 
> 2. **Which is the 0th index for `animalsHebrew`?**  
> Similarly, for `animalsHebrew`:
> 
> 3. **How does the JRE handle Unicode in arrays?**  
> The Java Runtime Environment (JRE) handles Unicode natively. Java strings (and arrays containing strings) are internally encoded in UTF-16. This means that the characters like `"כלב"` in your array are properly stored and processed without needing any special handling. When you print or manipulate strings containing Unicode characters, Java will manage the encoding and decoding automatically, provided that your source files are saved in an appropriate encoding (like UTF-8).
> 
> 4. **Will the JRE determine a RTL language (Right-to-Left) and likewise count the 0th index from RTL?**  
> No, the JRE does not change the indexing based on the direction of the language. Indexing in arrays and lists is strictly 0-based (left-to-right) regardless of whether the language is RTL (Right-to-Left) like Hebrew or LTR (Left-to-Right) like English. The way text is rendered (i.e., from right to left for RTL languages) does not affect the underlying array structure or indexing. For instance:
> 
> 5. **Will I have to utilize Unicode hex values in the array instead of strings?**  
> No, you don’t have to use Unicode hex values in your JSON array. You can simply store the characters as strings, and the JRE will handle the Unicode encoding automatically. For example, the string `"כלב"` is perfectly valid and can be used directly in the array. You would only need to use Unicode escape sequences (e.g., `\u05db\u05dc\u05d1`) if you were dealing with a situation where raw Unicode characters were not possible, such as in environments where you have limited character encoding support.
> 
> In summary:
> 
> - **Indexing is based on the position in the array, not the language direction.**
> - **Unicode characters in strings (including RTL characters) are handled automatically by the JRE.**
> - **You don’t need to use Unicode hex values unless you encounter specific encoding issues.**
> 
> If you have any more questions about how the JRE handles Unicode or specific programming details, feel free to ask!

`:)`

---

<div class="post-metadata">

**Author:** ![Bingo\_dan](https://avatars.discourse-cdn.com/v4/letter/b/e47774/32.png) [@Bingo\_dan](https://discourse.processing.org/u/Bingo_dan)\
**Post date:** [November 10, 2024, 2:14pm UTC](https://discourse.processing.org/t/string-arrays-with-ltr-and-rtl-languages/45314/3 "2024-11-10T14:14:44Z")

</div>

> [@glv](#):
>
> **Will the JRE determine a RTL language (Right-to-Left) and likewise count the 0th index from RTL?**  
> No, the JRE does not change the indexing based on the direction of the language. Indexing in arrays and lists is strictly 0-based (left-to-right) regardless of whether the language is RTL (Right-to-Left) like Hebrew or LTR (Left-to-Right) like English.

Apparently, ChatGippity is contradicting itself. :sigh:  
If the above statement is correct, “סוס” would be the 0-index, counting from left-to-right.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [November 10, 2024, 4:00pm UTC](https://discourse.processing.org/t/string-arrays-with-ltr-and-rtl-languages/45314/4 "2024-11-10T16:00:03Z")

</div>

> [@Bingo\_dan](#):
>
> Which is the zero’th index for _animalsHebrew[]_?

For the way you have it posted: `["כלב", "חתול", "דג", "סוס"]`  
The [0] index is gonna be the last word `"כלב"`!

You can check that out by copying & pasting this line below on any browser console: [“כלב”, “חתול”, “דג”, “סוס”][0]`

And if we use our keyboard’s right key to navigate the line above letter-by letter, we’ll notice the cursor will jump to the end of the line and then it will start to move to the left!

Another clue something isn’t as we’d expect, that line is using space + comma `a ,a` rather the regular comma + space `a, a` style.

So the whole thing is RTL, thus creating a reversed array!

The workaround I’ve found was having each Hebrew word on a separate line:

```auto
[
  { "animalsEnglish": [
    "dog",
    "cat",
    "fish",
    "horse"
  ] },

  { "animalsHebrew": [
    "סוס",
    "דג",
    "חתול",
    "כלב"
  ] }
]

```

This way, we make sure the Hebrew strings won’t be in reversed order due to RTL:

```auto
[
    "סוס",
    "דג",
    "חתול",
    "כלב"
][0]

```

Gonna log `'סוס'` this time!

---

<div class="post-metadata">

**Author:** ![Bingo\_dan](https://avatars.discourse-cdn.com/v4/letter/b/e47774/32.png) [@Bingo\_dan](https://discourse.processing.org/u/Bingo_dan)\
**Post date:** [November 17, 2024, 4:47pm UTC](https://discourse.processing.org/t/string-arrays-with-ltr-and-rtl-languages/45314/5 "2024-11-17T16:47:55Z")

</div>

@GoToLoop OK. Writing each word on a separate line provides a little more control.  
I wouldn’t have thought the array would parse differently per line vs inline.  
I’ll have to explore these methods.  
Thank you for the suggestions.  
Now to get Processing running and test these for myself.

---

<div class="post-metadata">

**Author:** ![Bingo\_dan](https://avatars.discourse-cdn.com/v4/letter/b/e47774/32.png) [@Bingo\_dan](https://discourse.processing.org/u/Bingo_dan)\
**Post date:** [December 9, 2024, 9:29am UTC](https://discourse.processing.org/t/string-arrays-with-ltr-and-rtl-languages/45314/6 "2024-12-09T09:29:26Z")

</div>

I have installed the latest 4.3.1, and so now I have a working version of Processing to test which solutions will work with my project.

```auto
size(800, 600);
PFont mono;
mono = createFont("PortlandLdo-L394.ttf", 24);
background(0);
textFont(mono);
text("Word Here", 48, 100);
text("כלב", 96, 100);

```

The information in the code snippet is not what I see.  
This image is exactly what I see.

 ![Sketch-String-Test](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/2/d/2d24e447e69bef929587d70304d7e4133cb7f3cf.png)

When I run the Sketch, the first text item is visible but the second text item is not visible or not present.

---

<div class="post-metadata">

**Author:** ![George](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/george/32/5858_2.png) [@George](https://discourse.processing.org/u/George)\
**Post date:** [December 9, 2024, 11:02am UTC](https://discourse.processing.org/t/string-arrays-with-ltr-and-rtl-languages/45314/7 "2024-12-09T11:02:02Z")

</div>

> [@Bingo\_dan](#):
>
> ```auto
> size(800, 600);
> PFont mono;
> mono = createFont("PortlandLdo-L394.ttf", 24);
> background(0);
> textFont(mono);
> text("Word Here", 48, 100);
> text("כלב", 96, 100);
> 
> ```

This may relate to unicode character support:

1. what Processing app supports
2. what the font can display as well

The good news is there at least 1 version that should work in the Processing IDE:

- Go to **Preferences \> Interfaces and Fonts**
- Next to language tick the **Enable complex text input** checkbox
- In **Editor and Console font:** (above), select **Monospaced** (other fonts may work too, however not the current default (Source Code Pro) doesn’t))

Restart Processing to apply the changes and try again.

 ![Screenshot 2024-12-09 at 21.55.01](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/e/6/e6805b7b53880dde9b77830286faaa8477dcb694.jpeg)  
 ![Screenshot 2024-12-09 at 21.55.39](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/c/2/c29352f89e4b6ade98bdb0d334adf9bc3ebe3702.jpeg)

Hope this helps,  
George

---

<div class="post-metadata">

**Author:** ![Bingo\_dan](https://avatars.discourse-cdn.com/v4/letter/b/e47774/32.png) [@Bingo\_dan](https://discourse.processing.org/u/Bingo_dan)\
**Post date:** [December 9, 2024, 12:30pm UTC](https://discourse.processing.org/t/string-arrays-with-ltr-and-rtl-languages/45314/8 "2024-12-09T12:30:16Z")

</div>

It is useful. It helped me to understand better questions.  
The preferences dialog is buggy. Sometimes the font list box appears normally, inline, but often it is larger than the space and moves to the next line behind Edit Font Size.  
I installed opensiddur-hebrew-fonts in Arch Linux (I don’t have Monospaced).  
The files are present, but aren’t showing all of them in Processing Preferences.  
What directories is Processing checking to include fonts listed in the Preferences dialog?  
Not all available fonts are listing in Preferences.

Now my Processing editor shows Hebrew characters, Miriam Mono CLM, but running the sketch doesn’t display any Hebrew.

 ![sketch-string-test_new-font-install](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/f/c/fcbad6ddb4d58b9bc1e7b87d73afdd697f46807f.png)

What is needed for the sketch run/play to display the font?

---

<div class="post-metadata">

**Author:** ![Bingo\_dan](https://avatars.discourse-cdn.com/v4/letter/b/e47774/32.png) [@Bingo\_dan](https://discourse.processing.org/u/Bingo_dan)\
**Post date:** [December 9, 2024, 12:42pm UTC](https://discourse.processing.org/t/string-arrays-with-ltr-and-rtl-languages/45314/9 "2024-12-09T12:42:24Z")

</div>

That is a great answer. Very helpful in identifying the arrays structure.  
From there I can determine the structure and make changes to get the array to form as I need for further use.  
I can’t verify anything yet, though. I need to get font issues sorted out.  
When that is complete, I’ll run through the solutions to see which one is best for my project.  
Thanks.

---

<div class="post-metadata">

**Author:** ![Bingo\_dan](https://avatars.discourse-cdn.com/v4/letter/b/e47774/32.png) [@Bingo\_dan](https://discourse.processing.org/u/Bingo_dan)\
**Post date:** [December 9, 2024, 1:51pm UTC](https://discourse.processing.org/t/string-arrays-with-ltr-and-rtl-languages/45314/10 "2024-12-09T13:51:18Z")

</div>

I didn’t click the reply button in your space that would show my response related to yours.  
Sorry about that.

---

<div class="post-metadata">

**Author:** ![George](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/george/32/5858_2.png) [@George](https://discourse.processing.org/u/George)\
**Post date:** [December 12, 2024, 7:00pm UTC](https://discourse.processing.org/t/string-arrays-with-ltr-and-rtl-languages/45314/11 "2024-12-12T19:00:45Z")

</div>

No worries at all, no time on my side anyway 🙂

I didn’t realise you’re on ArchLinux. I don’t have experience with it yet.  
I did a quick search and found [Arch Linux Fonts](https://wiki.archlinux.org/title/Fonts). Hopefully there’s a font there with the character support you need. (Doing another search I can find the Monospaced font in multiple places, including [github](https://github.com/chrissimpkins/codeface/blob/master/fonts/monospace/Monospace.ttf)).

> The files are present, but aren’t showing all of them in Processing Preferences.  
> What directories is Processing checking to include fonts listed in the Preferences dialog?  
> Not all available fonts are listing in Preferences.

It might be that Processing Preferences doesn’t list all fonts, but filters monospaced fonts. (see. [`getMonoFontList()`](https://github.com/processing/processing4/blob/main/app/src/processing/app/ui/Toolkit.java#L1176) and [`getMonoFont(int size, int style)`](https://github.com/processing/processing4/blob/main/app/src/processing/app/ui/Toolkit.java#L1250)).

I can’t easily replicate your ArchLinux setup at the moment, however I’d try something like this:

- check what monospaced .ttf fonts are already on ArchLinux (in a public/default font location).
- double check the font characters you need are present (might need [gnome-font-viewer](https://archlinux.org/packages/extra/x86_64/gnome-font-viewer/) or similar)
- if installing a new monospaced font with the character set you need, restart processing, then check if it shows up in Preferences.

I wish I could be more helpful than this.  
Best of luck!

---

<div class="post-metadata">

**Author:** ![Bingo\_dan](https://avatars.discourse-cdn.com/v4/letter/b/e47774/32.png) [@Bingo\_dan](https://discourse.processing.org/u/Bingo_dan)\
**Post date:** [December 15, 2024, 9:58am UTC](https://discourse.processing.org/t/string-arrays-with-ltr-and-rtl-languages/45314/12 "2024-12-15T09:58:30Z")

</div>

What I’ve learned:  
Processing focuses on Mono Fonts.  
Previously, I believed any font will do. I assumed running an application was ‘painting’ a canvas. Apparently, that isn’t what is happening.  
I have to determine, of the fonts I want to use, which ones are Mono.  
I may decide to reorganize Font/folders into TTF and TTF-mono if that indeed is the solution.

What I often use, when I need to, is Font-Manager. Although, I don’t recall if it identifies whether a font is mono or not.

For any program I have used, I have never needed to know whether a font is mono or not.  
All of my graphics tools, inkscape, gimp except any font I choose.

Edit:

- found this solution for Linux
- The command `fc-list` can list all available fonts according to their properties. In your case one needs to search for the **spacing** corresponding to **mono** , that would be **100** , so `fc-list :spacing=100`. Simpler form `fc-list :mono` should probably work too.\*
- [unix.stackexchange.com](http://unix.stackexchange.com)\*

The Guidance is helping.

---

<div class="post-metadata">

**Author:** ![George](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/george/32/5858_2.png) [@George](https://discourse.processing.org/u/George)\
**Post date:** [December 17, 2024, 9:47am UTC](https://discourse.processing.org/t/string-arrays-with-ltr-and-rtl-languages/45314/13 "2024-12-17T09:47:29Z")

</div>

Have a look at [PDE.properties](https://github.com/search?q=repo%3Aprocessing%2Fprocessing4%20font.family.mono&type=code) as well (and take into account different locales if you use a different system language other than english).

Hopefully you can edit the file and explicitly set the font 🤞

Best of luck

---

<div class="post-metadata">

**Author:** ![Bingo\_dan](https://avatars.discourse-cdn.com/v4/letter/b/e47774/32.png) [@Bingo\_dan](https://discourse.processing.org/u/Bingo_dan)\
**Post date:** [December 26, 2024, 1:50pm UTC](https://discourse.processing.org/t/string-arrays-with-ltr-and-rtl-languages/45314/14 "2024-12-26T13:50:58Z")

</div>

I found a resource which discussed how Java handles fonts, Included vs. Custom.  
Which means it is possible to use any Font.  
Trying to find one specific font in a sea of fonts is kinda like trying to cut down a forest with a razor blade. Font types are not always listed where fonts can be downloaded.  
To me, it seems like the longest path to the goal.

> Java has a wide range of fonts which comе by dеfault.  
> Whеn wе dеvеlop our Java applications, wе may nееd to dеsign them with custom fonts to makе things appеar morе clear in GUI.  
> Java supports thе intеgration of TruеTypе fonts (TTF) and OpеnTypе fonts (OTF) for custom font usagе.  
> Practically, thеsе fonts arеn’t inhеrеntly includеd in thе standard Java font library, nеcеssitating us to load thеm into our applications еxplicitly.  
> Lеt’s divе into thе stеps rеquirеd to load custom fonts in Java using thе following codе snippеt:  
> [https://www.baeldung.com/java-custom-font](https://www.baeldung.com/java-custom-font)

When I understand the article, having used what it promises, I’ll post back my results.
