use of com.xenoage.zong.core.format.SystemLayout 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;
}
use of com.xenoage.zong.core.format.SystemLayout in project Zong by Xenoage.
the class EmptySystems method createEmptySystem.
/**
* Creates an additional system for the given {@link Score} with
* the given width and y-offset in mm and returns it.
*/
private SystemSpacing createEmptySystem(Score score, float width, float offsetY) {
// compute staves spacing
StavesSpacing stavesSpacing = StavesSpacer.stavesSpacer.compute(score, 0);
// create and returns system
SystemLayout defaultSystemLayout = score.getFormat().getSystemLayout();
return new SystemSpacing(CollectionUtils.<ColumnSpacing>alist(), defaultSystemLayout.getMarginLeft(), defaultSystemLayout.getMarginRight(), width, stavesSpacing, offsetY);
}
use of com.xenoage.zong.core.format.SystemLayout in project Zong by Xenoage.
the class EmptySystems method compute.
@Override
public void compute(FrameSpacing frame, Score score) {
Size2f usableSize = frame.usableSizeMm;
// compute remaining space
float remainingSpace = usableSize.height;
float offsetY = 0;
if (frame.systems.size() > 0) {
SystemSpacing lastSystem = getLast(frame.systems);
offsetY = lastSystem.getOffsetYMm() + lastSystem.getHeightMm();
remainingSpace -= offsetY;
}
// compute height of an additional system
SystemLayout defaultSystemLayout = score.getFormat().getSystemLayout();
float defaultSystemDistance = defaultSystemLayout.getDistance();
float defaultMargin = defaultSystemLayout.getMarginLeft() + defaultSystemLayout.getMarginRight();
SystemSpacing newSystem = createEmptySystem(score, usableSize.width, 0);
float newSystemHeight = defaultSystemDistance + newSystem.getHeightMm();
// add as many additional empty staves as possible
int newSystemsCount = (int) (remainingSpace / newSystemHeight);
for (int i : range(newSystemsCount)) {
frame.systems.add(createEmptySystem(score, usableSize.width - defaultMargin, offsetY + (i * newSystemHeight) + defaultSystemDistance));
}
}
use of com.xenoage.zong.core.format.SystemLayout in project Zong by Xenoage.
the class PrintReader method readSystemLayout.
private SystemLayout readSystemLayout(boolean isPageStarted, float tenthMm) {
MxlLayout mxlLayout = mxlPrint.getLayout();
if (mxlLayout != null) {
MxlSystemLayout mxlSystemLayout = mxlLayout.getSystemLayout();
if (mxlSystemLayout != null) {
SystemLayoutReader systemLayoutReader = new SystemLayoutReader(mxlSystemLayout, tenthMm);
SystemLayout systemLayout = systemLayoutReader.read();
Float topSystemDistance = systemLayoutReader.getTopSystemDistance();
// for first systems on a page, use top-system-distance
if (isPageStarted && topSystemDistance != null)
systemLayout.setDistance(topSystemDistance);
return systemLayout;
}
}
return null;
}
use of com.xenoage.zong.core.format.SystemLayout in project Zong by Xenoage.
the class PrintReader method readToContext.
public void readToContext(Context context) {
ScoreHeader header = context.getScore().getHeader();
int measure = context.getMp().measure;
// system and page break
Break break_ = readBreak();
if (break_ != null) {
// MusicXML print is in the first broken measure, but we
// store the break in the last measure before the break (thus -1)
int breakMeasure = measure - 1;
if (// ignore, when in the first measure
breakMeasure >= 0)
context.writeColumnElement(break_, breakMeasure);
}
// the first measure of a score is also ok.
if (measure == 0 || break_ != null) {
// first page or new page?
boolean isPageBreak = break_ != null && break_.getPageBreak() == PageBreak.NewPage;
boolean isPageStarted = (measure == 0 || isPageBreak);
if (isPageBreak) {
// increment page index
context.incPageIndex();
}
// first system or new system?
boolean isSystemBreak = isPageBreak || (break_ != null && break_.getSystemBreak() == SystemBreak.NewSystem);
if (isSystemBreak) {
// increment system index
context.incSystemIndex();
}
// read system layout, if there
SystemLayout systemLayout = readSystemLayout(isPageStarted, context.getTenthMm());
if (systemLayout != null)
header.setSystemLayout(context.getSystemIndex(), systemLayout);
// staff layouts
MxlLayout mxlLayout = mxlPrint.getLayout();
if (mxlLayout != null) {
for (MxlStaffLayout mxlStaffLayout : it(mxlLayout.getStaffLayouts())) {
int staffIndex = mxlStaffLayout.getNumberNotNull() - 1;
// get system layout. if it does not exist yet, create it
systemLayout = header.getSystemLayout(context.getSystemIndex());
if (systemLayout == null) {
systemLayout = new SystemLayout();
header.setSystemLayout(context.getSystemIndex(), systemLayout);
}
StaffLayout staffLayout = new StaffLayoutReader(mxlStaffLayout, context.getTenthMm()).read();
systemLayout.setStaffLayout(context.getPartStaffIndices().getStart() + staffIndex, staffLayout);
}
}
}
}
Aggregations