An attempt to make font resolution more predictable.
In case the default font family is not there. Bug: skia:10701 Change-Id: Ie1155d820bfcc25870bedcd0310b0e779d55e942 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/316087 Reviewed-by: Ben Wagner <bungeman@google.com> Commit-Queue: Julia Lavrova <jlavrova@google.com>
This commit is contained in:
parent
401a009aaa
commit
0f64e0dfd8
@ -2993,6 +2993,58 @@ private:
|
||||
using INHERITED = Sample;
|
||||
};
|
||||
|
||||
|
||||
class ParagraphView48 : public ParagraphView_Base {
|
||||
protected:
|
||||
SkString name() override { return SkString("Paragraph48"); }
|
||||
|
||||
void onDrawContent(SkCanvas* canvas) override {
|
||||
canvas->clear(SK_ColorGRAY);
|
||||
|
||||
// To reproduce the client problem set DEFAULT_FONT_FAMILY to something
|
||||
// non-existing: "sans-serif1", for instance
|
||||
SkPaint paint;
|
||||
paint.setColor(SK_ColorRED);
|
||||
|
||||
auto fontCollection = sk_make_sp<FontCollection>();
|
||||
fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
|
||||
|
||||
TextStyle defaultStyle;
|
||||
defaultStyle.setForegroundColor(paint);
|
||||
|
||||
ParagraphStyle paraStyle;
|
||||
paraStyle.setTextStyle(defaultStyle);
|
||||
|
||||
const char* hello = "👶 487";
|
||||
auto builder = ParagraphBuilder::make(paraStyle, fontCollection);
|
||||
builder->addText(hello, strlen(hello));
|
||||
|
||||
auto paragraph = builder->Build();
|
||||
paragraph->layout(200);
|
||||
paragraph->paint(canvas, 200, 200);
|
||||
|
||||
const char* hello2 = "487";
|
||||
auto builder2 = ParagraphBuilder::make(paraStyle, fontCollection);
|
||||
builder2->addText(hello2, strlen(hello2));
|
||||
|
||||
auto paragraph2 = builder2->Build();
|
||||
paragraph2->layout(200);
|
||||
paragraph2->paint(canvas, 200, 300);
|
||||
|
||||
const char* hello3 = " 👶 487";
|
||||
auto builder3 = ParagraphBuilder::make(paraStyle, fontCollection);
|
||||
builder3->addText(hello3, strlen(hello3));
|
||||
|
||||
auto paragraph3 = builder3->Build();
|
||||
paragraph3->layout(200);
|
||||
paragraph3->paint(canvas, 200, 400);
|
||||
canvas->restore();
|
||||
}
|
||||
|
||||
private:
|
||||
using INHERITED = Sample;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
@ -3041,3 +3093,4 @@ DEF_SAMPLE(return new ParagraphView44();)
|
||||
DEF_SAMPLE(return new ParagraphView45();)
|
||||
DEF_SAMPLE(return new ParagraphView46();)
|
||||
DEF_SAMPLE(return new ParagraphView47();)
|
||||
DEF_SAMPLE(return new ParagraphView48();)
|
||||
|
@ -85,6 +85,14 @@ std::vector<sk_sp<SkTypeface>> FontCollection::findTypefaces(const std::vector<S
|
||||
|
||||
if (typefaces.empty()) {
|
||||
sk_sp<SkTypeface> match = matchTypeface(fDefaultFamilyName, fontStyle);
|
||||
if (!match) {
|
||||
for (const auto& manager : this->getFontManagerOrder()) {
|
||||
match = manager->legacyMakeTypeface(nullptr, fontStyle);
|
||||
if (match) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (match) {
|
||||
typefaces.emplace_back(std::move(match));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user