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);
  }
  public void draw(
      UShape ushape, double x, double y, ColorMapper mapper, UParam param, Graphics2D g2d) {
    final UEllipse shape = (UEllipse) ushape;
    g2d.setStroke(new BasicStroke((float) param.getStroke().getThickness()));
    visible.ensureVisible(x, y);
    visible.ensureVisible(x + shape.getWidth(), y + shape.getHeight());
    if (shape.getStart() == 0 && shape.getExtend() == 0) {
      final Shape ellipse = new Ellipse2D.Double(x, y, shape.getWidth(), shape.getHeight());

      // Shadow
      if (shape.getDeltaShadow() != 0) {
        drawShadow(g2d, ellipse, shape.getDeltaShadow(), dpiFactor);
      }

      final HtmlColor back = param.getBackcolor();
      if (back instanceof HtmlColorGradient) {
        final GradientPaint paint = getPaintGradient(x, y, mapper, shape, back);
        g2d.setPaint(paint);
        g2d.fill(ellipse);

        if (param.getColor() != null) {
          g2d.setColor(mapper.getMappedColor(param.getColor()));
          DriverLineG2d.manageStroke(param, g2d);
          g2d.draw(ellipse);
        }
      } else {
        if (back != null) {
          g2d.setColor(mapper.getMappedColor(param.getBackcolor()));
          DriverRectangleG2d.managePattern(param, g2d);
          g2d.fill(ellipse);
        }
        if (param.getColor() != null && param.getColor().equals(param.getBackcolor()) == false) {
          g2d.setColor(mapper.getMappedColor(param.getColor()));
          DriverLineG2d.manageStroke(param, g2d);
          g2d.draw(ellipse);
        }
      }
    } else {
      final Shape arc =
          new Arc2D.Double(
              x,
              y,
              shape.getWidth(),
              shape.getHeight(),
              round(shape.getStart()),
              round(shape.getExtend()),
              Arc2D.OPEN);
      if (param.getColor() != null) {
        g2d.setColor(mapper.getMappedColor(param.getColor()));
        g2d.draw(arc);
      }
    }
  }
  public void draw(
      UShape ushape, double x, double y, ColorMapper mapper, UParam param, Html5Drawer html) {
    final URectangle rect = (URectangle) ushape;

    double width = rect.getWidth();
    double height = rect.getHeight();

    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;
    }

    final double rx = rect.getRx();
    final double ry = rect.getRy();

    //		// Shadow
    //		if (rect.getDeltaShadow() != 0) {
    //			eps.epsRectangleShadow(x, y, width, height, rx / 2, ry / 2, rect.getDeltaShadow());
    //		}

    final HtmlColor back = param.getBackcolor();
    if (back instanceof HtmlColorGradient) {
      //			eps.setStrokeColor(mapper.getMappedColor(param.getColor()));
      //			eps.epsRectangle(x, y, width, height, rx / 2, ry / 2, (HtmlColorGradient) back, mapper);
    } else {
      final String color =
          param.getColor() == null
              ? null
              : StringUtils.getAsHtml(mapper.getMappedColor(param.getColor()));
      final String backcolor =
          param.getColor() == null
              ? null
              : StringUtils.getAsHtml(mapper.getMappedColor(param.getBackcolor()));

      html.setStrokeColor(color);
      html.setFillColor(backcolor);
      //			eps.setStrokeWidth("" + param.getStroke().getThickness(),
      // param.getStroke().getDashVisible(), param
      //					.getStroke().getDashSpace());
      html.htmlRectangle(x, y, width, height, rx / 2, ry / 2);
    }
  }
  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);
  }
Exemple #5
0
  private void drawAsText(
      UText shape, double x, double y, UParam param, EpsGraphics eps, ColorMapper mapper) {
    final FontConfiguration fontConfiguration = shape.getFontConfiguration();
    // final FontMetrics fm = g2dummy.getFontMetrics(fontConfiguration.getFont().getFont());
    // final double ypos = y - fm.getDescent() + 0.5;
    final double ypos = y - 1;

    eps.setStrokeColor(mapper.getMappedColor(fontConfiguration.getColor()));
    ((EpsGraphicsMacroAndText) eps).drawText(shape.getText(), fontConfiguration, x, ypos);
  }
Exemple #6
0
  public void draw(ColorMapper colorMapper, Graphics2D g2d) {

    g2d.setStroke(new BasicStroke(thickness));

    final double startX = Math.max(armsLenght, legsX) - headDiam / 2.0 + thickness;

    final Shape head = new Ellipse2D.Double(startX, thickness, headDiam, headDiam);
    final Rectangle2D headBound = head.getBounds2D();

    final double centerX = headBound.getCenterX();

    final Shape body =
        new Line2D.Double(centerX, headBound.getMaxY(), centerX, headBound.getMaxY() + bodyLenght);

    final Shape arms =
        new Line2D.Double(
            centerX - armsLenght,
            headBound.getMaxY() + armsY,
            centerX + armsLenght,
            headBound.getMaxY() + armsY);

    final double y = body.getBounds2D().getMaxY();

    final Shape legs1 = new Line2D.Double(centerX, y, centerX - legsX, y + legsY);
    final Shape legs2 = new Line2D.Double(centerX, y, centerX + legsX, y + legsY);

    g2d.setColor(colorMapper.getMappedColor(backgroundColor));
    g2d.fill(head);

    g2d.setColor(colorMapper.getMappedColor(foregroundColor));
    g2d.draw(head);
    g2d.draw(body);
    g2d.draw(arms);
    g2d.draw(legs1);
    g2d.draw(legs2);

    g2d.setStroke(new BasicStroke());
    throw new UnsupportedOperationException();
  }
  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());
  }
 private GradientPaint getPaintGradient(
     double x, double y, ColorMapper mapper, final UEllipse shape, final HtmlColor back) {
   final HtmlColorGradient gr = (HtmlColorGradient) back;
   final char policy = gr.getPolicy();
   final GradientPaint paint;
   if (policy == '|') {
     paint =
         new GradientPaint(
             (float) x,
             (float) (y + shape.getHeight()) / 2,
             mapper.getMappedColor(gr.getColor1()),
             (float) (x + shape.getWidth()),
             (float) (y + shape.getHeight()) / 2,
             mapper.getMappedColor(gr.getColor2()));
   } else if (policy == '\\') {
     paint =
         new GradientPaint(
             (float) x,
             (float) (y + shape.getHeight()),
             mapper.getMappedColor(gr.getColor1()),
             (float) (x + shape.getWidth()),
             (float) y,
             mapper.getMappedColor(gr.getColor2()));
   } else if (policy == '-') {
     paint =
         new GradientPaint(
             (float) (x + shape.getWidth()) / 2,
             (float) y,
             mapper.getMappedColor(gr.getColor1()),
             (float) (x + shape.getWidth()) / 2,
             (float) (y + shape.getHeight()),
             mapper.getMappedColor(gr.getColor2()));
   } else {
     // for /
     paint =
         new GradientPaint(
             (float) x,
             (float) y,
             mapper.getMappedColor(gr.getColor1()),
             (float) (x + shape.getWidth()),
             (float) (y + shape.getHeight()),
             mapper.getMappedColor(gr.getColor2()));
   }
   return paint;
 }
Exemple #9
0
  public void drawTOBEREMOVED(ColorMapper colorMapper, Graphics2D g2d, double x, double y) {
    // TO be removed
    g2d.setFont(fontConfiguration.getFont().getFont());
    g2d.setPaint(colorMapper.getMappedColor(fontConfiguration.getColor()));
    g2d.drawString(text, (float) x, (float) y);

    if (fontConfiguration.containsStyle(FontStyle.UNDERLINE)) {
      final Dimension2D dim = calculateDimension(StringBounderUtils.asStringBounder(g2d));
      final int ypos = (int) (y + 2.5);
      g2d.setStroke(new BasicStroke((float) 1.3));
      g2d.drawLine((int) x, ypos, (int) (x + dim.getWidth()), ypos);
      g2d.setStroke(new BasicStroke());
    }
    if (fontConfiguration.containsStyle(FontStyle.STRIKE)) {
      final Dimension2D dim = calculateDimension(StringBounderUtils.asStringBounder(g2d));
      final FontMetrics fm = g2d.getFontMetrics(fontConfiguration.getFont().getFont());
      final int ypos = (int) (y - fm.getDescent() - 0.5);
      g2d.setStroke(new BasicStroke((float) 1.5));
      g2d.drawLine((int) x, ypos, (int) (x + dim.getWidth()), ypos);
      g2d.setStroke(new BasicStroke());
    }
  }
Exemple #10
0
  public void draw(
      UShape ushape, double x, double y, ColorMapper mapper, UParam param, EpsGraphics eps) {

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

    final UText shape = (UText) ushape;

    if (strategy == EpsStrategy.WITH_MACRO_AND_TEXT) {
      drawAsText(shape, x, y, param, eps, mapper);
      return;
    }

    final FontConfiguration fontConfiguration = shape.getFontConfiguration();
    final UFont font = fontConfiguration.getFont();

    final TextLayout t = new TextLayout(shape.getText(), font.getFont(), fontRenderContext);
    eps.setStrokeColor(mapper.getMappedColor(fontConfiguration.getColor()));
    drawPathIterator(eps, x, y, t.getOutline(null).getPathIterator(null));

    if (fontConfiguration.containsStyle(FontStyle.UNDERLINE)) {
      final HtmlColor extended = fontConfiguration.getExtendedColor();
      if (extended != null) {
        eps.setStrokeColor(mapper.getMappedColor(extended));
      }
      final Dimension2D dim =
          DriverTextG2d.calculateDimension(stringBounder, font, shape.getText());
      eps.setStrokeWidth("1.1", 0, 0);
      eps.epsLine(x, y + 1.5, x + dim.getWidth(), y + 1.5);
      eps.setStrokeWidth("1", 0, 0);
    }
    if (fontConfiguration.containsStyle(FontStyle.WAVE)) {
      final Dimension2D dim =
          DriverTextG2d.calculateDimension(stringBounder, font, shape.getText());
      final int ypos = (int) (y + 2.5) - 1;
      final HtmlColor extended = fontConfiguration.getExtendedColor();
      if (extended != null) {
        eps.setStrokeColor(mapper.getMappedColor(extended));
      }
      eps.setStrokeWidth("1.1", 0, 0);
      for (int i = (int) x; i < x + dim.getWidth() - 5; i += 6) {
        eps.epsLine(i, ypos - 0, i + 3, ypos + 1);
        eps.epsLine(i + 3, ypos + 1, i + 6, ypos - 0);
      }
      eps.setStrokeWidth("1", 0, 0);
    }
    if (fontConfiguration.containsStyle(FontStyle.STRIKE)) {
      final HtmlColor extended = fontConfiguration.getExtendedColor();
      if (extended != null) {
        eps.setStrokeColor(mapper.getMappedColor(extended));
      }
      final Dimension2D dim =
          DriverTextG2d.calculateDimension(stringBounder, font, shape.getText());
      final FontMetrics fm = g2dummy.getFontMetrics(font.getFont());
      final int ypos = (int) (y - fm.getDescent() - 0.5);
      eps.setStrokeWidth("1.3", 0, 0);
      eps.epsLine(x, ypos, x + dim.getWidth(), ypos);
      eps.setStrokeWidth("1", 0, 0);
    }
  }