Class ScreenMeasurer

java.lang.Object
com.codename1.wordprocessing.ScreenMeasurer
All Implemented Interfaces:
Measurer

public class ScreenMeasurer extends Object implements Measurer

Measures text with the platform fonts DocumentView draws it in.

The view's default. A layout measured with one font and drawn with another puts every run where the first font would have ended the previous one, so wider glyphs run into the next word. PdfMeasurer measures the PDF's fonts; use it on a view only when its pages must break exactly where the exported PDF's do.

Widths are measured at PIXELS_PER_POINT pixels per point and scaled back, so they do not depend on the size the view happens to draw at.

  • Constructor Details

    • ScreenMeasurer

      public ScreenMeasurer()
  • Method Details

    • font

      public Font font(TextStyle style, int px)

      The platform font a style is drawn in, at a pixel size.

      Parameters
      • style: the style

      • px: the size in pixels

      Returns

      the font

    • width

      public float width(String text, TextStyle style)
      Description copied from interface: Measurer

      The advance width of text drawn in a style.

      Parameters
      • text: the text, never containing a line break

      • style: the style

      Returns

      the width in points

      Specified by:
      width in interface Measurer
    • ascent

      public float ascent(TextStyle style)
      Description copied from interface: Measurer

      The distance from the top of a line of this style to its baseline.

      Parameters
      • style: the style
      Returns

      the ascent in points

      Specified by:
      ascent in interface Measurer
    • descent

      public float descent(TextStyle style)
      Description copied from interface: Measurer

      The distance from the baseline to the bottom of a line of this style.

      Parameters
      • style: the style
      Returns

      the descent in points, positive

      Specified by:
      descent in interface Measurer