Skip to content

Commit 7b87135

Browse files
committed
Fixed parenthesis problem in RTL language
1 parent ea03bcb commit 7b87135

File tree

5 files changed

+959
-122
lines changed

5 files changed

+959
-122
lines changed

Assets/RTLTMPro/RTLSupport.cs

Lines changed: 103 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@ protected virtual char[] FixGlyphs(char[] letters)
482482
}
483483
}
484484

485+
485486
// If this letter as Lam and special Lam-Alef connection was made, We want to skip the Alef
486487
// (Lam-Alef occupies 1 space)
487488
if (skipNext)
@@ -549,8 +550,8 @@ protected virtual void FixLigature(IList<char> shapeFixedLetters)
549550
for (int i = shapeFixedLetters.Count - 1; i >= 0; i--)
550551
{
551552
bool isInMiddle = i > 0 && i < shapeFixedLetters.Count - 1;
552-
bool isAtEnd = i == shapeFixedLetters.Count - 1;
553-
bool isAtBegining = i == 0;
553+
bool isAtBegining = i == shapeFixedLetters.Count - 1;
554+
bool isAtEnd = i == 0;
554555

555556
if (char.IsPunctuation(shapeFixedLetters[i]) || char.IsSymbol(shapeFixedLetters[i]))
556557
{
@@ -561,7 +562,7 @@ protected virtual void FixLigature(IList<char> shapeFixedLetters)
561562
// We need to check if it is actually the begining of a tag.
562563
bool valid = false;
563564
// If > is at the end of the text (At begining of the array), it can't be a tag
564-
if (isAtBegining == false)
565+
if (isAtEnd == false)
565566
{
566567
for (int j = i - 1; j >= 0; j--)
567568
{
@@ -592,6 +593,99 @@ protected virtual void FixLigature(IList<char> shapeFixedLetters)
592593
}
593594
}
594595

596+
if (shapeFixedLetters[i] == ')')
597+
{
598+
if (isInMiddle)
599+
{
600+
bool isAfterRTLCharacter = IsRTLCharacter(shapeFixedLetters[i + 1]);
601+
bool isBeforeRTLCharacter = IsRTLCharacter(shapeFixedLetters[i - 1]);
602+
603+
if (isAfterRTLCharacter || isBeforeRTLCharacter)
604+
shapeFixedLetters[i] = '(';
605+
}
606+
else if (isAtEnd)
607+
{
608+
bool isAfterRTLCharacter = IsRTLCharacter(shapeFixedLetters[i + 1]);
609+
if (isAfterRTLCharacter)
610+
shapeFixedLetters[i] = '(';
611+
}
612+
else if (isAtBegining)
613+
{
614+
bool isBeforeRTLCharacter = IsRTLCharacter(shapeFixedLetters[i - 1]);
615+
if (isBeforeRTLCharacter)
616+
shapeFixedLetters[i] = '(';
617+
}
618+
}
619+
else if (shapeFixedLetters[i] == '(')
620+
{
621+
if (isInMiddle)
622+
{
623+
bool isAfterRTLCharacter = IsRTLCharacter(shapeFixedLetters[i + 1]);
624+
bool isBeforeRTLCharacter = IsRTLCharacter(shapeFixedLetters[i - 1]);
625+
626+
if (isAfterRTLCharacter || isBeforeRTLCharacter)
627+
shapeFixedLetters[i] = ')';
628+
}
629+
else if (isAtEnd)
630+
{
631+
bool isAfterRTLCharacter = IsRTLCharacter(shapeFixedLetters[i + 1]);
632+
if (isAfterRTLCharacter)
633+
shapeFixedLetters[i] = ')';
634+
}
635+
else if (isAtBegining)
636+
{
637+
bool isBeforeRTLCharacter = IsRTLCharacter(shapeFixedLetters[i - 1]);
638+
if (isBeforeRTLCharacter)
639+
shapeFixedLetters[i] = ')';
640+
}
641+
}
642+
else if (shapeFixedLetters[i] == '«')
643+
{
644+
if (isInMiddle)
645+
{
646+
bool isAfterRTLCharacter = IsRTLCharacter(shapeFixedLetters[i + 1]);
647+
bool isBeforeRTLCharacter = IsRTLCharacter(shapeFixedLetters[i - 1]);
648+
649+
if (isAfterRTLCharacter || isBeforeRTLCharacter)
650+
shapeFixedLetters[i] = '»';
651+
}
652+
else if (isAtEnd)
653+
{
654+
bool isAfterRTLCharacter = IsRTLCharacter(shapeFixedLetters[i + 1]);
655+
if (isAfterRTLCharacter)
656+
shapeFixedLetters[i] = '»';
657+
}
658+
else if (isAtBegining)
659+
{
660+
bool isBeforeRTLCharacter = IsRTLCharacter(shapeFixedLetters[i - 1]);
661+
if (isBeforeRTLCharacter)
662+
shapeFixedLetters[i] = '»';
663+
}
664+
}
665+
else if (shapeFixedLetters[i] == '»')
666+
{
667+
if (isInMiddle)
668+
{
669+
bool isAfterRTLCharacter = IsRTLCharacter(shapeFixedLetters[i + 1]);
670+
bool isBeforeRTLCharacter = IsRTLCharacter(shapeFixedLetters[i - 1]);
671+
672+
if (isAfterRTLCharacter || isBeforeRTLCharacter)
673+
shapeFixedLetters[i] = '«';
674+
}
675+
else if (isAtEnd)
676+
{
677+
bool isAfterRTLCharacter = IsRTLCharacter(shapeFixedLetters[i + 1]);
678+
if (isAfterRTLCharacter)
679+
shapeFixedLetters[i] = '«';
680+
}
681+
else if (isAtBegining)
682+
{
683+
bool isBeforeRTLCharacter = IsRTLCharacter(shapeFixedLetters[i - 1]);
684+
if (isBeforeRTLCharacter)
685+
shapeFixedLetters[i] = '«';
686+
}
687+
}
688+
595689
if (isInMiddle)
596690
{
597691
// NOTE: Array is reversed. i + 1 is behind and i - 1 is ahead
@@ -613,11 +707,11 @@ protected virtual void FixLigature(IList<char> shapeFixedLetters)
613707
ltrText.Add(shapeFixedLetters[i]);
614708
}
615709
}
616-
else if (isAtBegining)
710+
else if (isAtEnd)
617711
{
618712
FinalLetters.Add(shapeFixedLetters[i]);
619713
}
620-
else if (isAtEnd)
714+
else if (isAtBegining)
621715
{
622716
ltrText.Add(shapeFixedLetters[i]);
623717
}
@@ -628,7 +722,7 @@ protected virtual void FixLigature(IList<char> shapeFixedLetters)
628722
{
629723
bool valid = false;
630724

631-
if (isAtEnd == false)
725+
if (isAtBegining == false)
632726
{
633727
for (int j = i + 1; j < shapeFixedLetters.Count; j++)
634728
{
@@ -793,7 +887,6 @@ protected virtual bool IsLeadingLetter(IList<char> letters, int index)
793887
letters[index - 1] == (int) GeneralLetters.AlefMaksoor ||
794888
letters[index - 1] == (int) GeneralLetters.ZeroWidthNoJoiner ||
795889
letters[index - 1] == (int) GeneralLetters.WawHamza ||
796-
797890
letters[index - 1] == (int) IsolatedLetters.Alef ||
798891
letters[index - 1] == (int) IsolatedLetters.Dal ||
799892
letters[index - 1] == (int) IsolatedLetters.Thal ||
@@ -865,10 +958,10 @@ protected virtual bool IsFinishingLetter(IList<char> letters, int index)
865958
IsRTLCharacter(letters[index - 1]);
866959

867960

868-
bool canThisLetterBeFinishing = letters[index] != ' ' &&
869-
letters[index] != (int) GeneralLetters.ZeroWidthNoJoiner &&
961+
bool canThisLetterBeFinishing = letters[index] != ' ' &&
962+
letters[index] != (int) GeneralLetters.ZeroWidthNoJoiner &&
870963
letters[index] != (int) GeneralLetters.Hamza;
871-
964+
872965
return isPreviousLetterConnectable && canThisLetterBeFinishing;
873966
}
874967

0 commit comments

Comments
 (0)