Class FigmaReader

java.lang.Object
com.codename1.art.FigmaReader

public final class FigmaReader extends Object

Reads a Figma file from the JSON of Figma's REST API (GET /v1/files/:key) into an ArtDocument.

Request the file with geometry=paths: each node's outline then comes as SVG path data, which is drawn exactly -- boolean operations and vector networks included. Without it, rectangles, ellipses and frames are rebuilt from their sizes and other vectors are skipped with a note. FigmaClient fetches a file that way.

Every canvas (page) becomes a group under the root; the first is visible and the document is sized to its content. Frames, groups, components and instances keep their structure; fills, strokes, drop and inner shadows, layer and background blurs, blend modes, masks, opacity and text are read and rendered. Image fills are looked up by their imageRef.

  • Field Details

  • Method Details

    • read

      public static ArtDocument read(InputStream json, Map<String,byte[]> images) throws IOException

      Reads a file's JSON.

      Parameters
      • json: the API response; read to its end, not closed
      • images: image fill bytes keyed by imageRef, or null to leave image fills empty
      Throws:
      IOException
    • read

      public static ArtDocument read(byte[] json, Map<String,byte[]> images) throws IOException

      Reads a file's JSON from bytes.

      Parameters
      • json: the API response
      • images: image fill bytes keyed by imageRef, or null
      Throws:
      IOException
    • imageRefs

      public static List<String> imageRefs(Map<String,Object> json)

      The imageRef of every image fill in a file's JSON, so the caller can fetch them.

      Parameters
      • json: the parsed API response