18bf80f4bSopenharmony_ci/* 28bf80f4bSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 38bf80f4bSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 48bf80f4bSopenharmony_ci * you may not use this file except in compliance with the License. 58bf80f4bSopenharmony_ci * You may obtain a copy of the License at 68bf80f4bSopenharmony_ci * 78bf80f4bSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 88bf80f4bSopenharmony_ci * 98bf80f4bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 108bf80f4bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 118bf80f4bSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 128bf80f4bSopenharmony_ci * See the License for the specific language governing permissions and 138bf80f4bSopenharmony_ci * limitations under the License. 148bf80f4bSopenharmony_ci */ 158bf80f4bSopenharmony_ci 168bf80f4bSopenharmony_ci#ifndef UTIL__FONT_H 178bf80f4bSopenharmony_ci#define UTIL__FONT_H 188bf80f4bSopenharmony_ci 198bf80f4bSopenharmony_ci#include <atomic> 208bf80f4bSopenharmony_ci#include <memory> 218bf80f4bSopenharmony_ci 228bf80f4bSopenharmony_ci#include <font/intf_font_manager.h> 238bf80f4bSopenharmony_ci 248bf80f4bSopenharmony_ci#include "font_defs.h" 258bf80f4bSopenharmony_ci 268bf80f4bSopenharmony_ciFONT_BEGIN_NAMESPACE() 278bf80f4bSopenharmony_ciclass FaceData; 288bf80f4bSopenharmony_ciclass FontData; 298bf80f4bSopenharmony_ci 308bf80f4bSopenharmony_ciclass Font final : public IFont { 318bf80f4bSopenharmony_cipublic: 328bf80f4bSopenharmony_ci // interface API 338bf80f4bSopenharmony_ci explicit Font(std::shared_ptr<FaceData>&& faceData); 348bf80f4bSopenharmony_ci ~Font() = default; 358bf80f4bSopenharmony_ci 368bf80f4bSopenharmony_ci // IInterface 378bf80f4bSopenharmony_ci const CORE_NS::IInterface* GetInterface(const BASE_NS::Uid& uid) const override; 388bf80f4bSopenharmony_ci CORE_NS::IInterface* GetInterface(const BASE_NS::Uid& uid) override; 398bf80f4bSopenharmony_ci void Ref() override; 408bf80f4bSopenharmony_ci void Unref() override; 418bf80f4bSopenharmony_ci 428bf80f4bSopenharmony_ci // IFont 438bf80f4bSopenharmony_ci // set current size in Points for all consequent font operations 448bf80f4bSopenharmony_ci void SetSize(FontSize sizeInPt) override; 458bf80f4bSopenharmony_ci // get current font size in Points 468bf80f4bSopenharmony_ci FontSize GetSize() override; 478bf80f4bSopenharmony_ci void SetDpi(uint16_t x, uint16_t y) override; 488bf80f4bSopenharmony_ci void GetDpi(uint16_t& x, uint16_t& y) override; 498bf80f4bSopenharmony_ci 508bf80f4bSopenharmony_ci BASE_NS::array_view<uint8_t> GetFontData() override; 518bf80f4bSopenharmony_ci 528bf80f4bSopenharmony_ci FontMetrics GetMetrics() override; 538bf80f4bSopenharmony_ci GlyphMetrics GetGlyphMetrics(uint32_t glyphIndex) override; 548bf80f4bSopenharmony_ci GlyphInfo GetGlyphInfo(uint32_t glyphIndex) override; 558bf80f4bSopenharmony_ci 568bf80f4bSopenharmony_ci uint32_t GetGlyphIndex(uint32_t codepoint) override; 578bf80f4bSopenharmony_ci 588bf80f4bSopenharmony_ci // measure string dimension as if text would have been drawn by DrawString 598bf80f4bSopenharmony_ci BASE_NS::Math::Vec2 MeasureString(const BASE_NS::string_view) override; 608bf80f4bSopenharmony_ci 618bf80f4bSopenharmony_ci // implementation specific API 628bf80f4bSopenharmony_ci void DrawGlyphs(BASE_NS::array_view<const GlyphInfo>, const FontDefs::RenderData&); 638bf80f4bSopenharmony_ci 648bf80f4bSopenharmony_ci // This function draws UTF-8 string by positioning corresponding glyphs 658bf80f4bSopenharmony_ci // based on their advances and kerning (if kerning is supported by font). 668bf80f4bSopenharmony_ci // NOTE: this function does not perform any font shaping nor guarantees 678bf80f4bSopenharmony_ci // accurate glyphs positioning. 688bf80f4bSopenharmony_ci void DrawString(const BASE_NS::string_view, const FontDefs::RenderData&); 698bf80f4bSopenharmony_ci 708bf80f4bSopenharmony_ciprivate: 718bf80f4bSopenharmony_ci std::atomic_uint32_t refcnt_ { 0 }; 728bf80f4bSopenharmony_ci 738bf80f4bSopenharmony_ci std::shared_ptr<FaceData> faceData_; 748bf80f4bSopenharmony_ci FontData* data_ { nullptr }; // FontData is owned by FaceData 758bf80f4bSopenharmony_ci FontSize fontSize_ { DEFAULT_FONT_PT_SIZE }; // in PT 768bf80f4bSopenharmony_ci uint16_t xDpi_ = DEFAULT_XDPI; 778bf80f4bSopenharmony_ci uint16_t yDpi_ = DEFAULT_YDPI; 788bf80f4bSopenharmony_ci 798bf80f4bSopenharmony_ci FontData* GetData(); 808bf80f4bSopenharmony_ci}; 818bf80f4bSopenharmony_ciFONT_END_NAMESPACE() 828bf80f4bSopenharmony_ci#endif 83