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) {
578 var iPaint = this._fillPaint();
591 this._canvas.drawImageRect(img, srcRect, destRect, iPaint, false);
596 this.ellipse = function(x, y, radiusX, radiusY, rotation,
598 ellipse(this._currentPath, x, y, radiusX, radiusY, rotation,
603 // This applies the global alpha.
605 this._fillPaint = function() {
606 var paint = this._paint.copy();
608 if (isCanvasKitColor(this._fillStyle)) {
609 var alphaColor = CanvasKit.multiplyByAlpha(this._fillStyle, this._globalAlpha);
612 var shader = this._fillStyle._getShader(this._currentTransform);
613 paint.setColor(CanvasKit.Color(0,0,0, this._globalAlpha));
621 this.delete();
626 this.fill = function(path, fillRule) {
630 path = this._currentPath;
635 this._currentPath.setFillType(CanvasKit.FillType.EvenOdd);
637 this._currentPath.setFillType(CanvasKit.FillType.Winding);
642 path = this._currentPath;
645 var fillPaint = this._fillPaint();
647 var shadowPaint = this._shadowPaint(fillPaint);
649 this._canvas.save();
650 this._applyShadowOffsetMatrix();
651 this._canvas.drawPath(path, shadowPaint);
652 this._canvas.restore();
655 this._canvas.drawPath(path, fillPaint);
659 this.fillRect = function(x, y, width, height) {
660 var fillPaint = this._fillPaint();
662 var shadowPaint = this._shadowPaint(fillPaint);
664 this._canvas.save();
665 this._applyShadowOffsetMatrix();
666 this._canvas.drawRect(CanvasKit.XYWHRect(x, y, width, height), shadowPaint);
667 this._canvas.restore();
671 this._canvas.drawRect(CanvasKit.XYWHRect(x, y, width, height), fillPaint);
675 this.fillText = function(text, x, y, maxWidth) {
677 var fillPaint = this._fillPaint();
678 var blob = CanvasKit.TextBlob.MakeFromText(text, this._font);
680 var shadowPaint = this._shadowPaint(fillPaint);
682 this._canvas.save();
683 this._applyShadowOffsetMatrix();
684 this._canvas.drawTextBlob(blob, x, y, shadowPaint);
685 this._canvas.restore();
688 this._canvas.drawTextBlob(blob, x, y, fillPaint);
693 this.getImageData = function(x, y, w, h) {
694 var pixels = this._canvas.readPixels(x, y, {
704 // This essentially re-wraps the pixels from a Uint8Array to
711 this.getLineDash = function() {
712 return this._lineDashList.slice();
715 this._mapToLocalCoordinates = function(pts) {
716 var inverted = CanvasKit.Matrix.invert(this._currentTransform);
721 this.isPointInPath = function(x, y, fillmode) {
724 var path = this._currentPath;
741 var pts = this._mapToLocalCoordinates([x, y]);
750 this.isPointInStroke = function(x, y) {
753 var path = this._currentPath;
764 var pts = this._mapToLocalCoordinates([x, y]);
770 temp.stroke({'width': this.lineWidth, 'miter_limit': this.miterLimit,
771 'cap': this._paint.getStrokeCap(), 'join': this._paint.getStrokeJoin(),
772 'precision': 0.3, // this is what Chrome uses to compute this
779 this.lineTo = function(x, y) {
780 lineTo(this._currentPath, x, y);
783 this.measureText = function(text) {
784 const ids = this._font.getGlyphIDs(text);
785 const widths = this._font.getGlyphWidths(ids);
795 this.moveTo = function(x, y) {
796 moveTo(this._currentPath, x, y);
799 this.putImageData = function(imageData, x, y, dirtyX, dirtyY, dirtyWidth, dirtyHeight) {
805 this._canvas.writePixels(imageData.data, imageData.width, imageData.height, x, y);
842 var inverted = CanvasKit.Matrix.invert(this._currentTransform);
843 this._canvas.save();
845 this._canvas.concat(inverted);
846 this._canvas.drawImageRect(img, src, dst, null, false);
847 this._canvas.restore();
851 this.quadraticCurveTo = function(cpx, cpy, x, y) {
852 quadraticCurveTo(this._currentPath, cpx, cpy, x, y);
855 this.rect = function(x, y, width, height) {
856 rect(this._currentPath, x, y, width, height);
859 this.resetTransform = function() {
862 this._currentPath.transform(this._currentTransform);
863 var inverted = CanvasKit.Matrix.invert(this._currentTransform);
864 this._canvas.concat(inverted);
865 // This should be identity, modulo floating point drift.
866 this._currentTransform = this._canvas.getTotalMatrix();
869 this.restore = function() {
870 var newState = this._canvasStateStack.pop();
878 this._currentTransform,
881 this._currentPath.transform(combined);
882 this._paint.delete();
883 this._paint = newState.paint;
885 this._lineDashList = newState.ldl;
886 this._strokeWidth = newState.sw;
887 this._strokeStyle = newState.ss;
888 this._fillStyle = newState.fs;
889 this._shadowOffsetX = newState.sox;
890 this._shadowOffsetY = newState.soy;
891 this._shadowBlur = newState.sb;
892 this._shadowColor = newState.shc;
893 this._globalAlpha = newState.ga;
894 this._globalCompositeOperation = newState.gco;
895 this._lineDashOffset = newState.ldo;
896 this._fontString = newState.fontstr;
901 this._canvas.restore();
902 this._currentTransform = this._canvas.getTotalMatrix();
905 this.rotate = function(radians) {
909 // retroactively apply the inverse of this transform to the previous
912 this._currentPath.transform(inverted);
913 this._canvas.rotate(radiansToDegrees(radians), 0, 0);
914 this._currentTransform = this._canvas.getTotalMatrix();
917 this.save = function() {
918 if (this._fillStyle._copy) {
919 var fs = this._fillStyle._copy();
920 this._toCleanUp.push(fs);
922 var fs = this._fillStyle;
925 if (this._strokeStyle._copy) {
926 var ss = this._strokeStyle._copy();
927 this._toCleanUp.push(ss);
929 var ss = this._strokeStyle;
932 this._canvasStateStack.push({
933 ctm: this._currentTransform.slice(),
934 ldl: this._lineDashList.slice(),
935 sw: this._strokeWidth,
938 sox: this._shadowOffsetX,
939 soy: this._shadowOffsetY,
940 sb: this._shadowBlur,
941 shc: this._shadowColor,
942 ga: this._globalAlpha,
943 ldo: this._lineDashOffset,
944 gco: this._globalCompositeOperation,
945 paint: this._paint.copy(),
946 fontstr: this._fontString,
950 this._canvas.save();
953 this.scale = function(sx, sy) {
957 // retroactively apply the inverse of this transform to the previous
960 this._currentPath.transform(inverted);
961 this._canvas.scale(sx, sy);
962 this._currentTransform = this._canvas.getTotalMatrix();
965 this.setLineDash = function(dashes) {
977 this._lineDashList = dashes;
980 this.setTransform = function(a, b, c, d, e, f) {
984 this.resetTransform();
985 this.transform(a, b, c, d, e, f);
990 this._applyShadowOffsetMatrix = function() {
991 var inverted = CanvasKit.Matrix.invert(this._currentTransform);
992 this._canvas.concat(inverted);
993 this._canvas.concat(CanvasKit.Matrix.translated(this._shadowOffsetX, this._shadowOffsetY));
994 this._canvas.concat(this._currentTransform);
998 // should be no shadow. This ends up being a copy of the given
1000 this._shadowPaint = function(basePaint) {
1002 var alphaColor = CanvasKit.multiplyByAlpha(this._shadowColor, this._globalAlpha);
1009 if (!(this._shadowBlur || this._shadowOffsetY || this._shadowOffsetX)) {
1015 BlurRadiusToSigma(this._shadowBlur),
1023 this.delete();
1029 // This applies the global alpha and the dashedness.
1031 this._strokePaint = function() {
1032 var paint = this._paint.copy();
1034 if (isCanvasKitColor(this._strokeStyle)) {
1035 var alphaColor = CanvasKit.multiplyByAlpha(this._strokeStyle, this._globalAlpha);
1038 var shader = this._strokeStyle._getShader(this._currentTransform);
1039 paint.setColor(CanvasKit.Color(0,0,0, this._globalAlpha));
1043 paint.setStrokeWidth(this._strokeWidth);
1045 if (this._lineDashList.length) {
1046 var dashedEffect = CanvasKit.PathEffect.MakeDash(this._lineDashList, this._lineDashOffset);
1052 this.delete();
1057 this.stroke = function(path) {
1058 path = path ? path._getPath() : this._currentPath;
1059 var strokePaint = this._strokePaint();
1061 var shadowPaint = this._shadowPaint(strokePaint);
1063 this._canvas.save();
1064 this._applyShadowOffsetMatrix();
1065 this._canvas.drawPath(path, shadowPaint);
1066 this._canvas.restore();
1070 this._canvas.drawPath(path, strokePaint);
1074 this.strokeRect = function(x, y, width, height) {
1075 var strokePaint = this._strokePaint();
1077 var shadowPaint = this._shadowPaint(strokePaint);
1079 this._canvas.save();
1080 this._applyShadowOffsetMatrix();
1081 this._canvas.drawRect(CanvasKit.XYWHRect(x, y, width, height), shadowPaint);
1082 this._canvas.restore();
1085 this._canvas.drawRect(CanvasKit.XYWHRect(x, y, width, height), strokePaint);
1089 this.strokeText = function(text, x, y, maxWidth) {
1091 var strokePaint = this._strokePaint();
1092 var blob = CanvasKit.TextBlob.MakeFromText(text, this._font);
1094 var shadowPaint = this._shadowPaint(strokePaint);
1096 this._canvas.save();
1097 this._applyShadowOffsetMatrix();
1098 this._canvas.drawTextBlob(blob, x, y, shadowPaint);
1099 this._canvas.restore();
1102 this._canvas.drawTextBlob(blob, x, y, strokePaint);
1107 this.translate = function(dx, dy) {
1111 // retroactively apply the inverse of this transform to the previous
1114 this._currentPath.transform(inverted);
1115 this._canvas.translate(dx, dy);
1116 this._currentTransform = this._canvas.getTotalMatrix();
1119 this.transform = function(a, b, c, d, e, f) {
1123 // retroactively apply the inverse of this transform to the previous
1126 this._currentPath.transform(inverted);
1127 this._canvas.concat(newTransform);
1128 this._currentTransform = this._canvas.getTotalMatrix();
1132 this.addHitRegion = function() {};
1133 this.clearHitRegions = function() {};
1134 this.drawFocusIfNeeded = function() {};
1135 this.removeHitRegion = function() {};
1136 this.scrollPathIntoView = function() {};
1138 Object.defineProperty(this, 'canvas', {
1147 // This may change in future releases.
1148 // This code is staying here in case any clients are interested in using it
1154 // This is what the spec says, which is how Firefox and others operate.