Search in sources :

Example 1 with Size2f

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

use of com.xenoage.utils.math.geom.Size2f 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;
}
Also used : Bitmap(android.graphics.Bitmap) Size2f(com.xenoage.utils.math.geom.Size2f) AndroidCanvas(com.xenoage.zong.android.renderer.canvas.AndroidCanvas) Canvas(android.graphics.Canvas) Page(com.xenoage.zong.layout.Page) AndroidCanvas(com.xenoage.zong.android.renderer.canvas.AndroidCanvas)

Example 3 with Size2f

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

the class FramesSpacer method compute.

public FramesSpacing compute(List<ColumnSpacing> columns, Target target, Context context, Notations notations) {
    context.saveMp();
    ArrayList<FrameSpacing> frames = alist();
    int measuresCount = context.score.getMeasuresCount();
    int iMeasure = 0;
    int iSystem = 0;
    int iFrame = 0;
    boolean additionalFrameIteration;
    while (true) {
        additionalFrameIteration = false;
        // find score frame
        Size2f frameSize;
        if (iFrame < target.areas.size()) {
            // there is another existing score frame
            frameSize = target.getArea(iFrame).sizeMm;
        } else {
            // there is no another existing score frame
            if (false == target.isCompleteLayout) {
                // we are not interested in the stuff after the last score frame. exit.
                break;
            } else if (iMeasure >= measuresCount) {
                // all measures layouted. exit.
                break;
            } else {
                // still material to layout and additional frames requested. create one.
                frameSize = target.additionalArea.sizeMm;
                additionalFrameIteration = true;
            }
        }
        // some material left to layout?
        if (iMeasure < measuresCount) {
            // more measures to layout
            context.mp = atMeasure(iMeasure);
            FrameSpacing frame = frameSpacer.compute(context, iSystem, frameSize, additionalFrameIteration, columns, notations);
            if (frame.getSystems().size() > 0) {
                // at least one measure in this frame. remember frame
                frames.add(frame);
                iMeasure = frame.getEndMeasure() + 1;
                iSystem += frame.getSystems().size();
            } else {
                // do not create endless list of empty additional frames
                if (!additionalFrameIteration) {
                    frames.add(FrameSpacing.empty(frameSize));
                } else {
                    break;
                }
            }
        } else {
            // no material left. empty frame.
            frames.add(FrameSpacing.empty(frameSize));
        }
        // next frame
        iFrame++;
    }
    context.restoreMp();
    return new FramesSpacing(frames);
}
Also used : FramesSpacing(com.xenoage.zong.musiclayout.spacing.FramesSpacing) FrameSpacing(com.xenoage.zong.musiclayout.spacing.FrameSpacing) Size2f(com.xenoage.utils.math.geom.Size2f)

Example 4 with Size2f

use of com.xenoage.utils.math.geom.Size2f 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();
}
Also used : PdfWriter(com.itextpdf.text.pdf.PdfWriter) Size2f(com.xenoage.utils.math.geom.Size2f) PdfGraphics2D(com.itextpdf.awt.PdfGraphics2D) AwtCanvas(com.xenoage.zong.renderer.awt.canvas.AwtCanvas) PdfContentByte(com.itextpdf.text.pdf.PdfContentByte) Page(com.xenoage.zong.layout.Page) Document(com.itextpdf.text.Document) PdfTemplate(com.itextpdf.text.pdf.PdfTemplate) Graphics2D(java.awt.Graphics2D) PdfGraphics2D(com.itextpdf.awt.PdfGraphics2D)

Example 5 with Size2f

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

the class PrintProcess method print.

@Override
public int print(Graphics g, PageFormat pageFormat, int pageIndex) throws PrinterException {
    // valid page number?
    if (pageIndex < 0 || pageIndex >= layout.getPages().size()) {
        return Printable.NO_SUCH_PAGE;
    }
    // print page
    INSTANCE.log(Companion.remark("Printing page " + pageIndex + "..."));
    Graphics2D g2d = (Graphics2D) g;
    Size2f pageSize = layout.getPages().get(pageIndex).getFormat().getSize();
    LayoutRenderer.paintToCanvas(layout, pageIndex, new AwtCanvas(g2d, pageSize, CanvasFormat.Vector, CanvasDecoration.None, CanvasIntegrity.Perfect));
    return Printable.PAGE_EXISTS;
}
Also used : Size2f(com.xenoage.utils.math.geom.Size2f) AwtCanvas(com.xenoage.zong.renderer.awt.canvas.AwtCanvas) Graphics2D(java.awt.Graphics2D)

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