Skip to content

Commit

Permalink
Make combining marks inherit script
Browse files Browse the repository at this point in the history
Allow e.g. mixing Arabic and Hebrew Nikud.
  • Loading branch information
khaledhosny committed Apr 2, 2023
1 parent a8be04b commit 615cb15
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/raqm.c
Original file line number Diff line number Diff line change
Expand Up @@ -2017,6 +2017,22 @@ _get_pair_index (const uint32_t ch)
#define STACK_IS_EMPTY(script) ((script)->size <= 0)
#define IS_OPEN(pair_index) (((pair_index) & 1) == 0)

static hb_script_t
_raqm_unicode_script (hb_codepoint_t u)
{
static hb_unicode_funcs_t* unicode_funcs;

unicode_funcs = hb_unicode_funcs_get_default ();

/* Make combining marks inherit the script of their bases, regardless of
* their own script.
*/
if (hb_unicode_general_category (unicode_funcs, u) == HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK)
return HB_SCRIPT_INHERITED;

return hb_unicode_script (unicode_funcs, u);
}

/* Resolve the script for each character in the input string, if the character
* script is common or inherited it takes the script of the character before it
* except paired characters which we try to make them use the same script. We
Expand All @@ -2029,10 +2045,9 @@ _raqm_resolve_scripts (raqm_t *rq)
int last_set_index = -1;
hb_script_t last_script = HB_SCRIPT_INVALID;
_raqm_stack_t *stack = NULL;
hb_unicode_funcs_t* unicode_funcs = hb_unicode_funcs_get_default ();

for (size_t i = 0; i < rq->text_len; ++i)
rq->text_info[i].script = hb_unicode_script (unicode_funcs, rq->text[i]);
rq->text_info[i].script = _raqm_unicode_script (rq->text[i]);

#ifdef RAQM_TESTING
RAQM_TEST ("Before script detection:\n");
Expand Down
Binary file not shown.
1 change: 1 addition & 0 deletions tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ tests = [
'scripts-backward-rtl.test',
'scripts-backward.test',
'scripts-common.test',
'scripts-combinig-marks.test',
'scripts-forward-ltr.test',
'scripts-forward-rtl.test',
'scripts-forward.test',
Expand Down
46 changes: 46 additions & 0 deletions tests/scripts-combinig-marks.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
fonts/sha1sum/83db7d61f9292c18c951662f254f4ad038e41639.otf
عַرַبִي

Direction is: DEFAULT

Before script detection:
script for ch[0] Arab
script for ch[1] Zinh
script for ch[2] Arab
script for ch[3] Zinh
script for ch[4] Arab
script for ch[5] Zinh
script for ch[6] Arab

After script detection:
script for ch[0] Arab
script for ch[1] Arab
script for ch[2] Arab
script for ch[3] Arab
script for ch[4] Arab
script for ch[5] Arab
script for ch[6] Arab

Resolved direction is: RTL

Number of runs before script itemization: 1

BiDi Runs:
run[0]: start: 0 length: 7 level: 1

Number of runs after script itemization: 1

Final Runs:
run[0]: start: 0 length: 7 direction: rtl script: Arab font: Noto AH Test

Glyph information:
glyph [12] x_offset: 0 y_offset: 0 x_advance: 687 font: Noto AH Test
glyph [15] x_offset: 57 y_offset: -239 x_advance: 0 font: Noto AH Test
glyph [4] x_offset: 0 y_offset: 0 x_advance: 275 font: Noto AH Test
glyph [16] x_offset: -23 y_offset: -258 x_advance: 0 font: Noto AH Test
glyph [6] x_offset: 0 y_offset: 0 x_advance: 404 font: Noto AH Test
glyph [16] x_offset: 133 y_offset: -100 x_advance: 0 font: Noto AH Test
glyph [10] x_offset: 0 y_offset: 0 x_advance: 505 font: Noto AH Test

UTF-32 clusters: 06 04 04 02 02 00 00
UTF-8 clusters: 12 08 08 04 04 00 00

0 comments on commit 615cb15

Please sign in to comment.