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