/// <summary> /// Fixes the provided string /// </summary> /// <param name="input">Text to fix</param> /// <param name="output">Fixed text</param> /// <param name="fixTextTags"></param> /// <param name="preserveNumbers"></param> /// <param name="farsi"></param> /// <returns>Fixed text</returns> public static void FixRTL( string input, FastStringBuilder output, bool farsi = true, bool fixTextTags = true, bool preserveNumbers = false) { inputBuilder.SetValue(input); TashkeelFixer.RemoveTashkeel(inputBuilder); // The shape of the letters in shapeFixedLetters is fixed according to their position in word. But the flow of the text is not fixed. GlyphFixer.Fix(inputBuilder, glyphFixerOutput, preserveNumbers, farsi); //Restore tashkeel to their places. TashkeelFixer.RestoreTashkeel(glyphFixerOutput); // Fix flow of the text and put the result in FinalLetters field LigatureFixer.Fix(glyphFixerOutput, output, farsi, fixTextTags, preserveNumbers); if (fixTextTags) { RichTextFixer.Fix(output); } inputBuilder.Clear(); }
/// <summary> /// Fixes the shape of letters based on their position. /// </summary> /// <param name="input"></param> /// <param name="output"></param> /// <param name="preserveNumbers"></param> /// <param name="farsi"></param> /// <returns></returns> public static void Fix(FastStringBuilder input, FastStringBuilder output, bool preserveNumbers, bool farsi, bool fixTextTags) { FixYah(input, farsi); output.SetValue(input); for (int i = 0; i < input.Length; i++) { bool skipNext = false; int iChar = input.Get(i); // For special Lam Letter connections. if (iChar == (int)ArabicGeneralLetters.Lam) { if (i < input.Length - 1) { skipNext = HandleSpecialLam(input, output, i); if (skipNext) { iChar = output.Get(i); } } } // We don't want to fix tatweel or zwnj character if (iChar == (int)ArabicGeneralLetters.ArabicTatweel || iChar == (int)ArabicGeneralLetters.ZeroWidthNoJoiner) { continue; } if (iChar < 0xFFFF && TextUtils.IsGlyphFixedArabicCharacter((char)iChar)) { char converted = GlyphTable.Convert((char)iChar); if (IsMiddleLetter(input, i)) { output.Set(i, (char)(converted + 3)); } else if (IsFinishingLetter(input, i)) { output.Set(i, (char)(converted + 1)); } else if (IsLeadingLetter(input, i)) { output.Set(i, (char)(converted + 2)); } } // If this letter as Lam and special Lam-Alef connection was made, We want to skip the Alef // (Lam-Alef occupies 1 space) if (skipNext) { i++; } } if (!preserveNumbers) { if (fixTextTags) { FixNumbersOutsideOfTags(output, farsi); } else { FixNumbers(output, farsi); } } }