Created
February 8, 2019 20:09
-
-
Save HalCanary/44e3d167e3e9fd7cbdab5ee268c27b9a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright 2019 Google LLC. | |
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. | |
#include "SkPath.h" | |
#include "SkTextBlobPriv.h" | |
#include "SkRSXform.h" | |
SkPath SkTextBlobToPath(const SkTextBlob* blob) { | |
SkPath path; | |
for (SkTextBlobRunIterator it(blob); !it.done(); it.next()) { | |
uint32_t runSize = it.glyphCount(); | |
const SkFont& font = it.font(); | |
SkTextBlobRunIterator::GlyphPositioning glyphPositioning = it.positioning() ; | |
std::unique_ptr<SkPoint[]> buffer; | |
const SkScalar* pos = it.pos(); | |
const SkPoint* pts = (const SkPoint*)pos; | |
SkPoint offset = it.offset(); | |
if (SkTextBlobRunIterator::kDefault_Positioning == glyphPositioning) { | |
buffer.reset(new SkPoint[it.glyphCount()]); | |
font.getPos(it.glyphs(), it.glyphCount(), buffer.get(), offset); | |
pts = buffer.get(); | |
} | |
for (uint32_t i = 0; i < runSize; ++i) { | |
SkPath glyphPath; | |
font.getPath(it.glyphs()[i], &glyphPath); | |
switch (glyphPositioning) { | |
case SkTextBlobRunIterator::kHorizontal_Positioning: | |
SkASSERT(offset.x() == 0); | |
path.addPath(glyphPath, pos[i], offset.y()); | |
break; | |
case SkTextBlobRunIterator::kDefault_Positioning: | |
case SkTextBlobRunIterator::kFull_Positioning: | |
SkASSERT((offset == SkPoint{0, 0})); | |
path.addPath(glyphPath, pts[i].x(), pts[i].y()); | |
break; | |
case SkTextBlobRunIterator::kRSXform_Positioning: | |
SkASSERT((offset == SkPoint{0, 0})); | |
{ | |
SkMatrix tmp; | |
tmp.setRSXform(((const SkRSXform*)pos)[i]); | |
path.addPath(glyphPath, tmp); | |
} | |
break; | |
} | |
} | |
} | |
return path; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment