diff options
-rw-r--r-- | engines/gargoyle/fonts.cpp | 31 | ||||
-rw-r--r-- | engines/gargoyle/fonts.h | 9 | ||||
-rw-r--r-- | engines/gargoyle/window_text_buffer.cpp | 25 | ||||
-rw-r--r-- | engines/gargoyle/window_text_grid.cpp | 10 |
4 files changed, 39 insertions, 36 deletions
diff --git a/engines/gargoyle/fonts.cpp b/engines/gargoyle/fonts.cpp index 41b2f655ff..45f8671157 100644 --- a/engines/gargoyle/fonts.cpp +++ b/engines/gargoyle/fonts.cpp @@ -103,24 +103,31 @@ Graphics::Font *Fonts::loadFont(FACES face, double size, double aspect, int styl return Graphics::loadTTFFont(f, size, Graphics::kTTFSizeModeCharacter); } -int Fonts::drawString(int x, int y, int fidx, const byte *rgb, const char *s, int n, int spw) { - // TODO - return 0; +int Fonts::drawString(const Common::Point &pos, int fontIdx, const byte *rgb, const Common::String &text, int spw) { + Graphics::Font *font = _fontTable[fontIdx]; + const uint32 color = _surface->format.RGBToColor(rgb[0], rgb[1], rgb[2]); + font->drawString(_surface, text, pos.x, pos.y, _surface->w - pos.x, color); + return font->getBoundingBox(text, pos.x, pos.y, _surface->w - pos.x).right; } -int Fonts::drawStringUni(int x, int y, int fidx, const byte *rgb, const uint32 *s, int n, int spw) { - // TODO - return 0; +int Fonts::drawStringUni(const Common::Point &pos, int fontIdx, const byte *rgb, const Common::U32String &text, int spw) { + Graphics::Font *font = _fontTable[fontIdx]; + const uint32 color = _surface->format.RGBToColor(rgb[0], rgb[1], rgb[2]); + font->drawString(_surface, text, pos.x, pos.y, _surface->w - pos.x, color); + + return font->getBoundingBox(text, pos.x, pos.y, _surface->w - pos.x).right; } -int Fonts::stringWidth(int fidx, const char *s, int n, int spw) { - // TODO - return 0; +size_t Fonts::stringWidth(int fontIdx, const Common::String &text, int spw) { + // TODO: Handle spw + Graphics::Font *font = _fontTable[fontIdx]; + return font->getStringWidth(text); } -int Fonts::stringWidthUni(int fidx, const uint32 *s, int n, int spw) { - // TODO - return 0; +size_t Fonts::stringWidthUni(int fontIdx, const Common::U32String &text, int spw) { + // TODO: Handle spw + Graphics::Font *font = _fontTable[fontIdx]; + return font->getStringWidth(text); } } // End of namespace Gargoyle diff --git a/engines/gargoyle/fonts.h b/engines/gargoyle/fonts.h index 35db815ec4..a486a01154 100644 --- a/engines/gargoyle/fonts.h +++ b/engines/gargoyle/fonts.h @@ -25,6 +25,7 @@ #include "gargoyle/glk_types.h" #include "common/str.h" +#include "common/ustr.h" #include "graphics/font.h" namespace Gargoyle { @@ -57,13 +58,13 @@ public: */ virtual ~Fonts(); - int drawString(int x, int y, int fidx, const byte *rgb, const char *s, int n, int spw); + int drawString(const Common::Point &pos, int fontIdx, const byte *rgb, const Common::String &text, int spw = 0); - int drawStringUni(int x, int y, int fidx, const byte *rgb, const uint32 *s, int n, int spw); + int drawStringUni(const Common::Point &pos, int fontIdx, const byte *rgb, const Common::U32String &text, int spw = 0); - int stringWidth(int fidx, const char *s, int n, int spw); + size_t stringWidth(int fontIdx, const Common::String &text, int spw = -1); - int stringWidthUni(int fidx, const uint32 *s, int n, int spw); + size_t stringWidthUni(int fontIdx, const Common::U32String &text, int spw = -1); }; } // End of namespace Gargoyle diff --git a/engines/gargoyle/window_text_buffer.cpp b/engines/gargoyle/window_text_buffer.cpp index 818bcf0b9e..ebce9c3679 100644 --- a/engines/gargoyle/window_text_buffer.cpp +++ b/engines/gargoyle/window_text_buffer.cpp @@ -966,7 +966,7 @@ void TextBufferWindow::redraw() { link = ln->_attrs[a].hyper; font = ln->_attrs[a].attrFont(_styles); color = ln->_attrs[a].attrBg(_styles); - w = screen.stringWidthUni(font, ln->_chars + a, b - a, spw); + w = screen.stringWidthUni(font, Common::U32String(ln->_chars + a, b - a), spw); screen.fillRect(x/GLI_SUBPIX, y, w/GLI_SUBPIX, g_conf->_leading, color); @@ -985,7 +985,7 @@ void TextBufferWindow::redraw() { link = ln->_attrs[a].hyper; font = ln->_attrs[a].attrFont(_styles); color = ln->_attrs[a].attrBg(_styles); - w = screen.stringWidthUni(font, ln->_chars + a, b - a, spw); + w = screen.stringWidthUni(font, Common::U32String(ln->_chars + a, b - a), spw); screen.fillRect(x/GLI_SUBPIX, y, w/GLI_SUBPIX, g_conf->_leading, color); if (link) { @@ -1025,16 +1025,16 @@ void TextBufferWindow::redraw() { link = ln->_attrs[a].hyper; font = ln->_attrs[a].attrFont(_styles); color = link ? g_conf->_linkColor : ln->_attrs[a].attrFg(_styles); - x = screen.drawStringUni(x, y + g_conf->_baseLine, - font, color, ln->_chars + a, b - a, spw); + x = screen.drawStringUni(Common::Point(x, y + g_conf->_baseLine), + font, color, Common::U32String(ln->_chars + a, b - a), spw); a = b; } } link = ln->_attrs[a].hyper; font = ln->_attrs[a].attrFont(_styles); color = link ? g_conf->_linkColor : ln->_attrs[a].attrFg(_styles); - screen.drawStringUni(x, y + g_conf->_baseLine, - font, color, ln->_chars + a, linelen - a, spw); + screen.drawStringUni(Common::Point(x, y + g_conf->_baseLine), + font, color, Common::U32String(ln->_chars + a, linelen - a), spw); } /* @@ -1053,8 +1053,7 @@ void TextBufferWindow::redraw() { x1/GLI_SUBPIX - x/GLI_SUBPIX, g_conf->_leading, color); - w = screen.stringWidth(g_conf->_moreFont, - g_conf->_morePrompt.c_str(), g_conf->_morePrompt.size(), -1); + w = screen.stringWidth(g_conf->_moreFont, g_conf->_morePrompt); if (g_conf->_moreAlign == 1) /* center */ x = x0 + SLOP + (x1 - x0 - w - SLOP * 2) / 2; @@ -1062,9 +1061,8 @@ void TextBufferWindow::redraw() { x = x1 - SLOP - w; color = Windows::_overrideFgSet ? g_conf->_moreColor : _fgColor; - screen.drawString(x, y + g_conf->_baseLine, - g_conf->_moreFont, color, - g_conf->_morePrompt.c_str(), g_conf->_morePrompt.size(), -1); + screen.drawString(Common::Point(x, y + g_conf->_baseLine), + g_conf->_moreFont, color, g_conf->_morePrompt); y1 = y; /* don't want pictures overdrawing "[more]" */ /* try to claim the focus */ @@ -1617,13 +1615,12 @@ int TextBufferWindow::calcWidth(glui32 *chars, Attributes *attrs, int startchar, for (b = startchar; b < numChars; b++) { if (attrs[a] == attrs[b]) { w += screen.stringWidthUni(attrs[a].attrFont(_styles), - chars + a, b - a, spw); + Common::U32String(chars + a, b - a), spw); a = b; } } - w += screen.stringWidthUni(attrs[a].attrFont(_styles), - chars + a, b - a, spw); + w += screen.stringWidthUni(attrs[a].attrFont(_styles), Common::U32String(chars + a, b - a), spw); return w; } diff --git a/engines/gargoyle/window_text_grid.cpp b/engines/gargoyle/window_text_grid.cpp index e2ee06ec6a..7b349a5e48 100644 --- a/engines/gargoyle/window_text_grid.cpp +++ b/engines/gargoyle/window_text_grid.cpp @@ -607,9 +607,8 @@ void TextGridWindow::redraw() { o = x; for (k = a; k < b; k++) { - screen.drawStringUni(o * GLI_SUBPIX, - y + g_conf->_baseLine, font, fgcolor, - &ln->_chars[k], 1, -1); + screen.drawStringUni(Common::Point(o * GLI_SUBPIX, y + g_conf->_baseLine), + font, fgcolor, Common::U32String(&ln->_chars[k], 1), -1); o += g_conf->_cellW; } if (link) { @@ -631,9 +630,8 @@ void TextGridWindow::redraw() { o = x; for (k = a; k < b; k++) { - screen.drawStringUni(o * GLI_SUBPIX, - y + g_conf->_baseLine, font, fgcolor, - &ln->_chars[k], 1, -1); + screen.drawStringUni(Common::Point(o * GLI_SUBPIX, y + g_conf->_baseLine), + font, fgcolor, Common::U32String(&ln->_chars[k], 1)); o += g_conf->_cellW; } if (link) { |