blob: c2f238a2f498f9418ddc2380ffc309ca06482fb7 [file] [log] [blame]
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001// Copyright 2019 Google LLC.
2#include <string>
3#include "modules/skparagraph/include/ParagraphStyle.h"
4#include "unicode/unistr.h"
5
6namespace skia {
7namespace textlayout {
8
9StrutStyle::StrutStyle() {
10 fFontStyle = SkFontStyle::Normal();
11 fFontSize = 14;
12 fHeight = 1;
13 fLeading = -1;
14 fForceStrutHeight = false;
15 fStrutEnabled = false;
16}
17
18ParagraphStyle::ParagraphStyle() {
19 fTextAlign = TextAlign::kStart;
20 fTextDirection = TextDirection::kLtr;
21 fLinesLimit = std::numeric_limits<size_t>::max();
22 fHeight = 1;
23 fHintingIsOn = true;
24}
25
26TextAlign ParagraphStyle::effective_align() const {
27 if (fTextAlign == TextAlign::kStart) {
28 return (fTextDirection == TextDirection::kLtr) ? TextAlign::kLeft : TextAlign::kRight;
29 } else if (fTextAlign == TextAlign::kEnd) {
30 return (fTextDirection == TextDirection::kLtr) ? TextAlign::kRight : TextAlign::kLeft;
31 } else {
32 return fTextAlign;
33 }
34}
35
36void ParagraphStyle::setEllipsis(const std::u16string& ellipsis) {
37 icu::UnicodeString unicode;
38 unicode.setTo((UChar*)ellipsis.data());
39 std::string str;
40 unicode.toUTF8String(str);
41 fEllipsis = SkString(str.c_str());
42}
43} // namespace textlayout
44} // namespace skia