use of com.xenoage.zong.layout.frames.TextFrame in project Zong by Xenoage.
the class TextFrameRenderer method paintTransformed.
@Override
protected void paintTransformed(Frame frame, Canvas canvas, RendererArgs args) {
TextFrame textFrame = (TextFrame) frame;
Rectangle2f rect = getLocalRect(textFrame);
canvas.drawText(textFrame.getTextWithLineBreaks(), null, rect.position, false, rect.width());
}
use of com.xenoage.zong.layout.frames.TextFrame 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);
}
}
Aggregations