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

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

Issue 2924263003: [LayoutNG] Initial letter-spacing and word-spacing support (Closed)
Patch Set: Cleanup Created 3 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 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 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 for (unsigned i = 0; i < runs_.size(); ++i) { 301 for (unsigned i = 0; i < runs_.size(); ++i) {
302 if (runs_[i] && runs_[i]->font_data_ && 302 if (runs_[i] && runs_[i]->font_data_ &&
303 runs_[i]->font_data_ != primary_font_ && 303 runs_[i]->font_data_ != primary_font_ &&
304 !runs_[i]->font_data_->IsTextOrientationFallbackOf( 304 !runs_[i]->font_data_->IsTextOrientationFallbackOf(
305 primary_font_.Get())) { 305 primary_font_.Get())) {
306 fallback->insert(runs_[i]->font_data_.Get()); 306 fallback->insert(runs_[i]->font_data_.Get());
307 } 307 }
308 } 308 }
309 } 309 }
310 310
311 void ShapeResult::ApplySpacing(ShapeResultSpacing& spacing, 311 template <typename TextContainerType>
312 const TextRun& text_run) { 312 void ShapeResult::ApplySpacing(ShapeResultSpacing<TextContainerType>& spacing,
313 const TextContainerType& text,
314 bool is_rtl) {
313 float offset_x, offset_y; 315 float offset_x, offset_y;
314 float& offset = spacing.IsVerticalOffset() ? offset_y : offset_x; 316 float& offset = spacing.IsVerticalOffset() ? offset_y : offset_x;
315 float total_space = 0; 317 float total_space = 0;
316 for (auto& run : runs_) { 318 for (auto& run : runs_) {
317 if (!run) 319 if (!run)
318 continue; 320 continue;
319 float total_space_for_run = 0; 321 float total_space_for_run = 0;
320 for (size_t i = 0; i < run->glyph_data_.size(); i++) { 322 for (size_t i = 0; i < run->glyph_data_.size(); i++) {
321 HarfBuzzRunGlyphData& glyph_data = run->glyph_data_[i]; 323 HarfBuzzRunGlyphData& glyph_data = run->glyph_data_[i];
322 324
323 // Skip if it's not a grapheme cluster boundary. 325 // Skip if it's not a grapheme cluster boundary.
324 if (i + 1 < run->glyph_data_.size() && 326 if (i + 1 < run->glyph_data_.size() &&
325 glyph_data.character_index == 327 glyph_data.character_index ==
326 run->glyph_data_[i + 1].character_index) { 328 run->glyph_data_[i + 1].character_index) {
327 // In RTL, marks need the same letter-spacing offset as the base. 329 // In RTL, marks need the same letter-spacing offset as the base.
328 if (text_run.Rtl() && spacing.LetterSpacing()) { 330 if (is_rtl && spacing.LetterSpacing()) {
329 offset_x = offset_y = 0; 331 offset_x = offset_y = 0;
330 offset = spacing.LetterSpacing(); 332 offset = spacing.LetterSpacing();
331 glyph_data.offset.Expand(offset_x, offset_y); 333 glyph_data.offset.Expand(offset_x, offset_y);
332 } 334 }
333 } else { 335 } else {
334 offset_x = offset_y = 0; 336 offset_x = offset_y = 0;
335 float space = spacing.ComputeSpacing( 337 float space = spacing.ComputeSpacing(
336 text_run, run->start_index_ + glyph_data.character_index, offset); 338 text, run->start_index_ + glyph_data.character_index, offset);
337 glyph_data.advance += space; 339 glyph_data.advance += space;
338 total_space_for_run += space; 340 total_space_for_run += space;
339 if (text_run.Rtl()) { 341 if (is_rtl) {
340 // In RTL, spacing should be added to left side of glyphs. 342 // In RTL, spacing should be added to left side of glyphs.
341 offset += space; 343 offset += space;
342 } 344 }
343 glyph_data.offset.Expand(offset_x, offset_y); 345 glyph_data.offset.Expand(offset_x, offset_y);
344 } 346 }
345 has_vertical_offsets_ |= (glyph_data.offset.Height() != 0); 347 has_vertical_offsets_ |= (glyph_data.offset.Height() != 0);
346 } 348 }
347 run->width_ += total_space_for_run; 349 run->width_ += total_space_for_run;
348 total_space += total_space_for_run; 350 total_space += total_space_for_run;
349 } 351 }
350 width_ += total_space; 352 width_ += total_space;
351 if (spacing.IsVerticalOffset()) 353 if (spacing.IsVerticalOffset())
352 glyph_bounding_box_.SetHeight(glyph_bounding_box_.Height() + total_space); 354 glyph_bounding_box_.SetHeight(glyph_bounding_box_.Height() + total_space);
353 else 355 else
354 glyph_bounding_box_.SetWidth(glyph_bounding_box_.Width() + total_space); 356 glyph_bounding_box_.SetWidth(glyph_bounding_box_.Width() + total_space);
355 } 357 }
356 358
359 void ShapeResult::ApplySpacing(ShapeResultSpacing<StringView>& spacing,
360 const StringView& text,
361 TextDirection direction) {
362 ApplySpacing(spacing, text, direction == TextDirection::kRtl);
363 }
364
357 PassRefPtr<ShapeResult> ShapeResult::ApplySpacingToCopy( 365 PassRefPtr<ShapeResult> ShapeResult::ApplySpacingToCopy(
358 ShapeResultSpacing& spacing, 366 ShapeResultSpacing<TextRun>& spacing,
359 const TextRun& run) const { 367 const TextRun& run) const {
360 RefPtr<ShapeResult> result = ShapeResult::Create(*this); 368 RefPtr<ShapeResult> result = ShapeResult::Create(*this);
361 result->ApplySpacing(spacing, run); 369 result->ApplySpacing(spacing, run, run.Rtl());
362 return result.Release(); 370 return result.Release();
363 } 371 }
364 372
365 static inline float HarfBuzzPositionToFloat(hb_position_t value) { 373 static inline float HarfBuzzPositionToFloat(hb_position_t value) {
366 return static_cast<float>(value) / (1 << 16); 374 return static_cast<float>(value) / (1 << 16);
367 } 375 }
368 376
369 void ShapeResult::InsertRun(std::unique_ptr<ShapeResult::RunInfo> run_to_insert, 377 void ShapeResult::InsertRun(std::unique_ptr<ShapeResult::RunInfo> run_to_insert,
370 unsigned start_glyph, 378 unsigned start_glyph,
371 unsigned num_glyphs, 379 unsigned num_glyphs,
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 result->width_ = run->width_; 506 result->width_ = run->width_;
499 result->num_glyphs_ = count; 507 result->num_glyphs_ = count;
500 DCHECK_EQ(result->num_glyphs_, count); // no overflow 508 DCHECK_EQ(result->num_glyphs_, count); // no overflow
501 result->has_vertical_offsets_ = 509 result->has_vertical_offsets_ =
502 font_data->PlatformData().IsVerticalAnyUpright(); 510 font_data->PlatformData().IsVerticalAnyUpright();
503 result->runs_.push_back(std::move(run)); 511 result->runs_.push_back(std::move(run));
504 return result.Release(); 512 return result.Release();
505 } 513 }
506 514
507 } // namespace blink 515 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698