• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 #include "text/font.h"
17 
18 #include "impl_factory.h"
19 #include "impl_interface/font_impl.h"
20 
21 namespace OHOS {
22 namespace Rosen {
23 namespace Drawing {
Font()24 Font::Font() : fontImpl_(ImplFactory::CreateFontImpl()) {}
25 
Font(std::shared_ptr<Typeface> typeface,scalar size,scalar scaleX,scalar skewX)26 Font::Font(std::shared_ptr<Typeface> typeface, scalar size, scalar scaleX, scalar skewX)
27     : fontImpl_(ImplFactory::CreateFontImpl(typeface, size, scaleX, skewX)) {}
28 
SetEdging(FontEdging edging)29 void Font::SetEdging(FontEdging edging)
30 {
31     fontImpl_->SetEdging(edging);
32 }
33 
SetSubpixel(bool isSubpixel)34 void Font::SetSubpixel(bool isSubpixel)
35 {
36     fontImpl_->SetSubpixel(isSubpixel);
37 }
38 
SetHinting(FontHinting hintingLevel)39 void Font::SetHinting(FontHinting hintingLevel)
40 {
41     fontImpl_->SetHinting(hintingLevel);
42 }
43 
SetTypeface(std::shared_ptr<Typeface> typeface)44 void Font::SetTypeface(std::shared_ptr<Typeface> typeface)
45 {
46     fontImpl_->SetTypeface(typeface);
47 }
48 
SetSize(scalar textSize)49 void Font::SetSize(scalar textSize)
50 {
51     fontImpl_->SetSize(textSize);
52 }
53 
SetEmbolden(bool isEmbolden)54 void Font::SetEmbolden(bool isEmbolden)
55 {
56     fontImpl_->SetEmbolden(isEmbolden);
57 }
58 
SetScaleX(scalar scaleX)59 void Font::SetScaleX(scalar scaleX)
60 {
61     fontImpl_->SetScaleX(scaleX);
62 }
63 
SetSkewX(scalar skewX)64 void Font::SetSkewX(scalar skewX)
65 {
66     fontImpl_->SetSkewX(skewX);
67 }
68 
SetLinearMetrics(bool isLinearMetrics)69 void Font::SetLinearMetrics(bool isLinearMetrics)
70 {
71     fontImpl_->SetLinearMetrics(isLinearMetrics);
72 }
73 
GetMetrics(FontMetrics * metrics) const74 scalar Font::GetMetrics(FontMetrics* metrics) const
75 {
76     return fontImpl_->GetMetrics(metrics);
77 }
78 
GetWidths(const uint16_t glyphs[],int count,scalar widths[]) const79 void Font::GetWidths(const uint16_t glyphs[], int count, scalar widths[]) const
80 {
81     fontImpl_->GetWidths(glyphs, count, widths);
82 }
83 
GetWidths(const uint16_t glyphs[],int count,scalar widths[],Rect bounds[]) const84 void Font::GetWidths(const uint16_t glyphs[], int count, scalar widths[], Rect bounds[]) const
85 {
86     fontImpl_->GetWidths(glyphs, count, widths, bounds);
87 }
88 
GetSize() const89 scalar Font::GetSize() const
90 {
91     return fontImpl_->GetSize();
92 }
93 
GetTypeface()94 std::shared_ptr<Typeface> Font::GetTypeface()
95 {
96     return fontImpl_->GetTypeface();
97 }
98 
MeasureText(const void * text,size_t byteLength,TextEncoding encoding)99 scalar Font::MeasureText(const void* text, size_t byteLength, TextEncoding encoding)
100 {
101     return fontImpl_->MeasureText(text, byteLength, encoding);
102 }
103 } // namespace Drawing
104 } // namespace Rosen
105 } // namespace OHOS
106