Package org.apache.fop.pdf
Class PDFText
java.lang.Object
org.apache.fop.pdf.PDFObject
org.apache.fop.pdf.PDFText
- All Implemented Interfaces:
PDFWritable
This class represents a simple number object. It also contains contains some
utility methods for outputting numbers to PDF.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic final byte[]
escapeByteArray
(byte[] data) Escape a byte array for output to PDF (Used for encrypted strings)static final String
Escaped a String as described in section 4.4 in the PDF 1.3 specs.static final void
escapeStringChar
(char c, StringBuffer target) Escapes a character conforming to the rules established in the PostScript Language Reference (Search for "Literal Text Strings").static final String
escapeText
(String text) Escape text (see 4.4.1 in PDF 1.3 specs)static final String
escapeText
(String text, boolean forceHexMode) Escape text (see 4.4.1 in PDF 1.3 specs)getText()
Returns the text.void
Sets the text.static final String
toHex
(byte[] data) Converts a byte array to a Hexadecimal String (3.2.3 in PDF 1.4 specs)static final String
toHex
(byte[] data, boolean brackets) Converts a byte array to a Hexadecimal String (3.2.3 in PDF 1.4 specs)protected String
This method returns a String representation of the PDF object.static String
toPDFString
(CharSequence text) Converts a text to PDF's "string" data type.static String
toPDFString
(CharSequence text, char replacement) Converts a text to PDF's "string" data type.static final String
toUnicodeHex
(char c) Convert a char to a multibyte hex representationstatic final void
toUnicodeHex
(int c, StringBuffer sb) Convert a char to a multibyte hex representation appending to string buffer.static final byte[]
Converts a String to UTF-16 (big endian).Methods inherited from class org.apache.fop.pdf.PDFObject
contentEquals, encode, encodeBinaryToHexString, encodeString, encodeText, formatObject, getChildren, getDocument, getDocumentSafely, getGeneration, getObjectID, getObjectNumber, getParent, hasObjectNumber, makeReference, output, outputInline, referencePDF, setDocument, setObjectNumber, setObjectNumber, setObjectNumber, setParent, toPDF
-
Constructor Details
-
PDFText
public PDFText()
-
-
Method Details
-
getText
Returns the text.- Returns:
- the text
-
setText
Sets the text.- Parameters:
text
- the text
-
toPDFString
This method returns a String representation of the PDF object. The result is normally converted/encoded to a byte array by toPDF(). Only use this method to implement the serialization if the object can be fully represented as text. If the PDF representation of the object contains binary content use toPDF() or output(OutputStream) instead. This applies to any object potentially containing a string object because string object are encrypted and therefore need to be binary.- Overrides:
toPDFString
in classPDFObject
- Returns:
- String the String representation
-
escapeText
Escape text (see 4.4.1 in PDF 1.3 specs)- Parameters:
text
- the text to encode- Returns:
- encoded text
-
escapeText
Escape text (see 4.4.1 in PDF 1.3 specs)- Parameters:
text
- the text to encodeforceHexMode
- true if the output should follow the hex encoding rules- Returns:
- encoded text
-
toHex
Converts a byte array to a Hexadecimal String (3.2.3 in PDF 1.4 specs)- Parameters:
data
- the data to encodebrackets
- true if enclosing brackets should be included- Returns:
- String the resulting string
-
toHex
Converts a byte array to a Hexadecimal String (3.2.3 in PDF 1.4 specs)- Parameters:
data
- the data to encode- Returns:
- String the resulting string
-
toUTF16
Converts a String to UTF-16 (big endian).- Parameters:
text
- text to convert- Returns:
- byte[] UTF-16 stream
-
toUnicodeHex
Convert a char to a multibyte hex representation- Parameters:
c
- character to encode- Returns:
- the encoded character
-
toUnicodeHex
Convert a char to a multibyte hex representation appending to string buffer. The created string will be:- 4-character string in case of non-BMP character
- 6-character string in case of BMP character
- Parameters:
c
- character to encodesb
- the string buffer to append output
-
escapeString
Escaped a String as described in section 4.4 in the PDF 1.3 specs.- Parameters:
s
- String to escape- Returns:
- String the escaped String
-
escapeStringChar
Escapes a character conforming to the rules established in the PostScript Language Reference (Search for "Literal Text Strings").- Parameters:
c
- character to escapetarget
- target StringBuffer to write the escaped character to
-
escapeByteArray
public static final byte[] escapeByteArray(byte[] data) Escape a byte array for output to PDF (Used for encrypted strings)- Parameters:
data
- data to encode- Returns:
- byte[] encoded data
-
toPDFString
Converts a text to PDF's "string" data type. Unsupported characters get converted to '?' characters (similar to what the Java "US-ASCII" encoding does).- Parameters:
text
- the text to convert- Returns:
- the converted string
- See Also:
-
toPDFString
Converts a text to PDF's "string" data type. Unsupported characters get converted to the given replacement character.The PDF library currently doesn't properly distinguish between the PDF data types "string" and "text string", so we currently restrict "string" to US-ASCII, also because "string" seems somewhat under-specified concerning the upper 128 bytes.
- Parameters:
text
- the text to convertreplacement
- the replacement character used when substituting a character- Returns:
- the converted string
-