Package com.openhtmltopdf.java2d
Class Java2DTextRenderer
java.lang.Object
com.openhtmltopdf.java2d.Java2DTextRenderer
- All Implemented Interfaces:
TextRenderer
Renders to a Graphics2D instance.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
adjustGlyphPositions
(String string, JustificationInfo info, GlyphVector vector) private boolean
canDisplayWithFont
(String str, Font fnt) private List
<Java2DTextRenderer.FontRun> divideIntoFontRuns
(List<Font> fonts, String string) void
drawString
(OutputDevice outputDevice, String string, float x, float y) void
drawString
(OutputDevice outputDevice, String string, float x, float y, JustificationInfo info) Draws a justified string.float
getFSFontMetrics
(FontContext fc, FSFont font, String string) float[]
getGlyphPositions
(OutputDevice outputDevice, FSFont font, String text) This method gets glyph positions for purposes of selecting text.If anti-alias text is enabled, the value from RenderingHints to use for AA smoothing in Java2D.int
int
getWidth
(FontContext fc, FSFont font, String string) Rarely need to use this method directly.private int
getWidthFast
(FontContext fc, Font awtFont, String string) private int
getWidthSlow
(FontContext fc, List<Font> fonts, String string) This method divides the string up into font runs, then measures each font run, adding it to the total.void
setFontScale
(float scale) void
setRenderingHints
(Object renderingHints) If anti-alias text is enabled, the value from RenderingHints to use for AA smoothing in Java2D.void
setSmoothingLevel
(int level) void
setSmoothingThreshold
(float fontsize) Set the smoothing threashold.void
setup
(FontContext context) void
setup
(FontContext fontContext, BidiReorderer bidiReorderer)
-
Field Details
-
scale
protected float scale -
threshold
protected float threshold -
antiAliasRenderingHint
-
fractionalFontMetricsHint
-
-
Constructor Details
-
Java2DTextRenderer
public Java2DTextRenderer()
-
-
Method Details
-
drawString
- Specified by:
drawString
in interfaceTextRenderer
-
drawString
public void drawString(OutputDevice outputDevice, String string, float x, float y, JustificationInfo info) Draws a justified string. TODO: Font fallback.- Specified by:
drawString
in interfaceTextRenderer
-
adjustGlyphPositions
-
setup
- Parameters:
bidiReorderer
-
-
setFontScale
public void setFontScale(float scale) - Specified by:
setFontScale
in interfaceTextRenderer
-
setSmoothingThreshold
public void setSmoothingThreshold(float fontsize) Description copied from interface:TextRenderer
Set the smoothing threashold. This is a font size above which all text will be anti-aliased. Text below this size will not be antialiased. Set to -1 for no antialiasing. Set to 0 for all antialising. Else, set to the threshold font size. does not take font scaling into account.- Specified by:
setSmoothingThreshold
in interfaceTextRenderer
-
setSmoothingLevel
public void setSmoothingLevel(int level) - Specified by:
setSmoothingLevel
in interfaceTextRenderer
- Parameters:
level
- no-op
-
getFSFontMetrics
- Specified by:
getFSFontMetrics
in interfaceTextRenderer
-
canDisplayWithFont
-
getWidthFast
-
divideIntoFontRuns
-
getWidthSlow
This method divides the string up into font runs, then measures each font run, adding it to the total. We do this, rather than get the width of each character, in case kerning is enabled and it also may be faster. -
getWidth
Description copied from interface:TextRenderer
Rarely need to use this method directly. Instead favorBreaker
static method instead.- Specified by:
getWidth
in interfaceTextRenderer
-
getFontScale
public float getFontScale()- Specified by:
getFontScale
in interfaceTextRenderer
-
getSmoothingLevel
public int getSmoothingLevel()- Specified by:
getSmoothingLevel
in interfaceTextRenderer
-
getRenderingHints
If anti-alias text is enabled, the value from RenderingHints to use for AA smoothing in Java2D. Defaults toRenderingHints.VALUE_TEXT_ANTIALIAS_ON
.- Returns:
- Current AA rendering hint
-
setRenderingHints
If anti-alias text is enabled, the value from RenderingHints to use for AA smoothing in Java2D. Defaults toRenderingHints.VALUE_TEXT_ANTIALIAS_ON
.- Parameters:
renderingHints
- rendering hint for AA smoothing in Java2D
-
getGlyphPositions
This method gets glyph positions for purposes of selecting text. WE are not too worried about selecting text at this point so we just use the first font available. -
setup
- Specified by:
setup
in interfaceTextRenderer
-