1 /* 2 * Copyright 2013-2014, Stephan Aßmus <superstippi@gmx.de>. 3 * All rights reserved. Distributed under the terms of the MIT License. 4 */ 5 6 7 #include "MarkupTextView.h" 8 9 10 static const rgb_color kLightBlack = (rgb_color){ 60, 60, 60, 255 }; 11 12 13 MarkupTextView::MarkupTextView(const char* name) 14 : 15 TextDocumentView(name) 16 { 17 SetEditingEnabled(false); 18 CharacterStyle regularStyle; 19 20 float fontSize = regularStyle.Font().Size(); 21 22 ParagraphStyle paragraphStyle; 23 paragraphStyle.SetJustify(true); 24 paragraphStyle.SetSpacingTop(ceilf(fontSize * 0.3f)); 25 paragraphStyle.SetLineSpacing(ceilf(fontSize * 0.2f)); 26 27 fMarkupParser.SetStyles(regularStyle, paragraphStyle); 28 } 29 30 31 void 32 MarkupTextView::SetText(const BString& markupText) 33 { 34 SetTextDocument(fMarkupParser.CreateDocumentFromMarkup(markupText)); 35 } 36 37 38 void 39 MarkupTextView::SetText(const BString heading, const BString& markupText) 40 { 41 TextDocumentRef document(new(std::nothrow) TextDocument(), true); 42 43 Paragraph paragraph(fMarkupParser.HeadingParagraphStyle()); 44 paragraph.Append(TextSpan(heading, 45 fMarkupParser.HeadingCharacterStyle())); 46 document->Append(paragraph); 47 48 fMarkupParser.AppendMarkup(document, markupText); 49 50 SetTextDocument(document); 51 } 52 53 54 void 55 MarkupTextView::SetDisabledText(const BString& text) 56 { 57 TextDocumentRef document(new(std::nothrow) TextDocument(), true); 58 59 ParagraphStyle paragraphStyle; 60 paragraphStyle.SetAlignment(ALIGN_CENTER); 61 62 CharacterStyle disabledStyle(fMarkupParser.NormalCharacterStyle()); 63 disabledStyle.SetForegroundColor(kLightBlack); 64 65 Paragraph paragraph(paragraphStyle); 66 paragraph.Append(TextSpan(text, disabledStyle)); 67 document->Append(paragraph); 68 69 SetTextDocument(document); 70 } 71