1 /* 2 * Copyright 2013, Stephan Aßmus <superstippi@gmx.de>. 3 * All rights reserved. Distributed under the terms of the MIT License. 4 */ 5 6 #include "TextDocumentTest.h" 7 8 #include <math.h> 9 #include <stdio.h> 10 11 #include <LayoutBuilder.h> 12 #include <ScrollView.h> 13 #include <Window.h> 14 15 #include "MarkupParser.h" 16 #include "TextDocumentView.h" 17 18 TextDocumentTest::TextDocumentTest() 19 : 20 BApplication("application/x-vnd.Haiku-TextDocumentTest") 21 { 22 } 23 24 25 TextDocumentTest::~TextDocumentTest() 26 { 27 } 28 29 30 void 31 TextDocumentTest::ReadyToRun() 32 { 33 BRect frame(50.0, 50.0, 749.0, 549.0); 34 35 BWindow* window = new BWindow(frame, "Text document test", 36 B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE | B_AUTO_UPDATE_SIZE_LIMITS); 37 38 TextDocumentView* documentView = new TextDocumentView("text document view"); 39 40 BScrollView* scrollView = new BScrollView("text scroll view", documentView, 41 false, true, B_NO_BORDER); 42 43 BLayoutBuilder::Group<>(window, B_VERTICAL) 44 .Add(scrollView) 45 ; 46 47 CharacterStyle regularStyle; 48 49 float fontSize = regularStyle.Font().Size(); 50 51 ParagraphStyle paragraphStyle; 52 paragraphStyle.SetJustify(true); 53 paragraphStyle.SetSpacingTop(ceilf(fontSize * 0.6f)); 54 paragraphStyle.SetLineSpacing(ceilf(fontSize * 0.2f)); 55 56 // CharacterStyle boldStyle(regularStyle); 57 // boldStyle.SetBold(true); 58 // 59 // CharacterStyle italicStyle(regularStyle); 60 // italicStyle.SetItalic(true); 61 // 62 // CharacterStyle italicAndBoldStyle(boldStyle); 63 // italicAndBoldStyle.SetItalic(true); 64 // 65 // CharacterStyle bigStyle(regularStyle); 66 // bigStyle.SetFontSize(24); 67 // bigStyle.SetForegroundColor(255, 50, 50); 68 // 69 // TextDocumentRef document(new TextDocument(), true); 70 // 71 // Paragraph paragraph(paragraphStyle); 72 // paragraph.Append(TextSpan("This is a", regularStyle)); 73 // paragraph.Append(TextSpan(" test ", bigStyle)); 74 // paragraph.Append(TextSpan("to see if ", regularStyle)); 75 // paragraph.Append(TextSpan("different", boldStyle)); 76 // paragraph.Append(TextSpan(" character styles already work.", regularStyle)); 77 // document->Append(paragraph); 78 // 79 // paragraphStyle.SetSpacingTop(8.0f); 80 // paragraphStyle.SetAlignment(ALIGN_CENTER); 81 // paragraphStyle.SetJustify(false); 82 // 83 // paragraph = Paragraph(paragraphStyle); 84 // paragraph.Append(TextSpan("Different alignment styles ", regularStyle)); 85 // paragraph.Append(TextSpan("are", boldStyle)); 86 // paragraph.Append(TextSpan(" supported as of now!", regularStyle)); 87 // document->Append(paragraph); 88 // 89 // // Test a bullet list 90 // paragraphStyle.SetSpacingTop(8.0f); 91 // paragraphStyle.SetAlignment(ALIGN_LEFT); 92 // paragraphStyle.SetJustify(true); 93 // paragraphStyle.SetBullet(Bullet("•", 12.0f)); 94 // paragraphStyle.SetLineInset(10.0f); 95 // 96 // paragraph = Paragraph(paragraphStyle); 97 // paragraph.Append(TextSpan("Even bullet lists are supported.", regularStyle)); 98 // document->Append(paragraph); 99 // 100 // paragraph = Paragraph(paragraphStyle); 101 // paragraph.Append(TextSpan("The wrapping in ", regularStyle)); 102 // paragraph.Append(TextSpan("this", italicStyle)); 103 // 104 // paragraph.Append(TextSpan(" bullet item should look visually " 105 // "pleasing. And ", regularStyle)); 106 // paragraph.Append(TextSpan("why", italicAndBoldStyle)); 107 // paragraph.Append(TextSpan(" should it not?", regularStyle)); 108 // document->Append(paragraph); 109 110 MarkupParser parser(regularStyle, paragraphStyle); 111 112 TextDocumentRef document = parser.CreateDocumentFromMarkup( 113 "== Text document test ==\n" 114 "This is a test to see if '''different''' " 115 "character styles already work.\n" 116 "Different alignment styles '''are''' supported as of now!\n" 117 " * Even bullet lists are supported.\n" 118 " * The wrapping in ''this'' bullet item should look visually " 119 "pleasing. And ''why'' should it not?\n" 120 ); 121 122 documentView->SetTextDocument(document); 123 documentView->SetTextEditor(TextEditorRef(new TextEditor(), true)); 124 documentView->MakeFocus(); 125 126 window->Show(); 127 } 128 129 130 int 131 main(int argc, char* argv[]) 132 { 133 TextDocumentTest().Run(); 134 return 0; 135 } 136 137 138