use of com.xenoage.zong.musiclayout.layouter.Context 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.musiclayout.layouter.Context in project Zong by Xenoage.
the class Layout method updateScoreLayouts.
/**
* Updates the {@link ScoreLayout}s belonging to the given {@link Score}.
*/
public void updateScoreLayouts(Score score) {
ScoreFrameChain chain = getScoreFrameChain(score);
if (chain == null)
return;
ScoreLayout oldScoreLayout = chain.getScoreLayout();
// select symbol pool and layout settings
SymbolPool symbolPool = oldScoreLayout != null ? oldScoreLayout.symbolPool : defaults.getSymbolPool();
LayoutSettings layoutSettings = oldScoreLayout != null ? oldScoreLayout.layoutSettings : defaults.getLayoutSettings();
CList<ScoreLayoutArea> areas = clist();
for (ScoreFrame scoreFrame : chain.getFrames()) {
areas.add(new ScoreLayoutArea(scoreFrame.getSize(), scoreFrame.getHFill(), scoreFrame.getVFill()));
}
areas.close();
Context context = new Context(score, symbolPool, layoutSettings);
Target target = new Target(areas, areas.get(areas.size() - 1), false);
ScoreLayout scoreLayout = new ScoreLayouter(context, target).createScoreLayout();
// set updated layout
chain.setScoreLayout(scoreLayout);
}
use of com.xenoage.zong.musiclayout.layouter.Context in project Zong by Xenoage.
the class WebApp method openFile.
private void openFile(String filePath) {
// show loading, hide score
if (loadingPanel != null)
loadingPanel.getStyle().setDisplay(BLOCK);
canvas.setVisible(false);
// load score
platformUtils().openFileAsync(filePath).thenAsync(scoreStream -> new MusicXmlScoreDocFileReader(scoreStream, null).read()).thenAsync(scoreDoc -> {
WebApp.this.scoreDoc = scoreDoc;
return platformUtils().openFileAsync("data/layout/default.xml");
}).thenDo(testXmlStream -> {
LayoutSettings layoutSettings;
try {
layoutSettings = LayoutSettingsReader.read(testXmlStream);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
Size2f areaSize = new Size2f(150, 10000);
SymbolPool symbolPool = zongPlatformUtils().getSymbolPool();
Context context = new Context(scoreDoc.getScore(), symbolPool, layoutSettings);
Target target = Target.completeLayoutTarget(new ScoreLayoutArea(areaSize));
paintLayout();
// show score, hide loading
canvas.setVisible(true);
if (loadingPanel != null)
loadingPanel.getStyle().setDisplay(NONE);
}).onError(ex -> consoleLog("Error: " + ex.toString()));
}
Aggregations