Search in sources :

Example 16 with FormattedText

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

the class FormattedTextUtilsTest method cleanTest.

@Test
public void cleanTest() {
    FormattedText text = createText1Para();
    FormattedText textCleaned = FormattedTextUtils.INSTANCE.clean(text);
    assertEquals(1, textCleaned.getParagraphs().size());
    assertEquals(2, textCleaned.getParagraphs().getFirst().getElements().size());
    assertEquals(new FormattedTextString("Hallo ", text.getParagraphs().getFirst().getElements().get(0).getStyle()), textCleaned.getParagraphs().getFirst().getElements().get(0));
    assertEquals(new FormattedTextString("Andrea", text.getParagraphs().getFirst().getElements().get(1).getStyle()), textCleaned.getParagraphs().getFirst().getElements().get(1));
}
Also used : FormattedTextString(com.xenoage.zong.core.text.FormattedTextString) FormattedText(com.xenoage.zong.core.text.FormattedText) Test(org.junit.Test)

Example 17 with FormattedText

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

the class FormattedTextUtilsTest method splitTest3Paras.

@Test
public void splitTest3Paras() {
    // test case: split a text with multiple lines and see if correct strings are produced
    FormattedText text = createText3Paras();
    // split after first line
    Tuple2<FormattedText, FormattedText> textSplit = split(text, 10);
    assertEquals("First Line", textSplit.get1().toString());
    assertEquals("\nSecond Line and\na Third Line", textSplit.get2().toString());
    // split at beginning of second line
    textSplit = split(text, 11);
    assertEquals("First Line\n", textSplit.get1().toString());
    assertEquals("Second Line and\na Third Line", textSplit.get2().toString());
    // split in the middle of the first line
    textSplit = split(text, 3);
    assertEquals("Fir", textSplit.get1().toString());
    assertEquals("st Line\nSecond Line and\na Third Line", textSplit.get2().toString());
    // split in the middle of the second line
    textSplit = split(text, 14);
    assertEquals("First Line\nSec", textSplit.get1().toString());
    assertEquals("ond Line and\na Third Line", textSplit.get2().toString());
    // split in the middle of the third line
    textSplit = split(text, 30);
    assertEquals("First Line\nSecond Line and\na T", textSplit.get1().toString());
    assertEquals("hird Line", textSplit.get2().toString());
    // split at the very beginning
    textSplit = split(text, 0);
    assertEquals("", textSplit.get1().toString());
    assertEquals("First Line\nSecond Line and\na Third Line", textSplit.get2().toString());
    // split at the very end
    textSplit = split(text, 39);
    assertEquals("First Line\nSecond Line and\na Third Line", textSplit.get1().toString());
    assertEquals("", textSplit.get2().toString());
}
Also used : FormattedText(com.xenoage.zong.core.text.FormattedText) Test(org.junit.Test)

Example 18 with FormattedText

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

the class FormattedTextUtilsTest method insertTextTest.

@Test
public void insertTextTest() {
    // test case: insert multiline text into multiline text
    FormattedText text = createText3Paras();
    // insert at index 14: "First Line\nSecFirst Line\nSecond Li..."
    FormattedText textInsert = insert(text, 14, text);
    assertEquals("First Line\nSecFirst Line\nSecond Line and\na Third Lineond Line and\na Third Line", textInsert.toString());
    assertEquals(5, textInsert.getParagraphs().size());
}
Also used : FormattedText(com.xenoage.zong.core.text.FormattedText) Test(org.junit.Test)

Example 19 with FormattedText

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

the class BarlinesStamper method stamp.

public List<Stamping> stamp(SystemSpacing system, List<StaffStamping> systemStaves, Score score) {
    List<Stamping> ret = alist();
    StaffStamping firstStaff = getFirst(systemStaves);
    int stavesCount = systemStaves.size();
    int systemIndex = system.getSystemIndexInFrame();
    float xOffset = firstStaff.positionMm.x;
    // common barline at the beginning, when system has at least one measure
    if (system.columns.size() > 0) {
        ret.add(new BarlineStamping(Barline.Companion.barlineRegular(), systemStaves, xOffset, BarlineGroup.Style.Common));
    }
    // barlines within the system and measure numbers
    for (int iMeasure : range(system.columns)) {
        float xLeft = xOffset;
        // measure numbering
        MeasureNumbering measureNumbering = score.getFormat().getMeasureNumbering();
        int globalMeasureIndex = system.getStartMeasure() + iMeasure;
        boolean showMeasureNumber = false;
        if (measureNumbering == MeasureNumbering.System) {
            // measure number at the beginning of each system (except the first one)
            showMeasureNumber = (iMeasure == 0 && globalMeasureIndex > 0);
        } else if (measureNumbering == MeasureNumbering.Measure) {
            // measure number at each measure (except the first one)
            showMeasureNumber = (globalMeasureIndex > 0);
        }
        if (showMeasureNumber) {
            FormattedText text = Companion.fText("" + (globalMeasureIndex + 1), new FormattedTextStyle(8), Alignment.Left);
            ret.add(new StaffTextStamping(text, sp(xLeft, firstStaff.linesCount * 2), firstStaff, null));
        }
        // for the first measure in the system: begin after leading spacing
        if (iMeasure == 0)
            xLeft += system.columns.get(iMeasure).getLeadingWidthMm();
        xOffset += system.columns.get(iMeasure).getWidthMm();
        float xRight = xOffset;
        // regard the groups of the score
        for (int iStaff : range(stavesCount)) {
            ColumnHeader columnHeader = score.getColumnHeader(globalMeasureIndex);
            BarlineGroup.Style barlineGroupStyle = BarlineGroup.Style.Single;
            BarlineGroup group = score.getStavesList().getBarlineGroupByStaff(iStaff);
            if (group != null)
                barlineGroupStyle = group.getStyle();
            List<StaffStamping> groupStaves = getBarlineGroupStaves(systemStaves, group);
            // start barline
            Barline startBarline = columnHeader.getStartBarline();
            if (startBarline != null) {
                // don't draw a regular barline at the left side of first measure of a system
                if ((startBarline.getStyle() == BarlineStyle.Regular && systemIndex == 0) == false)
                    ret.add(new BarlineStamping(startBarline, groupStaves, xLeft, barlineGroupStyle));
            }
            // end barline. if none is set, use a regular one.
            Barline endBarline = columnHeader.getEndBarline();
            if (endBarline == null)
                endBarline = Barline.Companion.barlineRegular();
            ret.add(new BarlineStamping(endBarline, groupStaves, xRight, barlineGroupStyle));
            // middle barlines
            for (BeatE<Barline> middleBarline : columnHeader.getMiddleBarlines()) {
                ret.add(new BarlineStamping(middleBarline.getElement(), groupStaves, xLeft + system.columns.get(iMeasure).getBarlineOffsetMm(middleBarline.getBeat()), barlineGroupStyle));
            }
            // go to next group
            if (group != null)
                iStaff = group.getStaves().getStop();
        }
    }
    return ret;
}
Also used : StaffStamping(com.xenoage.zong.musiclayout.stampings.StaffStamping) FormattedTextStyle(com.xenoage.zong.core.text.FormattedTextStyle) StaffTextStamping(com.xenoage.zong.musiclayout.stampings.StaffTextStamping) FormattedText(com.xenoage.zong.core.text.FormattedText) StaffStamping(com.xenoage.zong.musiclayout.stampings.StaffStamping) Stamping(com.xenoage.zong.musiclayout.stampings.Stamping) BarlineStamping(com.xenoage.zong.musiclayout.stampings.BarlineStamping) StaffTextStamping(com.xenoage.zong.musiclayout.stampings.StaffTextStamping) ColumnHeader(com.xenoage.zong.core.header.ColumnHeader) BarlineStamping(com.xenoage.zong.musiclayout.stampings.BarlineStamping) MeasureNumbering(com.xenoage.zong.core.format.MeasureNumbering) Barline(com.xenoage.zong.core.music.barline.Barline) BarlineGroup(com.xenoage.zong.core.music.group.BarlineGroup)

Example 20 with FormattedText

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

the class PartNameStamper method stamp.

@MaybeNull
public FrameTextStamping stamp(Part part, int firstStaffIndex, List<StaffStamping> systemStaves, Style style) {
    StaffStamping firstStaff = systemStaves.get(firstStaffIndex);
    StaffStamping lastStaff = systemStaves.get(firstStaffIndex + part.getStavesCount() - 1);
    String name = (style == Style.Full ? part.getName() : part.getAbbreviation());
    if (name == null || name.length() == 0)
        return null;
    // in the middle of the staves
    float top = firstStaff.positionMm.y;
    float bottom = lastStaff.positionMm.y + (lastStaff.linesCount - 1) * lastStaff.is;
    FormattedText text = // TODO
    Companion.fText(// TODO
    name, // TODO
    new FormattedTextStyle(firstStaff.is * 2.5f * 2.67f), Alignment.Right);
    if (text.getParagraphs().size() == 0)
        return null;
    // TODO correction of baseline. /3 looks good.
    float middle = (top + bottom) / 2 + text.getFirstParagraph().getMetrics().getAscent() / 3;
    return new FrameTextStamping(text, new Point2f(firstStaff.positionMm.x - firstStaff.is * 2.5f, middle), // TODO
    null);
}
Also used : Point2f(com.xenoage.utils.math.geom.Point2f) StaffStamping(com.xenoage.zong.musiclayout.stampings.StaffStamping) FormattedTextStyle(com.xenoage.zong.core.text.FormattedTextStyle) FrameTextStamping(com.xenoage.zong.musiclayout.stampings.FrameTextStamping) FormattedText(com.xenoage.zong.core.text.FormattedText) MaybeNull(com.xenoage.utils.annotations.MaybeNull)

Aggregations

FormattedText (com.xenoage.zong.core.text.FormattedText)22 Test (org.junit.Test)8 FormattedTextString (com.xenoage.zong.core.text.FormattedTextString)5 StaffStamping (com.xenoage.zong.musiclayout.stampings.StaffStamping)5 Point2f (com.xenoage.utils.math.geom.Point2f)4 FormattedTextParagraph (com.xenoage.zong.core.text.FormattedTextParagraph)4 FormattedTextStyle (com.xenoage.zong.core.text.FormattedTextStyle)4 Color (com.xenoage.utils.color.Color)3 Alignment (com.xenoage.zong.core.text.Alignment)3 FormattedTextElement (com.xenoage.zong.core.text.FormattedTextElement)3 StaffTextStamping (com.xenoage.zong.musiclayout.stampings.StaffTextStamping)3 FontInfo (com.xenoage.utils.font.FontInfo)2 Chord (com.xenoage.zong.core.music.chord.Chord)2 OtherReader.readAlignment (com.xenoage.zong.io.musicxml.in.readers.OtherReader.readAlignment)2 TupletStamping (com.xenoage.zong.musiclayout.stampings.TupletStamping)2 VoltaStamping (com.xenoage.zong.musiclayout.stampings.VoltaStamping)2 BitmapLine (com.xenoage.zong.musiclayout.stampings.bitmap.BitmapLine)2 BitmapStaff (com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff)2 MxlFormattedText (com.xenoage.zong.musicxml.types.MxlFormattedText)2 MaybeNull (com.xenoage.utils.annotations.MaybeNull)1