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 classJava2DTextRenderer.FontRun
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.ObjectantiAliasRenderingHintprotected java.lang.ObjectfractionalFontMetricsHintprotected floatscaleprotected floatthreshold
-
Constructor Summary
Constructors Constructor Description Java2DTextRenderer()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidadjustGlyphPositions(java.lang.String string, JustificationInfo info, java.awt.font.GlyphVector vector)private booleancanDisplayWithFont(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)voiddrawString(OutputDevice outputDevice, java.lang.String string, float x, float y)voiddrawString(OutputDevice outputDevice, java.lang.String string, float x, float y, JustificationInfo info)Draws a justified string.floatgetFontScale()FSFontMetricsgetFSFontMetrics(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.ObjectgetRenderingHints()If anti-alias text is enabled, the value from RenderingHints to use for AA smoothing in Java2D.intgetSmoothingLevel()intgetWidth(FontContext fc, FSFont font, java.lang.String string)Rarely need to use this method directly.private intgetWidthFast(FontContext fc, java.awt.Font awtFont, java.lang.String string)private intgetWidthSlow(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.voidsetFontScale(float scale)voidsetRenderingHints(java.lang.Object renderingHints)If anti-alias text is enabled, the value from RenderingHints to use for AA smoothing in Java2D.voidsetSmoothingLevel(int level)voidsetSmoothingThreshold(float fontsize)Set the smoothing threashold.voidsetup(FontContext context)voidsetup(FontContext fontContext, BidiReorderer bidiReorderer)
-
-
-
Method Detail
-
drawString
public void drawString(OutputDevice outputDevice, java.lang.String string, float x, float y)
- Specified by:
drawStringin 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:
drawStringin 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:
setFontScalein interfaceTextRenderer
-
setSmoothingThreshold
public void setSmoothingThreshold(float fontsize)
Description copied from interface:TextRendererSet 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:
setSmoothingThresholdin interfaceTextRenderer
-
setSmoothingLevel
public void setSmoothingLevel(int level)
- Specified by:
setSmoothingLevelin interfaceTextRenderer- Parameters:
level- no-op
-
getFSFontMetrics
public FSFontMetrics getFSFontMetrics(FontContext fc, FSFont font, java.lang.String string)
- Specified by:
getFSFontMetricsin 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:TextRendererRarely need to use this method directly. Instead favorBreakerstatic method instead.- Specified by:
getWidthin interfaceTextRenderer
-
getFontScale
public float getFontScale()
- Specified by:
getFontScalein interfaceTextRenderer
-
getSmoothingLevel
public int getSmoothingLevel()
- Specified by:
getSmoothingLevelin 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:
setupin interfaceTextRenderer
-
-