コード例 #1
0
ファイル: SVGTextFigure.java プロジェクト: DevBoost/Reuseware
  private Shape getTextShape() {
    if (cachedTextShape == null) {
      String text = getText();
      if (text == null || text.length() == 0) {
        text = " ";
      }

      FontRenderContext frc = getFontRenderContext();
      HashMap<TextAttribute, Object> textAttributes = new HashMap<TextAttribute, Object>();
      textAttributes.put(TextAttribute.FONT, getFont());
      if (FONT_UNDERLINE.get(this)) {
        textAttributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
      }
      TextLayout textLayout = new TextLayout(text, textAttributes, frc);

      AffineTransform tx = new AffineTransform();
      tx.translate(coordinates[0].x, coordinates[0].y);
      switch (TEXT_ANCHOR.get(this)) {
        case END:
          tx.translate(-textLayout.getAdvance(), 0);
          break;
        case MIDDLE:
          tx.translate(-textLayout.getAdvance() / 2d, 0);
          break;
        case START:
          break;
      }
      tx.rotate(rotates[0]);

      /*
      if (TRANSFORM.get(this) != null) {
          tx.preConcatenate(TRANSFORM.get(this));
      }*/

      cachedTextShape = tx.createTransformedShape(textLayout.getOutline(tx));
      cachedTextShape = textLayout.getOutline(tx);
    }
    return cachedTextShape;
  }
コード例 #2
0
 /**
  * All other write methods delegate their work to here.
  */
 public void write(OutputStream out, java.util.List<Figure> figures) throws IOException {
     Rectangle2D.Double drawingRect = null;
     
     for (Figure f : figures) {
         if (drawingRect == null) {
             drawingRect = f.getBounds();
         } else {
             drawingRect.add(f.getBounds());
         }
     }
     
     AffineTransform drawingTransform = new AffineTransform();
     drawingTransform.translate(
             -Math.min(0, drawingRect.x),
             -Math.min(0, drawingRect.y)
             );
     
     write(out, figures, drawingTransform,
             new Dimension(
             (int) (Math.abs(drawingRect.x) + drawingRect.width),
             (int) (Math.abs(drawingRect.y) + drawingRect.height))
             );
 }