增加中文转拼音- mac

This commit is contained in:
onvia
2023-07-27 15:04:13 +08:00
parent dd0373c362
commit 1840eab0d3
287 changed files with 61358 additions and 56240 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -331,8 +331,8 @@ ifeq ($(strip $(foreach prefix,$(NO_LOAD),\
endif
quiet_cmd_regen_makefile = ACTION Regenerating $@
cmd_regen_makefile = cd $(srcdir); /Users/wsl/.nvm/versions/node/v16.14.0/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py -fmake --ignore-environment "-Dlibrary=shared_library" "-Dvisibility=default" "-Dnode_root_dir=/Users/wsl/Library/Caches/node-gyp/16.14.0" "-Dnode_gyp_dir=/Users/wsl/.nvm/versions/node/v16.14.0/lib/node_modules/npm/node_modules/node-gyp" "-Dnode_lib_file=/Users/wsl/Library/Caches/node-gyp/16.14.0/<(target_arch)/node.lib" "-Dmodule_root_dir=/Users/wsl/Documents/Test/CC249Test/packages/ccc-tnt-psd2ui/node_modules/canvas" "-Dnode_engine=v8" "--depth=." "-Goutput_dir=." "--generator-output=build" -I/Users/wsl/Documents/Test/CC249Test/packages/ccc-tnt-psd2ui/node_modules/canvas/build/config.gypi -I/Users/wsl/.nvm/versions/node/v16.14.0/lib/node_modules/npm/node_modules/node-gyp/addon.gypi -I/Users/wsl/Library/Caches/node-gyp/16.14.0/include/node/common.gypi "--toplevel-dir=." binding.gyp
Makefile: $(srcdir)/../../../../../../../Library/Caches/node-gyp/16.14.0/include/node/common.gypi $(srcdir)/binding.gyp $(srcdir)/build/config.gypi $(srcdir)/../../../../../../../.nvm/versions/node/v16.14.0/lib/node_modules/npm/node_modules/node-gyp/addon.gypi
cmd_regen_makefile = cd $(srcdir); /Users/wsl/.nvm/versions/node/v16.14.0/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py -fmake --ignore-environment "-Dlibrary=shared_library" "-Dvisibility=default" "-Dnode_root_dir=/Users/wsl/Library/Caches/node-gyp/16.14.0" "-Dnode_gyp_dir=/Users/wsl/.nvm/versions/node/v16.14.0/lib/node_modules/npm/node_modules/node-gyp" "-Dnode_lib_file=/Users/wsl/Library/Caches/node-gyp/16.14.0/<(target_arch)/node.lib" "-Dmodule_root_dir=/Users/wsl/Documents/Git/ccc-tnt-psd2ui/ccc-tnt-psd2ui-v2.4.x/node_modules/canvas" "-Dnode_engine=v8" "--depth=." "-Goutput_dir=." "--generator-output=build" -I/Users/wsl/Documents/Git/ccc-tnt-psd2ui/ccc-tnt-psd2ui-v2.4.x/node_modules/canvas/build/config.gypi -I/Users/wsl/.nvm/versions/node/v16.14.0/lib/node_modules/npm/node_modules/node-gyp/addon.gypi -I/Users/wsl/Library/Caches/node-gyp/16.14.0/include/node/common.gypi "--toplevel-dir=." binding.gyp
Makefile: $(srcdir)/binding.gyp $(srcdir)/../../../../../../Library/Caches/node-gyp/16.14.0/include/node/common.gypi $(srcdir)/build/config.gypi $(srcdir)/../../../../../../.nvm/versions/node/v16.14.0/lib/node_modules/npm/node_modules/node-gyp/addon.gypi
$(call do_cmd,regen_makefile)
# "all" is a concatenation of the "all" targets from all the included

View File

@@ -355,16 +355,16 @@
"standalone_static_library": 1,
"fallback_to_build": "true",
"update_binary": "true",
"module": "/Users/wsl/Documents/Test/CC249Test/packages/ccc-tnt-psd2ui/node_modules/canvas/build/Release/canvas.node",
"module": "/Users/wsl/Documents/Git/ccc-tnt-psd2ui/ccc-tnt-psd2ui-v2.4.x/node_modules/canvas/build/Release/canvas.node",
"module_name": "canvas",
"module_path": "/Users/wsl/Documents/Test/CC249Test/packages/ccc-tnt-psd2ui/node_modules/canvas/build/Release",
"module_path": "/Users/wsl/Documents/Git/ccc-tnt-psd2ui/ccc-tnt-psd2ui-v2.4.x/node_modules/canvas/build/Release",
"napi_version": "8",
"node_abi_napi": "napi",
"node_napi_label": "node-v93",
"metrics_registry": "http://registry.npm.taobao.org/",
"global_prefix": "/Users/wsl/.nvm/versions/node/v16.14.0",
"registry": "http://registry.npm.taobao.org/",
"local_prefix": "/Users/wsl/Documents/Test/CC249Test/packages/ccc-tnt-psd2ui",
"local_prefix": "/Users/wsl/Documents/Git/ccc-tnt-psd2ui/ccc-tnt-psd2ui-v2.4.x",
"globalconfig": "/Users/wsl/.nvm/versions/node/v16.14.0/etc/npmrc",
"userconfig": "/Users/wsl/.npmrc",
"init_module": "/Users/wsl/.npm-init.js",

View File

@@ -1,19 +0,0 @@
toBuffer and other canvas methods were static and unwrapped
the this arg. this seemed weird. they are now instance
methods since that's how object wrap works, XXX add
instanceof checks?
node-canvas no lunger flushes microtasks when calling stream
cbs XXX wait now that I say it that sounds wrong?
we don't need CHECK_RECEIVER anymore? dbl check that?
TODO: check changes from As<X> to AsX. bad assumption.
dbl check try catch changes?
Error is now CairoError
global this in all callbacks, streamPNGSync now flushes microtasks
streamPDF uses MakeCallback, not runInAsyncScope

View File

@@ -1,7 +1,7 @@
{
"name": "canvas",
"description": "Canvas graphics API backed by Cairo",
"version": "2.11.2",
"version": "2.10.2",
"author": "TJ Holowaychuk <tj@learnboost.com>",
"main": "index.js",
"browser": "browser.js",

View File

@@ -171,13 +171,6 @@ Context2d::Context2d(Canvas *canvas) {
_canvas = canvas;
_context = canvas->createCairoContext();
_layout = pango_cairo_create_layout(_context);
// As of January 2023, Pango rounds glyph positions which renders text wider
// or narrower than the browser. See #2184 for more information
#if PANGO_VERSION_CHECK(1, 44, 0)
pango_context_set_round_glyph_positions(pango_layout_get_context(_layout), FALSE);
#endif
states.emplace();
state = &states.top();
pango_layout_set_font_description(_layout, state->fontDescription);
@@ -207,6 +200,7 @@ void Context2d::resetState() {
void Context2d::_resetPersistentHandles() {
_fillStyle.Reset();
_strokeStyle.Reset();
_font.Reset();
}
/*
@@ -2552,8 +2546,15 @@ NAN_METHOD(Context2d::MoveTo) {
NAN_GETTER(Context2d::GetFont) {
CHECK_RECEIVER(Context2d.GetFont);
Context2d *context = Nan::ObjectWrap::Unwrap<Context2d>(info.This());
Isolate *iso = Isolate::GetCurrent();
Local<Value> font;
info.GetReturnValue().Set(Nan::New(context->state->font).ToLocalChecked());
if (context->_font.IsEmpty())
font = Nan::New("10px sans-serif").ToLocalChecked();
else
font = context->_font.Get(iso);
info.GetReturnValue().Set(font);
}
/*
@@ -2616,7 +2617,7 @@ NAN_SETTER(Context2d::SetFont) {
context->state->fontDescription = sys_desc;
pango_layout_set_font_description(context->_layout, sys_desc);
context->state->font = *Nan::Utf8String(value);
context->_font.Reset(value);
}
/*

View File

@@ -27,7 +27,6 @@ struct canvas_state_t {
cairo_pattern_t* fillGradient = nullptr;
cairo_pattern_t* strokeGradient = nullptr;
PangoFontDescription* fontDescription = nullptr;
std::string font = "10px sans-serif";
cairo_filter_t patternQuality = CAIRO_FILTER_GOOD;
float globalAlpha = 1.f;
int shadowBlur = 0;
@@ -58,7 +57,6 @@ struct canvas_state_t {
shadowOffsetY = other.shadowOffsetY;
textDrawingMode = other.textDrawingMode;
fontDescription = pango_font_description_copy(other.fontDescription);
font = other.font;
imageSmoothingEnabled = other.imageSmoothingEnabled;
}
@@ -218,6 +216,7 @@ class Context2d : public Nan::ObjectWrap {
void _setStrokePattern(v8::Local<v8::Value> arg);
Nan::Persistent<v8::Value> _fillStyle;
Nan::Persistent<v8::Value> _strokeStyle;
Nan::Persistent<v8::Value> _font;
Canvas *_canvas;
cairo_t *_context;
cairo_path_t *_path;

View File

@@ -1,226 +0,0 @@
// Copyright (c) 2010 LearnBoost <tj@learnboost.com>
#pragma once
#include "cairo.h"
#include "Canvas.h"
#include "color.h"
#include "napi.h"
#include "uv.h"
#include <pango/pangocairo.h>
#include <stack>
/*
* State struct.
*
* Used in conjunction with Save() / Restore() since
* cairo's gstate maintains only a single source pattern at a time.
*/
struct canvas_state_t {
rgba_t fill = { 0, 0, 0, 1 };
rgba_t stroke = { 0, 0, 0, 1 };
rgba_t shadow = { 0, 0, 0, 0 };
double shadowOffsetX = 0.;
double shadowOffsetY = 0.;
cairo_pattern_t* fillPattern = nullptr;
cairo_pattern_t* strokePattern = nullptr;
cairo_pattern_t* fillGradient = nullptr;
cairo_pattern_t* strokeGradient = nullptr;
PangoFontDescription* fontDescription = nullptr;
std::string font = "10px sans-serif";
cairo_filter_t patternQuality = CAIRO_FILTER_GOOD;
float globalAlpha = 1.f;
int shadowBlur = 0;
text_align_t textAlignment = TEXT_ALIGNMENT_LEFT; // TODO default is supposed to be START
text_baseline_t textBaseline = TEXT_BASELINE_ALPHABETIC;
canvas_draw_mode_t textDrawingMode = TEXT_DRAW_PATHS;
bool imageSmoothingEnabled = true;
canvas_state_t() {
fontDescription = pango_font_description_from_string("sans");
pango_font_description_set_absolute_size(fontDescription, 10 * PANGO_SCALE);
}
canvas_state_t(const canvas_state_t& other) {
fill = other.fill;
stroke = other.stroke;
patternQuality = other.patternQuality;
fillPattern = other.fillPattern;
strokePattern = other.strokePattern;
fillGradient = other.fillGradient;
strokeGradient = other.strokeGradient;
globalAlpha = other.globalAlpha;
textAlignment = other.textAlignment;
textBaseline = other.textBaseline;
shadow = other.shadow;
shadowBlur = other.shadowBlur;
shadowOffsetX = other.shadowOffsetX;
shadowOffsetY = other.shadowOffsetY;
textDrawingMode = other.textDrawingMode;
fontDescription = pango_font_description_copy(other.fontDescription);
font = other.font;
imageSmoothingEnabled = other.imageSmoothingEnabled;
}
~canvas_state_t() {
pango_font_description_free(fontDescription);
}
};
/*
* Equivalent to a PangoRectangle but holds floats instead of ints
* (software pixels are stored here instead of pango units)
*
* Should be compatible with PANGO_ASCENT, PANGO_LBEARING, etc.
*/
typedef struct {
float x;
float y;
float width;
float height;
} float_rectangle;
class Context2d : public Napi::ObjectWrap<Context2d> {
public:
std::stack<canvas_state_t> states;
canvas_state_t *state;
Context2d(Canvas *canvas);
static Napi::FunctionReference _DOMMatrix;
static Napi::FunctionReference _parseFont;
static Napi::FunctionReference constructor;
static void Initialize(Napi::Env& env, Napi::Object& target);
static Napi::Value New(const Napi::CallbackInfo& info);
static Napi::Value SaveExternalModules(const Napi::CallbackInfo& info);
static Napi::Value DrawImage(const Napi::CallbackInfo& info);
static Napi::Value PutImageData(const Napi::CallbackInfo& info);
static Napi::Value Save(const Napi::CallbackInfo& info);
static Napi::Value Restore(const Napi::CallbackInfo& info);
static Napi::Value Rotate(const Napi::CallbackInfo& info);
static Napi::Value Translate(const Napi::CallbackInfo& info);
static Napi::Value Scale(const Napi::CallbackInfo& info);
static Napi::Value Transform(const Napi::CallbackInfo& info);
static Napi::Value GetTransform(const Napi::CallbackInfo& info);
static Napi::Value ResetTransform(const Napi::CallbackInfo& info);
static Napi::Value SetTransform(const Napi::CallbackInfo& info);
static Napi::Value IsPointInPath(const Napi::CallbackInfo& info);
static Napi::Value BeginPath(const Napi::CallbackInfo& info);
static Napi::Value ClosePath(const Napi::CallbackInfo& info);
static Napi::Value AddPage(const Napi::CallbackInfo& info);
static Napi::Value Clip(const Napi::CallbackInfo& info);
static Napi::Value Fill(const Napi::CallbackInfo& info);
static Napi::Value Stroke(const Napi::CallbackInfo& info);
static Napi::Value FillText(const Napi::CallbackInfo& info);
static Napi::Value StrokeText(const Napi::CallbackInfo& info);
static Napi::Value SetFont(const Napi::CallbackInfo& info);
static Napi::Value SetFillColor(const Napi::CallbackInfo& info);
static Napi::Value SetStrokeColor(const Napi::CallbackInfo& info);
static Napi::Value SetStrokePattern(const Napi::CallbackInfo& info);
static Napi::Value SetTextAlignment(const Napi::CallbackInfo& info);
static Napi::Value SetLineDash(const Napi::CallbackInfo& info);
static Napi::Value GetLineDash(const Napi::CallbackInfo& info);
static Napi::Value MeasureText(const Napi::CallbackInfo& info);
static Napi::Value BezierCurveTo(const Napi::CallbackInfo& info);
static Napi::Value QuadraticCurveTo(const Napi::CallbackInfo& info);
static Napi::Value LineTo(const Napi::CallbackInfo& info);
static Napi::Value MoveTo(const Napi::CallbackInfo& info);
static Napi::Value FillRect(const Napi::CallbackInfo& info);
static Napi::Value StrokeRect(const Napi::CallbackInfo& info);
static Napi::Value ClearRect(const Napi::CallbackInfo& info);
static Napi::Value Rect(const Napi::CallbackInfo& info);
static Napi::Value RoundRect(const Napi::CallbackInfo& info);
static Napi::Value Arc(const Napi::CallbackInfo& info);
static Napi::Value ArcTo(const Napi::CallbackInfo& info);
static Napi::Value Ellipse(const Napi::CallbackInfo& info);
static Napi::Value GetImageData(const Napi::CallbackInfo& info);
static Napi::Value CreateImageData(const Napi::CallbackInfo& info);
static Napi::Value GetStrokeColor(const Napi::CallbackInfo& info);
static Napi::Value CreatePattern(const Napi::CallbackInfo& info);
static Napi::Value CreateLinearGradient(const Napi::CallbackInfo& info);
static Napi::Value CreateRadialGradient(const Napi::CallbackInfo& info);
Napi::Value GetFormat(const Napi::CallbackInfo& info);
Napi::Value GetPatternQuality(const Napi::CallbackInfo& info);
Napi::Value GetImageSmoothingEnabled(const Napi::CallbackInfo& info);
Napi::Value GetGlobalCompositeOperation(const Napi::CallbackInfo& info);
Napi::Value GetGlobalAlpha(const Napi::CallbackInfo& info);
Napi::Value GetShadowColor(const Napi::CallbackInfo& info);
Napi::Value GetMiterLimit(const Napi::CallbackInfo& info);
Napi::Value GetLineCap(const Napi::CallbackInfo& info);
Napi::Value GetLineJoin(const Napi::CallbackInfo& info);
Napi::Value GetLineWidth(const Napi::CallbackInfo& info);
Napi::Value GetLineDashOffset(const Napi::CallbackInfo& info);
Napi::Value GetShadowOffsetX(const Napi::CallbackInfo& info);
Napi::Value GetShadowOffsetY(const Napi::CallbackInfo& info);
Napi::Value GetShadowBlur(const Napi::CallbackInfo& info);
Napi::Value GetAntiAlias(const Napi::CallbackInfo& info);
Napi::Value GetTextDrawingMode(const Napi::CallbackInfo& info);
Napi::Value GetQuality(const Napi::CallbackInfo& info);
Napi::Value GetCurrentTransform(const Napi::CallbackInfo& info);
Napi::Value GetFillStyle(const Napi::CallbackInfo& info);
Napi::Value GetStrokeStyle(const Napi::CallbackInfo& info);
Napi::Value GetFont(const Napi::CallbackInfo& info);
Napi::Value GetTextBaseline(const Napi::CallbackInfo& info);
Napi::Value GetTextAlign(const Napi::CallbackInfo& info);
void SetPatternQuality(const Napi::CallbackInfo& info, const Napi::Value& value);
void SetImageSmoothingEnabled(const Napi::CallbackInfo& info, const Napi::Value& value);
void SetGlobalCompositeOperation(const Napi::CallbackInfo& info, const Napi::Value& value);
void SetGlobalAlpha(const Napi::CallbackInfo& info, const Napi::Value& value);
void SetShadowColor(const Napi::CallbackInfo& info, const Napi::Value& value);
void SetMiterLimit(const Napi::CallbackInfo& info, const Napi::Value& value);
void SetLineCap(const Napi::CallbackInfo& info, const Napi::Value& value);
void SetLineJoin(const Napi::CallbackInfo& info, const Napi::Value& value);
void SetLineWidth(const Napi::CallbackInfo& info, const Napi::Value& value);
void SetLineDashOffset(const Napi::CallbackInfo& info, const Napi::Value& value);
void SetShadowOffsetX(const Napi::CallbackInfo& info, const Napi::Value& value);
void SetShadowOffsetY(const Napi::CallbackInfo& info, const Napi::Value& value);
void SetShadowBlur(const Napi::CallbackInfo& info, const Napi::Value& value);
void SetAntiAlias(const Napi::CallbackInfo& info, const Napi::Value& value);
void SetTextDrawingMode(const Napi::CallbackInfo& info, const Napi::Value& value);
void SetQuality(const Napi::CallbackInfo& info, const Napi::Value& value);
void SetCurrentTransform(const Napi::CallbackInfo& info, const Napi::Value& value);
void SetFillStyle(const Napi::CallbackInfo& info, const Napi::Value& value);
void SetStrokeStyle(const Napi::CallbackInfo& info, const Napi::Value& value);
void SetFont(const Napi::CallbackInfo& info, const Napi::Value& value);
void SetTextBaseline(const Napi::CallbackInfo& info, const Napi::Value& value);
void SetTextAlign(const Napi::CallbackInfo& info, const Napi::Value& value);
inline void setContext(cairo_t *ctx) { _context = ctx; }
inline cairo_t *context(){ return _context; }
inline Canvas *canvas(){ return _canvas; }
inline bool hasShadow();
void inline setSourceRGBA(rgba_t color);
void inline setSourceRGBA(cairo_t *ctx, rgba_t color);
void setTextPath(double x, double y);
void blur(cairo_surface_t *surface, int radius);
void shadow(void (fn)(cairo_t *cr));
void shadowStart();
void shadowApply();
void savePath();
void restorePath();
void saveState();
void restoreState();
void inline setFillRule(Napi::Value value);
void fill(bool preserve = false);
void stroke(bool preserve = false);
void save();
void restore();
void setFontFromState();
void resetState();
inline PangoLayout *layout(){ return _layout; }
private:
~Context2d();
void _resetPersistentHandles();
Napi::Value _getFillColor();
Napi::Value _getStrokeColor();
void _setFillColor(Napi::Value arg);
void _setFillPattern(Napi::Value arg);
void _setStrokeColor(Napi::Value arg);
void _setStrokePattern(Napi::Value arg);
Napi::Persistent<v8::Value> _fillStyle;
Napi::Persistent<v8::Value> _strokeStyle;
Canvas *_canvas;
cairo_t *_context;
cairo_path_t *_path;
PangoLayout *_layout;
};

View File

@@ -1,8 +0,0 @@
#include <napi.h>
struct InstanceData {
Napi::FunctionReference ImageBackendCtor;
Napi::FunctionReference PdfBackendCtor;
Napi::FunctionReference SvgBackendCtor;
Napi::FunctionReference CanvasCtor;
};

View File

@@ -264,7 +264,7 @@ get_pango_font_description(unsigned char* filepath) {
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL,
NULL
);
if(!hFile){

View File

@@ -1,3 +0,0 @@
Notes:
* `"unified-signatures": false` because of https://github.com/Microsoft/dtslint/issues/183

View File

@@ -1,4 +1,5 @@
// TypeScript Version: 3.0
/// <reference lib="dom" />
import { Readable } from 'stream'
@@ -79,7 +80,7 @@ export class Canvas {
constructor(width: number, height: number, type?: 'image'|'pdf'|'svg')
getContext(contextId: '2d', contextAttributes?: NodeCanvasRenderingContext2DSettings): CanvasRenderingContext2D
getContext(contextId: '2d', contextAttributes?: NodeCanvasRenderingContext2DSettings): NodeCanvasRenderingContext2D
/**
* For image canvases, encodes the canvas as a PNG. For PDF canvases,
@@ -127,126 +128,19 @@ export class Canvas {
toDataURL(mimeType: 'image/jpeg', quality: number, cb: (err: Error|null, result: string) => void): void
}
export interface TextMetrics {
readonly actualBoundingBoxAscent: number;
readonly actualBoundingBoxDescent: number;
readonly actualBoundingBoxLeft: number;
readonly actualBoundingBoxRight: number;
readonly fontBoundingBoxAscent: number;
readonly fontBoundingBoxDescent: number;
readonly width: number;
}
export type CanvasFillRule = 'evenodd' | 'nonzero';
export type GlobalCompositeOperation =
| 'clear'
| 'copy'
| 'destination'
| 'source-over'
| 'destination-over'
| 'source-in'
| 'destination-in'
| 'source-out'
| 'destination-out'
| 'source-atop'
| 'destination-atop'
| 'xor'
| 'lighter'
| 'normal'
| 'multiply'
| 'screen'
| 'overlay'
| 'darken'
| 'lighten'
| 'color-dodge'
| 'color-burn'
| 'hard-light'
| 'soft-light'
| 'difference'
| 'exclusion'
| 'hue'
| 'saturation'
| 'color'
| 'luminosity'
| 'saturate';
export type CanvasLineCap = 'butt' | 'round' | 'square';
export type CanvasLineJoin = 'bevel' | 'miter' | 'round';
export type CanvasTextBaseline = 'alphabetic' | 'bottom' | 'hanging' | 'ideographic' | 'middle' | 'top';
export type CanvasTextAlign = 'center' | 'end' | 'left' | 'right' | 'start';
export class CanvasRenderingContext2D {
drawImage(image: Canvas|Image, dx: number, dy: number): void
drawImage(image: Canvas|Image, dx: number, dy: number, dw: number, dh: number): void
drawImage(image: Canvas|Image, sx: number, sy: number, sw: number, sh: number, dx: number, dy: number, dw: number, dh: number): void
putImageData(imagedata: ImageData, dx: number, dy: number): void;
putImageData(imagedata: ImageData, dx: number, dy: number, dirtyX: number, dirtyY: number, dirtyWidth: number, dirtyHeight: number): void;
getImageData(sx: number, sy: number, sw: number, sh: number): ImageData;
createImageData(sw: number, sh: number): ImageData;
createImageData(imagedata: ImageData): ImageData;
/**
* For PDF canvases, adds another page. If width and/or height are omitted,
* the canvas's initial size is used.
*/
addPage(width?: number, height?: number): void
save(): void;
restore(): void;
rotate(angle: number): void;
translate(x: number, y: number): void;
transform(a: number, b: number, c: number, d: number, e: number, f: number): void;
getTransform(): DOMMatrix;
resetTransform(): void;
setTransform(transform?: DOMMatrix): void;
isPointInPath(x: number, y: number, fillRule?: CanvasFillRule): boolean;
scale(x: number, y: number): void;
clip(fillRule?: CanvasFillRule): void;
fill(fillRule?: CanvasFillRule): void;
stroke(): void;
fillText(text: string, x: number, y: number, maxWidth?: number): void;
strokeText(text: string, x: number, y: number, maxWidth?: number): void;
fillRect(x: number, y: number, w: number, h: number): void;
strokeRect(x: number, y: number, w: number, h: number): void;
clearRect(x: number, y: number, w: number, h: number): void;
rect(x: number, y: number, w: number, h: number): void;
roundRect(x: number, y: number, w: number, h: number, radii?: number | number[]): void;
measureText(text: string): TextMetrics;
moveTo(x: number, y: number): void;
lineTo(x: number, y: number): void;
bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): void;
quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): void;
beginPath(): void;
closePath(): void;
arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, counterclockwise?: boolean): void;
arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void;
ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, counterclockwise?: boolean): void;
setLineDash(segments: number[]): void;
getLineDash(): number[];
createPattern(image: Canvas|Image, repetition: 'repeat' | 'repeat-x' | 'repeat-y' | 'no-repeat' | '' | null): CanvasPattern
createLinearGradient(x0: number, y0: number, x1: number, y1: number): CanvasGradient;
createRadialGradient(x0: number, y0: number, r0: number, x1: number, y1: number, r1: number): CanvasGradient;
declare class NodeCanvasRenderingContext2D extends CanvasRenderingContext2D {
/**
* _Non-standard_. Defaults to 'good'. Affects pattern (gradient, image,
* etc.) rendering quality.
*/
patternQuality: 'fast' | 'good' | 'best' | 'nearest' | 'bilinear'
imageSmoothingEnabled: boolean;
globalCompositeOperation: GlobalCompositeOperation;
globalAlpha: number;
shadowColor: string;
miterLimit: number;
lineWidth: number;
lineCap: CanvasLineCap;
lineJoin: CanvasLineJoin;
lineDashOffset: number;
shadowOffsetX: number;
shadowOffsetY: number;
shadowBlur: number;
/** _Non-standard_. Sets the antialiasing mode. */
antialias: 'default' | 'gray' | 'none' | 'subpixel'
/**
* _Non-standard_. Defaults to 'good'. Like `patternQuality`, but applies to
* transformations affecting more than just patterns.
*/
quality: 'fast' | 'good' | 'best' | 'nearest' | 'bilinear'
/**
* Defaults to 'path'. The effect depends on the canvas type:
*
@@ -271,28 +165,55 @@ export class CanvasRenderingContext2D {
* (aside from using the stroke and fill style, respectively).
*/
textDrawingMode: 'path' | 'glyph'
/**
* _Non-standard_. Defaults to 'good'. Like `patternQuality`, but applies to
* transformations affecting more than just patterns.
*/
quality: 'fast' | 'good' | 'best' | 'nearest' | 'bilinear'
/** _Non-standard_. Sets the antialiasing mode. */
antialias: 'default' | 'gray' | 'none' | 'subpixel'
// Standard, but not in the TS lib and needs node-canvas class return type.
/** Returns or sets a `DOMMatrix` for the current transformation matrix. */
currentTransform: DOMMatrix
fillStyle: string | CanvasGradient | CanvasPattern;
strokeStyle: string | CanvasGradient | CanvasPattern;
font: string;
textBaseline: CanvasTextBaseline;
textAlign: CanvasTextAlign;
canvas: Canvas;
}
currentTransform: NodeCanvasDOMMatrix
export class CanvasGradient {
addColorStop(offset: number, color: string): void;
}
// Standard, but need node-canvas class versions:
getTransform(): NodeCanvasDOMMatrix
setTransform(a: number, b: number, c: number, d: number, e: number, f: number): void
setTransform(transform?: NodeCanvasDOMMatrix): void
createImageData(sw: number, sh: number): NodeCanvasImageData
createImageData(imagedata: NodeCanvasImageData): NodeCanvasImageData
getImageData(sx: number, sy: number, sw: number, sh: number): NodeCanvasImageData
putImageData(imagedata: NodeCanvasImageData, dx: number, dy: number): void
putImageData(imagedata: NodeCanvasImageData, dx: number, dy: number, dirtyX: number, dirtyY: number, dirtyWidth: number, dirtyHeight: number): void
drawImage(image: Canvas|Image, dx: number, dy: number): void
drawImage(image: Canvas|Image, dx: number, dy: number, dw: number, dh: number): void
drawImage(image: Canvas|Image, sx: number, sy: number, sw: number, sh: number, dx: number, dy: number, dw: number, dh: number): void
/**
* **Do not use this overload. Use one of the other three overloads.** This
* is a catch-all definition required for compatibility with the base
* `CanvasRenderingContext2D` interface.
*/
drawImage(...args: any[]): void
createPattern(image: Canvas|Image, repetition: 'repeat' | 'repeat-x' | 'repeat-y' | 'no-repeat' | '' | null): NodeCanvasCanvasPattern
/**
* **Do not use this overload. Use the other three overload.** This is a
* catch-all definition required for compatibility with the base
* `CanvasRenderingContext2D` interface.
*/
createPattern(...args: any[]): NodeCanvasCanvasPattern
createLinearGradient(x0: number, y0: number, x1: number, y1: number): NodeCanvasCanvasGradient;
createRadialGradient(x0: number, y0: number, r0: number, x1: number, y1: number, r1: number): NodeCanvasCanvasGradient;
export class CanvasPattern {
setTransform(transform?: DOMMatrix): void;
/**
* For PDF canvases, adds another page. If width and/or height are omitted,
* the canvas's initial size is used.
*/
addPage(width?: number, height?: number): void
}
export { NodeCanvasRenderingContext2D as CanvasRenderingContext2D }
declare class NodeCanvasCanvasGradient extends CanvasGradient {}
export { NodeCanvasCanvasGradient as CanvasGradient }
declare class NodeCanvasCanvasPattern extends CanvasPattern {}
export { NodeCanvasCanvasPattern as CanvasPattern }
// This does not extend HTMLImageElement because there are dozens of inherited
// methods and properties that we do not provide.
@@ -391,79 +312,14 @@ export class JPEGStream extends Readable {}
/** This class must not be constructed directly; use `canvas.createPDFStream()`. */
export class PDFStream extends Readable {}
export class DOMPoint {
w: number;
x: number;
y: number;
z: number;
}
declare class NodeCanvasDOMMatrix extends DOMMatrix {}
export { NodeCanvasDOMMatrix as DOMMatrix }
export class DOMMatrix {
constructor(init: string | number[]);
toString(): string;
multiply(other?: DOMMatrix): DOMMatrix;
multiplySelf(other?: DOMMatrix): DOMMatrix;
preMultiplySelf(other?: DOMMatrix): DOMMatrix;
translate(tx?: number, ty?: number, tz?: number): DOMMatrix;
translateSelf(tx?: number, ty?: number, tz?: number): DOMMatrix;
scale(scaleX?: number, scaleY?: number, scaleZ?: number, originX?: number, originY?: number, originZ?: number): DOMMatrix;
scale3d(scale?: number, originX?: number, originY?: number, originZ?: number): DOMMatrix;
scale3dSelf(scale?: number, originX?: number, originY?: number, originZ?: number): DOMMatrix;
scaleSelf(scaleX?: number, scaleY?: number, scaleZ?: number, originX?: number, originY?: number, originZ?: number): DOMMatrix;
rotateFromVector(x?: number, y?: number): DOMMatrix;
rotateFromVectorSelf(x?: number, y?: number): DOMMatrix;
rotate(rotX?: number, rotY?: number, rotZ?: number): DOMMatrix;
rotateSelf(rotX?: number, rotY?: number, rotZ?: number): DOMMatrix;
rotateAxisAngle(x?: number, y?: number, z?: number, angle?: number): DOMMatrix;
rotateAxisAngleSelf(x?: number, y?: number, z?: number, angle?: number): DOMMatrix;
skewX(sx?: number): DOMMatrix;
skewXSelf(sx?: number): DOMMatrix;
skewY(sy?: number): DOMMatrix;
skewYSelf(sy?: number): DOMMatrix;
flipX(): DOMMatrix;
flipY(): DOMMatrix;
inverse(): DOMMatrix;
invertSelf(): DOMMatrix;
setMatrixValue(transformList: string): DOMMatrix;
transformPoint(point?: DOMPoint): DOMPoint;
toFloat32Array(): Float32Array;
toFloat64Array(): Float64Array;
readonly is2D: boolean;
readonly isIdentity: boolean;
a: number;
b: number;
c: number;
d: number;
e: number;
f: number;
m11: number;
m12: number;
m13: number;
m14: number;
m21: number;
m22: number;
m23: number;
m24: number;
m31: number;
m32: number;
m33: number;
m34: number;
m41: number;
m42: number;
m43: number;
m44: number;
static fromMatrix(other: DOMMatrix): DOMMatrix;
static fromFloat32Array(a: Float32Array): DOMMatrix;
static fromFloat64Array(a: Float64Array): DOMMatrix;
}
declare class NodeCanvasDOMPoint extends DOMPoint {}
export { NodeCanvasDOMPoint as DOMPoint }
export class ImageData {
constructor(sw: number, sh: number);
constructor(data: Uint8ClampedArray, sw: number, sh?: number);
readonly data: Uint8ClampedArray;
readonly height: number;
readonly width: number;
}
declare class NodeCanvasImageData extends ImageData {}
export { NodeCanvasImageData as ImageData }
// This is marked private, but is exported...
// export function parseFont(description: string): object