Class Picture

java.lang.Object
com.codename1.wordprocessing.Picture
All Implemented Interfaces:
Block, Inline

public final class Picture extends Object implements Block, Inline
An immutable picture block: the original encoded image bytes, kept as they were read so a document written back carries the same image, plus its displayed size in points.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final String
    Where a floating picture sits across the column: LEFT, CENTER or RIGHT.
    static final String
    Floats behind the text, which ignores it.
    static final String
    Horizontal placement of a floating picture: centered in the column.
    final String
    Alternative text for readers that cannot show the picture.
    final float
    The gap kept between a floating picture and the text wrapped around it, in points.
    final float
    The displayed height in points.
    final String
    The block id.
    static final String
    Floats over the text, which ignores it.
    static final String
    Laid out in the line like a large character; the default.
    static final String
    Horizontal placement of a floating picture: at the left edge of the column.
    final String
    The MIME type of data(), such as image/png; empty for a linked picture.
    final float
    How far below the top of its anchor paragraph a floating picture starts, in points.
    static final String
    Horizontal placement of a floating picture: at the right edge of the column.
    final String
    The URL a linked picture names, as Markdown's ![alt](url) or HTML's <img src> gives it; null for a picture that holds its own bytes.
    static final String
    Floats at a side of the column; text wraps around its box.
    static final String
    Floats on lines of its own; no text beside it.
    final float
    The displayed width in points.
    final String
    How text flows around the picture: INLINE, SQUARE, TOP_BOTTOM, BEHIND or IN_FRONT.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Picture(String id, byte[] data, String mimeType, float width, float height, String description)
    Creates a picture.
  • Method Summary

    Modifier and Type
    Method
    Description
    byte[]
    The encoded image.
    int
    The size of the encoded image.
    A picture in a line reads as nothing in plain text.
    boolean
    Two pictures are equal when their id, bytes, source, type, size, description and placement are.
    int
    A hash consistent with equals.
    id()
    The block id.
    boolean
    Whether the picture floats instead of sitting in a line.
    boolean
    Whether the picture names its image by URL and holds no bytes.
    static Picture
    linked(String id, String source, float width, float height, String description)
    A picture that names its image by URL instead of holding it.
    withSize(float w, float h)
    A copy shown at another size.
    withWrap(String wrapMode, String alignment, float offset, float gap)
    A copy placed differently.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • id

      public final String id
      The block id.
    • mimeType

      public final String mimeType
      The MIME type of data(), such as image/png; empty for a linked picture.
    • source

      public final String source
      The URL a linked picture names, as Markdown's ![alt](url) or HTML's <img src> gives it; null for a picture that holds its own bytes. A linked picture has no bytes: HTML, Markdown and .cn1doc write the URL back, while DOCX, ODT, RTF, a page view and PDF export, which can only show an image they hold, leave its box empty or skip it.
    • width

      public final float width
      The displayed width in points.
    • height

      public final float height
      The displayed height in points.
    • description

      public final String description
      Alternative text for readers that cannot show the picture.
    • INLINE

      public static final String INLINE
      Laid out in the line like a large character; the default.
      See Also:
    • SQUARE

      public static final String SQUARE
      Floats at a side of the column; text wraps around its box.
      See Also:
    • TOP_BOTTOM

      public static final String TOP_BOTTOM
      Floats on lines of its own; no text beside it.
      See Also:
    • BEHIND

      public static final String BEHIND
      Floats behind the text, which ignores it.
      See Also:
    • IN_FRONT

      public static final String IN_FRONT
      Floats over the text, which ignores it.
      See Also:
    • LEFT

      public static final String LEFT
      Horizontal placement of a floating picture: at the left edge of the column.
      See Also:
    • CENTER

      public static final String CENTER
      Horizontal placement of a floating picture: centered in the column.
      See Also:
    • wrap

      public final String wrap
      How text flows around the picture: INLINE, SQUARE, TOP_BOTTOM, BEHIND or IN_FRONT.
    • align

      public final String align
      Where a floating picture sits across the column: LEFT, CENTER or RIGHT.
    • offsetY

      public final float offsetY
      How far below the top of its anchor paragraph a floating picture starts, in points.
    • distance

      public final float distance
      The gap kept between a floating picture and the text wrapped around it, in points.
  • Constructor Details

    • Picture

      public Picture(String id, byte[] data, String mimeType, float width, float height, String description)

      Creates a picture.

      Parameters
      • id: the block id

      • data: the encoded image; the array is copied

      • mimeType: its MIME type

      • width: the displayed width in points, greater than zero

      • height: the displayed height in points, greater than zero

      • description: alternative text, or null

  • Method Details

    • linked

      public static Picture linked(String id, String source, float width, float height, String description)

      A picture that names its image by URL instead of holding it.

      Parameters
      • id: the block id

      • source: the image URL, not empty

      • width: the displayed width in points, greater than zero

      • height: the displayed height in points, greater than zero

      • description: alternative text, or null

      Returns

      the picture

    • isLinked

      public boolean isLinked()

      Whether the picture names its image by URL and holds no bytes.

      Returns

      true when source is set

    • isFloating

      public boolean isFloating()

      Whether the picture floats instead of sitting in a line.

      Returns

      true unless the wrap is INLINE

    • withWrap

      public Picture withWrap(String wrapMode, String alignment, float offset, float gap)

      A copy placed differently.

      Parameters
      • wrapMode: INLINE, SQUARE, TOP_BOTTOM, BEHIND or IN_FRONT

      • alignment: LEFT, CENTER or RIGHT

      • offset: points below the top of the anchor paragraph

      • gap: points kept between the picture and wrapped text, 0 to 72

      Returns

      the copy

    • id

      public String id()

      The block id.

      Returns

      the id

      Specified by:
      id in interface Block
    • data

      public byte[] data()

      The encoded image.

      Returns

      a copy of the bytes; empty for a linked picture

    • dataLength

      public int dataLength()

      The size of the encoded image.

      Returns

      the byte count

    • withSize

      public Picture withSize(float w, float h)

      A copy shown at another size.

      Parameters
      • w: the width in points

      • h: the height in points

      Returns

      the copy

    • equals

      public boolean equals(Object o)

      Two pictures are equal when their id, bytes, source, type, size, description and placement are.

      Parameters
      • o: the other object
      Returns

      true when equal

      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()

      A hash consistent with equals.

      Returns

      the hash

      Overrides:
      hashCode in class Object
    • displayText

      public String displayText()

      A picture in a line reads as nothing in plain text.

      Returns

      the empty string

      Specified by:
      displayText in interface Inline