• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "ui_test_canvas.h"
17 #include "common/screen.h"
18 #include "components/ui_label.h"
19 #include "test_resource_config.h"
20 
21 namespace OHOS {
SetUp()22 void UITestCanvas::SetUp()
23 {
24     if (container_ == nullptr) {
25         container_ = new UIScrollView();
26         container_->Resize(Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight() - BACK_BUTTON_HEIGHT);
27         container_->SetHorizontalScrollState(false);
28         container_->SetThrowDrag(true);
29     }
30     positionY_ = 0;
31 }
32 
TearDown()33 void UITestCanvas::TearDown()
34 {
35     DeleteChildren(container_);
36     container_ = nullptr;
37 }
38 
GetTestView()39 const UIView* UITestCanvas::GetTestView()
40 {
41     UIKitCanvasTestDrawLine001();
42     UIKitCanvasTestDrawLine002();
43     UIKitCanvasTestDrawCurve001();
44     UIKitCanvasTestDrawCurve002();
45     UIKitCanvasTestDrawRect001();
46     UIKitCanvasTestDrawRect002();
47     UIKitCanvasTestDrawRect003();
48     UIKitCanvasTestDrawCircle001();
49     UIKitCanvasTestDrawCircle002();
50     UIKitCanvasTestDrawCircle003();
51     UIKitCanvasTestDrawArc001();
52     UIKitCanvasTestDrawImage001();
53     UIKitCanvasTestDrawLabel001();
54     UIKitCanvasTestDrawSector001();
55     UIKitCanvasTestClear001();
56     UIKitCanvasTestDrawPath001();
57     UIKitCanvasTestDrawPath002();
58     UIKitCanvasTestDrawPath003();
59     UIKitCanvasTestDrawPath004();
60     UIKitCanvasTestDrawPath005();
61     UIKitCanvasTestDrawPath006();
62     UIKitCanvasTestDrawPath007();
63     UIKitCanvasTestDrawPath008();
64     UIKitCanvasTestDrawPath009();
65     UIKitCanvasTestDrawPath010();
66     UIKitCanvasTestDrawPath011();
67     UIKitCanvasTestDrawPath012();
68     UIKitCanvasTestDrawPath013();
69     UIKitCanvasTestDrawPath014();
70     UIKitCanvasTestDrawPath015();
71     UIKitCanvasTestDrawPath016();
72     UIKitCanvasTestDrawPath017();
73     UIKitCanvasTestDrawPath018();
74     UIKitCanvasTestDrawPath019();
75     UIKitCanvasTestDrawPath020();
76     UIKitCanvasTestDrawPath021();
77     UIKitCanvasTestDrawPath022();
78     UIKitCanvasTestDrawPath023();
79     UIKitCanvasTestDrawPath024();
80     UIKitCanvasTestDrawPath025();
81     UIKitCanvasTestDrawPath026();
82     UIKitCanvasTestDrawPath027();
83     UIKitCanvasTestDrawPath028();
84     UIKitCanvasTestDrawPath029();
85     UIKitCanvasTestDrawPath030();
86     UIKitCanvasTestDrawPath031();
87     UIKitCanvasTestDrawPath032();
88     UIKitCanvasTestDrawPath033();
89     UIKitCanvasTestDrawPath034();
90 
91     return container_;
92 }
93 
CreateTitleLabel(const char * title)94 void UITestCanvas::CreateTitleLabel(const char* title)
95 {
96     UILabel* titleLabel = new UILabel();
97     titleLabel->SetPosition(TEXT_DISTANCE_TO_LEFT_SIDE, positionY_, Screen::GetInstance().GetWidth(), TITLE_HEIGHT);
98     titleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
99     titleLabel->SetText(title);
100     container_->Add(titleLabel);
101     positionY_ += TITLE_HEIGHT + 8; // 8: gap
102 }
103 
CreateCanvas()104 UICanvas* UITestCanvas::CreateCanvas()
105 {
106     UICanvas* canvas = new UICanvas();
107     canvas->SetHeight(CANVAS_HEIGHT);
108     canvas->SetWidth(CANVAS_WIDTH);
109     canvas->SetPosition(VIEW_DISTANCE_TO_LEFT_SIDE, positionY_);
110     canvas->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full);
111     container_->Add(canvas);
112     positionY_ += CANVAS_HEIGHT + GAP;
113     return canvas;
114 }
115 
UIKitCanvasTestDrawLine001()116 void UITestCanvas::UIKitCanvasTestDrawLine001()
117 {
118     if (container_ == nullptr) {
119         return;
120     }
121     CreateTitleLabel("绘制直线");
122     UICanvas* canvas = CreateCanvas();
123     Paint paint;
124     // {0, 10}: Start point coordinates x, y; {50, 10}: end point coordinates x, y
125     canvas->DrawLine({0, 10}, {50, 10}, paint);
126 }
127 
UIKitCanvasTestDrawLine002()128 void UITestCanvas::UIKitCanvasTestDrawLine002()
129 {
130     if (container_ == nullptr) {
131         return;
132     }
133     CreateTitleLabel("绘制直线");
134     UICanvas* canvas = CreateCanvas();
135 
136     Paint paint;
137     paint.SetStrokeWidth(5); // 5: line width
138     canvas->SetStartPosition({ 50, 10 }); // {50, 10}: Start point coordinates x, y;
139     canvas->DrawLine({ 100, 50 }, paint); // {100, 50}: end point coordinates x, y
140 }
141 
UIKitCanvasTestDrawCurve001()142 void UITestCanvas::UIKitCanvasTestDrawCurve001()
143 {
144     if (container_ == nullptr) {
145         return;
146     }
147     CreateTitleLabel("绘制曲线");
148     UICanvas* canvas = CreateCanvas();
149 
150     Paint paint;
151     paint.SetStrokeColor(Color::Red());
152     canvas->DrawCurve({ 100, 50 }, { 150, 50 }, { 150, 50 }, { 150, 100 }, paint);
153 }
154 
UIKitCanvasTestDrawCurve002()155 void UITestCanvas::UIKitCanvasTestDrawCurve002()
156 {
157     if (container_ == nullptr) {
158         return;
159     }
160     CreateTitleLabel("绘制曲线");
161     UICanvas* canvas = CreateCanvas();
162 
163     Paint paint;
164     paint.SetStrokeColor(Color::Red());
165     canvas->DrawCurve({ 100, 50 }, { 150, 50 }, { 150, 100 }, paint);
166 }
167 
UIKitCanvasTestDrawRect001()168 void UITestCanvas::UIKitCanvasTestDrawRect001()
169 {
170     if (container_ == nullptr) {
171         return;
172     }
173     CreateTitleLabel("矩形填充");
174     UICanvas* canvas = CreateCanvas();
175 
176     Paint paint;
177     paint.SetStyle(Paint::PaintStyle::FILL_STYLE);
178     paint.SetFillColor(Color::Yellow());
179     paint.SetStrokeWidth(30); // 30: line width
180     // {100, 10}: left corner coordinates point, 50: width, 50: rectangle style
181     canvas->DrawRect({ 100, 10 }, 50, 50, paint);
182 }
183 
UIKitCanvasTestDrawRect002()184 void UITestCanvas::UIKitCanvasTestDrawRect002()
185 {
186     if (container_ == nullptr) {
187         return;
188     }
189     CreateTitleLabel("矩形描边");
190     UICanvas* canvas = CreateCanvas();
191 
192     Paint paint;
193     paint.SetStyle(Paint::PaintStyle::STROKE_STYLE);
194     paint.SetStrokeColor(Color::Blue());
195     // {200, 10}: left corner coordinates point, 50: width, 50: rectangle style
196     canvas->DrawRect({ 200, 10 }, 50, 50, paint);
197 }
198 
UIKitCanvasTestDrawRect003()199 void UITestCanvas::UIKitCanvasTestDrawRect003()
200 {
201     if (container_ == nullptr) {
202         return;
203     }
204     CreateTitleLabel("矩形填充 + 描边");
205     UICanvas* canvas = CreateCanvas();
206 
207     Paint paint;
208     paint.SetStyle(Paint::PaintStyle::STROKE_FILL_STYLE);
209     paint.SetFillColor(Color::Yellow());
210     paint.SetStrokeColor(Color::Blue());
211     // {300, 10}: left corner coordinates point, 50: width, 50: rectangle style
212     canvas->DrawRect({ 300, 10 }, 50, 50, paint);
213 }
214 
UIKitCanvasTestDrawCircle001()215 void UITestCanvas::UIKitCanvasTestDrawCircle001()
216 {
217     if (container_ == nullptr) {
218         return;
219     }
220     CreateTitleLabel("圆形填充");
221     UICanvas* canvas = CreateCanvas();
222 
223     Paint paint;
224     paint.SetStyle(Paint::PaintStyle::FILL_STYLE);
225     paint.SetStrokeColor(Color::Yellow());
226     paint.SetFillColor(Color::Yellow());
227     paint.SetStrokeWidth(10); // 10: line width
228     paint.SetOpacity(127);    // 127: opacity
229     // {100, 100}: circle center coordinates, 30: circle radius
230     canvas->DrawCircle({ 100, 100 }, 30, paint);
231 }
232 
UIKitCanvasTestDrawCircle002()233 void UITestCanvas::UIKitCanvasTestDrawCircle002()
234 {
235     if (container_ == nullptr) {
236         return;
237     }
238     CreateTitleLabel("圆形描边");
239     UICanvas* canvas = CreateCanvas();
240 
241     Paint paint;
242     paint.SetStyle(Paint::PaintStyle::STROKE_STYLE);
243     paint.SetStrokeColor(Color::Blue());
244     paint.SetStrokeWidth(10); // 10: line width
245     paint.SetOpacity(127);    // 127: opacity
246     // {200, 100}: circle center coordinates, 30: circle radius
247     canvas->DrawCircle({ 200, 100 }, 30, paint);
248 }
249 
UIKitCanvasTestDrawCircle003()250 void UITestCanvas::UIKitCanvasTestDrawCircle003()
251 {
252     if (container_ == nullptr) {
253         return;
254     }
255     CreateTitleLabel("圆形填充 + 描边");
256     UICanvas* canvas = CreateCanvas();
257 
258     Paint paint;
259     paint.SetStyle(Paint::PaintStyle::STROKE_FILL_STYLE);
260     paint.SetFillColor(Color::Yellow());
261     paint.SetStrokeColor(Color::Blue());
262     paint.SetStrokeWidth(10); // 10: line width
263     paint.SetOpacity(127);    // 127: opacity
264     // {300, 100}: circle center coordinates, 30: circle radius
265     canvas->DrawCircle({ 300, 100 }, 30, paint);
266 }
267 
UIKitCanvasTestDrawArc001()268 void UITestCanvas::UIKitCanvasTestDrawArc001()
269 {
270     if (container_ == nullptr) {
271         return;
272     }
273     CreateTitleLabel("绘制弧线");
274     UICanvas* canvas = CreateCanvas();
275 
276     Paint paint;
277     paint.SetStyle(Paint::PaintStyle::STROKE_STYLE);
278     paint.SetStrokeColor(Color::Red());
279     paint.SetStrokeWidth(10); // 10: line width
280     // {100, 150}: arc's center coordinates, 50: arc radius, 135: start angle, 270: end angle
281     canvas->DrawArc({ 100, 150 }, 50, 135, 270, paint);
282 }
283 
UIKitCanvasTestDrawImage001()284 void UITestCanvas::UIKitCanvasTestDrawImage001()
285 {
286     if (container_ == nullptr) {
287         return;
288     }
289     CreateTitleLabel("绘制图片");
290     UICanvas* canvas = CreateCanvas();
291 
292     Paint paint;
293     paint.SetOpacity(127); // 127: opacity
294     // {200, 50}: start point coordinates
295     canvas->DrawImage({ 200, 50 }, GREEN_IMAGE_PATH, paint);
296 }
297 
UIKitCanvasTestDrawLabel001()298 void UITestCanvas::UIKitCanvasTestDrawLabel001()
299 {
300     if (container_ == nullptr) {
301         return;
302     }
303     CreateTitleLabel("绘制文字");
304     UICanvas* canvas = CreateCanvas();
305 
306     Paint paint;
307     paint.SetFillColor(Color::Blue());
308     UICanvas::FontStyle fontStyle;
309     fontStyle.align = TEXT_ALIGNMENT_RIGHT;
310     fontStyle.direct = TEXT_DIRECT_RTL;
311     fontStyle.fontName = DEFAULT_VECTOR_FONT_FILENAME;
312     fontStyle.fontSize = 30;    // 30: font size
313     fontStyle.letterSpace = 10; // 10 letter space
314     // {50, 50}: start point coordinates, 100: max width
315     canvas->DrawLabel({ 50, 50 }, "canvas绘制字体", 100, fontStyle, paint);
316 }
317 
UIKitCanvasTestDrawSector001()318 void UITestCanvas::UIKitCanvasTestDrawSector001()
319 {
320     if (container_ == nullptr) {
321         return;
322     }
323     CreateTitleLabel("扇形填充");
324     UICanvas* canvas = CreateCanvas();
325 
326     Paint paint;
327     paint.SetStyle(Paint::PaintStyle::FILL_STYLE);
328     paint.SetFillColor(Color::Yellow());
329     // {350, 150}: sector's center coordinates, 100: sector radius, 0: start angle, 30: end angle
330     canvas->DrawSector({ 350, 150 }, 100, 0, 30, paint);
331 }
332 
UIKitCanvasTestClear001()333 void UITestCanvas::UIKitCanvasTestClear001()
334 {
335     if (container_ == nullptr) {
336         return;
337     }
338     CreateTitleLabel("清空画布,无显示");
339     UICanvas* canvas = CreateCanvas();
340 
341     Paint paint;
342     // {0, 10}: Start point coordinates x, y; {50, 10}: end point coordinates x, y
343     canvas->DrawLine({ 0, 10 }, { 50, 10 }, paint);
344     canvas->Clear();
345 }
346 
UIKitCanvasTestDrawPath001()347 void UITestCanvas::UIKitCanvasTestDrawPath001()
348 {
349     if (container_ == nullptr) {
350         return;
351     }
352     CreateTitleLabel("moveTo,无显示");
353     UICanvas* canvas = CreateCanvas();
354 
355     Paint paint;
356     canvas->BeginPath();
357     canvas->MoveTo({ START1_X, START1_Y });
358     canvas->ClosePath();
359     canvas->DrawPath(paint);
360 }
361 
UIKitCanvasTestDrawPath002()362 void UITestCanvas::UIKitCanvasTestDrawPath002()
363 {
364     if (container_ == nullptr) {
365         return;
366     }
367     CreateTitleLabel("lineTo,无显示");
368     UICanvas* canvas = CreateCanvas();
369 
370     Paint paint;
371     canvas->BeginPath();
372     canvas->LineTo({ LINE1_X, LINE1_Y });
373     canvas->DrawPath(paint);
374 }
375 
UIKitCanvasTestDrawPath003()376 void UITestCanvas::UIKitCanvasTestDrawPath003()
377 {
378     if (container_ == nullptr) {
379         return;
380     }
381     CreateTitleLabel("arc");
382     UICanvas* canvas = CreateCanvas();
383 
384     Paint paint;
385     canvas->BeginPath();
386     canvas->ArcTo({ CENTER_X, CENTER_Y }, RADIUS, START_ANGLE, END_ANGLE);
387     canvas->DrawPath(paint);
388 }
389 
UIKitCanvasTestDrawPath004()390 void UITestCanvas::UIKitCanvasTestDrawPath004()
391 {
392     if (container_ == nullptr) {
393         return;
394     }
395     CreateTitleLabel("rect");
396     UICanvas* canvas = CreateCanvas();
397 
398     Paint paint;
399     canvas->BeginPath();
400     canvas->AddRect({ RECT_X, RECT_Y }, RECT_HEIGHT, RECT_WIDTH);
401     canvas->DrawPath(paint);
402 }
403 
UIKitCanvasTestDrawPath005()404 void UITestCanvas::UIKitCanvasTestDrawPath005()
405 {
406     if (container_ == nullptr) {
407         return;
408     }
409     CreateTitleLabel("closePath,无显示");
410     UICanvas* canvas = CreateCanvas();
411 
412     Paint paint;
413     canvas->BeginPath();
414     canvas->ClosePath();
415     canvas->DrawPath(paint);
416 }
417 
UIKitCanvasTestDrawPath006()418 void UITestCanvas::UIKitCanvasTestDrawPath006()
419 {
420     if (container_ == nullptr) {
421         return;
422     }
423     CreateTitleLabel("moveTo + lineTo");
424     UICanvas* canvas = CreateCanvas();
425 
426     Paint paint;
427     canvas->BeginPath();
428     canvas->MoveTo({ START1_X, START1_Y });
429     canvas->LineTo({ LINE1_X, LINE1_Y });
430     canvas->DrawPath(paint);
431 }
432 
UIKitCanvasTestDrawPath007()433 void UITestCanvas::UIKitCanvasTestDrawPath007()
434 {
435     if (container_ == nullptr) {
436         return;
437     }
438     CreateTitleLabel("moveTo + arc");
439     UICanvas* canvas = CreateCanvas();
440 
441     Paint paint;
442     canvas->BeginPath();
443     canvas->MoveTo({ START1_X, START1_Y });
444     canvas->ArcTo({ CENTER_X, CENTER_Y }, RADIUS, START_ANGLE, END_ANGLE);
445     canvas->DrawPath(paint);
446 }
447 
UIKitCanvasTestDrawPath008()448 void UITestCanvas::UIKitCanvasTestDrawPath008()
449 {
450     if (container_ == nullptr) {
451         return;
452     }
453     CreateTitleLabel("moveTo + rect");
454     UICanvas* canvas = CreateCanvas();
455 
456     Paint paint;
457     canvas->BeginPath();
458     canvas->MoveTo({ START1_X, START1_Y });
459     canvas->AddRect({ RECT_X, RECT_Y }, RECT_HEIGHT, RECT_WIDTH);
460     canvas->DrawPath(paint);
461 }
462 
UIKitCanvasTestDrawPath009()463 void UITestCanvas::UIKitCanvasTestDrawPath009()
464 {
465     if (container_ == nullptr) {
466         return;
467     }
468     CreateTitleLabel("moveTo + closePath");
469     UICanvas* canvas = CreateCanvas();
470 
471     Paint paint;
472     canvas->BeginPath();
473     canvas->MoveTo({ START1_X, START1_Y });
474     canvas->LineTo({ LINE1_X, LINE1_Y });
475     canvas->LineTo({ LINE2_X, LINE2_Y });
476     canvas->ClosePath();
477     canvas->DrawPath(paint);
478 }
479 
UIKitCanvasTestDrawPath010()480 void UITestCanvas::UIKitCanvasTestDrawPath010()
481 {
482     if (container_ == nullptr) {
483         return;
484     }
485     CreateTitleLabel("闭合路径调用closePath");
486     UICanvas* canvas = CreateCanvas();
487 
488     Paint paint;
489     canvas->BeginPath();
490     canvas->MoveTo({ START1_X, START1_Y });
491     canvas->LineTo({ LINE1_X, LINE1_Y });
492     canvas->LineTo({ LINE2_X, LINE2_Y });
493     canvas->LineTo({ START1_X, START1_Y });
494     canvas->ClosePath();
495     canvas->DrawPath(paint);
496 }
497 
UIKitCanvasTestDrawPath011()498 void UITestCanvas::UIKitCanvasTestDrawPath011()
499 {
500     if (container_ == nullptr) {
501         return;
502     }
503     CreateTitleLabel("moveTo + lineTo + moveTo + lineTo");
504     UICanvas* canvas = CreateCanvas();
505 
506     Paint paint;
507     canvas->BeginPath();
508     canvas->MoveTo({ START1_X, START1_Y });
509     canvas->LineTo({ LINE1_X, LINE1_Y });
510     canvas->MoveTo({ START2_X, START2_Y });
511     canvas->LineTo({ LINE2_X, LINE2_Y });
512     canvas->DrawPath(paint);
513 }
514 
UIKitCanvasTestDrawPath012()515 void UITestCanvas::UIKitCanvasTestDrawPath012()
516 {
517     if (container_ == nullptr) {
518         return;
519     }
520     CreateTitleLabel("moveTo + lineTo + arc");
521     UICanvas* canvas = CreateCanvas();
522 
523     Paint paint;
524     canvas->BeginPath();
525     canvas->MoveTo({ START1_X, START1_Y });
526     canvas->LineTo({ LINE1_X, LINE1_Y });
527     canvas->ArcTo({ CENTER_X, CENTER_Y }, RADIUS, START_ANGLE, END_ANGLE);
528     canvas->DrawPath(paint);
529 }
530 
UIKitCanvasTestDrawPath013()531 void UITestCanvas::UIKitCanvasTestDrawPath013()
532 {
533     if (container_ == nullptr) {
534         return;
535     }
536     CreateTitleLabel("moveTo + lineTo + arc + closePath");
537     UICanvas* canvas = CreateCanvas();
538 
539     Paint paint;
540     canvas->BeginPath();
541     canvas->MoveTo({ START1_X, START1_Y });
542     canvas->LineTo({ LINE1_X, LINE1_Y });
543     canvas->ArcTo({ CENTER_X, CENTER_Y }, RADIUS, START_ANGLE, END_ANGLE);
544     canvas->ClosePath();
545     canvas->DrawPath(paint);
546 }
547 
UIKitCanvasTestDrawPath014()548 void UITestCanvas::UIKitCanvasTestDrawPath014()
549 {
550     if (container_ == nullptr) {
551         return;
552     }
553     CreateTitleLabel("moveTo + lineTo + rect");
554     UICanvas* canvas = CreateCanvas();
555 
556     Paint paint;
557     canvas->BeginPath();
558     canvas->MoveTo({ START1_X, START1_Y });
559     canvas->LineTo({ LINE1_X, LINE1_Y });
560     canvas->AddRect({ RECT_X, RECT_Y }, RECT_HEIGHT, RECT_WIDTH);
561     canvas->DrawPath(paint);
562 }
563 
UIKitCanvasTestDrawPath015()564 void UITestCanvas::UIKitCanvasTestDrawPath015()
565 {
566     if (container_ == nullptr) {
567         return;
568     }
569     CreateTitleLabel("moveTo + lineTo + rect + closePath");
570     UICanvas* canvas = CreateCanvas();
571 
572     Paint paint;
573     canvas->BeginPath();
574     canvas->MoveTo({ START1_X, START1_Y });
575     canvas->LineTo({ LINE1_X, LINE1_Y });
576     canvas->AddRect({ RECT_X, RECT_Y }, RECT_HEIGHT, RECT_WIDTH);
577     canvas->ClosePath();
578     canvas->DrawPath(paint);
579 }
580 
UIKitCanvasTestDrawPath016()581 void UITestCanvas::UIKitCanvasTestDrawPath016()
582 {
583     if (container_ == nullptr) {
584         return;
585     }
586     CreateTitleLabel("rect + lineTo");
587     UICanvas* canvas = CreateCanvas();
588 
589     Paint paint;
590     canvas->BeginPath();
591     canvas->AddRect({ RECT_X, RECT_Y }, RECT_HEIGHT, RECT_WIDTH);
592     canvas->LineTo({ LINE1_X, LINE1_Y });
593     canvas->DrawPath(paint);
594 }
595 
UIKitCanvasTestDrawPath017()596 void UITestCanvas::UIKitCanvasTestDrawPath017()
597 {
598     if (container_ == nullptr) {
599         return;
600     }
601     CreateTitleLabel("rect + moveTo + lineTo");
602     UICanvas* canvas = CreateCanvas();
603 
604     Paint paint;
605     canvas->BeginPath();
606     canvas->AddRect({ RECT_X, RECT_Y }, RECT_HEIGHT, RECT_WIDTH);
607     canvas->MoveTo({ START1_X, START1_Y });
608     canvas->LineTo({ LINE1_X, LINE1_Y });
609     canvas->DrawPath(paint);
610 }
611 
UIKitCanvasTestDrawPath018()612 void UITestCanvas::UIKitCanvasTestDrawPath018()
613 {
614     if (container_ == nullptr) {
615         return;
616     }
617     CreateTitleLabel("rect + arc");
618     UICanvas* canvas = CreateCanvas();
619 
620     Paint paint;
621     canvas->BeginPath();
622     canvas->AddRect({ RECT_X, RECT_Y }, RECT_HEIGHT, RECT_WIDTH);
623     canvas->ArcTo({ CENTER_X, CENTER_Y }, RADIUS, START_ANGLE, END_ANGLE);
624     canvas->DrawPath(paint);
625 }
626 
UIKitCanvasTestDrawPath019()627 void UITestCanvas::UIKitCanvasTestDrawPath019()
628 {
629     if (container_ == nullptr) {
630         return;
631     }
632     CreateTitleLabel("arc + rect");
633     UICanvas* canvas = CreateCanvas();
634 
635     Paint paint;
636     canvas->BeginPath();
637     canvas->ArcTo({ CENTER_X, CENTER_Y }, RADIUS, START_ANGLE, END_ANGLE);
638     canvas->AddRect({ RECT_X, RECT_Y }, RECT_HEIGHT, RECT_WIDTH);
639     canvas->DrawPath(paint);
640 }
641 
UIKitCanvasTestDrawPath020()642 void UITestCanvas::UIKitCanvasTestDrawPath020()
643 {
644     if (container_ == nullptr) {
645         return;
646     }
647     CreateTitleLabel("moveTo + arc + closePath + lineTo");
648     UICanvas* canvas = CreateCanvas();
649 
650     Paint paint;
651     canvas->BeginPath();
652     canvas->MoveTo({ START1_X, START1_Y });
653     canvas->ArcTo({ CENTER_X, CENTER_Y }, RADIUS, START_ANGLE, END_ANGLE);
654     canvas->ClosePath();
655     canvas->LineTo({ LINE1_X, LINE1_Y });
656     canvas->DrawPath(paint);
657 }
658 
UIKitCanvasTestDrawPath021()659 void UITestCanvas::UIKitCanvasTestDrawPath021()
660 {
661     if (container_ == nullptr) {
662         return;
663     }
664     CreateTitleLabel("不调用beginPath,无显示");
665     UICanvas* canvas = CreateCanvas();
666 
667     Paint paint;
668     canvas->MoveTo({ START1_X, START1_Y });
669     canvas->ArcTo({ CENTER_X, CENTER_Y }, RADIUS, START_ANGLE, END_ANGLE);
670     canvas->ClosePath();
671     canvas->LineTo({ LINE1_X, LINE1_Y });
672     canvas->DrawPath(paint);
673 }
674 
UIKitCanvasTestDrawPath022()675 void UITestCanvas::UIKitCanvasTestDrawPath022()
676 {
677     if (container_ == nullptr) {
678         return;
679     }
680     CreateTitleLabel("不调用drawPath,无显示");
681     UICanvas* canvas = CreateCanvas();
682 
683     Paint paint;
684     canvas->BeginPath();
685     canvas->MoveTo({ START1_X, START1_Y });
686     canvas->ArcTo({ CENTER_X, CENTER_Y }, RADIUS, START_ANGLE, END_ANGLE);
687     canvas->ClosePath();
688     canvas->LineTo({ LINE1_X, LINE1_Y });
689 }
690 
UIKitCanvasTestDrawPath023()691 void UITestCanvas::UIKitCanvasTestDrawPath023()
692 {
693     if (container_ == nullptr) {
694         return;
695     }
696     CreateTitleLabel("moveTo + lineTo + closePath");
697     UICanvas* canvas = CreateCanvas();
698 
699     Paint paint;
700     canvas->BeginPath();
701     canvas->MoveTo({ START1_X, START1_Y });
702     canvas->LineTo({ LINE1_X, LINE1_Y });
703     canvas->ClosePath();
704     canvas->DrawPath(paint);
705 }
706 
UIKitCanvasTestDrawPath024()707 void UITestCanvas::UIKitCanvasTestDrawPath024()
708 {
709     if (container_ == nullptr) {
710         return;
711     }
712     CreateTitleLabel("moveTo + closePath,无显示");
713     UICanvas* canvas = CreateCanvas();
714 
715     Paint paint;
716     canvas->BeginPath();
717     canvas->MoveTo({ START1_X, START1_Y });
718     canvas->ClosePath();
719     canvas->DrawPath(paint);
720 }
721 
UIKitCanvasTestDrawPath025()722 void UITestCanvas::UIKitCanvasTestDrawPath025()
723 {
724     if (container_ == nullptr) {
725         return;
726     }
727     CreateTitleLabel("多次drawPath");
728     UICanvas* canvas = CreateCanvas();
729 
730     Paint paint;
731     canvas->BeginPath();
732     canvas->MoveTo({ START1_X, START1_Y });
733     canvas->LineTo({ LINE1_X, LINE1_Y });
734     canvas->DrawPath(paint);
735     paint.SetStrokeColor(Color::Blue());
736     paint.SetStrokeWidth(1);
737     canvas->LineTo({ LINE2_X, LINE2_Y });
738     canvas->DrawPath(paint);
739 }
740 
UIKitCanvasTestDrawPath026()741 void UITestCanvas::UIKitCanvasTestDrawPath026()
742 {
743     if (container_ == nullptr) {
744         return;
745     }
746     CreateTitleLabel("arc起止角度互换");
747     UICanvas* canvas = CreateCanvas();
748 
749     Paint paint;
750     canvas->BeginPath();
751     canvas->MoveTo({ START1_X, START1_Y });
752     canvas->ArcTo({ CENTER_X, CENTER_Y }, RADIUS, START_ANGLE, END_ANGLE);
753 
754     canvas->MoveTo({ START2_X, START2_Y });
755     canvas->ArcTo({ CENTER_X + CENTER_X, CENTER_Y }, RADIUS, END_ANGLE, START_ANGLE);
756 
757     canvas->DrawPath(paint);
758 }
759 
UIKitCanvasTestDrawPath027()760 void UITestCanvas::UIKitCanvasTestDrawPath027()
761 {
762     if (container_ == nullptr) {
763         return;
764     }
765     CreateTitleLabel("arc扫描范围超过360度 ");
766     UICanvas* canvas = CreateCanvas();
767 
768     Paint paint;
769     canvas->BeginPath();
770     canvas->MoveTo({ START1_X, START1_Y });
771     canvas->ArcTo({ CENTER_X, CENTER_Y }, RADIUS, START_ANGLE, START_ANGLE + CIRCLE_IN_DEGREE + QUARTER_IN_DEGREE);
772     canvas->ArcTo({ CENTER_X + CENTER_X, CENTER_Y }, RADIUS, END_ANGLE, START_ANGLE + CIRCLE_IN_DEGREE);
773 
774     canvas->DrawPath(paint);
775 }
776 
UIKitCanvasTestDrawPath028()777 void UITestCanvas::UIKitCanvasTestDrawPath028()
778 {
779     if (container_ == nullptr) {
780         return;
781     }
782     CreateTitleLabel("创建两条路径,只绘制后一条 ");
783     UICanvas* canvas = CreateCanvas();
784 
785     Paint paint;
786     canvas->BeginPath();
787     canvas->MoveTo({ START1_X, START1_Y });
788     canvas->ArcTo({ CENTER_X, CENTER_Y }, RADIUS, START_ANGLE, START_ANGLE + CIRCLE_IN_DEGREE);
789 
790     canvas->BeginPath();
791     canvas->MoveTo({ START2_X, START2_Y });
792     canvas->ArcTo({ CENTER_X + CENTER_X, CENTER_Y }, RADIUS, END_ANGLE, START_ANGLE + CIRCLE_IN_DEGREE);
793 
794     canvas->DrawPath(paint);
795 }
796 
UIKitCanvasTestDrawPath029()797 void UITestCanvas::UIKitCanvasTestDrawPath029()
798 {
799     if (container_ == nullptr) {
800         return;
801     }
802     CreateTitleLabel("绘制两条不同样式的路径 ");
803     UICanvas* canvas = CreateCanvas();
804 
805     Paint paint;
806     canvas->BeginPath();
807     canvas->MoveTo({ START1_X, START1_Y });
808     canvas->ArcTo({ CENTER_X, CENTER_Y }, RADIUS, START_ANGLE, START_ANGLE + CIRCLE_IN_DEGREE);
809     canvas->DrawPath(paint);
810 
811     canvas->BeginPath();
812     canvas->MoveTo({ START2_X, START2_Y });
813     canvas->ArcTo({ CENTER_X + CENTER_X, CENTER_Y }, RADIUS, END_ANGLE, START_ANGLE + CIRCLE_IN_DEGREE);
814     paint.SetStrokeColor(Color::Blue());
815     canvas->DrawPath(paint);
816 }
817 
UIKitCanvasTestDrawPath030()818 void UITestCanvas::UIKitCanvasTestDrawPath030()
819 {
820     if (container_ == nullptr) {
821         return;
822     }
823     CreateTitleLabel("同一条路径绘制100遍 ");
824     UICanvas* canvas = CreateCanvas();
825 
826     Paint paint;
827     canvas->BeginPath();
828     canvas->MoveTo({ START1_X, START1_Y });
829     canvas->LineTo({ LINE1_X, LINE1_Y });
830     canvas->ArcTo({ CENTER_X, CENTER_Y }, RADIUS, START_ANGLE, START_ANGLE + CIRCLE_IN_DEGREE);
831     canvas->AddRect({ RECT_X, RECT_Y }, RECT_HEIGHT, RECT_WIDTH);
832     for (uint8_t i = 0; i < 100; i++) { // 100: number of times for drawing loops
833         canvas->DrawPath(paint);
834     }
835 }
836 
UIKitCanvasTestDrawPath031()837 void UITestCanvas::UIKitCanvasTestDrawPath031()
838 {
839     if (container_ == nullptr) {
840         return;
841     }
842     CreateTitleLabel("绘制直线超出canvas范围");
843     UICanvas* canvas = CreateCanvas();
844 
845     Paint paint;
846     canvas->BeginPath();
847     canvas->MoveTo({ START1_X, START1_Y });
848     canvas->LineTo({ LINE1_X + HORIZONTAL_RESOLUTION, LINE1_Y });
849     canvas->LineTo({ LINE2_X, LINE2_Y });
850     canvas->DrawPath(paint);
851 }
852 
UIKitCanvasTestDrawPath032()853 void UITestCanvas::UIKitCanvasTestDrawPath032()
854 {
855     if (container_ == nullptr) {
856         return;
857     }
858     CreateTitleLabel("绘制直线传入临界值 ");
859     UICanvas* canvas = CreateCanvas();
860 
861     Paint paint;
862     canvas->BeginPath();
863     canvas->MoveTo({ INT16_MAX, INT16_MAX });
864     canvas->LineTo({ 0, 0 });
865 
866     canvas->MoveTo({ 0, 0 });
867     canvas->LineTo({ INT16_MAX, INT16_MAX });
868 
869     canvas->MoveTo({ INT16_MIN, INT16_MIN });
870     canvas->LineTo({ 0, 0 });
871 
872     canvas->MoveTo({ 0, 0 });
873     canvas->LineTo({ INT16_MIN, INT16_MIN });
874     canvas->DrawPath(paint);
875 }
876 
877 
UIKitCanvasTestDrawPath033()878 void UITestCanvas::UIKitCanvasTestDrawPath033()
879 {
880     if (container_ == nullptr) {
881         return;
882     }
883 
884     CreateTitleLabel("绘制arc传入临界值 ");
885     UICanvas* canvas = CreateCanvas();
886 
887     Paint paint;
888     canvas->BeginPath();
889     canvas->ArcTo({ INT16_MAX, INT16_MAX }, RADIUS, START_ANGLE, END_ANGLE);
890     canvas->DrawPath(paint);
891 
892     canvas->BeginPath();
893     canvas->ArcTo({ INT16_MIN, INT16_MIN }, RADIUS, START_ANGLE, END_ANGLE);
894     paint.SetStrokeColor(Color::Red());
895     canvas->DrawPath(paint);
896 
897     canvas->BeginPath();
898     canvas->ArcTo({ CENTER_X, CENTER_Y }, UINT16_MAX, START_ANGLE, END_ANGLE);
899     paint.SetStrokeColor(Color::Yellow());
900     canvas->DrawPath(paint);
901 
902     canvas->BeginPath();
903     canvas->ArcTo({ CENTER_X + CENTER_X, CENTER_Y }, RADIUS, INT16_MIN, INT16_MAX);
904     paint.SetStrokeColor(Color::Blue());
905     canvas->DrawPath(paint);
906 }
907 
UIKitCanvasTestDrawPath034()908 void UITestCanvas::UIKitCanvasTestDrawPath034()
909 {
910     if (container_ == nullptr) {
911         return;
912     }
913 
914     CreateTitleLabel("绘制rect传入临界值 ");
915     UICanvas* canvas = CreateCanvas();
916 
917     Paint paint;
918     canvas->BeginPath();
919     canvas->AddRect({ INT16_MAX, INT16_MAX }, RECT_HEIGHT, RECT_WIDTH);
920     canvas->DrawPath(paint);
921 
922     canvas->BeginPath();
923     canvas->AddRect({ RECT_X, RECT_Y }, INT16_MAX, INT16_MAX);
924     paint.SetStrokeColor(Color::Red());
925     canvas->DrawPath(paint);
926 }
927 } // namespace OHOS