
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
Drawing text to HTML5
Drawing text in a canvas with a typeface that is loaded via @font-face does not show text correctly at first. This is because the browser has not yet loaded the font from network. Therefore, it makes use of the font, which is already available.
The font has to be completed loaded before it is used. This can be ensured using <div> tag. If you want to make sure that the font is available and have some other elements preloaded, then you can do this by using the <div> tag as under
<div style="font-family: PressStart;"></div>
You can also load font like this −
var newFont = new FontFace(‘New Font', 'url(https://samplefont.woff2)'); newFont.load().then(function(font){ document.fonts.add(font); alert('Font successfully loaded!'); });
- Related Articles
- How to actually work with HTML5 Canvas camera/viewport?
- HTML5 Canvas Circle Text
- Drawing an SVG file on an HTML5 canvas
- Properties to create text using HTML5 Canvas
- Drawing an image from a data URL to a HTML5 canvas
- How to use GoJS HTML5 Canvas Library for drawing diagrams and graphs?
- Drawing sine waves with HTML5
- Does HTML5 Canvas support Double Buffering?
- Measure text height on an HTML5 canvas element
- HTML5 Canvas Text Stroke for Large Font Size
- Create a text inside circles in HTML5 Canvas
- Enhance real-time performance on HTML5 canvas effects
- Drop Shadow with HTML5 Canvas
- How to use images with HTML5 canvas?
- How to prevent text select outside HTML5 canvas on double-click?

Advertisements