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 "skbug_8955.h"
16
17 #include <native_drawing/drawing_brush.h>
18 #include <native_drawing/drawing_font.h>
19 #include <native_drawing/drawing_pen.h>
20 #include <native_drawing/drawing_text_blob.h>
21
22 #include "test_common.h"
23
24 #include "common/log_common.h"
25
26 enum {
27 K_W = 100,
28 K_H = 100,
29 };
30
SkBug8955()31 SkBug8955::SkBug8955()
32 {
33 // dm file gm/skbug_8955.cpp
34 bitmapWidth_ = K_W;
35 bitmapHeight_ = K_H;
36 fileName_ = "skbug_8955";
37 }
38
OnTestFunction(OH_Drawing_Canvas * canvas)39 void SkBug8955::OnTestFunction(OH_Drawing_Canvas* canvas)
40 {
41 OH_Drawing_Brush* brush = OH_Drawing_BrushCreate();
42 OH_Drawing_Font* font = OH_Drawing_FontCreate();
43 float fSize = 50.f;
44 OH_Drawing_FontSetTextSize(font, fSize);
45 auto blob = OH_Drawing_TextBlobCreateFromText("+", 1, font, TEXT_ENCODING_UTF8); // 1 为字符串长度
46 OH_Drawing_CanvasSave(canvas);
47 OH_Drawing_CanvasScale(canvas, 0, 0);
48 OH_Drawing_CanvasAttachBrush(canvas, brush);
49 float x = 30.f;
50 float y = 60.f;
51 OH_Drawing_CanvasDrawTextBlob(canvas, blob, x, y);
52 OH_Drawing_CanvasRestore(canvas);
53 OH_Drawing_CanvasDrawTextBlob(canvas, blob, x, y);
54
55 OH_Drawing_CanvasDetachBrush(canvas);
56 OH_Drawing_FontDestroy(font);
57 OH_Drawing_BrushDestroy(brush);
58 OH_Drawing_TextBlobDestroy(blob);
59 }
60