Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Unified Diff: ui/gfx/render_text_harfbuzz.cc

Issue 324983002: Move unusual character block logic to a helper function (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/render_text_harfbuzz.h ('k') | ui/gfx/render_text_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/render_text_harfbuzz.cc
diff --git a/ui/gfx/render_text_harfbuzz.cc b/ui/gfx/render_text_harfbuzz.cc
index 6e2be3a1b03871a134adb40ef6a2f6c8f4f57237..b5693d269680d27bc576c295e640b47bbd351f7d 100644
--- a/ui/gfx/render_text_harfbuzz.cc
+++ b/ui/gfx/render_text_harfbuzz.cc
@@ -277,6 +277,26 @@ 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))) {
+ return run_start + iter.array_pos();
+ }
+ }
+ 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.
@@ -908,22 +928,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));
style.UpdatePosition(LayoutIndexToTextIndex(run_break));
« no previous file with comments | « ui/gfx/render_text_harfbuzz.h ('k') | ui/gfx/render_text_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698