使用案例
有些应用程序需要访问的不仅仅是渲染的文本字形。这在设计软件中尤其常见,因为需要将文本字形转换为形状以便进行调整、动画或样式设置。
例如,Skia有一个getPath方法:
https://github.com/google/skia/blob/main/include/core/SkFont.h
/** Modifies path to be the outline of the glyph.
If the glyph has an outline, modifies path to be the glyph's outline and returns true.
The glyph outline may be empty. Degenerate contours in the glyph outline will be skipped.
If glyph is described by a bitmap, returns false and ignores path parameter.
@param glyphID index of glyph
@param path pointer to existing SkPath
@return true if glyphID is described by path
*/
bool getPath(SkGlyphID glyphID, SkPath* path) const;
/** Returns path corresponding to glyph array.
@param glyphIDs array of glyph indices
@param count number of glyphs
@param glyphPathProc function returning one glyph description as path
@param ctx function context
*/
void getPaths(const SkGlyphID glyphIDs[], int count,
void (*glyphPathProc)(const SkPath* pathOrNull, const SkMatrix& mx, void* ctx),
void* ctx) const;
/** Returns SkFontMetrics associated with SkTypeface.
The return value is the recommended spacing between lines: the sum of metrics
descent, ascent, and leading.
If metrics is not nullptr, SkFontMetrics is copied to metrics.
Results are scaled by text size but does not take into account
dimensions required by text scale, text skew, fake bold,
style stroke, and SkPathEffect.
@param metrics storage for SkFontMetrics; may be nullptr
@return recommended spacing between lines
*/
这个问题之前已经提过,但我认为缺乏一个更具体的问题,就像@Hixie要求的那样:
#137064
Flutter应该暴露一个API(可能在TextPainter上),用于获取文本的原始路径。
建议
添加从TextPainter获取Glyph / Shapes的能力(GlyphInfo已经存在,但没有一个很好的方法可以获取当前文本的整个列表):
class GlyphPath {
/// the glyph corresponding to this path
final GlyphInfo glyph;
/// the relative placement of this glyph
final Offset offset;
/// return a Path object for rendering
Path toPath();
}
List<GlyphPath> getGlyphs()
这对于某些用例来说是足够的,但是Path目前缺乏一些基本的功能,如果需要将其更改为Path,需要添加以下内容,与Skia底层数据相匹配( https://api.skia.org/classSkPath.html ),或者类似的功能:
List<PathVerb> getVerbs();
List<Offset> getPoints();
1条答案
按热度按时间kb5ga3dv1#
我们缺少一些API来正确地完成这个操作。我们可以通过字形获取路径(只要字体实际上有路径),但我们没有暴露一个API来从字符串/字体/大小组合中获取字形。