Class TextStyle


  • public final class TextStyle
    extends Object
    The TextStyle class sets the font, color and so on for any text displayed on the Graph. Each item of text has several attributes:
    • Font. The font to display the text in. This is specified as a String, which is turned into an actual font by the Output object you draw the graph to. By default, the font used across the whole graph is called "Default".
    • Color. The color of the text
    • Alignment. Each item of text displayed in the graph has a "control point", and the alignment setting controls how the text is positioned relative to that point.
    • Rotation. Text may be rotated to any angle.
    • Padding. Text may optionally be given some padding around it to distance itself from it's neighbours. This is useful in a number of circumstances - for example, the distance between the label on the tooth of an Axis and the tooth itself can be adjusted by setting padding.
    • Field Detail

      • ROTATE_AUTO

        public static final float ROTATE_AUTO
        A special value for setRotate(double) that may be used with labels on PieGraphs - causes the label to be rotated to match the angle of the slice. With other labels this has no effect.
        Since:
        2.0.2
        See Also:
        Constant Field Values
    • Constructor Detail

      • TextStyle

        public TextStyle​(String fontname,
                         double size,
                         Paint textcolor)
        Create a new TextStyle and set the font, size and color
        Parameters:
        fontname - the name of the font to use.
        size - The size of the text. Typically in points but may be in whatever units your Output uses.
        textcolor - what color to make the text
      • TextStyle

        public TextStyle​(String fontname,
                         double size,
                         Paint textcolor,
                         int align)
        Create a new TextStyle and set the font, size and textcolor
        Parameters:
        fontname - the name of the font to use.
        size - The size of the text. Typically in points but may be in whatever units your Output uses.
        textcolor - what color to make the text
        align - the alignment to use - a combination of one or more of the values from the Align class
      • TextStyle

        public TextStyle​(TextStyle style)
        Create a new TextStyle that is a clone of the specified style
    • Method Detail

      • setOverflow

        public void setOverflow​(boolean overflow)
        Set whether this text can overflow the edge of the graph. Overflowing text will not contribute to the calculated dimensions of the graph. Usually this should be left to the default of false.
        Since:
        2.4.7
      • setTextColor

        public void setTextColor​(Paint textcolor)
        Set the color of the text
        Parameters:
        textcolor - the color to make the text
      • setFont

        public void setFont​(String name,
                            double size)
        Set the font
        Parameters:
        name - the name of the font to use
        size - The size of the text. Typically in points but may be in whatever units your Output uses.
      • addBackupFont

        public void addBackupFont​(String name)
        Add a backup font to this style. If text cannot be displayed in the main font, the first backup font will be tried, and so on. Mainly useful for output formats like PDF that do not have automatic fallback with fonts
        Parameters:
        name - the name of the font to use
        Since:
        2.4.8
      • setRotate

        public void setRotate​(double val)
        Set the rotation of the text
        Parameters:
        val - the angle to rotate the text, in degrees clockwise from 12 o'clock
      • setAlign

        public void setAlign​(int align)
        Set the alignment of the text
        Parameters:
        align - a combination of one or more of the values from the Align class
      • setPaddingRight

        public void setPaddingRight​(double padding)
        Set the padding to the right of the text
        Parameters:
        padding - the padding to use, in pixels or whatever units are use by your Output class
      • setPaddingTop

        public void setPaddingTop​(double padding)
        Set the padding to the top of the text
        Parameters:
        padding - the padding to use, in pixels or whatever units are use by your Output class
      • setPaddingBottom

        public void setPaddingBottom​(double padding)
        Set the padding to the bottom of the text
        Parameters:
        padding - the padding to use, in pixels or whatever units are use by your Output class
      • setPaddingLeft

        public void setPaddingLeft​(double padding)
        Set the padding to the left of the text
        Parameters:
        padding - the padding to use, in pixels or whatever units are use by your Output class