Package com.openhtmltopdf.java2d
Class Java2DTextRenderer
- java.lang.Object
-
- com.openhtmltopdf.java2d.Java2DTextRenderer
-
- All Implemented Interfaces:
TextRenderer
public class Java2DTextRenderer extends java.lang.Object implements TextRenderer
Renders to a Graphics2D instance.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
Java2DTextRenderer.FontRun
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.Object
antiAliasRenderingHint
protected java.lang.Object
fractionalFontMetricsHint
protected float
scale
protected float
threshold
-
Constructor Summary
Constructors Constructor Description Java2DTextRenderer()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
adjustGlyphPositions(java.lang.String string, JustificationInfo info, java.awt.font.GlyphVector vector)
private boolean
canDisplayWithFont(java.lang.String str, java.awt.Font fnt)
private java.util.List<Java2DTextRenderer.FontRun>
divideIntoFontRuns(java.util.List<java.awt.Font> fonts, java.lang.String string)
void
drawString(OutputDevice outputDevice, java.lang.String string, float x, float y)
void
drawString(OutputDevice outputDevice, java.lang.String string, float x, float y, JustificationInfo info)
Draws a justified string.float
getFontScale()
FSFontMetrics
getFSFontMetrics(FontContext fc, FSFont font, java.lang.String string)
float[]
getGlyphPositions(OutputDevice outputDevice, FSFont font, java.lang.String text)
This method gets glyph positions for purposes of selecting text.java.lang.Object
getRenderingHints()
If anti-alias text is enabled, the value from RenderingHints to use for AA smoothing in Java2D.int
getSmoothingLevel()
int
getWidth(FontContext fc, FSFont font, java.lang.String string)
Rarely need to use this method directly.private int
getWidthFast(FontContext fc, java.awt.Font awtFont, java.lang.String string)
private int
getWidthSlow(FontContext fc, java.util.List<java.awt.Font> fonts, java.lang.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(java.lang.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)
-
-
-
Method Detail
-
drawString
public void drawString(OutputDevice outputDevice, java.lang.String string, float x, float y)
- Specified by:
drawString
in interfaceTextRenderer
-
drawString
public void drawString(OutputDevice outputDevice, java.lang.String string, float x, float y, JustificationInfo info)
Draws a justified string. TODO: Font fallback.- Specified by:
drawString
in interfaceTextRenderer
-
adjustGlyphPositions
private void adjustGlyphPositions(java.lang.String string, JustificationInfo info, java.awt.font.GlyphVector vector)
-
setup
public void setup(FontContext fontContext, BidiReorderer bidiReorderer)
- 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
public FSFontMetrics getFSFontMetrics(FontContext fc, FSFont font, java.lang.String string)
- Specified by:
getFSFontMetrics
in interfaceTextRenderer
-
canDisplayWithFont
private boolean canDisplayWithFont(java.lang.String str, java.awt.Font fnt)
-
getWidthFast
private int getWidthFast(FontContext fc, java.awt.Font awtFont, java.lang.String string)
-
divideIntoFontRuns
private java.util.List<Java2DTextRenderer.FontRun> divideIntoFontRuns(java.util.List<java.awt.Font> fonts, java.lang.String string)
-
getWidthSlow
private int getWidthSlow(FontContext fc, java.util.List<java.awt.Font> fonts, java.lang.String string)
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
public int getWidth(FontContext fc, FSFont font, java.lang.String string)
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
public java.lang.Object 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
public void setRenderingHints(java.lang.Object renderingHints)
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
public float[] getGlyphPositions(OutputDevice outputDevice, FSFont font, java.lang.String text)
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
public void setup(FontContext context)
- Specified by:
setup
in interfaceTextRenderer
-
-