Lines Matching full:this

2   this._canvas = skcanvas;
3 this._paint = new CanvasKit.Paint();
4 this._paint.setAntiAlias(true);
6 this._paint.setStrokeMiter(10);
7 this._paint.setStrokeCap(CanvasKit.StrokeCap.Butt);
8 this._paint.setStrokeJoin(CanvasKit.StrokeJoin.Miter);
9 this._fontString = '10px monospace';
11 this._font = new CanvasKit.Font(null, 10);
12 this._font.setSubpixel(true);
14 this._strokeStyle = CanvasKit.BLACK;
15 this._fillStyle = CanvasKit.BLACK;
16 this._shadowBlur = 0;
17 this._shadowColor = CanvasKit.TRANSPARENT;
18 this._shadowOffsetX = 0;
19 this._shadowOffsetY = 0;
20 this._globalAlpha = 1;
21 this._strokeWidth = 1;
22 this._lineDashOffset = 0;
23 this._lineDashList = [];
25 this._globalCompositeOperation = CanvasKit.BlendMode.SrcOver;
27 this._paint.setStrokeWidth(this._strokeWidth);
28 this._paint.setBlendMode(this._globalCompositeOperation);
30 this._currentPath = new CanvasKit.Path();
31 this._currentTransform = CanvasKit.Matrix.identity();
33 // Use this for save/restore
34 this._canvasStateStack = [];
37 this._toCleanUp = [];
39 this._dispose = function() {
40 this._currentPath.delete();
41 this._paint.delete();
42 this._font.delete();
43 this._toCleanUp.forEach(function(c) {
46 // Don't delete this._canvas as it will be disposed
50 // This always accepts DOMMatrix/SVGMatrix or any other
53 Object.defineProperty(this, 'currentTransform', {
57 'a' : this._currentTransform[0],
58 'c' : this._currentTransform[1],
59 'e' : this._currentTransform[2],
60 'b' : this._currentTransform[3],
61 'd' : this._currentTransform[4],
62 'f' : this._currentTransform[5],
70 this.setTransform(matrix.a, matrix.b, matrix.c,
76 Object.defineProperty(this, 'fillStyle', {
79 if (isCanvasKitColor(this._fillStyle)) {
80 return colorToString(this._fillStyle);
82 return this._fillStyle;
86 this._fillStyle = parseColor(newStyle);
89 this._fillStyle = newStyle
94 Object.defineProperty(this, 'font', {
97 return this._fontString;
105 this._font.setSize(tf['sizePx']);
106 this._font.setTypeface(tf['typeface']);
107 this._fontString = newFont;
112 Object.defineProperty(this, 'globalAlpha', {
115 return this._globalAlpha;
122 this._globalAlpha = newAlpha;
126 Object.defineProperty(this, 'globalCompositeOperation', {
129 switch (this._globalCompositeOperation) {
194 this._globalCompositeOperation = CanvasKit.BlendMode.SrcOver;
197 this._globalCompositeOperation = CanvasKit.BlendMode.DstOver;
200 this._globalCompositeOperation = CanvasKit.BlendMode.Src;
203 this._globalCompositeOperation = CanvasKit.BlendMode.Dst;
206 this._globalCompositeOperation = CanvasKit.BlendMode.Clear;
209 this._globalCompositeOperation = CanvasKit.BlendMode.SrcIn;
212 this._globalCompositeOperation = CanvasKit.BlendMode.DstIn;
215 this._globalCompositeOperation = CanvasKit.BlendMode.SrcOut;
218 this._globalCompositeOperation = CanvasKit.BlendMode.DstOut;
221 this._globalCompositeOperation = CanvasKit.BlendMode.SrcATop;
224 this._globalCompositeOperation = CanvasKit.BlendMode.DstATop;
227 this._globalCompositeOperation = CanvasKit.BlendMode.Xor;
230 this._globalCompositeOperation = CanvasKit.BlendMode.Plus;
233 this._globalCompositeOperation = CanvasKit.BlendMode.Plus;
240 this._globalCompositeOperation = CanvasKit.BlendMode.Multiply;
243 this._globalCompositeOperation = CanvasKit.BlendMode.Screen;
246 this._globalCompositeOperation = CanvasKit.BlendMode.Overlay;
249 this._globalCompositeOperation = CanvasKit.BlendMode.Darken;
252 this._globalCompositeOperation = CanvasKit.BlendMode.Lighten;
255 this._globalCompositeOperation = CanvasKit.BlendMode.ColorDodge;
258 this._globalCompositeOperation = CanvasKit.BlendMode.ColorBurn;
261 this._globalCompositeOperation = CanvasKit.BlendMode.HardLight;
264 this._globalCompositeOperation = CanvasKit.BlendMode.SoftLight;
267 this._globalCompositeOperation = CanvasKit.BlendMode.Difference;
270 this._globalCompositeOperation = CanvasKit.BlendMode.Exclusion;
273 this._globalCompositeOperation = CanvasKit.BlendMode.Hue;
276 this._globalCompositeOperation = CanvasKit.BlendMode.Saturation;
279 this._globalCompositeOperation = CanvasKit.BlendMode.Color;
282 this._globalCompositeOperation = CanvasKit.BlendMode.Luminosity;
287 this._paint.setBlendMode(this._globalCompositeOperation);
291 Object.defineProperty(this, 'imageSmoothingEnabled', {
301 Object.defineProperty(this, 'imageSmoothingQuality', {
311 Object.defineProperty(this, 'lineCap', {
314 switch (this._paint.getStrokeCap()) {
326 this._paint.setStrokeCap(CanvasKit.StrokeCap.Butt);
329 this._paint.setStrokeCap(CanvasKit.StrokeCap.Round);
332 this._paint.setStrokeCap(CanvasKit.StrokeCap.Square);
338 Object.defineProperty(this, 'lineDashOffset', {
341 return this._lineDashOffset;
347 this._lineDashOffset = newOffset;
351 Object.defineProperty(this, 'lineJoin', {
354 switch (this._paint.getStrokeJoin()) {
366 this._paint.setStrokeJoin(CanvasKit.StrokeJoin.Miter);
369 this._paint.setStrokeJoin(CanvasKit.StrokeJoin.Round);
372 this._paint.setStrokeJoin(CanvasKit.StrokeJoin.Bevel);
378 Object.defineProperty(this, 'lineWidth', {
381 return this._paint.getStrokeWidth();
388 this._strokeWidth = newWidth;
389 this._paint.setStrokeWidth(newWidth);
393 Object.defineProperty(this, 'miterLimit', {
396 return this._paint.getStrokeMiter();
403 this._paint.setStrokeMiter(newLimit);
407 Object.defineProperty(this, 'shadowBlur', {
410 return this._shadowBlur;
417 this._shadowBlur = newBlur;
421 Object.defineProperty(this, 'shadowColor', {
424 return colorToString(this._shadowColor);
427 this._shadowColor = parseColor(newColor);
431 Object.defineProperty(this, 'shadowOffsetX', {
434 return this._shadowOffsetX;
440 this._shadowOffsetX = newOffset;
444 Object.defineProperty(this, 'shadowOffsetY', {
447 return this._shadowOffsetY;
453 this._shadowOffsetY = newOffset;
457 Object.defineProperty(this, 'strokeStyle', {
460 return colorToString(this._strokeStyle);
464 this._strokeStyle = parseColor(newStyle);
467 this._strokeStyle = newStyle
472 this.arc = function(x, y, radius, startAngle, endAngle, ccw) {
473 arc(this._currentPath, x, y, radius, startAngle, endAngle, ccw);
476 this.arcTo = function(x1, y1, x2, y2, radius) {
477 arcTo(this._currentPath, x1, y1, x2, y2, radius);
480 // As per the spec this doesn't begin any paths, it only
482 this.beginPath = function() {
483 this._currentPath.delete();
484 this._currentPath = new CanvasKit.Path();
487 this.bezierCurveTo = function(cp1x, cp1y, cp2x, cp2y, x, y) {
488 bezierCurveTo(this._currentPath, cp1x, cp1y, cp2x, cp2y, x, y);
491 this.clearRect = function(x, y, width, height) {
492 this._paint.setStyle(CanvasKit.PaintStyle.Fill);
493 this._paint.setBlendMode(CanvasKit.BlendMode.Clear);
494 this._canvas.drawRect(CanvasKit.XYWHRect(x, y, width, height), this._paint);
495 this._paint.setBlendMode(this._globalCompositeOperation);
498 this.clip = function(path, fillRule) {
502 path = this._currentPath;
507 path = this._currentPath;
516 this._canvas.clipPath(clip, CanvasKit.ClipOp.Intersect, true);
520 this.closePath = function() {
521 closePath(this._currentPath);
524 this.createImageData = function() {
544 this.createLinearGradient = function(x1, y1, x2, y2) {
549 this._toCleanUp.push(lcg);
553 this.createPattern = function(image, repetition) {
555 this._toCleanUp.push(cp);
559 this.createRadialGradient = function(x1, y1, r1, x2, y2, r2) {
564 this._toCleanUp.push(rcg);
568 this.drawImage = function(img) {
575 var iPaint = this._fillPaint();
588 this._canvas.drawImageRect(img, srcRect, destRect, iPaint, false);
593 this.ellipse = function(x, y, radiusX, radiusY, rotation,
595 ellipse(this._currentPath, x, y, radiusX, radiusY, rotation,
600 // This applies the global alpha.
602 this._fillPaint = function() {
603 var paint = this._paint.copy();
605 if (isCanvasKitColor(this._fillStyle)) {
606 var alphaColor = CanvasKit.multiplyByAlpha(this._fillStyle, this._globalAlpha);
609 var shader = this._fillStyle._getShader(this._currentTransform);
610 paint.setColor(CanvasKit.Color(0,0,0, this._globalAlpha));
618 this.delete();
623 this.fill = function(path, fillRule) {
627 path = this._currentPath;
632 this._currentPath.setFillType(CanvasKit.FillType.EvenOdd);
634 this._currentPath.setFillType(CanvasKit.FillType.Winding);
639 path = this._currentPath;
642 var fillPaint = this._fillPaint();
644 var shadowPaint = this._shadowPaint(fillPaint);
646 this._canvas.save();
647 this._applyShadowOffsetMatrix();
648 this._canvas.drawPath(path, shadowPaint);
649 this._canvas.restore();
652 this._canvas.drawPath(path, fillPaint);
656 this.fillRect = function(x, y, width, height) {
657 var fillPaint = this._fillPaint();
659 var shadowPaint = this._shadowPaint(fillPaint);
661 this._canvas.save();
662 this._applyShadowOffsetMatrix();
663 this._canvas.drawRect(CanvasKit.XYWHRect(x, y, width, height), shadowPaint);
664 this._canvas.restore();
668 this._canvas.drawRect(CanvasKit.XYWHRect(x, y, width, height), fillPaint);
672 this.fillText = function(text, x, y, maxWidth) {
674 var fillPaint = this._fillPaint();
675 var blob = CanvasKit.TextBlob.MakeFromText(text, this._font);
677 var shadowPaint = this._shadowPaint(fillPaint);
679 this._canvas.save();
680 this._applyShadowOffsetMatrix();
681 this._canvas.drawTextBlob(blob, x, y, shadowPaint);
682 this._canvas.restore();
685 this._canvas.drawTextBlob(blob, x, y, fillPaint);
690 this.getImageData = function(x, y, w, h) {
691 var pixels = this._canvas.readPixels(x, y, {
701 // This essentially re-wraps the pixels from a Uint8Array to
708 this.getLineDash = function() {
709 return this._lineDashList.slice();
712 this._mapToLocalCoordinates = function(pts) {
713 var inverted = CanvasKit.Matrix.invert(this._currentTransform);
718 this.isPointInPath = function(x, y, fillmode) {
721 var path = this._currentPath;
738 var pts = this._mapToLocalCoordinates([x, y]);
747 this.isPointInStroke = function(x, y) {
750 var path = this._currentPath;
761 var pts = this._mapToLocalCoordinates([x, y]);
767 temp.stroke({'width': this.lineWidth, 'miter_limit': this.miterLimit,
768 'cap': this._paint.getStrokeCap(), 'join': this._paint.getStrokeJoin(),
769 'precision': 0.3, // this is what Chrome uses to compute this
776 this.lineTo = function(x, y) {
777 lineTo(this._currentPath, x, y);
780 this.measureText = function(text) {
784 this.moveTo = function(x, y) {
785 moveTo(this._currentPath, x, y);
788 this.putImageData = function(imageData, x, y, dirtyX, dirtyY, dirtyWidth, dirtyHeight) {
794 this._canvas.writePixels(imageData.data, imageData.width, imageData.height, x, y);
831 var inverted = CanvasKit.Matrix.invert(this._currentTransform);
832 this._canvas.save();
834 this._canvas.concat(inverted);
835 this._canvas.drawImageRect(img, src, dst, null, false);
836 this._canvas.restore();
840 this.quadraticCurveTo = function(cpx, cpy, x, y) {
841 quadraticCurveTo(this._currentPath, cpx, cpy, x, y);
844 this.rect = function(x, y, width, height) {
845 rect(this._currentPath, x, y, width, height);
848 this.resetTransform = function() {
851 this._currentPath.transform(this._currentTransform);
852 var inverted = CanvasKit.Matrix.invert(this._currentTransform);
853 this._canvas.concat(inverted);
854 // This should be identity, modulo floating point drift.
855 this._currentTransform = this._canvas.getTotalMatrix();
858 this.restore = function() {
859 var newState = this._canvasStateStack.pop();
867 this._currentTransform,
870 this._currentPath.transform(combined);
871 this._paint.delete();
872 this._paint = newState.paint;
874 this._lineDashList = newState.ldl;
875 this._strokeWidth = newState.sw;
876 this._strokeStyle = newState.ss;
877 this._fillStyle = newState.fs;
878 this._shadowOffsetX = newState.sox;
879 this._shadowOffsetY = newState.soy;
880 this._shadowBlur = newState.sb;
881 this._shadowColor = newState.shc;
882 this._globalAlpha = newState.ga;
883 this._globalCompositeOperation = newState.gco;
884 this._lineDashOffset = newState.ldo;
885 this._fontString = newState.fontstr;
890 this._canvas.restore();
891 this._currentTransform = this._canvas.getTotalMatrix();
894 this.rotate = function(radians) {
898 // retroactively apply the inverse of this transform to the previous
901 this._currentPath.transform(inverted);
902 this._canvas.rotate(radiansToDegrees(radians), 0, 0);
903 this._currentTransform = this._canvas.getTotalMatrix();
906 this.save = function() {
907 if (this._fillStyle._copy) {
908 var fs = this._fillStyle._copy();
909 this._toCleanUp.push(fs);
911 var fs = this._fillStyle;
914 if (this._strokeStyle._copy) {
915 var ss = this._strokeStyle._copy();
916 this._toCleanUp.push(ss);
918 var ss = this._strokeStyle;
921 this._canvasStateStack.push({
922 ctm: this._currentTransform.slice(),
923 ldl: this._lineDashList.slice(),
924 sw: this._strokeWidth,
927 sox: this._shadowOffsetX,
928 soy: this._shadowOffsetY,
929 sb: this._shadowBlur,
930 shc: this._shadowColor,
931 ga: this._globalAlpha,
932 ldo: this._lineDashOffset,
933 gco: this._globalCompositeOperation,
934 paint: this._paint.copy(),
935 fontstr: this._fontString,
939 this._canvas.save();
942 this.scale = function(sx, sy) {
946 // retroactively apply the inverse of this transform to the previous
949 this._currentPath.transform(inverted);
950 this._canvas.scale(sx, sy);
951 this._currentTransform = this._canvas.getTotalMatrix();
954 this.setLineDash = function(dashes) {
966 this._lineDashList = dashes;
969 this.setTransform = function(a, b, c, d, e, f) {
973 this.resetTransform();
974 this.transform(a, b, c, d, e, f);
979 this._applyShadowOffsetMatrix = function() {
980 var inverted = CanvasKit.Matrix.invert(this._currentTransform);
981 this._canvas.concat(inverted);
982 this._canvas.concat(CanvasKit.Matrix.translated(this._shadowOffsetX, this._shadowOffsetY));
983 this._canvas.concat(this._currentTransform);
987 // should be no shadow. This ends up being a copy of the given
989 this._shadowPaint = function(basePaint) {
991 var alphaColor = CanvasKit.multiplyByAlpha(this._shadowColor, this._globalAlpha);
998 if (!(this._shadowBlur || this._shadowOffsetY || this._shadowOffsetX)) {
1004 BlurRadiusToSigma(this._shadowBlur),
1012 this.delete();
1018 // This applies the global alpha and the dashedness.
1020 this._strokePaint = function() {
1021 var paint = this._paint.copy();
1023 if (isCanvasKitColor(this._strokeStyle)) {
1024 var alphaColor = CanvasKit.multiplyByAlpha(this._strokeStyle, this._globalAlpha);
1027 var shader = this._strokeStyle._getShader(this._currentTransform);
1028 paint.setColor(CanvasKit.Color(0,0,0, this._globalAlpha));
1032 paint.setStrokeWidth(this._strokeWidth);
1034 if (this._lineDashList.length) {
1035 var dashedEffect = CanvasKit.PathEffect.MakeDash(this._lineDashList, this._lineDashOffset);
1041 this.delete();
1046 this.stroke = function(path) {
1047 path = path ? path._getPath() : this._currentPath;
1048 var strokePaint = this._strokePaint();
1050 var shadowPaint = this._shadowPaint(strokePaint);
1052 this._canvas.save();
1053 this._applyShadowOffsetMatrix();
1054 this._canvas.drawPath(path, shadowPaint);
1055 this._canvas.restore();
1059 this._canvas.drawPath(path, strokePaint);
1063 this.strokeRect = function(x, y, width, height) {
1064 var strokePaint = this._strokePaint();
1066 var shadowPaint = this._shadowPaint(strokePaint);
1068 this._canvas.save();
1069 this._applyShadowOffsetMatrix();
1070 this._canvas.drawRect(CanvasKit.XYWHRect(x, y, width, height), shadowPaint);
1071 this._canvas.restore();
1074 this._canvas.drawRect(CanvasKit.XYWHRect(x, y, width, height), strokePaint);
1078 this.strokeText = function(text, x, y, maxWidth) {
1080 var strokePaint = this._strokePaint();
1081 var blob = CanvasKit.TextBlob.MakeFromText(text, this._font);
1083 var shadowPaint = this._shadowPaint(strokePaint);
1085 this._canvas.save();
1086 this._applyShadowOffsetMatrix();
1087 this._canvas.drawTextBlob(blob, x, y, shadowPaint);
1088 this._canvas.restore();
1091 this._canvas.drawTextBlob(blob, x, y, strokePaint);
1096 this.translate = function(dx, dy) {
1100 // retroactively apply the inverse of this transform to the previous
1103 this._currentPath.transform(inverted);
1104 this._canvas.translate(dx, dy);
1105 this._currentTransform = this._canvas.getTotalMatrix();
1108 this.transform = function(a, b, c, d, e, f) {
1112 // retroactively apply the inverse of this transform to the previous
1115 this._currentPath.transform(inverted);
1116 this._canvas.concat(newTransform);
1117 this._currentTransform = this._canvas.getTotalMatrix();
1121 this.addHitRegion = function() {};
1122 this.clearHitRegions = function() {};
1123 this.drawFocusIfNeeded = function() {};
1124 this.removeHitRegion = function() {};
1125 this.scrollPathIntoView = function() {};
1127 Object.defineProperty(this, 'canvas', {
1136 // This may change in future releases.
1137 // This code is staying here in case any clients are interested in using it
1143 // This is what the spec says, which is how Firefox and others operate.