Skip to content

Add full Persian (FA) localization and improve Arabic-script font rendering (FreeType/Vazirmatn ) - #8808

Merged
joa-quim merged 2 commits into
GenericMappingTools:masterfrom
mohseniaref:feat/localization-fa
Oct 9, 2025
Merged

joa-quim merged 2 commits into
GenericMappingTools:masterfrom
mohseniaref:feat/localization-fa

Conversation

@mohseniaref

@mohseniaref mohseniaref commented Oct 9, 2025 •

Copy link
Copy Markdown
Contributor

Add full Persian (FA) localization + font rendering (Vazirmatn test)

Summary

I added new Persian (FA) localization files for GMT but still doesn't work:

You can see it in master...mohseniaref:gmt:feat/localization-fa

  • gmt_fa.locale → Persian (UTF-8)
  • gmt_fa_ascii.locale → ASCII transliteration fallback

Both work correctly for day/month names, but Persian text (e.g. شنبه, یکشنبه) does not render properly, even when FreeType and Fontconfig are enabled. Glyphs appear isolated (no Arabic shaping) and left-to-right.

Environment

Component Version
GMT 6.7.0_82093c8-dirty (built from master, 2025-10-09)
OS Ubuntu 24.04.1 LTS
FreeType 2.13.0
Fontconfig 2.15.0
Fonts tested Vazirmatn, Noto Naskh Arabic

Steps to Reproduce

gmt set PS_CHAR_ENCODING=Standard+
gmt set GMT_LANGUAGE=FA FORMAT_TIME_PRIMARY_MAP=full TIME_WEEK_START=Saturday
gmt set FONT_ANNOT_PRIMARY 12p,@/home/mohammad/.local/share/fonts/Vazirmatn-Regular.ttf,black
gmt begin fa_test pdf
  gmt basemap -R2025-01-04T/2025-01-11T/0/1 -JX12c/2c               -Bxa1K -Bya0.5 -BWSen+t"نمایش فارسی"
gmt end show

Result: Persian letters render unjoined or replaced with default Latin font.

Works fine

GMT_LANGUAGE=FA_ASCII (transliteration: Shanbeh, Yekshanbeh, etc.)

Request

  1. Add Persian (FA) and transliterated (FA_ASCII) locales to official GMT.
  2. Review and merge my branch feat/localization-fa.
  3. Investigate FreeType/HarfBuzz support for Arabic/Persian shaping and RTL text.

Thank you for maintaining GMT!
— Mohammad Mohseni Aref
University of Potsdam

@welcome

welcome Bot commented Oct 9, 2025

Copy link
Copy Markdown

💖 Thanks for opening this pull request! 💖

Please make sure you read our Contributing Guide and abide by our Code of Conduct.

A few things to keep in mind:

  • If you need help writing tests, take a look at the existing ones for inspiration. If you don't know where to start, let us know and we'll walk you through it.
  • All new features should be documented. It helps to write the comments below for your functions describing the it, all arguments, and return types before writing the code. This will help you think about your code design and results in better code.
  • We are grateful that you put in the effort to do this! 🎉

@mohseniaref
mohseniaref marked this pull request as draft October 9, 2025 11:54
@mohseniaref
mohseniaref marked this pull request as ready for review October 9, 2025 12:03
@joa-quim

joa-quim commented Oct 9, 2025

Copy link
Copy Markdown
Member

Why was that merge of master in this branch?

@Esteban82

Copy link
Copy Markdown
Member

Why was that merge of master in this branch?

Because it was out of date. Did I do something wrong?

@joa-quim

joa-quim commented Oct 9, 2025

Copy link
Copy Markdown
Member

Well, branches are always out of date. We don't have to permanently have them in sync with master. No problem with that as long as conflicts do not com in. I saw that the merge updated one .dvc file (can't find it anymore).

@Esteban82

Copy link
Copy Markdown
Member

Ok.

Can I merge this? I think it is ok.

@joa-quim

joa-quim commented Oct 9, 2025

Copy link
Copy Markdown
Member

Hmm, I wanted to ask @mohseniaref what he meant by

"Investigate FreeType/HarfBuzz support for Arabic/Persian shaping and RTL text."

Does this mean that this PR improves the situation of the Farsi language but still leaves issues to be solved?

And, BTW, thank you @mohseniaref for this contribution.

(P.S. I knew that already, but always fun to see how the name of the region where I leave, Algarve, derived from the Gharb as in

# Compass directions (full names transliterated; abbreviations Latin)
C	1	Gharb		W	W

@mohseniaref

Copy link
Copy Markdown
Contributor Author

Reply to Developer Comment on Persian (FA) Localization

Thank you very much for your message!

Yes, exactly — this PR adds complete Persian (Farsi) localization (months, weekdays, etc.) and a transliterated FA_ASCII fallback, so Persian users can use GMT immediately in both native and ASCII-friendly modes.

However, the note about FreeType/HarfBuzz refers to the remaining limitation:
still GMT can not display Persian characters (via FreeType), it doesn’t yet perform text shaping (joining of Arabic letters and right-to-left layout).
HarfBuzz(https://github.com/harfbuzz/harfbuzz) might be the library that handles this correctly — for example, connecting letters like “شـنـبـه” into “شنبه”. I am trying to solve this issue with your help.

So, the localization part is solved , but full Persian rendering (proper joining and RTL direction) would still need HarfBuzz or another shaping engine in GMT’s text pipeline.


Additional context

Step-by-step: Register Vazirmatn (or any TTF/OTF) for GMT PostScript output

I have tried:

# Create the file ~/.gmt/PSL_custom_fonts.txt
mkdir -p ~/.gmt
nano ~/.gmt/PSL_custom_fonts.txt

Then added entries such as:

Vazirmatn-Regular    0.700    0
Vazirmatn-Bold       0.700    0

This allows GMT to recognize Persian-capable fonts for PostScript output, even without system-level font detection. I couldn't fix it so far for Persian language.


Rebuilding GMT with FreeType enabled

I rebuilt GMT manually to ensure FreeType was enabled:

cd ~/Software/gmt
rm -rf build
mkdir build && cd build

cmake ..   -DCMAKE_BUILD_TYPE=Release   -DCMAKE_INSTALL_PREFIX=$HOME/Software/gmt-install   -DGMT_ENABLE_FREETYPE=ON

make -j"$(nproc)"
make install

Again, thank you for reviewing and encouraging this addition — it’s great to make GMT more accessible to Persian-speaking researchers!
— Mohammad Mohseni Aref

@joa-quim

joa-quim commented Oct 9, 2025

Copy link
Copy Markdown
Member

OK, I'll merge this. As for the remaining difficulties ... we will see. Don't know how much we can help but hatfbuzz seems to be a c++ dependency. That would difficult to add and I'm not even seeing the level of technical difficulties involved.
And, BTW, does this make any difference? -DGMT_ENABLE_FREETYPE=ON
We don't have freetype on our list of dependencies.

@joa-quim
joa-quim merged commit 65461bd into GenericMappingTools:master Oct 9, 2025
@welcome

welcome Bot commented Oct 9, 2025

Copy link
Copy Markdown

🎉🎉🎉 Congrats on merging your first pull request and welcome to the team! 🎉🎉🎉

We hope that this was a good experience for you. Let us know if there is any way that the contributing process could be improved.

@Esteban82 Esteban82 added the add-changelog Add PR to the changelog label Oct 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

add-changelog Add PR to the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants