Java Code Examples for com.lowagie.text.Image#hasAbsoluteY()

The following examples show how to use com.lowagie.text.Image#hasAbsoluteY() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PdfContentByte.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Adds an <CODE>Image</CODE> to the page. The <CODE>Image</CODE> must have absolute
 * positioning. The image can be placed inline.
 * 
 * @param image the <CODE>Image</CODE> object
 * @param inlineImage <CODE>true</CODE> to place this image inline, <CODE>false</CODE> otherwise
 * @throws DocumentException if the <CODE>Image</CODE> does not have absolute positioning
 */
public void addImage(Image image, boolean inlineImage) throws DocumentException {
	if (!image.hasAbsoluteY()) {
		throw new DocumentException("The image must have absolute positioning.");
	}
	float matrix[] = image.matrix();
	matrix[Image.CX] = image.getAbsoluteX() - matrix[Image.CX];
	matrix[Image.CY] = image.getAbsoluteY() - matrix[Image.CY];
	addImage(image, matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5], inlineImage);
}
 
Example 2
Source File: PdfContentByte.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Adds an <CODE>Image</CODE> to the page. The <CODE>Image</CODE> must have
 * absolute positioning. The image can be placed inline.
 * @param image the <CODE>Image</CODE> object
 * @param inlineImage <CODE>true</CODE> to place this image inline, <CODE>false</CODE> otherwise
 * @throws DocumentException if the <CODE>Image</CODE> does not have absolute positioning
 */
public void addImage(Image image, boolean inlineImage) throws DocumentException {
    if (!image.hasAbsoluteY())
        throw new DocumentException("The image must have absolute positioning.");
    float matrix[] = image.matrix();
    matrix[Image.CX] = image.getAbsoluteX() - matrix[Image.CX];
    matrix[Image.CY] = image.getAbsoluteY() - matrix[Image.CY];
    addImage(image, matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5], inlineImage);
}
 
Example 3
Source File: PdfDocument.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
/**
 * Adds an image to the document.
 *
 * @param image the <CODE>Image</CODE> to add
 * @throws PdfException on error
 * @throws DocumentException on error
 */

protected void add(Image image) throws PdfException, DocumentException {

	if (image.hasAbsoluteY()) {
		graphics.addImage(image);
		pageEmpty = false;
		return;
	}

	// if there isn't enough room for the image on this page, save it for the next page
	if (currentHeight != 0 && indentTop() - currentHeight - image.getScaledHeight() < indentBottom()) {
		if (!strictImageSequence && imageWait == null) {
			imageWait = image;
			return;
		}
		newPage();
		if (currentHeight != 0 && indentTop() - currentHeight - image.getScaledHeight() < indentBottom()) {
			imageWait = image;
			return;
		}
	}
	pageEmpty = false;
	// avoid endless loops
	if (image == imageWait) {
		imageWait = null;
	}
	boolean textwrap = (image.getAlignment() & Image.TEXTWRAP) == Image.TEXTWRAP && !((image.getAlignment() & Image.MIDDLE) == Image.MIDDLE);
	boolean underlying = (image.getAlignment() & Image.UNDERLYING) == Image.UNDERLYING;
	float diff = leading / 2;
	if (textwrap) {
		diff += leading;
	}
	float lowerleft = indentTop() - currentHeight - image.getScaledHeight() - diff;
	float mt[] = image.matrix();
	float startPosition = indentLeft() - mt[4];
	if ((image.getAlignment() & Image.RIGHT) == Image.RIGHT) {
		startPosition = indentRight() - image.getScaledWidth() - mt[4];
	}
	if ((image.getAlignment() & Image.MIDDLE) == Image.MIDDLE) {
		startPosition = indentLeft() + (indentRight() - indentLeft() - image.getScaledWidth()) / 2 - mt[4];
	}
	if (image.hasAbsoluteX()) {
		startPosition = image.getAbsoluteX();
	}
	if (textwrap) {
		if (imageEnd < 0 || imageEnd < currentHeight + image.getScaledHeight() + diff) {
			imageEnd = currentHeight + image.getScaledHeight() + diff;
		}
		if ((image.getAlignment() & Image.RIGHT) == Image.RIGHT) {
			// indentation suggested by Pelikan Stephan
			indentation.imageIndentRight += image.getScaledWidth() + image.getIndentationLeft();
		} else {
			// indentation suggested by Pelikan Stephan
			indentation.imageIndentLeft += image.getScaledWidth() + image.getIndentationRight();
		}
	} else {
		if ((image.getAlignment() & Image.RIGHT) == Image.RIGHT) {
			startPosition -= image.getIndentationRight();
		} else if ((image.getAlignment() & Image.MIDDLE) == Image.MIDDLE) {
			startPosition += image.getIndentationLeft() - image.getIndentationRight();
		} else {
			startPosition += image.getIndentationLeft();
		}
	}
	graphics.addImage(image, mt[0], mt[1], mt[2], mt[3], startPosition, lowerleft - mt[5]);
	if (!(textwrap || underlying)) {
		currentHeight += image.getScaledHeight() + diff;
		flushLines();
		text.moveText(0, -(image.getScaledHeight() + diff));
		newLine();
	}
}
 
Example 4
Source File: PdfDocument.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Adds an image to the document.
 * @param image the <CODE>Image</CODE> to add
 * @throws PdfException on error
 * @throws DocumentException on error
 */

protected void add(Image image) throws PdfException, DocumentException {

    if (image.hasAbsoluteY()) {
        graphics.addImage(image);
        pageEmpty = false;
        return;
    }

    // if there isn't enough room for the image on this page, save it for the next page
    if (currentHeight != 0 && indentTop() - currentHeight - image.getScaledHeight() < indentBottom()) {
        if (!strictImageSequence && imageWait == null) {
            imageWait = image;
            return;
        }
        newPage();
        if (currentHeight != 0 && indentTop() - currentHeight - image.getScaledHeight() < indentBottom()) {
            imageWait = image;
            return;
        }
    }
    pageEmpty = false;
    // avoid endless loops
    if (image == imageWait)
        imageWait = null;
    boolean textwrap = (image.getAlignment() & Image.TEXTWRAP) == Image.TEXTWRAP
    && !((image.getAlignment() & Image.MIDDLE) == Image.MIDDLE);
    boolean underlying = (image.getAlignment() & Image.UNDERLYING) == Image.UNDERLYING;
    float diff = leading / 2;
    if (textwrap) {
        diff += leading;
    }
    float lowerleft = indentTop() - currentHeight - image.getScaledHeight() -diff;
    float mt[] = image.matrix();
    float startPosition = indentLeft() - mt[4];
    if ((image.getAlignment() & Image.RIGHT) == Image.RIGHT) startPosition = indentRight() - image.getScaledWidth() - mt[4];
    if ((image.getAlignment() & Image.MIDDLE) == Image.MIDDLE) startPosition = indentLeft() + ((indentRight() - indentLeft() - image.getScaledWidth()) / 2) - mt[4];
    if (image.hasAbsoluteX()) startPosition = image.getAbsoluteX();
    if (textwrap) {
        if (imageEnd < 0 || imageEnd < currentHeight + image.getScaledHeight() + diff) {
            imageEnd = currentHeight + image.getScaledHeight() + diff;
        }
        if ((image.getAlignment() & Image.RIGHT) == Image.RIGHT) {
        	// indentation suggested by Pelikan Stephan
        	indentation.imageIndentRight += image.getScaledWidth() + image.getIndentationLeft();
        }
        else {
        	// indentation suggested by Pelikan Stephan
        	indentation.imageIndentLeft += image.getScaledWidth() + image.getIndentationRight();
        }
    }
    else {
    	if ((image.getAlignment() & Image.RIGHT) == Image.RIGHT) startPosition -= image.getIndentationRight();
    	else if ((image.getAlignment() & Image.MIDDLE) == Image.MIDDLE) startPosition += image.getIndentationLeft() - image.getIndentationRight();
    	else startPosition += image.getIndentationLeft();
    }
    graphics.addImage(image, mt[0], mt[1], mt[2], mt[3], startPosition, lowerleft - mt[5]);
    if (!(textwrap || underlying)) {
        currentHeight += image.getScaledHeight() + diff;
        flushLines();
        text.moveText(0, - (image.getScaledHeight() + diff));
        newLine();
    }
}