Search in sources :

Example 6 with FormattedTextParagraph

use of com.xenoage.zong.core.text.FormattedTextParagraph in project Zong by Xenoage.

the class Test32b method getFormattedTextElement.

private FormattedTextElement getFormattedTextElement(Words words, MP mp) {
    assertTrue("" + mp, words.getText() instanceof FormattedText);
    FormattedText wordsText = (FormattedText) words.getText();
    assertEquals("" + mp, 1, wordsText.getParagraphs().size());
    FormattedTextParagraph wordsPara = wordsText.getFirstParagraph();
    assertEquals("" + mp, 1, wordsPara.getElements().size());
    FormattedTextElement wordsElem = wordsPara.getElements().getFirst();
    return wordsElem;
}
Also used : FormattedTextParagraph(com.xenoage.zong.core.text.FormattedTextParagraph) FormattedText(com.xenoage.zong.core.text.FormattedText) FormattedTextElement(com.xenoage.zong.core.text.FormattedTextElement)

Example 7 with FormattedTextParagraph

use of com.xenoage.zong.core.text.FormattedTextParagraph in project Zong by Xenoage.

the class CreditsReader method addTextFrame.

/**
 * Adds the given credit element as a {@link TextFrame} to the given {@link Layout}.
 */
private static void addTextFrame(MxlCredit credit, Layout layout, ScoreFormat scoreFormat) {
    if (credit.getContent().getCreditContentType() == MxlCreditContentType.CreditWords) {
        MxlCreditWords mxlCreditWords = (MxlCreditWords) credit.getContent();
        // create formatted text
        FormattedText text = createFormattedText(mxlCreditWords, scoreFormat.getLyricFont());
        // compute position (read only the position of the first credit-words element)
        Page firstPage = layout.getPages().get(0);
        float tenths = scoreFormat.getInterlineSpace() / 10;
        MxlFormattedText mxlFirstCreditWords = mxlCreditWords.getItems().get(0);
        MxlPosition mxlPosition = mxlFirstCreditWords.getPrintStyle().getPosition();
        Point2f offsetFromBottomInTenths = mxlPosition.getDefault().or(new Point2f(10f, 10f));
        Point2f position = new Point2f(offsetFromBottomInTenths.x * tenths, firstPage.getFormat().getSize().height - offsetFromBottomInTenths.y * tenths);
        // compute size
        // this is the width of the widest paragraph and the height of the sum of all paragraphs
        // at least 1 mm
        float maxParagraphWidth = 1;
        // at least 1 mm
        float sumParagraphsHeight = 1;
        for (FormattedTextParagraph paragraph : text.getParagraphs()) {
            maxParagraphWidth = Math.max(maxParagraphWidth, paragraph.getMetrics().getWidth());
            sumParagraphsHeight += paragraph.getHeightMm();
        }
        Size2f size = new Size2f(maxParagraphWidth, sumParagraphsHeight);
        // horizontal alignment:
        // try with halign first, and if not set, use justify
        Alignment alignment = readAlignment(mxlFirstCreditWords.getHAlign());
        if (alignment == null) {
            alignment = readAlignment(mxlFirstCreditWords.getJustify());
        }
        if (alignment == null || alignment == Alignment.Left) {
            position = position.add(size.width / 2, 0);
        } else if (alignment == Alignment.Center) {
        // already centered
        } else if (alignment == Alignment.Right) {
            position = position.add(-size.width / 2, 0);
        }
        // vertical alignment
        MxlVAlign mxlVAlign = mxlFirstCreditWords.getVAlign();
        if (mxlVAlign == MxlVAlign.Top || mxlVAlign == MxlVAlign.Unknown) {
            position = position.add(0, size.height / 2);
        } else if (mxlVAlign == MxlVAlign.Middle) {
        // already centered
        } else if (mxlVAlign == MxlVAlign.Bottom || mxlVAlign == MxlVAlign.Baseline) {
            position = position.add(0, -size.height / 2);
        }
        // create and add TextFrame
        TextFrame textFrame = new TextFrame();
        textFrame.setPosition(position);
        textFrame.setSize(size);
        textFrame.setText(text);
        layout.getPages().get(0).addFrame(textFrame);
    }
}
Also used : Alignment(com.xenoage.zong.core.text.Alignment) OtherReader.readAlignment(com.xenoage.zong.io.musicxml.in.readers.OtherReader.readAlignment) Point2f(com.xenoage.utils.math.geom.Point2f) MxlFormattedText(com.xenoage.zong.musicxml.types.MxlFormattedText) Size2f(com.xenoage.utils.math.geom.Size2f) MxlPosition(com.xenoage.zong.musicxml.types.attributes.MxlPosition) FormattedTextParagraph(com.xenoage.zong.core.text.FormattedTextParagraph) TextFrame(com.xenoage.zong.layout.frames.TextFrame) MxlCreditWords(com.xenoage.zong.musicxml.types.MxlCreditWords) Page(com.xenoage.zong.layout.Page) MxlVAlign(com.xenoage.zong.musicxml.types.enums.MxlVAlign) FormattedText(com.xenoage.zong.core.text.FormattedText) MxlFormattedText(com.xenoage.zong.musicxml.types.MxlFormattedText)

Example 8 with FormattedTextParagraph

use of com.xenoage.zong.core.text.FormattedTextParagraph in project Zong by Xenoage.

the class FormattedTextParagraphTest method testFormattedTextParagraph.

@Test
public void testFormattedTextParagraph() {
    FormattedTextStyle style = new FormattedTextStyle(new FontInfo((String) null, null, fontStyle(FontStyle.Bold)), Color.Companion.getRed(), Superscript.Super);
    FormattedTextParagraph paragraph = Companion.fPara(Companion.fString("This is a formatted text.", style));
    assertEquals("This is a formatted text.", paragraph.getText());
    style = ((FormattedTextString) paragraph.getElements().getFirst()).getStyle();
    assertEquals(true, style.getFont().getStyle().isSet(FontStyle.Bold));
    assertEquals(false, style.getFont().getStyle().isSet(FontStyle.Italic));
    assertEquals(false, style.getFont().getStyle().isSet(FontStyle.Underline));
    assertEquals(false, style.getFont().getStyle().isSet(FontStyle.Strikethrough));
    assertEquals(Color.Companion.getRed(), style.getColor());
    assertEquals(Superscript.Super, style.getSuperscript());
}
Also used : FormattedTextStyle(com.xenoage.zong.core.text.FormattedTextStyle) FormattedTextParagraph(com.xenoage.zong.core.text.FormattedTextParagraph) FormattedTextString(com.xenoage.zong.core.text.FormattedTextString) FormattedTextString.fString(com.xenoage.zong.core.text.FormattedTextString.fString) FontInfo(com.xenoage.utils.font.FontInfo) Test(org.junit.Test)

Example 9 with FormattedTextParagraph

use of com.xenoage.zong.core.text.FormattedTextParagraph in project Zong by Xenoage.

the class FormattedTextParagraphTest method testSimpleTextParagraph.

@Test
public void testSimpleTextParagraph() {
    FormattedTextParagraph paragraph = Companion.fPara(Companion.fString("This is a simple text.", FormattedTextStyle.Companion.getDefaultStyle()));
    assertEquals("This is a simple text.", paragraph.getText());
}
Also used : FormattedTextParagraph(com.xenoage.zong.core.text.FormattedTextParagraph) Test(org.junit.Test)

Example 10 with FormattedTextParagraph

use of com.xenoage.zong.core.text.FormattedTextParagraph in project Zong by Xenoage.

the class FormattedTextParagraphTest method getMixedStyleTextParagraph.

public static FormattedTextParagraph getMixedStyleTextParagraph() {
    FormattedTextStyle style1 = new FormattedTextStyle(new FontInfo(new JLabel().getFont().getName(), 14f, fontStyle(FontStyle.Italic, FontStyle.Underline)));
    FormattedTextStyle style2 = new FormattedTextStyle(new FontInfo(new JLabel().getFont().getName(), 14f, fontStyle(FontStyle.Bold, FontStyle.Italic, FontStyle.Underline, FontStyle.Strikethrough)), Color.Companion.getGreen(), null);
    FormattedTextParagraph paragraph = new FormattedTextParagraph(CList.<FormattedTextElement>ilist(new FormattedTextString("This is ", style1), new FormattedTextString("a mixed styled text!", style2)), FormattedTextParagraph.Companion.getDefaultAlignment());
    return paragraph;
}
Also used : FormattedTextString(com.xenoage.zong.core.text.FormattedTextString) FormattedTextStyle(com.xenoage.zong.core.text.FormattedTextStyle) FormattedTextParagraph(com.xenoage.zong.core.text.FormattedTextParagraph) JLabel(javax.swing.JLabel) FontInfo(com.xenoage.utils.font.FontInfo)

Aggregations

FormattedTextParagraph (com.xenoage.zong.core.text.FormattedTextParagraph)14 FormattedTextString (com.xenoage.zong.core.text.FormattedTextString)10 FormattedTextElement (com.xenoage.zong.core.text.FormattedTextElement)9 FormattedTextStyle (com.xenoage.zong.core.text.FormattedTextStyle)6 FontInfo (com.xenoage.utils.font.FontInfo)4 FormattedText (com.xenoage.zong.core.text.FormattedText)4 FormattedTextSymbol (com.xenoage.zong.core.text.FormattedTextSymbol)4 Test (org.junit.Test)4 Point2f (com.xenoage.utils.math.geom.Point2f)3 Alignment (com.xenoage.zong.core.text.Alignment)3 TextMetrics (com.xenoage.utils.font.TextMetrics)2 OtherReader.readAlignment (com.xenoage.zong.io.musicxml.in.readers.OtherReader.readAlignment)2 MxlFormattedText (com.xenoage.zong.musicxml.types.MxlFormattedText)2 BadLocationException (javax.swing.text.BadLocationException)2 SimpleAttributeSet (javax.swing.text.SimpleAttributeSet)2 Paint (android.graphics.Paint)1 Color (com.xenoage.utils.color.Color)1 JfxFontUtils.toJavaFXFont (com.xenoage.utils.jse.javafx.font.JfxFontUtils.toJavaFXFont)1 Fraction (com.xenoage.utils.math.Fraction)1 Size2f (com.xenoage.utils.math.geom.Size2f)1