• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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 SKIA_FONT_H
17 #define SKIA_FONT_H
18 
19 #include <memory>
20 
21 #include "include/core/SkFont.h"
22 
23 #include "impl_interface/font_impl.h"
24 #include "text/font.h"
25 
26 namespace OHOS {
27 namespace Rosen {
28 namespace Drawing {
29 class SkiaFont : public FontImpl {
30 public:
31     static inline constexpr AdapterType TYPE = AdapterType::SKIA_ADAPTER;
32 
33     SkiaFont() noexcept = default;
34     SkiaFont(std::shared_ptr<Typeface> typeface, scalar size, scalar scaleX, scalar skewX) noexcept;
35     explicit SkiaFont(const Font& font) noexcept;
36     ~SkiaFont() override = default;
37 
GetType()38     AdapterType GetType() const override
39     {
40         return AdapterType::SKIA_ADAPTER;
41     }
42 
43     void SetEdging(FontEdging edging) override;
44     void SetBaselineSnap(bool baselineSnap) override;
45     void SetForceAutoHinting(bool isForceAutoHinting) override;
46     void SetSubpixel(bool isSubpixel) override;
47     void SetHinting(FontHinting hintingLevel) override;
48     void SetEmbeddedBitmaps(bool embeddedBitmaps) override;
49     void SetTypeface(std::shared_ptr<Typeface> typeface) override;
50     void SetSize(scalar textSize) override;
51     void SetEmbolden(bool isEmbolden) override;
52     void SetScaleX(scalar scaleX) override;
53     void SetSkewX(scalar skewX) override;
54     void SetLinearMetrics(bool isLinearMetrics) override;
55 
56     scalar GetMetrics(FontMetrics* metrics) const override;
57     void GetWidths(const uint16_t glyphs[], int count, scalar widths[]) const override;
58     void GetWidths(const uint16_t glyphs[], int count, scalar widths[], Rect bounds[]) const override;
59     scalar GetSize() const override;
60     std::shared_ptr<Typeface> GetTypeface() const override;
61 
62     FontEdging GetEdging() const override;
63     FontHinting GetHinting() const override;
64     bool IsEmbeddedBitmaps() const override;
65     scalar GetScaleX() const override;
66     scalar GetSkewX() const override;
67     bool IsBaselineSnap() const override;
68     bool IsForceAutoHinting() const override;
69     bool IsSubpixel() const override;
70     bool IsLinearMetrics() const override;
71     bool IsEmbolden() const override;
72 
73     uint16_t UnicharToGlyph(int32_t uni) const override;
74     int TextToGlyphs(const void* text, size_t byteLength, TextEncoding encoding,
75         uint16_t glyphs[], int maxGlyphCount) const override;
76 
77     scalar MeasureText(const void* text, size_t byteLength, TextEncoding encoding, Rect* bounds) const override;
78     int CountText(const void* text, size_t byteLength, TextEncoding encoding) const override;
79 
80     const SkFont& GetFont() const;
81 
82 private:
83     SkFont skFont_;
84     std::shared_ptr<Typeface> typeface_ = nullptr;
85 };
86 } // namespace Drawing
87 } // namespace Rosen
88 } // namespace OHOS
89 #endif