mirror of
https://github.com/love2d/love.git
synced 2026-08-16 00:02:12 +02:00
Cleaned up some duplicated pixel format-related code in Font files.
--HG-- branch : minor
This commit is contained in:
@@ -35,12 +35,15 @@ namespace font
|
||||
|
||||
love::Type GlyphData::type("GlyphData", &Data::type);
|
||||
|
||||
GlyphData::GlyphData(uint32 glyph, GlyphMetrics glyphMetrics, GlyphData::Format f)
|
||||
GlyphData::GlyphData(uint32 glyph, GlyphMetrics glyphMetrics, PixelFormat f)
|
||||
: glyph(glyph)
|
||||
, metrics(glyphMetrics)
|
||||
, data(nullptr)
|
||||
, format(f)
|
||||
{
|
||||
if (f != PIXELFORMAT_LA8 && f != PIXELFORMAT_RGBA8)
|
||||
throw love::Exception("Invalid GlyphData pixel format.");
|
||||
|
||||
if (metrics.width > 0 && metrics.height > 0)
|
||||
data = new uint8[metrics.width * metrics.height * getPixelSize()];
|
||||
}
|
||||
@@ -57,14 +60,7 @@ void *GlyphData::getData() const
|
||||
|
||||
size_t GlyphData::getPixelSize() const
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
case FORMAT_LUMINANCE_ALPHA:
|
||||
return 2;
|
||||
case FORMAT_RGBA:
|
||||
default:
|
||||
return 4;
|
||||
}
|
||||
return getPixelFormatSize(format);
|
||||
}
|
||||
|
||||
void *GlyphData::getData(int x, int y) const
|
||||
@@ -150,28 +146,10 @@ int GlyphData::getMaxY() const
|
||||
return getBearingY();
|
||||
}
|
||||
|
||||
GlyphData::Format GlyphData::getFormat() const
|
||||
PixelFormat GlyphData::getFormat() const
|
||||
{
|
||||
return format;
|
||||
}
|
||||
|
||||
bool GlyphData::getConstant(const char *in, GlyphData::Format &out)
|
||||
{
|
||||
return formats.find(in, out);
|
||||
}
|
||||
|
||||
bool GlyphData::getConstant(GlyphData::Format in, const char *&out)
|
||||
{
|
||||
return formats.find(in, out);
|
||||
}
|
||||
|
||||
StringMap<GlyphData::Format, GlyphData::FORMAT_MAX_ENUM>::Entry GlyphData::formatEntries[] =
|
||||
{
|
||||
{"luminancealpha", FORMAT_LUMINANCE_ALPHA},
|
||||
{"rgba", FORMAT_RGBA},
|
||||
};
|
||||
|
||||
StringMap<GlyphData::Format, GlyphData::FORMAT_MAX_ENUM> GlyphData::formats(GlyphData::formatEntries, sizeof(GlyphData::formatEntries));
|
||||
|
||||
} // font
|
||||
} // love
|
||||
|
||||
Reference in New Issue
Block a user