<commit_before>interface CanvasRenderingContext2D {
    isPointInStroke(x: number, y: number): boolean;
}
if (!CanvasRenderingContext2D.prototype.isPointInStroke) {
    CanvasRenderingContext2D.prototype.isPointInStroke = function (x: number, y: number) {
        return false;
    };
}

module minerva.core.render {
    export interface IStrokeParameters {
        stroke: IBrush;
        strokeThickness: number;
        strokeLineJoin: PenLineJoin;
        strokeStartLineCap: PenLineCap;
        strokeEndLineCap: PenLineCap;
        strokeMiterLimit: number;
    }

    var ARC_TO_BEZIER = 0.55228475;
    var caps: string[] = [
        "butt", //flat
        "square", //square
        "round", //round
        "butt" //triangle
    ];
    var joins: string[] = [
        "miter",
        "bevel",
        "round"
    ];
    export class RenderContext {
        private $$transforms = [];
        currentTransform = mat3.identity();
        raw: CanvasRenderingContext2D;
        hasFillRule: boolean;

        constructor (ctx: CanvasRenderingContext2D) {
            Object.defineProperty(this, 'raw', {value: ctx, writable: false});
            Object.defineProperty(this, 'currentTransform', {value: mat3.identity(), writable: false});
            Object.defineProperty(this, 'hasFillRule', {value: RenderContext.hasFillRule, writable: false});
        }

        static get hasFillRule (): boolean {
            if (navigator.appName === "Microsoft Internet Explorer") {
                var version = getIEVersion();
                return version < 0 || version > 10;
            }
            return true;
        }

        resize (width: number, height: number) {
            var canvas = this.raw.canvas;
            canvas.width = width;
            canvas.height = height;
        }

        save () {
            this.$$transforms.push(mat3.create(this.currentTransform));
            this.raw.save();
        }

        restore () {
            var old = this.$$transforms.pop();
            if (old)
                mat3.copyTo(old, this.currentTransform);
            this.raw.restore();
        }

        setTransform (m11: number, m12: number, m21: number, m22: number, dx: number, dy: number) {
            mat3.copyTo([m11, m12, m21, m22, dx, dy], this.currentTransform);
            this.raw.setTransform(m11, m12, m21, m22, dx, dy);
        }

        resetTransform () {
            mat3.identity(this.currentTransform);
            var raw = <any>this.raw;
            if (raw.resetTransform)
                raw.resetTransform();
        }
<commit_msg>Add automatic scaling for high-resolution screens<commit_after>interface CanvasRenderingContext2D {
    isPointInStroke(x: number, y: number): boolean;
}
if (!CanvasRenderingContext2D.prototype.isPointInStroke) {
    CanvasRenderingContext2D.prototype.isPointInStroke = function (x: number, y: number) {
        return false;
    };
}

module minerva.core.render {
    export interface IStrokeParameters {
        stroke: IBrush;
        strokeThickness: number;
        strokeLineJoin: PenLineJoin;
        strokeStartLineCap: PenLineCap;
        strokeEndLineCap: PenLineCap;
        strokeMiterLimit: number;
    }

    var ARC_TO_BEZIER = 0.55228475;
    var caps: string[] = [
        "butt", //flat
        "square", //square
        "round", //round
        "butt" //triangle
    ];
    var joins: string[] = [
        "miter",
        "bevel",
        "round"
    ];
    export class RenderContext {
        private $$transforms = [];
        currentTransform = mat3.identity();
        raw: CanvasRenderingContext2D;
        hasFillRule: boolean;
	private ratio = 1.0;

        constructor (ctx: CanvasRenderingContext2D) {
            Object.defineProperty(this, 'raw', {value: ctx, writable: false});
            Object.defineProperty(this, 'currentTransform', {value: mat3.identity(), writable: false});
            Object.defineProperty(this, 'hasFillRule', {value: RenderContext.hasFillRule, writable: false});
        }

        static get hasFillRule (): boolean {
            if (navigator.appName === "Microsoft Internet Explorer") {
                var version = getIEVersion();
                return version < 0 || version > 10;
            }
            return true;
        }

        resize (width: number, height: number) {
	    // Compute a scaling ratio that will account for both the
	    // devicePixelRatio and the size of the canvas backing
	    // store.
            var canvas = this.raw.canvas;
	    var context : any = <any>this.raw;
	    var backingStoreRatio = context.webkitBackingStorePixelRatio ||
                context.mozBackingStorePixelRatio ||
                context.msBackingStorePixelRatio ||
                context.oBackingStorePixelRatio ||
                context.backingStorePixelRatio || 1;
	    var ratio = (window.devicePixelRatio || 1) / backingStoreRatio;
	    this.ratio = ratio;
	    
	    // Size the canvas width and height (the virtual canvas
	    // size) to the scaled up pixel count.
            canvas.width = width * ratio;
            canvas.height = height * ratio;

	    // Size the physical canvas using CSS width and height to
	    // the pixel dimensions.
	    canvas.style.width = width + "px";
	    canvas.style.height = height + "px";

	    // Add a transform to the canvas to scale the contents
	    // according to the scaling ratio, and update the
	    // currentTransform to match.
	    this.raw.transform(ratio, 0, 0, ratio, 0, 0);
	    mat3.copyTo([ratio, 0, 0, ratio, 0, 0], this.currentTransform);

	    // In setTransform and resetTransform, ensure that the transforms
	    // are appropriately scaled by the ratio for this canvas.
	    /*
	    console.log("Resize canvas: (" + width + "," + height + ") ==> (" +
			canvas.width + "," + canvas.height + ") ratio " + ratio + ": "
			+ this.currentTransform[0] + ","
			+ this.currentTransform[1] + ","
			+ this.currentTransform[2] + ","
			+ this.currentTransform[3] + ","
			+ this.currentTransform[4] + ","
			+ this.currentTransform[5]
		       );
	    */
        }

        save () {
            this.$$transforms.push(mat3.create(this.currentTransform));
            this.raw.save();
        }

        restore () {
            var old = this.$$transforms.pop();
            if (old)
                mat3.copyTo(old, this.currentTransform);
            this.raw.restore();
        }

        setTransform (m11: number, m12: number, m21: number, m22: number, dx: number, dy: number) {
            mat3.copyTo([m11, m12, m21, m22, dx, dy], this.currentTransform);
            this.raw.setTransform(m11, m12, m21, m22, dx, dy);
	    this.raw.transform(this.ratio, 0, 0, this.ratio, 0, 0);
        }

        resetTransform () {
            mat3.identity(this.currentTransform);
            var raw = <any>this.raw;
            if (raw.resetTransform) {
                raw.resetTransform();
		this.raw.transform(this.ratio, 0, 0, this.ratio, 0, 0);
	    }
        }

{'fraction_non_alphanumeric': 0.11831187410586552, 'fraction_numerical': 0.017310443490701002, 'mean_word_length': 2.100221729490022, 'pattern_counts': {'":': 1, '<': 8, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1057956', 'n_tokens_mistral': 2112, 'n_tokens_neox': 1969, 'n_words': 486}