From 85326c89aecba8f79d334cd1f7038f3dc74dd3d6 Mon Sep 17 00:00:00 2001 From: Bryan Krol Date: Wed, 13 Mar 2019 20:21:29 -0400 Subject: [PATCH 1/3] Added some more definitions for use. --- types/fabric/fabric-impl.d.ts | 59 ++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/types/fabric/fabric-impl.d.ts b/types/fabric/fabric-impl.d.ts index 8e973de1ab..2b384347aa 100644 --- a/types/fabric/fabric-impl.d.ts +++ b/types/fabric/fabric-impl.d.ts @@ -865,7 +865,7 @@ interface IShadowOptions { /** * Whether the shadow should affect stroke operations */ - affectStrike?: boolean; + affectStroke?: boolean; /** * Indicates whether toObject should include default values */ @@ -3529,6 +3529,40 @@ export class Object { * @return {fabric.Point} */ translateToGivenOrigin(pointL: Point, fromOriginX: string, fromOriginY: string, toOriginX: string, toOriginY: string): Point; + /* + * Calculate object dimensions from its properties + * @private + * @return {Object} .x width dimension + * @return {Object} .y height dimension + */ + _getNonTransformedDimensions(): {x: number, y: number}; + /** + * + * @param ctx + * @private + */ + _renderStroke(ctx: CanvasRenderingContext2D): void; + /** + * @private + * @param {CanvasRenderingContext2D} ctx Context to render on + */ + _removeShadow(ctx: CanvasRenderingContext2D): void; + /** + * @private + * Sets line dash + * @param {CanvasRenderingContext2D} ctx Context to set the dash line on + * @param {Array} dashArray array representing dashes + * @param {Function} alternative function to call if browser does not support lineDash + */ + _setLineDash(ctx: CanvasRenderingContext2D, dashArray: number[], alternative: Function): void; + /** + * @private + * @param {CanvasRenderingContext2D} ctx Context to render on + * @param {Object} filler fabric.Pattern or fabric.Gradient + * @return {Object} offset.offsetX offset for text rendering + * @return {Object} offset.offsetY offset for text rendering + */ + _applyPatternGradientTransform(ctx: CanvasRenderingContext2D, filler: string | Pattern | Gradient): void; } interface IPathOptions extends IObjectOptions { @@ -3940,6 +3974,20 @@ export class Text extends Object { * @return {Boolean} */ styleHas(property: string, lineIndex?: number): boolean; + /** + * Measure a single line given its index. Used to calculate the initial + * text bounding box. The values are calculated and stored in __lineWidths cache. + * @private + * @param {Number} lineIndex line number + * @return {Number} Line width + */ + getLineWidth(lineIndex: number): number; + /** + * @private + * @param {Number} lineIndex index text line + * @return {Number} Line left offset + */ + _getLineLeftOffset(lineIndex: number): number } interface ITextOptions extends TextOptions { /** @@ -4372,6 +4420,15 @@ export class IText extends Text { * @param {Event} e Event object */ setCursorByClick(e: Event): void; + /** + * @private + */ + _getNewSelectionStartFromOffset(mouseOffset: {x: number, y: number}, prevWidth: number, width: number, index: number, jlen: number): number; + /** + * @private + * @param {CanvasRenderingContext2D} ctx Context to render on + */ + _render(ctx: CanvasRenderingContext2D): void; } interface ITextboxOptions extends ITextOptions { /** From dce8d5bba1fcfd2875ac8bddcbc316db38c5774e Mon Sep 17 00:00:00 2001 From: Bryan Krol Date: Wed, 13 Mar 2019 20:33:01 -0400 Subject: [PATCH 2/3] Updated type for vptCoords so they are correct and also added a few more type defs --- types/fabric/fabric-impl.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/fabric/fabric-impl.d.ts b/types/fabric/fabric-impl.d.ts index 2b384347aa..4e7fec0258 100644 --- a/types/fabric/fabric-impl.d.ts +++ b/types/fabric/fabric-impl.d.ts @@ -1038,7 +1038,7 @@ interface IStaticCanvasOptions { * The coordinates get updated with @method calcViewportBoundaries. * @memberOf fabric.StaticCanvas.prototype */ - vptCoords?: {tl: number, tr: number, bl: number, br: number} + vptCoords?: {tl: {x: number, y: number}, tr: {x: number, y: number}, bl: {x: number, y: number}, br: {x: number, y: number}} /** * Based on vptCoords and object.aCoords, skip rendering of objects that * are not included in current viewport. From db73f28f5316fd40992664afef28e4b71fa64c28 Mon Sep 17 00:00:00 2001 From: Bryan Krol Date: Mon, 8 Apr 2019 12:24:39 -0400 Subject: [PATCH 3/3] Added some additional type defs based on my current needs. --- types/fabric/fabric-impl.d.ts | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/types/fabric/fabric-impl.d.ts b/types/fabric/fabric-impl.d.ts index 37038912fa..7add5b5630 100644 --- a/types/fabric/fabric-impl.d.ts +++ b/types/fabric/fabric-impl.d.ts @@ -1075,6 +1075,8 @@ export class StaticCanvas { */ constructor(element: HTMLCanvasElement | string, options?: ICanvasOptions); + _activeObject?: Object | Group; + /** * Calculates canvas element offset relative to the document * This method is also attached as "resize" event handler of window @@ -1454,7 +1456,7 @@ export class StaticCanvas { * @return {Boolean | null} `true` if method is supported (or at least exists), * `null` if canvas element or context can not be initialized */ - supports(methodName: "getImageData" | "toDataURL" | "toDataURLWithQuality" | "setLineDash"): boolean; + static supports(methodName: "getImageData" | "toDataURL" | "toDataURLWithQuality" | "setLineDash"): boolean; /** * Exports canvas element to a dataurl image. Note that when multiplier is used, cropping is scaled appropriately @@ -2347,6 +2349,11 @@ export class Line { * Produces a function that calculates distance from canvas edge to Line origin. */ makeEdgeToOriginGetter(propertyNames: {origin: number, axis1: any, axis2: any, dimension: any}, originValues: {nearest: any, center: any, farthest: any}): Function; + /** + * Recalculates line points given width and height + * @private + */ + calcLinePoints(): {x1: number, x2: number, y1: number, y2: number}; } interface IObjectOptions { @@ -3550,7 +3557,7 @@ export class Object { * @param {Array} dashArray array representing dashes * @param {Function} alternative function to call if browser does not support lineDash */ - _setLineDash(ctx: CanvasRenderingContext2D, dashArray: number[], alternative: Function): void; + _setLineDash(ctx: CanvasRenderingContext2D, dashArray: number[], alternative?: (ctx: CanvasRenderingContext2D) => void): void; /** * @private * @param {CanvasRenderingContext2D} ctx Context to render on @@ -3559,6 +3566,16 @@ export class Object { * @return {Object} offset.offsetY offset for text rendering */ _applyPatternGradientTransform(ctx: CanvasRenderingContext2D, filler: string | Pattern | Gradient): void; + /** + * @private + * @param {CanvasRenderingContext2D} ctx Context to render on + */ + _render(ctx: CanvasRenderingContext2D): void; + /** + * @private + * @param {CanvasRenderingContext2D} ctx Context to render on + */ + _renderPaintInOrder(ctx: CanvasRenderingContext2D): void; } interface IPathOptions extends IObjectOptions {