Class Java2DTextRenderer

  • All Implemented Interfaces:
    TextRenderer

    public class Java2DTextRenderer
    extends java.lang.Object
    implements TextRenderer
    Renders to a Graphics2D instance.
    • Field Detail

      • scale

        protected float scale
      • threshold

        protected float threshold
      • antiAliasRenderingHint

        protected java.lang.Object antiAliasRenderingHint
      • fractionalFontMetricsHint

        protected java.lang.Object fractionalFontMetricsHint
    • Constructor Detail

      • Java2DTextRenderer

        public Java2DTextRenderer()
    • Method Detail

      • adjustGlyphPositions

        private void adjustGlyphPositions​(java.lang.String string,
                                          JustificationInfo info,
                                          java.awt.font.GlyphVector vector)
      • 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
      • 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.
      • getRenderingHints

        public java.lang.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​(java.lang.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,
                                         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.