OLD | NEW |
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 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 // 2) the glyph buffer is encoded as a single blob, and | 400 // 2) the glyph buffer is encoded as a single blob, and |
401 // 3) the blob is not upright/rotated | 401 // 3) the blob is not upright/rotated |
402 if (runInfo.cachedTextBlob && bloberizer.blobCount() == 1 && | 402 if (runInfo.cachedTextBlob && bloberizer.blobCount() == 1 && |
403 blob.second == NoRotation) { | 403 blob.second == NoRotation) { |
404 ASSERT(!*runInfo.cachedTextBlob); | 404 ASSERT(!*runInfo.cachedTextBlob); |
405 *runInfo.cachedTextBlob = std::move(blob.first); | 405 *runInfo.cachedTextBlob = std::move(blob.first); |
406 ASSERT(*runInfo.cachedTextBlob); | 406 ASSERT(*runInfo.cachedTextBlob); |
407 } | 407 } |
408 } | 408 } |
409 | 409 |
| 410 static int getInterceptsFromBloberizer(const GlyphBuffer& glyphBuffer, |
| 411 const Font* font, |
| 412 const SkPaint& paint, |
| 413 float deviceScaleFactor, |
| 414 const std::tuple<float, float>& bounds, |
| 415 SkScalar* interceptsBuffer) { |
| 416 SkScalar boundsArray[2] = {std::get<0>(bounds), std::get<1>(bounds)}; |
| 417 GlyphBufferBloberizer bloberizer(glyphBuffer, font, deviceScaleFactor); |
| 418 std::pair<sk_sp<SkTextBlob>, BlobRotation> blob; |
| 419 |
| 420 int numIntervals = 0; |
| 421 while (!bloberizer.done()) { |
| 422 blob = bloberizer.next(); |
| 423 DCHECK(blob.first); |
| 424 |
| 425 // GlyphBufferBloberizer splits for a new blob rotation, but does not split |
| 426 // for a change in font. A TextBlob can contain runs with differing fonts |
| 427 // and the getTextBlobIntercepts method handles multiple fonts for us. For |
| 428 // upright in vertical blobs we currently have to bail, see crbug.com/655154 |
| 429 if (blob.second == BlobRotation::CCWRotation) |
| 430 continue; |
| 431 |
| 432 SkScalar* offsetInterceptsBuffer = nullptr; |
| 433 if (interceptsBuffer) |
| 434 offsetInterceptsBuffer = &interceptsBuffer[numIntervals]; |
| 435 numIntervals += paint.getTextBlobIntercepts(blob.first.get(), boundsArray, |
| 436 offsetInterceptsBuffer); |
| 437 } |
| 438 return numIntervals; |
| 439 } |
| 440 |
| 441 void Font::getTextIntercepts(const TextRunPaintInfo& runInfo, |
| 442 float deviceScaleFactor, |
| 443 const SkPaint& paint, |
| 444 const std::tuple<float, float>& bounds, |
| 445 Vector<TextIntercept>& intercepts) const { |
| 446 if (shouldSkipDrawing()) |
| 447 return; |
| 448 |
| 449 if (runInfo.cachedTextBlob && runInfo.cachedTextBlob->get()) { |
| 450 SkScalar boundsArray[2] = {std::get<0>(bounds), std::get<1>(bounds)}; |
| 451 int numIntervals = paint.getTextBlobIntercepts( |
| 452 runInfo.cachedTextBlob->get(), boundsArray, nullptr); |
| 453 if (!numIntervals) |
| 454 return; |
| 455 DCHECK_EQ(numIntervals % 2, 0); |
| 456 intercepts.resize(numIntervals / 2); |
| 457 paint.getTextBlobIntercepts(runInfo.cachedTextBlob->get(), boundsArray, |
| 458 reinterpret_cast<SkScalar*>(intercepts.data())); |
| 459 return; |
| 460 } |
| 461 |
| 462 GlyphBuffer glyphBuffer; |
| 463 buildGlyphBuffer(runInfo, glyphBuffer); |
| 464 |
| 465 // Get the number of intervals, without copying the actual values by |
| 466 // specifying nullptr for the buffer, following the Skia allocation model for |
| 467 // retrieving text intercepts. |
| 468 int numIntervals = getInterceptsFromBloberizer( |
| 469 glyphBuffer, this, paint, deviceScaleFactor, bounds, nullptr); |
| 470 if (!numIntervals) |
| 471 return; |
| 472 DCHECK_EQ(numIntervals % 2, 0); |
| 473 intercepts.resize(numIntervals / 2); |
| 474 |
| 475 getInterceptsFromBloberizer(glyphBuffer, this, paint, deviceScaleFactor, |
| 476 bounds, |
| 477 reinterpret_cast<SkScalar*>(intercepts.data())); |
| 478 } |
| 479 |
410 static inline FloatRect pixelSnappedSelectionRect(FloatRect rect) { | 480 static inline FloatRect pixelSnappedSelectionRect(FloatRect rect) { |
411 // Using roundf() rather than ceilf() for the right edge as a compromise to | 481 // Using roundf() rather than ceilf() for the right edge as a compromise to |
412 // ensure correct caret positioning. | 482 // ensure correct caret positioning. |
413 float roundedX = roundf(rect.x()); | 483 float roundedX = roundf(rect.x()); |
414 return FloatRect(roundedX, rect.y(), roundf(rect.maxX() - roundedX), | 484 return FloatRect(roundedX, rect.y(), roundf(rect.maxX() - roundedX), |
415 rect.height()); | 485 rect.height()); |
416 } | 486 } |
417 | 487 |
418 FloatRect Font::selectionRectForText(const TextRun& run, | 488 FloatRect Font::selectionRectForText(const TextRun& run, |
419 const FloatPoint& point, | 489 const FloatPoint& point, |
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
938 | 1008 |
939 bool Font::loadingCustomFonts() const { | 1009 bool Font::loadingCustomFonts() const { |
940 return m_fontFallbackList && m_fontFallbackList->loadingCustomFonts(); | 1010 return m_fontFallbackList && m_fontFallbackList->loadingCustomFonts(); |
941 } | 1011 } |
942 | 1012 |
943 bool Font::isFallbackValid() const { | 1013 bool Font::isFallbackValid() const { |
944 return !m_fontFallbackList || m_fontFallbackList->isValid(); | 1014 return !m_fontFallbackList || m_fontFallbackList->isValid(); |
945 } | 1015 } |
946 | 1016 |
947 } // namespace blink | 1017 } // namespace blink |
OLD | NEW |