mirror of
https://github.com/love2d/love.git
synced 2026-08-18 11:44:15 +02:00
did a bunch of other stuff, sorry about the monolithic changeset but the diffs should be understandable enough
This commit is contained in:
@@ -50,7 +50,7 @@ namespace font
|
||||
return MAX_CHARS;
|
||||
}
|
||||
|
||||
GlyphData * FontData::getGlyph(unsigned short glyph) const
|
||||
GlyphData * FontData::getGlyphData(unsigned short glyph) const
|
||||
{
|
||||
return data[glyph];
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace font
|
||||
void * getData() const;
|
||||
int getSize() const;
|
||||
|
||||
GlyphData * getGlyph(unsigned short glyph) const;
|
||||
GlyphData * getGlyphData(unsigned short glyph) const;
|
||||
int getHeight() const;
|
||||
|
||||
static const unsigned int MAX_CHARS = 256;
|
||||
|
||||
@@ -25,10 +25,20 @@ namespace love
|
||||
namespace font
|
||||
{
|
||||
|
||||
GlyphData::GlyphData(unsigned short glyph, GlyphMetrics glyphMetrics)
|
||||
: glyph(glyph), metrics(glyphMetrics)
|
||||
GlyphData::GlyphData(unsigned short glyph, GlyphMetrics glyphMetrics, GlyphData::Format f)
|
||||
: glyph(glyph), metrics(glyphMetrics), format(f)
|
||||
{
|
||||
data = new unsigned char[getWidth() * getHeight() * 4];
|
||||
if (getWidth() && getHeight()) {
|
||||
switch (f) {
|
||||
case GlyphData::FORMAT_LUMINOSITY_ALPHA:
|
||||
data = new unsigned char[getWidth() * getHeight() * 2];
|
||||
break;
|
||||
case GlyphData::FORMAT_RGBA:
|
||||
default:
|
||||
data = new unsigned char[getWidth() * getHeight() * 4];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GlyphData::~GlyphData()
|
||||
@@ -43,7 +53,16 @@ namespace font
|
||||
|
||||
int GlyphData::getSize() const
|
||||
{
|
||||
return getWidth() * getHeight() * 4;
|
||||
switch(format) {
|
||||
case GlyphData::FORMAT_LUMINOSITY_ALPHA:
|
||||
return getWidth() * getHeight() * 2;
|
||||
break;
|
||||
case GlyphData::FORMAT_RGBA:
|
||||
default:
|
||||
return getWidth() * getHeight() * 4;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int GlyphData::getHeight() const
|
||||
@@ -90,6 +109,11 @@ namespace font
|
||||
{
|
||||
return this->getBearingY();
|
||||
}
|
||||
|
||||
GlyphData::Format GlyphData::getFormat() const
|
||||
{
|
||||
return format;
|
||||
}
|
||||
|
||||
} // font
|
||||
} // love
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2010 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
/**
|
||||
* Copyright (c) 2006-2010 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_FONT_GLYPH_DATA_H
|
||||
@@ -29,16 +29,17 @@ namespace love
|
||||
{
|
||||
namespace font
|
||||
{
|
||||
/**
|
||||
* Holds the specific glyph data.
|
||||
**/
|
||||
struct GlyphMetrics
|
||||
{
|
||||
int height;
|
||||
int width;
|
||||
int advance;
|
||||
int bearingX;
|
||||
int bearingY;
|
||||
/**
|
||||
* Holds the specific glyph data.
|
||||
**/
|
||||
struct GlyphMetrics
|
||||
{
|
||||
int height;
|
||||
int width;
|
||||
int advance;
|
||||
int bearingX;
|
||||
int bearingY;
|
||||
int spacing;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -46,22 +47,19 @@ namespace font
|
||||
**/
|
||||
class GlyphData : public Data
|
||||
{
|
||||
private:
|
||||
// The glyph itself
|
||||
unsigned short glyph;
|
||||
|
||||
// Glyph metrics
|
||||
GlyphMetrics metrics;
|
||||
|
||||
// Glyph texture data
|
||||
unsigned char * data;
|
||||
|
||||
public:
|
||||
GlyphData(unsigned short glyph, GlyphMetrics glyphMetrics);
|
||||
enum Format
|
||||
{
|
||||
FORMAT_LUMINOSITY_ALPHA,
|
||||
FORMAT_RGBA
|
||||
};
|
||||
|
||||
GlyphData(unsigned short glyph, GlyphMetrics glyphMetrics, Format f);
|
||||
virtual ~GlyphData();
|
||||
|
||||
// Implements Data.
|
||||
void * getData() const;
|
||||
// Implements Data.
|
||||
void * getData() const;
|
||||
int getSize() const;
|
||||
|
||||
/**
|
||||
@@ -108,6 +106,24 @@ namespace font
|
||||
* Gets the max y value of the glyph.
|
||||
**/
|
||||
int getMaxY() const;
|
||||
|
||||
/**
|
||||
* Gets the format of the glyph data.
|
||||
**/
|
||||
Format getFormat() const;
|
||||
|
||||
private:
|
||||
// The glyph itself
|
||||
unsigned short glyph;
|
||||
|
||||
// Glyph metrics
|
||||
GlyphMetrics metrics;
|
||||
|
||||
// Glyph texture data
|
||||
unsigned char * data;
|
||||
|
||||
// The format the data's in
|
||||
Format format;
|
||||
|
||||
}; // GlyphData
|
||||
|
||||
|
||||
@@ -38,8 +38,11 @@ namespace font
|
||||
{
|
||||
imageData->retain();
|
||||
positions = new unsigned int[MAX_CHARS];
|
||||
memset(positions, 0, MAX_CHARS*4);
|
||||
widths = new unsigned int[MAX_CHARS];
|
||||
memset(widths, 0, MAX_CHARS*4);
|
||||
spacing = new unsigned int[MAX_CHARS];
|
||||
memset(spacing, 0, MAX_CHARS*4);
|
||||
load();
|
||||
}
|
||||
|
||||
@@ -61,11 +64,15 @@ namespace font
|
||||
GlyphMetrics gm;
|
||||
gm.height = metrics.height;
|
||||
gm.width = widths[glyph];
|
||||
GlyphData * g = new GlyphData(glyph, gm);
|
||||
gm.advance = spacing[glyph] + widths[glyph];
|
||||
gm.bearingX = 0;
|
||||
gm.bearingY = 0;
|
||||
GlyphData * g = new GlyphData(glyph, gm, GlyphData::FORMAT_RGBA);
|
||||
if (gm.width == 0) return g;
|
||||
unsigned char * gd = (unsigned char*)g->getData();
|
||||
love::image::pixel * pixels = (love::image::pixel *)(imageData->getData());
|
||||
for (unsigned int i = positions[glyph]; i < positions[glyph] + widths[glyph]; i++) {
|
||||
love::image::pixel p = pixels[i];
|
||||
for (unsigned int i = 0; i < widths[glyph]*getHeight(); i++) {
|
||||
love::image::pixel p = pixels[ positions[glyph] + (i % widths[glyph]) + (imageData->getWidth() * (i / widths[glyph])) ];
|
||||
gd[i*4] = p.r;
|
||||
gd[i*4+1] = p.g;
|
||||
gd[i*4+2] = p.b;
|
||||
@@ -132,6 +139,11 @@ namespace font
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int ImageRasterizer::getNumGlyphs() const
|
||||
{
|
||||
return length;
|
||||
}
|
||||
|
||||
} // font
|
||||
} // love
|
||||
@@ -59,6 +59,7 @@ namespace font
|
||||
// Implement Rasterizer
|
||||
virtual int getLineHeight() const;
|
||||
virtual GlyphData * getGlyphData(unsigned short glyph) const;
|
||||
virtual int getNumGlyphs() const;
|
||||
|
||||
static const unsigned int MAX_CHARS = 256;
|
||||
|
||||
|
||||
@@ -82,6 +82,11 @@ namespace font
|
||||
* @param glyph The (UNICODE) glyph to get data for
|
||||
**/
|
||||
virtual GlyphData * getGlyphData(unsigned short glyph) const = 0;
|
||||
|
||||
/**
|
||||
* Gets the number of glyphs the rasterizer has data for.
|
||||
**/
|
||||
virtual int getNumGlyphs() const = 0;
|
||||
|
||||
|
||||
}; // Rasterizer
|
||||
|
||||
@@ -46,10 +46,11 @@ namespace freetype
|
||||
FT_Set_Pixel_Sizes(face, size, size);
|
||||
|
||||
// Set global metrics
|
||||
metrics.advance = face->max_advance_width;
|
||||
metrics.ascent = face->ascender;
|
||||
metrics.descent = face->descender;
|
||||
metrics.height = face->height;
|
||||
FT_Size_Metrics s = face->size->metrics;
|
||||
metrics.advance = s.max_advance >> 6;
|
||||
metrics.ascent = s.ascender >> 6;
|
||||
metrics.descent = s.descender >> 6;
|
||||
metrics.height = s.height >> 6;
|
||||
}
|
||||
|
||||
TrueTypeRasterizer::~TrueTypeRasterizer()
|
||||
@@ -80,23 +81,24 @@ namespace freetype
|
||||
FT_Bitmap& bitmap = bitmap_glyph->bitmap; //just to make things easier
|
||||
|
||||
// Get metrics
|
||||
glyphMetrics.bearingX = face->glyph->metrics.horiBearingX;
|
||||
glyphMetrics.bearingY = face->glyph->metrics.horiBearingY;
|
||||
glyphMetrics.bearingX = face->glyph->metrics.horiBearingX >> 6;
|
||||
glyphMetrics.bearingY = face->glyph->metrics.horiBearingY >> 6;
|
||||
glyphMetrics.height = bitmap.rows;
|
||||
glyphMetrics.width = bitmap.width;
|
||||
glyphMetrics.advance = face->glyph->advance.x >> 6;
|
||||
glyphMetrics.advance = face->glyph->metrics.horiAdvance >> 6;
|
||||
|
||||
GlyphData * glyphData = new GlyphData(glyph, glyphMetrics);
|
||||
GlyphData * glyphData = new GlyphData(glyph, glyphMetrics, GlyphData::FORMAT_RGBA);
|
||||
|
||||
{
|
||||
int size = bitmap.rows*bitmap.width;
|
||||
unsigned char * dst = (unsigned char *)glyphData->getData();
|
||||
|
||||
// Note that bitmap.buffer contains only luminosity. We copy that single value to
|
||||
// our rgba format.
|
||||
// our luminosity-alpha format.
|
||||
for(int i = 0; i<size; i++)
|
||||
{
|
||||
dst[4*i] = dst[4*i+1] = dst[4*i+2] = dst[4*i+3] = bitmap.buffer[i];
|
||||
dst[4*i] = dst[4*i+1] = dst[4*i+2] = 255;
|
||||
dst[4*i+3] = bitmap.buffer[i];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,6 +108,11 @@ namespace freetype
|
||||
// Return data
|
||||
return glyphData;
|
||||
}
|
||||
|
||||
int TrueTypeRasterizer::getNumGlyphs() const
|
||||
{
|
||||
return 256;
|
||||
}
|
||||
|
||||
} // freetype
|
||||
} // font
|
||||
|
||||
@@ -63,6 +63,7 @@ namespace freetype
|
||||
// Implement Rasterizer
|
||||
virtual int getLineHeight() const;
|
||||
virtual GlyphData * getGlyphData(unsigned short glyph) const;
|
||||
virtual int getNumGlyphs() const;
|
||||
|
||||
}; // FreetypeRasterizer
|
||||
|
||||
|
||||
Reference in New Issue
Block a user