use of com.xenoage.zong.core.text.FormattedText in project Zong by Xenoage.
the class Test32b method getFontSize.
private float getFontSize(Score score, int wordsIndex) {
MP mp = expectedTexts.get(wordsIndex).get1();
FormattedText text = getTextAt(score, mp);
return getFontSize(text);
}
use of com.xenoage.zong.core.text.FormattedText in project Zong by Xenoage.
the class LyricStamper method createHyphenStamping.
/**
* Creates and returns the {@link StaffTextStamping} containing
* a hypen ("-") between the two given lyric stampings.
*/
public StaffTextStamping createHyphenStamping(StaffTextStamping syllableLeft, StaffTextStamping syllableRight, FormattedTextStyle style) {
FormattedText text = Companion.fText("-", style, Alignment.Center);
float positionX;
float widthLeft = syllableLeft.getText().getFirstParagraph().getMetrics().getWidth();
if (syllableLeft.parentStaff == syllableRight.parentStaff) {
// syllables are in same staff
// the horizontal position of the hyphen is in the middle of the empty
// space between the left and right syllable
float widthRight = syllableRight.getText().getFirstParagraph().getMetrics().getWidth();
positionX = ((syllableLeft.position.xMm + widthLeft / 2) + (syllableRight.position.xMm - widthRight / 2)) / 2;
} else {
// right syllable is in a new staff
// place the hypen to the right side of the first syllable
positionX = (syllableLeft.position.xMm + widthLeft / 2) + 2 * text.getFirstParagraph().getMetrics().getWidth();
}
return new StaffTextStamping(text, sp(positionX, syllableLeft.position.lp), syllableLeft.parentStaff, // hyphen belongs to the left syllable
syllableLeft.getElement());
}
use of com.xenoage.zong.core.text.FormattedText 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);
}
}
use of com.xenoage.zong.core.text.FormattedText in project Zong by Xenoage.
the class FormattedTextUtilsTest method splitTestExceptions.
@Test
public void splitTestExceptions() {
// test case: split at all possible positions
// (problems are only discovered by exceptions)
FormattedText text1 = createText1Para();
for (int i : range(text1.toString().length() + 1)) split(text1, i);
FormattedText text2 = createText3Paras();
for (int i : range(text2.toString().length() + 1)) split(text2, i);
}
use of com.xenoage.zong.core.text.FormattedText in project Zong by Xenoage.
the class FormattedTextUtilsTest method insertElementTest2.
@Test
public void insertElementTest2() {
// test case: insert element with different style at the end of an element
FormattedText text = createText1Para();
FormattedTextString insertText = new FormattedTextString("di und An", // different style
text.getParagraphs().getFirst().getElements().get(0).getStyle());
// insert at index 8: "Hallo An{di und An}drea"
FormattedText textInsert = insert(text, 8, insertText);
assertEquals(1, textInsert.getParagraphs().size());
assertEquals(4, 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("An", text.getParagraphs().getFirst().getElements().get(1).getStyle()), textInsert.getParagraphs().getFirst().getElements().get(1));
assertEquals(new FormattedTextString("di und An", text.getParagraphs().getFirst().getElements().get(0).getStyle()), textInsert.getParagraphs().getFirst().getElements().get(2));
assertEquals(new FormattedTextString("drea", text.getParagraphs().getFirst().getElements().get(1).getStyle()), textInsert.getParagraphs().getFirst().getElements().get(3));
}
Aggregations