From 33dbde556bd2a791947bcd433f594766031c48ac Mon Sep 17 00:00:00 2001 From: Aleksander Guryanov Date: Fri, 2 Jun 2017 17:39:10 +0700 Subject: [PATCH] Fix cutting when render text through TTF_RenderText_Solid --- src/library_sdl.js | 9 ++++++--- tests/sdl_ttf_render_text_solid.c | 19 +++++++++++++++++++ tests/sdl_ttf_render_text_solid.png | Bin 0 -> 1554 bytes tests/test_browser.py | 3 +++ 4 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 tests/sdl_ttf_render_text_solid.c create mode 100644 tests/sdl_ttf_render_text_solid.png diff --git a/src/library_sdl.js b/src/library_sdl.js index 96851be1befbd..9e17166dc3d99 100644 --- a/src/library_sdl.js +++ b/src/library_sdl.js @@ -3001,14 +3001,17 @@ 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 ' + fontData.name; + var fontString = h + 'px ' + fontData.name + ', serif'; var surf = SDL.makeSurface(w, h, 0, false, 'text:' + text); // bogus numbers.. var surfData = SDL.surfaces[surf]; surfData.ctx.save(); surfData.ctx.fillStyle = color; surfData.ctx.font = fontString; - surfData.ctx.textBaseline = 'top'; - surfData.ctx.fillText(text, 0, 0); + // use bottom alligment, because it works + // same in all browsers, more info here: + // https://bugzilla.mozilla.org/show_bug.cgi?id=737852 + surfData.ctx.textBaseline = 'bottom'; + surfData.ctx.fillText(text, 0, h|0); surfData.ctx.restore(); return surf; }, diff --git a/tests/sdl_ttf_render_text_solid.c b/tests/sdl_ttf_render_text_solid.c new file mode 100644 index 0000000000000..05fadfe33f74b --- /dev/null +++ b/tests/sdl_ttf_render_text_solid.c @@ -0,0 +1,19 @@ +#include +#include +#include + +int main() +{ + SDL_Init(SDL_INIT_VIDEO); + SDL_Surface *screen = SDL_SetVideoMode(320, 32, 32, SDL_HWSURFACE); + + TTF_Init(); + TTF_Font *font = TTF_OpenFont("Arial", 32); + + SDL_Color color = { 0xff, 0x99, 0x00, 0xff }; + SDL_Surface *text = TTF_RenderText_Solid(font, "Play", color); + SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 0, 0)); + SDL_BlitSurface(text, NULL, screen, NULL); + return 0; +} + diff --git a/tests/sdl_ttf_render_text_solid.png b/tests/sdl_ttf_render_text_solid.png new file mode 100644 index 0000000000000000000000000000000000000000..f94ac8f086248ad978cf661803cf77a886a367b7 GIT binary patch literal 1554 zcmV+t2JQKYP)a&SB+~(`;|k6TI#2cxV2C%Vj$EcZQ#;Q*~-)%!b*-LLdY}U;+uuhyYIDsOObK zAO!v)Fh>CQ1a=-kMPKm`;AdbK@GkHQ@O6*#4hJ?V`z{8)4fPNRfe`rr5SSx?GlAWw z@L<0KPXG_MoO>*=McICOAEBJWZF5Qpgg^*%CD1N_dTQVFxb#B662S6}{f`3=Hnv3o zyN*xJ4}lPvhXmRM@R1%KUHw5;1rDl(xPJkLxu4b!iU7{Tq06O1AOyM+n7ROZ=Y@eY zfi=owJOkVl0qi;`IX?tKVEz#3CV)QUj=&-1VfFqli~!D`q03!DAOyM+=q`Zk1E-b8 z_yIU+3Iezeur06=uw0pA{0;aX_z-vrc)RhcO9K0pZDyq(7=U61a6s`|z3xL@(dGOQ z2!ZKNpt}HW2%J(dSPo;hx3WQVfQtZ!0ox3LQ4zcYaIUekbAdI>2j?F@?sJ`uYvTMg zaPJWJ%poBV0%J{}y8v20xOZXn7I59a5WwSs&C2m+o)x(-fIo{TxH+&v?RxhEPu4!~ zQoK4hx!wJ}>`-8bvhyO~ld&Gxyj%!`zz_tw3E(Ql<1-x9?gpM6QUJFEjw#3Lxm^YP z((=T+0sEHip8*%tj#(PG99XcF?dW~BE$lN{b0x5N@e=hGV<8X%6HlOB03QV`g=yLX zz@os)fZmxNn4+Q?{u+`xcUM`z5csGv@8_{s1Ml=03-75oDzb*Zie_Epjs~_W=jwgx zg*I(F;K;JkEVbF{SO|o`#1rVg5=4ZG-u1wH4W9i3(9)UJfE57eXXXqp5zO_oh@T}ToG(TYZEpmL1G~g0uxW5y8!CB=~cDOsSQek48m`SYi9VsGAHQq z&Kv$(J5dkOFnE~~LZ93aNVmJ+<6Z-98FbU^4}lPv6awu6Xd=SDrWt}NK0lQeA9{RW z_CYnQ04`OM9eRX@*DC?5*F>*=i>3g&Z+~Fda?tH1nNpooPn0NrieM}RLLda@>IPG9 zhA_-hxMA=O5)(fw3phEekvdPd@>)e$S%mDue8`6e%;kpBE4FgA!VwQJVv76F|@PnDvUlDRf@T zdzhHfn#=SCJ$v?tKnRRIfzb)zS%51*G&8r>@b#+Avu@9l8?BcB?gSiMj=2kXzN{44 zqih>gC_VN=ofiy&5NHw@jR39%oKqgfwp)g&^~`SlDNSBn3oKSPp3tLS&=y@+l%;NO z0ymVf*zj0kRYYSU5CS1kBQP2Pv~JJ(J?(Yi=00O$LsdiR%1#7+>~Xxce%AciwffSU z$leD$m2nS&5D0;}35-Sn>+5pADnezAUelH>i3^h@m08Evt6A%&fF7due#tDS_AlT0 z5D0-D1V$r(E={`(u>3`H4Y17#zAK+yZDNB2yS*rabvwT#N!nh>jxTzC^={RJJj{GG zLLdYtmcVEPP~6)CN7T5x5=76=|F*<(?oWHM`~cHl<#V&nuQ_x!X0Sm+Ww!#aPVD&R z#X}$j`VbhM0QykQ1zN;x@pIi2K||Qb023P4@tG*mnst87mor;jB|I#JF=Td5FctzK z5CRPXqyJrC!&Wo33YVd=qGflOsjk;G{51^rx~cuk7d`|+U?>l8TrgSpS9OX`?ccbJ zYThFR<_Uq(dw~DtYx$F%_6sy?Y%6^eEwK;?fe`3HV0sIni4sFzlP4>d#;IGEH@yvb zIpZDzArJz+2~2MRbe`{~mPQJ8sj-P_zaE46R)jzZOgw?B~zyJb&17sU!@U7&(C;$Ke07*qoM6N<$ Eg4m(JmjD0& literal 0 HcmV?d00001 diff --git a/tests/test_browser.py b/tests/test_browser.py index ba4ec5420a840..a6c3960492902 100644 --- a/tests/test_browser.py +++ b/tests/test_browser.py @@ -1825,6 +1825,9 @@ def test_sdl_canvas_palette_2(self): self.btest('sdl_canvas_palette_2.c', reference='sdl_canvas_palette_g.png', args=['--pre-js', 'pre.js', '--pre-js', 'args-g.js', '-lSDL', '-lGL']) self.btest('sdl_canvas_palette_2.c', reference='sdl_canvas_palette_b.png', args=['--pre-js', 'pre.js', '--pre-js', 'args-b.js', '-lSDL', '-lGL']) + def test_sdl_ttf_render_text_solid(self): + self.btest('sdl_ttf_render_text_solid.c', reference='sdl_ttf_render_text_solid.png', args=['-O2', '-s', 'TOTAL_MEMORY=16MB', '-lSDL', '-lGL']) + def test_sdl_alloctext(self): self.btest('sdl_alloctext.c', expected='1', args=['-O2', '-s', 'TOTAL_MEMORY=16MB', '-lSDL', '-lGL'])