Skip to content

graphics ​

原文: https://finproducts.atlassian.net/wiki/spaces/JIDD3/pages/34793455665/FIN+5.3.1+graphics 中文整理基于 FIN 5.3.1

导读: @Serializable

以下为 API 参考,保留英文以便对照源码;目录已列出(英文标题便于检索);概述已尽量中译。


目录(导读) ​

  • mixins
  • classes
  • enums
  • Slot Details
    • a
    • asColorPaint
    • b
    • black
    • darker
    • desaturate
    • equals
    • fromStr
    • g
    • h
    • hash
    • interpolateHsl
    • interpolateRgb
    • isColorPaint
    • isTransparent
    • l
    • lighter
    • make
    • makeHsl
    • makeRgb
    • opacity
    • r
    • rgb
    • s
    • saturate
    • toHexStr
    • toStr
    • transparent
    • white
    • fromProps
    • name
    • names
    • size
    • style
    • toProps
    • toSize
    • toStyle
    • toWeight
    • weight
    • ascent
    • descent
    • height
    • leading
    • width
    • isNormal
    • italic
    • normal
    • oblique
    • vals
    • bold
    • extraBold
    • extraLight
    • fromNum
    • light
    • medium
    • num
    • semiBold
    • thin
    • alpha
    • clipRect
    • clipRoundRect
    • color
    • dispose
    • drawEllipse
    • drawImage
    • drawImageRegion
    • drawLine
    • drawRect
    • drawRoundRect
    • drawText
    • fillEllipse
    • fillRect
    • fillRoundRect
    • font
    • metrics
    • paint
    • path
    • pop
    • push
    • stroke
    • transform
    • translate
    • cur
    • image
    • arc
    • clip
    • close
    • curveTo
    • draw
    • fill
    • lineTo
    • moveTo
    • quadTo
    • isLoaded
    • mime
    • render
    • uri
    • w
    • write
    • bottom
    • defVal
    • isNone
    • left
    • right
    • top
    • makeInt
    • x
    • y
    • contains
    • intersection
    • intersects
    • makePosSize
    • pos
    • union
    • cap
    • dash
  • …(其余标题见英文正文)

API 正文(英文) ​

enums ​

FontStyleFont style property values: normal, italic, oblique
FontWeightFont weight property values
StrokeCapDefines how a stroke end cap is rendered
StrokeJoinDefines how two stroke lines are joined together

Color ​

@Js @Serializable { simple=true } const class Color : Obj, Paint

Models an CSS4 RGB color with alpha

Constructors

fromStrParse color from CSS 4 string.
makeMake a new instance with the RGB components masked together: bits 16-23 red; bits 8-15 green; bits 0-7 blue.

Fields

aThe alpha component from 0.0 to 1.0
blackBlack is #000
rgbThe RGB components masked together: bits 16-23 red; bits 8-15 green; bits 0-7 blue.
transparentTransparent constant with opacity set to zero
whiteWhite is #FFF

Methods

asColorPaintReturn this
bThe blue component from 0 to 255.
darkerGet a color which is a dark shade of this color.
desaturateConvenience for saturate(-percentage).
equalsEquality
gThe green component from 0 to 255.
hHue as a float between 0.0 and 360.0 of the HSL model (hue, saturation, lightness).
hashReturn the hash code.
interpolateHslInterpolate between a and b where t is 0.0 to 1.0 using HSL color model.
interpolateRgbInterpolate between a and b where t is 0.0 to 1.0 using RGB color model.
isColorPaintAlways return true
isTransparentReturn if a is zero, fully transparent
lLightness (brightness) as a float between 0.0 and 1.0 of the HSL model (hue, saturation, lightness).
lighterGet a color which is a lighter shade of this color.
makeHslConstruct a color using HSL model (hue, saturation, lightness)
makeRgbMake a new instance with the RGB individual components as integers between 0 and 255 and alpha as float between 1.0 and 0.0.
opacityAdjust the opacity of this color and return new instance, where opacity is between 0.0 and 1.0.
rThe red component from 0 to 255.
sSaturation as a float between 0.0 and 1.0 of the HSL model (hue, saturation, lightness).
saturateAdjust saturation as percentage between -1..1.
toHexStrFormat as #RGB, #RRGGBB or #RRGGBBAA syntax
toStrIf the alpha component is 1.0, then format as "#RRGGBB" hex string, otherwise format as "rbga()" notation.

Slot Details ​


a ​

const Float a

The alpha component from 0.0 to 1.0


asColorPaint ​

virtual override Color asColorPaint()

Return this


b ​

Int b()

The blue component from 0 to 255.


black ​

const static Color black := Color.make(0, 1.0)

Black is #000


darker ​

Color darker(Float percentage := 0.2f)

Get a color which is a dark shade of this color. This decreases the brightness by the given percentage which is a float between 0.0 and 1.0.


desaturate ​

Color desaturate(Float percentage := 0.2f)

Convenience for saturate(-percentage).


equals ​

virtual override Bool equals(Obj? that)

Equality


fromStr ​

static new fromStr(Str s, Bool checked := true)

Parse color from CSS 4 string. If invalid and checked is true then throw ParseErr otherwise return null. The following formats are supported:

  • CSS keyword color
  • #RRGGBB
  • #RRGGBBAA
  • #RGB
  • #RGBA
  • rgb(r, g b)
  • rgba(r, g, b, a)
  • hsl(h, s, l)
  • hsla(h, s, l, a)

Functional notation works with comma or space separated arguments.

Examples:

Color.fromStr("red")
Color.fromStr("#8A0")
Color.fromStr("#88AA00")
Color.fromStr("rgba(255, 0, 0, 0.3)")
Color.fromStr("rgb(100% 0% 0% 25%)")

g ​

Int g()

The green component from 0 to 255.


h ​

Float h()

Hue as a float between 0.0 and 360.0 of the HSL model (hue, saturation, lightness). Also see makeHsl, s, l.


hash ​

virtual override Int hash()

Return the hash code.


interpolateHsl ​

static Color interpolateHsl(Color a, Color b, Float t)

Interpolate between a and b where t is 0.0 to 1.0 using HSL color model.


interpolateRgb ​

static Color interpolateRgb(Color a, Color b, Float t)

Interpolate between a and b where t is 0.0 to 1.0 using RGB color model.


isColorPaint ​

virtual override Bool isColorPaint()

Always return true


isTransparent ​

Bool isTransparent()

Return if a is zero, fully transparent


l ​

Float l()

Lightness (brightness) as a float between 0.0 and 1.0 of the HSL model (hue, saturation, lightness). Also see makeHsl, h, s.


lighter ​

Color lighter(Float percentage := 0.2f)

Get a color which is a lighter shade of this color. This increases the brightness by the given percentage which is a float between 0.0 and 1.0.


make ​

new make(Int rgb := 0, Float a := 1.0f)

Make a new instance with the RGB components masked together: bits 16-23 red; bits 8-15 green; bits 0-7 blue. Alpha should be a float between 1.0 and 0.0.


makeHsl ​

static Color makeHsl(Float h, Float s, Float l, Float a := 1.0f)

Construct a color using HSL model (hue, saturation, lightness):

  • hue as 0.0 to 360.0
  • saturation as 0.0 to 1.0
  • lightness (or brightness) as 0.0 to 1.0
  • alpha as 0.0 to 1.0 Also see h, s, l.

makeRgb ​

static Color makeRgb(Int r, Int g, Int b, Float a := 1.0f)

Make a new instance with the RGB individual components as integers between 0 and 255 and alpha as float between 1.0 and 0.0.


opacity ​

Color opacity(Float opacity := 1.0f)

Adjust the opacity of this color and return new instance, where opacity is between 0.0 and 1.0.


r ​

Int r()

The red component from 0 to 255.


rgb ​

const Int rgb

The RGB components masked together: bits 16-23 red; bits 8-15 green; bits 0-7 blue.


s ​

Float s()

Saturation as a float between 0.0 and 1.0 of the HSL model (hue, saturation, lightness). Also see makeHsl, h, l.


saturate ​

Color saturate(Float percentage := 0.2f)

Adjust saturation as percentage between -1..1.


toHexStr ​

Str toHexStr()

Format as #RGB, #RRGGBB or #RRGGBBAA syntax


toStr ​

virtual override Str toStr()

If the alpha component is 1.0, then format as "#RRGGBB" hex string, otherwise format as "rbga()" notation.


transparent ​

const static Color transparent := Color.make(0, 0.0)

Transparent constant with opacity set to zero


white ​

const static Color white := Color.make(16777215, 1.0)

White is #FFF


Font ​

@Js @Serializable { simple=true } const class Font : Obj

Font models font-family, font-size, and font-style, and font-weight. Metrics are available for a predefined set of fonts.

Constructors

fromPropsConstruct from a map of CSS props such as font-family, font-size.
fromStrParse font from string using CSS shorthand format for supported properties
makeConstruct with it-block

Fields

namesList of prioritized family names
sizeSize of font in points.
styleStyle as normal, italic, or oblique
weightWeight as number from 100 to 900

Methods

equalsEquality is based on all fields.
hashReturn hash of all fields
nameFirst family name in names
toPropsGet CSS style properties for this font.
toSizeReturn this font with different point size.
toStrFormat as "[style] [weight] <size>pt <names>"
toStyleReturn this font with different style
toWeightReturn this font with different weight.

Slot Details ​


equals ​

virtual override Bool equals(Obj? that)

Equality is based on all fields.


fromProps ​

static new fromProps(Str:Str props)

Construct from a map of CSS props such as font-family, font-size. Also see toProps.


fromStr ​

static new fromStr(Str s, Bool checked := true)

Parse font from string using CSS shorthand format for supported properties:

[<style>] [<weight>] <size> <names>

Examples:

Font.fromStr("12pt Arial")
Font.fromStr("bold 10pt Courier")
Font.fromStr("italic bold 8pt Times")
Font.fromStr("italic 300 10pt sans-serif")

hash ​

virtual override Int hash()

Return hash of all fields


make ​

new make(|This| f)

Construct with it-block


name ​

Str name()

First family name in names


names ​

const Str[] names := Str["sans-serif"]

List of prioritized family names


size ​

const Float size := 11.0f

Size of font in points.


style ​

const FontStyle style := FontStyle.normal

Style as normal, italic, or oblique


toProps ​

Str:Str toProps()

Get CSS style properties for this font. Also see fromProps


toSize ​

Font toSize(Float size)

Return this font with different point size.


toStr ​

virtual override Str toStr()

Format as "[style] [weight] <size>pt <names>"


toStyle ​

Font toStyle(FontStyle style)

Return this font with different style


toWeight ​

Font toWeight(FontWeight weight)

Return this font with different weight.


weight ​

const FontWeight weight := FontWeight.normal

Weight as number from 100 to 900


FontMetrics ​

@Js abstract const class FontMetrics : Obj

FontMetrics represents font size information for a Font within a specific graphics context.

Methods

ascentGet ascent of this font which is the distance from baseline to top of chars, not including any leading area.
descentGet descent of this font which is the distance from baseline to bottom of chars, not including any leading area.
heightGet height of this font which is the sum of ascent, descent, and leading.
leadingGet leading of this font which is the distance above the ascent which may include accents and other marks.
widthGet the width of the string when painted with this font.

Slot Details ​


ascent ​

abstract Float ascent()

Get ascent of this font which is the distance from baseline to top of chars, not including any leading area.


descent ​

abstract Float descent()

Get descent of this font which is the distance from baseline to bottom of chars, not including any leading area.


height ​

abstract Float height()

Get height of this font which is the sum of ascent, descent, and leading.


leading ​

abstract Float leading()

Get leading of this font which is the distance above the ascent which may include accents and other marks.


width ​

abstract Float width(Str s)

Get the width of the string when painted with this font.


FontStyle ​

@Js @Serializable { simple=true } enum class FontStyle : Enum

Font style property values: normal, italic, oblique

Enum

normal
italic
oblique

Constructors

fromStrReturn the FontStyle instance for the specified name.

Fields

valsList of FontStyle values indexed by ordinal

Methods

isNormalIs this the normal value

Slot Details ​


fromStr ​

static new fromStr(Str name, Bool checked := true)

Return the FontStyle instance for the specified name. If not a valid name and checked is false return null, otherwise throw ParseErr.


isNormal ​

Bool isNormal()

Is this the normal value


italic ​

const static FontStyle italic := ...


normal ​

const static FontStyle normal := ...


oblique ​

const static FontStyle oblique := ...


vals ​

const static FontStyle[] vals := ...

List of FontStyle values indexed by ordinal


FontWeight ​

@Js @Serializable { simple=true } enum class FontWeight : Enum

Font weight property values

Enum

thin
extraLight
light
normal
medium
semiBold
bold
extraBold
black

Constructors

fromStrReturn the FontWeight instance for the specified name.

Fields

numNumeric weight as number from 100 to 900
valsList of FontWeight values indexed by ordinal

Methods

fromNumFrom numeric value 100 to 900
isNormalIs this the normal value

Slot Details ​


black ​

const static FontWeight black := ...


bold ​

const static FontWeight bold := ...


extraBold ​

const static FontWeight extraBold := ...


extraLight ​

const static FontWeight extraLight := ...


fromNum ​

static FontWeight? fromNum(Int num, Bool checked := true)

From numeric value 100 to 900


fromStr ​

static new fromStr(Str name, Bool checked := true)

Return the FontWeight instance for the specified name. If not a valid name and checked is false return null, otherwise throw ParseErr.


isNormal ​

Bool isNormal()

Is this the normal value


light ​

const static FontWeight light := ...


medium ​

const static FontWeight medium := ...


normal ​

const static FontWeight normal := ...


num ​

const Int num

Numeric weight as number from 100 to 900


semiBold ​

const static FontWeight semiBold := ...


thin ​

const static FontWeight thin := ...


vals ​

const static FontWeight[] vals := ...

List of FontWeight values indexed by ordinal


Graphics ​

@Js mixin Graphics

Graphics is used to draw 2D graphics.

Fields

alphaGlobal alpha value used to control opacity for rending.
colorConvenience for setting paint to a solid color.
fontCurrent font used for drawing text
paintCurrent paint defines how text and shapes are stroked and filled
strokeCurrent stroke defines how the shapes are outlined

Methods

clipRectConvenience to clip the given the rectangle.
clipRoundRectClip a rectangle with rounded corners with the current paint.
disposeDispose of this graphics context and release underyling OS resources.
drawEllipseDraw an ellipse within the given bounds with the current stroke and paint.
drawImageDraw an image at the given coordinate for the top/left corner.
drawImageRegionDraw a rectangular region of the source image to the drawing surface.
drawLineDraw a line with the current stroke and paint.
drawRectDraw a rectangle with the current stroke and paint.
drawRoundRectDraw a rectangle with rounded corners with the current stroke and paint.
drawTextDraw a the text string with the current paint and font.
fillEllipseFill an ellipse within the given bounds with the current stroke and paint.
fillRectFill a rectangle with the current paint.
fillRoundRectFill a rectangle with rounded corners with the current paint.
metricsGet font metrics for the current font
pathBegin a new path operation to stroke, fill, or clip a shape.
popPop the graphics stack and reset the state to the the last push.
pushPush the current graphics state onto an internal stack.
transformPerform an affine transformation on the coordinate system
translateTranslate the coordinate system to the new origin.

Slot Details ​


alpha ​

abstract Float alpha

Global alpha value used to control opacity for rending. The value must be between 0.0 (transparent) and 1.0 (opaue).


clipRect ​

abstract This clipRect(Float x, Float y, Float w, Float h)

Convenience to clip the given the rectangle. This sets the clipping area to the intersection of the current clipping region and the specified rectangle.


clipRoundRect ​

abstract This clipRoundRect(Float x, Float y, Float w, Float h, Float wArc, Float hArc)

Clip a rectangle with rounded corners with the current paint. The ellipse of the corners is specified by wArc and hArc.


color ​

abstract Color color

Convenience for setting paint to a solid color. If the paint is currently not a solid color, then get returns Paint.asColorPaint.


dispose ​

abstract Void dispose()

Dispose of this graphics context and release underyling OS resources.


drawEllipse ​

abstract This drawEllipse(Float x, Float y, Float w, Float h)

Draw an ellipse within the given bounds with the current stroke and paint.


drawImage ​

abstract This drawImage(Image img, Float x, Float y, Float w := img.w(), Float h := img.h())

Draw an image at the given coordinate for the top/left corner. If the width or height does not correspond to the image's natural size then the image is scaled to fit.


drawImageRegion ​

abstract This drawImageRegion(Image img, Rect src, Rect dst)

Draw a rectangular region of the source image to the drawing surface. The src rectangle defines the subregion of the source image to use. The dst rectangle identifies the destination location. If the src size does not correspond to the dst size, then the image is scaled to fit.


drawLine ​

abstract This drawLine(Float x1, Float y1, Float x2, Float y2)

Draw a line with the current stroke and paint.


drawRect ​

abstract This drawRect(Float x, Float y, Float w, Float h)

Draw a rectangle with the current stroke and paint.


drawRoundRect ​

abstract This drawRoundRect(Float x, Float y, Float w, Float h, Float wArc, Float hArc)

Draw a rectangle with rounded corners with the current stroke and paint. The ellipse of the corners is specified by wArc and hArc.


drawText ​

abstract This drawText(Str s, Float x, Float y)

Draw a the text string with the current paint and font. The x, y coordinate specifies the left baseline corner of where the text is to be drawn. Technically this is a fill operation similiar to the Canvas fillText function (there is currently no support to stroke/outline text).


fillEllipse ​

abstract This fillEllipse(Float x, Float y, Float w, Float h)

Fill an ellipse within the given bounds with the current stroke and paint.


fillRect ​

abstract This fillRect(Float x, Float y, Float w, Float h)

Fill a rectangle with the current paint.


fillRoundRect ​

abstract This fillRoundRect(Float x, Float y, Float w, Float h, Float wArc, Float hArc)

Fill a rectangle with rounded corners with the current paint. The ellipse of the corners is specified by wArc and hArc.


font ​

abstract Font font

Current font used for drawing text


metrics ​

abstract FontMetrics metrics()

Get font metrics for the current font


paint ​

abstract Paint paint

Current paint defines how text and shapes are stroked and filled


path ​

abstract GraphicsPath path()

Begin a new path operation to stroke, fill, or clip a shape.


pop ​

abstract This pop()

Pop the graphics stack and reset the state to the the last push.


push ​

abstract This push(Rect? r := null)

Push the current graphics state onto an internal stack. Reset the state back to its current state via pop. If r is non-null, the graphics state is automatically translated and clipped to the bounds.


stroke ​

abstract Stroke stroke

Current stroke defines how the shapes are outlined


transform ​

abstract This transform(Transform transform)

Perform an affine transformation on the coordinate system


translate ​

abstract This translate(Float x, Float y)

Translate the coordinate system to the new origin. This call is a convenience for:

transform(Transform.translate(x, y))

GraphicsEnv ​

@Js const mixin GraphicsEnv

GraphicsEnv encapsulates a graphics toolkit. It is responsible image loading and caching.

Methods

curDefault environment for the VM
imageGet an image for the given uri.

Slot Details ​


cur ​

static GraphicsEnv cur()

Default environment for the VM


image ​

abstract Image image(Uri uri, Buf? data := null)

Get an image for the given uri. The uri is the unique key for the image in this environment. If file data is null, then asynchronously load and cache the image on the first load. Standard supported formats are: PNG, JPEG, and SVG.


GraphicsPath ​

@Js mixin GraphicsPath

GraphicsPath is used to path complex shapes for stroking, filling, and clipping.

Methods

arcCreate circular arc centered at x, y with given radius.
clipIntersect the current clipping shape with this path.
closeClose the path by add a line from current point back to starting point.
curveToAdd a Bézier curve to the path.
drawStroke the the current path using current stroke and paint.
fillFill the current path with current paint.
lineToAdd a line to the path from current point to given point.
moveToMove the current point without creating a line.
quadToAdd a quadratic Bézier curve to the path.

Slot Details ​


arc ​

abstract This arc(Float x, Float y, Float radius, Float start, Float sweep)

Create circular arc centered at x, y with given radius. The start angle and sweep angle are measured in degrees. East is 0°, north 90°, west is 180°, and south is 270°. Positive sweeps are counterclockwise and negative sweeps are clockwise.


clip ​

abstract This clip()

Intersect the current clipping shape with this path. This call terminates the current pathing operation.


close ​

abstract This close()

Close the path by add a line from current point back to starting point.


curveTo ​

abstract This curveTo(Float cp1x, Float cp1y, Float cp2x, Float cp2y, Float x, Float y)

Add a Bézier curve to the path. The cp1 and cp2 parameters specify the first and second control points; x and y specify the end point.


draw ​

abstract This draw()

Stroke the the current path using current stroke and paint. This call terminates the current pathing operation.


fill ​

abstract This fill()

Fill the current path with current paint. This call terminates the current pathing operation.


lineTo ​

abstract This lineTo(Float x, Float y)

Add a line to the path from current point to given point.


moveTo ​

abstract This moveTo(Float x, Float y)

Move the current point without creating a line.


quadTo ​

abstract This quadTo(Float cpx, Float cpy, Float x, Float y)

Add a quadratic Bézier curve to the path. The cpx and cpy specify the control point; the x and y specify the end point.


Image ​

@Js mixin Image

Graphical image. Images are loaded from a file using GraphicsEnv.image.

Methods

hGet the size height
isLoadedIs this image completely loaded into memory for use.
mimeImage format based on file type
renderRender a new image with the given MIME type and size using the provided Graphics instance.
sizeGet the natural size of this image.
uriUnique uri key for this image in the GraphicsEnv cache.
wGet the size width
writeWrite image content to the given output stream, where encoding is based on mime type.

Slot Details ​


h ​

virtual Float h()

Get the size height


isLoaded ​

abstract Bool isLoaded()

Is this image completely loaded into memory for use. When a given uri is first accessed by GraphicsEnv.image it may be asynchronously loaded in the background and false is returned until load is complete.


mime ​

abstract MimeType mime()

Image format based on file type:

  • image/png
  • image/gif
  • image/jpeg
  • image/svg+xml

render ​

static Image render(MimeType mime, Size size, |Graphics| f)

Render a new image with the given MIME type and size using the provided Graphics instance. Throws UnsupportedErr if rendering is not supported in this env.


size ​

abstract Size size()

Get the natural size of this image. If the image has not been loaded yet, then return 0,0.


uri ​

abstract Uri uri()

Unique uri key for this image in the GraphicsEnv cache.


w ​

virtual Float w()

Get the size width


write ​

virtual Void write(OutStream out)

Write image content to the given output stream, where encoding is based on mime type. Throws UnsupportedErr if write is not supported in this env.


Insets ​

@Js @Serializable { simple=true } const class Insets : Obj

Insets represents spacing around the edge of a rectangle.

Constructors

fromStrParse from comma or space separated string using CSS format
makeConstruct with top, and optional right, bottom, left.

Fields

bottomBottom side spacing
defValDefault instance 0, 0, 0, 0.
leftLeft side spacing
rightRight side spacing
topTop side spacing

Methods

equalsReturn if obj is same Insets value.
hTop plus bottom
hashReturn hash of top, right, bottom, left.
isNoneReturn if all sides are set to zero
toSizeReturn right+left, top+bottom
toStrIf all four sides are equal return "len" otherwise return "top right bottom left".
wLeft plus right

Slot Details ​


bottom ​

const Float bottom

Bottom side spacing


defVal ​

const static Insets defVal := ...

Default instance 0, 0, 0, 0.


equals ​

virtual override Bool equals(Obj? obj)

Return if obj is same Insets value.


fromStr ​

static new fromStr(Str s, Bool checked := true)

Parse from comma or space separated string using CSS format:

  • "top"
  • "top, right" (implies bottom = top, left = right)
  • "top, right, bottom" (implies left = right)
  • "top, right, bottom, left"

h ​

Float h()

Top plus bottom


hash ​

virtual override Int hash()

Return hash of top, right, bottom, left.


isNone ​

Bool isNone()

Return if all sides are set to zero


left ​

const Float left

Left side spacing


make ​

new make(Num top, Num? right := null, Num? bottom := null, Num? left := null)

Construct with top, and optional right, bottom, left. If one side is not specified, it is reflected from the opposite side:

Insets(5)     => Insets(5,5,5,5)
Insets(5,6)   => Insets(5,6,5,6)
Insets(5,6,7) => Insets(5,6,7,6)

const Float right

Right side spacing


toSize ​

Size toSize()

Return right+left, top+bottom


toStr ​

virtual override Str toStr()

If all four sides are equal return "len" otherwise return "top right bottom left".


top ​

const Float top

Top side spacing


w ​

Float w()

Left plus right


Paint ​

@Js const mixin Paint

Paint models the color, image, or pattern used to stroke or fill a shape. Currently there is only one implementation: Color.

Methods

asColorPaintReturn as solid Color
isColorPaintIs this solid color paint

Slot Details ​


asColorPaint ​

abstract Color asColorPaint()

Return as solid Color


isColorPaint ​

abstract Bool isColorPaint()

Is this solid color paint


Point ​

@Js @Serializable { simple=true } const class Point : Obj

Point models a x,y coordinate.

Constructors

fromStrParse from comma or space separated string.
makeConstruct with x, y.
makeIntConstruct with x, y.

Fields

defValDefault instance is 0,0.
xX coordinate
yY coordinate

Methods

equalsReturn if obj is same Point value.
hashReturn hash of x and y.
toStrReturn "x y"
translateReturn x+tx, y+ty

Slot Details ​


defVal ​

const static Point defVal := Point.<ctor>(0.0, 0.0)

Default instance is 0,0.


equals ​

virtual override Bool equals(Obj? obj)

Return if obj is same Point value.


fromStr ​

static new fromStr(Str s, Bool checked := true)

Parse from comma or space separated string. If invalid then throw ParseErr or return null based on checked flag.


hash ​

virtual override Int hash()

Return hash of x and y.


make ​

new make(Float x, Float y)

Construct with x, y.


makeInt ​

new makeInt(Int x, Int y)

Construct with x, y.


toStr ​

virtual override Str toStr()

Return "x y"


translate ​

Point translate(Point t)

Return x+tx, y+ty


x ​

const Float x

X coordinate


y ​

const Float y

Y coordinate


Rect ​

@Js @Serializable { simple=true } const class Rect : Obj

Represents the x,y coordinate and w,h size of a rectangle.

Constructors

fromStrParse from comma or space separated string.
makeConstruct with x, y, w, h.
makeIntConstruct with x, y, w, h as integers.
makePosSizeConstruct from a Point and Size instance

Fields

defValDefault instance is 0, 0, 0, 0.
hHeight
wWidth
xX coordinate
yY coordinate

Methods

containsReturn true if x,y is inside the bounds of this rectangle.
equalsReturn if obj is same Rect value.
hashReturn hash of x, y, w, and h.
intersectionCompute the intersection between this rectangle and that rectangle.
intersectsReturn true if this rectangle intersects any portion of that rectangle
posGet the x, y coordinate of this rectangle.
sizeGet the w, h size of this rectangle.
toStrReturn "x y w h"
unionCompute the union between this rectangle and that rectangle, which is the bounding box that exactly contains both rectangles.

Slot Details ​


contains ​

Bool contains(Point pt)

Return true if x,y is inside the bounds of this rectangle.


defVal ​

const static Rect defVal := Rect.<ctor>(0.0, 0.0, 0.0, 0.0)

Default instance is 0, 0, 0, 0.


equals ​

virtual override Bool equals(Obj? obj)

Return if obj is same Rect value.


fromStr ​

static new fromStr(Str s, Bool checked := true)

Parse from comma or space separated string. If invalid then throw ParseErr or return null based on checked flag.


h ​

const Float h

Height


hash ​

virtual override Int hash()

Return hash of x, y, w, and h.


intersection ​

Rect intersection(Rect that)

Compute the intersection between this rectangle and that rectangle. If there is no intersection, then return defVal.


intersects ​

Bool intersects(Rect that)

Return true if this rectangle intersects any portion of that rectangle


make ​

new make(Float x, Float y, Float w, Float h)

Construct with x, y, w, h.


makeInt ​

new makeInt(Int x, Int y, Int w, Int h)

Construct with x, y, w, h as integers.


makePosSize ​

new makePosSize(Point p, Size s)

Construct from a Point and Size instance


pos ​

Point pos()

Get the x, y coordinate of this rectangle.


size ​

Size size()

Get the w, h size of this rectangle.


toStr ​

virtual override Str toStr()

Return "x y w h"


union ​

Rect union(Rect that)

Compute the union between this rectangle and that rectangle, which is the bounding box that exactly contains both rectangles.


w ​

const Float w

Width


x ​

const Float x

X coordinate


y ​

const Float y

Y coordinate


Size ​

@Js @Serializable { simple=true } const class Size : Obj

Size models the width and height of a shape.

Constructors

fromStrParse from comma or space separated string.
makeConstruct with w, h.
makeIntConstruct with w, h as integers.

Fields

defValDefault instance is 0,0.
hHeight
wWidth

Methods

equalsReturn if obj is same Size value.
hashReturn hash of w and h.
toStrReturn "w h"

Slot Details ​


defVal ​

const static Size defVal := Size.<ctor>(0.0, 0.0)

Default instance is 0,0.


equals ​

virtual override Bool equals(Obj? obj)

Return if obj is same Size value.


fromStr ​

static new fromStr(Str s, Bool checked := true)

Parse from comma or space separated string. If invalid then throw ParseErr or return null based on checked flag.


h ​

const Float h

Height


hash ​

virtual override Int hash()

Return hash of w and h.


make ​

new make(Float w, Float h)

Construct with w, h.


makeInt ​

new makeInt(Int w, Int h)

Construct with w, h as integers.


toStr ​

virtual override Str toStr()

Return "w h"


w ​

const Float w

Width


Stroke ​

@Js @Serializable { simple=true } const class Stroke : Obj

Stroke defines the how to render shape outlines.

Constructors

fromStrParse from string format
makeMake with an it-block
makeFieldsMake with fields

Fields

capHow to render line end caps.
dashDash pattern as space/comma separated numbers of dashes and gaps.
defValDefault value is width 1, no dash, butt cap, miter join.
joinHow to render line joins.
noneValue with width of zero
widthStroke width.

Methods

equalsEquality is based on fields
hashHash is based on fields
isNoneIs the width set to zero
scaleScale size and dash pattern by given ratio
toSizeReturn this stroke with different width.
toStrReturn string format - see fromStr

Slot Details ​


cap ​

const StrokeCap cap := StrokeCap.butt

How to render line end caps. Default is butt.


dash ​

const Str? dash

Dash pattern as space/comma separated numbers of dashes and gaps. If null then render as solid line.


defVal ​

const static Stroke defVal := makeFields

Default value is width 1, no dash, butt cap, miter join.


equals ​

virtual override Bool equals(Obj? obj)

Equality is based on fields


fromStr ​

static new fromStr(Str s, Bool checked := true)

Parse from string format:

width [dash] cap join

Examples:

0.5
2 [1, 2]
round radius

hash ​

virtual override Int hash()

Hash is based on fields


isNone ​

Bool isNone()

Is the width set to zero


join ​

const StrokeJoin join := StrokeJoin.miter

How to render line joins. Default is miter.


make ​

new make(|This| f)

Make with an it-block


makeFields ​

new makeFields(Float width := 1.0f, Str? dash := null, StrokeCap cap := StrokeCap.butt, StrokeJoin join := StrokeJoin.miter)

Make with fields


none ​

const static Stroke none := Stroke.makeFields(0.0)

Value with width of zero


scale ​

Stroke scale(Float ratio)

Scale size and dash pattern by given ratio


toSize ​

Stroke toSize(Float newWidth)

Return this stroke with different width.


toStr ​

virtual override Str toStr()

Return string format - see fromStr


width ​

const Float width := 1.0f

Stroke width. Default is 1.


StrokeCap ​

@Js @Serializable { simple=true } enum class StrokeCap : Enum

Defines how a stroke end cap is rendered

Enum

buttCap is a flat edge with no extension
roundCap is a a rounded semi-circle
squareCap is a half square extension

Constructors

fromStrReturn the StrokeCap instance for the specified name.

Fields

valsList of StrokeCap values indexed by ordinal

Slot Details ​


butt ​

const static StrokeCap butt := ...

Cap is a flat edge with no extension


fromStr ​

static new fromStr(Str name, Bool checked := true)

Return the StrokeCap instance for the specified name. If not a valid name and checked is false return null, otherwise throw ParseErr.


round ​

const static StrokeCap round := ...

Cap is a a rounded semi-circle


square ​

const static StrokeCap square := ...

Cap is a half square extension


vals ​

const static StrokeCap[] vals := ...

List of StrokeCap values indexed by ordinal


StrokeJoin ​

@Js @Serializable { simple=true } enum class StrokeJoin : Enum

Defines how two stroke lines are joined together

Enum

bevelJoin using a bevel with angle to smooth transition
miterJoin using sharp corners
radiusJoin using rounded semi-circle (round in SVG terminology)

Constructors

fromStrReturn the StrokeJoin instance for the specified name.

Fields

valsList of StrokeJoin values indexed by ordinal

Slot Details ​


bevel ​

const static StrokeJoin bevel := ...

Join using a bevel with angle to smooth transition


fromStr ​

static new fromStr(Str name, Bool checked := true)

Return the StrokeJoin instance for the specified name. If not a valid name and checked is false return null, otherwise throw ParseErr.


miter ​

const static StrokeJoin miter := ...

Join using sharp corners


radius ​

const static StrokeJoin radius := ...

Join using rounded semi-circle (round in SVG terminology)


vals ​

const static StrokeJoin[] vals := ...

List of StrokeJoin values indexed by ordinal


Transform ​

@Js @Serializable { simple=true } const class Transform : Obj

Transform models an affine transformation matrix:

|a  c  e|
|b  d  f|
|0  0  1|

Constructors

fromStrParse from SVG string format
makeConstruct from matrix values

Fields

a
b
c
d
defValDefault instance is no transform.
e
f

Methods

equalsEquality is based on string format
hashHash code is based on string format
multMultiply this matrix by given matrix and return result as new instance
rotateRotate angle in degrees
scaleScale transform
skewXSkew x by angle in degrees
skewYSkew y by angle in degrees
toStrReturn in matrix(<a> <b> <c> <d> <e> <f>) format
translateTranslate transform

Slot Details ​


a ​

const Float a


b ​

const Float b


c ​

const Float c


d ​

const Float d


defVal ​

const static Transform defVal := ...

Default instance is no transform.


e ​

const Float e


equals ​

virtual override Bool equals(Obj? obj)

Equality is based on string format


f ​

const Float f


fromStr ​

static new fromStr(Str s, Bool checked := true)

Parse from SVG string format:

matrix(<a> <b> <c> <d> <e> <f>)
translate(<x> [<y>])
scale(<x> [<y>])
rotate(<a> [<x> <y>])
skewX(<a>)
skewY(<a>)

hash ​

virtual override Int hash()

Hash code is based on string format


make ​

new make(Float a, Float b, Float c, Float d, Float e, Float f)

Construct from matrix values


mult ​

@Operator This mult(Transform that)

Multiply this matrix by given matrix and return result as new instance


rotate ​

static Transform rotate(Float angle, Float? cx := null, Float? cy := null)

Rotate angle in degrees


scale ​

static Transform scale(Float sx, Float sy)

Scale transform


skewX ​

static Transform skewX(Float angle)

Skew x by angle in degrees


skewY ​

static Transform skewY(Float angle)

Skew y by angle in degrees


toStr ​

virtual override Str toStr()

Return in matrix(<a> <b> <c> <d> <e> <f>) format


translate ​

static Transform translate(Float tx, Float ty)

Translate transform