blob: 8327790a85436a75cc9899d6d9ae0542d38c3c1e [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;
Julia Lavrovadb9f6692019-08-01 16:02:17 -040014 fForceHeight = false;
Julia Lavrovac2228562019-08-08 16:51:27 -040015 fHeightOverride = false;
Julia Lavrovadb9f6692019-08-01 16:02:17 -040016 fEnabled = false;
Julia Lavrovaa3552c52019-05-30 16:12:56 -040017}
18
19ParagraphStyle::ParagraphStyle() {
20 fTextAlign = TextAlign::kStart;
21 fTextDirection = TextDirection::kLtr;
22 fLinesLimit = std::numeric_limits<size_t>::max();
23 fHeight = 1;
Julia Lavrova9588a642020-04-30 11:31:25 -040024 fTextHeightBehavior = TextHeightBehavior::kAll;
Julia Lavrovaa3552c52019-05-30 16:12:56 -040025 fHintingIsOn = true;
26}
27
28TextAlign ParagraphStyle::effective_align() const {
29 if (fTextAlign == TextAlign::kStart) {
30 return (fTextDirection == TextDirection::kLtr) ? TextAlign::kLeft : TextAlign::kRight;
31 } else if (fTextAlign == TextAlign::kEnd) {
32 return (fTextDirection == TextDirection::kLtr) ? TextAlign::kRight : TextAlign::kLeft;
33 } else {
34 return fTextAlign;
35 }
36}
37
38void ParagraphStyle::setEllipsis(const std::u16string& ellipsis) {
39 icu::UnicodeString unicode;
40 unicode.setTo((UChar*)ellipsis.data());
41 std::string str;
42 unicode.toUTF8String(str);
43 fEllipsis = SkString(str.c_str());
44}
45} // namespace textlayout
46} // namespace skia