diff options
author | Paul Gilbert | 2014-08-16 23:18:53 -0400 |
---|---|---|
committer | Paul Gilbert | 2014-08-16 23:18:53 -0400 |
commit | ff01ee6807ccd6e5a71ddc945196d68b87f3aa65 (patch) | |
tree | 598bff2258c80d09367aae7b7598e2b0c4b0796a /engines/access/data.cpp | |
parent | f784b4efba7518806195f96d0177ccdc6e2dbaf8 (diff) | |
download | scummvm-rg350-ff01ee6807ccd6e5a71ddc945196d68b87f3aa65.tar.gz scummvm-rg350-ff01ee6807ccd6e5a71ddc945196d68b87f3aa65.tar.bz2 scummvm-rg350-ff01ee6807ccd6e5a71ddc945196d68b87f3aa65.zip |
ACCESS: Added code for bubble box size calculations
Diffstat (limited to 'engines/access/data.cpp')
-rw-r--r-- | engines/access/data.cpp | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/engines/access/data.cpp b/engines/access/data.cpp index 1f8b33ef43..65702db9f1 100644 --- a/engines/access/data.cpp +++ b/engines/access/data.cpp @@ -60,7 +60,7 @@ void Font::load(const int *index, const byte *data) { } int Font::charWidth(char c) { - error("TODO"); + return *_chars[c - ' ']; } int Font::stringWidth(const Common::String &msg) { @@ -72,6 +72,45 @@ int Font::stringWidth(const Common::String &msg) { return 0; } +bool Font::getLine(Common::String &s, int maxWidth, Common::String &line, int &width) { + width = 0; + const char *src = s.c_str(); + char c; + + while ((c = *src) != '\0') { + if (c == '\r') { + // End of line, so return calculated line + line = Common::String(s.c_str(), src - 1); + s = Common::String(src + 1); + return false; + } + + ++src; + width += charWidth(c); + if (width < maxWidth) + continue; + + // Reached maximum allowed. Work backwards to find space at the + // start of the current word as a point to split the line on + while (*src != ' ' && src >= s.c_str()) { + width -= charWidth(*src); + --src; + } + if (src < s.c_str()) + error("Could not fit line"); + + // Split the line around the space + line = Common::String(s.c_str(), src - 1); + s = Common::String(src + 1); + return false; + } + + // Return entire string + line = s; + s = Common::String(); + return true; +} + /*------------------------------------------------------------------------*/ FontManager::FontManager() { |