Search in sources :

Example 1 with Path

use of com.xenoage.zong.symbols.path.Path in project Zong by Xenoage.

the class SvgPathSymbolReader method read.

/**
 * Creates a {@link PathSymbol} from the given SVG document.
 * If an error occurs, an IllegalArgumentException is thrown.
 * @param id         the ID of the symbol
 * @param xmlReader  the {@link XmlReader}, positioned at the root element. It will
 *                   not be closed by this this method.
 */
public static PathSymbol read(String id, XmlReader xmlReader) {
    // read baseline and ascent, if there
    Float baseline = null;
    Float ascent = null;
    String attr = xmlReader.getAttribute("zong-baseline");
    if (attr != null)
        baseline = Parser.parseFloat(attr) * 0.01f - 10;
    attr = xmlReader.getAttribute("zong-ascent");
    if (attr != null)
        ascent = Parser.parseFloat(attr) * 0.01f;
    // custom left and right border, if there
    Float leftBorder = null;
    Float rightBorder = null;
    attr = xmlReader.getAttribute("zong-leftborder");
    if (attr != null)
        leftBorder = Parser.parseFloat(attr) * 0.01f - 10;
    attr = xmlReader.getAttribute("zong-rightborder");
    if (attr != null)
        rightBorder = Parser.parseFloat(attr) * 0.01f - 10;
    // search for a path
    String d = findPath(xmlReader);
    // otherwise throw exception.
    if (d != null) {
        Path path = new SvgPathReader(d).read();
        PathSymbol ret = new PathSymbol(id, path, baseline, ascent, leftBorder, rightBorder);
        return ret;
    } else {
        throw new IllegalArgumentException("No path element was found!");
    }
}
Also used : Path(com.xenoage.zong.symbols.path.Path) PathSymbol(com.xenoage.zong.symbols.PathSymbol)

Example 2 with Path

use of com.xenoage.zong.symbols.path.Path in project Zong by Xenoage.

the class SimpleSlurShape method createPath.

private Path createPath() {
    List<PathElement> elements = alist(5);
    float cap = interlineSpace / 4;
    elements.add(new MoveTo(p1top));
    // bezier curve from p1top to p2top
    elements.add(new CubicCurveTo(c1top, c2top, p2top));
    // cap at p2
    Point2f capDir = p2top.sub(c2top).normalize().scale(cap);
    elements.add(new CubicCurveTo(p2top.add(capDir), p2bottom.add(capDir), p2bottom));
    // bezier curve back from p2bottom to p1bottom
    elements.add(new CubicCurveTo(c2bottom, c1bottom, p1bottom));
    // cap at p1
    capDir = p1top.sub(c1top).normalize().scale(cap);
    elements.add(new CubicCurveTo(p1bottom.add(capDir), p1top.add(capDir), p1top));
    Path path = new Path(elements);
    return path;
}
Also used : Path(com.xenoage.zong.symbols.path.Path) Point2f(com.xenoage.utils.math.geom.Point2f) PathElement(com.xenoage.zong.symbols.path.PathElement) MoveTo(com.xenoage.zong.symbols.path.MoveTo) CubicCurveTo(com.xenoage.zong.symbols.path.CubicCurveTo)

Example 3 with Path

use of com.xenoage.zong.symbols.path.Path in project Zong by Xenoage.

the class SvgPathReaderTest method testImplicitLineToAbs.

@Test
public void testImplicitLineToAbs() {
    String validPath = "M1200,1300 1400,1050 1600,1300 1800,1550 2000,1300z";
    Path p = new SvgPathReader(validPath).read();
    assertEquals(alist(new MoveTo(p(2, 3)), new LineTo(p(4, 0.5f)), new LineTo(p(6, 3)), new LineTo(p(8, 5.5f)), new LineTo(p(10, 3)), new ClosePath()), p.getElements());
}
Also used : ClosePath(com.xenoage.zong.symbols.path.ClosePath) Path(com.xenoage.zong.symbols.path.Path) ClosePath(com.xenoage.zong.symbols.path.ClosePath) MoveTo(com.xenoage.zong.symbols.path.MoveTo) LineTo(com.xenoage.zong.symbols.path.LineTo) Test(org.junit.Test)

Example 4 with Path

use of com.xenoage.zong.symbols.path.Path in project Zong by Xenoage.

the class SvgPathReaderTest method test2.

@Test
public void test2() {
    String validPath = "M1200,1300 L1400,1050 L1600,1300 1800,1550 M2000,1300z";
    Path p = new SvgPathReader(validPath).read();
    assertEquals(alist(new MoveTo(p(2, 3)), new LineTo(p(4, 0.5f)), new LineTo(p(6, 3)), new LineTo(p(8, 5.5f)), new MoveTo(p(10, 3)), new ClosePath()), p.getElements());
}
Also used : ClosePath(com.xenoage.zong.symbols.path.ClosePath) Path(com.xenoage.zong.symbols.path.Path) ClosePath(com.xenoage.zong.symbols.path.ClosePath) MoveTo(com.xenoage.zong.symbols.path.MoveTo) LineTo(com.xenoage.zong.symbols.path.LineTo) Test(org.junit.Test)

Example 5 with Path

use of com.xenoage.zong.symbols.path.Path in project Zong by Xenoage.

the class SvgPathReaderTest method test1.

@Test
public void test1() {
    String validPath = "M 1100 1100 L 1300 1100 L 1200 1300 z";
    Path p = new SvgPathReader(validPath).read();
    assertEquals(alist(new MoveTo(p(1, 1)), new LineTo(p(3, 1)), new LineTo(p(2, 3)), new ClosePath()), p.getElements());
}
Also used : ClosePath(com.xenoage.zong.symbols.path.ClosePath) Path(com.xenoage.zong.symbols.path.Path) ClosePath(com.xenoage.zong.symbols.path.ClosePath) MoveTo(com.xenoage.zong.symbols.path.MoveTo) LineTo(com.xenoage.zong.symbols.path.LineTo) Test(org.junit.Test)

Aggregations

Path (com.xenoage.zong.symbols.path.Path)7 ClosePath (com.xenoage.zong.symbols.path.ClosePath)5 MoveTo (com.xenoage.zong.symbols.path.MoveTo)5 LineTo (com.xenoage.zong.symbols.path.LineTo)4 Test (org.junit.Test)4 Point2f (com.xenoage.utils.math.geom.Point2f)2 PathSymbol (com.xenoage.zong.symbols.PathSymbol)1 CubicCurveTo (com.xenoage.zong.symbols.path.CubicCurveTo)1 PathElement (com.xenoage.zong.symbols.path.PathElement)1