mirror of
https://gitee.com/openharmony/graphic_graphic_2d
synced 2024-11-27 17:21:51 +00:00
commit
2b097bf9c2
@ -1,103 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @kit ArkGraphics 2D
|
||||
*/
|
||||
/**
|
||||
* The date structure that provides the basis for graphics.
|
||||
*
|
||||
* @namespace common2D
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
declare namespace common2D {
|
||||
/**
|
||||
* Provide a description in the form of color ARGB.
|
||||
* @typedef Color
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
interface Color {
|
||||
/**
|
||||
* Alpha component of color, from 0 to 255.
|
||||
* @type { number }
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
alpha: number;
|
||||
/**
|
||||
* Red component of color, from 0 to 255.
|
||||
* @type { number }
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
red: number;
|
||||
/**
|
||||
* Green component of color, from 0 to 255.
|
||||
* @type { number }
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
green: number;
|
||||
/**
|
||||
* Blue component of color, from 0 to 255.
|
||||
* @type { number }
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
blue: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the definition of the rectangle.
|
||||
* @typedef Rect
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
interface Rect {
|
||||
/**
|
||||
* Left Position of Rectangle.
|
||||
* @type { number }
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
left: number;
|
||||
/**
|
||||
* Top side position of the rectangle
|
||||
* @type { number }
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
top: number;
|
||||
/**
|
||||
* Right Position of Rectangle.
|
||||
* @type { number }
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
right: number;
|
||||
/**
|
||||
* Position of the bottom side of the rectangle.
|
||||
* @type { number }
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
bottom: number;
|
||||
}
|
||||
}
|
||||
|
||||
export default common2D;
|
@ -1,871 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @kit ArkGraphics 2D
|
||||
*/
|
||||
|
||||
import type image from './@ohos.multimedia.image';
|
||||
import type common2D from './@ohos.graphics.common2D';
|
||||
|
||||
/**
|
||||
* Provides functions such as 2D graphics rendering, text drawing, and image display.
|
||||
*
|
||||
* @namespace drawing
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
declare namespace drawing {
|
||||
/**
|
||||
* Enumerate blending modes for colors.
|
||||
* Blend is a operation that use 4 components(red, green, blue, alpha) to generate
|
||||
* a new color from two colors(source, destination).
|
||||
* @enum { number }
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
enum BlendMode {
|
||||
/**
|
||||
* Disable 4 regions(red, green, blue, alpha)
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
CLEAR = 0,
|
||||
/**
|
||||
* Use components of the source
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
SRC = 1,
|
||||
/**
|
||||
* Use components of the destination
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
DST = 2,
|
||||
/**
|
||||
* The source is placed above the destination.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
SRC_OVER = 3,
|
||||
/**
|
||||
* The Destination is placed above the source.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
DST_OVER = 4,
|
||||
/**
|
||||
* Use source replaces the destination, and will not exceed the boundaries of the destination
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
SRC_IN = 5,
|
||||
/**
|
||||
* Use destination, and will not exceed the boundaries of the source
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
DST_IN = 6,
|
||||
/**
|
||||
* Source is use in outside of the boundaries of the destination.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
SRC_OUT = 7,
|
||||
/**
|
||||
* Destination is use in outside of the boundaries of the source.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
DST_OUT = 8,
|
||||
/**
|
||||
* Source which overlaps the destination will replaces the destination.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
SRC_ATOP = 9,
|
||||
/**
|
||||
* Destination which overlaps the source will replaces the source.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
DST_ATOP = 10,
|
||||
/**
|
||||
* Combine regions where source and destination do not overlap.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
XOR = 11,
|
||||
/**
|
||||
* The sum of the source and destination.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
PLUS = 12,
|
||||
/**
|
||||
* All components are multiplied.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
MODULATE = 13,
|
||||
/**
|
||||
* Multiply the complement values of the background and source color values,
|
||||
* and then complement the result.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
SCREEN = 14,
|
||||
/**
|
||||
* Multiplies or screens the colors, depending on destination
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
OVERLAY = 15,
|
||||
/**
|
||||
* Choose a darker background and source color.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
DARKEN = 16,
|
||||
/**
|
||||
* Choose a lighter background and source color.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
LIGHTEN = 17,
|
||||
/**
|
||||
* Brightens destination color to reflect the source color.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
COLOR_DODGE = 18,
|
||||
/**
|
||||
* Darkens destination color to reflect the source color.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
COLOR_BURN = 19,
|
||||
/**
|
||||
* Multiplies or screens the colors, depending on source
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
HARD_LIGHT = 20,
|
||||
/**
|
||||
* Lightens or Darkens the colors, depending on the source.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
SOFT_LIGHT = 21,
|
||||
/**
|
||||
* Subtract the darker of the two colors from the brighter color.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
DIFFERENCE = 22,
|
||||
/**
|
||||
* Produces an effect similar to difference mode, but with lower contrast.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
EXCLUSION = 23,
|
||||
/**
|
||||
* Multiply the source color by the destination color and replace the destination.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
MULTIPLY = 24,
|
||||
/**
|
||||
* Use the hue of the source and the saturation and brightness of the destination.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
HUE = 25,
|
||||
/**
|
||||
* Use the saturation of the source and the hue and brightness of the destination.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
SATURATION = 26,
|
||||
/**
|
||||
* Use the hue and saturation of the source and the brightness of the destination.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
COLOR = 27,
|
||||
/**
|
||||
* Use the brightness of the source and the hue and saturation of the destination.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
LUMINOSITY = 28,
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes a path object.
|
||||
*
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
class Path {
|
||||
/**
|
||||
* Sets the start point of a path
|
||||
* @param { number } x - Indicates the x coordinate of the start point.
|
||||
* @param { number } y - Indicates the y coordinate of the start point.
|
||||
* @throws { BusinessError } 401 - Parameter error.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
moveTo(x: number, y: number): void;
|
||||
|
||||
/**
|
||||
* Draws a line segment from the last point of a path to the target point.
|
||||
* @param { number } x - Indicates the x coordinate of the target point.
|
||||
* @param { number } y - Indicates the y coordinate of the target point.
|
||||
* @throws { BusinessError } 401 - Parameter error.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
lineTo(x: number, y: number): void;
|
||||
|
||||
/**
|
||||
* This is done by using angle arc mode. In this mode, a rectangle that encloses an ellipse is specified first,
|
||||
* and then a start angle and a sweep angle are specified.
|
||||
* The arc is a portion of the ellipse defined by the start angle and the sweep angle.
|
||||
* By default, a line segment from the last point of the path to the start point of the arc is also added.
|
||||
* @param { number } x1 - Indicates the x coordinate of the upper left corner of the rectangle.
|
||||
* @param { number } y1 - Indicates the y coordinate of the upper left corner of the rectangle.
|
||||
* @param { number } x2 - Indicates the x coordinate of the lower right corner of the rectangle.
|
||||
* @param { number } y2 - Indicates the y coordinate of the lower right corner of the rectangle.
|
||||
* @param { number } startDeg - Indicates the start angle, in degrees.
|
||||
* @param { number } sweepDeg - Indicates the angle to sweep, in degrees.
|
||||
* @throws { BusinessError } 401 - Parameter error.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
arcTo(x1: number, y1: number, x2: number, y2: number, startDeg: number, sweepDeg: number): void;
|
||||
|
||||
/**
|
||||
* Draws a quadratic Bezier curve from the last point of a path to the target point.
|
||||
* @param { number } ctrlX - Indicates the x coordinate of the control point.
|
||||
* @param { number } ctrlY - Indicates the y coordinate of the control point.
|
||||
* @param { number } endX - Indicates the x coordinate of the target point.
|
||||
* @param { number } endY - Indicates the y coordinate of the target point.
|
||||
* @throws { BusinessError } 401 - Parameter error.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
quadTo(ctrlX: number, ctrlY: number, endX: number, endY: number): void;
|
||||
|
||||
/**
|
||||
* Draws a cubic Bezier curve from the last point of a path to the target point.
|
||||
* @param { number } ctrlX1 - Indicates the x coordinate of the first control point.
|
||||
* @param { number } ctrlY1 - Indicates the y coordinate of the first control point.
|
||||
* @param { number } ctrlX2 - Indicates the x coordinate of the second control point.
|
||||
* @param { number } ctrlY2 - Indicates the y coordinate of the second control point.
|
||||
* @param { number } endX - Indicates the x coordinate of the target point.
|
||||
* @param { number } endY - Indicates the y coordinate of the target point.
|
||||
* @throws { BusinessError } 401 - Parameter error.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
cubicTo(ctrlX1: number, ctrlY1: number, ctrlX2: number, ctrlY2: number, endX: number, endY: number): void;
|
||||
|
||||
/**
|
||||
* Closes a path. A line segment from the start point to the last point of the path is added.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
close(): void;
|
||||
|
||||
/**
|
||||
* Resets path data.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
reset(): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides an interface to the drawing, and how to clip and transform the drawing.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
class Canvas {
|
||||
/**
|
||||
* Constructor for the Canvas.
|
||||
* @param { image.PixelMap } pixelmap - PixelMap.
|
||||
* @throws { BusinessError } 401 - Parameter error.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
constructor(pixelmap: image.PixelMap);
|
||||
|
||||
/**
|
||||
* If rectangle is stroked, use pen to stroke width describes the line thickness,
|
||||
* else use brush to fill the rectangle.
|
||||
* @param { common2D.Rect } rect - Rectangle to draw.
|
||||
* @throws { BusinessError } 401 - Parameter error.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
drawRect(rect: common2D.Rect): void;
|
||||
|
||||
/**
|
||||
* If radius is zero or less, nothing is drawn. If circle is stroked, use pen to
|
||||
* stroke width describes the line thickness, else use brush to fill the circle.
|
||||
* @param { number } x - X coordinate of the circle center.
|
||||
* @param { number } y - Y coordinate of the circle center.
|
||||
* @param { number } radius - Half the diameter of circle.
|
||||
* @throws { BusinessError } 401 - Parameter error.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
drawCircle(x: number, y: number, radius: number): void;
|
||||
|
||||
/**
|
||||
* Draw an pixelmap, with the upper left corner at (left, top).
|
||||
* @param { image.PixelMap } pixelmap - PixelMap.
|
||||
* @param { number } left - Left side of image.
|
||||
* @param { number } top - Top side of image.
|
||||
* @throws { BusinessError } 401 - Parameter error.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
drawImage(pixelmap: image.PixelMap, left: number, top: number): void;
|
||||
|
||||
/**
|
||||
* Fills clip with color color. Mode determines how ARGB is combined with destination.
|
||||
* @param { common2D.Color } color - Color in 32-bit argb format.
|
||||
* @param { BlendMode } blendMode - Used to combine source color and destination. The default value is SRC_OVER.
|
||||
* @throws { BusinessError } 401 - Parameter error.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
drawColor(color: common2D.Color, blendMode?: BlendMode): void;
|
||||
|
||||
/**
|
||||
* Draw a point.
|
||||
* @param { number } x - X coordinate position of the point.
|
||||
* @param { number } y - Y coordinate position of the point.
|
||||
* @throws { BusinessError } 401 - Parameter error.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
drawPoint(x: number, y: number): void;
|
||||
|
||||
/**
|
||||
* Path contains an array of path contour, each of which may be open or closed.
|
||||
* @param { Path } path - Path to draw.
|
||||
* @throws { BusinessError } 401 - Parameter error.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
drawPath(path: Path): void;
|
||||
|
||||
/**
|
||||
* Draws line segment from startPt to endPt.
|
||||
* @param { number } x0 - X coordinate of the start point of the line segment.
|
||||
* @param { number } y0 - Y coordinate of the start point of the line segment.
|
||||
* @param { number } x1 - X coordinate of the end point of the line segment.
|
||||
* @param { number } y1 - Y coordinate of the end point of the line segment.
|
||||
* @throws { BusinessError } 401 - Parameter error.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
drawLine(x0: number, y0: number, x1: number, y1: number): void;
|
||||
|
||||
/**
|
||||
* Draws line segment from startPt to endPt.
|
||||
* @param { TextBlob } blob - X coordinate of the start point of the line segment.
|
||||
* @param { number } x - X coordinate of the text start point.
|
||||
* @param { number } y - Y coordinate of the text start point.
|
||||
* @throws { BusinessError } 401 - Parameter error.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
drawTextBlob(blob: TextBlob, x: number, y: number): void;
|
||||
|
||||
/**
|
||||
* Set pen to a canvas.
|
||||
* @param { Pen } pen - object.
|
||||
* @throws { BusinessError } 401 - Parameter error.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
attachPen(pen: Pen): void;
|
||||
|
||||
/**
|
||||
* Set brush to a canvas.
|
||||
* @param { Brush } brush - Object.
|
||||
* @throws { BusinessError } 401 - Parameter error.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
attachBrush(brush: Brush): void;
|
||||
|
||||
/**
|
||||
* Unset pen to a canvas.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
detachPen(): void;
|
||||
|
||||
/**
|
||||
* Unset brush to a canvas.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
detachBrush(): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a description of the type and position of the text.
|
||||
* @typedef TextBlobRunBuffer
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
interface TextBlobRunBuffer {
|
||||
/**
|
||||
* Text model.
|
||||
* @type { number }
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
glyph: number;
|
||||
/**
|
||||
* X-coordinate of the text start point.
|
||||
* @type { number }
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
positionX: number;
|
||||
/**
|
||||
* Y-coordinate of the text start point.
|
||||
* @type { number }
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
positionY: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encoding type of the description text.
|
||||
*
|
||||
* @enum { number }
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
enum TextEncoding {
|
||||
/**
|
||||
* Use 1 byte to represent UTF-8 or ASCII
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
TEXT_ENCODING_UTF8 = 0,
|
||||
/**
|
||||
* Use 2 bytes to represent most of unicode
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
TEXT_ENCODING_UTF16 = 1,
|
||||
/**
|
||||
* Use 4 bytes to represent all unicode.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
TEXT_ENCODING_UTF32 = 2,
|
||||
/**
|
||||
* Use 2 bytes to represent the glyph index.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
TEXT_ENCODING_GLYPH_ID = 3,
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a description of the text
|
||||
*
|
||||
* class TextBlob
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
class TextBlob {
|
||||
/**
|
||||
* Create a textblob from a string
|
||||
* @param { string } text - Drawn glyph content.
|
||||
* @param { Font } font - Specify text size, font, text scale, etc.
|
||||
* @param { TextEncoding } encoding - The default value is TEXT_ENCODING_UTF8.
|
||||
* @returns { TextBlob } TextBlob object.
|
||||
* @throws { BusinessError } 401 - Parameter error.
|
||||
* @static
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
static makeFromString(text: string, font: Font, encoding?: TextEncoding): TextBlob;
|
||||
|
||||
/**
|
||||
* Creating a textblob object based on RunBuffer information
|
||||
* @param { Array<TextBlobRunBuffer> } pos - The array of TextBlobRunBuffer.
|
||||
* @param { Font } font - Font used for this run.
|
||||
* @param { common2D.Rect } bounds - Optional run bounding box.
|
||||
* @returns { TextBlob } TextBlob object.
|
||||
* @throws { BusinessError } 401 - Parameter error.
|
||||
* @static
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
static makeFromRunBuffer(pos: Array<TextBlobRunBuffer>, font: Font, bounds?: common2D.Rect): TextBlob;
|
||||
|
||||
/**
|
||||
* Returns the bounding rectangle shape
|
||||
* @returns { common2D.Rect } Rect object.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
bounds(): common2D.Rect;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Typeface class specifies the typeface and intrinsic style of a font.
|
||||
*
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
class Typeface {
|
||||
/**
|
||||
* Get the family name for this typeface.
|
||||
* @returns { string } Family name.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
getFamilyName(): string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Font controls options applied when drawing and measuring text.
|
||||
*
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
class Font {
|
||||
/**
|
||||
* Requests, but does not require, that glyphs respect sub-pixel positioning.
|
||||
* @param { boolean } isSubpixel - Setting for sub-pixel positioning.
|
||||
* @throws { BusinessError } 401 - Parameter error.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
enableSubpixel(isSubpixel: boolean): void;
|
||||
|
||||
/**
|
||||
* Increases stroke width when creating glyph bitmaps to approximate a bold typeface.
|
||||
* @param { boolean } isEmbolden - Setting for bold approximation.
|
||||
* @throws { BusinessError } 401 - Parameter error.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
enableEmbolden(isEmbolden: boolean): void;
|
||||
|
||||
/**
|
||||
* Requests linearly scalable font and glyph metrics.
|
||||
* @param { boolean } isLinearMetrics - Setting for linearly scalable font and glyph metrics.
|
||||
* @throws { BusinessError } 401 - Parameter error.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
enableLinearMetrics(isLinearMetrics: boolean): void;
|
||||
|
||||
/**
|
||||
* Sets text size in points. Has no effect if textSize is not greater than or equal to zero.
|
||||
* @param { number } textSize - Typographic height of text.
|
||||
* @throws { BusinessError } 401 - Parameter error.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
setSize(textSize: number): void;
|
||||
|
||||
/**
|
||||
* Obtains the text size.
|
||||
* @returns { number } Text size.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
getSize(): number;
|
||||
|
||||
/**
|
||||
* Sets Typeface to font.
|
||||
* @param { Typeface } typeface - Font and style used to draw text.
|
||||
* @throws { BusinessError } 401 - Parameter error.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
setTypeface(typeface: Typeface): void;
|
||||
|
||||
/**
|
||||
* Get Typeface to font.
|
||||
* @returns { Typeface } Typeface.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
getTypeface(): Typeface;
|
||||
|
||||
/**
|
||||
* Get fontMetrics associated with typeface.
|
||||
* @returns { FontMetrics } The fontMetrics value returned to the caller.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
getMetrics(): FontMetrics;
|
||||
|
||||
/**
|
||||
* Measure the width of text.
|
||||
* @param { string } text - Text Symbol Content.
|
||||
* @param { TextEncoding } encoding - Encoding format.
|
||||
* @returns { number } The width of text.
|
||||
* @throws { BusinessError } 401 - Parameter error.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
measureText(text: string, encoding: TextEncoding): number;
|
||||
}
|
||||
|
||||
/**
|
||||
* The metrics of an Font.
|
||||
* @typedef FontMetrics
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
interface FontMetrics {
|
||||
/**
|
||||
* Maximum range above the glyph bounding box.
|
||||
* @type { number }
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
top: number;
|
||||
/**
|
||||
* Distance Retained Above Baseline.
|
||||
* @type { number }
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
ascent: number;
|
||||
/**
|
||||
* The distance that remains below the baseline.
|
||||
* @type { number }
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
descent: number;
|
||||
/**
|
||||
* Maximum range below the glyph bounding box.
|
||||
* @type { number }
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
bottom: number;
|
||||
/**
|
||||
* Line Spacing.
|
||||
* @type { number }
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
leading: number;
|
||||
}
|
||||
/**
|
||||
* ColorFilters are optional objects in the drawing pipeline.
|
||||
*
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
class ColorFilter {
|
||||
/**
|
||||
* Makes a color filter with the given color and blend mode.
|
||||
* @param { common2D.Color } color - Color.
|
||||
* @param { BlendMode } mode - BlendMode.
|
||||
* @returns { ColorFilter } Colorfilter object.
|
||||
* @throws { BusinessError } 401 - Parameter error.
|
||||
* @static
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
static createBlendModeColorFilter(color: common2D.Color, mode: BlendMode): ColorFilter;
|
||||
|
||||
/**
|
||||
* Create a color filter consisting of two filters.
|
||||
* @param { ColorFilter } outer - The filter is used next.
|
||||
* @param { ColorFilter } inner - The filter is used first.
|
||||
* @returns { ColorFilter } Colorfilter object.
|
||||
* @throws { BusinessError } 401 - Parameter error.
|
||||
* @static
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
static createComposeColorFilter(outer: ColorFilter, inner: ColorFilter): ColorFilter;
|
||||
|
||||
/**
|
||||
* Makes a color filter that converts between linear colors and sRGB colors.
|
||||
* @returns { ColorFilter } Colorfilter object.
|
||||
* @static
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
static createLinearToSRGBGamma(): ColorFilter;
|
||||
|
||||
/**
|
||||
* Makes a color filter that converts between sRGB colors and linear colors.
|
||||
* @returns { ColorFilter } Colorfilter object.
|
||||
* @static
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
static createSRGBGammaToLinear(): ColorFilter;
|
||||
|
||||
/**
|
||||
* Makes a color filter that multiplies the luma of its input into the alpha channel,
|
||||
* and sets the red, green, and blue channels to zero.
|
||||
* @returns { ColorFilter } Colorfilter.
|
||||
* @static
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
static createLumaColorFilter(): ColorFilter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides settings for strokes during drawing.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
class Pen {
|
||||
/**
|
||||
* Set the color of the pen.
|
||||
* @param { common2D.Color } color - Set colors.
|
||||
* @throws { BusinessError } 401 - Parameter error.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
setColor(color: common2D.Color): void;
|
||||
/**
|
||||
* Sets the thickness of the pen used by the paint to outline the shape.
|
||||
*
|
||||
* @param { number } width - Zero thickness for hairline; greater than zero for pen thickness.
|
||||
* @throws { BusinessError } 401 - Parameter error.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
setStrokeWidth(width: number): void;
|
||||
/**
|
||||
* Requests, but does not require, that edge pixels draw opaque or with
|
||||
* partial transparency.
|
||||
*
|
||||
* @param { boolean } aa - Setting for antialiasing.
|
||||
* @throws { BusinessError } 401 - Parameter error.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
setAntiAlias(aa: boolean): void;
|
||||
/**
|
||||
* Replaces alpha, leaving RGB
|
||||
*
|
||||
* @param { number } alpha - Alpha component of color.
|
||||
* @throws { BusinessError } 401 - Parameter error.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
setAlpha(alpha: number): void;
|
||||
/**
|
||||
* Sets ColorFilter to pen
|
||||
*
|
||||
* @param { ColorFilter } filter - ColorFilter to apply to subsequent draw.
|
||||
* @throws { BusinessError } 401 - Parameter error.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
setColorFilter(filter: ColorFilter): void;
|
||||
/**
|
||||
* Sets a blender that implements the specified blendmode enum.
|
||||
*
|
||||
* @param { BlendMode } mode - Blendmode.
|
||||
* @throws { BusinessError } 401 - Parameter error.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
setBlendMode(mode: BlendMode): void;
|
||||
/**
|
||||
* Request color distribution error.
|
||||
*
|
||||
* @param { boolean } dither - Whether the color is distributed incorrectly.
|
||||
* @throws { BusinessError } 401 - Parameter error.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
setDither(dither: boolean): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides settings for brush fill when drawing.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
class Brush {
|
||||
/**
|
||||
* Set the color of the brush.
|
||||
* @param { common2D.Color } color - Set colors.
|
||||
* @throws { BusinessError } 401 - Parameter error.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
setColor(color: common2D.Color): void;
|
||||
/**
|
||||
* Requests, but does not require, that edge pixels draw opaque or with
|
||||
* partial transparency.
|
||||
* @param { boolean } aa - Setting for antialiasing.
|
||||
* @throws { BusinessError } 401 - Parameter error.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
setAntiAlias(aa: boolean): void;
|
||||
/**
|
||||
* Replaces alpha, leaving RGB
|
||||
* @param { number } alpha - Alpha component of color, value range: 0–255.
|
||||
* @throws { BusinessError } 401 - Parameter error.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
setAlpha(alpha: number): void;
|
||||
/**
|
||||
* Sets ColorFilter to brush
|
||||
* @param { ColorFilter } filter - ColorFilter to apply to subsequent draw.
|
||||
* @throws { BusinessError } 401 - Parameter error.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
setColorFilter(filter: ColorFilter): void;
|
||||
/**
|
||||
* Sets a blender that implements the specified blendmode enum.
|
||||
* @param { BlendMode } mode - Blendmode.
|
||||
* @throws { BusinessError } 401 - Parameter error.
|
||||
* @syscap SystemCapability.Graphics.Drawing
|
||||
* @since 11
|
||||
*/
|
||||
setBlendMode(mode: BlendMode): void;
|
||||
}
|
||||
}
|
||||
|
||||
export default drawing;
|
@ -112,39 +112,18 @@ napi_value JsBrush::SetColor(napi_env env, napi_callback_info info)
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
|
||||
size_t argc = ARGC_ONE;
|
||||
napi_value argv[ARGC_ONE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_ONE) {
|
||||
ROSEN_LOGE("JsBrush::SetColor Argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_ONE);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_object);
|
||||
|
||||
napi_valuetype valueType = napi_undefined;
|
||||
if (argv[0] == nullptr || napi_typeof(env, argv[0], &valueType) != napi_ok || valueType != napi_object) {
|
||||
int32_t argb[ARGC_FOUR] = {0};
|
||||
if (!ConvertFromJsColor(env, argv[ARGC_ZERO], argb, ARGC_FOUR)) {
|
||||
ROSEN_LOGE("JsBrush::SetColor Argv[0] is invalid");
|
||||
return NapiGetUndefined(env);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM,
|
||||
"Parameter verification failed. The range of color channels must be [0, 255].");
|
||||
}
|
||||
|
||||
napi_value tempValue = nullptr;
|
||||
int32_t alpha = 0;
|
||||
int32_t red = 0;
|
||||
int32_t green = 0;
|
||||
int32_t blue = 0;
|
||||
napi_get_named_property(env, argv[0], "alpha", &tempValue);
|
||||
bool isAlphaOk = ConvertClampFromJsValue(env, tempValue, alpha, 0, Color::RGB_MAX);
|
||||
napi_get_named_property(env, argv[0], "red", &tempValue);
|
||||
bool isRedOk = ConvertClampFromJsValue(env, tempValue, red, 0, Color::RGB_MAX);
|
||||
napi_get_named_property(env, argv[0], "green", &tempValue);
|
||||
bool isGreenOk = ConvertClampFromJsValue(env, tempValue, green, 0, Color::RGB_MAX);
|
||||
napi_get_named_property(env, argv[0], "blue", &tempValue);
|
||||
bool isBlueOk = ConvertClampFromJsValue(env, tempValue, blue, 0, Color::RGB_MAX);
|
||||
if (!(isAlphaOk && isRedOk && isGreenOk && isBlueOk)) {
|
||||
ROSEN_LOGE("JsBrush::SetColor Argv[0] is invalid");
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
|
||||
Color color(Color::ColorQuadSetARGB(alpha, red, green, blue));
|
||||
Color color(Color::ColorQuadSetARGB(argb[ARGC_ZERO], argb[ARGC_ONE], argb[ARGC_TWO], argb[ARGC_THREE]));
|
||||
brush->SetColor(color);
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
@ -161,18 +140,15 @@ napi_value JsBrush::SetAntiAlias(napi_env env, napi_callback_info info)
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
|
||||
size_t argc = ARGC_ONE;
|
||||
napi_value argv[ARGC_ONE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_ONE) {
|
||||
ROSEN_LOGE("JsBrush::SetAntiAlias Argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_ONE);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_boolean);
|
||||
|
||||
bool aa = true;
|
||||
if (!ConvertFromJsValue(env, argv[0], aa)) {
|
||||
ROSEN_LOGE("JsBrush::SetAntiAlias Argv[0] is invalid");
|
||||
return NapiGetUndefined(env);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM,
|
||||
"Parameter verification failed. The range of the aa parameter is true or false.");
|
||||
}
|
||||
|
||||
brush->SetAntiAlias(aa);
|
||||
@ -191,18 +167,15 @@ napi_value JsBrush::SetAlpha(napi_env env, napi_callback_info info)
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
|
||||
size_t argc = ARGC_ONE;
|
||||
napi_value argv[ARGC_ONE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_ONE) {
|
||||
ROSEN_LOGE("JsBrush::SetAlpha Argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_ONE);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_number);
|
||||
|
||||
int32_t alpha = 0;
|
||||
if (!ConvertClampFromJsValue(env, argv[0], alpha, 0, Color::RGB_MAX)) {
|
||||
if (!ConvertFromJsNumber(env, argv[ARGC_ZERO], alpha, 0, Color::RGB_MAX)) {
|
||||
ROSEN_LOGE("JsBrush::SetAlpha Argv[0] is invalid");
|
||||
return NapiGetUndefined(env);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM,
|
||||
"Parameter verification failed. The alpha range must be [0, 255].");
|
||||
}
|
||||
|
||||
brush->SetAlpha(alpha);
|
||||
@ -221,13 +194,9 @@ napi_value JsBrush::SetColorFilter(napi_env env, napi_callback_info info)
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
|
||||
size_t argc = ARGC_ONE;
|
||||
napi_value argv[ARGC_ONE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_ONE) {
|
||||
ROSEN_LOGE("JsBrush::SetColorFilter Argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_ONE);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_object);
|
||||
|
||||
JsColorFilter* jsColorFilter = nullptr;
|
||||
napi_unwrap(env, argv[0], reinterpret_cast<void **>(&jsColorFilter));
|
||||
@ -255,13 +224,9 @@ napi_value JsBrush::SetMaskFilter(napi_env env, napi_callback_info info)
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
|
||||
size_t argc = ARGC_ONE;
|
||||
napi_value argv[ARGC_ONE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_ONE) {
|
||||
ROSEN_LOGE("JsBrush::SetMaskFilter Argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_ONE);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_object);
|
||||
|
||||
JsMaskFilter* jsMaskFilter = nullptr;
|
||||
napi_unwrap(env, argv[ARGC_ZERO], reinterpret_cast<void **>(&jsMaskFilter));
|
||||
@ -288,13 +253,9 @@ napi_value JsBrush::SetBlendMode(napi_env env, napi_callback_info info)
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
|
||||
size_t argc = ARGC_ONE;
|
||||
napi_value argv[ARGC_ONE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_ONE) {
|
||||
ROSEN_LOGE("JsBrush::SetBlendMode Argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_ONE);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_number);
|
||||
|
||||
uint32_t mode = 0;
|
||||
if (!ConvertFromJsValue(env, argv[0], mode)) {
|
||||
@ -319,13 +280,9 @@ napi_value JsBrush::SetShadowLayer(napi_env env, napi_callback_info info)
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
|
||||
size_t argc = ARGC_ONE;
|
||||
napi_value argv[ARGC_ONE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_ONE) {
|
||||
ROSEN_LOGE("JsBrush::SetShadowLayer Argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_ONE);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_object);
|
||||
|
||||
JsShadowLayer* jsShadowLayer = nullptr;
|
||||
napi_unwrap(env, argv[ARGC_ZERO], reinterpret_cast<void **>(&jsShadowLayer));
|
||||
|
@ -446,41 +446,18 @@ napi_value JsCanvas::OnDrawRect(napi_env env, napi_callback_info info)
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
|
||||
size_t argc = ARGC_ONE;
|
||||
napi_value argv[ARGC_ONE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_ONE) {
|
||||
ROSEN_LOGE("JsCanvas::OnDrawRect Argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_ONE);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_object);
|
||||
|
||||
double ltrb[ARGC_FOUR] = {0};
|
||||
if (!ConvertFromJsRect(env, argv[ARGC_ZERO], ltrb, ARGC_FOUR)) {
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM,
|
||||
"Incorrect parameter0 type. The type of left, top, right and bottom must be number.");
|
||||
}
|
||||
|
||||
napi_valuetype valueType = napi_undefined;
|
||||
if (argv[0] == nullptr || napi_typeof(env, argv[0], &valueType) != napi_ok || valueType != napi_object) {
|
||||
ROSEN_LOGE("JsCanvas::OnDrawRect Argv[0] is invalid");
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
|
||||
napi_value tempValue = nullptr;
|
||||
double left = 0.0;
|
||||
double top = 0.0;
|
||||
double right = 0.0;
|
||||
double bottom = 0.0;
|
||||
napi_get_named_property(env, argv[0], "left", &tempValue);
|
||||
bool isLeftOk = ConvertFromJsValue(env, tempValue, left);
|
||||
napi_get_named_property(env, argv[0], "right", &tempValue);
|
||||
bool isRightOk = ConvertFromJsValue(env, tempValue, right);
|
||||
napi_get_named_property(env, argv[0], "top", &tempValue);
|
||||
bool isTopOk = ConvertFromJsValue(env, tempValue, top);
|
||||
napi_get_named_property(env, argv[0], "bottom", &tempValue);
|
||||
bool isBottomOk = ConvertFromJsValue(env, tempValue, bottom);
|
||||
if (!(isLeftOk && isRightOk && isTopOk && isBottomOk)) {
|
||||
ROSEN_LOGE("JsCanvas::OnDrawRect Argv[0] is invalid");
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
|
||||
Drawing::Rect drawingRect = Drawing::Rect(left, top, right, bottom);
|
||||
Drawing::Rect drawingRect = Drawing::Rect(ltrb[ARGC_ZERO], ltrb[ARGC_ONE], ltrb[ARGC_TWO], ltrb[ARGC_THREE]);
|
||||
JS_CALL_DRAWING_FUNC(m_canvas->DrawRect(drawingRect));
|
||||
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
|
||||
@ -496,13 +473,12 @@ napi_value JsCanvas::OnDrawCircle(napi_env env, napi_callback_info info)
|
||||
ROSEN_LOGE("JsCanvas::OnDrawCircle canvas is null");
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
size_t argc = ARGC_THREE;
|
||||
|
||||
napi_value argv[ARGC_THREE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_THREE) {
|
||||
ROSEN_LOGE("JsCanvas::OnDrawCircle Argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_THREE);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_number);
|
||||
CHECK_EACH_PARAM(ARGC_ONE, napi_number);
|
||||
CHECK_EACH_PARAM(ARGC_TWO, napi_number);
|
||||
|
||||
double x = 0.0;
|
||||
double y = 0.0;
|
||||
@ -514,8 +490,7 @@ napi_value JsCanvas::OnDrawCircle(napi_env env, napi_callback_info info)
|
||||
}
|
||||
|
||||
Drawing::Point centerPt = Drawing::Point(x, y);
|
||||
JS_CALL_DRAWING_FUNC(
|
||||
m_canvas->DrawCircle(centerPt, radius));
|
||||
JS_CALL_DRAWING_FUNC(m_canvas->DrawCircle(centerPt, radius));
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
|
||||
@ -534,11 +509,10 @@ napi_value JsCanvas::OnDrawImage(napi_env env, napi_callback_info info)
|
||||
}
|
||||
size_t argc = ARGC_FOUR;
|
||||
napi_value argv[ARGC_FOUR] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_THREE || argc > ARGC_FOUR) {
|
||||
ROSEN_LOGE("JsCanvas::OnDrawImage Argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITH_OPTIONAL_PARAMS(argv, argc, ARGC_THREE, ARGC_FOUR);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_object);
|
||||
CHECK_EACH_PARAM(ARGC_ONE, napi_number);
|
||||
CHECK_EACH_PARAM(ARGC_TWO, napi_number);
|
||||
|
||||
PixelMapNapi* pixelMapNapi = nullptr;
|
||||
double px = 0.0;
|
||||
@ -564,6 +538,7 @@ napi_value JsCanvas::OnDrawImage(napi_env env, napi_callback_info info)
|
||||
if (argc == ARGC_THREE) {
|
||||
JS_CALL_DRAWING_FUNC(m_canvas->DrawImage(*image, px, py, Drawing::SamplingOptions()));
|
||||
} else {
|
||||
CHECK_EACH_PARAM(ARGC_THREE, napi_object);
|
||||
JsSamplingOptions* jsSamplingOptions = nullptr;
|
||||
napi_unwrap(env, argv[ARGC_THREE], reinterpret_cast<void **>(&jsSamplingOptions));
|
||||
if (jsSamplingOptions == nullptr) {
|
||||
@ -597,34 +572,21 @@ napi_value JsCanvas::OnDrawColor(napi_env env, napi_callback_info info)
|
||||
}
|
||||
size_t argc = ARGC_TWO;
|
||||
napi_value argv[ARGC_TWO] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_ONE || argc > ARGC_TWO) {
|
||||
ROSEN_LOGE("JsCanvas::OnDrawColor Argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITH_OPTIONAL_PARAMS(argv, argc, ARGC_ONE, ARGC_TWO);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_object);
|
||||
|
||||
napi_value tempValue = nullptr;
|
||||
int32_t alpha = 0;
|
||||
int32_t red = 0;
|
||||
int32_t green = 0;
|
||||
int32_t blue = 0;
|
||||
napi_get_named_property(env, argv[0], "alpha", &tempValue);
|
||||
bool isAlphaOk = ConvertClampFromJsValue(env, tempValue, alpha, 0, Color::RGB_MAX);
|
||||
napi_get_named_property(env, argv[0], "red", &tempValue);
|
||||
bool isRedOk = ConvertClampFromJsValue(env, tempValue, red, 0, Color::RGB_MAX);
|
||||
napi_get_named_property(env, argv[0], "green", &tempValue);
|
||||
bool isGreenOk = ConvertClampFromJsValue(env, tempValue, green, 0, Color::RGB_MAX);
|
||||
napi_get_named_property(env, argv[0], "blue", &tempValue);
|
||||
bool isBlueOk = ConvertClampFromJsValue(env, tempValue, blue, 0, Color::RGB_MAX);
|
||||
if (!(isAlphaOk && isRedOk && isGreenOk && isBlueOk)) {
|
||||
int32_t argb[ARGC_FOUR] = {0};
|
||||
if (!ConvertFromJsColor(env, argv[ARGC_ZERO], argb, ARGC_FOUR)) {
|
||||
ROSEN_LOGE("JsCanvas::OnDrawColor Argv[0] is invalid");
|
||||
return NapiGetUndefined(env);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM,
|
||||
"Parameter verification failed. The range of color channels must be [0, 255].");
|
||||
}
|
||||
|
||||
auto color = Color::ColorQuadSetARGB(alpha, red, green, blue);
|
||||
auto color = Color::ColorQuadSetARGB(argb[ARGC_ZERO], argb[ARGC_ONE], argb[ARGC_TWO], argb[ARGC_THREE]);
|
||||
if (argc == ARGC_ONE) {
|
||||
JS_CALL_DRAWING_FUNC(m_canvas->DrawColor(color));
|
||||
} else {
|
||||
CHECK_EACH_PARAM(ARGC_ONE, napi_number);
|
||||
uint32_t jsMode = 0;
|
||||
if (!ConvertFromJsValue(env, argv[1], jsMode)) {
|
||||
ROSEN_LOGE("JsCanvas::OnDrawColor Argv[1] is invalid");
|
||||
@ -647,13 +609,12 @@ napi_value JsCanvas::OnDrawPoint(napi_env env, napi_callback_info info)
|
||||
ROSEN_LOGE("JsCanvas::OnDrawPoint canvas is nullptr");
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
size_t argc = ARGC_TWO;
|
||||
|
||||
napi_value argv[ARGC_TWO] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_TWO) {
|
||||
ROSEN_LOGE("JsCanvas::OnDrawPoint Argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_TWO);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_number);
|
||||
CHECK_EACH_PARAM(ARGC_ONE, napi_number);
|
||||
|
||||
double px = 0.0;
|
||||
double py = 0.0;
|
||||
if (!(ConvertFromJsValue(env, argv[0], px) && ConvertFromJsValue(env, argv[1], py))) {
|
||||
@ -677,13 +638,10 @@ napi_value JsCanvas::OnDrawPath(napi_env env, napi_callback_info info)
|
||||
ROSEN_LOGE("JsCanvas::OnDrawPath canvas is nullptr");
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
size_t argc = ARGC_ONE;
|
||||
|
||||
napi_value argv[ARGC_ONE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_ONE) {
|
||||
ROSEN_LOGE("JsCanvas::OnDrawPath Argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_ONE);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_object);
|
||||
|
||||
JsPath* jsPath = nullptr;
|
||||
napi_unwrap(env, argv[0], reinterpret_cast<void**>(&jsPath));
|
||||
@ -713,13 +671,13 @@ napi_value JsCanvas::OnDrawLine(napi_env env, napi_callback_info info)
|
||||
ROSEN_LOGE("JsCanvas::OnDrawLine canvas is nullptr");
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
size_t argc = ARGC_FOUR;
|
||||
|
||||
napi_value argv[ARGC_FOUR] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_FOUR) {
|
||||
ROSEN_LOGE("JsCanvas::OnDrawLine Argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_FOUR);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_number);
|
||||
CHECK_EACH_PARAM(ARGC_ONE, napi_number);
|
||||
CHECK_EACH_PARAM(ARGC_TWO, napi_number);
|
||||
CHECK_EACH_PARAM(ARGC_THREE, napi_number);
|
||||
|
||||
double startPx = 0.0;
|
||||
double startPy = 0.0;
|
||||
@ -747,13 +705,12 @@ napi_value JsCanvas::OnDrawText(napi_env env, napi_callback_info info)
|
||||
ROSEN_LOGE("JsCanvas::OnDrawText canvas is null");
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
size_t argc = ARGC_THREE;
|
||||
|
||||
napi_value argv[ARGC_THREE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_THREE) {
|
||||
ROSEN_LOGE("JsCanvas::OnDrawText Argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_THREE);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_object);
|
||||
CHECK_EACH_PARAM(ARGC_ONE, napi_number);
|
||||
CHECK_EACH_PARAM(ARGC_TWO, napi_number);
|
||||
|
||||
JsTextBlob* jsTextBlob = nullptr;
|
||||
double x = 0.0;
|
||||
@ -782,13 +739,17 @@ napi_value JsCanvas::OnDrawPixelMapMesh(napi_env env, napi_callback_info info)
|
||||
ROSEN_LOGE("JsCanvas::OnDrawPixelMapMesh canvas is null");
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
size_t argc = ARGC_SEVEN;
|
||||
|
||||
napi_value argv[ARGC_SEVEN] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc != ARGC_SEVEN) {
|
||||
ROSEN_LOGE("JsCanvas::OnDrawPixelMapMesh Argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_SEVEN);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_object);
|
||||
CHECK_EACH_PARAM(ARGC_ONE, napi_number);
|
||||
CHECK_EACH_PARAM(ARGC_TWO, napi_number);
|
||||
CHECK_EACH_PARAM(ARGC_THREE, napi_object);
|
||||
CHECK_EACH_PARAM(ARGC_FOUR, napi_number);
|
||||
CHECK_EACH_PARAM(ARGC_FIVE, napi_object);
|
||||
CHECK_EACH_PARAM(ARGC_SIX, napi_number);
|
||||
|
||||
PixelMapNapi* pixelMapNapi = nullptr;
|
||||
napi_unwrap(env, argv[0], reinterpret_cast<void**>(&pixelMapNapi));
|
||||
if (pixelMapNapi == nullptr) {
|
||||
@ -893,13 +854,10 @@ napi_value JsCanvas::AttachPen(napi_env env, napi_callback_info info)
|
||||
ROSEN_LOGE("JsCanvas::AttachPen canvas is nullptr");
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
size_t argc = ARGC_ONE;
|
||||
|
||||
napi_value argv[ARGC_ONE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_ONE) {
|
||||
ROSEN_LOGE("JsCanvas::AttachPen Argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_ONE);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_object);
|
||||
|
||||
JsPen* jsPen = nullptr;
|
||||
napi_unwrap(env, argv[0], reinterpret_cast<void **>(&jsPen));
|
||||
@ -926,13 +884,10 @@ napi_value JsCanvas::AttachBrush(napi_env env, napi_callback_info info)
|
||||
ROSEN_LOGE("JsCanvas::AttachBrush canvas is nullptr");
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
size_t argc = ARGC_ONE;
|
||||
|
||||
napi_value argv[ARGC_ONE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_ONE) {
|
||||
ROSEN_LOGE("JsCanvas::AttachBrush Argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_ONE);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_object);
|
||||
|
||||
JsBrush* jsBrush = nullptr;
|
||||
napi_unwrap(env, argv[0], reinterpret_cast<void **>(&jsBrush));
|
||||
@ -990,13 +945,12 @@ napi_value JsCanvas::OnSkew(napi_env env, napi_callback_info info)
|
||||
ROSEN_LOGE("JsCanvas::OnSkew m_canvas is null");
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
size_t argc = ARGC_TWO;
|
||||
|
||||
napi_value argv[ARGC_TWO] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc != ARGC_TWO) {
|
||||
ROSEN_LOGE("JsCanvas::OnSkew Argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_TWO);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_number);
|
||||
CHECK_EACH_PARAM(ARGC_ONE, napi_number);
|
||||
|
||||
double sx = 0.0;
|
||||
double sy = 0.0;
|
||||
if (!(ConvertFromJsValue(env, argv[ARGC_ZERO], sx) && ConvertFromJsValue(env, argv[ARGC_ONE], sy))) {
|
||||
@ -1020,13 +974,13 @@ napi_value JsCanvas::OnRotate(napi_env env, napi_callback_info info)
|
||||
ROSEN_LOGE("JsCanvas::OnRotate m_canvas is null");
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
size_t argc = ARGC_THREE;
|
||||
|
||||
napi_value argv[ARGC_THREE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc != ARGC_THREE) {
|
||||
ROSEN_LOGE("JsCanvas::OnRotate argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_THREE);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_number);
|
||||
CHECK_EACH_PARAM(ARGC_ONE, napi_number);
|
||||
CHECK_EACH_PARAM(ARGC_TWO, napi_number);
|
||||
|
||||
double degree = 0.0;
|
||||
double sx = 0.0;
|
||||
double sy = 0.0;
|
||||
@ -1052,13 +1006,6 @@ napi_value JsCanvas::OnGetSaveCount(napi_env env, napi_callback_info info)
|
||||
ROSEN_LOGE("JsCanvas::OnGetSaveCount canvas is null");
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
size_t argc = 0;
|
||||
napi_value argv[ARGC_ONE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc != 0) {
|
||||
ROSEN_LOGE("JsCanvas::OnGetSaveCount argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
return CreateJsNumber(env, m_canvas->GetSaveCount());
|
||||
}
|
||||
|
||||
@ -1076,11 +1023,8 @@ napi_value JsCanvas::OnClipPath(napi_env env, napi_callback_info info)
|
||||
}
|
||||
size_t argc = ARGC_THREE;
|
||||
napi_value argv[ARGC_THREE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_ONE || argc > ARGC_THREE) {
|
||||
ROSEN_LOGE("JsCanvas::OnClipPath argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITH_OPTIONAL_PARAMS(argv, argc, ARGC_ONE, ARGC_THREE);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_object);
|
||||
|
||||
JsPath* jsPath = nullptr;
|
||||
napi_unwrap(env, argv[ARGC_ZERO], reinterpret_cast<void **>(&jsPath));
|
||||
@ -1097,6 +1041,7 @@ napi_value JsCanvas::OnClipPath(napi_env env, napi_callback_info info)
|
||||
m_canvas->ClipPath(*path);
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
CHECK_EACH_PARAM(ARGC_ONE, napi_number);
|
||||
uint32_t jsClipOp = 0;
|
||||
if (!ConvertFromJsValue(env, argv[ARGC_ONE], jsClipOp)) {
|
||||
ROSEN_LOGE("JsCanvas::OnClipPath argv[1] is error");
|
||||
@ -1106,6 +1051,7 @@ napi_value JsCanvas::OnClipPath(napi_env env, napi_callback_info info)
|
||||
m_canvas->ClipPath(*path, static_cast<ClipOp>(jsClipOp));
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
CHECK_EACH_PARAM(ARGC_TWO, napi_boolean);
|
||||
bool jsDoAntiAlias = false;
|
||||
if (!ConvertFromJsValue(env, argv[ARGC_TWO], jsDoAntiAlias)) {
|
||||
ROSEN_LOGE("JsCanvas::OnClipPath argv[2] is error");
|
||||
@ -1127,13 +1073,12 @@ napi_value JsCanvas::OnTranslate(napi_env env, napi_callback_info info)
|
||||
ROSEN_LOGE("JsCanvas::OnTranslate m_canvas is null");
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
size_t argc = ARGC_TWO;
|
||||
|
||||
napi_value argv[ARGC_TWO] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_TWO) {
|
||||
ROSEN_LOGE("JsCanvas::OnTranslate argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_TWO);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_number);
|
||||
CHECK_EACH_PARAM(ARGC_ONE, napi_number);
|
||||
|
||||
double dx = 0.0;
|
||||
double dy = 0.0;
|
||||
if (!(ConvertFromJsValue(env, argv[ARGC_ZERO], dx) && ConvertFromJsValue(env, argv[ARGC_ONE], dy))) {
|
||||
@ -1156,9 +1101,7 @@ napi_value JsCanvas::OnSave(napi_env env, napi_callback_info info)
|
||||
ROSEN_LOGE("JsCanvas::OnSave canvas is null");
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
|
||||
auto saveCount = m_canvas->Save();
|
||||
return CreateJsNumber(env, saveCount);
|
||||
return CreateJsNumber(env, m_canvas->Save());
|
||||
}
|
||||
|
||||
napi_value JsCanvas::RestoreToCount(napi_env env, napi_callback_info info)
|
||||
@ -1173,13 +1116,11 @@ napi_value JsCanvas::OnRestoreToCount(napi_env env, napi_callback_info info)
|
||||
ROSEN_LOGE("JsCanvas::OnRestoreToCount canvas is nullptr");
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
size_t argc = ARGC_ONE;
|
||||
|
||||
napi_value argv[ARGC_ONE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_ONE) {
|
||||
ROSEN_LOGE("JsCanvas::OnRestoreToCount argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_ONE);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_number);
|
||||
|
||||
uint32_t count = 0;
|
||||
if (!(ConvertFromJsValue(env, argv[ARGC_ZERO], count))) {
|
||||
ROSEN_LOGE("JsCanvas::OnRestoreToCount argv is invalid");
|
||||
@ -1219,40 +1160,21 @@ napi_value JsCanvas::OnClipRect(napi_env env, napi_callback_info info)
|
||||
}
|
||||
size_t argc = ARGC_THREE;
|
||||
napi_value argv[ARGC_THREE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_ONE || argc > ARGC_THREE) {
|
||||
ROSEN_LOGE("JsCanvas::OnClipRect argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
CHECK_PARAM_NUMBER_WITH_OPTIONAL_PARAMS(argv, argc, ARGC_ONE, ARGC_THREE);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_object);
|
||||
|
||||
double ltrb[ARGC_FOUR] = {0};
|
||||
if (!ConvertFromJsRect(env, argv[ARGC_ZERO], ltrb, ARGC_FOUR)) {
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM,
|
||||
"Incorrect parameter0 type. The type of left, top, right and bottom must be number.");
|
||||
}
|
||||
napi_valuetype valueType = napi_undefined;
|
||||
if (argv[ARGC_ZERO] == nullptr || napi_typeof(env, argv[ARGC_ZERO], &valueType) != napi_ok ||
|
||||
valueType != napi_object) {
|
||||
ROSEN_LOGE("JsCanvas::OnClipRect argv[0] is invalid");
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
napi_value tempValue = nullptr;
|
||||
double left = 0.0;
|
||||
double top = 0.0;
|
||||
double right = 0.0;
|
||||
double bottom = 0.0;
|
||||
napi_get_named_property(env, argv[ARGC_ZERO], "left", &tempValue);
|
||||
bool isLeftOk = ConvertFromJsValue(env, tempValue, left);
|
||||
napi_get_named_property(env, argv[ARGC_ZERO], "right", &tempValue);
|
||||
bool isRightOk = ConvertFromJsValue(env, tempValue, right);
|
||||
napi_get_named_property(env, argv[ARGC_ZERO], "top", &tempValue);
|
||||
bool isTopOk = ConvertFromJsValue(env, tempValue, top);
|
||||
napi_get_named_property(env, argv[ARGC_ZERO], "bottom", &tempValue);
|
||||
bool isBottomOk = ConvertFromJsValue(env, tempValue, bottom);
|
||||
if (!(isLeftOk && isRightOk && isTopOk && isBottomOk)) {
|
||||
ROSEN_LOGE("JsCanvas::OnClipRect argv[0] is invalid");
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
Drawing::Rect drawingRect = Drawing::Rect(left, top, right, bottom);
|
||||
Drawing::Rect drawingRect = Drawing::Rect(ltrb[ARGC_ZERO], ltrb[ARGC_ONE], ltrb[ARGC_TWO], ltrb[ARGC_THREE]);
|
||||
|
||||
if (argc == ARGC_ONE) {
|
||||
m_canvas->ClipRect(drawingRect);
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
CHECK_EACH_PARAM(ARGC_ONE, napi_number);
|
||||
uint32_t clipOpInt = 0;
|
||||
if (!ConvertFromJsValue(env, argv[ARGC_ONE], clipOpInt)) {
|
||||
ROSEN_LOGE("JsCanvas::OnClipRect argv[1] is error");
|
||||
@ -1262,6 +1184,7 @@ napi_value JsCanvas::OnClipRect(napi_env env, napi_callback_info info)
|
||||
m_canvas->ClipRect(drawingRect, static_cast<ClipOp>(clipOpInt));
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
CHECK_EACH_PARAM(ARGC_TWO, napi_boolean);
|
||||
bool doAntiAlias = false;
|
||||
if (!ConvertFromJsValue(env, argv[ARGC_TWO], doAntiAlias)) {
|
||||
ROSEN_LOGE("JsCanvas::OnClipRect argv[2] is error");
|
||||
@ -1283,13 +1206,12 @@ napi_value JsCanvas::OnScale(napi_env env, napi_callback_info info)
|
||||
ROSEN_LOGE("JsCanvas::OnScale canvas is nullptr");
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
size_t argc = ARGC_TWO;
|
||||
|
||||
napi_value argv[ARGC_TWO] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_TWO) {
|
||||
ROSEN_LOGE("JsCanvas::OnScale argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_TWO);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_number);
|
||||
CHECK_EACH_PARAM(ARGC_ONE, napi_number);
|
||||
|
||||
double sx = 0.0;
|
||||
double sy = 0.0;
|
||||
if (!(ConvertFromJsValue(env, argv[ARGC_ZERO], sx) && ConvertFromJsValue(env, argv[1], sy))) {
|
||||
|
@ -103,30 +103,16 @@ void JsColorFilter::Destructor(napi_env env, void *nativeObject, void *finalize)
|
||||
|
||||
napi_value JsColorFilter::CreateBlendModeColorFilter(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = ARGC_TWO;
|
||||
napi_value argv[ARGC_TWO] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_TWO) {
|
||||
ROSEN_LOGE("JsColorFilter::CreateBlendModeColorFilter Argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_TWO);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_object);
|
||||
CHECK_EACH_PARAM(ARGC_ONE, napi_number);
|
||||
|
||||
napi_value tempValue = nullptr;
|
||||
int32_t alpha = 0;
|
||||
int32_t red = 0;
|
||||
int32_t green = 0;
|
||||
int32_t blue = 0;
|
||||
napi_get_named_property(env, argv[0], "alpha", &tempValue);
|
||||
bool isAlphaOk = ConvertClampFromJsValue(env, tempValue, alpha, 0, Color::RGB_MAX);
|
||||
napi_get_named_property(env, argv[0], "red", &tempValue);
|
||||
bool isRedOk = ConvertClampFromJsValue(env, tempValue, red, 0, Color::RGB_MAX);
|
||||
napi_get_named_property(env, argv[0], "green", &tempValue);
|
||||
bool isGreenOk = ConvertClampFromJsValue(env, tempValue, green, 0, Color::RGB_MAX);
|
||||
napi_get_named_property(env, argv[0], "blue", &tempValue);
|
||||
bool isBlueOk = ConvertClampFromJsValue(env, tempValue, blue, 0, Color::RGB_MAX);
|
||||
if (!(isAlphaOk && isRedOk && isGreenOk && isBlueOk)) {
|
||||
ROSEN_LOGE("JsColorFilter::CreateBlendModeColorFilter Argv[0] is invalid");
|
||||
return NapiGetUndefined(env);
|
||||
int32_t argb[ARGC_FOUR] = {0};
|
||||
if (!ConvertFromJsColor(env, argv[ARGC_ZERO], argb, ARGC_FOUR)) {
|
||||
ROSEN_LOGE("JsPen::SetColor Argv[0] is invalid");
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM,
|
||||
"Parameter verification failed. The range of color channels must be [0, 255].");
|
||||
}
|
||||
|
||||
uint32_t jsMode = 0;
|
||||
@ -135,20 +121,17 @@ napi_value JsColorFilter::CreateBlendModeColorFilter(napi_env env, napi_callback
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
|
||||
auto color = Color::ColorQuadSetARGB(alpha, red, green, blue);
|
||||
auto color = Color::ColorQuadSetARGB(argb[ARGC_ZERO], argb[ARGC_ONE], argb[ARGC_TWO], argb[ARGC_THREE]);
|
||||
std::shared_ptr<ColorFilter> colorFilter = ColorFilter::CreateBlendModeColorFilter(color, BlendMode(jsMode));
|
||||
return JsColorFilter::Create(env, colorFilter);
|
||||
}
|
||||
|
||||
napi_value JsColorFilter::CreateComposeColorFilter(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = ARGC_TWO;
|
||||
napi_value argv[ARGC_TWO] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_TWO) {
|
||||
ROSEN_LOGE("JsColorFilter::CreateComposeColorFilter Argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_TWO);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_object);
|
||||
CHECK_EACH_PARAM(ARGC_ONE, napi_object);
|
||||
|
||||
JsColorFilter *jsColorFilter1 = nullptr;
|
||||
JsColorFilter *jsColorFilter2 = nullptr;
|
||||
|
@ -186,13 +186,9 @@ napi_value JsFont::OnEnableSubpixel(napi_env env, napi_callback_info info)
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
|
||||
size_t argc = ARGC_ONE;
|
||||
napi_value argv[ARGC_ONE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_ONE) {
|
||||
ROSEN_LOGE("JsFont::OnEnableSubpixel Argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_ONE);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_boolean);
|
||||
|
||||
bool isSubpixel = false;
|
||||
if (!ConvertFromJsValue(env, argv[0], isSubpixel)) {
|
||||
@ -211,13 +207,9 @@ napi_value JsFont::OnEnableEmbolden(napi_env env, napi_callback_info info)
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
|
||||
size_t argc = ARGC_ONE;
|
||||
napi_value argv[ARGC_ONE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_ONE) {
|
||||
ROSEN_LOGE("JsFont::OnEnableEmbolden Argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_ONE);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_boolean);
|
||||
|
||||
bool isEmbolden = false;
|
||||
if (!ConvertFromJsValue(env, argv[0], isEmbolden)) {
|
||||
@ -236,13 +228,9 @@ napi_value JsFont::OnEnableLinearMetrics(napi_env env, napi_callback_info info)
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
|
||||
size_t argc = ARGC_ONE;
|
||||
napi_value argv[ARGC_ONE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_ONE) {
|
||||
ROSEN_LOGE("JsFont::OnEnableLinearMetrics Argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_ONE);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_boolean);
|
||||
|
||||
bool isLinearMetrics = false;
|
||||
if (!ConvertFromJsValue(env, argv[0], isLinearMetrics)) {
|
||||
@ -261,13 +249,9 @@ napi_value JsFont::OnSetSize(napi_env env, napi_callback_info info)
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
|
||||
size_t argc = ARGC_ONE;
|
||||
napi_value argv[ARGC_ONE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_ONE) {
|
||||
ROSEN_LOGE("JsFont::OnSetSize Argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_ONE);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_number);
|
||||
|
||||
double textSize = 0.0;
|
||||
if (!ConvertFromJsValue(env, argv[0], textSize)) {
|
||||
@ -308,13 +292,10 @@ napi_value JsFont::OnSetTypeface(napi_env env, napi_callback_info info)
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
|
||||
size_t argc = ARGC_ONE;
|
||||
napi_value argv[ARGC_ONE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_ONE) {
|
||||
ROSEN_LOGE("JsFont::OnSetTypeface Argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_ONE);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_object);
|
||||
|
||||
JsTypeface *jsTypeface = nullptr;
|
||||
napi_unwrap(env, argv[0], (void **)&jsTypeface);
|
||||
if (jsTypeface == nullptr) {
|
||||
@ -344,13 +325,10 @@ napi_value JsFont::OnMeasureText(napi_env env, napi_callback_info info)
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
|
||||
size_t argc = ARGC_TWO;
|
||||
napi_value argv[ARGC_TWO] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_TWO) {
|
||||
ROSEN_LOGE("JsFont::OnMeasureText Argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_TWO);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_string);
|
||||
CHECK_EACH_PARAM(ARGC_ONE, napi_number);
|
||||
|
||||
std::string text = "";
|
||||
if (!ConvertFromJsValue(env, argv[0], text)) {
|
||||
|
@ -14,10 +14,13 @@
|
||||
*/
|
||||
|
||||
#include "js_drawing_utils.h"
|
||||
|
||||
#ifdef ROSEN_OHOS
|
||||
#include <parameters.h>
|
||||
#endif
|
||||
|
||||
#include "draw/color.h"
|
||||
|
||||
namespace OHOS::Rosen {
|
||||
|
||||
#ifdef ROSEN_OHOS
|
||||
@ -81,5 +84,35 @@ napi_value NapiThrowError(napi_env env, DrawingErrorCode err, const std::string&
|
||||
napi_throw(env, CreateJsError(env, static_cast<int32_t>(err), message));
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
|
||||
static const char* ARGB_STRING[4] = {"alpha", "red", "green", "blue"};
|
||||
static const char* LTRB_STRING[4] = {"left", "top", "right", "bottom"};
|
||||
|
||||
bool ConvertFromJsColor(napi_env env, napi_value jsValue, int32_t* argb, size_t size)
|
||||
{
|
||||
napi_value tempValue = nullptr;
|
||||
for (size_t idx = 0; idx < size; idx++) {
|
||||
int32_t* curChannel = argb + idx;
|
||||
napi_get_named_property(env, jsValue, ARGB_STRING[idx], &tempValue);
|
||||
if (napi_get_value_int32(env, tempValue, curChannel) != napi_ok ||
|
||||
*curChannel < 0 || *curChannel > Color::RGB_MAX) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ConvertFromJsRect(napi_env env, napi_value jsValue, double* ltrb, size_t size)
|
||||
{
|
||||
napi_value tempValue = nullptr;
|
||||
for (size_t idx = 0; idx < size; idx++) {
|
||||
double* curEdge = ltrb + idx;
|
||||
napi_get_named_property(env, jsValue, LTRB_STRING[idx], &tempValue);
|
||||
if (napi_get_value_double(env, tempValue, curEdge) != napi_ok) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace Drawing
|
||||
} // namespace OHOS::Rosen
|
||||
|
@ -52,6 +52,32 @@ private:
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#define CHECK_PARAM_NUMBER_WITH_OPTIONAL_PARAMS(argv, argc, minNum, maxNum) \
|
||||
do { \
|
||||
if (napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr) != napi_ok || argc < minNum || argc > maxNum) { \
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, \
|
||||
std::string("Incorrect number of ") + __FUNCTION__ + " parameters."); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, paramNum) \
|
||||
do { \
|
||||
size_t argc = paramNum; \
|
||||
if (napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr) != napi_ok || argc != paramNum) { \
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, \
|
||||
std::string("Incorrect number of ") + __FUNCTION__ + " parameters."); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CHECK_EACH_PARAM(argc, type) \
|
||||
do { \
|
||||
napi_valuetype valueType = napi_undefined; \
|
||||
if (argv[argc] == nullptr || napi_typeof(env, argv[argc], &valueType) != napi_ok || valueType != type) { \
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, \
|
||||
std::string("Incorrect ") + __FUNCTION__ + " parameter" + std::to_string(argc) + " type."); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
namespace Drawing {
|
||||
constexpr size_t ARGC_ZERO = 0;
|
||||
constexpr size_t ARGC_ONE = 1;
|
||||
@ -222,14 +248,13 @@ bool ConvertFromJsValue(napi_env env, napi_value jsValue, T& value)
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool ConvertClampFromJsValue(napi_env env, napi_value jsValue, int32_t& value, int32_t lo, int32_t hi)
|
||||
bool ConvertFromJsColor(napi_env env, napi_value jsValue, int32_t* argb, size_t size);
|
||||
|
||||
bool ConvertFromJsRect(napi_env env, napi_value jsValue, double* ltrb, size_t size);
|
||||
|
||||
inline bool ConvertFromJsNumber(napi_env env, napi_value jsValue, int32_t& value, int32_t lo, int32_t hi)
|
||||
{
|
||||
if (jsValue == nullptr) {
|
||||
return false;
|
||||
}
|
||||
bool ret = napi_get_value_int32(env, jsValue, &value) == napi_ok;
|
||||
value = std::clamp(value, lo, hi);
|
||||
return ret;
|
||||
return napi_get_value_int32(env, jsValue, &value) == napi_ok && value >= lo && value <= hi;
|
||||
}
|
||||
|
||||
inline napi_value GetDoubleAndConvertToJsValue(napi_env env, double d)
|
||||
|
@ -99,13 +99,10 @@ void JsMaskFilter::Destructor(napi_env env, void *nativeObject, void *finalize)
|
||||
|
||||
napi_value JsMaskFilter::CreateBlurMaskFilter(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = ARGC_TWO;
|
||||
napi_value argv[ARGC_TWO] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc != ARGC_TWO) {
|
||||
ROSEN_LOGE("JsMaskFilter::CreateBlurMaskFilter argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_TWO);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_number);
|
||||
CHECK_EACH_PARAM(ARGC_ONE, napi_number);
|
||||
|
||||
uint32_t blurType = 0;
|
||||
if (!ConvertFromJsNumber(env, argv[ARGC_ZERO], blurType)) {
|
||||
|
@ -99,13 +99,10 @@ void JsPathEffect::Destructor(napi_env env, void *nativeObject, void *finalize)
|
||||
|
||||
napi_value JsPathEffect::CreateDashPathEffect(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = ARGC_TWO;
|
||||
napi_value argv[ARGC_TWO] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc != ARGC_TWO) {
|
||||
ROSEN_LOGE("JsPathEffect::CreateDashPathEffect argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_TWO);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_object);
|
||||
CHECK_EACH_PARAM(ARGC_ONE, napi_number);
|
||||
|
||||
uint32_t arrayLength = 0;
|
||||
napi_get_array_length(env, argv[ARGC_ZERO], &arrayLength);
|
||||
|
@ -147,13 +147,10 @@ napi_value JsPath::OnMoveTo(napi_env env, napi_callback_info info)
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
|
||||
size_t argc = ARGC_TWO;
|
||||
napi_value argv[ARGC_TWO] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_TWO) {
|
||||
ROSEN_LOGE("JsPath::OnMoveTo Argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_TWO);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_number);
|
||||
CHECK_EACH_PARAM(ARGC_ONE, napi_number);
|
||||
|
||||
double x = 0.0;
|
||||
double y = 0.0;
|
||||
@ -173,13 +170,10 @@ napi_value JsPath::OnLineTo(napi_env env, napi_callback_info info)
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
|
||||
size_t argc = ARGC_TWO;
|
||||
napi_value argv[ARGC_TWO] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_TWO) {
|
||||
ROSEN_LOGE("JsPath::OnLineTo Argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_TWO);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_number);
|
||||
CHECK_EACH_PARAM(ARGC_ONE, napi_number);
|
||||
|
||||
double x = 0.0;
|
||||
double y = 0.0;
|
||||
@ -199,13 +193,14 @@ napi_value JsPath::OnArcTo(napi_env env, napi_callback_info info)
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
|
||||
size_t argc = ARGC_SIX;
|
||||
napi_value argv[ARGC_SIX] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_SIX) {
|
||||
ROSEN_LOGE("JsPath::OnArcTo Argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_SIX);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_number);
|
||||
CHECK_EACH_PARAM(ARGC_ONE, napi_number);
|
||||
CHECK_EACH_PARAM(ARGC_TWO, napi_number);
|
||||
CHECK_EACH_PARAM(ARGC_THREE, napi_number);
|
||||
CHECK_EACH_PARAM(ARGC_FOUR, napi_number);
|
||||
CHECK_EACH_PARAM(ARGC_FIVE, napi_number);
|
||||
|
||||
double x1 = 0.0;
|
||||
double y1 = 0.0;
|
||||
@ -231,13 +226,12 @@ napi_value JsPath::OnQuadTo(napi_env env, napi_callback_info info)
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
|
||||
size_t argc = ARGC_FOUR;
|
||||
napi_value argv[ARGC_FOUR] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_FOUR) {
|
||||
ROSEN_LOGE("JsPath::OnQuadTo Argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_FOUR);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_number);
|
||||
CHECK_EACH_PARAM(ARGC_ONE, napi_number);
|
||||
CHECK_EACH_PARAM(ARGC_TWO, napi_number);
|
||||
CHECK_EACH_PARAM(ARGC_THREE, napi_number);
|
||||
|
||||
double ctrlPtX = 0.0;
|
||||
double ctrlPtY = 0.0;
|
||||
@ -260,13 +254,14 @@ napi_value JsPath::OnCubicTo(napi_env env, napi_callback_info info)
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
|
||||
size_t argc = ARGC_SIX;
|
||||
napi_value argv[ARGC_SIX] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_SIX) {
|
||||
ROSEN_LOGE("JsPath::OnCubicTo Argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_SIX);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_number);
|
||||
CHECK_EACH_PARAM(ARGC_ONE, napi_number);
|
||||
CHECK_EACH_PARAM(ARGC_TWO, napi_number);
|
||||
CHECK_EACH_PARAM(ARGC_THREE, napi_number);
|
||||
CHECK_EACH_PARAM(ARGC_FOUR, napi_number);
|
||||
CHECK_EACH_PARAM(ARGC_FIVE, napi_number);
|
||||
|
||||
double px1 = 0.0;
|
||||
double py1 = 0.0;
|
||||
|
@ -122,39 +122,18 @@ napi_value JsPen::SetColor(napi_env env, napi_callback_info info)
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
|
||||
size_t argc = ARGC_ONE;
|
||||
napi_value argv[ARGC_ONE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_ONE) {
|
||||
ROSEN_LOGE("JsPen::SetColor Argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_ONE);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_object);
|
||||
|
||||
napi_valuetype valueType = napi_undefined;
|
||||
if (argv[0] == nullptr || napi_typeof(env, argv[0], &valueType) != napi_ok || valueType != napi_object) {
|
||||
int32_t argb[ARGC_FOUR] = {0};
|
||||
if (!ConvertFromJsColor(env, argv[ARGC_ZERO], argb, ARGC_FOUR)) {
|
||||
ROSEN_LOGE("JsPen::SetColor Argv[0] is invalid");
|
||||
return NapiGetUndefined(env);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM,
|
||||
"Parameter verification failed. The range of color channels must be [0, 255].");
|
||||
}
|
||||
|
||||
napi_value tempValue = nullptr;
|
||||
int32_t alpha = 0;
|
||||
int32_t red = 0;
|
||||
int32_t green = 0;
|
||||
int32_t blue = 0;
|
||||
napi_get_named_property(env, argv[0], "alpha", &tempValue);
|
||||
bool isAlphaOk = ConvertClampFromJsValue(env, tempValue, alpha, 0, Color::RGB_MAX);
|
||||
napi_get_named_property(env, argv[0], "red", &tempValue);
|
||||
bool isRedOk = ConvertClampFromJsValue(env, tempValue, red, 0, Color::RGB_MAX);
|
||||
napi_get_named_property(env, argv[0], "green", &tempValue);
|
||||
bool isGreenOk = ConvertClampFromJsValue(env, tempValue, green, 0, Color::RGB_MAX);
|
||||
napi_get_named_property(env, argv[0], "blue", &tempValue);
|
||||
bool isBlueOk = ConvertClampFromJsValue(env, tempValue, blue, 0, Color::RGB_MAX);
|
||||
if (!(isAlphaOk && isRedOk && isGreenOk && isBlueOk)) {
|
||||
ROSEN_LOGE("JsPen::SetColor Argv[0] is invalid");
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
|
||||
Color color(Color::ColorQuadSetARGB(alpha, red, green, blue));
|
||||
Color color(Color::ColorQuadSetARGB(argb[ARGC_ZERO], argb[ARGC_ONE], argb[ARGC_TWO], argb[ARGC_THREE]));
|
||||
pen->SetColor(color);
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
@ -171,13 +150,9 @@ napi_value JsPen::SetStrokeWidth(napi_env env, napi_callback_info info)
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
|
||||
size_t argc = ARGC_ONE;
|
||||
napi_value argv[ARGC_ONE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_ONE) {
|
||||
ROSEN_LOGE("JsPen::SetStrokeWidth Argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_ONE);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_number);
|
||||
|
||||
double width = 0.0;
|
||||
if (!ConvertFromJsValue(env, argv[0], width)) {
|
||||
@ -202,13 +177,9 @@ napi_value JsPen::SetAntiAlias(napi_env env, napi_callback_info info)
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
|
||||
size_t argc = ARGC_ONE;
|
||||
napi_value argv[ARGC_ONE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_ONE) {
|
||||
ROSEN_LOGE("JsPen::SetAntiAlias Argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_ONE);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_boolean);
|
||||
|
||||
bool aa = true;
|
||||
if (!ConvertFromJsValue(env, argv[0], aa)) {
|
||||
@ -232,16 +203,12 @@ napi_value JsPen::SetAlpha(napi_env env, napi_callback_info info)
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
|
||||
size_t argc = ARGC_ONE;
|
||||
napi_value argv[ARGC_ONE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_ONE) {
|
||||
ROSEN_LOGE("JsPen::SetAlpha Argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_ONE);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_number);
|
||||
|
||||
int32_t alpha = 0;
|
||||
if (!ConvertClampFromJsValue(env, argv[0], alpha, 0, Color::RGB_MAX)) {
|
||||
if (!ConvertFromJsNumber(env, argv[0], alpha, 0, Color::RGB_MAX)) {
|
||||
ROSEN_LOGE("JsPen::SetAlpha Argv[0] is invalid");
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
@ -262,13 +229,9 @@ napi_value JsPen::SetBlendMode(napi_env env, napi_callback_info info)
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
|
||||
size_t argc = ARGC_ONE;
|
||||
napi_value argv[ARGC_ONE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_ONE) {
|
||||
ROSEN_LOGE("JsPen::SetBlendMode Argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_ONE);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_number);
|
||||
|
||||
uint32_t mode = 0;
|
||||
if (!ConvertFromJsValue(env, argv[0], mode)) {
|
||||
@ -292,13 +255,9 @@ napi_value JsPen::SetColorFilter(napi_env env, napi_callback_info info)
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
|
||||
size_t argc = ARGC_ONE;
|
||||
napi_value argv[ARGC_ONE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_ONE) {
|
||||
ROSEN_LOGE("JsPen::SetColorFilter Argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_ONE);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_object);
|
||||
|
||||
JsColorFilter* jsColorFilter = nullptr;
|
||||
napi_unwrap(env, argv[0], reinterpret_cast<void **>(&jsColorFilter));
|
||||
@ -326,13 +285,9 @@ napi_value JsPen::SetMaskFilter(napi_env env, napi_callback_info info)
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
|
||||
size_t argc = ARGC_ONE;
|
||||
napi_value argv[ARGC_ONE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc != ARGC_ONE) {
|
||||
ROSEN_LOGE("JsPen::SetMaskFilter Argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_ONE);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_object);
|
||||
|
||||
JsMaskFilter* jsMaskFilter = nullptr;
|
||||
napi_unwrap(env, argv[ARGC_ZERO], reinterpret_cast<void **>(&jsMaskFilter));
|
||||
@ -349,13 +304,9 @@ napi_value JsPen::SetMaskFilter(napi_env env, napi_callback_info info)
|
||||
|
||||
napi_value JsPen::SetDither(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = ARGC_ONE;
|
||||
napi_value argv[ARGC_ONE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_ONE) {
|
||||
ROSEN_LOGE("JsPen::SetDither Argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_ONE);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_boolean);
|
||||
|
||||
bool dither = false;
|
||||
if (!ConvertFromJsValue(env, argv[0], dither)) {
|
||||
@ -379,13 +330,9 @@ napi_value JsPen::SetJoinStyle(napi_env env, napi_callback_info info)
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
|
||||
size_t argc = ARGC_ONE;
|
||||
napi_value argv[ARGC_ONE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_ONE) {
|
||||
ROSEN_LOGE("JsPen::SetJoinStyle argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_ONE);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_number);
|
||||
|
||||
int32_t joinStyle = 0;
|
||||
if (!ConvertFromJsValue(env, argv[ARGC_ZERO], joinStyle)) {
|
||||
@ -425,13 +372,9 @@ napi_value JsPen::SetCapStyle(napi_env env, napi_callback_info info)
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
|
||||
size_t argc = ARGC_ONE;
|
||||
napi_value argv[ARGC_ONE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_ONE) {
|
||||
ROSEN_LOGE("JsPen::SetCapStyle argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_ONE);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_number);
|
||||
|
||||
int32_t capStyle = 0;
|
||||
if (!ConvertFromJsValue(env, argv[ARGC_ZERO], capStyle)) {
|
||||
@ -472,13 +415,9 @@ napi_value JsPen::SetPathEffect(napi_env env, napi_callback_info info)
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
|
||||
size_t argc = ARGC_ONE;
|
||||
napi_value argv[ARGC_ONE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_ONE) {
|
||||
ROSEN_LOGE("JsPen::SetPathEffect argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_ONE);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_object);
|
||||
|
||||
JsPathEffect* jsPathEffect = nullptr;
|
||||
napi_unwrap(env, argv[ARGC_ZERO], reinterpret_cast<void **>(&jsPathEffect));
|
||||
@ -504,13 +443,9 @@ napi_value JsPen::SetShadowLayer(napi_env env, napi_callback_info info)
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
|
||||
size_t argc = ARGC_ONE;
|
||||
napi_value argv[ARGC_ONE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_ONE) {
|
||||
ROSEN_LOGE("JsPen::SetShadowLayer argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_ONE);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_object);
|
||||
|
||||
JsShadowLayer* jsShadowLayer = nullptr;
|
||||
napi_unwrap(env, argv[ARGC_ZERO], reinterpret_cast<void **>(&jsShadowLayer));
|
||||
|
@ -89,13 +89,12 @@ JsShadowLayer::~JsShadowLayer()
|
||||
|
||||
napi_value JsShadowLayer::Create(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = ARGC_FOUR;
|
||||
napi_value argv[ARGC_FOUR] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc != ARGC_FOUR) {
|
||||
ROSEN_LOGE("JsShadowLayer::Create argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_FOUR);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_number);
|
||||
CHECK_EACH_PARAM(ARGC_ONE, napi_number);
|
||||
CHECK_EACH_PARAM(ARGC_TWO, napi_number);
|
||||
CHECK_EACH_PARAM(ARGC_THREE, napi_object);
|
||||
|
||||
double blurRadius = 0.0;
|
||||
if (!ConvertFromJsValue(env, argv[ARGC_ZERO], blurRadius)) {
|
||||
@ -115,26 +114,14 @@ napi_value JsShadowLayer::Create(napi_env env, napi_callback_info info)
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
|
||||
napi_value tempValue = nullptr;
|
||||
int32_t alpha = 0;
|
||||
int32_t red = 0;
|
||||
int32_t green = 0;
|
||||
int32_t blue = 0;
|
||||
napi_get_named_property(env, argv[ARGC_THREE], "alpha", &tempValue);
|
||||
bool isAlphaOk = ConvertClampFromJsValue(env, tempValue, alpha, 0, Color::RGB_MAX);
|
||||
napi_get_named_property(env, argv[ARGC_THREE], "red", &tempValue);
|
||||
bool isRedOk = ConvertClampFromJsValue(env, tempValue, red, 0, Color::RGB_MAX);
|
||||
napi_get_named_property(env, argv[ARGC_THREE], "green", &tempValue);
|
||||
bool isGreenOk = ConvertClampFromJsValue(env, tempValue, green, 0, Color::RGB_MAX);
|
||||
napi_get_named_property(env, argv[ARGC_THREE], "blue", &tempValue);
|
||||
bool isBlueOk = ConvertClampFromJsValue(env, tempValue, blue, 0, Color::RGB_MAX);
|
||||
if (!(isAlphaOk && isRedOk && isGreenOk && isBlueOk)) {
|
||||
ROSEN_LOGE("JsShadowLayer::Create argv[3] is invalid");
|
||||
return NapiGetUndefined(env);
|
||||
int32_t argb[ARGC_FOUR] = {0};
|
||||
if (!ConvertFromJsColor(env, argv[ARGC_ZERO], argb, ARGC_FOUR)) {
|
||||
ROSEN_LOGE("JsPen::SetColor Argv[0] is invalid");
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM,
|
||||
"Parameter verification failed. The range of color channels must be [0, 255].");
|
||||
}
|
||||
|
||||
ColorQuad color = Color::ColorQuadSetARGB(alpha, red, green, blue);
|
||||
|
||||
ColorQuad color = Color::ColorQuadSetARGB(argb[ARGC_ZERO], argb[ARGC_ONE], argb[ARGC_TWO], argb[ARGC_THREE]);
|
||||
std::shared_ptr<BlurDrawLooper> looper = BlurDrawLooper::CreateBlurDrawLooper(blurRadius, dx, dy, color);
|
||||
return JsShadowLayer::CreateLooper(env, looper);
|
||||
}
|
||||
|
@ -103,11 +103,9 @@ napi_value JsTextBlob::MakeFromRunBuffer(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = ARGC_THREE;
|
||||
napi_value argv[ARGC_THREE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_TWO || argc > ARGC_THREE) {
|
||||
ROSEN_LOGE("JsTextBlob::MakeFromRunBuffer Argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITH_OPTIONAL_PARAMS(argv, argc, ARGC_TWO, ARGC_THREE);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_object);
|
||||
CHECK_EACH_PARAM(ARGC_ONE, napi_object);
|
||||
|
||||
napi_value array = argv[0];
|
||||
uint32_t size = 0;
|
||||
@ -131,6 +129,7 @@ napi_value JsTextBlob::MakeFromRunBuffer(napi_env env, napi_callback_info info)
|
||||
if (argc == ARGC_TWO) {
|
||||
runBuffer = textBlobBuilder->AllocRunPos(*font, size);
|
||||
} else {
|
||||
CHECK_EACH_PARAM(ARGC_TWO, napi_object);
|
||||
Rect drawingRect;
|
||||
napi_valuetype isRectNullptr;
|
||||
if (!OnMakeDrawingRect(env, argv[ARGC_TWO], drawingRect, isRectNullptr)) {
|
||||
@ -156,27 +155,16 @@ bool JsTextBlob::OnMakeDrawingRect(napi_env& env, napi_value& argv, Rect& drawin
|
||||
{
|
||||
napi_typeof(env, argv, &isRectNullptr);
|
||||
if (isRectNullptr != napi_null) {
|
||||
napi_value tempValue = nullptr;
|
||||
double left = 0.0;
|
||||
double top = 0.0;
|
||||
double right = 0.0;
|
||||
double bottom = 0.0;
|
||||
napi_get_named_property(env, argv, "left", &tempValue);
|
||||
bool isLeftOk = ConvertFromJsValue(env, tempValue, left);
|
||||
napi_get_named_property(env, argv, "right", &tempValue);
|
||||
bool isRightOk = ConvertFromJsValue(env, tempValue, right);
|
||||
napi_get_named_property(env, argv, "top", &tempValue);
|
||||
bool isTopOk = ConvertFromJsValue(env, tempValue, top);
|
||||
napi_get_named_property(env, argv, "bottom", &tempValue);
|
||||
bool isBottomOk = ConvertFromJsValue(env, tempValue, bottom);
|
||||
if (!(isLeftOk && isRightOk && isTopOk && isBottomOk)) {
|
||||
return false;
|
||||
double ltrb[ARGC_FOUR] = {0};
|
||||
if (!ConvertFromJsRect(env, argv, ltrb, ARGC_FOUR)) {
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM,
|
||||
"Incorrect parameter2 type. The type of left, top, right and bottom must be number.");
|
||||
}
|
||||
|
||||
drawingRect.SetLeft(left);
|
||||
drawingRect.SetRight(right);
|
||||
drawingRect.SetTop(top);
|
||||
drawingRect.SetBottom(bottom);
|
||||
drawingRect.SetLeft(ltrb[ARGC_ZERO]);
|
||||
drawingRect.SetTop(ltrb[ARGC_ONE]);
|
||||
drawingRect.SetRight(ltrb[ARGC_TWO]);
|
||||
drawingRect.SetBottom(ltrb[ARGC_THREE]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -211,11 +199,9 @@ napi_value JsTextBlob::MakeFromString(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = ARGC_THREE;
|
||||
napi_value argv[ARGC_THREE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_TWO || argc > ARGC_THREE) {
|
||||
ROSEN_LOGE("JsTextBlob::MakeFromString Argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
CHECK_PARAM_NUMBER_WITH_OPTIONAL_PARAMS(argv, argc, ARGC_TWO, ARGC_THREE);
|
||||
CHECK_EACH_PARAM(ARGC_ZERO, napi_string);
|
||||
CHECK_EACH_PARAM(ARGC_ONE, napi_object);
|
||||
|
||||
void* pointerResult = nullptr;
|
||||
napi_unwrap(env, argv[1], &pointerResult);
|
||||
|
Loading…
Reference in New Issue
Block a user