aboutsummaryrefslogtreecommitdiff
path: root/graphics/font.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/font.cpp')
-rw-r--r--graphics/font.cpp34
1 files changed, 33 insertions, 1 deletions
diff --git a/graphics/font.cpp b/graphics/font.cpp
index dba48249bc..7768b7362d 100644
--- a/graphics/font.cpp
+++ b/graphics/font.cpp
@@ -21,6 +21,7 @@
*/
#include "graphics/font.h"
+#include "graphics/managed_surface.h"
#include "common/array.h"
#include "common/util.h"
@@ -163,7 +164,16 @@ int wordWrapTextImpl(const Font &font, const StringType &str, int maxWidth, Comm
typename StringType::unsigned_type last = 0;
for (typename StringType::const_iterator x = str.begin(); x != str.end(); ++x) {
- const typename StringType::unsigned_type c = *x;
+ typename StringType::unsigned_type c = *x;
+
+ // Convert Windows and Mac line breaks into plain \n
+ if (c == '\r') {
+ if (x != str.end() && *(x + 1) == '\n') {
+ ++x;
+ }
+ c = '\n';
+ }
+
const int w = font.getCharWidth(c) + font.getKerningOffset(last, c);
last = c;
const bool wouldExceedWidth = (lineWidth + tmpWidth + w > maxWidth);
@@ -264,6 +274,14 @@ int Font::getStringWidth(const Common::U32String &str) const {
return getStringWidthImpl(*this, str);
}
+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);
+}
+
void Font::drawString(Surface *dst, const Common::String &str, int x, int y, int w, uint32 color, TextAlign align, int deltax, bool useEllipsis) const {
Common::String renderStr = useEllipsis ? handleEllipsis(str, w) : str;
drawStringImpl(*this, dst, renderStr, x, y, w, color, align, deltax);
@@ -273,6 +291,20 @@ void Font::drawString(Surface *dst, const Common::U32String &str, int x, int y,
drawStringImpl(*this, dst, str, x, y, w, color, align, 0);
}
+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);
+ if (w != 0) {
+ dst->addDirtyRect(getBoundingBox(str, x, y, w, align, deltax, useEllipsis));
+ }
+}
+
+void Font::drawString(ManagedSurface *dst, const Common::U32String &str, int x, int y, int w, uint32 color, TextAlign align) const {
+ drawString(&dst->_innerSurface, str, x, y, w, color, align);
+ if (w != 0) {
+ dst->addDirtyRect(getBoundingBox(str, x, y, w, align));
+ }
+}
+
int Font::wordWrapText(const Common::String &str, int maxWidth, Common::Array<Common::String> &lines) const {
return wordWrapTextImpl(*this, str, maxWidth, lines);
}