• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2017 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef LIB_TXT_SRC_PARAGRAPH_STYLE_H_
18 #define LIB_TXT_SRC_PARAGRAPH_STYLE_H_
19 
20 #include <climits>
21 #include <string>
22 
23 #include "font_style.h"
24 #include "font_weight.h"
25 #include "minikin/LineBreaker.h"
26 #include "text_style.h"
27 
28 namespace txt {
29 
30 enum class TextAlign {
31   left,
32   right,
33   center,
34   justify,
35   start,
36   end,
37 };
38 
39 enum class TextDirection {
40   rtl,
41   ltr,
42 };
43 
44 class ParagraphStyle {
45  public:
46   // Default TextStyle. Used in GetTextStyle() to obtain the base TextStyle to
47   // inherit off of.
48   FontWeight font_weight = FontWeight::w400;
49   FontStyle font_style = FontStyle::normal;
50   std::string font_family = "";
51   double font_size = 14;
52   double height = 1;
53   bool has_height_override = false;
54 
55   // Strut properties. strut_enabled must be set to true for the rest of the
56   // properties to take effect.
57   // TODO(garyq): Break the strut properties into a separate class.
58   bool strut_enabled = false;
59   FontWeight strut_font_weight = FontWeight::w400;
60   FontStyle strut_font_style = FontStyle::normal;
61   std::vector<std::string> strut_font_families;
62   double strut_font_size = 14;
63   double strut_height = 1;
64   bool strut_has_height_override = false;
65   double strut_leading = -1;  // Negative to use font's default leading. [0,inf)
66                               // to use custom leading as a ratio of font size.
67   bool force_strut_height = false;
68 
69   // General paragraph properties.
70   TextAlign text_align = TextAlign::start;
71   TextDirection text_direction = TextDirection::ltr;
72   size_t max_lines = std::numeric_limits<size_t>::max();
73   std::u16string ellipsis;
74   std::string locale;
75 
76   // Default strategy is kBreakStrategy_Greedy. Sometimes,
77   // kBreakStrategy_HighQuality will produce more desirable layouts (e.g., very
78   // long words are more likely to be reasonably placed).
79   // kBreakStrategy_Balanced will balance between the two.
80   minikin::BreakStrategy break_strategy =
81       minikin::BreakStrategy::kBreakStrategy_Greedy;
82 
83   minikin::WordBreakType word_break_type =
84       minikin::WordBreakType::kWordBreakType_BreakWord;
85 
86   TextStyle GetTextStyle() const;
87 
88   bool unlimited_lines() const;
89   bool ellipsized() const;
90 
91   // Return a text alignment value that is not dependent on the text direction.
92   TextAlign effective_align() const;
93 };
94 
95 }  // namespace txt
96 
97 #endif  // LIB_TXT_SRC_PARAGRAPH_STYLE_H_
98