partly import changes from tenfourfox:

- #482: better bidi M1358275 M1392181 M1428774 + backbugs (e88a717ab)
- M1739352 M1732572(partial) M1717318(partial) M1586061 (03ffdeadb)
- M1737515 M1737470(no tests) +TLDs, tzdata (fd2b82f13)
This commit is contained in:
roytam1 2022-01-04 11:19:13 +08:00
commit 34231f343b
10 changed files with 311 additions and 278 deletions

View file

@ -5,6 +5,10 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsBidiUtils.h"
namespace mozilla {
static const uint32_t kMinRTLChar = 0x0590;
} // namespace mozilla;
#define ARABIC_TO_HINDI_DIGIT_INCREMENT (START_HINDI_DIGITS - START_ARABIC_DIGITS)
#define PERSIAN_TO_HINDI_DIGIT_INCREMENT (START_HINDI_DIGITS - START_FARSI_DIGITS)
#define ARABIC_TO_PERSIAN_DIGIT_INCREMENT (START_FARSI_DIGITS - START_ARABIC_DIGITS)
@ -82,16 +86,18 @@ nsresult HandleNumbers(char16_t* aBuffer, uint32_t aSize, uint32_t aNumFlag)
return NS_OK;
}
bool HasRTLChars(const nsAString& aString)
bool HasRTLChars(const char16_t* aText, uint32_t aLength)
{
// This is used to determine whether to enable bidi if a string has
// right-to-left characters. To simplify things, anything that could be a
// surrogate or RTL presentation form is covered just by testing >= 0xD800).
// It's fine to enable bidi in rare cases where it actually isn't needed.
int32_t length = aString.Length();
for (int32_t i = 0; i < length; i++) {
char16_t ch = aString.CharAt(i);
if (ch >= 0xD800 || IS_IN_BMP_RTL_BLOCK(ch)) {
// This is used to determine whether a string has right-to-left characters
// that mean it will require bidi processing.
const char16_t* cp = aText;
const char16_t* end = cp + aLength;
while (cp < end) {
char16_t ch = *cp++;
if (ch < mozilla::kMinRTLChar) {
continue;
}
if (UTF16_CODE_UNIT_IS_BIDI(ch) || IsBidiControlRTL(ch)) {
return true;
}
}