From 43be89f12456a9b9380e1831e95ede9a695780bd Mon Sep 17 00:00:00 2001 From: thrust26 Date: Tue, 16 Jan 2018 18:16:56 +0100 Subject: [PATCH] when strings are shortened, ellipsis is added at the END now --- src/emucore/FBSurface.cxx | 31 +++++-------------------------- 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/src/emucore/FBSurface.cxx b/src/emucore/FBSurface.cxx index 32e751997..f0678f1ee 100644 --- a/src/emucore/FBSurface.cxx +++ b/src/emucore/FBSurface.cxx @@ -320,43 +320,22 @@ void FBSurface::drawString(const GUI::Font& font, const string& s, // String is too wide. So we shorten it "intelligently", by replacing // parts of it by an ellipsis ("..."). There are three possibilities // for this: replace the start, the end, or the middle of the string. - // What is best really depends on the context; but unless we want to - // make this configurable, replacing the middle probably is a good - // compromise. - const int ellipsisWidth = font.getStringWidth(ELLIPSIS); - - // SLOW algorithm to remove enough of the middle. But it is good enough for now. - const int halfWidth = (w - ellipsisWidth) / 2; - int w2 = 0; + // What is best really depends on the context; but most applications + // replace the end. So we use that too. + int w2 = font.getStringWidth(ELLIPSIS); + // SLOW algorithm to find the acceptable length. But it is good enough for now. for(i = 0; i < s.size(); ++i) { int charWidth = font.getCharWidth(s[i]); - if(w2 + charWidth > halfWidth) + if(w2 + charWidth > w) break; w2 += charWidth; str += s[i]; } - - // At this point we know that the first 'i' chars are together 'w2' - // pixels wide. We took the first i-1, and add "..." to them. str += ELLIPSIS; - // The original string is width wide. Of those we already skipped past - // w2 pixels, which means (width - w2) remain. - // The new str is (w2+ellipsisWidth) wide, so we can accomodate about - // (w - (w2+ellipsisWidth)) more pixels. - // Thus we skip ((width - w2) - (w - (w2+ellipsisWidth))) = - // (width + ellipsisWidth - w) - int skip = width + ellipsisWidth - w; - for(; i < s.size() && skip > 0; ++i) - skip -= font.getCharWidth(s[i]); - - // Append the remaining chars, if any - for(; i < s.size(); ++i) - str += s[i]; - width = font.getStringWidth(str); } else