• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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_IMPL_H
17 #define FONT_IMPL_H
18 
19 #include <cstdint>
20 
21 #include "draw/path.h"
22 #include "draw/brush.h"
23 #include "draw/pen.h"
24 #include "impl_interface/base_impl.h"
25 #include "text/font_metrics.h"
26 #include "text/font_types.h"
27 #include "text/typeface.h"
28 #include "utils/rect.h"
29 #include "utils/scalar.h"
30 
31 namespace OHOS {
32 namespace Rosen {
33 namespace Drawing {
34 enum class FontEdging;
35 
36 class FontImpl : public BaseImpl {
37 public:
38     ~FontImpl() override = default;
39 
40     virtual void SetEdging(FontEdging edging) = 0;
41     virtual void SetBaselineSnap(bool baselineSnap) = 0;
42     virtual void SetForceAutoHinting(bool isForceAutoHinting) = 0;
43     virtual void SetSubpixel(bool isSubpixel) = 0;
44     virtual void SetHinting(FontHinting hintingLevel) = 0;
45     virtual void SetEmbeddedBitmaps(bool embeddedBitmaps) = 0;
46     virtual void SetTypeface(std::shared_ptr<Typeface> typeface) = 0;
47     virtual void SetSize(scalar textSize) = 0;
48     virtual void SetEmbolden(bool isEmbolden) = 0;
49     virtual void SetScaleX(scalar scaleX) = 0;
50     virtual void SetSkewX(scalar skewX) = 0;
51     virtual void SetLinearMetrics(bool isLinearMetrics) = 0;
52 
53     virtual scalar GetMetrics(FontMetrics* metrics) const = 0;
54     virtual void GetWidths(const uint16_t glyphs[], int count, scalar widths[]) const = 0;
55     virtual void GetWidths(const uint16_t glyphs[], int count, scalar widths[], Rect bounds[]) const = 0;
56     virtual scalar GetSize() const = 0;
57     virtual std::shared_ptr<Typeface> GetTypeface() const = 0;
58 
59     virtual FontEdging GetEdging() const = 0;
60     virtual FontHinting GetHinting() const = 0;
61     virtual scalar GetScaleX() const = 0;
62     virtual scalar GetSkewX() const = 0;
63     virtual bool IsBaselineSnap() const = 0;
64     virtual bool IsEmbeddedBitmaps() const = 0;
65     virtual bool IsEmbolden() const = 0;
66     virtual bool IsForceAutoHinting() const = 0;
67     virtual bool IsLinearMetrics() const = 0;
68     virtual bool IsSubpixel() const = 0;
69 
70     virtual uint16_t UnicharToGlyph(int32_t uni) const = 0;
71     virtual int TextToGlyphs(const void* text, size_t byteLength, TextEncoding encoding,
72         uint16_t glyphs[], int maxGlyphCount) const = 0;
73     virtual bool GetPathForGlyph(uint16_t glyph, Path* path) const = 0;
74 
75     virtual scalar MeasureText(const void* text, size_t byteLength, TextEncoding encoding,
76         Rect* bounds = nullptr) const = 0;
77     virtual scalar MeasureText(const void* text, size_t byteLength, TextEncoding encoding, Rect* bounds,
78         const Brush* brush, const Pen* pen) const = 0;
79     virtual void GetWidthsBounds(const uint16_t glyphs[], int count, float widths[], Rect bounds[],
80         const Brush* brush, const Pen* pen) const = 0;
81     virtual void GetPos(const uint16_t glyphs[], int count, Point points[], Point origin = {0, 0}) const = 0;
82     virtual float GetSpacing() const = 0;
83     virtual int CountText(const void* text, size_t byteLength, TextEncoding encoding) const = 0;
84 
85     virtual void GetTextPath(const void* text, size_t byteLength,
86         TextEncoding encoding, float x, float y, Path* path) const = 0;
87 
88 protected:
89     FontImpl() noexcept = default;
90 };
91 } // namespace Drawing
92 } // namespace Rosen
93 } // namespace OHOS
94 #endif