private void _SpriteFont(HTMLImageElement image, int glyphWidth, int glyphHeight, bool xtrim) { HTMLCanvasElement canvas = new HTMLCanvasElement(); canvas.width = (uint)glyphWidth; canvas.height = (uint)glyphHeight; CanvasRenderingContext2D context = canvas.getContext(Literals._2d); for (int i = start; i <= end; i++) { context.clearRect(0, 0, canvas.width, canvas.height); context.drawImage(image, glyphWidth * (i - start), 0, glyphWidth, glyphHeight, 0, 0, glyphWidth, glyphHeight); // Make sure loaded image is large enough // If image is not large enough, generate error glyphs if (image.width >= glyphWidth * (i - start) + glyphWidth) { glyphs[i] = SpriteSheet.AddSpriteFontGlyph(canvas, context, xtrim); } else { glyphs[i] = SpriteSheet.AddSpriteFontGlyph(canvas, context, false); } } canvas.remove(); loaded = true; }