use of com.xenoage.zong.layout.Page 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;
}
use of com.xenoage.zong.layout.Page in project Zong by Xenoage.
the class AndroidLayoutRenderer method paint.
/**
* Returns a {@link Bitmap} with the given page of the given {@link Layout}
* which is rendered at the given zoom level.
*/
public Bitmap paint(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);
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
// TODO: necessary? and really 8888 bitmap?
canvas.drawARGB(255, 255, 255, 255);
canvas.scale(zoom, zoom);
paint(layout, pageIndex, new AndroidCanvas(canvas, pageSize, CanvasFormat.Raster, CanvasDecoration.None, CanvasIntegrity.Perfect), zoom);
return bitmap;
}
use of com.xenoage.zong.layout.Page in project Zong by Xenoage.
the class PdfPrinter method print.
/**
* Prints the given {@link Layout} into the given PDF output stream.
*/
public static void print(Layout layout, OutputStream out) {
Document document = new Document();
PdfWriter writer = null;
try {
writer = PdfWriter.getInstance(document, out);
} catch (Exception e) {
handle(warning(Voc.ErrorWhilePrinting));
}
document.open();
PdfContentByte cb = writer.getDirectContent();
It<Page> pages = it(layout.getPages());
for (Page page : pages) {
// create PDF page
Size2f pageSize = page.getFormat().getSize();
float width = Units.mmToPx(pageSize.width, 1);
float height = Units.mmToPx(pageSize.height, 1);
document.newPage();
PdfTemplate tp = cb.createTemplate(width, height);
// fill PDF page
Graphics2D g2d = new PdfGraphics2D(cb, width, height);
INSTANCE.log(Companion.remark("Printing page " + pages.getIndex() + "..."));
LayoutRenderer.paintToCanvas(layout, pages.getIndex(), new AwtCanvas(g2d, pageSize, CanvasFormat.Vector, CanvasDecoration.None, CanvasIntegrity.Perfect));
// finish page
g2d.dispose();
cb.addTemplate(tp, 0, 0);
}
document.close();
}
use of com.xenoage.zong.layout.Page in project Zong by Xenoage.
the class Frame method getCenterLP.
/**
* Gets the {@link LayoutPos} of the center of the frame.
* If this frame is not part of a layout, the page index -1 is returned.
*/
public final LayoutPos getCenterLP() {
Point2f pos = getAbsolutePosition();
Layout layout = getParentLayout();
Page page = getParentPage();
int pageIndex = (page != null ? page.getIndex() : -1);
return layoutPos(layout, pageIndex, pos);
}
use of com.xenoage.zong.layout.Page in project Zong by Xenoage.
the class AwtLayoutRenderer method paintToImage.
/**
* Returns a {@link BufferedImage} with the given page of the given {@link Layout}
* which is rendered at the given zoom level.
*/
public static BufferedImage 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);
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = img.createGraphics();
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
g2d.setColor(Color.WHITE);
g2d.fillRect(0, 0, width, height);
LayoutRenderer.paintToCanvas(layout, pageIndex, zoom, origin, new AwtCanvas(g2d, pageSize, CanvasFormat.Raster, CanvasDecoration.Interactive, CanvasIntegrity.Perfect));
g2d.dispose();
return img;
}
Aggregations