Skip to content

Commit 5598c41

Browse files
committed
EMCC: Emscripten version wip
- fix text measurement
1 parent 3c33e1e commit 5598c41

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

src/platform/emcc/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ sbasic_html_SOURCES = \
4141
canvas.h canvas.cpp \
4242
main.cpp
4343

44-
sbasic_html_LDFLAGS = -O3 -lembind --shell-file shell.html -s ASYNCIFY=1 --preload-file basic
44+
sbasic_html_LDFLAGS = -O3 -lembind --shell-file shell.html -s ASYNCIFY=1 -s ALLOW_MEMORY_GROWTH=1 --preload-file basic
4545

4646
sbasic_html_LDADD = -L$(top_srcdir)/src/common -lsb_common @PACKAGE_LIBS@
4747

src/platform/emcc/canvas.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ EM_JS(int, get_text_size, (int id, const char *str, const char *face), {
7474

7575
var s = UTF8ToString(str);
7676
var metrics = ctx.measureText(s);
77-
var height = metrics.fontBoundingBoxAscent + metrics.fontBoundingBoxDescent;
78-
var width = metrics.width;
79-
return (width << 16) + height;
77+
var height = metrics.fontBoundingBoxAscent + metrics.fontBoundingBoxDescent + 2;
78+
var width = s == "W" ? metrics.width : (metrics.actualBoundingBoxRight + 2);
79+
return (Math.round(width) << 16) + height;
8080
});
8181

8282
EM_JS(void, draw_arc, (int id, int xc, int yc, double r, double start, double end, double aspect), {

src/platform/emcc/runtime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Runtime::Runtime() :
6565
_output = new AnsiWidget(EXTENT_X(screenSize), EXTENT_Y(screenSize));
6666
_output->construct();
6767
_output->setTextColor(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND);
68-
_output->setFontSize(11);
68+
_output->setFontSize(12);
6969
_eventQueue = new Stack<MAEvent *>();
7070
_state = kActiveState;
7171
g_themeId = 0;

src/ui/system.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,7 @@ void System::showMenu() {
10851085
_systemMenu[index++] = MENU_PASTE;
10861086
_systemMenu[index++] = MENU_SELECT_ALL;
10871087
}
1088-
#if defined(_SDL) || defined(_FLTK)
1088+
#if defined(_SDL) || defined(_FLTK) || defined(_EMCC)
10891089
items->add(new String(MENU_STR_BACK));
10901090
_systemMenu[index++] = MENU_BACK;
10911091
#else
@@ -1109,7 +1109,7 @@ void System::showMenu() {
11091109
_systemMenu[index++] = MENU_RESTART;
11101110
}
11111111
#endif
1112-
#if !defined(_SDL) && !defined(_FLTK)
1112+
#if !defined(_SDL) && !defined(_FLTK) && !defined(_EMCC)
11131113
items->add(new String(MENU_STR_KEYPAD));
11141114
_systemMenu[index++] = MENU_KEYPAD;
11151115
#endif
@@ -1130,7 +1130,7 @@ void System::showMenu() {
11301130
sprintf(buffer, MENU_STR_AUDIO, (opt_mute_audio ? MENU_STR_OFF : MENU_STR_ON));
11311131
items->add(new String(buffer));
11321132
_systemMenu[index++] = MENU_AUDIO;
1133-
#if !defined(_SDL) && !defined(_FLTK)
1133+
#if !defined(_SDL) && !defined(_FLTK) && !defined(_EMCC)
11341134
if (!_mainBas && !_activeFile.empty()) {
11351135
items->add(new String(MENU_STR_SHORT));
11361136
items->add(new String(MENU_STR_SHARE));
@@ -1140,7 +1140,7 @@ void System::showMenu() {
11401140
#endif
11411141
items->add(new String(MENU_STR_SCREEN));
11421142
_systemMenu[index++] = MENU_SCREENSHOT;
1143-
#if defined(_SDL) || defined(_FLTK)
1143+
#if defined(_SDL) || defined(_FLTK) || defined(_EMCC)
11441144
items->add(new String(MENU_STR_BACK));
11451145
_systemMenu[index++] = MENU_BACK;
11461146
#endif

src/ui/utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#define deviceLog(...) appLog(__VA_ARGS__)
3434
#endif
3535

36-
#if defined(_DEBUG) || defined(_EMCC)
36+
#if defined(_DEBUG)
3737
#define trace(...) deviceLog(__VA_ARGS__)
3838
#else
3939
#define trace(...)

0 commit comments

Comments
 (0)