Class LabelPainter


  • public class LabelPainter
    extends Object
    This class performs the layouting and painting of the single label (leaving the label cache the task to sort labels and locate the best label points)
    Author:
    Andrea Aime
    • Method Detail

      • setLabel

        public void setLabel​(LabelCacheItem labelItem)
        Sets the current label. The label will be laid out according to the label item settings (curved lines, auto wrapping, curved line usage) and the painter will be ready to draw it.
      • getLabel

        public LabelCacheItem getLabel()
        Returns the current label item
      • getLineHeight

        public double getLineHeight()
        Returns the line height for this label in pixels (for multiline labels, it's the height of the first line)
      • getLineHeightForAnchorY

        public double getLineHeightForAnchorY​(double anchorY)
        Returns appropriate line height for the given displacemntY Should give Top line for max displacementY (1) and Bottom line for min displacemntY (0)
        Returns:
        height of appropriate line for passed label displacementY
      • getAscent

        public double getAscent()
        The full size above the baseline
      • getStraightLabelWidth

        public int getStraightLabelWidth()
        Returns the width of the label, as painted in straight form (
      • getLineCount

        public int getLineCount()
        Number of lines for this label (more than 1 if the label has embedded newlines or if we're auto-wrapping it)
      • getFullLabelBounds

        public Rectangle2D getFullLabelBounds()
        Get the straight label bounds, taking into account halo, shield and line wrapping
      • getLabelBounds

        public Rectangle2D getLabelBounds()
        Get the straight label bounds, without taking into account halo and shield
      • paintStraightLabel

        public void paintStraightLabel​(AffineTransform transform)
                                throws Exception
        Paints the label as a non curved one. The positioning and rotation are provided by the transformation
        Throws:
        Exception
      • paintStraightLabel

        public void paintStraightLabel​(AffineTransform transform,
                                       Coordinate labelPoint)
                                throws Exception
        Paints the label as a non curved one. The positioning and rotation are provided by the transformation
        Throws:
        Exception
      • paintCurvedLabel

        public void paintCurvedLabel​(LineStringCursor cursor)
        Paints a label that follows the line, centered in the current cursor position
      • getLinePlacementYAnchor

        public double getLinePlacementYAnchor()
        Vertical centering is not trivial, because visually we want centering on characters such as a,m,e, and not centering on d,g whose center is affected by the full ascent or the full descent. This method tries to computes the y anchor taking into account those.