@awayjs/graphics
Version:
AwayJS graphics classes
243 lines • 9.68 kB
TypeScript
import { DataBuffer } from './DataBuffer';
/**
* Copyright 2014 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Serialization format for shape data:
* (canonical, update this instead of anything else!)
*
* Shape data is serialized into a set of three buffers:
* - `commands`: a Uint8Array for commands
* - valid values: [1-11] (i.e. one of the PathCommand enum values)
* - `coordinates`: an Int32Array for path coordinates*
* OR uint8 thickness iff the current command is PathCommand.LineStyleSolid
* - valid values: the full range of 32bit numbers, representing x,y coordinates in twips
* - `styles`: a DataBuffer for style definitions
* - valid values: structs for the various style definitions as described below
*
* (*: with one exception: to make various things faster, stroke widths are stored in the
* coordinates buffer, too.)
*
* All entries always contain all fields, default values aren't omitted.
*
* the various commands write the following sets of values into the various buffers:
*
* moveTo:
* commands: PathCommand.MoveTo
* coordinates: target x coordinate, in twips
* target y coordinate, in twips
* styles: n/a
*
* lineTo:
* commands: PathCommand.LineTo
* coordinates: target x coordinate, in twips
* target y coordinate, in twips
* styles: n/a
*
* curveTo:
* commands: PathCommand.CurveTo
* coordinates: control point x coordinate, in twips
* control point y coordinate, in twips
* target x coordinate, in twips
* target y coordinate, in twips
* styles: n/a
*
* cubicCurveTo:
* commands: PathCommand.CubicCurveTo
* coordinates: control point 1 x coordinate, in twips
* control point 1 y coordinate, in twips
* control point 2 x coordinate, in twips
* control point 2 y coordinate, in twips
* target x coordinate, in twips
* target y coordinate, in twips
* styles: n/a
*
* beginFill:
* commands: PathCommand.BeginSolidFill
* coordinates: n/a
* styles: uint32 - RGBA color
*
* beginGradientFill:
* commands: PathCommand.BeginGradientFill
* coordinates: n/a
* Note: the style fields are ordered this way to optimize performance in the rendering backend
* Note: the style record has a variable length depending on the number of color stops
* styles: uint8 - GradientType.{LINEAR,RADIAL}
* fix8 - focalPoint [-128.0xff,127.0xff]
* matrix - transform (see Matrix#writeExternal for details)
* uint8 - colorStops (Number of color stop records that follow)
* list of uint8,uint32 pairs:
* uint8 - ratio [0-0xff]
* uint32 - RGBA color
* uint8 - SpreadMethod.{PAD,REFLECT,REPEAT}
* uint8 - InterpolationMethod.{RGB,LINEAR_RGB}
*
* beginBitmapFill:
* commands: PathCommand.BeginBitmapFill
* coordinates: n/a
* styles: uint32 - Index of the bitmapData object in the Graphics object's `textures`
* array
* matrix - transform (see Matrix#writeExternal for details)
* bool - repeat
* bool - smooth
*
* lineStyle:
* commands: PathCommand.LineStyleSolid
* coordinates: uint32 - thickness (!)
* style: uint32 - RGBA color
* bool - pixelHinting
* uint8 - LineScaleMode, [0-3] see LineScaleMode.fromNumber for meaning
* uint8 - CapsStyle, [0-2] see CapsStyle.fromNumber for meaning
* uint8 - JointStyle, [0-2] see JointStyle.fromNumber for meaning
* uint8 - miterLimit
*
* lineGradientStyle:
* commands: PathCommand.LineStyleGradient
* coordinates: n/a
* Note: the style fields are ordered this way to optimize performance in the rendering backend
* Note: the style record has a variable length depending on the number of color stops
* styles: uint8 - GradientType.{LINEAR,RADIAL}
* int8 - focalPoint [-128,127]
* matrix - transform (see Matrix#writeExternal for details)
* uint8 - colorStops (Number of color stop records that follow)
* list of uint8,uint32 pairs:
* uint8 - ratio [0-0xff]
* uint32 - RGBA color
* uint8 - SpreadMethod.{PAD,REFLECT,REPEAT}
* uint8 - InterpolationMethod.{RGB,LINEAR_RGB}
*
* lineBitmapStyle:
* commands: PathCommand.LineBitmapStyle
* coordinates: n/a
* styles: uint32 - Index of the bitmapData object in the Graphics object's `textures`
* array
* matrix - transform (see Matrix#writeExternal for details)
* bool - repeat
* bool - smooth
*
* lineEnd:
* Note: emitted for invalid `lineStyle` calls
* commands: PathCommand.LineEnd
* coordinates: n/a
* styles: n/a
*
*/
/**
* Used for (de-)serializing Graphics path data in defineShape, flash.display.Graphics
* and the renderer.
*/
export declare const enum PathCommand {
BeginSolidFill = 1,
BeginGradientFill = 2,
BeginBitmapFill = 3,
EndFill = 4,
LineStyleSolid = 5,
LineStyleGradient = 6,
LineStyleBitmap = 7,
LineEnd = 8,
MoveTo = 9,
LineTo = 10,
CurveTo = 11,
CubicCurveTo = 12
}
export declare const enum GradientType {
Linear = 16,
Radial = 18
}
export declare const enum GradientSpreadMethod {
Pad = 0,
Reflect = 1,
Repeat = 2
}
export declare const enum GradientInterpolationMethod {
RGB = 0,
LinearRGB = 1
}
export declare const enum LineScaleMode {
None = 0,
Normal = 1,
Vertical = 2,
Horizontal = 3
}
export interface ShapeMatrix {
a: number;
b: number;
c: number;
d: number;
tx: number;
ty: number;
}
export declare class PlainObjectShapeData {
commands: Uint8Array;
commandsPosition: number;
coordinates: Int32Array;
morphCoordinates: Int32Array;
coordinatesPosition: number;
styles: ArrayBuffer;
stylesLength: number;
morphStyles: ArrayBuffer;
morphStylesLength: number;
hasFills: boolean;
hasLines: boolean;
constructor(commands: Uint8Array, commandsPosition: number, coordinates: Int32Array, morphCoordinates: Int32Array, coordinatesPosition: number, styles: ArrayBuffer, stylesLength: number, morphStyles: ArrayBuffer, morphStylesLength: number, hasFills: boolean, hasLines: boolean);
}
export declare class ShapeData {
commands: Uint8Array;
commandsPosition: number;
coordinates: Int32Array;
morphCoordinates: Int32Array;
coordinatesPosition: number;
styles: DataBuffer;
morphStyles: DataBuffer;
hasFills: boolean;
hasLines: boolean;
constructor(initialize?: boolean);
static FromPlainObject(source: PlainObjectShapeData): ShapeData;
moveTo(x: number, y: number): void;
lineTo(x: number, y: number): void;
curveTo(controlX: number, controlY: number, anchorX: number, anchorY: number): void;
cubicCurveTo(controlX1: number, controlY1: number, controlX2: number, controlY2: number, anchorX: number, anchorY: number): void;
beginFill(color: number): void;
writeMorphFill(color: number): void;
endFill(): void;
endLine(): void;
lineStyle(thickness: number, color: number, pixelHinting: boolean, scaleMode: LineScaleMode, caps: number, joints: number, miterLimit: number): void;
writeMorphLineStyle(thickness: number, color: number): void;
/**
* Bitmaps are specified the same for fills and strokes, so we only need to serialize them
* once. The Parameter `pathCommand` is treated as the actual command to serialize, and must
* be one of BeginBitmapFill and LineStyleBitmap.
*/
beginBitmap(pathCommand: PathCommand, bitmapId: number, matrix: ShapeMatrix, repeat: boolean, smooth: boolean): void;
writeMorphBitmap(matrix: ShapeMatrix): void;
/**
* Gradients are specified the same for fills and strokes, so we only need to serialize them
* once. The Parameter `pathCommand` is treated as the actual command to serialize, and must
* be one of BeginGradientFill and LineStyleGradient.
*/
beginGradient(pathCommand: PathCommand, colors: number[], ratios: number[], gradientType: number, matrix: ShapeMatrix, spread: number, interpolation: number, focalPointRatio: number): void;
writeMorphGradient(colors: number[], ratios: number[], matrix: ShapeMatrix): void;
writeCommandAndCoordinates(command: PathCommand, x: number, y: number): void;
writeCoordinates(x: number, y: number): void;
writeMorphCoordinates(x: number, y: number): void;
clear(): void;
isEmpty(): boolean;
clone(): ShapeData;
toPlainObject(): PlainObjectShapeData;
get buffers(): ArrayBuffer[];
private _writeStyleMatrix;
private ensurePathCapacities;
}
//# sourceMappingURL=ShapeData.d.ts.map