use of com.xenoage.zong.symbols.SymbolPool in project Zong by Xenoage.
the class TimeRenderer method draw.
/**
* Draws the given {@link TimeStamping} on the given {@link Canvas},
* using the given {@link RendererArgs}.
*/
@Override
public void draw(Stamping stamping, Canvas canvas, RendererArgs args) {
TimeStamping s = (TimeStamping) stamping;
SymbolPool symbolPool = args.symbolPool;
float interlineSpace = s.parentStaff.is;
float linesCount = s.parentStaff.linesCount;
// write numerator digits
float offsetX = s.numeratorOffsetIs * interlineSpace;
String num = Integer.toString(s.time.element.getType().getNumerator());
for (int i = 0; i < num.length(); i++) {
int d = num.charAt(i) - '0';
Symbol symbol = symbolPool.getSymbol(CommonSymbol.getDigit(d));
if (symbol != null) {
float symbolWidth = symbol.getBoundingRect().size.width;
StaffSymbolRenderer.drawWith(symbol, null, sp(s.xMm + offsetX, linesCount + 1), 1, s.parentStaff, false, canvas, args);
offsetX += (symbolWidth + s.digitGapIs) * interlineSpace;
}
}
// write denominator digits
offsetX = s.denominatorOffsetIs * interlineSpace;
String den = Integer.toString(s.time.element.getType().getDenominator());
for (int i = 0; i < den.length(); i++) {
int d = den.charAt(i) - '0';
Symbol symbol = symbolPool.getSymbol(CommonSymbol.getDigit(d));
if (symbol != null) {
float symbolWidth = symbol.getBoundingRect().size.width;
StaffSymbolRenderer.drawWith(symbol, null, sp(s.xMm + offsetX, linesCount - 3), 1, s.parentStaff, false, canvas, args);
offsetX += (symbolWidth + s.digitGapIs) * interlineSpace;
}
}
}
use of com.xenoage.zong.symbols.SymbolPool in project Zong by Xenoage.
the class DemoScoreLayoutTry method main.
public static void main(String... args) throws Exception {
SymbolPool symbolPool = sync(new SymbolPoolReader("default"));
LayoutSettings layoutSettings = LayoutSettingsReader.read(jsePlatformUtils().openFile("data/test/layout/LayoutSettingsTest.xml"));
try {
Score score = ScoreRevolutionary.createScore();
Size2f areaSize = new Size2f(150, 10000);
Context context = new Context(score, symbolPool, layoutSettings);
Target target = Target.completeLayoutTarget(new ScoreLayoutArea(areaSize));
ScoreLayout layout = new ScoreLayouter(context, target).createLayoutWithExceptions();
System.out.println(layout.toString());
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of com.xenoage.zong.symbols.SymbolPool in project Zong by Xenoage.
the class ScoreLayouterTest method testSampleFiles.
/**
* Try to layout all official MusicXML 1.1 and 2.0 sample files.
* We can not test for the correct layout of course, but at least
* we want to have no exceptions.
*/
@Test
public void testSampleFiles() throws Exception {
SymbolPool symbolPool = sync(new SymbolPoolReader("default"));
LayoutSettings layoutSettings = LayoutSettingsReader.read(jsePlatformUtils().openFile("data/test/layout/LayoutSettingsTest.xml"));
for (String file : MusicXmlScoreFileInputTest.getSampleFiles()) {
try {
// System.out.println(file);
Score score = new MusicXmlScoreFileInput().read(jsePlatformUtils().openFile(file), file);
Size2f areaSize = new Size2f(150, 10000);
Context context = new Context(score, symbolPool, layoutSettings);
Target target = Target.completeLayoutTarget(new ScoreLayoutArea(areaSize));
ScoreLayouter layouter = new ScoreLayouter(context, target);
layouter.createLayoutWithExceptions();
} catch (Exception ex) {
ex.printStackTrace();
fail("Failed to layout file: " + file);
}
}
}
Aggregations