From 9d38cba626403e6c38e92abbd6c24289da9f0cbc Mon Sep 17 00:00:00 2001 From: Bill Meltsner Date: Sat, 5 Mar 2011 23:37:36 -0500 Subject: [PATCH] brutally murdered padding and predefined glyph loading --HG-- branch : newfont --- src/modules/font/GlyphData.cpp | 73 +------------------ src/modules/font/GlyphData.h | 30 -------- src/modules/font/ImageRasterizer.cpp | 1 - .../font/freetype/TrueTypeRasterizer.cpp | 3 - src/modules/graphics/opengl/Font.cpp | 15 +--- src/modules/graphics/opengl/Font.h | 9 --- 6 files changed, 7 insertions(+), 124 deletions(-) diff --git a/src/modules/font/GlyphData.cpp b/src/modules/font/GlyphData.cpp index 1f9f16944..a688038da 100644 --- a/src/modules/font/GlyphData.cpp +++ b/src/modules/font/GlyphData.cpp @@ -28,7 +28,7 @@ namespace font { 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) { switch (f) { @@ -69,12 +69,12 @@ namespace font int GlyphData::getHeight() const { - return (padded ? getPaddedHeight() : metrics.height); + return metrics.height; } int GlyphData::getWidth() const { - return (padded ? getPaddedWidth() : metrics.width); + return metrics.width; } int GlyphData::getAdvance() const @@ -116,71 +116,6 @@ namespace font { 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 } // love diff --git a/src/modules/font/GlyphData.h b/src/modules/font/GlyphData.h index 440e00fb4..bc8e4b031 100644 --- a/src/modules/font/GlyphData.h +++ b/src/modules/font/GlyphData.h @@ -112,33 +112,6 @@ namespace font **/ 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: // The glyph itself unsigned short glyph; @@ -151,9 +124,6 @@ namespace font // The format the data's in Format format; - - // Padded? - bool padded; }; // GlyphData diff --git a/src/modules/font/ImageRasterizer.cpp b/src/modules/font/ImageRasterizer.cpp index 94cca67b6..cfa222a20 100644 --- a/src/modules/font/ImageRasterizer.cpp +++ b/src/modules/font/ImageRasterizer.cpp @@ -79,7 +79,6 @@ namespace font gd[i*4+2] = p.b; gd[i*4+3] = p.a; } - g->pad(); return g; } diff --git a/src/modules/font/freetype/TrueTypeRasterizer.cpp b/src/modules/font/freetype/TrueTypeRasterizer.cpp index cf0cc0dd5..ce5a0e2a1 100644 --- a/src/modules/font/freetype/TrueTypeRasterizer.cpp +++ b/src/modules/font/freetype/TrueTypeRasterizer.cpp @@ -104,9 +104,6 @@ namespace freetype // Having copied the data over, we can destroy the glyph FT_Done_Glyph(ftglyph); - - // Pad the GlyphData for graphics cards that don't support npo2 textures - glyphData->pad(); // Return data return glyphData; diff --git a/src/modules/graphics/opengl/Font.cpp b/src/modules/graphics/opengl/Font.cpp index bf2b40be0..43dcad8b1 100644 --- a/src/modules/graphics/opengl/Font.cpp +++ b/src/modules/graphics/opengl/Font.cpp @@ -34,18 +34,9 @@ namespace opengl Font::Font(love::font::Rasterizer * r, const Image::Filter& filter) : rasterizer(r), height(r->getHeight()), lineHeight(1), mSpacing(1) { - type = FONT_UNKNOWN; - love::font::GlyphData * 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); - } + love::font::GlyphData * gd = r->getGlyphData(0); + type = (gd->getFormat() == love::font::GlyphData::FORMAT_LUMINANCE_ALPHA ? FONT_TRUETYPE : FONT_IMAGE); + delete gd; } Font::~Font() diff --git a/src/modules/graphics/opengl/Font.h b/src/modules/graphics/opengl/Font.h index 7b9b62920..e1c4f3902 100644 --- a/src/modules/graphics/opengl/Font.h +++ b/src/modules/graphics/opengl/Font.h @@ -57,15 +57,6 @@ namespace opengl FontType type; 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.