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

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

Issue 2807913002: Replace ASSERT, ASSERT_NOT_REACHED, and RELEASE_ASSERT in platform/fonts (Closed)
Patch Set: rebase Created 3 years, 8 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 25 matching lines...) Expand all
36 #include "platform/fonts/Font.h" 36 #include "platform/fonts/Font.h"
37 #include "platform/fonts/shaping/ShapeResultInlineHeaders.h" 37 #include "platform/fonts/shaping/ShapeResultInlineHeaders.h"
38 #include "platform/fonts/shaping/ShapeResultSpacing.h" 38 #include "platform/fonts/shaping/ShapeResultSpacing.h"
39 #include "platform/wtf/PtrUtil.h" 39 #include "platform/wtf/PtrUtil.h"
40 40
41 namespace blink { 41 namespace blink {
42 42
43 float ShapeResult::RunInfo::XPositionForVisualOffset( 43 float ShapeResult::RunInfo::XPositionForVisualOffset(
44 unsigned offset, 44 unsigned offset,
45 AdjustMidCluster adjust_mid_cluster) const { 45 AdjustMidCluster adjust_mid_cluster) const {
46 ASSERT(offset < num_characters_); 46 DCHECK_LT(offset, num_characters_);
47 if (Rtl()) 47 if (Rtl())
48 offset = num_characters_ - offset - 1; 48 offset = num_characters_ - offset - 1;
49 return XPositionForOffset(offset, adjust_mid_cluster); 49 return XPositionForOffset(offset, adjust_mid_cluster);
50 } 50 }
51 51
52 float ShapeResult::RunInfo::XPositionForOffset( 52 float ShapeResult::RunInfo::XPositionForOffset(
53 unsigned offset, 53 unsigned offset,
54 AdjustMidCluster adjust_mid_cluster) const { 54 AdjustMidCluster adjust_mid_cluster) const {
55 ASSERT(offset <= num_characters_); 55 DCHECK_LE(offset, num_characters_);
56 const unsigned num_glyphs = glyph_data_.size(); 56 const unsigned num_glyphs = glyph_data_.size();
57 unsigned glyph_index = 0; 57 unsigned glyph_index = 0;
58 float position = 0; 58 float position = 0;
59 if (Rtl()) { 59 if (Rtl()) {
60 while (glyph_index < num_glyphs && 60 while (glyph_index < num_glyphs &&
61 glyph_data_[glyph_index].character_index > offset) { 61 glyph_data_[glyph_index].character_index > offset) {
62 position += glyph_data_[glyph_index].advance; 62 position += glyph_data_[glyph_index].advance;
63 ++glyph_index; 63 ++glyph_index;
64 } 64 }
65 // Adjust offset if it's not on the cluster boundary. In RTL, this means 65 // Adjust offset if it's not on the cluster boundary. In RTL, this means
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 261
262 // The position in question might be just after the text. 262 // The position in question might be just after the text.
263 if (!offset_x && absolute_offset == NumCharacters()) 263 if (!offset_x && absolute_offset == NumCharacters())
264 return Rtl() ? 0 : width_; 264 return Rtl() ? 0 : width_;
265 265
266 return offset_x; 266 return offset_x;
267 } 267 }
268 268
269 void ShapeResult::FallbackFonts( 269 void ShapeResult::FallbackFonts(
270 HashSet<const SimpleFontData*>* fallback) const { 270 HashSet<const SimpleFontData*>* fallback) const {
271 ASSERT(fallback); 271 DCHECK(fallback);
272 ASSERT(primary_font_); 272 DCHECK(primary_font_);
273 for (unsigned i = 0; i < runs_.size(); ++i) { 273 for (unsigned i = 0; i < runs_.size(); ++i) {
274 if (runs_[i] && runs_[i]->font_data_ && 274 if (runs_[i] && runs_[i]->font_data_ &&
275 runs_[i]->font_data_ != primary_font_ && 275 runs_[i]->font_data_ != primary_font_ &&
276 !runs_[i]->font_data_->IsTextOrientationFallbackOf( 276 !runs_[i]->font_data_->IsTextOrientationFallbackOf(
277 primary_font_.Get())) { 277 primary_font_.Get())) {
278 fallback->insert(runs_[i]->font_data_.Get()); 278 fallback->insert(runs_[i]->font_data_.Get());
279 } 279 }
280 } 280 }
281 } 281 }
282 282
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 } 335 }
336 336
337 static inline float HarfBuzzPositionToFloat(hb_position_t value) { 337 static inline float HarfBuzzPositionToFloat(hb_position_t value) {
338 return static_cast<float>(value) / (1 << 16); 338 return static_cast<float>(value) / (1 << 16);
339 } 339 }
340 340
341 void ShapeResult::InsertRun(std::unique_ptr<ShapeResult::RunInfo> run_to_insert, 341 void ShapeResult::InsertRun(std::unique_ptr<ShapeResult::RunInfo> run_to_insert,
342 unsigned start_glyph, 342 unsigned start_glyph,
343 unsigned num_glyphs, 343 unsigned num_glyphs,
344 hb_buffer_t* harf_buzz_buffer) { 344 hb_buffer_t* harf_buzz_buffer) {
345 ASSERT(num_glyphs > 0); 345 DCHECK_GT(num_glyphs, 0u);
346 std::unique_ptr<ShapeResult::RunInfo> run(std::move(run_to_insert)); 346 std::unique_ptr<ShapeResult::RunInfo> run(std::move(run_to_insert));
347 ASSERT(num_glyphs == run->glyph_data_.size()); 347 DCHECK_EQ(num_glyphs, run->glyph_data_.size());
348 348
349 const SimpleFontData* current_font_data = run->font_data_.Get(); 349 const SimpleFontData* current_font_data = run->font_data_.Get();
350 const hb_glyph_info_t* glyph_infos = 350 const hb_glyph_info_t* glyph_infos =
351 hb_buffer_get_glyph_infos(harf_buzz_buffer, 0); 351 hb_buffer_get_glyph_infos(harf_buzz_buffer, 0);
352 const hb_glyph_position_t* glyph_positions = 352 const hb_glyph_position_t* glyph_positions =
353 hb_buffer_get_glyph_positions(harf_buzz_buffer, 0); 353 hb_buffer_get_glyph_positions(harf_buzz_buffer, 0);
354 const unsigned start_cluster = 354 const unsigned start_cluster =
355 HB_DIRECTION_IS_FORWARD(hb_buffer_get_direction(harf_buzz_buffer)) 355 HB_DIRECTION_IS_FORWARD(hb_buffer_get_direction(harf_buzz_buffer))
356 ? glyph_infos[start_glyph].cluster 356 ? glyph_infos[start_glyph].cluster
357 : glyph_infos[start_glyph + num_glyphs - 1].cluster; 357 : glyph_infos[start_glyph + num_glyphs - 1].cluster;
(...skipping 28 matching lines...) Expand all
386 386
387 FloatRect glyph_bounds = current_font_data->BoundsForGlyph(glyph); 387 FloatRect glyph_bounds = current_font_data->BoundsForGlyph(glyph);
388 glyph_bounds.Move(glyph_origin.X(), glyph_origin.Y()); 388 glyph_bounds.Move(glyph_origin.X(), glyph_origin.Y());
389 glyph_bounding_box_.Unite(glyph_bounds); 389 glyph_bounding_box_.Unite(glyph_bounds);
390 glyph_origin += FloatSize(advance + offset_x, offset_y); 390 glyph_origin += FloatSize(advance + offset_x, offset_y);
391 } 391 }
392 392
393 run->width_ = std::max(0.0f, total_advance); 393 run->width_ = std::max(0.0f, total_advance);
394 width_ += run->width_; 394 width_ += run->width_;
395 num_glyphs_ += num_glyphs; 395 num_glyphs_ += num_glyphs;
396 ASSERT(num_glyphs_ >= num_glyphs); 396 DCHECK_GE(num_glyphs_, num_glyphs);
397 has_vertical_offsets_ |= has_vertical_offsets; 397 has_vertical_offsets_ |= has_vertical_offsets;
398 398
399 // The runs are stored in result->m_runs in visual order. For LTR, we place 399 // The runs are stored in result->m_runs in visual order. For LTR, we place
400 // the run to be inserted before the next run with a bigger character 400 // the run to be inserted before the next run with a bigger character
401 // start index. For RTL, we place the run before the next run with a lower 401 // start index. For RTL, we place the run before the next run with a lower
402 // character index. Otherwise, for both directions, at the end. 402 // character index. Otherwise, for both directions, at the end.
403 if (HB_DIRECTION_IS_FORWARD(run->direction_)) { 403 if (HB_DIRECTION_IS_FORWARD(run->direction_)) {
404 for (size_t pos = 0; pos < runs_.size(); ++pos) { 404 for (size_t pos = 0; pos < runs_.size(); ++pos) {
405 if (runs_.at(pos)->start_index_ > run->start_index_) { 405 if (runs_.at(pos)->start_index_ > run->start_index_) {
406 runs_.insert(pos, std::move(run)); 406 runs_.insert(pos, std::move(run));
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 result->width_ = run->width_; 471 result->width_ = run->width_;
472 result->num_glyphs_ = count; 472 result->num_glyphs_ = count;
473 DCHECK_EQ(result->num_glyphs_, count); // no overflow 473 DCHECK_EQ(result->num_glyphs_, count); // no overflow
474 result->has_vertical_offsets_ = 474 result->has_vertical_offsets_ =
475 font_data->PlatformData().IsVerticalAnyUpright(); 475 font_data->PlatformData().IsVerticalAnyUpright();
476 result->runs_.push_back(std::move(run)); 476 result->runs_.push_back(std::move(run));
477 return result.Release(); 477 return result.Release();
478 } 478 }
479 479
480 } // namespace blink 480 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698