Class Java2DTextRenderer

java.lang.Object
com.openhtmltopdf.java2d.Java2DTextRenderer
All Implemented Interfaces:
TextRenderer

public class Java2DTextRenderer extends Object implements TextRenderer
Renders to a Graphics2D instance.
Author:
Joshua Marinacci, Torbjoern Gannholm
  • Field Details

    • scale

      protected float scale
    • threshold

      protected float threshold
    • antiAliasRenderingHint

      protected Object antiAliasRenderingHint
    • fractionalFontMetricsHint

      protected Object fractionalFontMetricsHint
  • Constructor Details

    • Java2DTextRenderer

      public Java2DTextRenderer()
  • Method Details

    • drawString

      public void drawString(OutputDevice outputDevice, String string, float x, float y)
      Specified by:
      drawString in interface TextRenderer
    • 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 interface TextRenderer
    • setup

      public void setup(FontContext fontContext, BidiReorderer bidiReorderer)
      Parameters:
      bidiReorderer -
    • setFontScale

      public void setFontScale(float scale)
      Specified by:
      setFontScale in interface TextRenderer
    • 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 interface TextRenderer
    • setSmoothingLevel

      public void setSmoothingLevel(int level)
      Specified by:
      setSmoothingLevel in interface TextRenderer
      Parameters:
      level - no-op
    • getFSFontMetrics

      public FSFontMetrics getFSFontMetrics(FontContext fc, FSFont font, String string)
      Specified by:
      getFSFontMetrics in interface TextRenderer
    • getWidth

      public int getWidth(FontContext fc, FSFont font, String string)
      Description copied from interface: TextRenderer
      Rarely need to use this method directly. Instead favor Breaker static method instead.
      Specified by:
      getWidth in interface TextRenderer
    • getFontScale

      public float getFontScale()
      Specified by:
      getFontScale in interface TextRenderer
    • getSmoothingLevel

      public int getSmoothingLevel()
      Specified by:
      getSmoothingLevel in interface TextRenderer
    • getRenderingHints

      public Object getRenderingHints()
      If anti-alias text is enabled, the value from RenderingHints to use for AA smoothing in Java2D. Defaults to RenderingHints.VALUE_TEXT_ANTIALIAS_ON.
      Returns:
      Current AA rendering hint
    • setRenderingHints

      public void setRenderingHints(Object renderingHints)
      If anti-alias text is enabled, the value from RenderingHints to use for AA smoothing in Java2D. Defaults to RenderingHints.VALUE_TEXT_ANTIALIAS_ON.
      Parameters:
      renderingHints - rendering hint for AA smoothing in Java2D
    • getGlyphPositions

      public float[] getGlyphPositions(OutputDevice outputDevice, FSFont font, 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 interface TextRenderer