Beispiel #1
0
  public void drawString(String str, int x, int y) {
    if (str == null || str.equals("")) return;

    Font excelFont = font;
    if (font.getName().equals("SansSerif")) {
      excelFont =
          new Font("Arial", font.getStyle(), (int) (font.getSize() / verticalPixelsPerPoint));
    } else {
      excelFont =
          new Font(
              font.getName(), font.getStyle(), (int) (font.getSize() / verticalPixelsPerPoint));
    }
    FontDetails d = StaticFontMetrics.getFontDetails(excelFont);
    int width = (int) ((d.getStringWidth(str) * 8) + 12);
    int height = (int) ((font.getSize() / verticalPixelsPerPoint) + 6) * 2;
    y -=
        (font.getSize() / verticalPixelsPerPoint)
            + 2 * verticalPixelsPerPoint; // we want to draw the shape from the top-left
    HSSFTextbox textbox =
        escherGroup.createTextbox(new HSSFChildAnchor(x, y, x + width, y + height));
    textbox.setNoFill(true);
    textbox.setLineStyle(HSSFShape.LINESTYLE_NONE);
    HSSFRichTextString s = new HSSFRichTextString(str);
    HSSFFont hssfFont = matchFont(excelFont);
    s.applyFont(hssfFont);
    textbox.setString(s);
  }