Lines Matching full:this
2 this._canvas = skcanvas;
3 this._paint = new CanvasKit.SkPaint();
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.SkFont(null, 10);
13 this._strokeStyle = CanvasKit.BLACK;
14 this._fillStyle = CanvasKit.BLACK;
15 this._shadowBlur = 0;
16 this._shadowColor = CanvasKit.TRANSPARENT;
17 this._shadowOffsetX = 0;
18 this._shadowOffsetY = 0;
19 this._globalAlpha = 1;
20 this._strokeWidth = 1;
21 this._lineDashOffset = 0;
22 this._lineDashList = [];
24 this._globalCompositeOperation = CanvasKit.BlendMode.SrcOver;
25 this._imageFilterQuality = CanvasKit.FilterQuality.Low;
26 this._imageSmoothingEnabled = true;
29 this._paint.setStrokeWidth(this._strokeWidth);
30 this._paint.setBlendMode(this._globalCompositeOperation);
32 this._currentPath = new CanvasKit.SkPath();
33 this._currentTransform = CanvasKit.SkMatrix.identity();
35 // Use this for save/restore
36 this._canvasStateStack = [];
39 this._toCleanUp = [];
41 this._dispose = function() {
42 this._currentPath.delete();
43 this._paint.delete();
44 this._font.delete();
45 this._toCleanUp.forEach(function(c) {
48 // Don't delete this._canvas as it will be disposed
52 // This always accepts DOMMatrix/SVGMatrix or any other
55 Object.defineProperty(this, 'currentTransform', {
59 'a' : this._currentTransform[0],
60 'c' : this._currentTransform[1],
61 'e' : this._currentTransform[2],
62 'b' : this._currentTransform[3],
63 'd' : this._currentTransform[4],
64 'f' : this._currentTransform[5],
72 this.setTransform(matrix.a, matrix.b, matrix.c,
78 Object.defineProperty(this, 'fillStyle', {
81 if (Number.isInteger(this._fillStyle)) {
82 return colorToString(this._fillStyle);
84 return this._fillStyle;
88 this._fillStyle = parseColor(newStyle);
91 this._fillStyle = newStyle
96 Object.defineProperty(this, 'font', {
99 return this._fontString;
107 this._font.setSize(tf['sizePx']);
108 this._font.setTypeface(tf['typeface']);
109 this._fontString = newFont;
114 Object.defineProperty(this, 'globalAlpha', {
117 return this._globalAlpha;
124 this._globalAlpha = newAlpha;
128 Object.defineProperty(this, 'globalCompositeOperation', {
131 switch (this._globalCompositeOperation) {
196 this._globalCompositeOperation = CanvasKit.BlendMode.SrcOver;
199 this._globalCompositeOperation = CanvasKit.BlendMode.DstOver;
202 this._globalCompositeOperation = CanvasKit.BlendMode.Src;
205 this._globalCompositeOperation = CanvasKit.BlendMode.Dst;
208 this._globalCompositeOperation = CanvasKit.BlendMode.Clear;
211 this._globalCompositeOperation = CanvasKit.BlendMode.SrcIn;
214 this._globalCompositeOperation = CanvasKit.BlendMode.DstIn;
217 this._globalCompositeOperation = CanvasKit.BlendMode.SrcOut;
220 this._globalCompositeOperation = CanvasKit.BlendMode.DstOut;
223 this._globalCompositeOperation = CanvasKit.BlendMode.SrcATop;
226 this._globalCompositeOperation = CanvasKit.BlendMode.DstATop;
229 this._globalCompositeOperation = CanvasKit.BlendMode.Xor;
232 this._globalCompositeOperation = CanvasKit.BlendMode.Plus;
235 this._globalCompositeOperation = CanvasKit.BlendMode.Plus;
242 this._globalCompositeOperation = CanvasKit.BlendMode.Multiply;
245 this._globalCompositeOperation = CanvasKit.BlendMode.Screen;
248 this._globalCompositeOperation = CanvasKit.BlendMode.Overlay;
251 this._globalCompositeOperation = CanvasKit.BlendMode.Darken;
254 this._globalCompositeOperation = CanvasKit.BlendMode.Lighten;
257 this._globalCompositeOperation = CanvasKit.BlendMode.ColorDodge;
260 this._globalCompositeOperation = CanvasKit.BlendMode.ColorBurn;
263 this._globalCompositeOperation = CanvasKit.BlendMode.HardLight;
266 this._globalCompositeOperation = CanvasKit.BlendMode.SoftLight;
269 this._globalCompositeOperation = CanvasKit.BlendMode.Difference;
272 this._globalCompositeOperation = CanvasKit.BlendMode.Exclusion;
275 this._globalCompositeOperation = CanvasKit.BlendMode.Hue;
278 this._globalCompositeOperation = CanvasKit.BlendMode.Saturation;
281 this._globalCompositeOperation = CanvasKit.BlendMode.Color;
284 this._globalCompositeOperation = CanvasKit.BlendMode.Luminosity;
289 this._paint.setBlendMode(this._globalCompositeOperation);
293 Object.defineProperty(this, 'imageSmoothingEnabled', {
296 return this._imageSmoothingEnabled;
299 this._imageSmoothingEnabled = !!newVal;
303 Object.defineProperty(this, 'imageSmoothingQuality', {
306 switch (this._imageFilterQuality) {
318 this._imageFilterQuality = CanvasKit.FilterQuality.Low;
321 this._imageFilterQuality = CanvasKit.FilterQuality.Medium;
324 this._imageFilterQuality = CanvasKit.FilterQuality.High;
330 Object.defineProperty(this, 'lineCap', {
333 switch (this._paint.getStrokeCap()) {
345 this._paint.setStrokeCap(CanvasKit.StrokeCap.Butt);
348 this._paint.setStrokeCap(CanvasKit.StrokeCap.Round);
351 this._paint.setStrokeCap(CanvasKit.StrokeCap.Square);
357 Object.defineProperty(this, 'lineDashOffset', {
360 return this._lineDashOffset;
366 this._lineDashOffset = newOffset;
370 Object.defineProperty(this, 'lineJoin', {
373 switch (this._paint.getStrokeJoin()) {
385 this._paint.setStrokeJoin(CanvasKit.StrokeJoin.Miter);
388 this._paint.setStrokeJoin(CanvasKit.StrokeJoin.Round);
391 this._paint.setStrokeJoin(CanvasKit.StrokeJoin.Bevel);
397 Object.defineProperty(this, 'lineWidth', {
400 return this._paint.getStrokeWidth();
407 this._strokeWidth = newWidth;
408 this._paint.setStrokeWidth(newWidth);
412 Object.defineProperty(this, 'miterLimit', {
415 return this._paint.getStrokeMiter();
422 this._paint.setStrokeMiter(newLimit);
426 Object.defineProperty(this, 'shadowBlur', {
429 return this._shadowBlur;
436 this._shadowBlur = newBlur;
440 Object.defineProperty(this, 'shadowColor', {
443 return colorToString(this._shadowColor);
446 this._shadowColor = parseColor(newColor);
450 Object.defineProperty(this, 'shadowOffsetX', {
453 return this._shadowOffsetX;
459 this._shadowOffsetX = newOffset;
463 Object.defineProperty(this, 'shadowOffsetY', {
466 return this._shadowOffsetY;
472 this._shadowOffsetY = newOffset;
476 Object.defineProperty(this, 'strokeStyle', {
479 return colorToString(this._strokeStyle);
483 this._strokeStyle = parseColor(newStyle);
486 this._strokeStyle = newStyle
491 this.arc = function(x, y, radius, startAngle, endAngle, ccw) {
492 arc(this._currentPath, x, y, radius, startAngle, endAngle, ccw);
495 this.arcTo = function(x1, y1, x2, y2, radius) {
496 arcTo(this._currentPath, x1, y1, x2, y2, radius);
499 // As per the spec this doesn't begin any paths, it only
501 this.beginPath = function() {
502 this._currentPath.delete();
503 this._currentPath = new CanvasKit.SkPath();
506 this.bezierCurveTo = function(cp1x, cp1y, cp2x, cp2y, x, y) {
507 bezierCurveTo(this._currentPath, cp1x, cp1y, cp2x, cp2y, x, y);
510 this.clearRect = function(x, y, width, height) {
511 this._paint.setStyle(CanvasKit.PaintStyle.Fill);
512 this._paint.setBlendMode(CanvasKit.BlendMode.Clear);
513 this._canvas.drawRect(CanvasKit.XYWHRect(x, y, width, height), this._paint);
514 this._paint.setBlendMode(this._globalCompositeOperation);
517 this.clip = function(path, fillRule) {
521 path = this._currentPath;
526 path = this._currentPath;
535 this._canvas.clipPath(clip, CanvasKit.ClipOp.Intersect, true);
539 this.closePath = function() {
540 closePath(this._currentPath);
543 this.createImageData = function() {
563 this.createLinearGradient = function(x1, y1, x2, y2) {
568 this._toCleanUp.push(lcg);
572 this.createPattern = function(image, repetition) {
574 this._toCleanUp.push(cp);
578 this.createRadialGradient = function(x1, y1, r1, x2, y2, r2) {
583 this._toCleanUp.push(rcg);
587 this._imagePaint = function() {
588 var iPaint = this._fillPaint();
589 if (!this._imageSmoothingEnabled) {
592 iPaint.setFilterQuality(this._imageFilterQuality);
597 this.drawImage = function(img) {
604 var iPaint = this._imagePaint();
617 this._canvas.drawImageRect(img, srcRect, destRect, iPaint, false);
622 this.ellipse = function(x, y, radiusX, radiusY, rotation,
624 ellipse(this._currentPath, x, y, radiusX, radiusY, rotation,
629 // This applies the global alpha.
631 this._fillPaint = function() {
632 var paint = this._paint.copy();
634 if (Number.isInteger(this._fillStyle)) {
635 var alphaColor = CanvasKit.multiplyByAlpha(this._fillStyle, this._globalAlpha);
638 var shader = this._fillStyle._getShader(this._currentTransform);
639 paint.setColor(CanvasKit.Color(0,0,0, this._globalAlpha));
647 this.delete();
652 this.fill = function(path, fillRule) {
656 path = this._currentPath;
661 this._currentPath.setFillType(CanvasKit.FillType.EvenOdd);
663 this._currentPath.setFillType(CanvasKit.FillType.Winding);
668 path = this._currentPath;
671 var fillPaint = this._fillPaint();
673 var shadowPaint = this._shadowPaint(fillPaint);
675 this._canvas.save();
676 this._canvas.concat(this._shadowOffsetMatrix());
677 this._canvas.drawPath(path, shadowPaint);
678 this._canvas.restore();
681 this._canvas.drawPath(path, fillPaint);
685 this.fillRect = function(x, y, width, height) {
686 var fillPaint = this._fillPaint();
687 this._canvas.drawRect(CanvasKit.XYWHRect(x, y, width, height), fillPaint);
691 this.fillText = function(text, x, y, maxWidth) {
693 var fillPaint = this._fillPaint();
694 var blob = CanvasKit.SkTextBlob.MakeFromText(text, this._font);
696 var shadowPaint = this._shadowPaint(fillPaint);
698 this._canvas.save();
699 this._canvas.concat(this._shadowOffsetMatrix());
700 this._canvas.drawTextBlob(blob, x, y, shadowPaint);
701 this._canvas.restore();
704 this._canvas.drawTextBlob(blob, x, y, fillPaint);
709 this.getImageData = function(x, y, w, h) {
710 var pixels = this._canvas.readPixels(x, y, w, h);
714 // This essentially re-wraps the pixels from a Uint8Array to
721 this.getLineDash = function() {
722 return this._lineDashList.slice();
725 this._mapToLocalCoordinates = function(pts) {
726 var inverted = CanvasKit.SkMatrix.invert(this._currentTransform);
731 this.isPointInPath = function(x, y, fillmode) {
734 var path = this._currentPath;
751 var pts = this._mapToLocalCoordinates([x, y]);
760 this.isPointInStroke = function(x, y) {
763 var path = this._currentPath;
774 var pts = this._mapToLocalCoordinates([x, y]);
780 temp.stroke({'width': this.lineWidth, 'miter_limit': this.miterLimit,
781 'cap': this._paint.getStrokeCap(), 'join': this._paint.getStrokeJoin(),
782 'precision': 0.3, // this is what Chrome uses to compute this
789 this.lineTo = function(x, y) {
790 lineTo(this._currentPath, x, y);
793 this.measureText = function(text) {
795 width: this._font.measureText(text),
800 this.moveTo = function(x, y) {
801 moveTo(this._currentPath, x, y);
804 this.putImageData = function(imageData, x, y, dirtyX, dirtyY, dirtyWidth, dirtyHeight) {
810 this._canvas.writePixels(imageData.data, imageData.width, imageData.height, x, y);
843 var inverted = CanvasKit.SkMatrix.invert(this._currentTransform);
844 this._canvas.save();
846 this._canvas.concat(inverted);
847 this._canvas.drawImageRect(img, src, dst, null, false);
848 this._canvas.restore();
852 this.quadraticCurveTo = function(cpx, cpy, x, y) {
853 quadraticCurveTo(this._currentPath, cpx, cpy, x, y);
856 this.rect = function(x, y, width, height) {
857 rect(this._currentPath, x, y, width, height);
860 this.resetTransform = function() {
863 this._currentPath.transform(this._currentTransform);
864 var inverted = CanvasKit.SkMatrix.invert(this._currentTransform);
865 this._canvas.concat(inverted);
866 // This should be identity, modulo floating point drift.
867 this._currentTransform = this._canvas.getTotalMatrix();
870 this.restore = function() {
871 var newState = this._canvasStateStack.pop();
879 this._currentTransform,
882 this._currentPath.transform(combined);
883 this._paint.delete();
884 this._paint = newState.paint;
886 this._lineDashList = newState.ldl;
887 this._strokeWidth = newState.sw;
888 this._strokeStyle = newState.ss;
889 this._fillStyle = newState.fs;
890 this._shadowOffsetX = newState.sox;
891 this._shadowOffsetY = newState.soy;
892 this._shadowBlur = newState.sb;
893 this._shadowColor = newState.shc;
894 this._globalAlpha = newState.ga;
895 this._globalCompositeOperation = newState.gco;
896 this._lineDashOffset = newState.ldo;
897 this._imageSmoothingEnabled = newState.ise;
898 this._imageFilterQuality = newState.isq;
899 this._fontString = newState.fontstr;
904 this._canvas.restore();
905 this._currentTransform = this._canvas.getTotalMatrix();
908 this.rotate = function(radians) {
912 // retroactively apply the inverse of this transform to the previous
915 this._currentPath.transform(inverted);
916 this._canvas.rotate(radiansToDegrees(radians), 0, 0);
917 this._currentTransform = this._canvas.getTotalMatrix();
920 this.save = function() {
921 if (this._fillStyle._copy) {
922 var fs = this._fillStyle._copy();
923 this._toCleanUp.push(fs);
925 var fs = this._fillStyle;
928 if (this._strokeStyle._copy) {
929 var ss = this._strokeStyle._copy();
930 this._toCleanUp.push(ss);
932 var ss = this._strokeStyle;
935 this._canvasStateStack.push({
936 ctm: this._currentTransform.slice(),
937 ldl: this._lineDashList.slice(),
938 sw: this._strokeWidth,
941 sox: this._shadowOffsetX,
942 soy: this._shadowOffsetY,
943 sb: this._shadowBlur,
944 shc: this._shadowColor,
945 ga: this._globalAlpha,
946 ldo: this._lineDashOffset,
947 gco: this._globalCompositeOperation,
948 ise: this._imageSmoothingEnabled,
949 isq: this._imageFilterQuality,
950 paint: this._paint.copy(),
951 fontstr: this._fontString,
955 this._canvas.save();
958 this.scale = function(sx, sy) {
962 // retroactively apply the inverse of this transform to the previous
965 this._currentPath.transform(inverted);
966 this._canvas.scale(sx, sy);
967 this._currentTransform = this._canvas.getTotalMatrix();
970 this.setLineDash = function(dashes) {
982 this._lineDashList = dashes;
985 this.setTransform = function(a, b, c, d, e, f) {
989 this.resetTransform();
990 this.transform(a, b, c, d, e, f);
993 // Returns the matrix representing the offset of the shadows. This unapplies
995 this._shadowOffsetMatrix = function() {
996 var sx = this._currentTransform[0];
997 var sy = this._currentTransform[4];
998 return CanvasKit.SkMatrix.translated(this._shadowOffsetX/sx, this._shadowOffsetY/sy);
1002 // should be no shadow. This ends up being a copy of the given
1004 this._shadowPaint = function(basePaint) {
1006 var alphaColor = CanvasKit.multiplyByAlpha(this._shadowColor, this._globalAlpha);
1013 if (!(this._shadowBlur || this._shadowOffsetY || this._shadowOffsetX)) {
1019 SkBlurRadiusToSigma(this._shadowBlur),
1027 this.delete();
1033 // This applies the global alpha and the dashedness.
1035 this._strokePaint = function() {
1036 var paint = this._paint.copy();
1038 if (Number.isInteger(this._strokeStyle)) {
1039 var alphaColor = CanvasKit.multiplyByAlpha(this._strokeStyle, this._globalAlpha);
1042 var shader = this._strokeStyle._getShader(this._currentTransform);
1043 paint.setColor(CanvasKit.Color(0,0,0, this._globalAlpha));
1047 paint.setStrokeWidth(this._strokeWidth);
1049 if (this._lineDashList.length) {
1050 var dashedEffect = CanvasKit.MakeSkDashPathEffect(this._lineDashList, this._lineDashOffset);
1056 this.delete();
1061 this.stroke = function(path) {
1062 path = path ? path._getPath() : this._currentPath;
1063 var strokePaint = this._strokePaint();
1065 var shadowPaint = this._shadowPaint(strokePaint);
1067 this._canvas.save();
1068 this._canvas.concat(this._shadowOffsetMatrix());
1069 this._canvas.drawPath(path, shadowPaint);
1070 this._canvas.restore();
1074 this._canvas.drawPath(path, strokePaint);
1078 this.strokeRect = function(x, y, width, height) {
1079 var strokePaint = this._strokePaint();
1080 this._canvas.drawRect(CanvasKit.XYWHRect(x, y, width, height), strokePaint);
1084 this.strokeText = function(text, x, y, maxWidth) {
1086 var strokePaint = this._strokePaint();
1087 var blob = CanvasKit.SkTextBlob.MakeFromText(text, this._font);
1089 var shadowPaint = this._shadowPaint(strokePaint);
1091 this._canvas.save();
1092 this._canvas.concat(this._shadowOffsetMatrix());
1093 this._canvas.drawTextBlob(blob, x, y, shadowPaint);
1094 this._canvas.restore();
1097 this._canvas.drawTextBlob(blob, x, y, strokePaint);
1102 this.translate = function(dx, dy) {
1106 // retroactively apply the inverse of this transform to the previous
1109 this._currentPath.transform(inverted);
1110 this._canvas.translate(dx, dy);
1111 this._currentTransform = this._canvas.getTotalMatrix();
1114 this.transform = function(a, b, c, d, e, f) {
1118 // retroactively apply the inverse of this transform to the previous
1121 this._currentPath.transform(inverted);
1122 this._canvas.concat(newTransform);
1123 this._currentTransform = this._canvas.getTotalMatrix();
1127 this.addHitRegion = function() {};
1128 this.clearHitRegions = function() {};
1129 this.drawFocusIfNeeded = function() {};
1130 this.removeHitRegion = function() {};
1131 this.scrollPathIntoView = function() {};
1133 Object.defineProperty(this, 'canvas', {
1142 // This may change in future releases.
1143 // This code is staying here in case any clients are interested in using it
1149 // This is what the spec says, which is how Firefox and others operate.