Search in sources :

Example 1 with PageFormat

use of com.xenoage.zong.core.format.PageFormat in project Zong by Xenoage.

the class ScoreDocScoreView method updateScreen.

@Override
public void updateScreen(Size2i screenSizePx, float zoom) {
    this.screenSizePx = screenSizePx;
    this.zoom = zoom;
    // recompute the layout, so that each page fits into the available screen space
    Size2f pageSizeMm = pxToMm(screenSizePx, zoom);
    float marginMm = pxToMm(marginPx, zoom);
    PageFormat pageFormat = new PageFormat(pageSizeMm, new PageMargins(marginMm, marginMm, marginMm, marginMm));
    Size2f frameSizeMm = new Size2f(pageFormat.getUseableWidth(), pageFormat.getUseableHeight());
    // first page needs space for title text
    titleTextHeightPx = screenSizePx.height / 20f;
    float firstFrameOffsetY = pxToMm(titleTextHeightPx, zoom);
    Size2f firstFrameSizeMm = new Size2f(frameSizeMm.width, frameSizeMm.height - firstFrameOffsetY);
    // delete unnecessary layout information, like system distances or system breaks
    Score score = doc.getScore();
    score.setFormat(new ScoreFormat());
    ScoreHeader header = score.getHeader();
    for (int i : range(header.getSystemLayouts())) {
        SystemLayout sl = header.getSystemLayout(i);
        if (sl != null)
            sl.setDistance(SystemLayout.defaultDistance);
    }
    for (int i : range(header.getColumnHeaders())) {
        ColumnHeader ch = header.getColumnHeader(i);
        if (ch.getMeasureBreak() != null)
            ch.setBreak(null);
    }
    // layout the score to find out the needed space
    Context context = new Context(score, App.getSymbolPool(), doc.getLayout().getDefaults().getLayoutSettings());
    Target target = new Target(alist(new ScoreLayoutArea(firstFrameSizeMm)), new ScoreLayoutArea(frameSizeMm), true);
    ScoreLayouter layouter = new ScoreLayouter(context, target);
    ScoreLayout scoreLayout = layouter.createScoreLayout();
    // create and fill at least one page
    Layout layout = new Layout(doc.getLayout().getDefaults());
    ScoreFrameChain chain = null;
    for (int i = 0; i < scoreLayout.frames.size(); i++) {
        Page page = new Page(pageFormat);
        Point2f position;
        Size2f size;
        if (i == 0) {
            // first page
            position = new Point2f(pageSizeMm.width / 2, pageSizeMm.height / 2 + firstFrameOffsetY);
            size = firstFrameSizeMm;
        } else {
            // other pages
            position = new Point2f(pageSizeMm.width / 2, pageSizeMm.height / 2);
            size = frameSizeMm;
        }
        ScoreFrame frame = new ScoreFrame();
        frame.setPosition(position);
        frame.setSize(size);
        page.addFrame(frame);
        layout.addPage(page);
        if (chain == null) {
            chain = new ScoreFrameChain(score);
            chain.setScoreLayout(scoreLayout);
        }
        chain.add(frame);
    }
    this.layout = layout;
}
Also used : Context(com.xenoage.zong.musiclayout.layouter.Context) ScoreFrame(com.xenoage.zong.layout.frames.ScoreFrame) ScoreLayouter(com.xenoage.zong.musiclayout.layouter.ScoreLayouter) ScoreLayout(com.xenoage.zong.musiclayout.ScoreLayout) Page(com.xenoage.zong.layout.Page) Paint(android.graphics.Paint) ScoreFormat(com.xenoage.zong.core.format.ScoreFormat) PageMargins(com.xenoage.zong.core.format.PageMargins) PageFormat(com.xenoage.zong.core.format.PageFormat) Score(com.xenoage.zong.core.Score) ScoreHeader(com.xenoage.zong.core.header.ScoreHeader) ColumnHeader(com.xenoage.zong.core.header.ColumnHeader) Target(com.xenoage.zong.musiclayout.layouter.Target) Point2f(com.xenoage.utils.math.geom.Point2f) ScoreLayout(com.xenoage.zong.musiclayout.ScoreLayout) SystemLayout(com.xenoage.zong.core.format.SystemLayout) Layout(com.xenoage.zong.layout.Layout) SystemLayout(com.xenoage.zong.core.format.SystemLayout) ScoreFrameChain(com.xenoage.zong.layout.frames.ScoreFrameChain) Size2f(com.xenoage.utils.math.geom.Size2f) ScoreLayoutArea(com.xenoage.zong.musiclayout.layouter.ScoreLayoutArea)

Example 2 with PageFormat

use of com.xenoage.zong.core.format.PageFormat in project Zong by Xenoage.

the class PageTest method createPageWithUnrotatedFrames.

/**
 * Creates a layout with a page with some unrotated frames for testing.
 */
private Layout createPageWithUnrotatedFrames() {
    Layout layout = new Layout(null);
    PageFormat pf = new PageFormat(new Size2f(200, 200), new PageMargins(10, 10, 10, 10));
    Page page = new Page(pf);
    layout.addPage(page);
    // Frame 1
    frm1 = new ScoreFrame();
    frm1.setPosition(p(120, 120));
    frm1.setSize(s(60, 80));
    page.addFrame(frm1);
    // Frame 2
    frm2 = new GroupFrame();
    frm2.setPosition(p(90, 110));
    frm2.setSize(s(60, 40));
    page.addFrame(frm2);
    // Childframe 2a
    frm2a = new ScoreFrame();
    frm2a.setPosition(p(30, 0));
    frm2a.setSize(s(10, 10));
    frm2.addChildFrame(frm2a);
    // Childframe 2b
    frm2b = new ScoreFrame();
    frm2b.setPosition(p(-10, -20));
    frm2b.setSize(s(10, 10));
    frm2.addChildFrame(frm2b);
    // Frame 3
    frm3 = new ScoreFrame();
    frm3.setPosition(p(30, 80));
    frm3.setSize(s(30, 60));
    page.addFrame(frm3);
    return layout;
}
Also used : PageMargins(com.xenoage.zong.core.format.PageMargins) PageFormat(com.xenoage.zong.core.format.PageFormat) ScoreFrame(com.xenoage.zong.layout.frames.ScoreFrame) Size2f(com.xenoage.utils.math.geom.Size2f) GroupFrame(com.xenoage.zong.layout.frames.GroupFrame)

Example 3 with PageFormat

use of com.xenoage.zong.core.format.PageFormat in project Zong by Xenoage.

the class PageViewManagerTest method setUp.

@Before
public void setUp() {
    Layout layout = new Layout(null);
    // 3 pages:
    // ----          --------
    // |1 | -2------ |3     |
    // |  | -------- |      |
    // ----          --------
    layout.addPage(new Page(new PageFormat(new Size2f(100, 200), new PageMargins(0, 0, 0, 0))));
    layout.addPage(new Page(new PageFormat(new Size2f(200, 100), new PageMargins(0, 0, 0, 0))));
    layout.addPage(new Page(new PageFormat(new Size2f(200, 200), new PageMargins(0, 0, 0, 0))));
    // create view
    view = new PageViewManager(layout);
    view.setPageDisplayAlignment(PageDisplayAlignment.Horizontal);
}
Also used : PageMargins(com.xenoage.zong.core.format.PageMargins) PageFormat(com.xenoage.zong.core.format.PageFormat) Layout(com.xenoage.zong.layout.Layout) Size2f(com.xenoage.utils.math.geom.Size2f) Page(com.xenoage.zong.layout.Page) Before(org.junit.Before)

Example 4 with PageFormat

use of com.xenoage.zong.core.format.PageFormat in project Zong by Xenoage.

the class PageTest method createPageWithRotatedFrames.

/**
 * Creates a layout with a page with some rotated frames for testing.
 * See PageTest.odg for a preview of the page.
 */
private Layout createPageWithRotatedFrames() {
    Layout layout = new Layout(null);
    PageFormat pf = new PageFormat(new Size2f(200, 200), new PageMargins(10, 10, 10, 10));
    Page page = new Page(pf);
    layout.addPage(page);
    // Frame 1
    frm1 = new ScoreFrame();
    frm1.setPosition(p(120, 120));
    frm1.setSize(s(60, 80));
    frm1.setRotation(-30);
    page.addFrame(frm1);
    // Frame 2
    frm2 = new GroupFrame();
    frm2.setPosition(p(90, 110));
    frm2.setSize(s(60, 40));
    frm2.setRotation(70);
    page.addFrame(frm2);
    // Childframe 2a
    frm2a = new ScoreFrame();
    frm2a.setPosition(p(20, 10));
    frm2a.setSize(s(10, 10));
    frm2a.setRotation(0);
    frm2.addChildFrame(frm2a);
    // Childframe 2b
    frm2b = new ScoreFrame();
    frm2b.setPosition(p(-10, -5));
    frm2b.setSize(s(20, 20));
    frm2b.setRotation(70);
    frm2.addChildFrame(frm2b);
    // Frame 3
    frm3 = new ScoreFrame();
    frm3.setPosition(p(95, 155));
    frm3.setSize(s(80, 40));
    frm3.setRotation(30);
    page.addFrame(frm3);
    return layout;
}
Also used : PageMargins(com.xenoage.zong.core.format.PageMargins) PageFormat(com.xenoage.zong.core.format.PageFormat) ScoreFrame(com.xenoage.zong.layout.frames.ScoreFrame) Size2f(com.xenoage.utils.math.geom.Size2f) GroupFrame(com.xenoage.zong.layout.frames.GroupFrame)

Example 5 with PageFormat

use of com.xenoage.zong.core.format.PageFormat in project Zong by Xenoage.

the class ScoreDocFactory method read.

/**
 * Creates a {@link ScoreDoc} instance from the given score.
 * TIDY: move elsewhere, e.g. in a ScoreDocFactory class
 */
public ScoreDoc read(Score score) throws InvalidFormatException, IOException {
    // page format
    LayoutFormat layoutFormat = Companion.getDefaultLayoutFormat();
    Object oLayoutFormat = score.getMetaData().get("layoutformat");
    if (oLayoutFormat instanceof LayoutFormat) {
        layoutFormat = (LayoutFormat) oLayoutFormat;
    }
    LayoutDefaults layoutDefaults = new LayoutDefaults(layoutFormat);
    // create the document
    ScoreDoc ret = new ScoreDoc(score, layoutDefaults);
    Layout layout = ret.getLayout();
    // layout basics
    PageFormat pageFormat = layoutFormat.getPageFormat(0);
    Size2f frameSize = new Size2f(pageFormat.getUseableWidth(), pageFormat.getUseableHeight());
    Point2f framePos = new Point2f(pageFormat.getMargins().getLeft() + frameSize.width / 2, pageFormat.getMargins().getTop() + frameSize.height / 2);
    // layout the score to find out the needed space
    Target target = Target.completeLayoutTarget(new ScoreLayoutArea(frameSize));
    ScoreLayouter layouter = new ScoreLayouter(ret, target);
    ScoreLayout scoreLayout = isErrorLayoutEnabled ? layouter.createScoreLayout() : layouter.createLayoutWithExceptions();
    // create and fill at least one page
    if (scoreLayout.frames.size() > 0) {
        // normal layout: one frame per page
        ScoreFrameChain chain = null;
        for (int i = 0; i < scoreLayout.frames.size(); i++) {
            Page page = new Page(pageFormat);
            layout.addPage(page);
            ScoreFrame frame = new ScoreFrame();
            frame.setPosition(framePos);
            frame.setSize(frameSize);
            // TEST frame = frame.withHFill(NoHorizontalSystemFillingStrategy.getInstance());
            page.addFrame(frame);
            if (chain == null) {
                chain = new ScoreFrameChain(score);
                chain.setScoreLayout(scoreLayout);
            }
            chain.add(frame);
        }
    } else {
        // no frames: create a single empty page
        Page page = new Page(pageFormat);
        layout.addPage(page);
    }
    return ret;
}
Also used : ScoreFrame(com.xenoage.zong.layout.frames.ScoreFrame) ScoreLayouter(com.xenoage.zong.musiclayout.layouter.ScoreLayouter) ScoreLayout(com.xenoage.zong.musiclayout.ScoreLayout) LayoutFormat.defaultLayoutFormat(com.xenoage.zong.core.format.LayoutFormat.defaultLayoutFormat) LayoutFormat(com.xenoage.zong.core.format.LayoutFormat) Page(com.xenoage.zong.layout.Page) LayoutDefaults(com.xenoage.zong.layout.LayoutDefaults) ScoreDoc(com.xenoage.zong.documents.ScoreDoc) PageFormat(com.xenoage.zong.core.format.PageFormat) Target(com.xenoage.zong.musiclayout.layouter.Target) Point2f(com.xenoage.utils.math.geom.Point2f) ScoreLayout(com.xenoage.zong.musiclayout.ScoreLayout) Layout(com.xenoage.zong.layout.Layout) ScoreFrameChain(com.xenoage.zong.layout.frames.ScoreFrameChain) Size2f(com.xenoage.utils.math.geom.Size2f) ScoreLayoutArea(com.xenoage.zong.musiclayout.layouter.ScoreLayoutArea)

Aggregations

Size2f (com.xenoage.utils.math.geom.Size2f)6 PageFormat (com.xenoage.zong.core.format.PageFormat)6 PageMargins (com.xenoage.zong.core.format.PageMargins)5 ScoreFrame (com.xenoage.zong.layout.frames.ScoreFrame)4 Layout (com.xenoage.zong.layout.Layout)3 Page (com.xenoage.zong.layout.Page)3 Point2f (com.xenoage.utils.math.geom.Point2f)2 LayoutFormat (com.xenoage.zong.core.format.LayoutFormat)2 LayoutFormat.defaultLayoutFormat (com.xenoage.zong.core.format.LayoutFormat.defaultLayoutFormat)2 GroupFrame (com.xenoage.zong.layout.frames.GroupFrame)2 ScoreFrameChain (com.xenoage.zong.layout.frames.ScoreFrameChain)2 ScoreLayout (com.xenoage.zong.musiclayout.ScoreLayout)2 ScoreLayoutArea (com.xenoage.zong.musiclayout.layouter.ScoreLayoutArea)2 ScoreLayouter (com.xenoage.zong.musiclayout.layouter.ScoreLayouter)2 Target (com.xenoage.zong.musiclayout.layouter.Target)2 Paint (android.graphics.Paint)1 Score (com.xenoage.zong.core.Score)1 ScoreFormat (com.xenoage.zong.core.format.ScoreFormat)1 SystemLayout (com.xenoage.zong.core.format.SystemLayout)1 ColumnHeader (com.xenoage.zong.core.header.ColumnHeader)1