2 * Copyright 2013-2014, Stephan Aßmus <superstippi@gmx.de>.
3 * All rights reserved. Distributed under the terms of the MIT License.
7 #include "MarkupTextView.h"
10 static const rgb_color kLightBlack
= (rgb_color
){ 60, 60, 60, 255 };
13 MarkupTextView::MarkupTextView(const char* name
)
15 TextDocumentView(name
)
17 SetEditingEnabled(false);
18 CharacterStyle regularStyle
;
20 float fontSize
= regularStyle
.Font().Size();
22 ParagraphStyle paragraphStyle
;
23 paragraphStyle
.SetJustify(true);
24 paragraphStyle
.SetSpacingTop(ceilf(fontSize
* 0.3f
));
25 paragraphStyle
.SetLineSpacing(ceilf(fontSize
* 0.2f
));
27 fMarkupParser
.SetStyles(regularStyle
, paragraphStyle
);
32 MarkupTextView::SetText(const BString
& markupText
)
34 SetTextDocument(fMarkupParser
.CreateDocumentFromMarkup(markupText
));
39 MarkupTextView::SetText(const BString heading
, const BString
& markupText
)
41 TextDocumentRef
document(new(std::nothrow
) TextDocument(), true);
43 Paragraph
paragraph(fMarkupParser
.HeadingParagraphStyle());
44 paragraph
.Append(TextSpan(heading
,
45 fMarkupParser
.HeadingCharacterStyle()));
46 document
->Append(paragraph
);
48 fMarkupParser
.AppendMarkup(document
, markupText
);
50 SetTextDocument(document
);
55 MarkupTextView::SetDisabledText(const BString
& text
)
57 TextDocumentRef
document(new(std::nothrow
) TextDocument(), true);
59 ParagraphStyle paragraphStyle
;
60 paragraphStyle
.SetAlignment(ALIGN_CENTER
);
62 CharacterStyle
disabledStyle(fMarkupParser
.NormalCharacterStyle());
63 disabledStyle
.SetForegroundColor(kLightBlack
);
65 Paragraph
paragraph(paragraphStyle
);
66 paragraph
.Append(TextSpan(text
, disabledStyle
));
67 document
->Append(paragraph
);
69 SetTextDocument(document
);