Search in sources :

Example 26 with Point2f

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

the class StaffStampingTest method createStaffLayoutElement.

@Test
public void createStaffLayoutElement() {
    // create default staff layout element.
    // drawing element must have 5 lines and the default interline space.
    StaffStamping staff1 = new StaffStamping(null, 0, new Point2f(40, 80), 160, 5, 1.6f);
    assertEquals(5, staff1.linesCount);
    assertEquals(scoreFormat.getInterlineSpace(), staff1.is, df);
    assertEquals(40, staff1.positionMm.x, df);
    assertEquals(80, staff1.positionMm.y, df);
    assertEquals(160, staff1.lengthMm, df);
    // create another staff layout element
    // with 3 lines and 4 mm interline space.
    StaffStamping staff2 = new StaffStamping(null, 0, new Point2f(40, 160), 160, 3, 4);
    assertEquals(3, staff2.linesCount);
    assertEquals(4, staff2.is, df);
}
Also used : Point2f(com.xenoage.utils.math.geom.Point2f) Test(org.junit.Test)

Example 27 with Point2f

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

the class PartNameStamper method stamp.

@MaybeNull
public FrameTextStamping stamp(Part part, int firstStaffIndex, List<StaffStamping> systemStaves, Style style) {
    StaffStamping firstStaff = systemStaves.get(firstStaffIndex);
    StaffStamping lastStaff = systemStaves.get(firstStaffIndex + part.getStavesCount() - 1);
    String name = (style == Style.Full ? part.getName() : part.getAbbreviation());
    if (name == null || name.length() == 0)
        return null;
    // in the middle of the staves
    float top = firstStaff.positionMm.y;
    float bottom = lastStaff.positionMm.y + (lastStaff.linesCount - 1) * lastStaff.is;
    FormattedText text = // TODO
    Companion.fText(// TODO
    name, // TODO
    new FormattedTextStyle(firstStaff.is * 2.5f * 2.67f), Alignment.Right);
    if (text.getParagraphs().size() == 0)
        return null;
    // TODO correction of baseline. /3 looks good.
    float middle = (top + bottom) / 2 + text.getFirstParagraph().getMetrics().getAscent() / 3;
    return new FrameTextStamping(text, new Point2f(firstStaff.positionMm.x - firstStaff.is * 2.5f, middle), // TODO
    null);
}
Also used : Point2f(com.xenoage.utils.math.geom.Point2f) StaffStamping(com.xenoage.zong.musiclayout.stampings.StaffStamping) FormattedTextStyle(com.xenoage.zong.core.text.FormattedTextStyle) FrameTextStamping(com.xenoage.zong.musiclayout.stampings.FrameTextStamping) FormattedText(com.xenoage.zong.core.text.FormattedText) MaybeNull(com.xenoage.utils.annotations.MaybeNull)

Example 28 with Point2f

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

the class Path method computeBounds.

private Rectangle2f computeBounds() {
    // just an estimate (curve lines not included, just the points), but ok for now
    float minX = Float.MAX_VALUE, maxX = Float.MIN_VALUE;
    float minY = Float.MAX_VALUE, maxY = Float.MIN_VALUE;
    for (PathElement e : elements) {
        Point2f p = e.getTarget();
        if (p != null) {
            minX = Math.min(minX, p.x);
            maxX = Math.max(maxX, p.x);
            minY = Math.min(minY, p.y);
            maxY = Math.max(maxY, p.y);
        }
    }
    return new Rectangle2f(minX, minY, maxX - minX, maxY - minY);
}
Also used : Point2f(com.xenoage.utils.math.geom.Point2f) Rectangle2f(com.xenoage.utils.math.geom.Rectangle2f)

Example 29 with Point2f

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

the class JfxCanvas method drawText.

@Override
public void drawText(FormattedText text, TextSelection selection, Point2f position, boolean yIsBaseline, float frameWidth) {
    context.save();
    context.translate(position.x, position.y);
    // print the text frame paragraph for paragraph
    float offsetX = 0;
    float offsetY = 0;
    for (FormattedTextParagraph p : text.getParagraphs()) {
        TextMetrics pMetrics = p.getMetrics();
        if (!yIsBaseline)
            offsetY += pMetrics.getAscent();
        // adjustment
        if (p.getAlignment() == Alignment.Center)
            offsetX = (frameWidth - pMetrics.getWidth()) / 2;
        else if (p.getAlignment() == Alignment.Right)
            offsetX = frameWidth - pMetrics.getWidth();
        else
            offsetX = 0;
        // draw elements
        for (FormattedTextElement e : p.getElements()) {
            if (e instanceof FormattedTextString) {
                // TODO formatting
                FormattedTextString t = (FormattedTextString) e;
                context.setFill(toJavaFXColor(t.getStyle().getColor()));
                Font font = toJavaFXFont(t.getStyle().getFont());
                context.setFont(font);
                context.save();
                context.scale(Units.pxToMm_1_1, Units.pxToMm_1_1);
                context.fillText(t.getText(), offsetX / Units.pxToMm_1_1, offsetY / Units.pxToMm_1_1);
                context.restore();
            } else {
                // symbol
                FormattedTextSymbol fts = (FormattedTextSymbol) e;
                float scaling = fts.getScaling();
                SymbolsRenderer.draw(fts.getSymbol(), this, Color.Companion.getBlack(), new Point2f(offsetX + fts.getOffsetX(), offsetY + fts.getSymbol().getBaselineOffset() * scaling), new Point2f(scaling, scaling));
            }
            offsetX += e.getMetrics().getWidth();
        }
        // next line
        offsetY += p.getMetrics().getAscent() + p.getMetrics().getDescent() + p.getMetrics().getLeading();
    }
    context.restore();
}
Also used : FormattedTextString(com.xenoage.zong.core.text.FormattedTextString) Point2f(com.xenoage.utils.math.geom.Point2f) TextMetrics(com.xenoage.utils.font.TextMetrics) FormattedTextParagraph(com.xenoage.zong.core.text.FormattedTextParagraph) FormattedTextElement(com.xenoage.zong.core.text.FormattedTextElement) FormattedTextSymbol(com.xenoage.zong.core.text.FormattedTextSymbol) Font(javafx.scene.text.Font) JfxFontUtils.toJavaFXFont(com.xenoage.utils.jse.javafx.font.JfxFontUtils.toJavaFXFont)

Example 30 with Point2f

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

the class FrameRenderer method paint.

/**
 * Paints the given {@link Frame} on the
 * given {@link Canvas} using the given {@link RendererArgs}.
 */
public void paint(Frame frame, Canvas canvas, RendererArgs args) {
    // backup old transformation
    canvas.transformSave();
    // apply translation: origin offset in screen space
    canvas.transformTranslate(args.offsetPx.x, args.offsetPx.y);
    // apply scaling
    float scaling = Units.mmToPx(args.scaling, 1);
    canvas.transformScale(scaling, scaling);
    // apply translation: absolute frame position in layout space
    Point2f pos = frame.getAbsolutePosition();
    canvas.transformTranslate(pos.x, pos.y);
    // apply rotation
    canvas.transformRotate(-frame.getAbsoluteRotation());
    // if there is a background, draw it
    if (frame.getBackground() != null) {
        Rectangle2f rect = getLocalRect(frame);
        canvas.fillRect(rect, frame.getBackground());
    }
    // paint the frame
    paintTransformed(frame, canvas, args);
    // restore old transformation
    canvas.transformRestore();
}
Also used : Point2f(com.xenoage.utils.math.geom.Point2f) Rectangle2f(com.xenoage.utils.math.geom.Rectangle2f)

Aggregations

Point2f (com.xenoage.utils.math.geom.Point2f)51 BitmapStaff (com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff)11 StaffStamping (com.xenoage.zong.musiclayout.stampings.StaffStamping)10 Test (org.junit.Test)10 Color (com.xenoage.utils.color.Color)7 Page (com.xenoage.zong.layout.Page)6 Size2f (com.xenoage.utils.math.geom.Size2f)5 Layout (com.xenoage.zong.layout.Layout)5 ScoreFrame (com.xenoage.zong.layout.frames.ScoreFrame)5 BitmapLine (com.xenoage.zong.musiclayout.stampings.bitmap.BitmapLine)5 Rectangle2f (com.xenoage.utils.math.geom.Rectangle2f)4 FormattedText (com.xenoage.zong.core.text.FormattedText)4 TextMetrics (com.xenoage.utils.font.TextMetrics)3 FormattedTextParagraph (com.xenoage.zong.core.text.FormattedTextParagraph)3 ScoreFrameChain (com.xenoage.zong.layout.frames.ScoreFrameChain)3 ScoreLayout (com.xenoage.zong.musiclayout.ScoreLayout)3 Paint (android.graphics.Paint)2 Point2i (com.xenoage.utils.math.geom.Point2i)2 Size2i (com.xenoage.utils.math.geom.Size2i)2 Score (com.xenoage.zong.core.Score)2