| 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 17 matching lines...) Expand all Loading... |
| 28 #include "platform/LayoutUnit.h" | 28 #include "platform/LayoutUnit.h" |
| 29 #include "platform/RuntimeEnabledFeatures.h" | 29 #include "platform/RuntimeEnabledFeatures.h" |
| 30 #include "platform/fonts/CharacterRange.h" | 30 #include "platform/fonts/CharacterRange.h" |
| 31 #include "platform/fonts/FontCache.h" | 31 #include "platform/fonts/FontCache.h" |
| 32 #include "platform/fonts/FontFallbackIterator.h" | 32 #include "platform/fonts/FontFallbackIterator.h" |
| 33 #include "platform/fonts/FontFallbackList.h" | 33 #include "platform/fonts/FontFallbackList.h" |
| 34 #include "platform/fonts/GlyphBuffer.h" | 34 #include "platform/fonts/GlyphBuffer.h" |
| 35 #include "platform/fonts/SimpleFontData.h" | 35 #include "platform/fonts/SimpleFontData.h" |
| 36 #include "platform/fonts/shaping/CachingWordShaper.h" | 36 #include "platform/fonts/shaping/CachingWordShaper.h" |
| 37 #include "platform/geometry/FloatRect.h" | 37 #include "platform/geometry/FloatRect.h" |
| 38 #include "platform/graphics/paint/PaintCanvas.h" |
| 39 #include "platform/graphics/paint/PaintFlags.h" |
| 38 #include "platform/text/BidiResolver.h" | 40 #include "platform/text/BidiResolver.h" |
| 39 #include "platform/text/Character.h" | 41 #include "platform/text/Character.h" |
| 40 #include "platform/text/TextRun.h" | 42 #include "platform/text/TextRun.h" |
| 41 #include "platform/text/TextRunIterator.h" | 43 #include "platform/text/TextRunIterator.h" |
| 42 #include "platform/transforms/AffineTransform.h" | 44 #include "platform/transforms/AffineTransform.h" |
| 43 #include "third_party/skia/include/core/SkCanvas.h" | |
| 44 #include "third_party/skia/include/core/SkPaint.h" | |
| 45 #include "third_party/skia/include/core/SkTextBlob.h" | 45 #include "third_party/skia/include/core/SkTextBlob.h" |
| 46 #include "wtf/StdLibExtras.h" | 46 #include "wtf/StdLibExtras.h" |
| 47 #include "wtf/text/CharacterNames.h" | 47 #include "wtf/text/CharacterNames.h" |
| 48 #include "wtf/text/Unicode.h" | 48 #include "wtf/text/Unicode.h" |
| 49 | 49 |
| 50 using namespace WTF; | 50 using namespace WTF; |
| 51 using namespace Unicode; | 51 using namespace Unicode; |
| 52 | 52 |
| 53 namespace blink { | 53 namespace blink { |
| 54 | 54 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 width = shaper.fillGlyphBufferForTextEmphasis(this, runInfo.run, | 114 width = shaper.fillGlyphBufferForTextEmphasis(this, runInfo.run, |
| 115 emphasisData, &glyphBuffer, | 115 emphasisData, &glyphBuffer, |
| 116 runInfo.from, runInfo.to); | 116 runInfo.from, runInfo.to); |
| 117 } else { | 117 } else { |
| 118 width = shaper.fillGlyphBuffer(this, runInfo.run, nullptr, &glyphBuffer, | 118 width = shaper.fillGlyphBuffer(this, runInfo.run, nullptr, &glyphBuffer, |
| 119 runInfo.from, runInfo.to); | 119 runInfo.from, runInfo.to); |
| 120 } | 120 } |
| 121 return width; | 121 return width; |
| 122 } | 122 } |
| 123 | 123 |
| 124 bool Font::drawText(SkCanvas* canvas, | 124 bool Font::drawText(PaintCanvas* canvas, |
| 125 const TextRunPaintInfo& runInfo, | 125 const TextRunPaintInfo& runInfo, |
| 126 const FloatPoint& point, | 126 const FloatPoint& point, |
| 127 float deviceScaleFactor, | 127 float deviceScaleFactor, |
| 128 const SkPaint& paint) const { | 128 const PaintFlags& paint) const { |
| 129 // Don't draw anything while we are using custom fonts that are in the process | 129 // Don't draw anything while we are using custom fonts that are in the process |
| 130 // of loading. | 130 // of loading. |
| 131 if (shouldSkipDrawing()) | 131 if (shouldSkipDrawing()) |
| 132 return false; | 132 return false; |
| 133 | 133 |
| 134 if (runInfo.cachedTextBlob && runInfo.cachedTextBlob->get()) { | 134 if (runInfo.cachedTextBlob && runInfo.cachedTextBlob->get()) { |
| 135 // we have a pre-cached blob -- happy joy! | 135 // we have a pre-cached blob -- happy joy! |
| 136 canvas->drawTextBlob(runInfo.cachedTextBlob->get(), point.x(), point.y(), | 136 canvas->drawTextBlob(runInfo.cachedTextBlob->get(), point.x(), point.y(), |
| 137 paint); | 137 paint); |
| 138 return true; | 138 return true; |
| 139 } | 139 } |
| 140 | 140 |
| 141 GlyphBuffer glyphBuffer; | 141 GlyphBuffer glyphBuffer; |
| 142 buildGlyphBuffer(runInfo, glyphBuffer); | 142 buildGlyphBuffer(runInfo, glyphBuffer); |
| 143 | 143 |
| 144 drawGlyphBuffer(canvas, paint, runInfo, glyphBuffer, point, | 144 drawGlyphBuffer(canvas, paint, runInfo, glyphBuffer, point, |
| 145 deviceScaleFactor); | 145 deviceScaleFactor); |
| 146 return true; | 146 return true; |
| 147 } | 147 } |
| 148 | 148 |
| 149 bool Font::drawBidiText(SkCanvas* canvas, | 149 bool Font::drawBidiText(PaintCanvas* canvas, |
| 150 const TextRunPaintInfo& runInfo, | 150 const TextRunPaintInfo& runInfo, |
| 151 const FloatPoint& point, | 151 const FloatPoint& point, |
| 152 CustomFontNotReadyAction customFontNotReadyAction, | 152 CustomFontNotReadyAction customFontNotReadyAction, |
| 153 float deviceScaleFactor, | 153 float deviceScaleFactor, |
| 154 const SkPaint& paint) const { | 154 const PaintFlags& paint) const { |
| 155 // Don't draw anything while we are using custom fonts that are in the process | 155 // Don't draw anything while we are using custom fonts that are in the process |
| 156 // of loading, except if the 'force' argument is set to true (in which case it | 156 // of loading, except if the 'force' argument is set to true (in which case it |
| 157 // will use a fallback font). | 157 // will use a fallback font). |
| 158 if (shouldSkipDrawing() && | 158 if (shouldSkipDrawing() && |
| 159 customFontNotReadyAction == DoNotPaintIfFontNotReady) | 159 customFontNotReadyAction == DoNotPaintIfFontNotReady) |
| 160 return false; | 160 return false; |
| 161 | 161 |
| 162 // sub-run painting is not supported for Bidi text. | 162 // sub-run painting is not supported for Bidi text. |
| 163 const TextRun& run = runInfo.run; | 163 const TextRun& run = runInfo.run; |
| 164 ASSERT((runInfo.from == 0) && (runInfo.to == run.length())); | 164 ASSERT((runInfo.from == 0) && (runInfo.to == run.length())); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 194 deviceScaleFactor); | 194 deviceScaleFactor); |
| 195 | 195 |
| 196 bidiRun = bidiRun->next(); | 196 bidiRun = bidiRun->next(); |
| 197 currPoint.move(runWidth, 0); | 197 currPoint.move(runWidth, 0); |
| 198 } | 198 } |
| 199 | 199 |
| 200 bidiRuns.deleteRuns(); | 200 bidiRuns.deleteRuns(); |
| 201 return true; | 201 return true; |
| 202 } | 202 } |
| 203 | 203 |
| 204 void Font::drawEmphasisMarks(SkCanvas* canvas, | 204 void Font::drawEmphasisMarks(PaintCanvas* canvas, |
| 205 const TextRunPaintInfo& runInfo, | 205 const TextRunPaintInfo& runInfo, |
| 206 const AtomicString& mark, | 206 const AtomicString& mark, |
| 207 const FloatPoint& point, | 207 const FloatPoint& point, |
| 208 float deviceScaleFactor, | 208 float deviceScaleFactor, |
| 209 const SkPaint& paint) const { | 209 const PaintFlags& paint) const { |
| 210 if (shouldSkipDrawing()) | 210 if (shouldSkipDrawing()) |
| 211 return; | 211 return; |
| 212 | 212 |
| 213 FontCachePurgePreventer purgePreventer; | 213 FontCachePurgePreventer purgePreventer; |
| 214 | 214 |
| 215 GlyphData emphasisGlyphData; | 215 GlyphData emphasisGlyphData; |
| 216 if (!getEmphasisMarkGlyphData(mark, emphasisGlyphData)) | 216 if (!getEmphasisMarkGlyphData(mark, emphasisGlyphData)) |
| 217 return; | 217 return; |
| 218 | 218 |
| 219 ASSERT(emphasisGlyphData.fontData); | 219 ASSERT(emphasisGlyphData.fontData); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 // For vertical upright text we need to compensate the inherited 90deg CW | 309 // For vertical upright text we need to compensate the inherited 90deg CW |
| 310 // rotation (using a 90deg CCW rotation). | 310 // rotation (using a 90deg CCW rotation). |
| 311 return (font->platformData().isVerticalAnyUpright() && font->verticalData()) | 311 return (font->platformData().isVerticalAnyUpright() && font->verticalData()) |
| 312 ? CCWRotation | 312 ? CCWRotation |
| 313 : NoRotation; | 313 : NoRotation; |
| 314 } | 314 } |
| 315 | 315 |
| 316 void appendRun(unsigned start, | 316 void appendRun(unsigned start, |
| 317 unsigned count, | 317 unsigned count, |
| 318 const SimpleFontData* fontData) { | 318 const SimpleFontData* fontData) { |
| 319 SkPaint paint; | 319 PaintFlags paint; |
| 320 fontData->platformData().setupPaint(&paint, m_deviceScaleFactor, m_font); | 320 fontData->platformData().setupPaint(&paint, m_deviceScaleFactor, m_font); |
| 321 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 321 paint.setTextEncoding(PaintFlags::kGlyphID_TextEncoding); |
| 322 | 322 |
| 323 const SkTextBlobBuilder::RunBuffer& buffer = | 323 const SkTextBlobBuilder::RunBuffer& buffer = |
| 324 m_hasVerticalOffsets ? m_builder.allocRunPos(paint, count) | 324 m_hasVerticalOffsets ? m_builder.allocRunPos(paint, count) |
| 325 : m_builder.allocRunPosH(paint, count, 0); | 325 : m_builder.allocRunPosH(paint, count, 0); |
| 326 | 326 |
| 327 const uint16_t* glyphs = m_buffer.glyphs(start); | 327 const uint16_t* glyphs = m_buffer.glyphs(start); |
| 328 const float* offsets = m_buffer.offsets(start); | 328 const float* offsets = m_buffer.offsets(start); |
| 329 std::copy(glyphs, glyphs + count, buffer.glyphs); | 329 std::copy(glyphs, glyphs + count, buffer.glyphs); |
| 330 | 330 |
| 331 if (m_rotation == NoRotation) { | 331 if (m_rotation == NoRotation) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 354 | 354 |
| 355 SkTextBlobBuilder m_builder; | 355 SkTextBlobBuilder m_builder; |
| 356 unsigned m_index; | 356 unsigned m_index; |
| 357 unsigned m_endIndex; | 357 unsigned m_endIndex; |
| 358 unsigned m_blobCount; | 358 unsigned m_blobCount; |
| 359 BlobRotation m_rotation; | 359 BlobRotation m_rotation; |
| 360 }; | 360 }; |
| 361 | 361 |
| 362 } // anonymous namespace | 362 } // anonymous namespace |
| 363 | 363 |
| 364 void Font::drawGlyphBuffer(SkCanvas* canvas, | 364 void Font::drawGlyphBuffer(PaintCanvas* canvas, |
| 365 const SkPaint& paint, | 365 const PaintFlags& paint, |
| 366 const TextRunPaintInfo& runInfo, | 366 const TextRunPaintInfo& runInfo, |
| 367 const GlyphBuffer& glyphBuffer, | 367 const GlyphBuffer& glyphBuffer, |
| 368 const FloatPoint& point, | 368 const FloatPoint& point, |
| 369 float deviceScaleFactor) const { | 369 float deviceScaleFactor) const { |
| 370 GlyphBufferBloberizer bloberizer(glyphBuffer, this, deviceScaleFactor); | 370 GlyphBufferBloberizer bloberizer(glyphBuffer, this, deviceScaleFactor); |
| 371 std::pair<sk_sp<SkTextBlob>, BlobRotation> blob; | 371 std::pair<sk_sp<SkTextBlob>, BlobRotation> blob; |
| 372 | 372 |
| 373 while (!bloberizer.done()) { | 373 while (!bloberizer.done()) { |
| 374 blob = bloberizer.next(); | 374 blob = bloberizer.next(); |
| 375 ASSERT(blob.first); | 375 ASSERT(blob.first); |
| 376 | 376 |
| 377 SkAutoCanvasRestore autoRestore(canvas, false); | 377 PaintCanvasAutoRestore autoRestore(canvas, false); |
| 378 if (blob.second == CCWRotation) { | 378 if (blob.second == CCWRotation) { |
| 379 canvas->save(); | 379 canvas->save(); |
| 380 | 380 |
| 381 SkMatrix m; | 381 SkMatrix m; |
| 382 m.setSinCos(-1, 0, point.x(), point.y()); | 382 m.setSinCos(-1, 0, point.x(), point.y()); |
| 383 canvas->concat(m); | 383 canvas->concat(m); |
| 384 } | 384 } |
| 385 | 385 |
| 386 canvas->drawTextBlob(blob.first, point.x(), point.y(), paint); | 386 canvas->drawTextBlob(blob.first, point.x(), point.y(), paint); |
| 387 } | 387 } |
| 388 | 388 |
| 389 // Cache results when | 389 // Cache results when |
| 390 // 1) requested by clients, and | 390 // 1) requested by clients, and |
| 391 // 2) the glyph buffer is encoded as a single blob, and | 391 // 2) the glyph buffer is encoded as a single blob, and |
| 392 // 3) the blob is not upright/rotated | 392 // 3) the blob is not upright/rotated |
| 393 if (runInfo.cachedTextBlob && bloberizer.blobCount() == 1 && | 393 if (runInfo.cachedTextBlob && bloberizer.blobCount() == 1 && |
| 394 blob.second == NoRotation) { | 394 blob.second == NoRotation) { |
| 395 ASSERT(!*runInfo.cachedTextBlob); | 395 ASSERT(!*runInfo.cachedTextBlob); |
| 396 *runInfo.cachedTextBlob = std::move(blob.first); | 396 *runInfo.cachedTextBlob = std::move(blob.first); |
| 397 ASSERT(*runInfo.cachedTextBlob); | 397 ASSERT(*runInfo.cachedTextBlob); |
| 398 } | 398 } |
| 399 } | 399 } |
| 400 | 400 |
| 401 static int getInterceptsFromBloberizer(const GlyphBuffer& glyphBuffer, | 401 static int getInterceptsFromBloberizer(const GlyphBuffer& glyphBuffer, |
| 402 const Font* font, | 402 const Font* font, |
| 403 const SkPaint& paint, | 403 const PaintFlags& paint, |
| 404 float deviceScaleFactor, | 404 float deviceScaleFactor, |
| 405 const std::tuple<float, float>& bounds, | 405 const std::tuple<float, float>& bounds, |
| 406 SkScalar* interceptsBuffer) { | 406 SkScalar* interceptsBuffer) { |
| 407 SkScalar boundsArray[2] = {std::get<0>(bounds), std::get<1>(bounds)}; | 407 SkScalar boundsArray[2] = {std::get<0>(bounds), std::get<1>(bounds)}; |
| 408 GlyphBufferBloberizer bloberizer(glyphBuffer, font, deviceScaleFactor); | 408 GlyphBufferBloberizer bloberizer(glyphBuffer, font, deviceScaleFactor); |
| 409 std::pair<sk_sp<SkTextBlob>, BlobRotation> blob; | 409 std::pair<sk_sp<SkTextBlob>, BlobRotation> blob; |
| 410 | 410 |
| 411 int numIntervals = 0; | 411 int numIntervals = 0; |
| 412 while (!bloberizer.done()) { | 412 while (!bloberizer.done()) { |
| 413 blob = bloberizer.next(); | 413 blob = bloberizer.next(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 424 if (interceptsBuffer) | 424 if (interceptsBuffer) |
| 425 offsetInterceptsBuffer = &interceptsBuffer[numIntervals]; | 425 offsetInterceptsBuffer = &interceptsBuffer[numIntervals]; |
| 426 numIntervals += paint.getTextBlobIntercepts(blob.first.get(), boundsArray, | 426 numIntervals += paint.getTextBlobIntercepts(blob.first.get(), boundsArray, |
| 427 offsetInterceptsBuffer); | 427 offsetInterceptsBuffer); |
| 428 } | 428 } |
| 429 return numIntervals; | 429 return numIntervals; |
| 430 } | 430 } |
| 431 | 431 |
| 432 void Font::getTextIntercepts(const TextRunPaintInfo& runInfo, | 432 void Font::getTextIntercepts(const TextRunPaintInfo& runInfo, |
| 433 float deviceScaleFactor, | 433 float deviceScaleFactor, |
| 434 const SkPaint& paint, | 434 const PaintFlags& paint, |
| 435 const std::tuple<float, float>& bounds, | 435 const std::tuple<float, float>& bounds, |
| 436 Vector<TextIntercept>& intercepts) const { | 436 Vector<TextIntercept>& intercepts) const { |
| 437 if (shouldSkipDrawing()) | 437 if (shouldSkipDrawing()) |
| 438 return; | 438 return; |
| 439 | 439 |
| 440 if (runInfo.cachedTextBlob && runInfo.cachedTextBlob->get()) { | 440 if (runInfo.cachedTextBlob && runInfo.cachedTextBlob->get()) { |
| 441 SkScalar boundsArray[2] = {std::get<0>(bounds), std::get<1>(bounds)}; | 441 SkScalar boundsArray[2] = {std::get<0>(bounds), std::get<1>(bounds)}; |
| 442 int numIntervals = paint.getTextBlobIntercepts( | 442 int numIntervals = paint.getTextBlobIntercepts( |
| 443 runInfo.cachedTextBlob->get(), boundsArray, nullptr); | 443 runInfo.cachedTextBlob->get(), boundsArray, nullptr); |
| 444 if (!numIntervals) | 444 if (!numIntervals) |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 | 636 |
| 637 bool Font::loadingCustomFonts() const { | 637 bool Font::loadingCustomFonts() const { |
| 638 return m_fontFallbackList && m_fontFallbackList->loadingCustomFonts(); | 638 return m_fontFallbackList && m_fontFallbackList->loadingCustomFonts(); |
| 639 } | 639 } |
| 640 | 640 |
| 641 bool Font::isFallbackValid() const { | 641 bool Font::isFallbackValid() const { |
| 642 return !m_fontFallbackList || m_fontFallbackList->isValid(); | 642 return !m_fontFallbackList || m_fontFallbackList->isValid(); |
| 643 } | 643 } |
| 644 | 644 |
| 645 } // namespace blink | 645 } // namespace blink |
| OLD | NEW |