use of com.xenoage.zong.musiclayout.ScoreLayout in project Zong by Xenoage.
the class ScoreDocFactory method read.
/**
* Creates a {@link ScoreDoc} instance from the given score.
* TIDY: move elsewhere, e.g. in a ScoreDocFactory class
*/
public ScoreDoc read(Score score) throws InvalidFormatException, IOException {
// page format
LayoutFormat layoutFormat = Companion.getDefaultLayoutFormat();
Object oLayoutFormat = score.getMetaData().get("layoutformat");
if (oLayoutFormat instanceof LayoutFormat) {
layoutFormat = (LayoutFormat) oLayoutFormat;
}
LayoutDefaults layoutDefaults = new LayoutDefaults(layoutFormat);
// create the document
ScoreDoc ret = new ScoreDoc(score, layoutDefaults);
Layout layout = ret.getLayout();
// layout basics
PageFormat pageFormat = layoutFormat.getPageFormat(0);
Size2f frameSize = new Size2f(pageFormat.getUseableWidth(), pageFormat.getUseableHeight());
Point2f framePos = new Point2f(pageFormat.getMargins().getLeft() + frameSize.width / 2, pageFormat.getMargins().getTop() + frameSize.height / 2);
// layout the score to find out the needed space
Target target = Target.completeLayoutTarget(new ScoreLayoutArea(frameSize));
ScoreLayouter layouter = new ScoreLayouter(ret, target);
ScoreLayout scoreLayout = isErrorLayoutEnabled ? layouter.createScoreLayout() : layouter.createLayoutWithExceptions();
// create and fill at least one page
if (scoreLayout.frames.size() > 0) {
// normal layout: one frame per page
ScoreFrameChain chain = null;
for (int i = 0; i < scoreLayout.frames.size(); i++) {
Page page = new Page(pageFormat);
layout.addPage(page);
ScoreFrame frame = new ScoreFrame();
frame.setPosition(framePos);
frame.setSize(frameSize);
// TEST frame = frame.withHFill(NoHorizontalSystemFillingStrategy.getInstance());
page.addFrame(frame);
if (chain == null) {
chain = new ScoreFrameChain(score);
chain.setScoreLayout(scoreLayout);
}
chain.add(frame);
}
} else {
// no frames: create a single empty page
Page page = new Page(pageFormat);
layout.addPage(page);
}
return ret;
}
use of com.xenoage.zong.musiclayout.ScoreLayout 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;
}
Aggregations