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

Unified Diff: ui/gfx/render_text_harfbuzz.cc

Issue 2630453005: RenderTextHarfBuzz: Don't draw newline glyph. (Closed)
Patch Set: -- Created 3 years, 11 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 | « no previous file | no next file » | 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 5b25f5b97861d5904c5038e2a3576d7012db26e8..1098d0b29953370626032f35212da5fd253321bd 100644
--- a/ui/gfx/render_text_harfbuzz.cc
+++ b/ui/gfx/render_text_harfbuzz.cc
@@ -205,6 +205,12 @@ inline hb_script_t ICUScriptToHBScript(UScriptCode script) {
return hb_script_from_string(uscript_getShortName(script), -1);
}
+// Whether |segment| corresponds to the newline character.
+bool IsNewlineSegment(const base::string16& text,
+ const internal::LineSegment& segment) {
+ return text[segment.char_range.start()] == '\n';
+}
+
// Helper template function for |TextRunHarfBuzz::GetClusterAt()|. |Iterator|
// can be a forward or reverse iterator type depending on the text direction.
template <class Iterator>
@@ -289,13 +295,14 @@ class HarfBuzzLineBreaker {
// the word to the current line.
bool new_line = false;
if (!word_segments.empty() &&
- text_[word_segments.back().char_range.start()] == '\n') {
+ IsNewlineSegment(text_, word_segments.back())) {
new_line = true;
// Since the line should at least contain some information regarding the
// text range it corresponds to, don't pop the newline segment, if it's
// the only segment in the line. This ensures that every line has a non-
- // empty segments vector (except the last in some cases).
+ // empty segments vector (except the last in some cases). This segment
+ // won't be drawn though.
if (word_segments.size() != 1u || available_width_ != max_width_) {
word_width -= word_segments.back().width();
word_segments.pop_back();
@@ -1216,6 +1223,10 @@ void RenderTextHarfBuzz::DrawVisualText(internal::SkiaTextRenderer* renderer) {
const Vector2d origin = GetLineOffset(i) + Vector2d(0, line.baseline);
SkScalar preceding_segment_widths = 0;
for (const internal::LineSegment& segment : line.segments) {
+ // Don't draw the newline glyph (crbug.com/680430).
+ if (IsNewlineSegment(GetDisplayText(), segment))
+ continue;
+
const internal::TextRunHarfBuzz& run = *run_list->runs()[segment.run];
renderer->SetTypeface(run.skia_face);
renderer->SetTextSize(SkIntToScalar(run.font_size));
« 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