Moscrif API Docs for: 2012q3
Show:

Paint Class

Library: core

The Paint class holds the style and color information about how to draw geometries, text and bitmaps.

Methods

this

()

Object constructor creates new Paint object.

measureText

(
  • text
)
Multivalue

Return the width and the height of the text.

Parameters:

  • text String

    The text string.

Returns:

Multivalue: The size of the text.

Example:

var paint = new Paint();

//get text dimensions
var (w, h) = paint.measureText("Moscrif");

//draw text to the midle of the screen. Position of left bottom point is calculations using tet dimension
canvas.drawText("Moscrif", System.width / 2 - w / 2, System.height / 2 - h / 2, paint);

reset

()

Restores the paint to its initial settings.

Example:

var paint = new Paint();
// 12
console<<paint.textSize<<"\n";
paint.textSize = 25;
// 25
console<<paint.textSize<<"\n";
// restore default settings
paint.reset()
// 12
console<<paint.textSize<<"\n";

Properties

alpha

Integer

Alpha level, affects transparency. Value 0 means fully transparent, value 255 -> no transparent

antiAlias

Boolean

Enable or disable antialiasing. Antialiasing is the technique of minimizing the distortion artifacts known as aliasing when representing a high-resolution image at a lower resolution.

color

Float

The property sets color used by the paint object. The color is defined in hexadecimal formats (from 00 to FF) for four channels in order: alpha, red, green, blue.

Example:

var paint = new Paint();
paint.color = 0xffffffff; // white
paint.color = 0xffff0000; // red
paint.color = 0xff00ff00; // green
paint.color = 0xff0000ff; // blue
paint.color = 0xff000000; // black
paint.color = 0x00000000; // transparent

colorFilter

ColorFilter

Color filter used to apply grayscale or colloring effect.

Example:

//create color filter for grayscale images
var colorFilter = ColorFilter.grayscale();

paint.colorFilter = colorFilter;

//draw bitmap converted to grayscale
canvas.drawBitmap(bitmap, 0, 0, paint);

fakeBoldText

Boolean

If fakeBoldText effect is set to true, the text is drawen with bold style.

fontAscent

Float

The recommended distance above the baseline (will be <= 0).

fontAvgCharWidth

Float

The average charactor width (>= 0)

fontBottom

Float

The greatest distance below the baseline for any glyph (will be >= 0).

fontDescent

Float

The recommended distance below the baseline (will be >= 0).

fontLeading

Float

The recommended distance to add between lines of text (will be >= 0).

fontSpacing

Float

Return the recommend line spacing. This will be Descent - Ascent + Leading.

fontTop

Float

The greatest distance above the baseline for any glyph (will be <= 0).

fontXHeight

Float

The height of an 'x' in px, or 0 if no 'x' in face.

fontXMax

Float

The maximum bounding box x value for all glyphs.

fontXMin

Float

The minimum bounding box x value for all glyphs.

maskFilter

MaskFilter

Paint's maskfilter object. Pass NULL to clear any previous maskfilter. As a convenience, the parameter passed is also returned.

Example:

    //create mask filter
    var maskFilter = MaskFilter.blur(10, #normal, #none);

    //apply mask filter to paint object
    paint.maskFilter = maskFilter;

    canvas.drawBitmap(bitmap, 0, 0, paint);

shader

Shader

Shader object. Pass NULL to clear any previous shader. As a convenience, the parameter passed is also returned. If a previous shader exists, its reference count is decremented. If shader is not NULL, its reference count is incremented.

Example:

//create new instance of shader class. For more information about parameters see Shader class
var shader = Shader.linear(pts, clrs, pos,0);

//create new instance of Paint class
this.paint = new Paint();

//set shader
this.paint.shader = shader;

strikeThruText

Boolean

Enable strikethrough text effect.

strokeCap

Symbol

Paint's stroke cap type, controlling how the start and end of stroked lines and paths are treated. This is the treatment that is applied to the beginning and end of each non-closed contour (e.g. lines).

  • #butt - begin/end contours with no extension.
  • #round - begin/end contours with a semi-circle extension.
  • #square - begin/end contours with a half square extension.

strokeJoin

Symbol

Paint's stroke join type. This is the treatment that is applied to corners in paths and rectangles

  • #miter - connect path segments with a sharp join.
  • #round - connect path segments with a round join.
  • #bevel - connect path segments with a flat bevel join.

strokeWidth

Float

Width for stroking. A value of 0 strokes in hairline mode. Hairlines always draw 1-pixel wide, regardless of the matrix.

style

Symbol

Setting or returning paint's style, used for controlling how primitives' geometries are interpreted. Bitmaps are always drawn in "fill", and lines are always drawn in "stroke". Note: strokeandfill implicitly draws the result with SkPath::kWinding_FillType, so if the original path is even-odd, the results may not appear the same as if it was drawn twice, filled and then stroked.

  • #fill - fill the geometry.
  • #stroke - stroke the geometry.
  • #stroke+fill - fill and stroke the geometry.

textAlign

Symbol

Paint's Align value for drawing text. This property is used by Canvas.drawTextBox function. This is the treatment that is applied to corners in paths and rectangles

  • #left
  • #center
  • #right

Example:

canvas.clear(0xffffffff);

// create paint object for text
var paint = new Paint();
paint.textSize = 40;
paint.textAlign = #center;
// set diferent font
paint.typeface = Typeface.fromName("FreeMono", #bold+italic);

// draw text to the center of screen
canvas.drawTextBox("Moscrif", 0, 0, System.width, System.height, paint, #center);

textSize

Float

Paint's text size.

typeFace

Typeface

Typeface object. The typeface object identifies which font to use when drawing or measuring text.

underlineText

Boolean

Create underline text effect.