Fix space text renders on the cocoa platform.

This commit is contained in:
pengweilv
2022-01-19 11:38:04 +08:00
committed by Dom Chen
parent 836b005270
commit c9539362e1
2 changed files with 23 additions and 15 deletions

View File

@@ -42,7 +42,7 @@
if ([pagFile numTexts] > 0) {
PAGText* textData = [pagFile getTextData:0];
textData.text = @"hah哈哈哈哈哈👌하";
textData.text = @"hah哈 哈哈哈哈👌하";
[pagFile replaceText:0 data:textData];
}

View File

@@ -241,23 +241,31 @@ class CTPathGeometrySink {
};
bool CGScalerContext::generatePath(GlyphID glyphID, Path* path) {
auto fontFormat = CTFontCopyAttribute(ctFont, kCTFontFormatAttribute);
if (!fontFormat) {
return false;
}
SInt16 format;
CFNumberGetValue(static_cast<CFNumberRef>(fontFormat), kCFNumberSInt16Type, &format);
if (format == kCTFontFormatUnrecognized || format == kCTFontFormatBitmap) {
return false;
}
CGAffineTransform xform = transform;
auto cgGlyph = static_cast<CGGlyph>(glyphID);
auto cgPath = CTFontCreatePathForGlyph(ctFont, cgGlyph, &xform);
path->reset();
if (!cgPath) {
return false;
}
CTPathGeometrySink sink;
CGPathApply(cgPath, &sink, CTPathGeometrySink::ApplyElement);
*path = sink.path();
CFRelease(cgPath);
if (rec.fauxBoldSize != 0) {
auto strokePath = *path;
auto pathEffect = PathEffect::MakeStroke(Stroke(rec.fauxBoldSize));
pathEffect->applyTo(&strokePath);
path->addPath(strokePath, PathOp::Union);
if (cgPath) {
CTPathGeometrySink sink;
CGPathApply(cgPath, &sink, CTPathGeometrySink::ApplyElement);
*path = sink.path();
CFRelease(cgPath);
if (rec.fauxBoldSize != 0) {
auto strokePath = *path;
auto pathEffect = PathEffect::MakeStroke(Stroke(rec.fauxBoldSize));
pathEffect->applyTo(&strokePath);
path->addPath(strokePath, PathOp::Union);
}
} else {
path->reset();
}
return true;
}