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
16 #ifndef DRAWING_CANVAS_H
17 #define DRAWING_CANVAS_H
18 #include "draw/canvas.h"
19 #include "drawing_error_code.h"
20 #include "utils/rect.h"
21 #include "utils/sampling_options.h"
22
23 namespace {
24 // Default typeface does not support chinese characters, needs to load chinese character ttf file.
25 static constexpr char ZH_CN_TTF[] = "/system/fonts/HarmonyOS_Sans_SC.ttf";
26 }
27
28 namespace OHOS {
29 namespace Media {
30 class PixelMap;
31 }
32 }
33
34 class DrawingCanvasUtils {
35 public:
36 static void DrawPixelMapRect(OHOS::Rosen::Drawing::Canvas* canvas, std::shared_ptr<OHOS::Media::PixelMap> pixelMap,
37 const OHOS::Rosen::Drawing::Rect* src, const OHOS::Rosen::Drawing::Rect* dst,
38 const OHOS::Rosen::Drawing::SamplingOptions* sampling);
39 };
40
g_LoadZhCnTypeface()41 inline std::shared_ptr<OHOS::Rosen::Drawing::Typeface> g_LoadZhCnTypeface()
42 {
43 auto typeface = OHOS::Rosen::Drawing::Typeface::MakeFromFile(ZH_CN_TTF);
44 if (typeface == nullptr) {
45 typeface = OHOS::Rosen::Drawing::Typeface::MakeDefault();
46 }
47 return typeface;
48 }
49
50 extern OH_Drawing_ErrorCode g_drawingErrorCode;
51 #endif // DRAWING_CANVAS_H