blob: 64564a2f0d39f42ebe4769eb20da1bf628fc920b [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;
24 fHintingIsOn = true;
25}
26
27TextAlign ParagraphStyle::effective_align() const {
28 if (fTextAlign == TextAlign::kStart) {
29 return (fTextDirection == TextDirection::kLtr) ? TextAlign::kLeft : TextAlign::kRight;
30 } else if (fTextAlign == TextAlign::kEnd) {
31 return (fTextDirection == TextDirection::kLtr) ? TextAlign::kRight : TextAlign::kLeft;
32 } else {
33 return fTextAlign;
34 }
35}
36
37void ParagraphStyle::setEllipsis(const std::u16string& ellipsis) {
38 icu::UnicodeString unicode;
39 unicode.setTo((UChar*)ellipsis.data());
40 std::string str;
41 unicode.toUTF8String(str);
42 fEllipsis = SkString(str.c_str());
43}
44} // namespace textlayout
45} // namespace skia