1 /* ScummVM - Graphic Adventure Engine
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.
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.
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.
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.
25 #ifndef GRAPHICS_FONT_H
26 #define GRAPHICS_FONT_H
28 #include "common/str.h"
29 #include "graphics/surface.h"
32 class SeekableReadStream
;
37 /** Text alignment modes */
40 kTextAlignLeft
, //!< Text should be aligned to the left
41 kTextAlignCenter
, //!< Text should be centered
42 kTextAlignRight
//!< Text should be aligned to the right
46 * Instances of this class represent a distinct font, with a built-in renderer.
47 * @todo Maybe move the high-level methods (drawString etc.) to a separate
48 * FontRenderer class? That way, we could have different variants... ?
55 virtual int getFontHeight() const = 0;
56 virtual int getMaxCharWidth() const = 0;
58 virtual int getCharWidth(byte chr
) const = 0;
59 virtual void drawChar(Surface
*dst
, byte chr
, int x
, int y
, uint32 color
) const = 0;
61 void drawString(Surface
*dst
, const Common::String
&str
, int x
, int y
, int w
, uint32 color
, TextAlign align
= kTextAlignLeft
, int deltax
= 0, bool useEllipsis
= true) const;
64 * Compute and return the width the string str has when rendered using this font.
66 int getStringWidth(const Common::String
&str
) const;
69 * Take a text (which may contain newlines characters) and word wrap it so thata
70 * no text line is wider than maxWidth pixels. If necessary, additional line breaks
71 * are generated, preferably between words (i.e. were whitespaces are).
72 * The resulting lines are appended to the string list lines.
73 * It returns the maximal width of any of the new lines (i.e. a value which is less
74 * or equal to maxWidth).
76 * @param str the string to word wrap
77 * @param maxWidth the maximum width a line may have
78 * @param lines the string list to which the text lines from str are appended
79 * @return the maximal width of any of the lines added to lines
81 int wordWrapText(const Common::String
&str
, int maxWidth
, Common::StringList
&lines
) const;
85 class ScummFont
: public Font
{
87 virtual int getFontHeight() const { return 8; }
88 virtual int getMaxCharWidth() const { return 8; }
90 virtual int getCharWidth(byte chr
) const;
91 virtual void drawChar(Surface
*dst
, byte chr
, int x
, int y
, uint32 color
) const;
94 typedef uint16 bitmap_t
; /* bitmap image unit size*/
103 /* builtin C-based proportional/fixed font structure */
104 /* based on The Microwindows Project http://microwindows.org */
106 const char * name
; /* font name*/
107 int maxwidth
; /* max width in pixels*/
108 int height
; /* height in pixels*/
109 int fbbw
, fbbh
, fbbx
, fbby
; /* max bounding box */
110 int ascent
; /* ascent (baseline) height*/
111 int firstchar
; /* first character in bitmap*/
112 int size
; /* font size in glyphs*/
113 const bitmap_t
* bits
; /* 16-bit right-padded bitmap data*/
114 const unsigned long* offset
; /* offsets into bitmap data*/
115 const unsigned char* width
; /* character widths or NULL if fixed*/
116 const BBX
* bbx
; /* character bounding box or NULL if fixed */
117 int defaultchar
; /* default char (not glyph index)*/
118 long bits_size
; /* # words of bitmap_t bits*/
123 class NewFont
: public Font
{
129 NewFont(const FontDesc
&d
, NewFontData
*font_
= 0) : desc(d
), font(font_
) {}
132 virtual int getFontHeight() const { return desc
.height
; }
133 virtual int getMaxCharWidth() const { return desc
.maxwidth
; }
135 virtual int getCharWidth(byte chr
) const;
136 virtual void drawChar(Surface
*dst
, byte chr
, int x
, int y
, uint32 color
) const;
138 static NewFont
*loadFont(Common::SeekableReadStream
&stream
);
139 static bool cacheFontData(const NewFont
&font
, const Common::String
&filename
);
140 static NewFont
*loadFromCache(Common::SeekableReadStream
&stream
);
143 #if (defined(PALMOS_ARM) || defined(PALMOS_DEBUG) || defined(__GP32__))
144 # define DEFINE_FONT(n) \
146 void create_##n() { \
147 n = new NewFont(desc); \
150 # define INIT_FONT(n) \
151 extern void create_##n(); \
155 } // End of namespace Graphics