blob: f3e3929188c52babe377b36dc9df66a923729872 [file] [log] [blame]
Florin Malita9867f612018-12-12 10:54:49 -05001/*
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 Wagner454e5fb2019-02-08 17:46:38 -05009#include "SkSpan.h"
Florin Malita9867f612018-12-12 10:54:49 -050010#include "SkTextBlobPriv.h"
11
Ben Wagnerb0591942019-02-15 14:46:18 -050012std::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
22SkShaper::SkShaper() {}
23SkShaper::~SkShaper() {}
24
Florin Malita950243d2019-01-11 11:08:35 -050025SkShaper::RunHandler::Buffer SkTextBlobBuilderRunHandler::newRunBuffer(const RunInfo&,
26 const SkFont& font,
27 int glyphCount,
Ben Wagner454e5fb2019-02-08 17:46:38 -050028 SkSpan<const char> utf8) {
Florin Malita9867f612018-12-12 10:54:49 -050029 const auto& runBuffer = SkTextBlobBuilderPriv::AllocRunTextPos(&fBuilder, font, glyphCount,
Ben Wagner454e5fb2019-02-08 17:46:38 -050030 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 Malita9867f612018-12-12 10:54:49 -050038 return { runBuffer.glyphs,
Mike Reed22451cc2019-01-01 15:40:28 -050039 runBuffer.points(),
Florin Malita9867f612018-12-12 10:54:49 -050040 runBuffer.clusters };
41}
42
Ben Wagner454e5fb2019-02-08 17:46:38 -050043void SkTextBlobBuilderRunHandler::commitRun() {
Ben Wagner18ea3c72019-02-15 16:35:48 -050044 SkASSERT(0 <= fClusterOffset);
Ben Wagner454e5fb2019-02-08 17:46:38 -050045 for (int i = 0; i < fGlyphCount; ++i) {
Ben Wagner18ea3c72019-02-15 16:35:48 -050046 SkASSERT(fClusters[i] >= (unsigned)fClusterOffset);
Ben Wagner454e5fb2019-02-08 17:46:38 -050047 fClusters[i] -= fClusterOffset;
48 }
49}
50
Florin Malita950243d2019-01-11 11:08:35 -050051sk_sp<SkTextBlob> SkTextBlobBuilderRunHandler::makeBlob() {
Florin Malita9867f612018-12-12 10:54:49 -050052 return fBuilder.make();
53}