• 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 #include "paragraph_style.h"
18 
19 #include <vector>
20 
21 namespace txt {
22 
GetTextStyle() const23 TextStyle ParagraphStyle::GetTextStyle() const {
24   TextStyle result;
25   result.font_weight = font_weight;
26   result.font_style = font_style;
27   result.font_families = std::vector<std::string>({font_family});
28   if (font_size >= 0) {
29     result.font_size = font_size;
30   }
31   result.locale = locale;
32   result.height = height;
33   result.has_height_override = has_height_override;
34   return result;
35 }
36 
unlimited_lines() const37 bool ParagraphStyle::unlimited_lines() const {
38   return max_lines == std::numeric_limits<size_t>::max();
39 };
40 
ellipsized() const41 bool ParagraphStyle::ellipsized() const {
42   return !ellipsis.empty();
43 }
44 
effective_align() const45 TextAlign ParagraphStyle::effective_align() const {
46   if (text_align == TextAlign::start) {
47     return (text_direction == TextDirection::ltr) ? TextAlign::left
48                                                   : TextAlign::right;
49   } else if (text_align == TextAlign::end) {
50     return (text_direction == TextDirection::ltr) ? TextAlign::right
51                                                   : TextAlign::left;
52   } else {
53     return text_align;
54   }
55 }
56 
57 }  // namespace txt
58