MCPcopy Create free account
hub / github.com/Tencent/tgfx / TGFX_TEST

Function TGFX_TEST

test/src/TypefaceTest.cpp:77–124  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

75};
76
77TGFX_TEST(TypefaceTest, CustomPathTypeface) {
78 const std::string fontFamily = "customPath";
79 const std::string fontStyle = "customStyle";
80 PathTypefaceBuilder builder;
81 builder.setFontName(fontFamily, fontStyle);
82
83 builder.addGlyph(std::make_shared<GlyphPathProvider>(0));
84 builder.addGlyph(std::make_shared<GlyphPathProvider>(1));
85 builder.addGlyph(std::make_shared<GlyphPathProvider>(2));
86 auto typeface = builder.detach();
87
88 ASSERT_TRUE(typeface != nullptr);
89 ASSERT_TRUE(typeface->hasOutlines());
90 ASSERT_FALSE(typeface->hasColor());
91 ASSERT_TRUE(typeface->openStream() == nullptr);
92 ASSERT_TRUE(typeface->copyTableData(0) == nullptr);
93 ASSERT_EQ(typeface->fontFamily(), fontFamily);
94 ASSERT_EQ(typeface->fontStyle(), fontStyle);
95 ASSERT_EQ(typeface->glyphsCount(), static_cast<size_t>(3));
96
97 builder.addGlyph(std::make_shared<GlyphPathProvider>(4));
98
99 typeface = builder.detach();
100 ASSERT_TRUE(typeface != nullptr);
101 ASSERT_EQ(typeface->glyphsCount(), static_cast<size_t>(4));
102
103 ContextScope scope;
104 auto context = scope.getContext();
105 ASSERT_TRUE(context != nullptr);
106 auto surface = Surface::Make(context, 200, 100);
107 auto canvas = surface->getCanvas();
108
109 auto paint = Paint();
110 paint.setColor(Color::Red());
111
112 float scaleFactor = 1.0f;
113 canvas->scale(scaleFactor, scaleFactor);
114
115 Font font(std::move(typeface), 1.f);
116 std::vector<GlyphID> glyphIDs1 = {1, 2, 3};
117 std::vector<Point> positions1 = {};
118 positions1.push_back(Point::Make(10.0f, 0.0f));
119 positions1.push_back(Point::Make(60.0f, 0.0f));
120 positions1.push_back(Point::Make(120.0f, 0.0f));
121 canvas->drawGlyphs(glyphIDs1.data(), positions1.data(), glyphIDs1.size(), font, paint);
122
123 EXPECT_TRUE(Baseline::Compare(surface, "TypefaceTest/CustomPathTypeface"));
124}
125
126TGFX_TEST(TypefaceTest, CustomImageTypeface) {
127 const std::string fontFamily = "customImage";

Callers

nothing calls this directly

Calls 15

MakeFunction · 0.85
CompareFunction · 0.85
setFontNameMethod · 0.80
addGlyphMethod · 0.80
detachMethod · 0.80
drawGlyphsMethod · 0.80
PaintClass · 0.50
hasOutlinesMethod · 0.45
hasColorMethod · 0.45
openStreamMethod · 0.45
copyTableDataMethod · 0.45
fontFamilyMethod · 0.45

Tested by

no test coverage detected