mirror of
https://github.com/love2d/love.git
synced 2026-08-21 13:09:56 +02:00
Cleaned up TrueType Rasterizer code
This commit is contained in:
@@ -30,16 +30,9 @@ namespace font
|
|||||||
namespace freetype
|
namespace freetype
|
||||||
{
|
{
|
||||||
|
|
||||||
struct la
|
|
||||||
{
|
|
||||||
unsigned char l,a;
|
|
||||||
};
|
|
||||||
|
|
||||||
TrueTypeRasterizer::TrueTypeRasterizer(FT_Library library, Data *data, int size)
|
TrueTypeRasterizer::TrueTypeRasterizer(FT_Library library, Data *data, int size)
|
||||||
: data(data)
|
: data(data)
|
||||||
{
|
{
|
||||||
data->retain();
|
|
||||||
|
|
||||||
if (FT_New_Memory_Face(library,
|
if (FT_New_Memory_Face(library,
|
||||||
(const FT_Byte *)data->getData(), /* first byte in memory */
|
(const FT_Byte *)data->getData(), /* first byte in memory */
|
||||||
data->getSize(), /* size in bytes */
|
data->getSize(), /* size in bytes */
|
||||||
@@ -55,6 +48,8 @@ TrueTypeRasterizer::TrueTypeRasterizer(FT_Library library, Data *data, int size)
|
|||||||
metrics.ascent = s.ascender >> 6;
|
metrics.ascent = s.ascender >> 6;
|
||||||
metrics.descent = s.descender >> 6;
|
metrics.descent = s.descender >> 6;
|
||||||
metrics.height = s.height >> 6;
|
metrics.height = s.height >> 6;
|
||||||
|
|
||||||
|
data->retain();
|
||||||
}
|
}
|
||||||
|
|
||||||
TrueTypeRasterizer::~TrueTypeRasterizer()
|
TrueTypeRasterizer::~TrueTypeRasterizer()
|
||||||
@@ -81,7 +76,7 @@ GlyphData *TrueTypeRasterizer::getGlyphData(unsigned int glyph) const
|
|||||||
throw love::Exception("TrueTypeFont Loading vm->error: FT_Get_Glyph failed\n");
|
throw love::Exception("TrueTypeFont Loading vm->error: FT_Get_Glyph failed\n");
|
||||||
|
|
||||||
FT_Glyph_To_Bitmap(&ftglyph, FT_RENDER_MODE_NORMAL, 0, 1);
|
FT_Glyph_To_Bitmap(&ftglyph, FT_RENDER_MODE_NORMAL, 0, 1);
|
||||||
FT_BitmapGlyph bitmap_glyph = (FT_BitmapGlyph)ftglyph;
|
FT_BitmapGlyph bitmap_glyph = (FT_BitmapGlyph) ftglyph;
|
||||||
FT_Bitmap &bitmap = bitmap_glyph->bitmap; //just to make things easier
|
FT_Bitmap &bitmap = bitmap_glyph->bitmap; //just to make things easier
|
||||||
|
|
||||||
// Get metrics
|
// Get metrics
|
||||||
@@ -93,18 +88,16 @@ GlyphData *TrueTypeRasterizer::getGlyphData(unsigned int glyph) const
|
|||||||
|
|
||||||
GlyphData *glyphData = new GlyphData(glyph, glyphMetrics, GlyphData::FORMAT_LUMINANCE_ALPHA);
|
GlyphData *glyphData = new GlyphData(glyph, glyphMetrics, GlyphData::FORMAT_LUMINANCE_ALPHA);
|
||||||
|
|
||||||
{
|
int size = bitmap.rows * bitmap.width;
|
||||||
int size = bitmap.rows*bitmap.width;
|
unsigned char *dst = (unsigned char *) glyphData->getData();
|
||||||
unsigned char *dst = (unsigned char *)glyphData->getData();
|
|
||||||
|
|
||||||
// Note that bitmap.buffer contains only luminosity. We copy that single value to
|
// Note that bitmap.buffer contains only luminosity. We copy that single value to
|
||||||
// our luminosity-alpha format.
|
// our luminosity-alpha format.
|
||||||
for (int i = 0; i<size; i++)
|
for (int i = 0; i < size; i++)
|
||||||
{
|
{
|
||||||
dst[2*i] = 255;
|
dst[2*i] = 255;
|
||||||
dst[2*i+1] = bitmap.buffer[i];
|
dst[2*i+1] = bitmap.buffer[i];
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Having copied the data over, we can destroy the glyph
|
// Having copied the data over, we can destroy the glyph
|
||||||
FT_Done_Glyph(ftglyph);
|
FT_Done_Glyph(ftglyph);
|
||||||
@@ -115,7 +108,7 @@ GlyphData *TrueTypeRasterizer::getGlyphData(unsigned int glyph) const
|
|||||||
|
|
||||||
int TrueTypeRasterizer::getNumGlyphs() const
|
int TrueTypeRasterizer::getNumGlyphs() const
|
||||||
{
|
{
|
||||||
return 256;
|
return face->num_glyphs;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // freetype
|
} // freetype
|
||||||
|
|||||||
Reference in New Issue
Block a user