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());
}
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));
}
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());
}
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);
}
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);
}
Aggregations