95 lines
1.9 KiB
C++
95 lines
1.9 KiB
C++
/* -----------------------------------------------------------------------------
|
|
GSFramework
|
|
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
|
----------------------------------------------------------------------------- */
|
|
|
|
|
|
#ifndef __NRASTERFONT__
|
|
#define __NRASTERFONT__
|
|
|
|
|
|
#include "core/render_data.h"
|
|
#include "container/nlist.h"
|
|
|
|
|
|
namespace GS {
|
|
namespace Render {
|
|
struct ResourceFactory;
|
|
|
|
/*!
|
|
@short Raster font.
|
|
|
|
Raster font that can be used by the Write() method of the renderer.
|
|
A raster font is of fixed size and stored in one or several texture
|
|
pages.
|
|
|
|
@author Emmanuel Julien (ejulien@gsworks.fr)
|
|
*/
|
|
class RasterFont
|
|
{
|
|
public:
|
|
|
|
/// Raster font glyph.
|
|
struct Glyph
|
|
{
|
|
bool available;
|
|
float u, v;
|
|
float w, h;
|
|
float offx, offy;
|
|
float step;
|
|
uint page;
|
|
|
|
void Reset()
|
|
{
|
|
available = false;
|
|
u = v = 0;
|
|
w = h = 0;
|
|
offx = offy = 0;
|
|
step = 0;
|
|
page = 0;
|
|
}
|
|
Glyph() { Reset(); }
|
|
};
|
|
|
|
private:
|
|
|
|
SharedList <Texture *> pages;
|
|
|
|
Glyph glyph[256]; ///< Character LUT.
|
|
|
|
float baseline;
|
|
float height;
|
|
|
|
public:
|
|
|
|
String name;
|
|
|
|
float GetHeight(bool normalized = true) const;
|
|
float GetBaseline(bool normalized = true) const;
|
|
|
|
/// Return the texture corresponding to a given font page.
|
|
Texture *GetPage(uint) const;
|
|
|
|
/// Return information structure for a given glyph.
|
|
const Glyph *GetGlyphInfos(uchar) const;
|
|
|
|
// Return the rect of a single-line string (stops at the first carriage return).
|
|
Vector2 ComputeLineRect(const char *s, bool normalized = true) const;
|
|
/// Return the rect a multi-line string.
|
|
Vector2 ComputeStringRect(const char *s, bool normalized = true) const;
|
|
|
|
/*!
|
|
@short Load a raster font.
|
|
@param nml The font meta file description.
|
|
@param base Font page texture base name.
|
|
*/
|
|
bool Load(ResourceFactory &, const char *nml, const char *base);
|
|
void Unload();
|
|
};
|
|
|
|
} // Render
|
|
} // GS
|
|
|
|
|
|
#endif // __NRASTERFONT__
|