BLF Bidirectional Text and Complex Shaping #100207

Open
opened 2022-08-04 19:08:19 +02:00 by Harley Acheson · 5 comments
Member

This task is for tracking the goals and implementation of bidirectional text layout and complex text shaping. Note that there might be many parts of this plan that could be (practically) impossible to do and are merely aspirational. Some definitions and explanations:

Bidirectional Text - https://en.wikipedia.org/wiki/Bidirectional_text

Blender currently only displays text left-to-right, which is what is expected for languages like English. However, there are languages - Arabic, Aramaic, Azeri, Dhivehi/Maldivian, Hebrew, Kurdish (Sorani), Persian/Farsi, Urdu - that are primarily right-to-left.

In our context this means that these languages have a display order that differs from their logical order, which remains LTR. When you append an extra character to the end of Arabic text, it is added to the end of the buffer or file, just like in English. It is only during the display of that string that it will (probably) be shown in reversed order.

In the preceding paragraphs I do use “primarily” and “probably” about the display order. This is because even when using only a RTL language there could be portions that are LTR. For example, numbers are shown LTR within strings that are RTL. The same goes for embedded and quoted text from other languages. To make this even more complex our need to support multiple languages simultaneously means that we need to support single strings containing multiple languages with multiple directions.

Complex Text Layout (shaping) - https://en.wikipedia.org/wiki/Complex_text_layout
This is the support of complex scripts like Arabic, Brahmic (Indic) scripts, Devanagai, Khmer, and Thai. These scripts will often use different glyph depending on the position of the character in the word, and/or based on context. Sometimes individual glyphs will have a different order depending on context.

For many English-only users the idea of complex scripts can seem a bit weird. But in English we can hand-write text in either block letters or cursive. If English users had decided to only use cursive we might be faced with a similar situation today, where the glyphs used to display a string might vary depending on their positions relative to other characters in order to make it all join up nicely.

Ligatures - https://en.wikipedia.org/wiki/Ligature_(writing)

Supporting Ligatures (replacing some combinations of multiple characters with a different specific character) is a part of supporting complex scripts. But it is also used in other languages. In English layout we often will replace an “f” followed by an “I” with a single “fi” glyph so that the “tittle” of the “I” does not collide with the hood of the “f”. Turkish has some specific ligatures to help distinguish dotted and dottless “I”. Dutch can sometimes have separate glyphs for combined “ij” and “IJ”.

One new Ligature-related topic that we might not be able to support is programming-specific fixed-width fonts that use ligatures for ease of reading. For example, these fonts will often replace the character combination “!=” with “≠” and ">=" with "≥". Supporting these features with this type of font might be very difficult within our codebase for Text Editor but might be nice to do.

Implementation Challenges

Tasks

Patch
D15687: WIP: Bidirectional Text and Complex Shaping

This task is for tracking the goals and implementation of bidirectional text layout and complex text shaping. Note that there might be many parts of this plan that could be (practically) impossible to do and are merely aspirational. Some definitions and explanations: **Bidirectional Text** - https://en.wikipedia.org/wiki/Bidirectional_text Blender currently only displays text left-to-right, which is what is expected for languages like English. However, there are languages - Arabic, Aramaic, Azeri, Dhivehi/Maldivian, Hebrew, Kurdish (Sorani), Persian/Farsi, Urdu - that are primarily right-to-left. In our context this means that these languages have a *display* order that differs from their *logical* order, which remains LTR. When you append an extra character to the end of Arabic text, it is added to the end of the buffer or file, just like in English. It is only during the display of that string that it will (probably) be shown in reversed order. In the preceding paragraphs I do use “primarily” and “probably” about the display order. This is because even when using only a RTL language there could be portions that are LTR. For example, numbers are shown LTR within strings that are RTL. The same goes for embedded and quoted text from other languages. To make this even more complex our need to support multiple languages simultaneously means that we need to support single strings containing multiple languages with multiple directions. **Complex Text Layout (shaping)** - https://en.wikipedia.org/wiki/Complex_text_layout This is the support of complex scripts like Arabic, Brahmic (Indic) scripts, Devanagai, Khmer, and Thai. These scripts will often use different glyph depending on the position of the character in the word, and/or based on context. Sometimes individual glyphs will have a different order depending on context. For many English-only users the idea of complex scripts can seem a bit weird. But in English we can hand-write text in either block letters or cursive. If English users had decided to only use cursive we might be faced with a similar situation today, where the glyphs used to display a string might vary depending on their positions relative to other characters in order to make it all join up nicely. **Ligatures** - https://en.wikipedia.org/wiki/Ligature_(writing) Supporting Ligatures (replacing some combinations of multiple characters with a different specific character) is a part of supporting complex scripts. But it is also used in other languages. In English layout we often will replace an “f” followed by an “I” with a single “fi” glyph so that the “tittle” of the “I” does not collide with the hood of the “f”. Turkish has some specific ligatures to help distinguish dotted and dottless “I”. Dutch can sometimes have separate glyphs for combined “ij” and “IJ”. One new Ligature-related topic that we might not be able to support is programming-specific fixed-width fonts that use ligatures for ease of reading. For example, these fonts will often replace the character combination “!=” with “≠” and ">=" with "≥". Supporting these features with this type of font might be very difficult within our codebase for Text Editor but might be nice to do. **Implementation Challenges** **Tasks** **Patch** [D15687: WIP: Bidirectional Text and Complex Shaping](https://archive.blender.org/developer/D15687)
Harley Acheson self-assigned this 2022-08-04 19:08:19 +02:00
Author
Member

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'
Author
Member

Added subscriber: @Harley

Added subscriber: @Harley
Philipp Oeser removed the
Interest
User Interface
label 2023-02-10 09:21:50 +01:00

@Harley I made a bidi text rendering system when I was working on a small experimental game engine, it supported arabic/urdu/faarsi ...

I wonder if I may be of service here in anyway. I'd love to contribute to Blender to land full text support ASAP.
This is especially crucial for the switch to the Geo Nodes system, text animation is impossible currently for arabic (...) text in Geo Nodes.

@Harley I made a bidi text rendering system when I was working on a small experimental game engine, it supported arabic/urdu/faarsi ... I wonder if I may be of service here in anyway. I'd love to contribute to Blender to land full text support ASAP. This is especially crucial for the switch to the Geo Nodes system, text animation is impossible currently for arabic (...) text in Geo Nodes.
Author
Member

@alba-delba - I wonder if I may be of service here in anyway.

Yes, there would be many ways for you to help with this, regardless of how much programming experience you have or experience with the Blender source. I mostly will need assistance from programmers of any ability that are native speakers of an RTL language. Bonus if you have experience with Harfbuzz and FriBiDi. I am an English-speaking Canadian so I have no direct experience in using RTL languages.

I have a PR, #104662, that was meant to bring full RTL support in the blender interface itself. For example having objects with Arabic names. Displaying RTL was fairly straightforward, with the difficult (and partially unworking) parts are all about interacting with such text afterward. Inserting the text cursor with your mouse, using arrow keys to move that cursor, selecting ranges of characters, etc. In that PR my target included the selection of mixed-direction text, so strings that includes multiple languages in different directions.

But that PR can be largely seen as a proof of concept and something I can draw from going forward. I can't currently devote the time needed to get this particular PR in a shape that it could merged any time soon. Instead...

For a first step I am going to make HarfBuzz and Fribidi optional components of our builds. Those libraries are now part of our project, but there are a number of steps that must be taken to use them, changes to build files, platform-specific changes, etc. Basically the "build_files" changes in 104662. If I do this then anyone can experiment with these libraries by changing a build option.

Another step I need to make is to change how Text Objects (and Geo Nodes) use our text output routines. Currently they deal with FreeType on their own and I want them to share code. You can read about those changes here: #110187

At that point we could consider doing RTL but only in Text Objects (and Nodes). To make it manageable I might have to restrict RTL languages to a single "run". As in a single string could not contain languages in multiple directions.

Further I will have to think through how editing of RTL strings could work. Right now if the output string is in a different order as the input string, or of differing length, it would be impossible to select characters, edit characters, etc. I might have to simplify things by treating the RTL output as single character (for now). I think the result would be bearable, with the major issue of not supporting being split over multiple lines. But that might be a good starting point that users would appreciate.

I am going to be away at the Blender Conference (flying out tomorrow morning) and then taking a holiday in England, flying back November 10th. So I will be away for a bit, although able to answer emails most days.

It would be useful if you could get yourself compiling the Blender sources, which is fairly straight-foward: https://wiki.blender.org/wiki/Building_Blender and reading the two documents above, and thinking about all this.

Cheers, Harley

> @alba-delba - I wonder if I may be of service here in anyway. Yes, there would be many ways for you to help with this, regardless of how much programming experience you have or experience with the Blender source. I mostly will need assistance from programmers of any ability that are native speakers of an RTL language. Bonus if you have experience with Harfbuzz and FriBiDi. I am an English-speaking Canadian so I have no direct experience in using RTL languages. I have a PR, https://projects.blender.org/blender/blender/pulls/104662, that was meant to bring full RTL support in the blender interface itself. For example having objects with Arabic names. Displaying RTL was fairly straightforward, with the difficult (and partially unworking) parts are all about interacting with such text afterward. Inserting the text cursor with your mouse, using arrow keys to move that cursor, selecting ranges of characters, etc. In that PR my _target_ included the selection of mixed-direction text, so strings that includes multiple languages in different directions. But that PR can be largely seen as a proof of concept and something I can draw from going forward. I can't currently devote the time needed to get this particular PR in a shape that it could merged any time soon. Instead... For a first step I am going to make HarfBuzz and Fribidi optional components of our builds. Those libraries are now part of our project, but there are a number of steps that must be taken to use them, changes to build files, platform-specific changes, etc. Basically the "build_files" changes in 104662. If I do this then anyone can experiment with these libraries by changing a build option. Another step I need to make is to change how Text Objects (and Geo Nodes) use our text output routines. Currently they deal with FreeType on their own and I want them to share code. You can read about those changes here: https://projects.blender.org/blender/blender/pulls/110187 At that point we could consider doing RTL but only in Text Objects (and Nodes). To make it manageable I might have to restrict RTL languages to a single "run". As in a single string could not contain languages in multiple directions. Further I will have to think through how editing of RTL strings could work. Right now if the output string is in a different order as the input string, or of differing length, it would be impossible to select characters, edit characters, etc. I might have to simplify things by treating the RTL output as single character (for now). I think the result would be bearable, with the major issue of not supporting being split over multiple lines. But that might be a good starting point that users would appreciate. I am going to be away at the Blender Conference (flying out tomorrow morning) and then taking a holiday in England, flying back November 10th. So I will be away for a bit, although able to answer emails most days. It would be useful if you could get yourself compiling the Blender sources, which is fairly straight-foward: https://wiki.blender.org/wiki/Building_Blender and reading the two documents above, and thinking about all this. Cheers, Harley

It would be useful if you could get yourself compiling the Blender sources, which is fairly straight-foward: https://wiki.blender.org/wiki/Building_Blender and reading the two documents above, and thinking about all this.

I followed the wiki, downloaded and built blender's latest version in lite mode using the pre-compiled libs.

> It would be useful if you could get yourself compiling the Blender sources, which is fairly straight-foward: https://wiki.blender.org/wiki/Building_Blender and reading the two documents above, and thinking about all this. I followed the wiki, downloaded and built blender's latest version in lite mode using the pre-compiled libs.
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#100207
No description provided.