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
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (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, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 /*
24  * This code is based on Broken Sword 2.5 engine
25  *
26  * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
27  *
28  * Licensed under GNU GPL v2
29  *
30  */
31 
32 #ifndef SWORD25_FONTRESOURCE_H
33 #define SWORD25_FONTRESOURCE_H
34 
35 #include "common/scummsys.h"
36 #include "common/rect.h"
37 #include "common/xmlparser.h"
38 #include "sword25/kernel/common.h"
39 #include "sword25/kernel/resource.h"
40 
41 namespace Sword25 {
42 
43 class Kernel;
44 
45 class FontResource : public Resource, Common::XMLParser {
46 public:
47 	/**
48 	    @brief Erzeugt eine neues Exemplar von BS_FontResource
49 	    @param pKernel ein Pointer auf den Kernel
50 	    @param FileName der Dateiname der zu ladenen Resource
51 	    @remark Wenn der Konstruktor erfolgreich ausgeführt werden konnte gibt die Methode IsValid true zurück.
52 	*/
53 	FontResource(Kernel *pKernel, const Common::String &fileName);
54 
55 	/**
56 	    @brief Gibt true zurück, wenn das Objekt korrekt initialisiert wurde.
57 
58 	    Diese Methode kann dazu benutzt werden um festzustellen, ob der Konstruktor erfolgreich ausgeführt wurde.
59 	*/
isValid()60 	bool isValid() const {
61 		return _valid;
62 	}
63 
64 	/**
65 	    @brief Gibt die Zeilenhöhe des Fonts in Pixeln zurück.
66 
67 	    Die Zeilenhöhe ist der Wert, der zur Y-Koordinate addiert wird, wenn ein Zeilenumbruch auftritt.
68 	*/
getLineHeight()69 	int getLineHeight() const {
70 		return _lineHeight;
71 	}
72 
73 	/**
74 	    @brief Gibt den Buchstabenabstand der Fonts in Pixeln zurück.
75 
76 	    Der Buchstabenabstand ist der Wert, der zwischen zwei Buchstaben freigelassen wird.
77 	*/
getGapWidth()78 	int getGapWidth() const {
79 		return _gapWidth;
80 	}
81 
82 	/**
83 	    @brief Gibt das Bounding-Rect eines Zeichens auf der Charactermap zurück.
84 	    @param Character der ASCII-Code des Zeichens
85 	    @return Das Bounding-Rect des übergebenen Zeichens auf der Charactermap.
86 	*/
getCharacterRect(int character)87 	const Common::Rect &getCharacterRect(int character) const {
88 		assert(character >= 0 && character < 256);
89 		return _characterRects[character];
90 	}
91 
92 	/**
93 	    @brief Gibt den Dateinamen der Charactermap zurück.
94 	*/
getCharactermapFileName()95 	const Common::String &getCharactermapFileName() const {
96 		return _bitmapFileName;
97 	}
98 
99 private:
100 	Kernel *_pKernel;
101 	bool _valid;
102 	Common::String _bitmapFileName;
103 	int _lineHeight;
104 	int _gapWidth;
105 	Common::Rect _characterRects[256];
106 
107 	// Parser
CUSTOM_XML_PARSER(FontResource)108 	CUSTOM_XML_PARSER(FontResource) {
109 		XML_KEY(font)
110 			XML_PROP(bitmap, true)
111 			XML_PROP(lineheight, false)
112 			XML_PROP(gap, false)
113 
114 			XML_KEY(character)
115 				XML_PROP(code, true)
116 				XML_PROP(left, true)
117 				XML_PROP(top, true)
118 				XML_PROP(right, true)
119 				XML_PROP(bottom, true)
120 			KEY_END()
121 		KEY_END()
122 	} PARSER_END()
123 
124 	// Parser callback methods
125 	bool parserCallback_font(ParserNode *node);
126 	bool parserCallback_character(ParserNode *node);
127 };
128 
129 } // End of namespace Sword25
130 
131 #endif
132