Search in sources :

Example 1 with FormattedText

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

the class FormattedTextUtilsTest method splitTest1Para.

@Test
public void splitTest1Para() {
    // test case: split a single line text and see if correct strings are produced
    FormattedText text = createText1Para();
    // "Hallo A|ndrea"
    Tuple2<FormattedText, FormattedText> textSplit = split(text, 7);
    assertEquals("Hallo A", textSplit.get1().toString());
    assertEquals("ndrea", textSplit.get2().toString());
    // "Hallo An|drea"
    textSplit = split(text, 8);
    assertEquals("Hallo An", textSplit.get1().toString());
    assertEquals("drea", textSplit.get2().toString());
}
Also used : FormattedText(com.xenoage.zong.core.text.FormattedText) Test(org.junit.Test)

Example 2 with FormattedText

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

the class FormattedTextUtilsTest method insertElementTest1.

@Test
public void insertElementTest1() {
    // test case: insert element with same style inbetween an element
    FormattedText text = createText1Para();
    FormattedTextString insertText = new FormattedTextString("ndi und A", // same style
    text.getParagraphs().getFirst().getElements().get(1).getStyle());
    // insert at index 7: "Hallo A{ndi und A}ndrea"
    FormattedText textInsert = insert(text, 7, insertText);
    assertEquals(1, textInsert.getParagraphs().size());
    assertEquals(2, textInsert.getParagraphs().getFirst().getElements().size());
    assertEquals(new FormattedTextString("Hallo ", text.getParagraphs().getFirst().getElements().get(0).getStyle()), textInsert.getParagraphs().getFirst().getElements().get(0));
    assertEquals(new FormattedTextString("Andi und Andrea", text.getParagraphs().getFirst().getElements().get(1).getStyle()), textInsert.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 3 with FormattedText

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

the class FormattedTextUtilsTest method mergeTest.

@Test
public void mergeTest() {
    // test case: merge some texts and see if correct strings are produced
    FormattedText text1 = createText1Para();
    FormattedText text2 = createText3Paras();
    assertEquals("Hallo AndreaHallo Andrea", merge(text1, text1).toString());
    assertEquals("Hallo AndreaFirst Line\nSecond Line and\na Third Line", merge(text1, text2).toString());
}
Also used : FormattedText(com.xenoage.zong.core.text.FormattedText) Test(org.junit.Test)

Example 4 with FormattedText

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

the class LyricStamper method createUnderscoreStamping.

private StaffTextStamping createUnderscoreStamping(float startX, float endX, float baseLine, float widthUnderscore, FormattedTextStyle style, StaffStamping staff, Object element) {
    // compute number of needed "_"
    int countU = Math.max((int) ((endX - startX) / widthUnderscore) + 1, 1);
    // create text
    FormattedText text = Companion.fText(StringUtils.repeat("_", countU), style, Alignment.Left);
    return new StaffTextStamping(text, sp(startX, baseLine), staff, element);
}
Also used : StaffTextStamping(com.xenoage.zong.musiclayout.stampings.StaffTextStamping) FormattedText(com.xenoage.zong.core.text.FormattedText)

Example 5 with FormattedText

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

the class TupletStamper method createTupletStamping.

/**
 * Computes the {@link TupletStamping} for the given {@link ChordStampings}
 * and returns it.
 */
public TupletStamping createTupletStamping(Tuplet tuplet, OpenTupletsCache cache, SymbolPool symbolPool) {
    StaffStamping ss = cache.getChord(tuplet.getChords().get(0), tuplet).staff;
    // horizontal position of the bracket
    float xDistance = ss.is / 4;
    float x1Mm = cache.getChord(tuplet.getFirstChord(), tuplet).xMm - xDistance;
    ChordStampings cs2 = cache.getChord(tuplet.getLastChord(), tuplet);
    // TODO: notehead width!
    float cs2Width = ss.is * 1.2f;
    float x2Mm = cs2.xMm + cs2Width + xDistance;
    // vertical position of the bracket (above or below) depends on the directions
    // of the majority of the stems
    int stemDir = 0;
    for (Chord chord : tuplet.getChords()) {
        ChordStampings cs = cache.getChord(chord, tuplet);
        if (cs.stem != null) {
            stemDir += cs.stem.direction.getSign();
        }
    }
    // 1: above, -1: below
    int placement = (stemDir < 0 ? 1 : -1);
    // compute position of start and end point
    // by default, the bracket is 1.5 IS away from the end of the stems
    // when there is no stem, the innermost notehead is used
    // TODO: if stems of inner chords are longer, correct!
    float distanceLp = 1.5f * 2;
    float y1Lp = computeBracketLP(cache.getChord(tuplet.getFirstChord(), tuplet), placement, distanceLp);
    float y2Lp = computeBracketLP(cache.getChord(tuplet.getLastChord(), tuplet), placement, distanceLp);
    // at least 2 IS over top barline / under bottom barline
    if (// above staff
    placement == 1) {
        y1Lp = Math.max(y1Lp, (ss.linesCount - 1) * 2 + 4);
        y2Lp = Math.max(y1Lp, (ss.linesCount - 1) * 2 + 4);
    } else // below staff
    {
        y1Lp = Math.min(y1Lp, 0 - 4);
        y2Lp = Math.min(y1Lp, 0 - 4);
    }
    // text
    float fontSize = 10 * ss.is / 1.6f;
    FormattedText text = createText(tuplet.getActualNotes(), fontSize, symbolPool);
    // return result
    return new TupletStamping(sp(x1Mm, y1Lp), sp(x2Mm, y2Lp), true, text, ss);
}
Also used : StaffStamping(com.xenoage.zong.musiclayout.stampings.StaffStamping) FormattedText(com.xenoage.zong.core.text.FormattedText) ChordStampings(com.xenoage.zong.musiclayout.layouter.scoreframelayout.util.ChordStampings) Chord(com.xenoage.zong.core.music.chord.Chord) TupletStamping(com.xenoage.zong.musiclayout.stampings.TupletStamping)

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