Florin Malita | 9867f61 | 2018-12-12 10:54:49 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "SkShaper.h" |
Ben Wagner | 454e5fb | 2019-02-08 17:46:38 -0500 | [diff] [blame] | 9 | #include "SkSpan.h" |
Florin Malita | 9867f61 | 2018-12-12 10:54:49 -0500 | [diff] [blame] | 10 | #include "SkTextBlobPriv.h" |
| 11 | |
Ben Wagner | b059194 | 2019-02-15 14:46:18 -0500 | [diff] [blame^] | 12 | std::unique_ptr<SkShaper> SkShaper::Make() { |
| 13 | #ifdef SK_SHAPER_HARFBUZZ_AVAILABLE |
| 14 | std::unique_ptr<SkShaper> shaper = SkShaper::MakeHarfBuzz(); |
| 15 | if (shaper) { |
| 16 | return shaper; |
| 17 | } |
| 18 | #endif |
| 19 | return SkShaper::MakePrimitive(); |
| 20 | } |
| 21 | |
| 22 | SkShaper::SkShaper() {} |
| 23 | SkShaper::~SkShaper() {} |
| 24 | |
Florin Malita | 950243d | 2019-01-11 11:08:35 -0500 | [diff] [blame] | 25 | SkShaper::RunHandler::Buffer SkTextBlobBuilderRunHandler::newRunBuffer(const RunInfo&, |
| 26 | const SkFont& font, |
| 27 | int glyphCount, |
Ben Wagner | 454e5fb | 2019-02-08 17:46:38 -0500 | [diff] [blame] | 28 | SkSpan<const char> utf8) { |
Florin Malita | 9867f61 | 2018-12-12 10:54:49 -0500 | [diff] [blame] | 29 | const auto& runBuffer = SkTextBlobBuilderPriv::AllocRunTextPos(&fBuilder, font, glyphCount, |
Ben Wagner | 454e5fb | 2019-02-08 17:46:38 -0500 | [diff] [blame] | 30 | utf8.size(), SkString()); |
| 31 | if (runBuffer.utf8text && fUtf8Text) { |
| 32 | memcpy(runBuffer.utf8text, utf8.data(), utf8.size()); |
| 33 | } |
| 34 | fClusters = runBuffer.clusters; |
| 35 | fGlyphCount = glyphCount; |
| 36 | fClusterOffset = utf8.data() - fUtf8Text; |
| 37 | |
Florin Malita | 9867f61 | 2018-12-12 10:54:49 -0500 | [diff] [blame] | 38 | return { runBuffer.glyphs, |
Mike Reed | 22451cc | 2019-01-01 15:40:28 -0500 | [diff] [blame] | 39 | runBuffer.points(), |
Florin Malita | 9867f61 | 2018-12-12 10:54:49 -0500 | [diff] [blame] | 40 | runBuffer.clusters }; |
| 41 | } |
| 42 | |
Ben Wagner | 454e5fb | 2019-02-08 17:46:38 -0500 | [diff] [blame] | 43 | void SkTextBlobBuilderRunHandler::commitRun() { |
Ben Wagner | 18ea3c7 | 2019-02-15 16:35:48 -0500 | [diff] [blame] | 44 | SkASSERT(0 <= fClusterOffset); |
Ben Wagner | 454e5fb | 2019-02-08 17:46:38 -0500 | [diff] [blame] | 45 | for (int i = 0; i < fGlyphCount; ++i) { |
Ben Wagner | 18ea3c7 | 2019-02-15 16:35:48 -0500 | [diff] [blame] | 46 | SkASSERT(fClusters[i] >= (unsigned)fClusterOffset); |
Ben Wagner | 454e5fb | 2019-02-08 17:46:38 -0500 | [diff] [blame] | 47 | fClusters[i] -= fClusterOffset; |
| 48 | } |
| 49 | } |
| 50 | |
Florin Malita | 950243d | 2019-01-11 11:08:35 -0500 | [diff] [blame] | 51 | sk_sp<SkTextBlob> SkTextBlobBuilderRunHandler::makeBlob() { |
Florin Malita | 9867f61 | 2018-12-12 10:54:49 -0500 | [diff] [blame] | 52 | return fBuilder.make(); |
| 53 | } |