• 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 #ifndef ROSEN_MODULES_TEXGINE_SRC_MEASURER_H
17 #define ROSEN_MODULES_TEXGINE_SRC_MEASURER_H
18 
19 #include <cstdint>
20 #include <vector>
21 
22 #include "char_groups.h"
23 #include "font_collection.h"
24 #include "texgine/text_style.h"
25 #include "texgine/typography.h"
26 #include "word_breaker.h"
27 
28 namespace OHOS {
29 namespace Rosen {
30 namespace TextEngine {
31 class Measurer {
32 public:
33     static std::unique_ptr<Measurer> Create(const std::vector<uint16_t> &text, const FontCollection &fontCollection);
34 
35     Measurer(const std::vector<uint16_t> &text, const FontCollection &fontCollection);
36     virtual ~Measurer() = default;
37     void SetFontStyle(const FontStyles &style);
38     void SetLocale(const std::string &locale);
39     void SetRTL(bool rtl);
40     void SetSize(uint32_t size);
41     void SetRange(size_t start, size_t end);
42     void SetFontFeatures(const FontFeatures &features);
43     void SetSpacing(double letterSpacing, double wordSpacing);
44     virtual const std::vector<Boundary> &GetWordBoundary() const = 0;
45     virtual int Measure(CharGroups &cgs) = 0;
46 
47 protected:
48     const std::vector<uint16_t> &text_;
49     const FontCollection &fontCollection_;
50     FontStyles style_;
51     std::string locale_ = "";
52     bool rtl_ = false;
53     uint32_t size_ = 16; // default text_style fontSize_
54     size_t startIndex_ = 0;
55     size_t endIndex_ = 0;
56     const FontFeatures *fontFeatures_ = nullptr;
57     double letterSpacing_ = 0.0;
58     double wordSpacing_ = 0.0;
59 };
60 } // namespace TextEngine
61 } // namespace Rosen
62 } // namespace OHOS
63 
64 #endif // ROSEN_MODULES_TEXGINE_SRC_MEASURER_H
65