com.lowagie.text.Utilities Java Examples

The following examples show how to use com.lowagie.text.Utilities. 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: BidiLine.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Gets the width of a range of characters.
 * 
 * @param startIdx the first index to calculate
 * @param lastIdx the last inclusive index to calculate
 * @return the sum of all widths
 */
public float getWidth(int startIdx, int lastIdx) {
	char c = 0;
	char uniC;
	PdfChunk ck = null;
	float width = 0;
	for (; startIdx <= lastIdx; ++startIdx) {
		boolean surrogate = Utilities.isSurrogatePair(text, startIdx);
		if (surrogate) {
			width += detailChunks[startIdx].getCharWidth(Utilities.convertToUtf32(text, startIdx));
			++startIdx;
		} else {
			c = text[startIdx];
			ck = detailChunks[startIdx];
			if (PdfChunk.noPrint(ck.getUnicodeEquivalent(c))) {
				continue;
			}
			width += detailChunks[startIdx].getCharWidth(c);
		}
	}
	return width;
}
 
Example #2
Source File: BidiLine.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/** Gets the width of a range of characters.
 * @param startIdx the first index to calculate
 * @param lastIdx the last inclusive index to calculate
 * @return the sum of all widths
 */    
public float getWidth(int startIdx, int lastIdx) {
    char c = 0;
    PdfChunk ck = null;
    float width = 0;
    for (; startIdx <= lastIdx; ++startIdx) {
        boolean surrogate = Utilities.isSurrogatePair(text, startIdx);
        if (surrogate) {
            width += detailChunks[startIdx].getCharWidth(Utilities.convertToUtf32(text, startIdx));
            ++startIdx;
        }
        else {
            c = text[startIdx];
            ck = detailChunks[startIdx];
            if (PdfChunk.noPrint(ck.getUnicodeEquivalent(c)))
                continue;
            width += detailChunks[startIdx].getCharWidth(c);
        }
    }
    return width;
}
 
Example #3
Source File: PdfContext.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
public Image getImage(String path) {
	try {
		URL url = getClass().getResource(path);
		if (url == null) {
			url = Utilities.toURL(path);
		}
		return Image.getInstance(url);
	} catch (Exception e) { // NOSONAR
		log.warn("could not fetch image", e);
		return null;
	}
}
 
Example #4
Source File: PdfChunk.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
int lengthUtf32() {
	if (!BaseFont.IDENTITY_H.equals(encoding)) {
		return value.length();
	}
	int total = 0;
	int len = value.length();
	for (int k = 0; k < len; ++k) {
		if (Utilities.isSurrogateHigh(value.charAt(k))) {
			++k;
		}
		++total;
	}
	return total;
}
 
Example #5
Source File: ElementFactory.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Creates a Cell object based on a list of properties.
 * @param attributes
 * @return a Cell
 */
public static Cell getCell(Properties attributes) {
	Cell cell = new Cell();
	String value;

	cell.setHorizontalAlignment(attributes
			.getProperty(ElementTags.HORIZONTALALIGN));
	cell.setVerticalAlignment(attributes
			.getProperty(ElementTags.VERTICALALIGN));

	value = attributes.getProperty(ElementTags.WIDTH);
	if (value != null) {
		cell.setWidth(value);
	}
	value = attributes.getProperty(ElementTags.COLSPAN);
	if (value != null) {
		cell.setColspan(Integer.parseInt(value));
	}
	value = attributes.getProperty(ElementTags.ROWSPAN);
	if (value != null) {
		cell.setRowspan(Integer.parseInt(value));
	}
	value = attributes.getProperty(ElementTags.LEADING);
	if (value != null) {
		cell.setLeading(Float.parseFloat(value + "f"));
	}
	cell.setHeader(Utilities.checkTrueOrFalse(attributes,
			ElementTags.HEADER));
	if (Utilities.checkTrueOrFalse(attributes, ElementTags.NOWRAP)) {
		cell.setMaxLines(1);
	}
	setRectangleProperties(cell, attributes);
	return cell;
}
 
Example #6
Source File: PdfChunk.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
int lengthUtf32() {
    if (!BaseFont.IDENTITY_H.equals(encoding))
        return value.length();
    int total = 0;
    int len = value.length();
    for (int k = 0; k < len; ++k) {
        if (Utilities.isSurrogateHigh(value.charAt(k)))
            ++k;
        ++total;
    }
    return total;
}
 
Example #7
Source File: ElementFactory.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Creates a Cell object based on a list of properties.
 * 
 * @param attributes
 * @return a Cell
 */
public static Cell getCell(Properties attributes) {
	Cell cell = new Cell();
	String value;

	cell.setHorizontalAlignment(attributes.getProperty(ElementTags.HORIZONTALALIGN));
	cell.setVerticalAlignment(attributes.getProperty(ElementTags.VERTICALALIGN));

	value = attributes.getProperty(ElementTags.WIDTH);
	if (value != null) {
		cell.setWidth(value);
	}
	value = attributes.getProperty(ElementTags.COLSPAN);
	if (value != null) {
		cell.setColspan(Integer.parseInt(value));
	}
	value = attributes.getProperty(ElementTags.ROWSPAN);
	if (value != null) {
		cell.setRowspan(Integer.parseInt(value));
	}
	value = attributes.getProperty(ElementTags.LEADING);
	if (value != null) {
		cell.setLeading(Float.parseFloat(value + "f"));
	}
	cell.setHeader(Utilities.checkTrueOrFalse(attributes, ElementTags.HEADER));
	if (Utilities.checkTrueOrFalse(attributes, ElementTags.NOWRAP)) {
		cell.setMaxLines(1);
	}
	setRectangleProperties(cell, attributes);
	return cell;
}
 
Example #8
Source File: ElementFactory.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
/**
 * Creates a List object based on a list of properties.
 * 
 * @param attributes
 * @return the List
 */
public static List getList(Properties attributes) {
	List list = new List();

	list.setNumbered(Utilities.checkTrueOrFalse(attributes, ElementTags.NUMBERED));
	list.setLettered(Utilities.checkTrueOrFalse(attributes, ElementTags.LETTERED));
	list.setLowercase(Utilities.checkTrueOrFalse(attributes, ElementTags.LOWERCASE));
	list.setAutoindent(Utilities.checkTrueOrFalse(attributes, ElementTags.AUTO_INDENT_ITEMS));
	list.setAlignindent(Utilities.checkTrueOrFalse(attributes, ElementTags.ALIGN_INDENTATION_ITEMS));

	String value;

	value = attributes.getProperty(ElementTags.FIRST);
	if (value != null) {
		char character = value.charAt(0);
		if (Character.isLetter(character)) {
			list.setFirst(character);
		} else {
			list.setFirst(Integer.parseInt(value));
		}
	}

	value = attributes.getProperty(ElementTags.LISTSYMBOL);
	if (value != null) {
		list.setListSymbol(new Chunk(value, FontFactory.getFont(attributes)));
	}

	value = attributes.getProperty(ElementTags.INDENTATIONLEFT);
	if (value != null) {
		list.setIndentationLeft(Float.parseFloat(value + "f"));
	}

	value = attributes.getProperty(ElementTags.INDENTATIONRIGHT);
	if (value != null) {
		list.setIndentationRight(Float.parseFloat(value + "f"));
	}

	value = attributes.getProperty(ElementTags.SYMBOLINDENT);
	if (value != null) {
		list.setSymbolIndent(Float.parseFloat(value));
	}

	return list;
}
 
Example #9
Source File: InputMeta.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
public void skip(int len) throws IOException{
    length += len;
    Utilities.skip(in, len);
}
 
Example #10
Source File: InputMeta.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void skip(int len) throws IOException{
    length += len;
    Utilities.skip(in, len);
}
 
Example #11
Source File: ElementFactory.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Creates a List object based on a list of properties.
 * @param attributes
 * @return the List
 */
public static List getList(Properties attributes) {
	List list = new List();

	list.setNumbered(Utilities.checkTrueOrFalse(attributes,
			ElementTags.NUMBERED));
	list.setLettered(Utilities.checkTrueOrFalse(attributes,
			ElementTags.LETTERED));
	list.setLowercase(Utilities.checkTrueOrFalse(attributes,
			ElementTags.LOWERCASE));
	list.setAutoindent(Utilities.checkTrueOrFalse(attributes,
			ElementTags.AUTO_INDENT_ITEMS));
	list.setAlignindent(Utilities.checkTrueOrFalse(attributes,
			ElementTags.ALIGN_INDENTATION_ITEMS));

	String value;

	value = attributes.getProperty(ElementTags.FIRST);
	if (value != null) {
		char character = value.charAt(0);
		if (Character.isLetter(character)) {
			list.setFirst(character);
		} else {
			list.setFirst(Integer.parseInt(value));
		}
	}

	value = attributes.getProperty(ElementTags.LISTSYMBOL);
	if (value != null) {
		list
				.setListSymbol(new Chunk(value, FontFactory
						.getFont(attributes)));
	}

	value = attributes.getProperty(ElementTags.INDENTATIONLEFT);
	if (value != null) {
		list.setIndentationLeft(Float.parseFloat(value + "f"));
	}

	value = attributes.getProperty(ElementTags.INDENTATIONRIGHT);
	if (value != null) {
		list.setIndentationRight(Float.parseFloat(value + "f"));
	}

	value = attributes.getProperty(ElementTags.SYMBOLINDENT);
	if (value != null) {
		list.setSymbolIndent(Float.parseFloat(value));
	}

	return list;
}
 
Example #12
Source File: PngImage.java    From gcs with Mozilla Public License 2.0 2 votes vote down vote up
/** Reads a PNG from a file.
 * @param file the file
 * @throws IOException on error
 * @return the image
 */    
public static Image getImage(String file) throws IOException {
    return getImage(Utilities.toURL(file));
}
 
Example #13
Source File: BmpImage.java    From itext2 with GNU Lesser General Public License v3.0 2 votes vote down vote up
/** Reads a BMP from a file.
 * @param file the file
 * @throws IOException on error
 * @return the image
 */    
public static Image getImage(String file) throws IOException {
    return getImage(Utilities.toURL(file));
}
 
Example #14
Source File: GifImage.java    From itext2 with GNU Lesser General Public License v3.0 2 votes vote down vote up
/** Reads gif images from a file.
 * @param file the file
 * @throws IOException on error
 */    
public GifImage(String file) throws IOException {
    this(Utilities.toURL(file));
}
 
Example #15
Source File: PngImage.java    From itext2 with GNU Lesser General Public License v3.0 2 votes vote down vote up
/** Reads a PNG from a file.
 * @param file the file
 * @throws IOException on error
 * @return the image
 */    
public static Image getImage(String file) throws IOException {
    return getImage(Utilities.toURL(file));
}
 
Example #16
Source File: GifImage.java    From gcs with Mozilla Public License 2.0 2 votes vote down vote up
/**
 * Reads gif images from a file.
 * 
 * @param file the file
 * @throws IOException on error
 */
public GifImage(String file) throws IOException {
	this(Utilities.toURL(file));
}
 
Example #17
Source File: BmpImage.java    From gcs with Mozilla Public License 2.0 2 votes vote down vote up
/**
 * Reads a BMP from a file.
 * 
 * @param file the file
 * @throws IOException on error
 * @return the image
 */
public static Image getImage(String file) throws IOException {
	return getImage(Utilities.toURL(file));
}