Ejemplo n.º 1
0
  public void draw(
      UShape ushape, double x, double y, ColorMapper mapper, UParam param, SvgGraphics svg) {

    final UClip clip = clipContainer.getClip();
    if (clip != null && clip.isInside(x, y) == false) {
      return;
    }

    final UText shape = (UText) ushape;
    final FontConfiguration fontConfiguration = shape.getFontConfiguration();
    final UFont font = fontConfiguration.getFont();
    String fontWeight = null;
    if (fontConfiguration.containsStyle(FontStyle.BOLD) || font.isBold()) {
      fontWeight = "bold";
    }
    String fontStyle = null;
    if (fontConfiguration.containsStyle(FontStyle.ITALIC) || font.isItalic()) {
      fontStyle = "italic";
    }
    String textDecoration = null;
    if (fontConfiguration.containsStyle(FontStyle.UNDERLINE)) {
      textDecoration = "underline";
    } else if (fontConfiguration.containsStyle(FontStyle.STRIKE)) {
      textDecoration = "line-through";
    }

    String backColor = null;
    if (fontConfiguration.containsStyle(FontStyle.BACKCOLOR)) {
      backColor =
          StringUtils.getAsHtml(mapper.getMappedColor(fontConfiguration.getExtendedColor()));
    }

    svg.setFillColor(StringUtils.getAsHtml(mapper.getMappedColor(fontConfiguration.getColor())));
    String text = shape.getText();
    if (text.startsWith(" ")) {
      final double space = stringBounder.calculateDimension(font, " ").getWidth();
      while (text.startsWith(" ")) {
        x += space;
        text = text.substring(1);
      }
    }
    text = StringUtils.trin(text);
    final Dimension2D dim = stringBounder.calculateDimension(font, text);
    svg.text(
        text,
        x,
        y,
        font.getFamily(UFontContext.SVG),
        font.getSize(),
        fontWeight,
        fontStyle,
        textDecoration,
        dim.getWidth(),
        fontConfiguration.getAttributes(),
        backColor);
  }
Ejemplo n.º 2
0
  public UGraphicSvg(
      ColorMapper mapper,
      HtmlColorGradient gr,
      boolean textAsPath,
      double scale,
      String linkTarget) {
    this(mapper, new SvgGraphics(scale), textAsPath, linkTarget);

    final SvgGraphics svg = getGraphicObject();
    svg.paintBackcolorGradient(mapper, gr);
  }
Ejemplo n.º 3
0
  public void draw(
      UShape ushape, double x, double y, ColorMapper mapper, UParam param, SvgGraphics svg) {
    final UPath shape = (UPath) ushape;

    final String color =
        param.getColor() == null
            ? "none"
            : StringUtils.getAsHtml(mapper.getMappedColor(param.getColor()));
    final String backcolor =
        param.getBackcolor() == null
            ? "none"
            : StringUtils.getAsHtml(mapper.getMappedColor(param.getBackcolor()));

    //		// Shadow
    //		if (shape.getDeltaShadow() != 0) {
    //			double lastX = 0;
    //			double lastY = 0;
    //			for (USegment seg : shape) {
    //				final USegmentType type = seg.getSegmentType();
    //				final double coord[] = seg.getCoord();
    //				if (type == USegmentType.SEG_MOVETO) {
    //					lastX = x + coord[0];
    //					lastY = y + coord[1];
    //				} else if (type == USegmentType.SEG_LINETO) {
    //					svg.svgLineShadow(lastX, lastY, x + coord[0], y + coord[1], shape.getDeltaShadow());
    //					lastX = x + coord[0];
    //					lastY = y + coord[1];
    //				} else {
    //					throw new UnsupportedOperationException();
    //				}
    //			}
    //		}

    svg.setFillColor(backcolor);
    svg.setStrokeColor(color);
    svg.setStrokeWidth("" + param.getStroke().getThickness(), param.getStroke().getDasharraySvg());

    svg.svgPath(x, y, shape, shape.getDeltaShadow());
  }
Ejemplo n.º 4
0
  public void draw(
      UShape ushape, double x, double y, ColorMapper mapper, UParam param, SvgGraphics svg) {
    final URectangle rect = (URectangle) ushape;

    final double rx = rect.getRx();
    final double ry = rect.getRy();
    double width = rect.getWidth();
    double height = rect.getHeight();

    final UGradient gr = param.getGradient();
    if (gr == null) {
      final String color =
          param.getColor() == null
              ? "none"
              : StringUtils.getAsHtml(mapper.getMappedColor(param.getColor()));
      final String backcolor =
          param.getBackcolor() == null
              ? "none"
              : StringUtils.getAsHtml(mapper.getMappedColor(param.getBackcolor()));
      svg.setFillColor(backcolor);
      svg.setStrokeColor(color);
    } else {
      final String id =
          svg.createSvgGradient(
              StringUtils.getAsHtml(mapper.getMappedColor(gr.getColor1())),
              StringUtils.getAsHtml(mapper.getMappedColor(gr.getColor2())));
      svg.setFillColor("url(#" + id + ")");
      svg.setStrokeColor(null);
    }

    svg.setStrokeWidth("" + param.getStroke().getThickness(), param.getStroke().getDasharraySvg());

    final UClip clip = clipContainer.getClip();
    if (clip != null) {
      final Rectangle2D.Double r =
          clip.getClippedRectangle(new Rectangle2D.Double(x, y, width, height));
      x = r.x;
      y = r.y;
      width = r.width;
      height = r.height;
    }

    svg.svgRectangle(x, y, width, height, rx / 2, ry / 2);
  }