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

Side by Side Diff: ui/gfx/render_text_harfbuzz.cc

Issue 594683002: RTHB: Limit text to 10k code units (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gfx/render_text_harfbuzz.h" 5 #include "ui/gfx/render_text_harfbuzz.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <map> 8 #include <map>
9 9
10 #include "base/i18n/bidi_line_iterator.h" 10 #include "base/i18n/bidi_line_iterator.h"
(...skipping 10 matching lines...) Expand all
21 #include "ui/gfx/utf16_indexing.h" 21 #include "ui/gfx/utf16_indexing.h"
22 22
23 #if defined(OS_WIN) 23 #if defined(OS_WIN)
24 #include "ui/gfx/font_fallback_win.h" 24 #include "ui/gfx/font_fallback_win.h"
25 #endif 25 #endif
26 26
27 namespace gfx { 27 namespace gfx {
28 28
29 namespace { 29 namespace {
30 30
31 // Text length limit. Longer strings are slow and not fully tested.
32 const size_t kMaxTextLength = 10000;
33
31 // The maximum number of scripts a Unicode character can belong to. This value 34 // The maximum number of scripts a Unicode character can belong to. This value
32 // is arbitrarily chosen to be a good limit because it is unlikely for a single 35 // is arbitrarily chosen to be a good limit because it is unlikely for a single
33 // character to belong to more scripts. 36 // character to belong to more scripts.
34 const size_t kMaxScripts = 5; 37 const size_t kMaxScripts = 5;
35 38
36 // Maps from code points to glyph indices in a font. 39 // Maps from code points to glyph indices in a font.
37 typedef std::map<uint32_t, uint16_t> GlyphCache; 40 typedef std::map<uint32_t, uint16_t> GlyphCache;
38 41
39 // Font data provider for HarfBuzz using Skia. Copied from Blink. 42 // Font data provider for HarfBuzz using Skia. Copied from Blink.
40 // TODO(ckocagil): Eliminate the duplication. http://crbug.com/368375 43 // TODO(ckocagil): Eliminate the duplication. http://crbug.com/368375
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 } 568 }
566 569
567 return Range(preceding_run_widths_int + cluster_begin_x, 570 return Range(preceding_run_widths_int + cluster_begin_x,
568 preceding_run_widths_int + cluster_end_x); 571 preceding_run_widths_int + cluster_end_x);
569 } 572 }
570 573
571 } // namespace internal 574 } // namespace internal
572 575
573 RenderTextHarfBuzz::RenderTextHarfBuzz() 576 RenderTextHarfBuzz::RenderTextHarfBuzz()
574 : RenderText(), 577 : RenderText(),
575 needs_layout_(false) {} 578 needs_layout_(false) {
579 set_truncate_length(kMaxTextLength);
580 }
576 581
577 RenderTextHarfBuzz::~RenderTextHarfBuzz() {} 582 RenderTextHarfBuzz::~RenderTextHarfBuzz() {}
578 583
579 Size RenderTextHarfBuzz::GetStringSize() { 584 Size RenderTextHarfBuzz::GetStringSize() {
580 const SizeF size_f = GetStringSizeF(); 585 const SizeF size_f = GetStringSizeF();
581 return Size(std::ceil(size_f.width()), size_f.height()); 586 return Size(std::ceil(size_f.width()), size_f.height());
582 } 587 }
583 588
584 SizeF RenderTextHarfBuzz::GetStringSizeF() { 589 SizeF RenderTextHarfBuzz::GetStringSizeF() {
585 EnsureLayout(); 590 EnsureLayout();
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after
1181 run->width = std::floor(run->width + 0.5f); 1186 run->width = std::floor(run->width + 0.5f);
1182 #endif 1187 #endif
1183 } 1188 }
1184 1189
1185 hb_buffer_destroy(buffer); 1190 hb_buffer_destroy(buffer);
1186 hb_font_destroy(harfbuzz_font); 1191 hb_font_destroy(harfbuzz_font);
1187 return true; 1192 return true;
1188 } 1193 }
1189 1194
1190 } // namespace gfx 1195 } // namespace gfx
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698