From 4cf42c6dac924f49ff2521ca80fd0d50a5c2c0d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torbj=C3=B6rn=20Andersson?= Date: Wed, 13 Oct 2021 14:31:55 +0200 Subject: [PATCH] SCUMM: Center text better in Mac Loom (bug #12984) Measure the whole string before dividing the length by 2 to get the low-res width of the string. Before, each character width was divided which led to rounding errors. The result is better, but not pixel perfect. I'm not sure what I'm still getting wrong. --- engines/scumm/charset.cpp | 21 ++++++++++++++++++++- engines/scumm/charset.h | 3 ++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/engines/scumm/charset.cpp b/engines/scumm/charset.cpp index 21816ed932a..e9e2698f099 100644 --- a/engines/scumm/charset.cpp +++ b/engines/scumm/charset.cpp @@ -538,7 +538,7 @@ int CharsetRenderer::getStringWidth(int arg, const byte *text, uint strLenMax) { if (arg == 1) break; while (text[pos++] == ' ') - ; + ; continue; } if (chr == 10 || chr == 21 || chr == 12 || chr == 13) { @@ -1666,6 +1666,25 @@ void CharsetRendererMac::setCurID(int32 id) { _curId = id; } +int CharsetRendererMac::getStringWidth(int arg, const byte *text, uint strLenMax) { + int pos = 0; + int width = 0; + int chr; + + while ((chr = text[pos++]) != 0) { + // The only control codes I've seen in use are line breaks in + // Loom. In Indy 3, I haven't seen anything at all like it. + if (chr == 255) { + chr = text[pos++]; + if (chr == 1) // 'Newline' + break; + } + width += _macFonts[_curId].getCharWidth(chr); + } + + return width / 2; +} + // HACK: Usually, we want the approximate width and height in the unscaled // graphics resolution. But for font 1 in Indiana Jones and the Last // crusade we want the actual dimensions for drawing the text boxes. diff --git a/engines/scumm/charset.h b/engines/scumm/charset.h index e4c781d5e8f..e5e6aab97ce 100644 --- a/engines/scumm/charset.h +++ b/engines/scumm/charset.h @@ -97,7 +97,7 @@ public: virtual void printChar(int chr, bool ignoreCharsetMask) = 0; virtual void drawChar(int chr, Graphics::Surface &s, int x, int y) {} - int getStringWidth(int a, const byte *str, uint strLenMax = 100000); + virtual int getStringWidth(int arg, const byte *text, uint strLenMax = 100000); void addLinebreaks(int a, byte *str, int pos, int maxwidth); void translateColor(); @@ -294,6 +294,7 @@ public: ~CharsetRendererMac() override; void setCurID(int32 id) override; + int getStringWidth(int arg, const byte *text, uint strLenMax = 100000); int getFontHeight() override; int getCharWidth(uint16 chr) override; void printChar(int chr, bool ignoreCharsetMask) override;