1 /*
2 * Copyright (c) 2024 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 #include "clipped_cubic.h"
16 #include <native_drawing/drawing_path.h>
17 #include <native_drawing/drawing_rect.h>
18 #include <native_drawing/drawing_brush.h>
19
20 enum {
21 K_W = 1240,
22 K_H = 390,
23 };
24
ClippedCubic()25 ClippedCubic::ClippedCubic()
26 {
27 // file gm/cubicpaths.cpp
28 bitmapWidth_ = K_W;
29 bitmapHeight_ = K_H;
30 fileName_ = "clippedcubic";
31 }
32
OnTestFunction(OH_Drawing_Canvas * canvas)33 void ClippedCubic::OnTestFunction(OH_Drawing_Canvas *canvas)
34 {
35 OH_Drawing_Path *path = OH_Drawing_PathCreate();
36 OH_Drawing_PathMoveTo(path, float(0), float(0));
37 OH_Drawing_PathCubicTo(path, float(140), float(150), float(40), // 140 150 40坐标
38 float(10), float(170), float(150)); // 10 170 150 坐标
39
40 OH_Drawing_Rect *bounds = OH_Drawing_RectCreate(float(0), float(0), float(170), float(150)); // 170 150 坐标
41
42 OH_Drawing_Brush *brush = OH_Drawing_BrushCreate();
43 OH_Drawing_CanvasAttachBrush(canvas, brush);
44
45 for (float dy = -1; dy <= 1; dy += 1) {
46 OH_Drawing_CanvasSave(canvas);
47 for (float dx = -1; dx <= 1; dx += 1) {
48 OH_Drawing_CanvasSave(canvas);
49 OH_Drawing_CanvasClipRect(canvas, bounds, INTERSECT, false);
50 OH_Drawing_CanvasTranslate(canvas, dx, dy);
51 OH_Drawing_CanvasDrawPath(canvas, path);
52 OH_Drawing_CanvasRestore(canvas);
53 OH_Drawing_CanvasTranslate(canvas, OH_Drawing_RectGetWidth(bounds), 0);
54 }
55 OH_Drawing_CanvasRestore(canvas);
56 OH_Drawing_CanvasTranslate(canvas, 0, OH_Drawing_RectGetHeight(bounds));
57 }
58
59 OH_Drawing_CanvasDetachBrush(canvas);
60 OH_Drawing_BrushDestroy(brush);
61 OH_Drawing_RectDestroy(bounds);
62 OH_Drawing_PathDestroy(path);
63 }
64