Search in sources :

Example 11 with Size2f

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();
    }
}
Also used : SymbolPoolReader(com.xenoage.zong.io.symbols.SymbolPoolReader) Score(com.xenoage.zong.core.Score) LayoutSettings(com.xenoage.zong.musiclayout.settings.LayoutSettings) Size2f(com.xenoage.utils.math.geom.Size2f) SymbolPool(com.xenoage.zong.symbols.SymbolPool) ScoreLayout(com.xenoage.zong.musiclayout.ScoreLayout)

Example 12 with Size2f

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);
        }
    }
}
Also used : SymbolPoolReader(com.xenoage.zong.io.symbols.SymbolPoolReader) Score(com.xenoage.zong.core.Score) LayoutSettings(com.xenoage.zong.musiclayout.settings.LayoutSettings) Size2f(com.xenoage.utils.math.geom.Size2f) SymbolPool(com.xenoage.zong.symbols.SymbolPool) MusicXmlScoreFileInput(com.xenoage.zong.io.musicxml.in.MusicXmlScoreFileInput) MusicXmlScoreFileInputTest(com.xenoage.zong.io.musicxml.in.MusicXmlScoreFileInputTest) Test(org.junit.Test)

Example 13 with Size2f

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));
    }
}
Also used : SystemLayout(com.xenoage.zong.core.format.SystemLayout) Size2f(com.xenoage.utils.math.geom.Size2f) SystemSpacing(com.xenoage.zong.musiclayout.spacing.SystemSpacing)

Example 14 with Size2f

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);
    }
}
Also used : Alignment(com.xenoage.zong.core.text.Alignment) OtherReader.readAlignment(com.xenoage.zong.io.musicxml.in.readers.OtherReader.readAlignment) Point2f(com.xenoage.utils.math.geom.Point2f) MxlFormattedText(com.xenoage.zong.musicxml.types.MxlFormattedText) Size2f(com.xenoage.utils.math.geom.Size2f) MxlPosition(com.xenoage.zong.musicxml.types.attributes.MxlPosition) FormattedTextParagraph(com.xenoage.zong.core.text.FormattedTextParagraph) TextFrame(com.xenoage.zong.layout.frames.TextFrame) MxlCreditWords(com.xenoage.zong.musicxml.types.MxlCreditWords) Page(com.xenoage.zong.layout.Page) MxlVAlign(com.xenoage.zong.musicxml.types.enums.MxlVAlign) FormattedText(com.xenoage.zong.core.text.FormattedText) MxlFormattedText(com.xenoage.zong.musicxml.types.MxlFormattedText)

Example 15 with Size2f

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);
}
Also used : Size2f(com.xenoage.utils.math.geom.Size2f) NonNull(com.xenoage.utils.annotations.NonNull)

Aggregations

Size2f (com.xenoage.utils.math.geom.Size2f)27 Page (com.xenoage.zong.layout.Page)10 PageFormat (com.xenoage.zong.core.format.PageFormat)6 PageMargins (com.xenoage.zong.core.format.PageMargins)5 ScoreFrame (com.xenoage.zong.layout.frames.ScoreFrame)5 Point2f (com.xenoage.utils.math.geom.Point2f)4 Score (com.xenoage.zong.core.Score)4 ScoreDoc (com.xenoage.zong.documents.ScoreDoc)4 Layout (com.xenoage.zong.layout.Layout)4 ScoreLayout (com.xenoage.zong.musiclayout.ScoreLayout)3 ScoreLayoutArea (com.xenoage.zong.musiclayout.layouter.ScoreLayoutArea)3 Target (com.xenoage.zong.musiclayout.layouter.Target)3 LayoutSettings (com.xenoage.zong.musiclayout.settings.LayoutSettings)3 SystemSpacing (com.xenoage.zong.musiclayout.spacing.SystemSpacing)3 AwtCanvas (com.xenoage.zong.renderer.awt.canvas.AwtCanvas)3 SymbolPool (com.xenoage.zong.symbols.SymbolPool)3 Graphics2D (java.awt.Graphics2D)3 JsonArray (com.google.gson.JsonArray)2 JsonObject (com.google.gson.JsonObject)2 Context2d (com.google.gwt.canvas.dom.client.Context2d)2