Example #1
0
 private void drawText(double x, double y, UText text) {
   final Dimension2D dim =
       stringBounder.calculateDimension(text.getFontConfiguration().getFont(), text.getText());
   y -= dim.getHeight() - 1.5;
   addPoint(x, y);
   addPoint(x, y + dim.getHeight());
   addPoint(x + dim.getWidth(), y);
   addPoint(x + dim.getWidth(), y + dim.getHeight());
 }
  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);
  }
Example #3
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);
  }
Example #4
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);
    }
  }