100 _invertPalette(invertPalette), _surface(0) {
118 std::vector<Glyph> glyphs;
128 std::map<uint32, Char>::const_iterator m =
_chars.find(
'm');
143 if ((versionMajor != 1) || ((versionMinor != 0) && (versionMinor != 1)))
144 throw Common::Exception(
"Unsupported version %u.%u", versionMajor, versionMinor);
147 if (fileSize > nftr.
size())
188 std::vector<Glyph> &glyphs) {
208 if ((depth != 1) && (depth != 2) && (depth != 4) && (depth != 8))
211 if ((width * height * depth) > (size * 8))
212 throw Common::Exception(
"Glyph can't fit (%u * %u * %u > %d", width, height, depth, size * 8);
218 const uint32 count = (sectionSize - 16) / size;
219 glyphs.resize(count);
221 size_t offset = nftr.
pos();
222 for (
uint32 i = 0; i < count; i++, offset += size) {
226 glyphs[i].palMode = header.
palMode;
227 glyphs[i].width = width;
228 glyphs[i].height = height;
229 glyphs[i].depth = depth;
232 glyphs[i].advance = header.
width + 1;
235 glyphs[i].character = 0;
240 std::vector<Glyph> &glyphs) {
263 for (
uint32 i = firstGlyph; i <= lastGlyph; i++) {
264 if (i >= glyphs.size())
272 glyphs[i].advance = (pixelWidth == 1) ? pixelLength : pixelWidth;
277 std::vector<Glyph> &glyphs) {
294 while ((nextOffset != 0) && (nextOffset < nftr.
size())) {
295 nftr.
seek(nextOffset);
305 if (firstChar > lastChar)
306 throw Common::Exception(
"Invalid character map range (%u - %u)", firstChar, lastChar);
317 count = lastChar - firstChar + 1;
320 if ((to + count) > glyphs.size())
322 to, count, (
uint)glyphs.size());
324 for (
uint32 i = 0; i < count; i++)
329 count = (sectionSize - 20 - 2) / 2;
331 for (
uint32 i = 0; i < count; i++) {
336 if (to >= glyphs.size())
338 to, (
uint)glyphs.size());
347 for (
uint32 i = 0; i < count; i++) {
353 if (to >= glyphs.size())
355 to, (
uint)glyphs.size());
365 std::map<uint32, Char>::const_iterator cC =
_chars.find(c);
369 return cC->second.width;
382 glVertex2f(0.0f , 0.0f);
383 glVertex2f(width, 0.0f);
388 glTranslatef(width + 1.0f, 0.0f, 0.0f);
392 std::map<uint32, Char>::const_iterator cC =
_chars.find(c);
401 for (
int i = 0; i < 4; i++) {
402 glTexCoord2f(cC->second.tX[i], cC->second.tY[i]);
403 glVertex2f (cC->second.vX[i], cC->second.vY[i]);
407 glTranslatef(cC->second.width, 0.0f, 0.0f);
422 const uint32 width = glyphs[0].width;
423 const uint32 height = glyphs[0].height;
424 const uint32 pixels = glyphs.size() * width * height;
427 if (textureLength > 2048)
430 assert(((textureLength / width) * (textureLength / height)) >= glyphs.size());
436 for (std::vector<Glyph>::const_iterator g = glyphs.begin(); g != glyphs.end(); ++g) {
439 std::pair<std::map<uint32, Char>::iterator,
bool> result;
440 result =
_chars.insert(std::make_pair(g->character,
Char()));
442 Char &ch = result.first->second;
444 ch.
width = g->advance;
446 ch.
vX[0] = 0.00f; ch.
vY[0] = 0.00f;
447 ch.
vX[1] = width; ch.
vY[1] = 0.00f;
448 ch.
vX[2] = width; ch.
vY[2] = height;
449 ch.
vX[3] = 0.00f; ch.
vY[3] = height;
451 const float tX = (float) x / (
float) textureLength;
452 const float tY = (float) y / (
float) textureLength;
453 const float tW = (float) width / (
float) textureLength;
454 const float tH = (float) height / (
float) textureLength;
456 ch.
tX[0] = tX; ch.
tY[0] = tY + tH;
457 ch.
tX[1] = tX + tW; ch.
tY[1] = tY + tH;
458 ch.
tX[2] = tX + tW; ch.
tY[2] = tY;
459 ch.
tX[3] = tX; ch.
tY[3] = tY;
462 if ((x + width) > textureLength) {
480 byte *destRow = dest;
499 value = (maxColors == 2) ? 0xFF : (255 * (pixel ) / (maxColors - 1));
501 value = (maxColors == 2) ? 0xFF : (255 * (pixel - 1) / (maxColors - 2));
514 *destRow++ = pixel == 0 ? 0 : 0xFF;
516 data <<= glyph.
depth;
533 memset(data, 0,
sizeof(data));
540 WRITE_LE_UINT16(data, codePoint);
541 }
else if (encoding == 3) {
void readHeader(Common::SeekableSubReadStreamEndian &nftr, Header &header)
#define ResMan
Shortcut for accessing the sound manager.
void readCharMaps(Common::SeekableSubReadStreamEndian &nftr, Header &header, std::vector< Glyph > &glyphs)
#define MKTAG(a0, a1, a2, a3)
A wrapper macro used around four character constants, like 'DATA', to ensure portability.
static const uint32 kCGLPID
void drawGlyphs(const std::vector< Glyph > &glyphs)
static const uint32 kCMAPID
This is a wrapper around SeekableSubReadStream, but it adds non-endian read methods whose endianness ...
float getWidth(uint32 c) const
Return the width of a character.
Texture & getTexture() const
static const uint32 kCWDHID
A class holding an UTF-8 string.
#define TextureMan
Shortcut for accessing the texture manager.
virtual size_t seek(ptrdiff_t offset, Origin whence=kOriginBegin)=0
Sets the stream position indicator for the stream.
static Texture * create(const Common::UString &name, bool deswizzle=false)
Create a texture from this image resource.
The Aurora texture manager.
Common::SeekableReadStream * data
NFTRFont(Common::SeekableReadStream *nftr, bool invertPalette=false)
void readGlyphs(Common::SeekableSubReadStreamEndian &nftr, Header &header, std::vector< Glyph > &glyphs)
UTF-16 LE (little endian).
size_t pos() const
Obtains the current value of the stream position indicator of the stream.
static uint32 NEXTPOWER2(uint32 x)
Round up to the next power of 2.
float getHeight() const
Return the height of a character.
void draw(uint32 c) const
Draw this character.
Utility templates and functions for working with strings and streams.
Exception that provides a stack of explanations.
size_t size() const
Obtains the total size of the stream, measured in bytes.
A simple scoped smart pointer template.
Basic exceptions to throw.
std::map< uint32, Char > _chars
const char * c_str() const
Return the (utf8 encoded) string data.
size_t seek(ptrdiff_t offset, Origin whence=kOriginBegin)
Sets the stream position indicator for the stream.
Utility templates and functions.
void drawGlyph(const Glyph &glyph, Surface &surface, uint32 x, uint32 y)
virtual size_t skip(ptrdiff_t offset)
Skip the specified number of bytes, adding that offset to the current position in the stream...
void readWidths(Common::SeekableSubReadStreamEndian &nftr, Header &header, std::vector< Glyph > &glyphs)
Nintendo's NFTR font, found in Sonic.
Utility functions for working with differing string encodings.
bool empty() const
Is the string empty?
void readInfo(Common::SeekableSubReadStreamEndian &nftr, Header &header)
Basic reading stream interfaces.
An image surface, in BGRA format.
A texture as used in the Aurora engines.
static const uint32 kNFTRID
UString debugTag(uint32 tag, bool trim)
Create an elaborate string from an integer tag, for debugging purposes.
void load(Common::SeekableSubReadStreamEndian &nftr)
static uint32 convertToUTF32(uint16 codePoint, uint8 encoding)
UString readString(SeekableReadStream &stream, Encoding encoding)
Read a string with the given encoding of a stream.
Windows codepage 1252 (Western European, Latin alphabet).
SeekableSubReadStream provides access to a SeekableReadStream restricted to the range [begin...
static const uint32 kFINFID
static Common::SeekableSubReadStreamEndian * open(Common::SeekableReadStream &stream)
Treat this stream as a Nitro file and return an endian'd stream according to its BOM.
Interface for a seekable & readable data stream.
byte readByte()
Read an unsigned byte from the stream and return it.
The global resource manager for Aurora resources.