diff options
author | James Gregory <james@james.id.au> | 2013-05-14 21:42:45 -0700 |
---|---|---|
committer | James Gregory <james@james.id.au> | 2013-05-14 21:42:45 -0700 |
commit | c33c3dfeafaec96f4c599bd62cc59a3162bd2e12 (patch) | |
tree | 57667b8a3fcbd30fae94ef903cd0c5ded4e3a43c /src/library_sdl.js | |
parent | 2b94dc6e7d29cd6c2a734114ed0ef7ac03243c67 (diff) |
* Switch to using offscren canvas for TTF size estimation in SDL
* use the actual font the user asked for.
Diffstat (limited to 'src/library_sdl.js')
-rw-r--r-- | src/library_sdl.js | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/library_sdl.js b/src/library_sdl.js index 9c5e9805..7fad5941 100644 --- a/src/library_sdl.js +++ b/src/library_sdl.js @@ -547,9 +547,8 @@ var LibrarySDL = { estimateTextWidth: function(fontData, text) { var h = fontData.size; - var fontString = h + 'px sans-serif'; - // TODO: use temp context, not screen's, to avoid affecting its performance? - var tempCtx = SDL.surfaces[SDL.screen].ctx; + var fontString = h + 'px ' + fontData.name; + var tempCtx = SDL.ttfContext; tempCtx.save(); tempCtx.font = fontString; var ret = tempCtx.measureText(text).width | 0; @@ -1561,7 +1560,11 @@ var LibrarySDL = { // SDL TTF - TTF_Init: function() { return 0 }, + TTF_Init: function() { + var canvas = document.createElement('canvas'); + SDL.ttfContext = canvas.getContext('2d'); + return 0; + }, TTF_OpenFont: function(filename, size) { filename = FS.standardizePath(Pointer_stringify(filename)); @@ -1584,7 +1587,7 @@ var LibrarySDL = { var w = SDL.estimateTextWidth(fontData, text); var h = fontData.size; var color = SDL.loadColorToCSSRGB(color); // XXX alpha breaks fonts? - var fontString = h + 'px sans-serif'; + var fontString = h + 'px ' + fontData.name; var surf = SDL.makeSurface(w, h, 0, false, 'text:' + text); // bogus numbers.. var surfData = SDL.surfaces[surf]; surfData.ctx.save(); |