mirror of
https://github.com/love2d/love.git
synced 2026-08-17 19:23:38 +02:00
Cleaned up the GlyphData code.
This commit is contained in:
@@ -40,18 +40,7 @@ GlyphData::GlyphData(uint32 glyph, GlyphMetrics glyphMetrics, GlyphData::Format
|
|||||||
, format(f)
|
, format(f)
|
||||||
{
|
{
|
||||||
if (metrics.width > 0 && metrics.height > 0)
|
if (metrics.width > 0 && metrics.height > 0)
|
||||||
{
|
data = new uint8[metrics.width * metrics.height * getPixelSize()];
|
||||||
switch (f)
|
|
||||||
{
|
|
||||||
case GlyphData::FORMAT_LUMINANCE_ALPHA:
|
|
||||||
data = new unsigned char[metrics.width * metrics.height * 2];
|
|
||||||
break;
|
|
||||||
case GlyphData::FORMAT_RGBA:
|
|
||||||
default:
|
|
||||||
data = new unsigned char[metrics.width * metrics.height * 4];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GlyphData::~GlyphData()
|
GlyphData::~GlyphData()
|
||||||
@@ -61,22 +50,30 @@ GlyphData::~GlyphData()
|
|||||||
|
|
||||||
void *GlyphData::getData() const
|
void *GlyphData::getData() const
|
||||||
{
|
{
|
||||||
return (void *) data;
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t GlyphData::getPixelSize() const
|
||||||
|
{
|
||||||
|
switch (format)
|
||||||
|
{
|
||||||
|
case FORMAT_LUMINANCE_ALPHA:
|
||||||
|
return 2;
|
||||||
|
case FORMAT_RGBA:
|
||||||
|
default:
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void *GlyphData::getData(int x, int y) const
|
||||||
|
{
|
||||||
|
size_t offset = (y * getWidth() + x) * getPixelSize();
|
||||||
|
return data + offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t GlyphData::getSize() const
|
size_t GlyphData::getSize() const
|
||||||
{
|
{
|
||||||
switch (format)
|
return size_t(getWidth() * getHeight()) * getPixelSize();
|
||||||
{
|
|
||||||
case GlyphData::FORMAT_LUMINANCE_ALPHA:
|
|
||||||
return size_t(getWidth() * getHeight() * 2);
|
|
||||||
break;
|
|
||||||
case GlyphData::FORMAT_RGBA:
|
|
||||||
default:
|
|
||||||
return size_t(getWidth() * getHeight() * 4);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int GlyphData::getHeight() const
|
int GlyphData::getHeight() const
|
||||||
@@ -133,22 +130,22 @@ int GlyphData::getBearingY() const
|
|||||||
|
|
||||||
int GlyphData::getMinX() const
|
int GlyphData::getMinX() const
|
||||||
{
|
{
|
||||||
return this->getBearingX();
|
return getBearingX();
|
||||||
}
|
}
|
||||||
|
|
||||||
int GlyphData::getMinY() const
|
int GlyphData::getMinY() const
|
||||||
{
|
{
|
||||||
return this->getHeight() - this->getBearingY();
|
return getHeight() - getBearingY();
|
||||||
}
|
}
|
||||||
|
|
||||||
int GlyphData::getMaxX() const
|
int GlyphData::getMaxX() const
|
||||||
{
|
{
|
||||||
return this->getBearingX() + this->getWidth();
|
return getBearingX() + getWidth();
|
||||||
}
|
}
|
||||||
|
|
||||||
int GlyphData::getMaxY() const
|
int GlyphData::getMaxY() const
|
||||||
{
|
{
|
||||||
return this->getBearingY();
|
return getBearingY();
|
||||||
}
|
}
|
||||||
|
|
||||||
GlyphData::Format GlyphData::getFormat() const
|
GlyphData::Format GlyphData::getFormat() const
|
||||||
@@ -168,8 +165,8 @@ bool GlyphData::getConstant(GlyphData::Format in, const char *&out)
|
|||||||
|
|
||||||
StringMap<GlyphData::Format, GlyphData::FORMAT_MAX_ENUM>::Entry GlyphData::formatEntries[] =
|
StringMap<GlyphData::Format, GlyphData::FORMAT_MAX_ENUM>::Entry GlyphData::formatEntries[] =
|
||||||
{
|
{
|
||||||
{"luminancealpha", GlyphData::FORMAT_LUMINANCE_ALPHA},
|
{"luminancealpha", FORMAT_LUMINANCE_ALPHA},
|
||||||
{"rgba", GlyphData::FORMAT_RGBA},
|
{"rgba", FORMAT_RGBA},
|
||||||
};
|
};
|
||||||
|
|
||||||
StringMap<GlyphData::Format, GlyphData::FORMAT_MAX_ENUM> GlyphData::formats(GlyphData::formatEntries, sizeof(GlyphData::formatEntries));
|
StringMap<GlyphData::Format, GlyphData::FORMAT_MAX_ENUM> GlyphData::formats(GlyphData::formatEntries, sizeof(GlyphData::formatEntries));
|
||||||
|
|||||||
@@ -69,6 +69,16 @@ public:
|
|||||||
void *getData() const;
|
void *getData() const;
|
||||||
size_t getSize() const;
|
size_t getSize() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the data starting at a specific pixel in the glyph.
|
||||||
|
**/
|
||||||
|
void *getData(int x, int y) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the size in bytes of each pixel in the glyph.
|
||||||
|
**/
|
||||||
|
size_t getPixelSize() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the height of the glyph.
|
* Gets the height of the glyph.
|
||||||
**/
|
**/
|
||||||
@@ -141,7 +151,7 @@ private:
|
|||||||
GlyphMetrics metrics;
|
GlyphMetrics metrics;
|
||||||
|
|
||||||
// Glyph texture data.
|
// Glyph texture data.
|
||||||
unsigned char *data;
|
uint8 *data;
|
||||||
|
|
||||||
// The format the data's in.
|
// The format the data's in.
|
||||||
Format format;
|
Format format;
|
||||||
|
|||||||
Reference in New Issue
Block a user