use of com.xenoage.utils.math.geom.Point2f in project Zong by Xenoage.
the class Layout method computeLP.
/**
* Returns the {@link LayoutPos} of the given {@link MP} within the given {@link Score}
* at the given line position, or null if unknown.
*/
public LayoutPos computeLP(Score score, MP mp, float lp) {
ScoreFrameChain chain = getScoreFrameChain(score);
if (chain != null) {
ScoreLayout sl = chain.getScoreLayout();
ScoreLayoutPos slp = sl.getScoreLP(mp, lp);
if (slp != null) {
ScoreFrame frame = chain.getFrames().get(slp.frameIndex);
Page page = frame.getParentPage();
if (page != null) {
Point2f frameP = slp.pMm.sub(frame.getSize().width / 2, frame.getSize().height / 2);
int pageIndex = pages.indexOf(page);
Point2f pMm = frame.getPagePosition(frameP);
return layoutPos(this, pageIndex, pMm);
}
}
}
return null;
}
use of com.xenoage.utils.math.geom.Point2f in project Zong by Xenoage.
the class ScoreLayout method getScoreLP.
/**
* Computes the {@link ScoreLayoutPos} of the given {@link MP} at the given line position.
* If not found, null is returned.
*/
public ScoreLayoutPos getScoreLP(MP mp, float lp) {
int iFrame = getFrameIndexOf(mp.getMeasure());
if (iFrame > -1) {
ScoreFrameLayout sfl = frames.get(iFrame);
StaffStamping ss;
if (mp.getStaff() != MP.Companion.getUnknown())
ss = sfl.getStaffStamping(mp.getStaff(), mp.getMeasure());
else
ss = sfl.getStaffStamping(0, mp.getMeasure());
if (ss != null) {
float x = ss.positionMm.x + ss.system.getXMmAt(mp.getTime());
float y = ss.computeYMm(lp);
return new ScoreLayoutPos(iFrame, new Point2f(x, y));
}
}
return null;
}
use of com.xenoage.utils.math.geom.Point2f in project Zong by Xenoage.
the class ScoreFrame method getScoreLayoutPosition.
/**
* Converts the given position from frame space into score layout space.
* Both spaces use mm units, the difference is the origin:
* While frames have their origin in the center, the
* origin of a score layout is in the upper left corner.
*/
public Point2f getScoreLayoutPosition(Point2f framePosition) {
Point2f ret = framePosition;
ret = ret.add(size.width / 2, size.height / 2);
return ret;
}
use of com.xenoage.utils.math.geom.Point2f in project Zong by Xenoage.
the class AndroidCanvas method drawText.
/**
* {@inheritDoc}
* The text selection is ignored.
*/
@Override
public void drawText(FormattedText text, TextSelection selection, Point2f position, boolean yIsBaseline, float frameWidth) {
int oldTransform = canvas.save();
canvas.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;
Paint paint = new Paint(AndroidColorUtils.black);
paint.setTypeface(Typeface.SERIF);
paint.setTextSize(Units.pxToMm(t.getStyle().getFont().getSize(), 1));
// nice, smooth drawing
paint.setFlags(Paint.LINEAR_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
canvas.drawText(t.getText(), offsetX, offsetY, paint);
} else {
// symbol
FormattedTextSymbol fts = (FormattedTextSymbol) e;
float scaling = fts.getScaling();
androidSymbolsRenderer.draw((PathSymbol) fts.getSymbol(), canvas, Color.black, new Point2f(offsetX + fts.getOffsetX(), offsetY + fts.getSymbol().baselineOffset * scaling), new Point2f(scaling, scaling));
}
offsetX += e.getMetrics().getWidth();
}
// next line
offsetY += p.getMetrics().getAscent() + p.getMetrics().getDescent() + p.getMetrics().getLeading();
}
canvas.restoreToCount(oldTransform);
}
use of com.xenoage.utils.math.geom.Point2f in project Zong by Xenoage.
the class MathUtils method computeRectangleFromTo.
/**
* Computes and returns a rotated rectangle, that encloses the given two
* points with the given width.
* This is shown here:
*
* <pre>
* [0]---___
* / ---___
* p1 ---[1] _ _
* / / /
* [3]---___ p2 / width
* ---___ / /
* ---[2] _/_
* </pre>
*
* The result is returned as four Point2f values as shown on the above
* sketch.
*/
public static Point2f[] computeRectangleFromTo(Point2f p1, Point2f p2, float width) {
// compute the line from p1 to p2
Point2f p1Top2 = p2.sub(p1);
// compute the line from p1 to [0]
Point2f p1To0 = new Point2f(p1Top2.y, -p1Top2.x).normalize().scale(width / 2);
// compute return values
Point2f[] ret = new Point2f[] { p1.add(p1To0), p2.add(p1To0), p2.sub(p1To0), p1.sub(p1To0) };
return ret;
}
Aggregations