Esempio n. 1
0
  /**
   * Draws the text block, aligning it with the specified anchor point and rotating it about the
   * specified rotation point.
   *
   * @param g2 the graphics device.
   * @param anchorX the x-coordinate for the anchor point.
   * @param anchorY the y-coordinate for the anchor point.
   * @param anchor the point on the text block that is aligned to the anchor point.
   * @param rotateX the x-coordinate for the rotation point.
   * @param rotateY the x-coordinate for the rotation point.
   * @param angle the rotation (in radians).
   */
  public void draw(
      final Graphics2D g2,
      final float anchorX,
      final float anchorY,
      final TextBlockAnchor anchor,
      final float rotateX,
      final float rotateY,
      final double angle) {

    final Size2D d = calculateDimensions(g2);
    final float[] offsets = calculateOffsets(anchor, d.getWidth(), d.getHeight());
    final Iterator iterator = this.lines.iterator();
    float yCursor = 0.0f;
    while (iterator.hasNext()) {
      TextLine line = (TextLine) iterator.next();
      Size2D dimension = line.calculateDimensions(g2);
      float lineOffset = 0.0f;
      if (this.lineAlignment == HorizontalAlignment.CENTER) {
        lineOffset = (float) (d.getWidth() - dimension.getWidth()) / 2.0f;
      } else if (this.lineAlignment == HorizontalAlignment.RIGHT) {
        lineOffset = (float) (d.getWidth() - dimension.getWidth());
      }
      line.draw(
          g2,
          anchorX + offsets[0] + lineOffset,
          anchorY + offsets[1] + yCursor,
          TextAnchor.TOP_LEFT,
          rotateX,
          rotateY,
          angle);
      yCursor = yCursor + (float) dimension.getHeight();
    }
  }
Esempio n. 2
0
 /**
  * Returns the width and height of the text block.
  *
  * @param g2 the graphics device.
  * @return The width and height.
  */
 public Size2D calculateDimensions(final Graphics2D g2) {
   double width = 0.0;
   double height = 0.0;
   final Iterator iterator = this.lines.iterator();
   while (iterator.hasNext()) {
     final TextLine line = (TextLine) iterator.next();
     final Size2D dimension = line.calculateDimensions(g2);
     width = Math.max(width, dimension.getWidth());
     height = height + dimension.getHeight();
   }
   return new Size2D(width, height);
 }