aboutsummaryrefslogtreecommitdiff
path: root/src/library_sdl.js
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-05-16 14:01:55 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-05-16 14:01:55 -0700
commitc8424ffa1546c67eb2c08cb1860630a99b2efd22 (patch)
tree37c08790d7c93913dee2cd72d3367203219b5230 /src/library_sdl.js
parent1a5990162a3f678ba76e017d81c34ba67df97c53 (diff)
parent4f0674d6adbe7fcf3f850086b87b164a57bce0cd (diff)
Merge pull request #1177 from j4m3z0r/sdl-fixes
SDL Fixes
Diffstat (limited to 'src/library_sdl.js')
-rw-r--r--src/library_sdl.js13
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();