Examples of SVGLengthParser


Examples of net.sf.latexdraw.parsers.svg.parsers.SVGLengthParser

   */
  public double getX2() {
    final String v = getAttribute(getUsablePrefix()+SVGAttributes.SVG_X2);
    double x2;

    try { x2 = v==null ? 0 : new SVGLengthParser(v).parseCoordinate().getValue(); }
    catch(final ParseException e) { x2 = 0; }

    return x2;
  }
View Full Code Here

Examples of net.sf.latexdraw.parsers.svg.parsers.SVGLengthParser

   */
  public double getY2() {
    final String v = getAttribute(getUsablePrefix()+SVGAttributes.SVG_Y2);
    double y2;

    try { y2 = v==null ? 0 : new SVGLengthParser(v).parseCoordinate().getValue(); }
    catch(final ParseException e) { y2 = 0; }

    return y2;
  }
View Full Code Here

Examples of net.sf.latexdraw.parsers.svg.parsers.SVGLengthParser

   */
  public double getX() {
    final String v = getAttribute(getUsablePrefix()+SVGAttributes.SVG_X);
    double x;

    try { x = v==null ? 0 : new SVGLengthParser(v).parseCoordinate().getValue(); }
    catch(final ParseException e) { x = 0; }

    return x;
  }
View Full Code Here

Examples of net.sf.latexdraw.parsers.svg.parsers.SVGLengthParser

   */
  public double getY() {
    final String v = getAttribute(getUsablePrefix()+SVGAttributes.SVG_Y);
    double y;

    try { y = v==null ? 0 : new SVGLengthParser(v).parseCoordinate().getValue(); }
    catch(final ParseException e) { y = 0; }

    return y;
  }
View Full Code Here

Examples of net.sf.latexdraw.parsers.svg.parsers.SVGLengthParser

   */
  public double getDX() {
    final String v = getAttribute(getUsablePrefix()+SVGAttributes.SVG_DX);
    double dx;

    try { dx = v==null ? 0 : new SVGLengthParser(v).parseLength().getValue(); }
    catch(final ParseException e) { dx = 0; }

    return dx;
  }
View Full Code Here

Examples of net.sf.latexdraw.parsers.svg.parsers.SVGLengthParser

   */
  public double getDY() {
    final String v = getAttribute(getUsablePrefix()+SVGAttributes.SVG_DY);
    double dy;

    try { dy = v==null ? 0 : new SVGLengthParser(v).parseLength().getValue(); }
    catch(final ParseException e) { dy = 0; }

    return dy;
  }
View Full Code Here

Examples of net.sf.latexdraw.parsers.svg.parsers.SVGLengthParser

public class TestSVGLengthParser {
  @SuppressWarnings("unused")
  @Test
  public void testParseLength() throws ParseException {
    SVGLengthParser p;
    SVGLength l;

    try {
      new SVGLengthParser(null);
      fail();
    }
    catch(IllegalArgumentException e){ /* */ }

    try {
      p = new SVGLengthParser(""); //$NON-NLS-1$
      l = p.parseLength();
      fail();
    }
    catch(ParseException e){ /* */ }

    try {
      p = new SVGLengthParser("1m"); //$NON-NLS-1$
      l = p.parseLength();
      fail();
    }
    catch(ParseException e){ /* */ }

    try {
      p = new SVGLengthParser("m"); //$NON-NLS-1$
      l = p.parseLength();
      fail();
    }
    catch(ParseException e){ /* */ }

    try {
      p = new SVGLengthParser("1p"); //$NON-NLS-1$
      l = p.parseLength();
      fail();
    }
    catch(ParseException e){ /* */ }

    try {
      p = new SVGLengthParser("1e1i"); //$NON-NLS-1$
      l = p.parseLength();
      fail();
    }
    catch(ParseException e){ /* */ }

    try {
      p = new SVGLengthParser("1ci"); //$NON-NLS-1$
      l = p.parseLength();
      fail();
    }
    catch(ParseException e){ /* */ }

    try {
      p = new SVGLengthParser("1 c "); //$NON-NLS-1$
      l = p.parseLength();
      fail();
    }
    catch(ParseException e){ /* */ }

    p = new SVGLengthParser("1mm"); //$NON-NLS-1$
    l = p.parseLength();

    assertEquals(l.getValueAsString(), "1"); //$NON-NLS-1$
    assertEquals(l.getLengthType(), SVGLength.LengthType.PX);
    assertEquals(UnitProcessor.INSTANCE.toUserUnit(1, SVGLength.LengthType.MM), l.getValue(), 0.001);

    p = new SVGLengthParser("0.65 cm"); //$NON-NLS-1$
    l = p.parseLength();

    assertEquals(l.getValueAsString(), "0.65"); //$NON-NLS-1$
    assertEquals(l.getLengthType(), SVGLength.LengthType.PX);
    assertEquals(UnitProcessor.INSTANCE.toUserUnit(0.65, SVGLength.LengthType.CM), l.getValue(), 0.001);

    p = new SVGLengthParser("\t -10.65  \t \n pc"); //$NON-NLS-1$
    l = p.parseLength();

    assertEquals(l.getValueAsString(), "-10.65"); //$NON-NLS-1$
    assertEquals(l.getLengthType(), SVGLength.LengthType.PX);
    assertEquals(UnitProcessor.INSTANCE.toUserUnit(-10.65, SVGLength.LengthType.PC), l.getValue(), 0.001);

    p = new SVGLengthParser("\t -10.65e2  \t \n px \t   "); //$NON-NLS-1$
    l = p.parseLength();

    assertEquals(l.getValueAsString(), "-10.65e2"); //$NON-NLS-1$
    assertEquals(l.getLengthType(), SVGLength.LengthType.PX);
    assertEquals(UnitProcessor.INSTANCE.toUserUnit(-10.65e2, SVGLength.LengthType.PX), l.getValue(), 0.001);

    p = new SVGLengthParser("\t -10.65e0pt \t   "); //$NON-NLS-1$
    l = p.parseLength();

    assertEquals(l.getValueAsString(), "-10.65e0"); //$NON-NLS-1$
    assertEquals(l.getLengthType(), SVGLength.LengthType.PX);
    assertEquals(UnitProcessor.INSTANCE.toUserUnit(-10.65e0, SVGLength.LengthType.PT), l.getValue(), 0.001);

    p = new SVGLengthParser("\t -1.in \t   "); //$NON-NLS-1$
    l = p.parseLength();

    assertEquals(l.getValueAsString(), "-1."); //$NON-NLS-1$
    assertEquals(l.getLengthType(), SVGLength.LengthType.PX);
    assertEquals(UnitProcessor.INSTANCE.toUserUnit(-1., SVGLength.LengthType.IN), l.getValue(), 0.001);

    p = new SVGLengthParser("-1."); //$NON-NLS-1$
    l = p.parseLength();

    assertEquals(l.getValueAsString(), "-1."); //$NON-NLS-1$
    assertEquals(l.getLengthType(), SVGLength.LengthType.PX);
    assertEquals(UnitProcessor.INSTANCE.toUserUnit(-1., SVGLength.LengthType.NUMBER), l.getValue(), 0.001);
  }
View Full Code Here

Examples of net.sf.latexdraw.parsers.svg.parsers.SVGLengthParser



  @Test
  public void testParseNumberOrPercent() throws ParseException {
    SVGLengthParser p;
    SVGLength l;

    p = new SVGLengthParser("1mm"); //$NON-NLS-1$
    l = p.parseNumberOrPercent();

    assertEquals(l.getValueAsString(), "1"); //$NON-NLS-1$
    assertEquals(l.getLengthType(), SVGLength.LengthType.NUMBER);
    assertEquals(UnitProcessor.INSTANCE.toUserUnit(1, SVGLength.LengthType.NUMBER), l.getValue(), 0.001);

    p = new SVGLengthParser("0.876"); //$NON-NLS-1$
    l = p.parseNumberOrPercent();

    assertEquals(l.getValueAsString(), "0.876"); //$NON-NLS-1$
    assertEquals(l.getLengthType(), SVGLength.LengthType.NUMBER);
    assertEquals(UnitProcessor.INSTANCE.toUserUnit(0.876, SVGLength.LengthType.NUMBER), l.getValue(), 0.001);
  }
View Full Code Here

Examples of net.sf.latexdraw.parsers.svg.parsers.SVGLengthParser



  @Test
  public void testParseCoordinate() throws ParseException {
    SVGLengthParser p;
    SVGLength l;

    try {
      p = new SVGLengthParser(""); //$NON-NLS-1$
      l = p.parseCoordinate();
      fail();
    }
    catch(ParseException e){ /* */ }

    try {
      p = new SVGLengthParser("1m"); //$NON-NLS-1$
      l = p.parseCoordinate();
      fail();
    }
    catch(ParseException e){ /* */ }

    try {
      p = new SVGLengthParser("m"); //$NON-NLS-1$
      l = p.parseCoordinate();
      fail();
    }
    catch(ParseException e){ /* */ }

    try {
      p = new SVGLengthParser("1p"); //$NON-NLS-1$
      l = p.parseCoordinate();
      fail();
    }
    catch(ParseException e){ /* */ }

    try {
      p = new SVGLengthParser("1e1i"); //$NON-NLS-1$
      l = p.parseCoordinate();
      fail();
    }
    catch(ParseException e){ /* */ }

    try {
      p = new SVGLengthParser("1ci"); //$NON-NLS-1$
      l = p.parseCoordinate();
      fail();
    }
    catch(ParseException e){ /* */ }

    try {
      p = new SVGLengthParser("1 c "); //$NON-NLS-1$
      l = p.parseCoordinate();
      fail();
    }
    catch(ParseException e){ /* */ }

    p = new SVGLengthParser("1mm"); //$NON-NLS-1$
    l = p.parseCoordinate();

    assertEquals(l.getValueAsString(), "1"); //$NON-NLS-1$
    assertEquals(l.getLengthType(), SVGLength.LengthType.PX);
    assertEquals(UnitProcessor.INSTANCE.toUserUnit(1, SVGLength.LengthType.MM), l.getValue(), 0.001);

    p = new SVGLengthParser("0.65 cm"); //$NON-NLS-1$
    l = p.parseCoordinate();

    assertEquals(l.getValueAsString(), "0.65"); //$NON-NLS-1$
    assertEquals(l.getLengthType(), SVGLength.LengthType.PX);
    assertEquals(UnitProcessor.INSTANCE.toUserUnit(0.65, SVGLength.LengthType.CM), l.getValue(), 0.001);

    p = new SVGLengthParser("\t -10.65  \t \n pc"); //$NON-NLS-1$
    l = p.parseCoordinate();

    assertEquals(l.getValueAsString(), "-10.65"); //$NON-NLS-1$
    assertEquals(l.getLengthType(), SVGLength.LengthType.PX);
    assertEquals(UnitProcessor.INSTANCE.toUserUnit(-10.65, SVGLength.LengthType.PC), l.getValue(), 0.001);

    p = new SVGLengthParser("\t -10.65e2  \t \n px \t   "); //$NON-NLS-1$
    l = p.parseCoordinate();

    assertEquals(l.getValueAsString(), "-10.65e2"); //$NON-NLS-1$
    assertEquals(l.getLengthType(), SVGLength.LengthType.PX);
    assertEquals(UnitProcessor.INSTANCE.toUserUnit(-10.65e2, SVGLength.LengthType.PX), l.getValue(), 0.001);

    p = new SVGLengthParser("\t -10.65e0pt \t   "); //$NON-NLS-1$
    l = p.parseCoordinate();

    assertEquals(l.getValueAsString(), "-10.65e0"); //$NON-NLS-1$
    assertEquals(l.getLengthType(), SVGLength.LengthType.PX);
    assertEquals(UnitProcessor.INSTANCE.toUserUnit(-10.65e0, SVGLength.LengthType.PT), l.getValue(), 0.001);

    p = new SVGLengthParser("\t -1.in \t   "); //$NON-NLS-1$
    l = p.parseCoordinate();

    assertEquals(l.getValueAsString(), "-1."); //$NON-NLS-1$
    assertEquals(l.getLengthType(), SVGLength.LengthType.PX);
    assertEquals(UnitProcessor.INSTANCE.toUserUnit(-1., SVGLength.LengthType.IN), l.getValue(), 0.001);

    p = new SVGLengthParser("-1."); //$NON-NLS-1$
    l = p.parseCoordinate();

    assertEquals(l.getValueAsString(), "-1."); //$NON-NLS-1$
    assertEquals(l.getLengthType(), SVGLength.LengthType.PX);
    assertEquals(UnitProcessor.INSTANCE.toUserUnit(-1., SVGLength.LengthType.NUMBER), l.getValue(), 0.001);
  }
View Full Code Here

Examples of net.sf.latexdraw.parsers.svg.parsers.SVGLengthParser

    final String swStr = getSVGAttribute(SVGAttributes.SVG_STROKE_WIDTH, getUsablePrefix());
    double sw;

    try {
      sw = swStr==null ? parent==null ? 1 : parent.getStrokeWidth() :
        new SVGLengthParser(swStr).parseLength().getValue();
    } catch(final ParseException e){ sw = 1; }

    return sw;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.