VIDEO: Load font for Subtitles

This commit is contained in:
Eugene Sandulenko 2018-05-22 21:16:26 +02:00
parent 8fa9f74d59
commit 9cb80bc9fb
2 changed files with 32 additions and 1 deletions

View File

@ -22,6 +22,9 @@
#include "common/debug.h"
#include "common/file.h"
#include "graphics/fonts/ttf.h"
#include "graphics/fontman.h"
#include "video/subtitles.h"
namespace Video {
@ -218,12 +221,32 @@ Common::String SRTParser::getSubtitle(uint32 timestamp) {
return (*entry)->text;
}
Subtitles::Subtitles() : _loaded(false) {
Subtitles::Subtitles() : _loaded(false), _font(nullptr) {
}
Subtitles::~Subtitles() {
}
void Subtitles::loadFont(const char *fontname, int height) {
Common::File file;
_fontHeight = height;
if (!file.open(fontname)) {
_font = Graphics::loadTTFFont(file, _fontHeight, Graphics::kTTFSizeModeCharacter, 96);
}
if (!_font)
_font = FontMan.getFontByName(fontname);
if (!_font) {
warning("Cannot load font %s", fontname);
_font = FontMan.getFontByUsage(Graphics::FontManager::kBigGUIFont);
}
}
void Subtitles::loadSRTFile(const char *fname) {
debug(1, "loadSRTFile('%s')", fname);

View File

@ -25,6 +25,10 @@
#include "common/str.h"
#include "common/array.h"
namespace Graphics {
class Font;
}
namespace Video {
struct SRTEntry {
@ -58,10 +62,14 @@ public:
~Subtitles();
void loadSRTFile(const char *fname);
void loadFont(const char *fontname, int height = 30);
private:
SRTParser _srtParser;
bool _loaded;
const Graphics::Font *_font;
int _fontHeight;
};
} // End of namespace Video