Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame^] | 1 | // Copyright 2019 Google LLC. |
| 2 | #include <string> |
| 3 | #include "modules/skparagraph/include/ParagraphStyle.h" |
| 4 | #include "unicode/unistr.h" |
| 5 | |
| 6 | namespace skia { |
| 7 | namespace textlayout { |
| 8 | |
| 9 | StrutStyle::StrutStyle() { |
| 10 | fFontStyle = SkFontStyle::Normal(); |
| 11 | fFontSize = 14; |
| 12 | fHeight = 1; |
| 13 | fLeading = -1; |
| 14 | fForceStrutHeight = false; |
| 15 | fStrutEnabled = false; |
| 16 | } |
| 17 | |
| 18 | ParagraphStyle::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 | |
| 26 | TextAlign 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 | |
| 36 | void 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 |