Index: ui/gfx/render_text_harfbuzz.cc |
diff --git a/ui/gfx/render_text_harfbuzz.cc b/ui/gfx/render_text_harfbuzz.cc |
index 138cd548c00e1653f8d85407b4b2c32cfdf719a5..368ec11c93740e2e8e2c82a61fa907c8e1e354c2 100644 |
--- a/ui/gfx/render_text_harfbuzz.cc |
+++ b/ui/gfx/render_text_harfbuzz.cc |
@@ -277,6 +277,27 @@ bool IsUnusualBlockCode(UBlockCode block_code) { |
block_code == UBLOCK_MISCELLANEOUS_SYMBOLS; |
} |
+// Returns the index of the first unusual character after a usual character or |
+// vice versa. Unusual characters are defined by |IsUnusualBlockCode|. |
+size_t FindUnusualCharacter(const base::string16& text, |
+ size_t run_start, |
+ size_t run_break) { |
+ const int32 run_length = static_cast<int32>(run_break - run_start); |
+ base::i18n::UTF16CharIterator iter(text.c_str() + run_start, |
+ run_length); |
+ const UBlockCode first_block_code = ublock_getCode(iter.get()); |
+ const bool first_block_unusual = IsUnusualBlockCode(first_block_code); |
+ while (iter.Advance() && iter.array_pos() < run_length) { |
+ const UBlockCode current_block_code = ublock_getCode(iter.get()); |
+ if (current_block_code != first_block_code && |
+ (first_block_unusual || IsUnusualBlockCode(current_block_code))) { |
+ run_break = run_start + iter.array_pos(); |
msw
2014/06/10 18:03:15
Just return run_start + iter.array_pos() here.
ckocagil
2014/06/11 07:49:37
Done.
|
+ break; |
+ } |
+ } |
+ return run_break; |
+} |
+ |
// If the given scripts match, returns the one that isn't USCRIPT_COMMON or |
// USCRIPT_INHERITED, i.e. the more specific one. Otherwise returns |
// USCRIPT_INVALID_CODE. |
@@ -904,22 +925,8 @@ void RenderTextHarfBuzz::ItemizeText() { |
// Break runs adjacent to character substrings in certain code blocks. |
// This avoids using their fallback fonts for more characters than needed, |
// in cases like "\x25B6 Media Title", etc. http://crbug.com/278913 |
- if (run_break > run->range.start()) { |
- const size_t run_start = run->range.start(); |
- const int32 run_length = static_cast<int32>(run_break - run_start); |
- base::i18n::UTF16CharIterator iter(text.c_str() + run_start, |
- run_length); |
- const UBlockCode first_block_code = ublock_getCode(iter.get()); |
- const bool first_block_unusual = IsUnusualBlockCode(first_block_code); |
- while (iter.Advance() && iter.array_pos() < run_length) { |
- const UBlockCode current_block_code = ublock_getCode(iter.get()); |
- if (current_block_code != first_block_code && |
- (first_block_unusual || IsUnusualBlockCode(current_block_code))) { |
- run_break = run_start + iter.array_pos(); |
- break; |
- } |
- } |
- } |
+ if (run_break > run->range.start()) |
+ run_break = FindUnusualCharacter(text, run->range.start(), run_break); |
} |
DCHECK(IsValidCodePointIndex(text, run_break)); |