Package org.fife.ui.rsyntaxtextarea
Class RtfGenerator
java.lang.Object
org.fife.ui.rsyntaxtextarea.RtfGenerator
Generates RTF text via a simple Java API.
The following RTF features are supported:
- Fonts
- Font sizes
- Foreground and background colors
- Bold, italic, and underline
- It assumes that tokens changing foreground color often is fairly common.
- It assumes that background highlighting is fairly uncommon.
- Version:
- 1.1
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
The default font size for RTF.private StringBuilder
private boolean
private int
private int
private int
private boolean
private boolean
private Color
private int
Java2D assumes a 72 dpi screen resolution, but on Windows the screen resolution is either 96 dpi or 120 dpi, depending on your font display settings. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a newline to the RTF document.void
appendToDoc
(String text, Font f, Color fg, Color bg) Appends styled text to the RTF document being generated.void
appendToDoc
(String text, Font f, Color fg, Color bg, boolean underline) Appends styled text to the RTF document being generated.void
appendToDoc
(String text, Font f, Color fg, Color bg, boolean underline, boolean setFG) Appends styled text to the RTF document being generated.void
appendToDocNoFG
(String text, Font f, Color bg, boolean underline) Appends styled text to the RTF document being generated.private void
escapeAndAdd
(StringBuilder sb, String text) Appends some text to a buffer, with special care taken for special characters as defined by the RTF spec.private int
fixFontSize
(float pointSize) Returns a font point size, adjusted for the current screen resolution.private static int
getColorIndex
(List<Color> list, Color item) Returns the index of the specified item in a list.private String
private static int
getFontIndex
(List<Font> list, Font font) Returns the index of the specified font in a list of fonts.private String
private static String
Returns a good "default" monospaced font to use when Java's logical font "Monospaced" is found.getRtf()
Returns the RTF document created by this generator.void
reset()
Resets this generator.
-
Field Details
-
mainBG
-
fontList
-
colorList
-
document
-
lastWasControlWord
private boolean lastWasControlWord -
lastFontIndex
private int lastFontIndex -
lastFGIndex
private int lastFGIndex -
lastBold
private boolean lastBold -
lastItalic
private boolean lastItalic -
lastFontSize
private int lastFontSize -
screenRes
private int screenResJava2D assumes a 72 dpi screen resolution, but on Windows the screen resolution is either 96 dpi or 120 dpi, depending on your font display settings. This is an attempt to make the RTF generated match the size of what's displayed in the RSyntaxTextArea. -
DEFAULT_FONT_SIZE
private static final int DEFAULT_FONT_SIZEThe default font size for RTF. This is point size, in half points.- See Also:
-
-
Constructor Details
-
RtfGenerator
Constructor.- Parameters:
mainBG
- The main background color to use.
-
-
Method Details
-
appendNewline
public void appendNewline()Adds a newline to the RTF document.- See Also:
-
appendToDoc
Appends styled text to the RTF document being generated.- Parameters:
text
- The text to append.f
- The font of the text. If this isnull
, the default font is used.fg
- The foreground of the text. If this isnull
, the default foreground color is used.bg
- The background color of the text. If this isnull
, the default background color is used.- See Also:
-
appendToDocNoFG
Appends styled text to the RTF document being generated.- Parameters:
text
- The text to append.f
- The font of the text. If this isnull
, the default font is used.bg
- The background color of the text. If this isnull
, the default background color is used.underline
- Whether the text should be underlined.- See Also:
-
appendToDoc
Appends styled text to the RTF document being generated.- Parameters:
text
- The text to append.f
- The font of the text. If this isnull
, the default font is used.fg
- The foreground of the text. If this isnull
, the default foreground color is used.bg
- The background color of the text. If this isnull
, the default background color is used.underline
- Whether the text should be underlined.- See Also:
-
appendToDoc
Appends styled text to the RTF document being generated.- Parameters:
text
- The text to append.f
- The font of the text. If this isnull
, the default font is used.fg
- The foreground of the text. If this isnull
, the default foreground color is used.bg
- The background color of the text. If this isnull
, the default background color is used.underline
- Whether the text should be underlined.setFG
- Whether the foreground specified byfg
should be honored (if it is non-null
).- See Also:
-
escapeAndAdd
Appends some text to a buffer, with special care taken for special characters as defined by the RTF spec.- All tab characters are replaced with the string
"
\tab
" - '\', '{' and '}' are changed to "\\", "\{" and "\}"
- Parameters:
sb
- The buffer to append to.text
- The text to append (with tab chars substituted).
- All tab characters are replaced with the string
"
-
fixFontSize
private int fixFontSize(float pointSize) Returns a font point size, adjusted for the current screen resolution.Java2D assumes 72 dpi. On systems with larger dpi (Windows, GTK, etc.), font rendering will appear too small if we simply return a Java "Font" object's getSize() value. We need to adjust it for the screen resolution.
- Parameters:
pointSize
- A Java Font's point size, as returned fromgetSize2D()
.- Returns:
- The font point size, adjusted for the current screen resolution. This will allow other applications to render fonts the same size as they appear in the Java application.
-
getColorIndex
Returns the index of the specified item in a list. If the item is not in the list, it is added, and its new index is returned.- Parameters:
list
- The list (possibly) containing the item.item
- The item to get the index of.- Returns:
- The index of the item.
-
getColorTableRtf
-
getFontIndex
Returns the index of the specified font in a list of fonts. This method only checks for a font by its family name; its attributes such as bold and italic are ignored.If the font is not in the list, it is added, and its new index is returned.
- Parameters:
list
- The list (possibly) containing the font.font
- The font to get the index of.- Returns:
- The index of the font.
-
getFontTableRtf
-
getMonospacedFontFamily
Returns a good "default" monospaced font to use when Java's logical font "Monospaced" is found.- Returns:
- The monospaced font family to use.
-
getRtf
Returns the RTF document created by this generator.- Returns:
- The RTF document, as a
String
.
-
reset
public void reset()Resets this generator. All document information and content is cleared.
-