Record Class TextMetrics

java.lang.Object
java.lang.Record
cloud.opencode.base.image.codec.font.TextMetrics
Record Components:
width - horizontal advance in pixels | 水平 advance(像素)
ascent - pixels above baseline (positive) | 基线以上像素(正)
descent - pixels below baseline (negative per stb convention) | 基线以下像素(按 stb 约定为负)
lineGap - recommended extra gap between lines in pixels | 建议的额外行间隔(像素)

public record TextMetrics(int width, int ascent, int descent, int lineGap) extends Record
Pixel-space metrics for a text run rendered at a specific pixel height. 给定像素高度下,一段文本的像素空间度量。

All values are in pixels at the requested font size. Per stb_truetype convention, descent is negative (below the baseline). Use lineHeight() to get the natural single-line height including lineGap.

所有值为请求字号下的像素值。按 stb_truetype 约定,descent 为负(基线以下)。使用 lineHeight() 获取包含 lineGap 的自然 单行高度。

Security | 安全性:

  • Thread-safe: Yes - immutable record. - 线程安全: 是 — 不可变 record。
Since:
JDK 25, opencode-base-image-codec V1.0.4
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    TextMetrics(int width, int ascent, int descent, int lineGap)
    Creates an instance of a TextMetrics record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the value of the ascent record component.
    int
    Returns the value of the descent record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    int
    Returns the value of the lineGap record component.
    int
    Total line height: ascent - descent + lineGap.
    final String
    Returns a string representation of this record class.
    int
    Returns the value of the width record component.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • TextMetrics

      public TextMetrics(int width, int ascent, int descent, int lineGap)
      Creates an instance of a TextMetrics record class.
      Parameters:
      width - the value for the width record component
      ascent - the value for the ascent record component
      descent - the value for the descent record component
      lineGap - the value for the lineGap record component
  • Method Details

    • lineHeight

      public int lineHeight()
      Total line height: ascent - descent + lineGap. 总行高:ascent - descent + lineGap
      Returns:
      line height in pixels | 像素行高
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • width

      public int width()
      Returns the value of the width record component.
      Returns:
      the value of the width record component
    • ascent

      public int ascent()
      Returns the value of the ascent record component.
      Returns:
      the value of the ascent record component
    • descent

      public int descent()
      Returns the value of the descent record component.
      Returns:
      the value of the descent record component
    • lineGap

      public int lineGap()
      Returns the value of the lineGap record component.
      Returns:
      the value of the lineGap record component