Restore canvas context update transformation stack
177300
function _restoreCanvas(ctx, data) {
	if (data.savedTransforms.length === 0) {
		// Reset transformation state if it can't be restored any more
		data.transforms = _cloneTransforms(baseTransforms);
	} else {
		// Restore canvas context
		ctx.restore();
		// Restore current transform state to the last saved state
		data.transforms = data.savedTransforms.pop();
	}
}
684805
public void restoreTransientState(FacesContext context, Object state)
    {
        boolean forceCreate = (state != null);
        TransientStateHelper helper = getTransientStateHelper(forceCreate);

        if (helper != null) {
            helper.restoreTransientState(context, state);
        }
    }
316796
function resize(newWidth, newHeight) {

        // Default size to zero
        newWidth = newWidth || 0;
        newHeight = newHeight || 0;

        // Calculate new dimensions of internal canvas
        var canvasWidth  = Math.ceil(newWidth  / CANVAS_SIZE_FACTOR) * CANVAS_SIZE_FACTOR;
        var canvasHeight = Math.ceil(newHeight / CANVAS_SIZE_FACTOR) * CANVAS_SIZE_FACTOR;

        // Resize only if canvas dimensions are actually changing
        if (canvas.width !== canvasWidth || canvas.height !== canvasHeight) {

            // Copy old data only if relevant and non-empty
            var oldData = null;
            if (!empty && canvas.width !== 0 && canvas.height !== 0) {

                // Create canvas and context for holding old data
                oldData = document.createElement("canvas");
                oldData.width = Math.min(layer.width, newWidth);
                oldData.height = Math.min(layer.height, newHeight);

                var oldDataContext = oldData.getContext("2d");

                // Copy image data from current
                oldDataContext.drawImage(canvas,
                        0, 0, oldData.width, oldData.height,
                        0, 0, oldData.width, oldData.height);

            }

            // Preserve composite operation
            var oldCompositeOperation = context.globalCompositeOperation;

            // Resize canvas
            canvas.width = canvasWidth;
            canvas.height = canvasHeight;

            // Redraw old data, if any
            if (oldData)
                context.drawImage(oldData,
                    0, 0, oldData.width, oldData.height,
                    0, 0, oldData.width, oldData.height);

            // Restore composite operation
            context.globalCompositeOperation = oldCompositeOperation;

            // Acknowledge reset of stack (happens on resize of canvas)
            stackSize = 0;
            context.save();

        }

        // If the canvas size is not changing, manually force state reset
        else
            layer.reset();

        // Assign new layer dimensions
        layer.width = newWidth;
        layer.height = newHeight;

    }
1068127
private void paintRestorePressed(Graphics2D g, JComponent c, int width, int height) {
        restorePainter.paintPressed(g, c, width, height);
    }
222491
@Override
	public void updateContext() {

		String newValue = replaceVariables( this.value, this.context, this.instancePath );
		if( newValue != null ) {
			this.context.variables.put( this.key, newValue );
		}

		// When not resolved, we disable it.
		// We also replace it by a mock value so that we can perform
		// validation. It implies populating the context.
		else {
			setDisabled( true );
			this.context.disabledVariables.add( this.key );
			this.context.variables.put( this.key, "fake" );
			String path = "/fake";
			if( this.instancePath != null )
				path = this.instancePath + path;

			this.context.instancePathToComponentName.put( path, FAKE_COMPONENT_NAME );
		}
	}
126467
function patchHooks(hooks) {
  var original = {};
  var restore;

  hookTypes.map(function(key) {
    original[key] = global[key];

    global[key] = function(title, fn) {
      // Hooks accept an optional title, though they're
      // ignored here for simplicity
      if (!fn) fn = title;
      hooks[key] = createWrapper(fn);
    };
  });

  restore = function() {
    hookTypes.forEach(function(key) {
      global[key] = original[key];
    });
  };

  return restore;
}
565474
function (col, opaque) {
            this.save();
            this.resetTransform();
            this.backBufferContext2D.globalCompositeOperation = opaque ? "copy" : "source-over";
            this.backBufferContext2D.fillStyle = (col instanceof me.Color) ? col.toRGBA() : col;
            this.fillRect(0, 0, this.backBufferCanvas.width, this.backBufferCanvas.height);
            this.restore();
        }
1003874
function(ctx) {
      ctx.save();

      var m = this.transformMatrix;
      if (m) {
        ctx.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
      }

      this.transform(ctx);
      for (var i = 0, l = this.paths.length; i < l; ++i) {
        this.paths[i].render(ctx, true);
      }
      if (this.active) {
        this.drawBorders(ctx);
        this.hideCorners || this.drawCorners(ctx);
      }
      ctx.restore();
    }
1125505
function (clip) {
    var canvas = this.canvas;
    var context = canvas.getContext('2d');
    morpheus.CanvasUtil.resetTransform(context);
    var width = this.getUnscaledWidth();
    var height = this.getUnscaledHeight();
    context.clearRect(0, 0, width, height);
    if (this.prePaint) {
      morpheus.CanvasUtil.resetTransform(context);
      context.translate(this.offset.x, this.offset.y);
      this.prePaint(clip, context);
    }
    morpheus.CanvasUtil.resetTransform(context);
    if (this.offscreenCanvas) {
      if (this.invalid) {
        var oc = this.offscreenCanvas.getContext('2d');
        morpheus.CanvasUtil.resetTransform(oc);
        context.translate(this.offset.x, this.offset.y);
        oc.clearRect(0, 0, width, height);
        this.draw(clip, oc);
      }
      if (width > 0 && height > 0) {
        context.drawImage(this.offscreenCanvas, 0, 0, width, height);
      }
    } else {
      this.draw(clip, context);
    }
    if (this.postPaint) {
      morpheus.CanvasUtil.resetTransform(context);
      context.translate(this.offset.x, this.offset.y);
      this.postPaint(clip, context);
    }
    this.lastClip = clip;
    this.invalid = false;
  }
1312683
function postDraw(renderer) {
         if (typeof this.mask !== "undefined") {
           renderer.clearMask();
         }

         if (typeof this.tint !== "undefined") {
           renderer.clearTint();
         } // restore the context


         renderer.restore();
       }
339120
function getTransformedLayerData(iCanvas, layer, rect) {
    var canvas = document.createElement('canvas');
    var ctx = canvas.getContext('2d');
    canvas.width = rect.width;
    canvas.height = rect.height;
    ctx.translate(-rect.x, -rect.y);
    transformLayer(ctx, iCanvas, layer);
    ctx.drawImage(layer.img, 0, 0);
    return ctx.getImageData(0, 0, rect.width, rect.height);
}
896676
def copy_image_to_context(self, context, position, rotation=0, zoom=None):
        
        if not zoom:
            zoom = self.__zoom
        zoom_multiplicator = zoom * self.multiplicator
        context.save()
        context.scale(1. / zoom_multiplicator, 1. / zoom_multiplicator)

        image_position = round(position[0] * zoom_multiplicator), round(position[1] * zoom_multiplicator)
        context.translate(*image_position)
        context.rotate(rotation)
        context.set_source_surface(self.__image, 0, 0)

        context.paint()
        context.restore()
1212483
function updatePrimaryRootContext(wrappingComponent) {
  const adapter = getAdapter(wrappingComponent[OPTIONS]);
  const primaryWrapper = wrappingComponent[PRIMARY_WRAPPER];
  const primaryRenderer = primaryWrapper[RENDERER];
  const primaryNode = primaryRenderer.getNode();
  const {
    legacyContext,
    providerValues,
  } = getContextFromWrappingComponent(wrappingComponent, adapter);
  const prevProviderValues = primaryWrapper[PROVIDER_VALUES];

  primaryWrapper.setContext({
    ...wrappingComponent[PRIMARY_WRAPPER][OPTIONS].context,
    ...legacyContext,
  });
  primaryWrapper[PROVIDER_VALUES] = new Map([...prevProviderValues, ...providerValues]);

  if (typeof adapter.isContextConsumer === 'function' && adapter.isContextConsumer(primaryNode.type)) {
    const Consumer = primaryNode.type;
    // Adapters with an `isContextConsumer` method will definitely have a `getProviderFromConsumer`
    // method.
    const Provider = adapter.getProviderFromConsumer(Consumer);
    const newValue = providerValues.get(Provider);
    const oldValue = prevProviderValues.get(Provider);

    // Use referential comparison like React
    if (newValue !== oldValue) {
      primaryWrapper.rerender();
    }
  }
}
122161
function(shape, context, top) {
            if (!top || top._id !== this._id) {
                var m = shape.getTransform().getMatrix();
                context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
            }
        }
1193283
function _getCanvasData(canvas) {
	var dataCache = caches.dataCache, data;
	if (dataCache._canvas === canvas && dataCache._data) {

		// Retrieve canvas data from cache if possible
		data = dataCache._data;

	} else {

		// Retrieve canvas data from jQuery's internal data storage
		data = $.data(canvas, 'jCanvas');
		if (!data) {

			// Create canvas data object if it does not already exist
			data = {
				// The associated canvas element
				canvas: canvas,
				// Layers array
				layers: [],
				// Layer maps
				layer: {
					names: {},
					groups: {}
				},
				eventHooks: {},
				// All layers that intersect with the event coordinates (regardless of visibility)
				intersecting: [],
				// The topmost layer whose area contains the event coordinates
				lastIntersected: null,
				cursor: $(canvas).css('cursor'),
				// Properties for the current drag event
				drag: {
					layer: null,
					dragging: false
				},
				// Data for the current event
				event: {
					type: null,
					x: null,
					y: null
				},
				// Events which already have been bound to the canvas
				events: {},
				// The canvas's current transformation state
				transforms: _cloneTransforms(baseTransforms),
				savedTransforms: [],
				// Whether a layer is being animated or not
				animating: false,
				// The layer currently being animated
				animated: null,
				// The device pixel ratio
				pixelRatio: 1,
				// Whether pixel ratio transformations have been applied
				scaled: false,
				// Whether the canvas should be redrawn when a layer mousemove
				// event triggers (either directly, or indirectly via dragging)
				redrawOnMousemove: false
			};
			// Use jQuery to store canvas data
			$.data(canvas, 'jCanvas', data);

		}
		// Cache canvas data for faster retrieval
		dataCache._canvas = canvas;
		dataCache._data = data;

	}
	return data;
}
1009670
function () {
            this._super(me.Renderer, "reset");
            if (this.isContextValid === false) {
                // on context lost/restore
                this.compositor.init(this);
            } else {
                this.compositor.reset();
            }
            this.gl.disable(this.gl.SCISSOR_TEST);
            if (typeof this.fontContext2D !== "undefined" ) {
                this.createFontTexture(this.cache);
            }

        }
1159383
function Canvas(context) {
        this.context = context;
        this.stateStack = [];
        this.color = Graphics.Color.BLACK;
        this.fillColor = Graphics.Color.WHITE;
        this.fontColor = Graphics.Color.BLACK;
        this.font = new Graphics.Font("Arial", 12, Graphics.FS_NORMAL);
        this.lineWidth = 1;
        this.alpha = 1.0;
        this.origin = new Graphics.Point(0.0, 0.0);
        this.zoomFactor = new Graphics.ZoomFactor(1, 1);
        this.gridFactor = new Graphics.GridFactor(1, 1);
        this.coordTransformApplied = true;
    }