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