Class Java2DTextRenderer

  • All Implemented Interfaces:
    com.openhtmltopdf.extend.TextRenderer

    public class Java2DTextRenderer
    extends Object
    implements com.openhtmltopdf.extend.TextRenderer
    Renders to a Graphics2D instance.
    Author:
    Joshua Marinacci, Torbjoern Gannholm
    • Method Summary

      Modifier and Type Method Description
      void drawGlyphVector​(com.openhtmltopdf.extend.OutputDevice outputDevice, com.openhtmltopdf.extend.FSGlyphVector fsGlyphVector, float x, float y)  
      void drawString​(com.openhtmltopdf.extend.OutputDevice outputDevice, String string, float x, float y)
      void drawString​(com.openhtmltopdf.extend.OutputDevice outputDevice, String string, float x, float y, com.openhtmltopdf.render.JustificationInfo info)
      Draws a justified string.
      float getFontScale()  
      com.openhtmltopdf.render.FSFontMetrics getFSFontMetrics​(com.openhtmltopdf.extend.FontContext fc, com.openhtmltopdf.render.FSFont font, String string)  
      Rectangle getGlyphBounds​(com.openhtmltopdf.extend.OutputDevice outputDevice, com.openhtmltopdf.render.FSFont font, com.openhtmltopdf.extend.FSGlyphVector fsGlyphVector, int index, float x, float y)
      This method gets glyph bounds for purposes of selecting text.
      float[] getGlyphPositions​(com.openhtmltopdf.extend.OutputDevice outputDevice, com.openhtmltopdf.render.FSFont font, com.openhtmltopdf.extend.FSGlyphVector fsGlyphVector)
      This method gets glyph positions for purposes of selecting text.
      float[] getGlyphPositions​(com.openhtmltopdf.extend.OutputDevice outputDevice, com.openhtmltopdf.render.FSFont font, String text)
      This method gets glyph positions for purposes of selecting text.
      com.openhtmltopdf.extend.FSGlyphVector getGlyphVector​(com.openhtmltopdf.extend.OutputDevice outputDevice, com.openhtmltopdf.render.FSFont font, String text)
      This method gets a glyph vector for purposes of selecting text.
      Object getRenderingHints()
      If anti-alias text is enabled, the value from RenderingHints to use for AA smoothing in Java2D.
      int getSmoothingLevel()  
      int getWidth​(com.openhtmltopdf.extend.FontContext fc, com.openhtmltopdf.render.FSFont font, String string)  
      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)  
      void setup​(com.openhtmltopdf.extend.FontContext context)  
      void setup​(com.openhtmltopdf.extend.FontContext fontContext, com.openhtmltopdf.bidi.BidiReorderer bidiReorderer)
    • Field Detail

      • scale

        protected float scale
      • threshold

        protected float threshold
      • antiAliasRenderingHint

        protected Object antiAliasRenderingHint
      • fractionalFontMetricsHint

        protected Object fractionalFontMetricsHint
    • Constructor Detail

      • Java2DTextRenderer

        public Java2DTextRenderer()
    • Method Detail

      • drawString

        public void drawString​(com.openhtmltopdf.extend.OutputDevice outputDevice,
                               String string,
                               float x,
                               float y)
        Specified by:
        drawString in interface com.openhtmltopdf.extend.TextRenderer
      • drawString

        public void drawString​(com.openhtmltopdf.extend.OutputDevice outputDevice,
                               String string,
                               float x,
                               float y,
                               com.openhtmltopdf.render.JustificationInfo info)
        Draws a justified string. TODO: Font fallback.
        Specified by:
        drawString in interface com.openhtmltopdf.extend.TextRenderer
      • drawGlyphVector

        public void drawGlyphVector​(com.openhtmltopdf.extend.OutputDevice outputDevice,
                                    com.openhtmltopdf.extend.FSGlyphVector fsGlyphVector,
                                    float x,
                                    float y)
        Specified by:
        drawGlyphVector in interface com.openhtmltopdf.extend.TextRenderer
      • setup

        public void setup​(com.openhtmltopdf.extend.FontContext fontContext,
                          com.openhtmltopdf.bidi.BidiReorderer bidiReorderer)
        Parameters:
        bidiReorderer -
      • setFontScale

        public void setFontScale​(float scale)
        Specified by:
        setFontScale in interface com.openhtmltopdf.extend.TextRenderer
      • setSmoothingThreshold

        public void setSmoothingThreshold​(float fontsize)
        Specified by:
        setSmoothingThreshold in interface com.openhtmltopdf.extend.TextRenderer
      • setSmoothingLevel

        public void setSmoothingLevel​(int level)
        Specified by:
        setSmoothingLevel in interface com.openhtmltopdf.extend.TextRenderer
      • getFSFontMetrics

        public com.openhtmltopdf.render.FSFontMetrics getFSFontMetrics​(com.openhtmltopdf.extend.FontContext fc,
                                                                       com.openhtmltopdf.render.FSFont font,
                                                                       String string)
        Specified by:
        getFSFontMetrics in interface com.openhtmltopdf.extend.TextRenderer
      • getWidth

        public int getWidth​(com.openhtmltopdf.extend.FontContext fc,
                            com.openhtmltopdf.render.FSFont font,
                            String string)
        Specified by:
        getWidth in interface com.openhtmltopdf.extend.TextRenderer
      • getFontScale

        public float getFontScale()
        Specified by:
        getFontScale in interface com.openhtmltopdf.extend.TextRenderer
      • getSmoothingLevel

        public int getSmoothingLevel()
        Specified by:
        getSmoothingLevel in interface com.openhtmltopdf.extend.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​(com.openhtmltopdf.extend.OutputDevice outputDevice,
                                         com.openhtmltopdf.render.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.
      • getGlyphBounds

        public Rectangle getGlyphBounds​(com.openhtmltopdf.extend.OutputDevice outputDevice,
                                        com.openhtmltopdf.render.FSFont font,
                                        com.openhtmltopdf.extend.FSGlyphVector fsGlyphVector,
                                        int index,
                                        float x,
                                        float y)
        This method gets glyph bounds for purposes of selecting text. WE are not too worried about selecting text at this point so we just use the first font available.
        Specified by:
        getGlyphBounds in interface com.openhtmltopdf.extend.TextRenderer
      • getGlyphPositions

        public float[] getGlyphPositions​(com.openhtmltopdf.extend.OutputDevice outputDevice,
                                         com.openhtmltopdf.render.FSFont font,
                                         com.openhtmltopdf.extend.FSGlyphVector fsGlyphVector)
        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.
        Specified by:
        getGlyphPositions in interface com.openhtmltopdf.extend.TextRenderer
      • getGlyphVector

        public com.openhtmltopdf.extend.FSGlyphVector getGlyphVector​(com.openhtmltopdf.extend.OutputDevice outputDevice,
                                                                     com.openhtmltopdf.render.FSFont font,
                                                                     String text)
        This method gets a glyph vector for purposes of selecting text. WE are not too worried about selecting text at this point so we just use the first font available.
        Specified by:
        getGlyphVector in interface com.openhtmltopdf.extend.TextRenderer
      • setup

        public void setup​(com.openhtmltopdf.extend.FontContext context)
        Specified by:
        setup in interface com.openhtmltopdf.extend.TextRenderer