From e45cb1544d03bb5b63cac61839dc3c4b42f046e0 Mon Sep 17 00:00:00 2001 From: Jonathan Kew Date: Mon, 5 Sep 2016 14:15:32 +0100 Subject: [PATCH] Bug 1296050 - When checking whether bidi resolution is needed, ignore Unicode directional-control characters that do not actually introduce right-to-left-ness. r=xidorn --- dom/base/nsTextFragment.cpp | 2 +- intl/unicharutil/util/nsBidiUtils.h | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/dom/base/nsTextFragment.cpp b/dom/base/nsTextFragment.cpp index 5473a615c738..260e254bed6b 100644 --- a/dom/base/nsTextFragment.cpp +++ b/dom/base/nsTextFragment.cpp @@ -461,7 +461,7 @@ nsTextFragment::UpdateBidiFlag(const char16_t* aBuffer, uint32_t aLength) char16_t ch2 = *cp++; utf32Char = SURROGATE_TO_UCS4(ch1, ch2); } - if (UTF32_CHAR_IS_BIDI(utf32Char) || IsBidiControl(utf32Char)) { + if (UTF32_CHAR_IS_BIDI(utf32Char) || IsBidiControlRTL(utf32Char)) { mState.mIsBidi = true; break; } diff --git a/intl/unicharutil/util/nsBidiUtils.h b/intl/unicharutil/util/nsBidiUtils.h index f002dd508a47..effe41861d68 100644 --- a/intl/unicharutil/util/nsBidiUtils.h +++ b/intl/unicharutil/util/nsBidiUtils.h @@ -111,10 +111,19 @@ typedef enum nsCharType nsCharType; * Return false, otherwise */ #define LRM_CHAR 0x200e +#define RLM_CHAR 0x200f + #define LRE_CHAR 0x202a +#define RLE_CHAR 0x202b +#define PDF_CHAR 0x202c +#define LRO_CHAR 0x202d #define RLO_CHAR 0x202e + #define LRI_CHAR 0x2066 +#define RLI_CHAR 0x2067 +#define FSI_CHAR 0x2068 #define PDI_CHAR 0x2069 + #define ALM_CHAR 0x061C inline bool IsBidiControl(uint32_t aChar) { return ((LRE_CHAR <= aChar && aChar <= RLO_CHAR) || @@ -123,6 +132,20 @@ typedef enum nsCharType nsCharType; (aChar & 0xfffffe) == LRM_CHAR); } + /** + * Give a UTF-32 codepoint + * Return true if the codepoint is a Bidi control character that may result + * in RTL directionality and therefore needs to trigger bidi resolution; + * return false otherwise. + */ + inline bool IsBidiControlRTL(uint32_t aChar) { + return aChar == RLM_CHAR || + aChar == RLE_CHAR || + aChar == RLO_CHAR || + aChar == RLI_CHAR || + aChar == ALM_CHAR; + } + /** * Give an nsString. * @return true if the string contains right-to-left characters