2 * Copyright 2018 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "include/utils/SkTextUtils.h"
10 #include "include/core/SkCanvas.h"
11 #include "include/core/SkFont.h"
12 #include "include/core/SkFontTypes.h"
13 #include "include/core/SkMatrix.h"
14 #include "include/core/SkPath.h"
15 #include "include/core/SkPoint.h"
16 #include "include/core/SkScalar.h"
17 #include "include/core/SkTextBlob.h"
18 #include "include/private/SkTemplates.h"
19 #include "src/core/SkFontPriv.h"
23 void SkTextUtils::Draw(SkCanvas* canvas, const void* text, size_t size, SkTextEncoding encoding,
24 SkScalar x, SkScalar y, const SkFont& font, const SkPaint& paint,
26 if (align != kLeft_Align) {
27 SkScalar width = font.measureText(text, size, encoding);
28 if (align == kCenter_Align) {
34 canvas->drawTextBlob(SkTextBlob::MakeFromText(text, size, font, encoding), x, y, paint);
37 void SkTextUtils::GetPath(const void* text, size_t length, SkTextEncoding encoding,
38 SkScalar x, SkScalar y, const SkFont& font, SkPath* path) {
39 SkAutoToGlyphs ag(font, text, length, encoding);
40 SkAutoTArray<SkPoint> pos(ag.count());
41 font.getPos(ag.glyphs(), ag.count(), pos.get(), {x, y});
46 } rec = { path, pos.get() };
49 font.getPaths(ag.glyphs(), ag.count(), [](const SkPath* src, const SkMatrix& mx, void* ctx) {
53 m.postTranslate(rec->fPos->fX, rec->fPos->fY);
54 rec->fDst->addPath(*src, m);