use of com.xenoage.utils.math.geom.Size2f in project Zong by Xenoage.
the class DemoScoreLayoutTry method main.
public static void main(String... args) throws Exception {
SymbolPool symbolPool = sync(new SymbolPoolReader("default"));
LayoutSettings layoutSettings = LayoutSettingsReader.read(jsePlatformUtils().openFile("data/test/layout/LayoutSettingsTest.xml"));
try {
Score score = ScoreRevolutionary.createScore();
Size2f areaSize = new Size2f(150, 10000);
Context context = new Context(score, symbolPool, layoutSettings);
Target target = Target.completeLayoutTarget(new ScoreLayoutArea(areaSize));
ScoreLayout layout = new ScoreLayouter(context, target).createLayoutWithExceptions();
System.out.println(layout.toString());
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of com.xenoage.utils.math.geom.Size2f in project Zong by Xenoage.
the class ScoreLayouterTest method testSampleFiles.
/**
* Try to layout all official MusicXML 1.1 and 2.0 sample files.
* We can not test for the correct layout of course, but at least
* we want to have no exceptions.
*/
@Test
public void testSampleFiles() throws Exception {
SymbolPool symbolPool = sync(new SymbolPoolReader("default"));
LayoutSettings layoutSettings = LayoutSettingsReader.read(jsePlatformUtils().openFile("data/test/layout/LayoutSettingsTest.xml"));
for (String file : MusicXmlScoreFileInputTest.getSampleFiles()) {
try {
// System.out.println(file);
Score score = new MusicXmlScoreFileInput().read(jsePlatformUtils().openFile(file), file);
Size2f areaSize = new Size2f(150, 10000);
Context context = new Context(score, symbolPool, layoutSettings);
Target target = Target.completeLayoutTarget(new ScoreLayoutArea(areaSize));
ScoreLayouter layouter = new ScoreLayouter(context, target);
layouter.createLayoutWithExceptions();
} catch (Exception ex) {
ex.printStackTrace();
fail("Failed to layout file: " + file);
}
}
}
use of com.xenoage.utils.math.geom.Size2f in project Zong by Xenoage.
the class EmptySystems method compute.
@Override
public void compute(FrameSpacing frame, Score score) {
Size2f usableSize = frame.usableSizeMm;
// compute remaining space
float remainingSpace = usableSize.height;
float offsetY = 0;
if (frame.systems.size() > 0) {
SystemSpacing lastSystem = getLast(frame.systems);
offsetY = lastSystem.getOffsetYMm() + lastSystem.getHeightMm();
remainingSpace -= offsetY;
}
// compute height of an additional system
SystemLayout defaultSystemLayout = score.getFormat().getSystemLayout();
float defaultSystemDistance = defaultSystemLayout.getDistance();
float defaultMargin = defaultSystemLayout.getMarginLeft() + defaultSystemLayout.getMarginRight();
SystemSpacing newSystem = createEmptySystem(score, usableSize.width, 0);
float newSystemHeight = defaultSystemDistance + newSystem.getHeightMm();
// add as many additional empty staves as possible
int newSystemsCount = (int) (remainingSpace / newSystemHeight);
for (int i : range(newSystemsCount)) {
frame.systems.add(createEmptySystem(score, usableSize.width - defaultMargin, offsetY + (i * newSystemHeight) + defaultSystemDistance));
}
}
use of com.xenoage.utils.math.geom.Size2f 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.utils.math.geom.Size2f in project Zong by Xenoage.
the class MxlPageLayout method read.
@NonNull
public static MxlPageLayout read(XmlReader reader) {
Float pageWidth = null;
Float pageHeight = null;
List<MxlPageMargins> pageMargins = alist();
while (reader.openNextChildElement()) {
String n = reader.getElementName();
switch(n) {
case "page-width":
pageWidth = Parser.parseFloatNull(reader.getText());
break;
case "page-height":
pageHeight = Parser.parseFloatNull(reader.getText());
break;
case "page-margins":
pageMargins.add(MxlPageMargins.read(reader));
break;
}
reader.closeElement();
}
Size2f pageSize = (pageWidth == null && pageHeight == null ? null : new Size2f(pageWidth, pageHeight));
return new MxlPageLayout(pageSize, pageMargins);
}
Aggregations