ScummVM API documentation
subtitles.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef VIDEO_SUBTITLES_H
23 #define VIDEO_SUBTITLES_H
24 
25 #include "common/str.h"
26 #include "common/array.h"
27 #include "common/hashmap.h"
28 #include "common/rect.h"
29 
30 namespace Graphics {
31 class Font;
32 struct Surface;
33 }
34 
35 namespace Video {
36 
37 struct SubtitlePart {
38  Common::String text;
39  Common::String tag;
40 
41  SubtitlePart(const Common::String &text_, const Common::String &tag_) : text(text_), tag(tag_) {}
42 };
43 
44 struct SRTEntry {
45  uint seq;
46  uint32 start;
47  uint32 end;
48 
50 
51  SRTEntry(uint seq_, uint32 start_, uint32 end_, const Common::Array<SubtitlePart> &parts_) {
52  seq = seq_; start = start_; end = end_; parts = parts_;
53  }
54 
55  // Dummy constructor for bsearch
56  SRTEntry(uint seq_, uint32 start_, uint32 end_, const Common::String &text, const Common::String &tag = "") {
57  seq = seq_; start = start_; end = end_;
58  parts.push_back(SubtitlePart(text, tag));
59  }
60 };
61 
62 class SRTParser {
63 public:
64  SRTParser();
65  ~SRTParser();
66 
67  void cleanup();
68  bool parseFile(const Common::Path &fname);
69  void parseTextAndTags(const Common::String &text, Common::Array<SubtitlePart> &parts) const;
70  const Common::Array<SubtitlePart> *getSubtitleParts(uint32 timestamp) const;
71  Common::String getSubtitle(uint32 timestamp) const;
72 
73 private:
75 };
76 
77 class Subtitles {
78 public:
79  Subtitles();
80  ~Subtitles();
81 
82  void loadSRTFile(const Common::Path &fname);
83  void close() { _loaded = false; _subtitle.clear(); _fname.clear(); _srtParser.cleanup(); }
84  void setFont(const char *fontname, int height = 18, Common::String type = "regular");
85  void setBBox(const Common::Rect &bbox);
86  void setColor(byte r, byte g, byte b);
87  void setPadding(uint16 horizontal, uint16 vertical);
88  bool drawSubtitle(uint32 timestamp, bool force = false, bool showSFX = false);
89  bool isLoaded() const { return _loaded || _subtitleDev; }
90 
91 private:
92  void renderSubtitle() const;
93 
94  SRTParser _srtParser;
95  bool _loaded;
96  bool _subtitleDev;
97  bool _overlayHasAlpha;
98 
100  int _fontHeight;
101 
102  Graphics::Surface *_surface;
103 
104  mutable Common::Rect _drawRect;
105  Common::Rect _requestedBBox;
106  mutable Common::Rect _realBBox;
107  mutable int16 _lastOverlayWidth, _lastOverlayHeight;
108 
109  Common::Path _fname;
110  mutable Common::String _subtitle;
111  mutable const Common::Array<SubtitlePart> *_parts;
112  uint32 _color;
113  uint32 _blackColor;
114  uint32 _transparentColor;
115  uint16 _hPad;
116  uint16 _vPad;
117 };
118 
119 } // End of namespace Video
120 
121 #endif
Definition: str.h:59
Definition: surface.h:67
Definition: subtitles.h:37
Definition: array.h:52
Definition: rect.h:524
Definition: path.h:52
Definition: subtitles.h:77
void push_back(const T &element)
Definition: array.h:183
Definition: hashmap.h:85
Definition: formatinfo.h:28
Definition: subtitles.h:44
Definition: subtitles.h:62
Definition: avi_frames.h:36