2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2004-03-13 13:03:25 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2014-02-18 01:34:20 +00:00
|
|
|
*
|
2004-03-13 13:03:25 +00:00
|
|
|
*/
|
|
|
|
|
2011-07-01 19:10:25 +00:00
|
|
|
#include "graphics/font.h"
|
2016-03-11 02:49:42 +00:00
|
|
|
#include "graphics/managed_surface.h"
|
2011-07-01 19:10:25 +00:00
|
|
|
|
2011-04-24 08:34:27 +00:00
|
|
|
#include "common/array.h"
|
|
|
|
#include "common/util.h"
|
2003-11-19 23:46:39 +00:00
|
|
|
|
2004-03-21 21:20:25 +00:00
|
|
|
namespace Graphics {
|
2003-11-19 23:46:39 +00:00
|
|
|
|
2013-11-23 20:34:54 +00:00
|
|
|
int Font::getKerningOffset(uint32 left, uint32 right) const {
|
2012-01-08 01:33:34 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-06-09 16:54:49 +00:00
|
|
|
Common::Rect Font::getBoundingBox(uint32 chr) const {
|
|
|
|
return Common::Rect(getCharWidth(chr), getFontHeight());
|
|
|
|
}
|
|
|
|
|
2013-11-23 20:34:54 +00:00
|
|
|
namespace {
|
|
|
|
|
2014-06-09 16:54:49 +00:00
|
|
|
template<class StringType>
|
|
|
|
Common::Rect getBoundingBoxImpl(const Font &font, const StringType &str, int x, int y, int w, TextAlign align, int deltax) {
|
|
|
|
// We follow the logic of drawStringImpl here. The only exception is
|
|
|
|
// that we do allow an empty width to be specified here. This allows us
|
|
|
|
// to obtain the complete bounding box of a string.
|
2020-06-08 13:53:14 +00:00
|
|
|
const int leftX = x, rightX = w ? (x + w + 1) : 0x7FFFFFFF;
|
2014-06-09 16:54:49 +00:00
|
|
|
int width = font.getStringWidth(str);
|
|
|
|
|
|
|
|
if (align == kTextAlignCenter)
|
|
|
|
x = x + (w - width)/2;
|
|
|
|
else if (align == kTextAlignRight)
|
|
|
|
x = x + w - width;
|
|
|
|
x += deltax;
|
|
|
|
|
|
|
|
bool first = true;
|
|
|
|
Common::Rect bbox;
|
|
|
|
|
|
|
|
typename StringType::unsigned_type last = 0;
|
|
|
|
for (typename StringType::const_iterator i = str.begin(), end = str.end(); i != end; ++i) {
|
|
|
|
const typename StringType::unsigned_type cur = *i;
|
|
|
|
x += font.getKerningOffset(last, cur);
|
|
|
|
last = cur;
|
2018-08-02 05:09:26 +00:00
|
|
|
|
|
|
|
Common::Rect charBox = font.getBoundingBox(cur);
|
|
|
|
if (x + charBox.right > rightX)
|
2014-06-09 16:54:49 +00:00
|
|
|
break;
|
2018-08-02 05:09:26 +00:00
|
|
|
if (x + charBox.right >= leftX) {
|
2014-06-09 16:54:49 +00:00
|
|
|
charBox.translate(x, y);
|
|
|
|
if (first) {
|
|
|
|
bbox = charBox;
|
|
|
|
first = false;
|
|
|
|
} else {
|
|
|
|
bbox.extend(charBox);
|
|
|
|
}
|
|
|
|
}
|
2018-08-02 05:09:26 +00:00
|
|
|
|
|
|
|
x += font.getCharWidth(cur);
|
2014-06-09 16:54:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return bbox;
|
|
|
|
}
|
|
|
|
|
2013-11-23 20:34:54 +00:00
|
|
|
template<class StringType>
|
|
|
|
int getStringWidthImpl(const Font &font, const StringType &str) {
|
2004-03-13 13:03:25 +00:00
|
|
|
int space = 0;
|
2013-11-23 20:34:54 +00:00
|
|
|
typename StringType::unsigned_type last = 0;
|
2012-01-08 01:33:34 +00:00
|
|
|
|
|
|
|
for (uint i = 0; i < str.size(); ++i) {
|
2013-11-23 20:34:54 +00:00
|
|
|
const typename StringType::unsigned_type cur = str[i];
|
|
|
|
space += font.getCharWidth(cur) + font.getKerningOffset(last, cur);
|
2012-01-08 01:33:34 +00:00
|
|
|
last = cur;
|
|
|
|
}
|
2004-03-13 13:03:25 +00:00
|
|
|
|
|
|
|
return space;
|
|
|
|
}
|
|
|
|
|
2013-11-23 20:34:54 +00:00
|
|
|
template<class StringType>
|
|
|
|
void drawStringImpl(const Font &font, Surface *dst, const StringType &str, int x, int y, int w, uint32 color, TextAlign align, int deltax) {
|
2014-06-09 16:54:49 +00:00
|
|
|
// The logic in getBoundingImpl is the same as we use here. In case we
|
|
|
|
// ever change something here we will need to change it there too.
|
2004-03-13 13:03:25 +00:00
|
|
|
assert(dst != 0);
|
2005-01-06 19:09:34 +00:00
|
|
|
|
2020-06-08 13:53:14 +00:00
|
|
|
const int leftX = x, rightX = x + w + 1;
|
2013-11-23 20:34:54 +00:00
|
|
|
int width = font.getStringWidth(str);
|
2004-03-13 13:03:25 +00:00
|
|
|
|
|
|
|
if (align == kTextAlignCenter)
|
2008-11-05 14:47:06 +00:00
|
|
|
x = x + (w - width)/2;
|
2004-03-13 13:03:25 +00:00
|
|
|
else if (align == kTextAlignRight)
|
|
|
|
x = x + w - width;
|
|
|
|
x += deltax;
|
|
|
|
|
2013-11-23 20:34:54 +00:00
|
|
|
typename StringType::unsigned_type last = 0;
|
|
|
|
for (typename StringType::const_iterator i = str.begin(), end = str.end(); i != end; ++i) {
|
|
|
|
const typename StringType::unsigned_type cur = *i;
|
|
|
|
x += font.getKerningOffset(last, cur);
|
2012-01-08 01:33:34 +00:00
|
|
|
last = cur;
|
2018-08-02 05:09:26 +00:00
|
|
|
|
|
|
|
Common::Rect charBox = font.getBoundingBox(cur);
|
|
|
|
if (x + charBox.right > rightX)
|
2004-03-13 13:03:25 +00:00
|
|
|
break;
|
2018-08-02 05:09:26 +00:00
|
|
|
if (x + charBox.right >= leftX)
|
2013-11-23 20:34:54 +00:00
|
|
|
font.drawChar(dst, cur, x, y, color);
|
2018-08-02 05:09:26 +00:00
|
|
|
|
|
|
|
x += font.getCharWidth(cur);
|
2004-03-13 13:03:25 +00:00
|
|
|
}
|
|
|
|
}
|
2003-11-19 23:46:39 +00:00
|
|
|
|
2013-11-23 20:34:54 +00:00
|
|
|
template<class StringType>
|
2005-05-15 16:13:52 +00:00
|
|
|
struct WordWrapper {
|
2013-11-23 20:34:54 +00:00
|
|
|
Common::Array<StringType> &lines;
|
2005-05-15 16:13:52 +00:00
|
|
|
int actualMaxLineWidth;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2013-11-23 20:34:54 +00:00
|
|
|
WordWrapper(Common::Array<StringType> &l) : lines(l), actualMaxLineWidth(0) {
|
2005-05-15 16:13:52 +00:00
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2013-11-23 20:34:54 +00:00
|
|
|
void add(StringType &line, int &w) {
|
2005-05-15 16:13:52 +00:00
|
|
|
if (actualMaxLineWidth < w)
|
|
|
|
actualMaxLineWidth = w;
|
|
|
|
|
|
|
|
lines.push_back(line);
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-05-15 16:13:52 +00:00
|
|
|
line.clear();
|
|
|
|
w = 0;
|
|
|
|
}
|
2019-07-21 19:42:09 +00:00
|
|
|
|
|
|
|
void clear() {
|
|
|
|
lines.clear();
|
|
|
|
actualMaxLineWidth = 0;
|
|
|
|
}
|
2005-05-15 16:13:52 +00:00
|
|
|
};
|
|
|
|
|
2013-11-23 20:34:54 +00:00
|
|
|
template<class StringType>
|
2019-07-21 19:42:09 +00:00
|
|
|
int wordWrapTextImpl(const Font &font, const StringType &str, int maxWidth, Common::Array<StringType> &lines, int initWidth, bool evenWidthLinesModeEnabled, bool wrapOnExplicitNewLines) {
|
2013-11-23 20:34:54 +00:00
|
|
|
WordWrapper<StringType> wrapper(lines);
|
|
|
|
StringType line;
|
|
|
|
StringType tmpStr;
|
2017-01-29 17:40:36 +00:00
|
|
|
int lineWidth = initWidth;
|
2005-05-15 16:13:52 +00:00
|
|
|
int tmpWidth = 0;
|
2019-07-21 19:42:09 +00:00
|
|
|
int fullTextWidthEWL = initWidth; // this replaces new line characters (if any) with single spaces - it is used in Even Width Lines mode
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-05-15 16:13:52 +00:00
|
|
|
// The rough idea behind this algorithm is as follows:
|
|
|
|
// We accumulate characters into the string tmpStr. Whenever a full word
|
|
|
|
// has been gathered together this way, we 'commit' it to the line buffer
|
|
|
|
// 'line', i.e. we add tmpStr to the end of line, then clear it. Before
|
|
|
|
// we do that, we check whether it would cause 'line' to exceed maxWidth;
|
|
|
|
// in that case, we first add line to lines, then reset it.
|
|
|
|
//
|
|
|
|
// If a newline character is read, then we also add line to lines and clear it.
|
|
|
|
//
|
|
|
|
// Special care has to be taken to account for 'words' that exceed the width
|
|
|
|
// of a line. If we encounter such a word, we have to wrap it over multiple
|
|
|
|
// lines.
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2013-11-23 20:34:54 +00:00
|
|
|
typename StringType::unsigned_type last = 0;
|
2016-09-05 16:41:40 +00:00
|
|
|
|
2019-07-21 19:42:09 +00:00
|
|
|
// When EvenWidthLines mode is enabled then we require an early loop over the entire string
|
|
|
|
// in order to get the full width of the text
|
|
|
|
//
|
|
|
|
// "Wrap On Explicit New Lines" and "Even Width Lines" modes are mutually exclusive,
|
|
|
|
// If both are set to true and there are new line characters in the text,
|
|
|
|
// then "Even Width Lines" mode is disabled.
|
|
|
|
//
|
|
|
|
if (evenWidthLinesModeEnabled) {
|
|
|
|
// Early loop to get the full width of the text
|
|
|
|
for (typename StringType::const_iterator x = str.begin(); x != str.end(); ++x) {
|
|
|
|
typename StringType::unsigned_type c = *x;
|
|
|
|
|
|
|
|
// Check for Windows and Mac line breaks
|
|
|
|
if (c == '\r') {
|
|
|
|
if (x != str.end() && *(x + 1) == '\n') {
|
|
|
|
++x;
|
|
|
|
}
|
|
|
|
c = '\n';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c == '\n') {
|
|
|
|
if (!wrapOnExplicitNewLines) {
|
|
|
|
c = ' ';
|
|
|
|
} else {
|
|
|
|
evenWidthLinesModeEnabled = false;
|
|
|
|
break;
|
|
|
|
}
|
2016-09-05 16:41:40 +00:00
|
|
|
}
|
2019-07-21 19:42:09 +00:00
|
|
|
|
|
|
|
const int w = font.getCharWidth(c) + font.getKerningOffset(last, c);
|
|
|
|
last = c;
|
|
|
|
fullTextWidthEWL += w;
|
2016-09-05 16:41:40 +00:00
|
|
|
}
|
2019-07-21 19:42:09 +00:00
|
|
|
}
|
2016-09-05 16:41:40 +00:00
|
|
|
|
2019-07-21 19:42:09 +00:00
|
|
|
int targetTotalLinesNumberEWL = 0;
|
|
|
|
int targetMaxLineWidth = 0;
|
|
|
|
do {
|
|
|
|
if (evenWidthLinesModeEnabled) {
|
|
|
|
wrapper.clear();
|
|
|
|
targetTotalLinesNumberEWL += 1;
|
|
|
|
// We add +2 to the fullTextWidthEWL to account for possible shadow pixels
|
|
|
|
// We add +10 * font.getCharWidth(' ') to the quotient since we want to allow some extra margin (about an extra wprd's length)
|
|
|
|
// since that yields better looking results
|
|
|
|
targetMaxLineWidth = ((fullTextWidthEWL + 2) / targetTotalLinesNumberEWL) + 10 * font.getCharWidth(' ');
|
|
|
|
if (targetMaxLineWidth > maxWidth) {
|
|
|
|
// repeat the loop with increased targetTotalLinesNumberEWL
|
2005-05-17 23:14:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
2019-07-21 19:42:09 +00:00
|
|
|
} else {
|
|
|
|
targetMaxLineWidth = maxWidth;
|
2005-05-15 16:13:52 +00:00
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2019-07-21 19:42:09 +00:00
|
|
|
last = 0;
|
|
|
|
tmpWidth = 0;
|
|
|
|
|
|
|
|
for (typename StringType::const_iterator x = str.begin(); x != str.end(); ++x) {
|
|
|
|
typename StringType::unsigned_type c = *x;
|
2018-07-29 09:56:21 +00:00
|
|
|
|
2019-07-21 19:42:09 +00:00
|
|
|
// Convert Windows and Mac line breaks into plain \n
|
|
|
|
if (c == '\r') {
|
|
|
|
if (x != str.end() && *(x + 1) == '\n') {
|
|
|
|
++x;
|
|
|
|
}
|
|
|
|
c = '\n';
|
|
|
|
}
|
|
|
|
// if wrapping on explicit new lines is disabled, then new line characters should be treated as a single white space char
|
|
|
|
if (!wrapOnExplicitNewLines && c == '\n') {
|
|
|
|
c = ' ';
|
|
|
|
}
|
2018-07-29 09:56:21 +00:00
|
|
|
|
2019-07-21 19:42:09 +00:00
|
|
|
const int currentCharWidth = font.getCharWidth(c);
|
|
|
|
const int w = currentCharWidth + font.getKerningOffset(last, c);
|
|
|
|
last = c;
|
|
|
|
const bool wouldExceedWidth = (lineWidth + tmpWidth + w > targetMaxLineWidth);
|
|
|
|
|
|
|
|
// If this char is a whitespace, then it represents a potential
|
|
|
|
// 'wrap point' where wrapping could take place. Everything that
|
|
|
|
// came before it can now safely be added to the line, as we know
|
|
|
|
// that it will not have to be wrapped.
|
|
|
|
if (Common::isSpace(c)) {
|
|
|
|
line += tmpStr;
|
|
|
|
lineWidth += tmpWidth;
|
|
|
|
|
|
|
|
tmpStr.clear();
|
|
|
|
tmpWidth = 0;
|
|
|
|
|
|
|
|
// If we encounter a line break (\n), or if the new space would
|
|
|
|
// cause the line to overflow: start a new line
|
|
|
|
if ((wrapOnExplicitNewLines && c == '\n') || wouldExceedWidth) {
|
|
|
|
wrapper.add(line, lineWidth);
|
2018-07-29 09:56:21 +00:00
|
|
|
continue;
|
|
|
|
}
|
2005-05-15 16:13:52 +00:00
|
|
|
}
|
|
|
|
|
2019-07-21 19:42:09 +00:00
|
|
|
// If the max line width would be exceeded by adding this char,
|
|
|
|
// insert a line break.
|
|
|
|
if (wouldExceedWidth) {
|
|
|
|
// Commit what we have so far, *if* we have anything.
|
|
|
|
// If line is empty, then we are looking at a word
|
|
|
|
// which exceeds the maximum line width.
|
|
|
|
if (lineWidth > 0) {
|
|
|
|
wrapper.add(line, lineWidth);
|
|
|
|
// Trim left side
|
|
|
|
while (tmpStr.size() && Common::isSpace(tmpStr[0])) {
|
|
|
|
tmpStr.deleteChar(0);
|
|
|
|
// This is not very fast, but it is the simplest way to
|
|
|
|
// assure we do not mess something up because of kerning.
|
|
|
|
tmpWidth = font.getStringWidth(tmpStr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tmpStr.empty()) {
|
|
|
|
// If tmpStr is empty, we might have removed the space before 'c'.
|
|
|
|
// That means we have to recompute the kerning.
|
|
|
|
|
|
|
|
tmpWidth += currentCharWidth + font.getKerningOffset(0, c);
|
|
|
|
tmpStr += c;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
wrapper.add(tmpStr, tmpWidth);
|
|
|
|
}
|
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2019-07-21 19:42:09 +00:00
|
|
|
tmpWidth += w;
|
|
|
|
tmpStr += c;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If some text is left over, add it as the final line
|
|
|
|
line += tmpStr;
|
|
|
|
lineWidth += tmpWidth;
|
|
|
|
if (lineWidth > 0) {
|
|
|
|
wrapper.add(line, lineWidth);
|
|
|
|
}
|
|
|
|
} while (evenWidthLinesModeEnabled
|
|
|
|
&& (targetMaxLineWidth > maxWidth));
|
2017-01-17 11:14:58 +00:00
|
|
|
return wrapper.actualMaxLineWidth;
|
2005-05-15 16:13:52 +00:00
|
|
|
}
|
|
|
|
|
2020-06-13 16:41:03 +00:00
|
|
|
template<typename StringType>
|
|
|
|
StringType handleEllipsis(const Font &font, const StringType &input, int w) {
|
|
|
|
StringType s = input;
|
|
|
|
int width = font.getStringWidth(s);
|
|
|
|
bool hasEllipsisAtEnd = false;
|
|
|
|
|
|
|
|
if (s.size() > 3 && s[s.size() - 1] == '.' && s[s.size() - 2] == '.' && s[s.size() - 3] == '.') {
|
|
|
|
hasEllipsisAtEnd = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (width > w && hasEllipsisAtEnd) {
|
|
|
|
// String is too wide. Check whether it ends in an ellipsis
|
|
|
|
// ("..."). If so, remove that and try again!
|
|
|
|
s.deleteLastChar();
|
|
|
|
s.deleteLastChar();
|
|
|
|
s.deleteLastChar();
|
|
|
|
width = font.getStringWidth(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (width > w) {
|
|
|
|
StringType str;
|
|
|
|
StringType ellipsis("...");
|
|
|
|
|
|
|
|
// String is too wide. So we shorten it "intelligently" by
|
|
|
|
// replacing parts of the string 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 seems to be 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;
|
2020-06-27 15:45:53 +00:00
|
|
|
typename StringType::unsigned_type last = 0;
|
2020-06-13 16:41:03 +00:00
|
|
|
uint i = 0;
|
|
|
|
|
|
|
|
for (; i < s.size(); ++i) {
|
2020-06-27 15:45:53 +00:00
|
|
|
const typename StringType::unsigned_type cur = s[i];
|
2020-06-13 16:41:03 +00:00
|
|
|
int charWidth = font.getCharWidth(cur) + font.getKerningOffset(last, cur);
|
|
|
|
if (w2 + charWidth > halfWidth)
|
|
|
|
break;
|
|
|
|
last = cur;
|
|
|
|
w2 += charWidth;
|
|
|
|
str += cur;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
last = '.';
|
|
|
|
|
|
|
|
// 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 accommodate 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) {
|
2020-06-27 15:45:53 +00:00
|
|
|
const typename StringType::unsigned_type cur = s[i];
|
2020-06-13 16:41:03 +00:00
|
|
|
skip -= font.getCharWidth(cur) + font.getKerningOffset(last, cur);
|
|
|
|
last = cur;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Append the remaining chars, if any
|
|
|
|
for (; i < s.size(); ++i) {
|
|
|
|
str += s[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2013-11-23 20:34:54 +00:00
|
|
|
} // End of anonymous namespace
|
|
|
|
|
2014-06-09 16:54:49 +00:00
|
|
|
Common::Rect Font::getBoundingBox(const Common::String &input, int x, int y, const int w, TextAlign align, int deltax, bool useEllipsis) const {
|
|
|
|
// In case no width was given we cannot use ellipsis or any alignment
|
|
|
|
// apart from left alignment.
|
|
|
|
if (w == 0) {
|
|
|
|
if (useEllipsis) {
|
|
|
|
warning("Font::getBoundingBox: Requested ellipsis when no width was specified");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (align != kTextAlignLeft) {
|
|
|
|
warning("Font::getBoundingBox: Requested text alignment when no width was specified");
|
|
|
|
}
|
|
|
|
|
|
|
|
useEllipsis = false;
|
|
|
|
align = kTextAlignLeft;
|
|
|
|
}
|
|
|
|
|
2020-06-13 16:41:03 +00:00
|
|
|
const Common::String str = useEllipsis ? handleEllipsis(*this, input, w) : input;
|
2014-06-09 16:54:49 +00:00
|
|
|
return getBoundingBoxImpl(*this, str, x, y, w, align, deltax);
|
|
|
|
}
|
|
|
|
|
2020-06-11 19:34:38 +00:00
|
|
|
Common::Rect Font::getBoundingBox(const Common::U32String &input, int x, int y, const int w, TextAlign align, int deltax, bool useEllipsis) const {
|
2014-06-09 16:54:49 +00:00
|
|
|
// In case no width was given we cannot any alignment apart from left
|
|
|
|
// alignment.
|
|
|
|
if (w == 0) {
|
2020-06-11 19:34:38 +00:00
|
|
|
if (useEllipsis) {
|
|
|
|
warning("Font::getBoundingBox: Requested ellipsis when no width was specified");
|
|
|
|
}
|
|
|
|
|
2014-06-09 16:54:49 +00:00
|
|
|
if (align != kTextAlignLeft) {
|
|
|
|
warning("Font::getBoundingBox: Requested text alignment when no width was specified");
|
|
|
|
}
|
|
|
|
|
2020-06-11 19:34:38 +00:00
|
|
|
useEllipsis = false;
|
2014-06-09 16:54:49 +00:00
|
|
|
align = kTextAlignLeft;
|
|
|
|
}
|
|
|
|
|
2020-06-13 16:41:03 +00:00
|
|
|
const Common::U32String str = useEllipsis ? handleEllipsis(*this, input, w) : input;
|
2014-06-09 16:54:49 +00:00
|
|
|
return getBoundingBoxImpl(*this, str, x, y, w, align, 0);
|
|
|
|
}
|
|
|
|
|
2013-11-23 20:34:54 +00:00
|
|
|
int Font::getStringWidth(const Common::String &str) const {
|
|
|
|
return getStringWidthImpl(*this, str);
|
|
|
|
}
|
|
|
|
|
|
|
|
int Font::getStringWidth(const Common::U32String &str) const {
|
|
|
|
return getStringWidthImpl(*this, str);
|
|
|
|
}
|
|
|
|
|
2016-03-20 20:38:26 +00:00
|
|
|
void Font::drawChar(ManagedSurface *dst, uint32 chr, int x, int y, uint32 color) const {
|
|
|
|
drawChar(&dst->_innerSurface, chr, x, y, color);
|
|
|
|
|
|
|
|
Common::Rect charBox = getBoundingBox(chr);
|
|
|
|
charBox.translate(x, y);
|
|
|
|
dst->addDirtyRect(charBox);
|
|
|
|
}
|
|
|
|
|
2014-06-09 16:54:49 +00:00
|
|
|
void Font::drawString(Surface *dst, const Common::String &str, int x, int y, int w, uint32 color, TextAlign align, int deltax, bool useEllipsis) const {
|
2020-06-13 16:41:03 +00:00
|
|
|
Common::String renderStr = useEllipsis ? handleEllipsis(*this, str, w) : str;
|
2014-06-09 16:54:49 +00:00
|
|
|
drawStringImpl(*this, dst, renderStr, x, y, w, color, align, deltax);
|
|
|
|
}
|
|
|
|
|
2020-06-11 19:34:38 +00:00
|
|
|
void Font::drawString(Surface *dst, const Common::U32String &str, int x, int y, int w, uint32 color, TextAlign align, int deltax, bool useEllipsis) const {
|
2020-06-13 16:41:03 +00:00
|
|
|
Common::U32String renderStr = useEllipsis ? handleEllipsis(*this, str, w) : str;
|
2020-06-11 19:34:38 +00:00
|
|
|
drawStringImpl(*this, dst, renderStr, x, y, w, color, align, deltax);
|
2014-06-09 16:54:49 +00:00
|
|
|
}
|
|
|
|
|
2016-03-11 02:49:42 +00:00
|
|
|
void Font::drawString(ManagedSurface *dst, const Common::String &str, int x, int y, int w, uint32 color, TextAlign align, int deltax, bool useEllipsis) const {
|
|
|
|
drawString(&dst->_innerSurface, str, x, y, w, color, align, deltax, useEllipsis);
|
2016-03-20 18:57:42 +00:00
|
|
|
if (w != 0) {
|
2016-03-20 19:01:52 +00:00
|
|
|
dst->addDirtyRect(getBoundingBox(str, x, y, w, align, deltax, useEllipsis));
|
2016-03-20 18:57:42 +00:00
|
|
|
}
|
2016-03-11 02:49:42 +00:00
|
|
|
}
|
|
|
|
|
2020-06-11 19:34:38 +00:00
|
|
|
void Font::drawString(ManagedSurface *dst, const Common::U32String &str, int x, int y, int w, uint32 color, TextAlign align, int deltax, bool useEllipsis) const {
|
|
|
|
drawString(&dst->_innerSurface, str, x, y, w, color, align, deltax, useEllipsis);
|
2016-03-20 18:57:42 +00:00
|
|
|
if (w != 0) {
|
2020-06-11 19:34:38 +00:00
|
|
|
dst->addDirtyRect(getBoundingBox(str, x, y, w, align, useEllipsis));
|
2016-03-20 18:57:42 +00:00
|
|
|
}
|
2016-03-11 02:49:42 +00:00
|
|
|
}
|
|
|
|
|
2019-07-21 19:42:09 +00:00
|
|
|
int Font::wordWrapText(const Common::String &str, int maxWidth, Common::Array<Common::String> &lines, int initWidth, bool evenWidthLinesModeEnabled, bool wrapOnExplicitNewLines) const {
|
|
|
|
return wordWrapTextImpl(*this, str, maxWidth, lines, initWidth, evenWidthLinesModeEnabled, wrapOnExplicitNewLines);
|
2014-06-09 16:54:49 +00:00
|
|
|
}
|
|
|
|
|
2019-07-21 19:42:09 +00:00
|
|
|
int Font::wordWrapText(const Common::U32String &str, int maxWidth, Common::Array<Common::U32String> &lines, int initWidth, bool evenWidthLinesModeEnabled, bool wrapOnExplicitNewLines) const {
|
|
|
|
return wordWrapTextImpl(*this, str, maxWidth, lines, initWidth, evenWidthLinesModeEnabled, wrapOnExplicitNewLines);
|
2014-06-09 16:54:49 +00:00
|
|
|
}
|
|
|
|
|
2020-06-21 21:22:56 +00:00
|
|
|
TextAlign convertTextAlignH(TextAlign alignH, bool rtl) {
|
|
|
|
switch (alignH) {
|
|
|
|
case kTextAlignStart:
|
|
|
|
return rtl ? kTextAlignRight : kTextAlignLeft;
|
|
|
|
case kTextAlignEnd:
|
|
|
|
return rtl ? kTextAlignLeft : kTextAlignRight;
|
|
|
|
default:
|
|
|
|
return alignH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-21 21:20:25 +00:00
|
|
|
} // End of namespace Graphics
|