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

Side by Side Diff: third_party/WebKit/Source/platform/fonts/shaping/ShapeResult.cpp

Issue 2875933006: [LayoutNG] Misc fixes in ShapingLineBreaker (Closed)
Patch Set: eae review + RTL snapping fixes Created 3 years, 7 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 Google Inc. All rights reserved. 2 * Copyright (c) 2012 Google Inc. All rights reserved.
3 * Copyright (C) 2013 BlackBerry Limited. All rights reserved. 3 * Copyright (C) 2013 BlackBerry Limited. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 ShapeResult::~ShapeResult() {} 176 ShapeResult::~ShapeResult() {}
177 177
178 size_t ShapeResult::ByteSize() const { 178 size_t ShapeResult::ByteSize() const {
179 size_t self_byte_size = sizeof(this); 179 size_t self_byte_size = sizeof(this);
180 for (unsigned i = 0; i < runs_.size(); ++i) { 180 for (unsigned i = 0; i < runs_.size(); ++i) {
181 self_byte_size += runs_[i]->ByteSize(); 181 self_byte_size += runs_[i]->ByteSize();
182 } 182 }
183 return self_byte_size; 183 return self_byte_size;
184 } 184 }
185 185
186 unsigned ShapeResult::StartIndexForResult() const {
187 return !Rtl() ? runs_.front()->start_index_ : runs_.back()->start_index_;
188 }
189
190 unsigned ShapeResult::EndIndexForResult() const {
191 return StartIndexForResult() + NumCharacters();
192 }
193
194 // If the position is outside of the result, returns the start or the end offset
195 // depends on the position.
186 unsigned ShapeResult::OffsetForPosition(float target_x, 196 unsigned ShapeResult::OffsetForPosition(float target_x,
187 bool include_partial_glyphs) const { 197 bool include_partial_glyphs) const {
188 unsigned characters_so_far = 0; 198 unsigned characters_so_far = 0;
189 float current_x = 0; 199 float current_x = 0;
190 200
191 if (Rtl()) { 201 if (Rtl()) {
202 if (target_x <= 0)
203 return num_characters_;
192 characters_so_far = num_characters_; 204 characters_so_far = num_characters_;
193 for (unsigned i = 0; i < runs_.size(); ++i) { 205 for (unsigned i = 0; i < runs_.size(); ++i) {
194 if (!runs_[i]) 206 if (!runs_[i])
195 continue; 207 continue;
196 characters_so_far -= runs_[i]->num_characters_; 208 characters_so_far -= runs_[i]->num_characters_;
197 float next_x = current_x + runs_[i]->width_; 209 float next_x = current_x + runs_[i]->width_;
198 float offset_for_run = target_x - current_x; 210 float offset_for_run = target_x - current_x;
199 if (offset_for_run >= 0 && offset_for_run <= runs_[i]->width_) { 211 if (offset_for_run >= 0 && offset_for_run <= runs_[i]->width_) {
200 // The x value in question is within this script run. 212 // The x value in question is within this script run.
201 const unsigned index = runs_[i]->CharacterIndexForXPosition( 213 const unsigned index = runs_[i]->CharacterIndexForXPosition(
202 offset_for_run, include_partial_glyphs); 214 offset_for_run, include_partial_glyphs);
203 return characters_so_far + index; 215 return characters_so_far + index;
204 } 216 }
205 current_x = next_x; 217 current_x = next_x;
206 } 218 }
207 } else { 219 } else {
220 if (target_x <= 0)
221 return 0;
208 for (unsigned i = 0; i < runs_.size(); ++i) { 222 for (unsigned i = 0; i < runs_.size(); ++i) {
209 if (!runs_[i]) 223 if (!runs_[i])
210 continue; 224 continue;
211 float next_x = current_x + runs_[i]->width_; 225 float next_x = current_x + runs_[i]->width_;
212 float offset_for_run = target_x - current_x; 226 float offset_for_run = target_x - current_x;
213 if (offset_for_run >= 0 && offset_for_run <= runs_[i]->width_) { 227 if (offset_for_run >= 0 && offset_for_run <= runs_[i]->width_) {
214 const unsigned index = runs_[i]->CharacterIndexForXPosition( 228 const unsigned index = runs_[i]->CharacterIndexForXPosition(
215 offset_for_run, include_partial_glyphs); 229 offset_for_run, include_partial_glyphs);
216 return characters_so_far + index; 230 return characters_so_far + index;
217 } 231 }
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 result->width_ = run->width_; 485 result->width_ = run->width_;
472 result->num_glyphs_ = count; 486 result->num_glyphs_ = count;
473 DCHECK_EQ(result->num_glyphs_, count); // no overflow 487 DCHECK_EQ(result->num_glyphs_, count); // no overflow
474 result->has_vertical_offsets_ = 488 result->has_vertical_offsets_ =
475 font_data->PlatformData().IsVerticalAnyUpright(); 489 font_data->PlatformData().IsVerticalAnyUpright();
476 result->runs_.push_back(std::move(run)); 490 result->runs_.push_back(std::move(run));
477 return result.Release(); 491 return result.Release();
478 } 492 }
479 493
480 } // namespace blink 494 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698