Exemple #1
0
  /**
   * Adds an image to this Cell.
   *
   * @param i the image to add
   * @param left the left border
   * @param right the right border
   * @param extraHeight extra height to add above image
   * @param alignment horizontal alignment (constant from Element class)
   * @return the height of the image
   */
  private float addImage(Image i, float left, float right, float extraHeight, int alignment) {
    Image image = Image.getInstance(i);
    if (image.scaledWidth() > right - left) {
      image.scaleToFit(right - left, Float.MAX_VALUE);
    }
    flushCurrentLine();
    if (line == null) {
      line = new PdfLine(left, right, alignment, leading);
    }
    PdfLine imageLine = line;

    // left and right in chunk is relative to the start of the line
    right = right - left;
    left = 0f;

    if ((image.alignment() & Image.RIGHT) == Image.RIGHT) {
      left = right - image.scaledWidth();
    } else if ((image.alignment() & Image.MIDDLE) == Image.MIDDLE) {
      left = left + ((right - left - image.scaledWidth()) / 2f);
    }
    Chunk imageChunk = new Chunk(image, left, 0);
    imageLine.add(new PdfChunk(imageChunk, null));
    addLine(imageLine);
    return imageLine.height();
  }
Exemple #2
0
 float width(String s) {
   if (image == null) return font.getWidthPoint(s, size) * hScale;
   else return image.scaledWidth();
 }
Exemple #3
0
 /**
  * Returns the width of a certain character of this font.
  *
  * @param character a certain character
  * @return a width in Text Space
  */
 float width(char character) {
   if (image == null) return font.getWidthPoint(character, size) * hScale;
   else return image.scaledWidth();
 }