javax.swing.text.rtf
Class RTFGenerator
java.lang.Object
javax.swing.text.rtf.RTFGenerator
- class RTFGenerator
- extends Object
Generates an RTF output stream (java.io.OutputStream) from rich text
(handed off through a series of LTTextAcceptor calls). Can be used to
generate RTF from any object which knows how to write to a text acceptor
(e.g., LTAttributedText and LTRTFFilter).
Note that this is a lossy conversion since RTF's model of
text does not exactly correspond with LightText's.
- See Also:
LTAttributedText
,
LTRTFFilter
,
LTTextAcceptor
,
OutputStream
Method Summary |
(package private) String |
approximationForUnicode(char ch)
|
private static Object |
attrDiff(MutableAttributeSet oldAttrs,
AttributeSet newAttrs,
Object key,
Object dfl)
|
protected void |
checkControlWord(MutableAttributeSet currentAttributes,
AttributeSet newAttributes,
RTFAttribute word)
|
protected void |
checkControlWords(MutableAttributeSet currentAttributes,
AttributeSet newAttributes,
RTFAttribute[] words,
int domain)
|
protected void |
checkNumericControlWord(MutableAttributeSet currentAttributes,
AttributeSet newAttributes,
Object attrName,
String controlWord,
float dflt,
float scale)
|
protected static int |
convertCharacter(int[] conversion,
char ch)
Takes a char and a conversion table (an int[] in the current
implementation, but conversion tables should be treated as an opaque
type) and returns the
corresponding byte value (as an int, since bytes are signed). |
private static boolean |
equalArraysOK(Object a,
Object b)
|
void |
examineElement(Element el)
|
private Style |
findStyle(AttributeSet a)
|
private Integer |
findStyleNumber(AttributeSet a,
String domain)
|
(package private) static int[] |
outputConversionForName(String name)
|
(package private) static int[] |
outputConversionFromTranslationTable(char[] table)
Takes a translation table (a 256-element array of characters)
and creates an output conversion table for use by
convertCharacter(). |
protected void |
resetCharacterAttributes(MutableAttributeSet currentAttributes)
|
protected void |
resetParagraphAttributes(MutableAttributeSet currentAttributes)
|
protected void |
resetSectionAttributes(MutableAttributeSet currentAttributes)
|
private void |
tallyStyles(AttributeSet a)
|
(package private) void |
updateCharacterAttributes(MutableAttributeSet current,
AttributeSet newAttributes,
boolean updateStyleChanges)
|
(package private) void |
updateParagraphAttributes(MutableAttributeSet current,
AttributeSet newAttributes,
boolean emitStyleChanges)
|
(package private) void |
updateSectionAttributes(MutableAttributeSet current,
AttributeSet newAttributes,
boolean emitStyleChanges)
|
void |
writeBegingroup()
|
void |
writeCharacter(char ch)
|
void |
writeControlWord(String keyword)
|
void |
writeControlWord(String keyword,
int arg)
|
static void |
writeDocument(Document d,
OutputStream to)
|
(package private) void |
writeDocumentProperties(Document doc)
|
void |
writeEndgroup()
|
void |
writeLineBreak()
|
void |
writeParagraphElement(Element el)
|
void |
writeRawString(String str)
|
void |
writeRTFHeader()
|
void |
writeRTFTrailer()
|
void |
writeText(Segment s)
|
void |
writeText(String s)
|
void |
writeTextElement(Element el)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
colorTable
Dictionary colorTable
colorCount
int colorCount
fontTable
Dictionary fontTable
fontCount
int fontCount
styleTable
Dictionary styleTable
styleCount
int styleCount
outputStream
OutputStream outputStream
afterKeyword
boolean afterKeyword
outputAttributes
MutableAttributeSet outputAttributes
unicodeCount
int unicodeCount
workingSegment
private Segment workingSegment
outputConversion
int[] outputConversion
defaultRTFColor
public static final Color defaultRTFColor
- The default color, used for text without an explicit color
attribute.
defaultFontSize
public static final float defaultFontSize
- See Also:
- Constant Field Values
defaultFontFamily
public static final String defaultFontFamily
- See Also:
- Constant Field Values
One
protected static Integer One
Zero
protected static Integer Zero
False
protected static Boolean False
ZeroPointZero
protected static Float ZeroPointZero
MagicToken
private static Object MagicToken
textKeywords
protected static RTFGenerator.CharacterKeywordPair[] textKeywords
hexdigits
static final char[] hexdigits
RTFGenerator
public RTFGenerator(OutputStream to)
writeDocument
public static void writeDocument(Document d,
OutputStream to)
throws IOException
- Throws:
IOException
examineElement
public void examineElement(Element el)
tallyStyles
private void tallyStyles(AttributeSet a)
findStyle
private Style findStyle(AttributeSet a)
findStyleNumber
private Integer findStyleNumber(AttributeSet a,
String domain)
attrDiff
private static Object attrDiff(MutableAttributeSet oldAttrs,
AttributeSet newAttrs,
Object key,
Object dfl)
equalArraysOK
private static boolean equalArraysOK(Object a,
Object b)
writeLineBreak
public void writeLineBreak()
throws IOException
- Throws:
IOException
writeRTFHeader
public void writeRTFHeader()
throws IOException
- Throws:
IOException
writeDocumentProperties
void writeDocumentProperties(Document doc)
throws IOException
- Throws:
IOException
writeRTFTrailer
public void writeRTFTrailer()
throws IOException
- Throws:
IOException
checkNumericControlWord
protected void checkNumericControlWord(MutableAttributeSet currentAttributes,
AttributeSet newAttributes,
Object attrName,
String controlWord,
float dflt,
float scale)
throws IOException
- Throws:
IOException
checkControlWord
protected void checkControlWord(MutableAttributeSet currentAttributes,
AttributeSet newAttributes,
RTFAttribute word)
throws IOException
- Throws:
IOException
checkControlWords
protected void checkControlWords(MutableAttributeSet currentAttributes,
AttributeSet newAttributes,
RTFAttribute[] words,
int domain)
throws IOException
- Throws:
IOException
updateSectionAttributes
void updateSectionAttributes(MutableAttributeSet current,
AttributeSet newAttributes,
boolean emitStyleChanges)
throws IOException
- Throws:
IOException
resetSectionAttributes
protected void resetSectionAttributes(MutableAttributeSet currentAttributes)
throws IOException
- Throws:
IOException
updateParagraphAttributes
void updateParagraphAttributes(MutableAttributeSet current,
AttributeSet newAttributes,
boolean emitStyleChanges)
throws IOException
- Throws:
IOException
writeParagraphElement
public void writeParagraphElement(Element el)
throws IOException
- Throws:
IOException
resetParagraphAttributes
protected void resetParagraphAttributes(MutableAttributeSet currentAttributes)
throws IOException
- Throws:
IOException
updateCharacterAttributes
void updateCharacterAttributes(MutableAttributeSet current,
AttributeSet newAttributes,
boolean updateStyleChanges)
throws IOException
- Throws:
IOException
resetCharacterAttributes
protected void resetCharacterAttributes(MutableAttributeSet currentAttributes)
throws IOException
- Throws:
IOException
writeTextElement
public void writeTextElement(Element el)
throws IOException
- Throws:
IOException
writeText
public void writeText(Segment s)
throws IOException
- Throws:
IOException
writeText
public void writeText(String s)
throws IOException
- Throws:
IOException
writeRawString
public void writeRawString(String str)
throws IOException
- Throws:
IOException
writeControlWord
public void writeControlWord(String keyword)
throws IOException
- Throws:
IOException
writeControlWord
public void writeControlWord(String keyword,
int arg)
throws IOException
- Throws:
IOException
writeBegingroup
public void writeBegingroup()
throws IOException
- Throws:
IOException
writeEndgroup
public void writeEndgroup()
throws IOException
- Throws:
IOException
writeCharacter
public void writeCharacter(char ch)
throws IOException
- Throws:
IOException
approximationForUnicode
String approximationForUnicode(char ch)
outputConversionFromTranslationTable
static int[] outputConversionFromTranslationTable(char[] table)
- Takes a translation table (a 256-element array of characters)
and creates an output conversion table for use by
convertCharacter().
outputConversionForName
static int[] outputConversionForName(String name)
throws IOException
- Throws:
IOException
convertCharacter
protected static int convertCharacter(int[] conversion,
char ch)
- Takes a char and a conversion table (an int[] in the current
implementation, but conversion tables should be treated as an opaque
type) and returns the
corresponding byte value (as an int, since bytes are signed).