[Scummvm-cvs-logs] scummvm master -> 15154641ac5ea674a4865d9478074cf1b1d8a36b
bluegr
bluegr at gmail.com
Tue Dec 23 00:54:45 CET 2014
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
15154641ac ZVISION: Move all of the text related code together
Commit: 15154641ac5ea674a4865d9478074cf1b1d8a36b
https://github.com/scummvm/scummvm/commit/15154641ac5ea674a4865d9478074cf1b1d8a36b
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2014-12-23T01:53:40+02:00
Commit Message:
ZVISION: Move all of the text related code together
Changed paths:
A engines/zvision/text/subtitles.cpp
A engines/zvision/text/subtitles.h
A engines/zvision/text/truetype_font.cpp
A engines/zvision/text/truetype_font.h
R engines/zvision/graphics/subtitles.cpp
R engines/zvision/graphics/subtitles.h
R engines/zvision/graphics/truetype_font.cpp
R engines/zvision/graphics/truetype_font.h
engines/zvision/graphics/render_manager.h
engines/zvision/module.mk
engines/zvision/scripting/sidefx/music_node.h
engines/zvision/scripting/sidefx/syncsound_node.h
engines/zvision/scripting/sidefx/ttytext_node.h
engines/zvision/text/string_manager.h
engines/zvision/text/text.cpp
engines/zvision/text/text.h
engines/zvision/video/video.cpp
engines/zvision/zvision.cpp
diff --git a/engines/zvision/graphics/render_manager.h b/engines/zvision/graphics/render_manager.h
index 29bbd8f..711c607 100644
--- a/engines/zvision/graphics/render_manager.h
+++ b/engines/zvision/graphics/render_manager.h
@@ -24,7 +24,7 @@
#define ZVISION_RENDER_MANAGER_H
#include "zvision/graphics/render_table.h"
-#include "zvision/graphics/truetype_font.h"
+#include "zvision/text/truetype_font.h"
#include "common/rect.h"
#include "common/hashmap.h"
diff --git a/engines/zvision/graphics/subtitles.cpp b/engines/zvision/graphics/subtitles.cpp
deleted file mode 100644
index d2c56f0..0000000
--- a/engines/zvision/graphics/subtitles.cpp
+++ /dev/null
@@ -1,108 +0,0 @@
-/* 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.
- *
- * 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
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#include "zvision/graphics/render_manager.h"
-#include "zvision/graphics/subtitles.h"
-#include "zvision/file/search_manager.h"
-#include "zvision/text/text.h"
-
-namespace ZVision {
-
-Subtitle::Subtitle(ZVision *engine, const Common::String &subname) :
- _engine(engine),
- _areaId(-1),
- _subId(-1) {
- Common::File file;
- if (_engine->getSearchManager()->openFile(file, subname)) {
- while (!file.eos()) {
- Common::String str = file.readLine();
- if (str.lastChar() == '~')
- str.deleteLastChar();
-
- if (str.matchString("*Initialization*", true)) {
- // Not used
- } else if (str.matchString("*Rectangle*", true)) {
- int32 x1, y1, x2, y2;
- sscanf(str.c_str(), "%*[^:]:%d %d %d %d", &x1, &y1, &x2, &y2);
- Common::Rect rct = Common::Rect(x1, y1, x2, y2);
- _areaId = _engine->getRenderManager()->createSubArea(rct);
- } else if (str.matchString("*TextFile*", true)) {
- char filename[64];
- sscanf(str.c_str(), "%*[^:]:%s", filename);
- Common::File txt;
- if (_engine->getSearchManager()->openFile(txt, filename)) {
- while (!txt.eos()) {
- Common::String txtline = readWideLine(txt);
- sub curSubtitle;
- curSubtitle.start = -1;
- curSubtitle.stop = -1;
- curSubtitle.subStr = txtline;
-
- _subs.push_back(curSubtitle);
- }
- txt.close();
- }
- } else {
- int32 st;
- int32 en;
- int32 sb;
- if (sscanf(str.c_str(), "%*[^:]:(%d,%d)=%d", &st, &en, &sb) == 3) {
- if (sb <= (int32)_subs.size()) {
- _subs[sb].start = st;
- _subs[sb].stop = en;
- }
- }
- }
- }
- }
-}
-
-Subtitle::~Subtitle() {
- if (_areaId != -1)
- _engine->getRenderManager()->deleteSubArea(_areaId);
-
- _subs.clear();
-}
-
-void Subtitle::process(int32 time) {
- int16 j = -1;
- for (uint16 i = 0; i < _subs.size(); i++)
- if (time >= _subs[i].start && time <= _subs[i].stop) {
- j = i;
- break;
- }
-
- if (j == -1 && _subId != -1) {
- if (_areaId != -1)
- _engine->getRenderManager()->updateSubArea(_areaId, "");
- _subId = -1;
- }
-
- if (j != -1 && j != _subId) {
- if (_subs[j].subStr.size())
- if (_areaId != -1)
- _engine->getRenderManager()->updateSubArea(_areaId, _subs[j].subStr);
- _subId = j;
- }
-}
-
-} // End of namespace ZVision
diff --git a/engines/zvision/graphics/subtitles.h b/engines/zvision/graphics/subtitles.h
deleted file mode 100644
index c3da658..0000000
--- a/engines/zvision/graphics/subtitles.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/* 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.
- *
- * 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
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef ZVISION_SUBTITLES_H
-#define ZVISION_SUBTITLES_H
-
-#include "zvision/zvision.h"
-
-namespace ZVision {
-
-class ZVision;
-
-class Subtitle {
-public:
- Subtitle(ZVision *engine, const Common::String &subname);
- ~Subtitle();
-
- void process(int32 time);
-private:
- ZVision *_engine;
- int32 _areaId;
- int16 _subId;
-
- struct sub {
- int start;
- int stop;
- Common::String subStr;
- };
-
- Common::Array<sub> _subs;
-};
-
-}
-
-#endif
diff --git a/engines/zvision/graphics/truetype_font.cpp b/engines/zvision/graphics/truetype_font.cpp
deleted file mode 100644
index 5c8aa03..0000000
--- a/engines/zvision/graphics/truetype_font.cpp
+++ /dev/null
@@ -1,228 +0,0 @@
-/* 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.
- *
- * 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
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#include "common/scummsys.h"
-#include "common/config-manager.h"
-#include "common/debug.h"
-#include "common/file.h"
-#include "common/system.h"
-#include "common/unzip.h"
-#include "graphics/font.h"
-#include "graphics/fonts/ttf.h"
-#include "graphics/surface.h"
-
-#include "zvision/zvision.h"
-#include "zvision/graphics/render_manager.h"
-#include "zvision/graphics/truetype_font.h"
-
-namespace ZVision {
-
-StyledTTFont::StyledTTFont(ZVision *engine) {
- _engine = engine;
- _style = 0;
- _font = NULL;
- _lineHeight = 0;
-}
-
-StyledTTFont::~StyledTTFont() {
- if (_font)
- delete _font;
-}
-
-bool StyledTTFont::loadFont(const Common::String &fontName, int32 point, uint style) {
- _style = style;
- return loadFont(fontName, point);
-}
-
-bool StyledTTFont::loadFont(const Common::String &fontName, int32 point) {
- struct FontStyle {
- const char *zorkFont;
- const char *fontBase;
- const char *freeFontBase;
- const char *freeFontItalicName;
- };
-
- const FontStyle systemFonts[] = {
- { "*times new roman*", "times", "FreeSerif", "Italic" },
- { "*times*", "times", "FreeSerif", "Italic" },
- { "*century schoolbook*", "censcbk", "FreeSerif", "Italic" },
- { "*garamond*", "gara", "FreeSerif", "Italic" },
- { "*courier new*", "cour", "FreeMono", "Oblique" },
- { "*courier*", "cour", "FreeMono", "Oblique" },
- { "*ZorkDeath*", "cour", "FreeMono", "Oblique" },
- { "*arial*", "arial", "FreeSans", "Oblique" },
- { "*ZorkNormal*", "arial", "FreeSans", "Oblique" },
- };
-
- Common::String newFontName;
- Common::String freeFontName;
-
- for (int i = 0; i < ARRAYSIZE(systemFonts); i++) {
- if (fontName.matchString(systemFonts[i].zorkFont, true)) {
- newFontName = systemFonts[i].fontBase;
- freeFontName = systemFonts[i].freeFontBase;
-
- if ((_style & STTF_BOLD) && (_style & STTF_ITALIC)) {
- newFontName += "bi";
- freeFontName += "Bold";
- freeFontName += systemFonts[i].freeFontItalicName;
- } else if (_style & STTF_BOLD) {
- newFontName += "bd";
- freeFontName += "Bold";
- } else if (_style & STTF_ITALIC) {
- newFontName += "i";
- freeFontName += systemFonts[i].freeFontItalicName;
- }
-
- newFontName += ".ttf";
- freeFontName += ".ttf";
- break;
- }
- }
-
- if (newFontName.empty()) {
- debug("Could not identify font: %s. Reverting to Arial", fontName.c_str());
- newFontName = "arial.ttf";
- freeFontName = "FreeSans.ttf";
- }
-
- bool sharp = (_style & STTF_SHARP) == STTF_SHARP;
-
- Common::File file;
- if (!file.open(newFontName) && !file.open(freeFontName))
- error("Unable to open font file %s (free alternative: %s)", newFontName.c_str(), freeFontName.c_str());
-
- Graphics::Font *_newFont = Graphics::loadTTFFont(file, point, 60, (sharp ? Graphics::kTTFRenderModeMonochrome : Graphics::kTTFRenderModeNormal)); // 66 dpi for 640 x 480 on 14" display
- if (_newFont) {
- if (!_font)
- delete _font;
- _font = _newFont;
- }
-
- _fntName = fontName;
- _lineHeight = point;
-
- if (_font)
- return true;
- return false;
-}
-
-void StyledTTFont::setStyle(uint newStyle) {
- if ((_style & (STTF_BOLD | STTF_ITALIC | STTF_SHARP)) != (newStyle & (STTF_BOLD | STTF_ITALIC | STTF_SHARP))) {
- _style = newStyle;
- loadFont(_fntName, _lineHeight);
- } else {
- _style = newStyle;
- }
-}
-
-int StyledTTFont::getFontHeight() {
- if (_font)
- return _font->getFontHeight();
- return 0;
-}
-
-int StyledTTFont::getMaxCharWidth() {
- if (_font)
- return _font->getMaxCharWidth();
- return 0;
-}
-
-int StyledTTFont::getCharWidth(byte chr) {
- if (_font)
- return _font->getCharWidth(chr);
- return 0;
-}
-
-int StyledTTFont::getKerningOffset(byte left, byte right) {
- if (_font)
- return _font->getKerningOffset(left, right);
- return 0;
-}
-
-void StyledTTFont::drawChar(Graphics::Surface *dst, byte chr, int x, int y, uint32 color) {
- if (_font) {
- _font->drawChar(dst, chr, x, y, color);
- if (_style & STTF_UNDERLINE) {
- int16 pos = floor(_font->getFontHeight() * 0.87);
- int thk = MAX((int)(_font->getFontHeight() * 0.05), 1);
- dst->fillRect(Common::Rect(x, y + pos, x + _font->getCharWidth(chr), y + pos + thk), color);
- }
- if (_style & STTF_STRIKEOUT) {
- int16 pos = floor(_font->getFontHeight() * 0.60);
- int thk = MAX((int)(_font->getFontHeight() * 0.05), 1);
- dst->fillRect(Common::Rect(x, y + pos, x + _font->getCharWidth(chr), y + pos + thk), color);
- }
- }
-}
-
-void StyledTTFont::drawString(Graphics::Surface *dst, const Common::String &str, int x, int y, int w, uint32 color, Graphics::TextAlign align) {
- if (_font) {
- _font->drawString(dst, str, x, y, w, color, align);
- if (_style & STTF_UNDERLINE) {
- int16 pos = floor(_font->getFontHeight() * 0.87);
- int16 wd = MIN(_font->getStringWidth(str), w);
- int16 stX = x;
- if (align == Graphics::kTextAlignCenter)
- stX += (w - wd) / 2;
- else if (align == Graphics::kTextAlignRight)
- stX += (w - wd);
-
- int thk = MAX((int)(_font->getFontHeight() * 0.05), 1);
-
- dst->fillRect(Common::Rect(stX, y + pos, stX + wd, y + pos + thk), color);
- }
- if (_style & STTF_STRIKEOUT) {
- int16 pos = floor(_font->getFontHeight() * 0.60);
- int16 wd = MIN(_font->getStringWidth(str), w);
- int16 stX = x;
- if (align == Graphics::kTextAlignCenter)
- stX += (w - wd) / 2;
- else if (align == Graphics::kTextAlignRight)
- stX += (w - wd);
-
- int thk = MAX((int)(_font->getFontHeight() * 0.05), 1);
-
- dst->fillRect(Common::Rect(stX, y + pos, stX + wd, y + pos + thk), color);
- }
- }
-}
-
-int StyledTTFont::getStringWidth(const Common::String &str) {
- if (_font)
- return _font->getStringWidth(str);
- return 0;
-}
-
-Graphics::Surface *StyledTTFont::renderSolidText(const Common::String &str, uint32 color) {
- Graphics::Surface *tmp = new Graphics::Surface;
- if (_font) {
- int16 w = _font->getStringWidth(str);
- if (w && w < 1024) {
- tmp->create(w, _font->getFontHeight(), _engine->_pixelFormat);
- drawString(tmp, str, 0, 0, w, color);
- }
- }
- return tmp;
-}
-
-} // End of namespace ZVision
diff --git a/engines/zvision/graphics/truetype_font.h b/engines/zvision/graphics/truetype_font.h
deleted file mode 100644
index b5fac4a..0000000
--- a/engines/zvision/graphics/truetype_font.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/* 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.
- *
- * 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
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-// This file is based on engines/wintermute/base/fonts/base_font_truetype.h/.cpp
-
-#ifndef ZVISION_TRUETYPE_FONT_H
-#define ZVISION_TRUETYPE_FONT_H
-
-#include "graphics/font.h"
-#include "graphics/pixelformat.h"
-
-namespace Graphics {
-struct Surface;
-}
-
-namespace ZVision {
-
-class ZVision;
-
-// Styled TTF
-class StyledTTFont {
-public:
- StyledTTFont(ZVision *engine);
- ~StyledTTFont();
-
- enum {
- STTF_BOLD = 1,
- STTF_ITALIC = 2,
- STTF_UNDERLINE = 4,
- STTF_STRIKEOUT = 8,
- STTF_SHARP = 16
- };
-
-private:
- ZVision *_engine;
- Graphics::Font *_font;
- int _lineHeight;
- uint _style;
- Common::String _fntName;
-
-public:
- bool loadFont(const Common::String &fontName, int32 point);
- bool loadFont(const Common::String &fontName, int32 point, uint style);
- void setStyle(uint newStyle);
-
- int getFontHeight();
- int getMaxCharWidth();
- int getCharWidth(byte chr);
- int getKerningOffset(byte left, byte right);
-
- void drawChar(Graphics::Surface *dst, byte chr, int x, int y, uint32 color);
-
- void drawString(Graphics::Surface *dst, const Common::String &str, int x, int y, int w, uint32 color, Graphics::TextAlign align = Graphics::kTextAlignLeft);
- int getStringWidth(const Common::String &str);
-
- Graphics::Surface *renderSolidText(const Common::String &str, uint32 color);
-
- bool isLoaded() {
- return _font != NULL;
- };
-};
-
-} // End of namespace ZVision
-
-#endif
diff --git a/engines/zvision/module.mk b/engines/zvision/module.mk
index 00652f0..3ea31ab 100644
--- a/engines/zvision/module.mk
+++ b/engines/zvision/module.mk
@@ -17,8 +17,6 @@ MODULE_OBJS := \
graphics/effects/wave.o \
graphics/render_manager.o \
graphics/render_table.o \
- graphics/subtitles.o \
- graphics/truetype_font.o \
scripting/actions.o \
scripting/control.o \
scripting/controls/fist_control.o \
@@ -44,7 +42,9 @@ MODULE_OBJS := \
sound/midi.o \
sound/zork_raw.o \
text/string_manager.o \
+ text/subtitles.o \
text/text.o \
+ text/truetype_font.o \
video/rlf_decoder.o \
video/video.o \
video/zork_avi_decoder.o \
diff --git a/engines/zvision/scripting/sidefx/music_node.h b/engines/zvision/scripting/sidefx/music_node.h
index 09bdc37..8f4a46f 100644
--- a/engines/zvision/scripting/sidefx/music_node.h
+++ b/engines/zvision/scripting/sidefx/music_node.h
@@ -25,7 +25,7 @@
#include "audio/mixer.h"
#include "zvision/scripting/sidefx.h"
-#include "zvision/graphics/subtitles.h"
+#include "zvision/text/subtitles.h"
namespace Common {
class String;
diff --git a/engines/zvision/scripting/sidefx/syncsound_node.h b/engines/zvision/scripting/sidefx/syncsound_node.h
index 7cd02a8..5961fcc 100644
--- a/engines/zvision/scripting/sidefx/syncsound_node.h
+++ b/engines/zvision/scripting/sidefx/syncsound_node.h
@@ -25,7 +25,7 @@
#include "audio/mixer.h"
#include "zvision/scripting/sidefx.h"
-#include "zvision/graphics/subtitles.h"
+#include "zvision/text/subtitles.h"
namespace Common {
class String;
diff --git a/engines/zvision/scripting/sidefx/ttytext_node.h b/engines/zvision/scripting/sidefx/ttytext_node.h
index b6cbed3..26d9be8 100644
--- a/engines/zvision/scripting/sidefx/ttytext_node.h
+++ b/engines/zvision/scripting/sidefx/ttytext_node.h
@@ -28,7 +28,7 @@
#include "zvision/scripting/sidefx.h"
#include "zvision/text/text.h"
-#include "zvision/graphics/truetype_font.h"
+#include "zvision/text/truetype_font.h"
namespace Common {
class String;
diff --git a/engines/zvision/text/string_manager.h b/engines/zvision/text/string_manager.h
index b77ad65..f4564ee 100644
--- a/engines/zvision/text/string_manager.h
+++ b/engines/zvision/text/string_manager.h
@@ -24,7 +24,7 @@
#define ZVISION_STRING_MANAGER_H
#include "zvision/detection.h"
-#include "zvision/graphics/truetype_font.h"
+#include "zvision/text/truetype_font.h"
namespace Graphics {
class FontManager;
diff --git a/engines/zvision/text/subtitles.cpp b/engines/zvision/text/subtitles.cpp
new file mode 100644
index 0000000..acf4c37
--- /dev/null
+++ b/engines/zvision/text/subtitles.cpp
@@ -0,0 +1,108 @@
+/* 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.
+ *
+ * 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
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "zvision/graphics/render_manager.h"
+#include "zvision/text/subtitles.h"
+#include "zvision/file/search_manager.h"
+#include "zvision/text/text.h"
+
+namespace ZVision {
+
+Subtitle::Subtitle(ZVision *engine, const Common::String &subname) :
+ _engine(engine),
+ _areaId(-1),
+ _subId(-1) {
+ Common::File file;
+ if (_engine->getSearchManager()->openFile(file, subname)) {
+ while (!file.eos()) {
+ Common::String str = file.readLine();
+ if (str.lastChar() == '~')
+ str.deleteLastChar();
+
+ if (str.matchString("*Initialization*", true)) {
+ // Not used
+ } else if (str.matchString("*Rectangle*", true)) {
+ int32 x1, y1, x2, y2;
+ sscanf(str.c_str(), "%*[^:]:%d %d %d %d", &x1, &y1, &x2, &y2);
+ Common::Rect rct = Common::Rect(x1, y1, x2, y2);
+ _areaId = _engine->getRenderManager()->createSubArea(rct);
+ } else if (str.matchString("*TextFile*", true)) {
+ char filename[64];
+ sscanf(str.c_str(), "%*[^:]:%s", filename);
+ Common::File txt;
+ if (_engine->getSearchManager()->openFile(txt, filename)) {
+ while (!txt.eos()) {
+ Common::String txtline = readWideLine(txt);
+ sub curSubtitle;
+ curSubtitle.start = -1;
+ curSubtitle.stop = -1;
+ curSubtitle.subStr = txtline;
+
+ _subs.push_back(curSubtitle);
+ }
+ txt.close();
+ }
+ } else {
+ int32 st;
+ int32 en;
+ int32 sb;
+ if (sscanf(str.c_str(), "%*[^:]:(%d,%d)=%d", &st, &en, &sb) == 3) {
+ if (sb <= (int32)_subs.size()) {
+ _subs[sb].start = st;
+ _subs[sb].stop = en;
+ }
+ }
+ }
+ }
+ }
+}
+
+Subtitle::~Subtitle() {
+ if (_areaId != -1)
+ _engine->getRenderManager()->deleteSubArea(_areaId);
+
+ _subs.clear();
+}
+
+void Subtitle::process(int32 time) {
+ int16 j = -1;
+ for (uint16 i = 0; i < _subs.size(); i++)
+ if (time >= _subs[i].start && time <= _subs[i].stop) {
+ j = i;
+ break;
+ }
+
+ if (j == -1 && _subId != -1) {
+ if (_areaId != -1)
+ _engine->getRenderManager()->updateSubArea(_areaId, "");
+ _subId = -1;
+ }
+
+ if (j != -1 && j != _subId) {
+ if (_subs[j].subStr.size())
+ if (_areaId != -1)
+ _engine->getRenderManager()->updateSubArea(_areaId, _subs[j].subStr);
+ _subId = j;
+ }
+}
+
+} // End of namespace ZVision
diff --git a/engines/zvision/text/subtitles.h b/engines/zvision/text/subtitles.h
new file mode 100644
index 0000000..c3da658
--- /dev/null
+++ b/engines/zvision/text/subtitles.h
@@ -0,0 +1,54 @@
+/* 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.
+ *
+ * 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
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef ZVISION_SUBTITLES_H
+#define ZVISION_SUBTITLES_H
+
+#include "zvision/zvision.h"
+
+namespace ZVision {
+
+class ZVision;
+
+class Subtitle {
+public:
+ Subtitle(ZVision *engine, const Common::String &subname);
+ ~Subtitle();
+
+ void process(int32 time);
+private:
+ ZVision *_engine;
+ int32 _areaId;
+ int16 _subId;
+
+ struct sub {
+ int start;
+ int stop;
+ Common::String subStr;
+ };
+
+ Common::Array<sub> _subs;
+};
+
+}
+
+#endif
diff --git a/engines/zvision/text/text.cpp b/engines/zvision/text/text.cpp
index 4ea40a1..91a0688 100644
--- a/engines/zvision/text/text.cpp
+++ b/engines/zvision/text/text.cpp
@@ -33,7 +33,7 @@
#include "zvision/text/text.h"
#include "zvision/graphics/render_manager.h"
-#include "zvision/graphics/truetype_font.h"
+#include "zvision/text/truetype_font.h"
#include "zvision/scripting/script_manager.h"
namespace ZVision {
diff --git a/engines/zvision/text/text.h b/engines/zvision/text/text.h
index c3c60f6..c278b01 100644
--- a/engines/zvision/text/text.h
+++ b/engines/zvision/text/text.h
@@ -25,7 +25,7 @@
#define ZVISION_TEXT_H
#include "zvision/detection.h"
-#include "zvision/graphics/truetype_font.h"
+#include "zvision/text/truetype_font.h"
#include "zvision/zvision.h"
namespace ZVision {
diff --git a/engines/zvision/text/truetype_font.cpp b/engines/zvision/text/truetype_font.cpp
new file mode 100644
index 0000000..f373afe
--- /dev/null
+++ b/engines/zvision/text/truetype_font.cpp
@@ -0,0 +1,228 @@
+/* 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.
+ *
+ * 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
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "common/scummsys.h"
+#include "common/config-manager.h"
+#include "common/debug.h"
+#include "common/file.h"
+#include "common/system.h"
+#include "common/unzip.h"
+#include "graphics/font.h"
+#include "graphics/fonts/ttf.h"
+#include "graphics/surface.h"
+
+#include "zvision/zvision.h"
+#include "zvision/graphics/render_manager.h"
+#include "zvision/text/truetype_font.h"
+
+namespace ZVision {
+
+StyledTTFont::StyledTTFont(ZVision *engine) {
+ _engine = engine;
+ _style = 0;
+ _font = NULL;
+ _lineHeight = 0;
+}
+
+StyledTTFont::~StyledTTFont() {
+ if (_font)
+ delete _font;
+}
+
+bool StyledTTFont::loadFont(const Common::String &fontName, int32 point, uint style) {
+ _style = style;
+ return loadFont(fontName, point);
+}
+
+bool StyledTTFont::loadFont(const Common::String &fontName, int32 point) {
+ struct FontStyle {
+ const char *zorkFont;
+ const char *fontBase;
+ const char *freeFontBase;
+ const char *freeFontItalicName;
+ };
+
+ const FontStyle systemFonts[] = {
+ { "*times new roman*", "times", "FreeSerif", "Italic" },
+ { "*times*", "times", "FreeSerif", "Italic" },
+ { "*century schoolbook*", "censcbk", "FreeSerif", "Italic" },
+ { "*garamond*", "gara", "FreeSerif", "Italic" },
+ { "*courier new*", "cour", "FreeMono", "Oblique" },
+ { "*courier*", "cour", "FreeMono", "Oblique" },
+ { "*ZorkDeath*", "cour", "FreeMono", "Oblique" },
+ { "*arial*", "arial", "FreeSans", "Oblique" },
+ { "*ZorkNormal*", "arial", "FreeSans", "Oblique" },
+ };
+
+ Common::String newFontName;
+ Common::String freeFontName;
+
+ for (int i = 0; i < ARRAYSIZE(systemFonts); i++) {
+ if (fontName.matchString(systemFonts[i].zorkFont, true)) {
+ newFontName = systemFonts[i].fontBase;
+ freeFontName = systemFonts[i].freeFontBase;
+
+ if ((_style & STTF_BOLD) && (_style & STTF_ITALIC)) {
+ newFontName += "bi";
+ freeFontName += "Bold";
+ freeFontName += systemFonts[i].freeFontItalicName;
+ } else if (_style & STTF_BOLD) {
+ newFontName += "bd";
+ freeFontName += "Bold";
+ } else if (_style & STTF_ITALIC) {
+ newFontName += "i";
+ freeFontName += systemFonts[i].freeFontItalicName;
+ }
+
+ newFontName += ".ttf";
+ freeFontName += ".ttf";
+ break;
+ }
+ }
+
+ if (newFontName.empty()) {
+ debug("Could not identify font: %s. Reverting to Arial", fontName.c_str());
+ newFontName = "arial.ttf";
+ freeFontName = "FreeSans.ttf";
+ }
+
+ bool sharp = (_style & STTF_SHARP) == STTF_SHARP;
+
+ Common::File file;
+ if (!file.open(newFontName) && !file.open(freeFontName))
+ error("Unable to open font file %s (free alternative: %s)", newFontName.c_str(), freeFontName.c_str());
+
+ Graphics::Font *_newFont = Graphics::loadTTFFont(file, point, 60, (sharp ? Graphics::kTTFRenderModeMonochrome : Graphics::kTTFRenderModeNormal)); // 66 dpi for 640 x 480 on 14" display
+ if (_newFont) {
+ if (!_font)
+ delete _font;
+ _font = _newFont;
+ }
+
+ _fntName = fontName;
+ _lineHeight = point;
+
+ if (_font)
+ return true;
+ return false;
+}
+
+void StyledTTFont::setStyle(uint newStyle) {
+ if ((_style & (STTF_BOLD | STTF_ITALIC | STTF_SHARP)) != (newStyle & (STTF_BOLD | STTF_ITALIC | STTF_SHARP))) {
+ _style = newStyle;
+ loadFont(_fntName, _lineHeight);
+ } else {
+ _style = newStyle;
+ }
+}
+
+int StyledTTFont::getFontHeight() {
+ if (_font)
+ return _font->getFontHeight();
+ return 0;
+}
+
+int StyledTTFont::getMaxCharWidth() {
+ if (_font)
+ return _font->getMaxCharWidth();
+ return 0;
+}
+
+int StyledTTFont::getCharWidth(byte chr) {
+ if (_font)
+ return _font->getCharWidth(chr);
+ return 0;
+}
+
+int StyledTTFont::getKerningOffset(byte left, byte right) {
+ if (_font)
+ return _font->getKerningOffset(left, right);
+ return 0;
+}
+
+void StyledTTFont::drawChar(Graphics::Surface *dst, byte chr, int x, int y, uint32 color) {
+ if (_font) {
+ _font->drawChar(dst, chr, x, y, color);
+ if (_style & STTF_UNDERLINE) {
+ int16 pos = floor(_font->getFontHeight() * 0.87);
+ int thk = MAX((int)(_font->getFontHeight() * 0.05), 1);
+ dst->fillRect(Common::Rect(x, y + pos, x + _font->getCharWidth(chr), y + pos + thk), color);
+ }
+ if (_style & STTF_STRIKEOUT) {
+ int16 pos = floor(_font->getFontHeight() * 0.60);
+ int thk = MAX((int)(_font->getFontHeight() * 0.05), 1);
+ dst->fillRect(Common::Rect(x, y + pos, x + _font->getCharWidth(chr), y + pos + thk), color);
+ }
+ }
+}
+
+void StyledTTFont::drawString(Graphics::Surface *dst, const Common::String &str, int x, int y, int w, uint32 color, Graphics::TextAlign align) {
+ if (_font) {
+ _font->drawString(dst, str, x, y, w, color, align);
+ if (_style & STTF_UNDERLINE) {
+ int16 pos = floor(_font->getFontHeight() * 0.87);
+ int16 wd = MIN(_font->getStringWidth(str), w);
+ int16 stX = x;
+ if (align == Graphics::kTextAlignCenter)
+ stX += (w - wd) / 2;
+ else if (align == Graphics::kTextAlignRight)
+ stX += (w - wd);
+
+ int thk = MAX((int)(_font->getFontHeight() * 0.05), 1);
+
+ dst->fillRect(Common::Rect(stX, y + pos, stX + wd, y + pos + thk), color);
+ }
+ if (_style & STTF_STRIKEOUT) {
+ int16 pos = floor(_font->getFontHeight() * 0.60);
+ int16 wd = MIN(_font->getStringWidth(str), w);
+ int16 stX = x;
+ if (align == Graphics::kTextAlignCenter)
+ stX += (w - wd) / 2;
+ else if (align == Graphics::kTextAlignRight)
+ stX += (w - wd);
+
+ int thk = MAX((int)(_font->getFontHeight() * 0.05), 1);
+
+ dst->fillRect(Common::Rect(stX, y + pos, stX + wd, y + pos + thk), color);
+ }
+ }
+}
+
+int StyledTTFont::getStringWidth(const Common::String &str) {
+ if (_font)
+ return _font->getStringWidth(str);
+ return 0;
+}
+
+Graphics::Surface *StyledTTFont::renderSolidText(const Common::String &str, uint32 color) {
+ Graphics::Surface *tmp = new Graphics::Surface;
+ if (_font) {
+ int16 w = _font->getStringWidth(str);
+ if (w && w < 1024) {
+ tmp->create(w, _font->getFontHeight(), _engine->_pixelFormat);
+ drawString(tmp, str, 0, 0, w, color);
+ }
+ }
+ return tmp;
+}
+
+} // End of namespace ZVision
diff --git a/engines/zvision/text/truetype_font.h b/engines/zvision/text/truetype_font.h
new file mode 100644
index 0000000..b5fac4a
--- /dev/null
+++ b/engines/zvision/text/truetype_font.h
@@ -0,0 +1,84 @@
+/* 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.
+ *
+ * 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
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+// This file is based on engines/wintermute/base/fonts/base_font_truetype.h/.cpp
+
+#ifndef ZVISION_TRUETYPE_FONT_H
+#define ZVISION_TRUETYPE_FONT_H
+
+#include "graphics/font.h"
+#include "graphics/pixelformat.h"
+
+namespace Graphics {
+struct Surface;
+}
+
+namespace ZVision {
+
+class ZVision;
+
+// Styled TTF
+class StyledTTFont {
+public:
+ StyledTTFont(ZVision *engine);
+ ~StyledTTFont();
+
+ enum {
+ STTF_BOLD = 1,
+ STTF_ITALIC = 2,
+ STTF_UNDERLINE = 4,
+ STTF_STRIKEOUT = 8,
+ STTF_SHARP = 16
+ };
+
+private:
+ ZVision *_engine;
+ Graphics::Font *_font;
+ int _lineHeight;
+ uint _style;
+ Common::String _fntName;
+
+public:
+ bool loadFont(const Common::String &fontName, int32 point);
+ bool loadFont(const Common::String &fontName, int32 point, uint style);
+ void setStyle(uint newStyle);
+
+ int getFontHeight();
+ int getMaxCharWidth();
+ int getCharWidth(byte chr);
+ int getKerningOffset(byte left, byte right);
+
+ void drawChar(Graphics::Surface *dst, byte chr, int x, int y, uint32 color);
+
+ void drawString(Graphics::Surface *dst, const Common::String &str, int x, int y, int w, uint32 color, Graphics::TextAlign align = Graphics::kTextAlignLeft);
+ int getStringWidth(const Common::String &str);
+
+ Graphics::Surface *renderSolidText(const Common::String &str, uint32 color);
+
+ bool isLoaded() {
+ return _font != NULL;
+ };
+};
+
+} // End of namespace ZVision
+
+#endif
diff --git a/engines/zvision/video/video.cpp b/engines/zvision/video/video.cpp
index 189fb22..97fbd87 100644
--- a/engines/zvision/video/video.cpp
+++ b/engines/zvision/video/video.cpp
@@ -29,7 +29,7 @@
#include "zvision/zvision.h"
#include "zvision/core/clock.h"
#include "zvision/graphics/render_manager.h"
-#include "zvision/graphics/subtitles.h"
+#include "zvision/text/subtitles.h"
#include "zvision/video/rlf_decoder.h"
#include "zvision/video/zork_avi_decoder.h"
diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp
index c32cceb..cf7ed28 100644
--- a/engines/zvision/zvision.cpp
+++ b/engines/zvision/zvision.cpp
@@ -33,7 +33,7 @@
#include "zvision/core/menu.h"
#include "zvision/file/search_manager.h"
#include "zvision/text/text.h"
-#include "zvision/graphics/truetype_font.h"
+#include "zvision/text/truetype_font.h"
#include "zvision/sound/midi.h"
#include "zvision/file/zfs_archive.h"
More information about the Scummvm-git-logs
mailing list