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

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

Issue 2716203002: blink: Fix cc/paint skia type mismatches (Closed)
Patch Set: Created 3 years, 9 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) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2000 Dirk Mueller (mueller@kde.org) 4 * (C) 2000 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2003, 2006, 2010, 2011 Apple Inc. All rights reserved. 5 * Copyright (C) 2003, 2006, 2010, 2011 Apple Inc. All rights reserved.
6 * Copyright (c) 2007, 2008, 2010 Google Inc. All rights reserved. 6 * Copyright (c) 2007, 2008, 2010 Google Inc. All rights reserved.
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 // For vertical upright text we need to compensate the inherited 90deg CW 285 // For vertical upright text we need to compensate the inherited 90deg CW
286 // rotation (using a 90deg CCW rotation). 286 // rotation (using a 90deg CCW rotation).
287 return (font->platformData().isVerticalAnyUpright() && font->verticalData()) 287 return (font->platformData().isVerticalAnyUpright() && font->verticalData())
288 ? CCWRotation 288 ? CCWRotation
289 : NoRotation; 289 : NoRotation;
290 } 290 }
291 291
292 void appendRun(unsigned start, 292 void appendRun(unsigned start,
293 unsigned count, 293 unsigned count,
294 const SimpleFontData* fontData) { 294 const SimpleFontData* fontData) {
295 PaintFlags flags; 295 SkPaint paint;
296 fontData->platformData().setupPaint(&flags, m_deviceScaleFactor, m_font); 296 fontData->platformData().setupPaint(&paint, m_deviceScaleFactor, m_font);
297 flags.setTextEncoding(PaintFlags::kGlyphID_TextEncoding); 297 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
298 298
299 const SkTextBlobBuilder::RunBuffer& buffer = 299 const SkTextBlobBuilder::RunBuffer& buffer =
300 m_hasVerticalOffsets ? m_builder.allocRunPos(flags, count) 300 m_hasVerticalOffsets ? m_builder.allocRunPos(paint, count)
301 : m_builder.allocRunPosH(flags, count, 0); 301 : m_builder.allocRunPosH(paint, count, 0);
302 302
303 const uint16_t* glyphs = m_buffer.glyphs(start); 303 const uint16_t* glyphs = m_buffer.glyphs(start);
304 const float* offsets = m_buffer.offsets(start); 304 const float* offsets = m_buffer.offsets(start);
305 std::copy(glyphs, glyphs + count, buffer.glyphs); 305 std::copy(glyphs, glyphs + count, buffer.glyphs);
306 306
307 if (m_rotation == NoRotation) { 307 if (m_rotation == NoRotation) {
308 std::copy(offsets, offsets + (m_hasVerticalOffsets ? 2 * count : count), 308 std::copy(offsets, offsets + (m_hasVerticalOffsets ? 2 * count : count),
309 buffer.pos); 309 buffer.pos);
310 } else { 310 } else {
311 ASSERT(m_hasVerticalOffsets); 311 ASSERT(m_hasVerticalOffsets);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 m.setSinCos(-1, 0, point.x(), point.y()); 355 m.setSinCos(-1, 0, point.x(), point.y());
356 canvas->concat(m); 356 canvas->concat(m);
357 } 357 }
358 358
359 canvas->drawTextBlob(blob.first, point.x(), point.y(), flags); 359 canvas->drawTextBlob(blob.first, point.x(), point.y(), flags);
360 } 360 }
361 } 361 }
362 362
363 static int getInterceptsFromBloberizer(const GlyphBuffer& glyphBuffer, 363 static int getInterceptsFromBloberizer(const GlyphBuffer& glyphBuffer,
364 const Font* font, 364 const Font* font,
365 const PaintFlags& flags, 365 const SkPaint& paint,
366 float deviceScaleFactor, 366 float deviceScaleFactor,
367 const std::tuple<float, float>& bounds, 367 const std::tuple<float, float>& bounds,
368 SkScalar* interceptsBuffer) { 368 SkScalar* interceptsBuffer) {
369 SkScalar boundsArray[2] = {std::get<0>(bounds), std::get<1>(bounds)}; 369 SkScalar boundsArray[2] = {std::get<0>(bounds), std::get<1>(bounds)};
370 GlyphBufferBloberizer bloberizer(glyphBuffer, font, deviceScaleFactor); 370 GlyphBufferBloberizer bloberizer(glyphBuffer, font, deviceScaleFactor);
371 371
372 int numIntervals = 0; 372 int numIntervals = 0;
373 while (!bloberizer.done()) { 373 while (!bloberizer.done()) {
374 auto blob = bloberizer.next(); 374 auto blob = bloberizer.next();
375 DCHECK(blob.first); 375 DCHECK(blob.first);
376 376
377 // GlyphBufferBloberizer splits for a new blob rotation, but does not split 377 // GlyphBufferBloberizer splits for a new blob rotation, but does not split
378 // for a change in font. A TextBlob can contain runs with differing fonts 378 // for a change in font. A TextBlob can contain runs with differing fonts
379 // and the getTextBlobIntercepts method handles multiple fonts for us. For 379 // and the getTextBlobIntercepts method handles multiple fonts for us. For
380 // upright in vertical blobs we currently have to bail, see crbug.com/655154 380 // upright in vertical blobs we currently have to bail, see crbug.com/655154
381 if (blob.second == BlobRotation::CCWRotation) 381 if (blob.second == BlobRotation::CCWRotation)
382 continue; 382 continue;
383 383
384 SkScalar* offsetInterceptsBuffer = nullptr; 384 SkScalar* offsetInterceptsBuffer = nullptr;
385 if (interceptsBuffer) 385 if (interceptsBuffer)
386 offsetInterceptsBuffer = &interceptsBuffer[numIntervals]; 386 offsetInterceptsBuffer = &interceptsBuffer[numIntervals];
387 numIntervals += flags.getTextBlobIntercepts(blob.first.get(), boundsArray, 387 numIntervals += paint.getTextBlobIntercepts(blob.first.get(), boundsArray,
388 offsetInterceptsBuffer); 388 offsetInterceptsBuffer);
389 } 389 }
390 return numIntervals; 390 return numIntervals;
391 } 391 }
392 392
393 void Font::getTextIntercepts(const TextRunPaintInfo& runInfo, 393 void Font::getTextIntercepts(const TextRunPaintInfo& runInfo,
394 float deviceScaleFactor, 394 float deviceScaleFactor,
395 const PaintFlags& flags, 395 const PaintFlags& flags,
396 const std::tuple<float, float>& bounds, 396 const std::tuple<float, float>& bounds,
397 Vector<TextIntercept>& intercepts) const { 397 Vector<TextIntercept>& intercepts) const {
398 if (shouldSkipDrawing()) 398 if (shouldSkipDrawing())
399 return; 399 return;
400 400
401 GlyphBuffer glyphBuffer(GlyphBuffer::Type::TextIntercepts); 401 GlyphBuffer glyphBuffer(GlyphBuffer::Type::TextIntercepts);
402 buildGlyphBuffer(runInfo, glyphBuffer); 402 buildGlyphBuffer(runInfo, glyphBuffer);
403 403
404 // Get the number of intervals, without copying the actual values by 404 // Get the number of intervals, without copying the actual values by
405 // specifying nullptr for the buffer, following the Skia allocation model for 405 // specifying nullptr for the buffer, following the Skia allocation model for
406 // retrieving text intercepts. 406 // retrieving text intercepts.
407 SkPaint paint(ToSkPaint(flags));
enne (OOO) 2017/02/27 05:16:59 This is changing back because I think the text int
407 int numIntervals = getInterceptsFromBloberizer( 408 int numIntervals = getInterceptsFromBloberizer(
408 glyphBuffer, this, flags, deviceScaleFactor, bounds, nullptr); 409 glyphBuffer, this, paint, deviceScaleFactor, bounds, nullptr);
409 if (!numIntervals) 410 if (!numIntervals)
410 return; 411 return;
411 DCHECK_EQ(numIntervals % 2, 0); 412 DCHECK_EQ(numIntervals % 2, 0);
412 intercepts.resize(numIntervals / 2); 413 intercepts.resize(numIntervals / 2);
413 414
414 getInterceptsFromBloberizer(glyphBuffer, this, flags, deviceScaleFactor, 415 getInterceptsFromBloberizer(glyphBuffer, this, paint, deviceScaleFactor,
415 bounds, 416 bounds,
416 reinterpret_cast<SkScalar*>(intercepts.data())); 417 reinterpret_cast<SkScalar*>(intercepts.data()));
417 } 418 }
418 419
419 static inline FloatRect pixelSnappedSelectionRect(FloatRect rect) { 420 static inline FloatRect pixelSnappedSelectionRect(FloatRect rect) {
420 // Using roundf() rather than ceilf() for the right edge as a compromise to 421 // Using roundf() rather than ceilf() for the right edge as a compromise to
421 // ensure correct caret positioning. 422 // ensure correct caret positioning.
422 float roundedX = roundf(rect.x()); 423 float roundedX = roundf(rect.x());
423 return FloatRect(roundedX, rect.y(), roundf(rect.maxX() - roundedX), 424 return FloatRect(roundedX, rect.y(), roundf(rect.maxX() - roundedX),
424 rect.height()); 425 rect.height());
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 581
581 bool Font::loadingCustomFonts() const { 582 bool Font::loadingCustomFonts() const {
582 return m_fontFallbackList && m_fontFallbackList->loadingCustomFonts(); 583 return m_fontFallbackList && m_fontFallbackList->loadingCustomFonts();
583 } 584 }
584 585
585 bool Font::isFallbackValid() const { 586 bool Font::isFallbackValid() const {
586 return !m_fontFallbackList || m_fontFallbackList->isValid(); 587 return !m_fontFallbackList || m_fontFallbackList->isValid();
587 } 588 }
588 589
589 } // namespace blink 590 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698