• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025-2025 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 FONT_HARFBUZZ_H
17 #define FONT_HARFBUZZ_H
18 
19 #include <hb.h>
20 #include <hb-ot.h>
21 
22 #include "modules/skshaper/include/SkShaper.h"
23 #include "text/font.h"
24 #include "text/typeface.h"
25 
26 namespace OHOS {
27 namespace Rosen {
28 namespace Drawing {
29 class FontHarfbuzz {
30 public:
31 #ifdef USE_M133_SKIA
32     using HBFont = std::unique_ptr<hb_font_t, SkFunctionObject<hb_font_destroy>>;
33     using HBFace = std::unique_ptr<hb_face_t, SkFunctionObject<hb_face_destroy>>;
34     using HBBuffer = std::unique_ptr<hb_buffer_t, SkFunctionObject<hb_buffer_destroy>>;
35 #else
36     template <typename T, typename P, P* p> using resource = std::unique_ptr<T, SkFunctionWrapper<P, p>>;
37     using HBFont = resource<hb_font_t, decltype(hb_font_destroy), hb_font_destroy>;
38     using HBFace = resource<hb_face_t, decltype(hb_face_destroy), hb_face_destroy>;
39     using HBBuffer = resource<hb_buffer_t, decltype(hb_buffer_destroy), hb_buffer_destroy>;
40 #endif
41 
42     static hb_bool_t SetGlyph(hb_font_t* hbFont, void* fontData, hb_codepoint_t unicode,
43         hb_codepoint_t variation_selector, hb_codepoint_t* glyph, void* userData);
44     static hb_bool_t SetNominalGlyph(hb_font_t* hbFont, void* fontData, hb_codepoint_t unicode, hb_codepoint_t* glyph,
45         void* userData);
46     static unsigned SetNominalGlyphs(hb_font_t *hbFont, void *fontData, unsigned int count,
47         const hb_codepoint_t *unicodes, unsigned int unicodeStride, hb_codepoint_t *glyphs, unsigned int glyphStride,
48         void *userData);
49     static hb_position_t SetGlyphAdvance(hb_font_t* hbFont, void* fontData, hb_codepoint_t hbGlyph, void* userData);
50     static hb_bool_t GetGlyphExtents(hb_font_t* hbFont, void* fontData, hb_codepoint_t hbGlyph,
51         hb_glyph_extents_t* extents, void* userData);
52     static void SetGlyphAdvances(hb_font_t* hbFont, void* fontData, unsigned count, const hb_codepoint_t* glyphs,
53         unsigned int glyphStride, hb_position_t* advances, unsigned int advanceStride, void* userData);
54     static HBFont CreateTypefaceHbFont(const Typeface& typeface);
55     static HBFont CreateSubHbFont(const Font& font, const HBFont& typefaceFont);
56 };
57 } // namespace Drawing
58 } // namespace Rosen
59 } // namespace OHOS
60 #endif