Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shape unit test #330

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/baseline/version.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"altas": "b1cfcd4",
"blendMode": "b3076a3",
"drawImage": "8cb853c",
"drawShape": "fb9a840",
"filter_mode_linear": "d010fb8",
"filter_mode_nearest": "d010fb8",
"hardware_render_target_blend": "d010fb8",
Expand Down
55 changes: 55 additions & 0 deletions test/src/CanvasTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,61 @@ TGFX_TEST(CanvasTest, shape) {
device->unlock();
}

TGFX_TEST(CanvasTest, drawShape) {
auto device = DevicePool::Make();
ASSERT_TRUE(device != nullptr);
auto context = device->lockContext();
ASSERT_TRUE(context != nullptr);
auto width = 300;
auto height = 200;
auto surface = Surface::Make(context, width, height);
auto canvas = surface->getCanvas();
canvas->clearRect(Rect::MakeWH(surface->width(), surface->height()), Color::White());
Paint paint;
paint.setStyle(PaintStyle::Stroke);
paint.setColor(Color::Red());
Path path = {};
auto rect = Rect::MakeWH(50, 50);
path.addRect(rect);
auto shape = Shape::MakeFrom(path);
auto transShape = Shape::ApplyMatrix(shape, Matrix::MakeTrans(10, 10));
canvas->drawShape(transShape, paint);
auto sacaleShape = Shape::ApplyMatrix(shape, Matrix::MakeScale(1.5, 0.5));
sacaleShape = Shape::ApplyMatrix(sacaleShape, Matrix::MakeTrans(10, 70));
canvas->setMatrix(Matrix::MakeScale(1.5, 1.5));
canvas->drawShape(sacaleShape, paint);

paint.setStyle(PaintStyle::Fill);
paint.setColor(Color::Blue());
auto mergeShape1 = Shape::ApplyMatrix(shape, Matrix::MakeTrans(0, 60));
mergeShape1 = Shape::Merge(mergeShape1, shape);
mergeShape1 = Shape::ApplyMatrix(mergeShape1, Matrix::MakeTrans(100, 10));
canvas->setMatrix(Matrix::MakeScale(1, 1));
canvas->drawShape(mergeShape1, paint);
paint.setColor(Color::Green());
auto mergeShape2 = Shape::ApplyMatrix(shape, Matrix::MakeTrans(0, 30));
mergeShape2 = Shape::Merge(mergeShape2, shape, PathOp::Intersect);
mergeShape2 = Shape::ApplyMatrix(mergeShape2, Matrix::MakeTrans(170, 10));
canvas->drawShape(mergeShape2, paint);

paint.setStyle(PaintStyle::Stroke);
auto typeface =
Typeface::MakeFromPath(ProjectPath::Absolute("resources/font/NotoSerifSC-Regular.otf"));
Font font(typeface, 30.f);
font.setFauxBold(true);
auto textBlob = TextBlob::MakeFrom("Hello TGFX", font);
auto textShape = Shape::MakeFrom(textBlob);
textShape = Shape::ApplyMatrix(textShape, Matrix::MakeTrans(10, 70));
auto matrix = Matrix::MakeRotate(10);
matrix.preConcat(Matrix::MakeScale(2, 1));
matrix.preConcat(Matrix::MakeTrans(0, 70));
canvas->setMatrix(matrix);
canvas->drawShape(textShape, paint);
EXPECT_TRUE(Baseline::Compare(surface, "CanvasTest/drawShape"));

device->unlock();
}

TGFX_TEST(CanvasTest, image) {
auto device = DevicePool::Make();
ASSERT_TRUE(device != nullptr);
Expand Down