Search in sources :

Example 16 with Size2f

use of com.xenoage.utils.math.geom.Size2f in project Zong by Xenoage.

the class StretchSystemsTest method computeTest.

@Test
public void computeTest() {
    // create a simple frame for testing
    float usableHeight = 400;
    int stavesCount = 2;
    float staffHeight = 10;
    float staffDistance = 30;
    float offset1 = 0;
    float offset2 = 100;
    float offset3 = 200;
    SystemSpacing system1 = createSystem(stavesCount, staffHeight, staffDistance, offset1);
    SystemSpacing system2 = createSystem(stavesCount, staffHeight, staffDistance, offset2);
    SystemSpacing system3 = createSystem(stavesCount, staffHeight, staffDistance, offset3);
    FrameSpacing frame = new FrameSpacing(ilist(system1, system2, system3), new Size2f(10, usableHeight));
    // apply strategy
    testee.compute(frame, null);
    // compare values
    // remaining space is usable height - offset3 - (height of last system)
    float remainingSpace = usableHeight - offset3 - system3.getHeightMm();
    // the last two systems are moved down, each remainingSpace/2
    float additionalSpace = remainingSpace / 2;
    // compare new offsets
    assertEquals(offset2 + 1 * additionalSpace, frame.getSystems().get(1).offsetYMm, df);
    assertEquals(offset3 + 2 * additionalSpace, frame.getSystems().get(2).offsetYMm, df);
}
Also used : FrameSpacing(com.xenoage.zong.musiclayout.spacing.FrameSpacing) Size2f(com.xenoage.utils.math.geom.Size2f) SystemSpacing(com.xenoage.zong.musiclayout.spacing.SystemSpacing) Test(org.junit.Test)

Example 17 with Size2f

use of com.xenoage.utils.math.geom.Size2f 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 18 with Size2f

use of com.xenoage.utils.math.geom.Size2f in project Zong by Xenoage.

the class JfxLayoutRenderer method paintToImage.

/**
 * Returns a {@link WritableImage} with the given page of the given {@link Layout}
 * which is rendered at the given zoom level.
 */
public static WritableImage paintToImage(Layout layout, int pageIndex, float zoom) {
    Page page = layout.getPages().get(pageIndex);
    Size2f pageSize = page.getFormat().getSize();
    int width = Units.mmToPxInt(pageSize.width, zoom);
    int height = Units.mmToPxInt(pageSize.height, zoom);
    WritableImage wim = new WritableImage(width, height);
    Canvas jfxCanvas = new Canvas(width, height);
    GraphicsContext context = jfxCanvas.getGraphicsContext2D();
    context.setFill(Color.WHITE);
    context.fillRect(0, 0, width, height);
    LayoutRenderer.paintToCanvas(layout, pageIndex, zoom, origin, new JfxCanvas(context, pageSize, CanvasFormat.Raster, CanvasDecoration.Interactive, CanvasIntegrity.Perfect));
    jfxCanvas.snapshot(null, wim);
    return wim;
}
Also used : WritableImage(javafx.scene.image.WritableImage) GraphicsContext(javafx.scene.canvas.GraphicsContext) Size2f(com.xenoage.utils.math.geom.Size2f) JfxCanvas(com.xenoage.zong.renderer.javafx.canvas.JfxCanvas) Canvas(javafx.scene.canvas.Canvas) Page(com.xenoage.zong.layout.Page) JfxCanvas(com.xenoage.zong.renderer.javafx.canvas.JfxCanvas)

Example 19 with Size2f

use of com.xenoage.utils.math.geom.Size2f 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 20 with Size2f

use of com.xenoage.utils.math.geom.Size2f in project Zong by Xenoage.

the class FrameTest method createFrameWithChildren.

public static GroupFrame createFrameWithChildren() {
    // frame
    GroupFrame frame = new GroupFrame();
    frame.setPosition(new Point2f(50, 75));
    frame.setSize(new Size2f(80, 50));
    frame.setRotation(30);
    // child frame
    GroupFrame child = new GroupFrame();
    child.setPosition(new Point2f(20, 10));
    child.setSize(new Size2f(30, 20));
    child.setRotation(30);
    // child frame of child frame
    TestFrame child2 = new TestFrame();
    child2.setPosition(new Point2f(-15, -10));
    child2.setSize(new Size2f(5, 5));
    child2.setRotation(45);
    // hierarchy
    child.addChildFrame(child2);
    frame.addChildFrame(child);
    return frame;
}
Also used : Point2f(com.xenoage.utils.math.geom.Point2f) Size2f(com.xenoage.utils.math.geom.Size2f)

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