use of org.terasology.rendering.nui.widgets.browser.data.ParagraphData in project Terasology by MovingBlocks.
the class DocumentRenderer method getDocumentPreferredSize.
public static Vector2i getDocumentPreferredSize(DocumentData documentData, Font defaultFont, Color defaultColor, int availableWidth) {
DefaultDocumentRenderStyle defaultDocumentRenderStyle = new DefaultDocumentRenderStyle(defaultFont, defaultColor);
DocumentRenderStyle documentRenderStyle = getDocumentRenderStyle(defaultDocumentRenderStyle, documentData);
Collection<ParagraphData> paragraphs = documentData.getParagraphs();
int minParagraphsWidth = getParagraphsMinimumWidth(availableWidth, documentRenderStyle, paragraphs);
int documentSideMargins = documentRenderStyle.getDocumentMarginLeft().getValue(availableWidth) + documentRenderStyle.getDocumentMarginRight().getValue(availableWidth);
int documentWidth = Math.max(availableWidth, minParagraphsWidth + documentSideMargins);
ContainerFlowContainerRenderSpace containerRenderSpace = new ContainerFlowContainerRenderSpace(documentWidth);
int preferredHeight = Math.max(getParagraphsPreferredHeight(documentRenderStyle, paragraphs, containerRenderSpace, 0), containerRenderSpace.getNextClearYPosition(ParagraphRenderStyle.ClearStyle.BOTH));
int documentVerticalMargins = documentRenderStyle.getDocumentMarginTop().getValue(documentWidth) + documentRenderStyle.getDocumentMarginBottom().getValue(documentWidth);
// Bring back the document indents to sides
return new Vector2i(documentWidth, preferredHeight + documentVerticalMargins);
}
use of org.terasology.rendering.nui.widgets.browser.data.ParagraphData in project Terasology by MovingBlocks.
the class DocumentRenderer method getParagraphsMinimumWidth.
public static int getParagraphsMinimumWidth(int availableWidth, ParagraphRenderStyle baseParagraphRenderStyle, Collection<ParagraphData> paragraphs) {
int minParagraphsWidth = 0;
for (ParagraphData paragraphData : paragraphs) {
ParagraphRenderStyle paragraphRenderStyle = getParagraphRenderStyle(baseParagraphRenderStyle, paragraphData);
int paragraphSideIndent = paragraphRenderStyle.getParagraphMarginLeft().getValue(availableWidth) + paragraphRenderStyle.getParagraphMarginRight().getValue(availableWidth) + paragraphRenderStyle.getParagraphPaddingLeft().getValue(availableWidth) + paragraphRenderStyle.getParagraphPaddingRight().getValue(availableWidth);
int paragraphMinWidth = Math.max(paragraphRenderStyle.getParagraphMinimumWidth().getValue(availableWidth), paragraphData.getParagraphContents().getContentsMinWidth(paragraphRenderStyle));
minParagraphsWidth = Math.max(minParagraphsWidth, paragraphSideIndent + paragraphMinWidth);
}
return minParagraphsWidth;
}
use of org.terasology.rendering.nui.widgets.browser.data.ParagraphData in project Terasology by MovingBlocks.
the class HTMLParserTest method testParseSimpleParagraph.
@Test
public void testParseSimpleParagraph() throws IOException, SAXException, ParserConfigurationException {
DocumentData documentData = htmlParser.parseHTMLDocument("<body><p>Text</p></body>");
assertEquals(1, documentData.getParagraphs().size());
ParagraphData paragraph = documentData.getParagraphs().iterator().next();
assertTrue(paragraph instanceof FlowParagraphData);
}
use of org.terasology.rendering.nui.widgets.browser.data.ParagraphData in project Terasology by MovingBlocks.
the class DocumentRenderer method renderParagraphs.
public static void renderParagraphs(Canvas canvas, ParagraphRenderable.HyperlinkRegister register, ParagraphRenderStyle baseRenderStyle, int xShift, int startY, int leftIndent, int rightIndent, Collection<ParagraphData> paragraphs, ContainerRenderSpace containerRenderSpace) {
int containerWidth = containerRenderSpace.getContainerWidth();
int yShift = startY;
for (ParagraphData paragraphData : paragraphs) {
yShift += renderParagraph(canvas, register, baseRenderStyle, xShift, leftIndent, rightIndent, containerRenderSpace, containerWidth, yShift, paragraphData);
}
}
use of org.terasology.rendering.nui.widgets.browser.data.ParagraphData in project Terasology by MovingBlocks.
the class DocumentRenderer method drawDocumentInRegion.
public static void drawDocumentInRegion(DocumentData documentData, Canvas canvas, Font defaultFont, Color defaultColor, Vector2i size, ParagraphRenderable.HyperlinkRegister register) {
DefaultDocumentRenderStyle defaultDocumentRenderStyle = new DefaultDocumentRenderStyle(defaultFont, defaultColor);
DocumentRenderStyle documentRenderStyle = getDocumentRenderStyle(defaultDocumentRenderStyle, documentData);
int documentWidth = size.x;
int documentMarginLeft = documentRenderStyle.getDocumentMarginLeft().getValue(documentWidth);
int documentMarginRight = documentRenderStyle.getDocumentMarginRight().getValue(documentWidth);
int documentMarginTop = documentRenderStyle.getDocumentMarginTop().getValue(documentWidth);
Color backgroundColor = documentRenderStyle.getBackgroundColor();
if (backgroundColor != null) {
canvas.drawFilledRectangle(canvas.getRegion(), backgroundColor);
}
Collection<ParagraphData> paragraphs = documentData.getParagraphs();
ContainerFlowContainerRenderSpace renderSpace = new ContainerFlowContainerRenderSpace(documentWidth);
renderParagraphs(canvas, register, documentRenderStyle, documentMarginLeft, documentMarginTop, documentMarginLeft, documentMarginRight, paragraphs, renderSpace);
}
Aggregations