Record Class ImageBlock

java.lang.Object
java.lang.Record
com.nsdev.lettergenerator.model.block.ImageBlock
Record Components:
data - encoded PNG/JPEG/static SVG bytes; null is retained for generation-time validation
mimeType - exact supported MIME type, image/png, image/jpeg or image/svg+xml
widthMm - maximum rendered width in millimeters; required and positive at generation
heightMm - maximum rendered height in millimeters; required and positive at generation
style - nullable block overrides for alignment and spacing
altText - optional human-readable image description for tagged output
All Implemented Interfaces:
Block

public record ImageBlock(byte[] data, String mimeType, Double widthMm, Double heightMm, Style style, String altText) extends Record implements Block
PNG/JPEG/static SVG image scaled proportionally to fit an explicit box in millimeters. The rendered image participates in body flow or the containing positioned region. The block style controls alignment and surrounding spacing. Generation checks the MIME type, signature, decodability, positive finite dimensions, and available width.

The constructor and data() clone bytes, so callers cannot mutate stored image content. Equality and hashing use byte contents along with all other record components. The constructor itself does not validate the image.

  • Constructor Details

    • ImageBlock

      public ImageBlock(byte[] data, String mimeType, Double widthMm, Double heightMm, Style style, String altText)
      Defensively copies image bytes without decoding or validating the supplied properties.
      Parameters:
      data - bytes to clone, or null
      mimeType - declared image MIME type
      widthMm - image box width in millimeters
      heightMm - image box height in millimeters
      style - optional block overrides
      altText - optional accessible image description
    • ImageBlock

      public ImageBlock(byte[] data, String mimeType, Double widthMm, Double heightMm, Style style)
      Preserves construction without an image description.
      Parameters:
      data - image bytes
      mimeType - declared format
      widthMm - image box width
      heightMm - image box height
      style - optional style
  • Method Details

    • withAltText

      public ImageBlock withAltText(String value)
      Replaces the description while preserving the image and its geometry.
      Parameters:
      value - optional accessible description
      Returns:
      independent image block
    • withStyle

      public ImageBlock withStyle(Style value)
      Replaces local style overrides while preserving the description.
      Parameters:
      value - new style
      Returns:
      independent image block
    • data

      public byte[] data()
      Returns a defensive copy of the encoded image.
      Returns:
      a new byte array, or null when no bytes were supplied
    • equals

      public boolean equals(Object other)
      Compares image byte contents and every other record component.
      Specified by:
      equals in class Record
      Parameters:
      other - object to compare, possibly null
      Returns:
      true for an image block with equal bytes and other components
    • hashCode

      public int hashCode()
      Hashes byte contents and every other record component consistently with equality.
      Specified by:
      hashCode in class Record
      Returns:
      content-based hash code
    • 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
    • mimeType

      public String mimeType()
      Returns the value of the mimeType record component.
      Returns:
      the value of the mimeType record component
    • widthMm

      public Double widthMm()
      Returns the value of the widthMm record component.
      Returns:
      the value of the widthMm record component
    • heightMm

      public Double heightMm()
      Returns the value of the heightMm record component.
      Returns:
      the value of the heightMm record component
    • style

      public Style style()
      Returns the value of the style record component.
      Specified by:
      style in interface Block
      Returns:
      the value of the style record component
    • altText

      public String altText()
      Returns the value of the altText record component.
      Returns:
      the value of the altText record component