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);
}
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);
}
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;
}
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;
}
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;
}
Aggregations