brutally murdered padding and predefined glyph loading

--HG--
branch : newfont
This commit is contained in:
Bill Meltsner
2011-03-05 23:37:36 -05:00
parent 94b4319878
commit 9d38cba626
6 changed files with 7 additions and 124 deletions
+4 -69
View File
@@ -28,7 +28,7 @@ namespace font
{ {
GlyphData::GlyphData(unsigned short glyph, GlyphMetrics glyphMetrics, GlyphData::Format f) GlyphData::GlyphData(unsigned short glyph, GlyphMetrics glyphMetrics, GlyphData::Format f)
: glyph(glyph), metrics(glyphMetrics), data(0), format(f), padded(false) : glyph(glyph), metrics(glyphMetrics), data(0), format(f)
{ {
if (metrics.width && metrics.height) { if (metrics.width && metrics.height) {
switch (f) { switch (f) {
@@ -69,12 +69,12 @@ namespace font
int GlyphData::getHeight() const int GlyphData::getHeight() const
{ {
return (padded ? getPaddedHeight() : metrics.height); return metrics.height;
} }
int GlyphData::getWidth() const int GlyphData::getWidth() const
{ {
return (padded ? getPaddedWidth() : metrics.width); return metrics.width;
} }
int GlyphData::getAdvance() const int GlyphData::getAdvance() const
@@ -116,71 +116,6 @@ namespace font
{ {
return format; return format;
} }
void GlyphData::pad()
{
if (data == 0)
return;
int w = getWidth();
int h = getHeight();
int pw = next_p2(w);
int ph = next_p2(h);
unsigned char * d = new unsigned char[pw * ph * (format == GlyphData::FORMAT_LUMINANCE_ALPHA ? 2 : 4)];
for (int j = 0; j < ph; j++) {
for (int i = 0; i < pw; i++) {
int n = i+j*w;
int p = i+j*pw;
if (i < w && j < h) {
if (format == GlyphData::FORMAT_LUMINANCE_ALPHA) {
p *= 2;
n *= 2;
d[p] = data[n];
d[p+1] = data[n+1];
} else {
p *= 4;
n *= 4;
d[p] = data[n];
d[p+1] = data[n+1];
d[p+2] = data[n+2];
d[p+3] = data[n+3];
}
} else {
if (format == GlyphData::FORMAT_LUMINANCE_ALPHA) {
p *= 2;
d[p] = d[p+1] = 0;
} else {
p *= 4;
d[p] = d[p+1] = d[p+2] = d[p+3] = 0;
}
}
}
}
delete[] data;
data = d;
padded = true;
}
bool GlyphData::isPadded() const
{
return padded;
}
int GlyphData::getPaddedWidth() const
{
return next_p2(metrics.width);
}
int GlyphData::getPaddedHeight() const
{
return next_p2(metrics.height);
}
inline int GlyphData::next_p2(int num) const
{
int powered = 2;
while(powered < num) powered <<= 1;
return powered;
}
} // font } // font
} // love } // love
-30
View File
@@ -112,33 +112,6 @@ namespace font
**/ **/
Format getFormat() const; Format getFormat() const;
/**
* Returns the closest number to num which is a power of two.
*
* @param num The number to be 2powered.
**/
inline int next_p2(int num) const;
/**
* Pads the data to fit into a power-of-2 texture.
**/
void pad();
/**
* Returns whether the data has been padded.
**/
bool isPadded() const;
/**
* Returns the padded width.
**/
int getPaddedWidth() const;
/**
* Returns the padded height.
**/
int getPaddedHeight() const;
private: private:
// The glyph itself // The glyph itself
unsigned short glyph; unsigned short glyph;
@@ -151,9 +124,6 @@ namespace font
// The format the data's in // The format the data's in
Format format; Format format;
// Padded?
bool padded;
}; // GlyphData }; // GlyphData
-1
View File
@@ -79,7 +79,6 @@ namespace font
gd[i*4+2] = p.b; gd[i*4+2] = p.b;
gd[i*4+3] = p.a; gd[i*4+3] = p.a;
} }
g->pad();
return g; return g;
} }
@@ -104,9 +104,6 @@ namespace freetype
// 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);
// Pad the GlyphData for graphics cards that don't support npo2 textures
glyphData->pad();
// Return data // Return data
return glyphData; return glyphData;
+3 -12
View File
@@ -34,18 +34,9 @@ namespace opengl
Font::Font(love::font::Rasterizer * r, const Image::Filter& filter) Font::Font(love::font::Rasterizer * r, const Image::Filter& filter)
: rasterizer(r), height(r->getHeight()), lineHeight(1), mSpacing(1) : rasterizer(r), height(r->getHeight()), lineHeight(1), mSpacing(1)
{ {
type = FONT_UNKNOWN; love::font::GlyphData * gd = r->getGlyphData(0);
love::font::GlyphData * gd; type = (gd->getFormat() == love::font::GlyphData::FORMAT_LUMINANCE_ALPHA ? FONT_TRUETYPE : FONT_IMAGE);
delete gd;
for(unsigned int i = 0; i < MAX_CHARS; i++)
{
gd = r->getGlyphData(i);
widths[i] = gd->getWidth();
spacing[i] = gd->getAdvance();
bearingX[i] = gd->getBearingX();
bearingY[i] = gd->getBearingY();
if (type == FONT_UNKNOWN) type = (gd->getFormat() == love::font::GlyphData::FORMAT_LUMINANCE_ALPHA ? FONT_TRUETYPE : FONT_IMAGE);
}
} }
Font::~Font() Font::~Font()
-9
View File
@@ -57,15 +57,6 @@ namespace opengl
FontType type; FontType type;
public: public:
static const unsigned int MAX_CHARS = 256;
// The widths of each character.
int widths[MAX_CHARS];
// The spacing of each character.
int spacing[MAX_CHARS];
// The X-bearing of each character.
int bearingX[MAX_CHARS];
// The Y-bearing of each character.
int bearingY[MAX_CHARS];
/** /**
* Default constructor. * Default constructor.