Skip to content

Text.getMeasuredLineHeight() is 0 in IE11 and inaccurate in Chrome 44 #652

Open
@Inverness

Description

@Inverness

I've found that the Text.getMeasuredLineHeight() function is returning 0 in IE11 and is returning an inaccurate value (30% smaller than it should be) in Chrome 44.

I have to assume this has to do with how the rendering context is cached statically, because creating a function that uses the same methodology on a fresh context has allowed me to avoid the issue:

        static getMeasuredLineHeight(text: createjs.Text): number {
            if (!text || !text.stage || !text.stage.canvas)
                return 0;

            var canvas = <HTMLCanvasElement> text.stage.canvas;
            var ctx = canvas.getContext("2d");

            ctx.save();

            ctx.font = text.font || "10px sans-serif";
            ctx.textAlign = text.textAlign || "left";
            ctx.textBaseline = text.textBaseline || "top";
            var result = ctx.measureText("M").width * 1.2;

            ctx.restore();

            return result;
        }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions