mirror of
https://github.com/love2d/love.git
synced 2026-08-19 12:14:20 +02:00
LÖVE will now try to guess the line height for BMFont files which are missing the 'lineHeight' attribute.
--HG-- branch : minor
This commit is contained in:
@@ -26,6 +26,7 @@
|
|||||||
// C++
|
// C++
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
// C
|
// C
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
@@ -174,7 +175,6 @@ void BMFontRasterizer::parseConfig(const std::string &configtext)
|
|||||||
{
|
{
|
||||||
lineHeight = cline.getAttributeInt("lineHeight");
|
lineHeight = cline.getAttributeInt("lineHeight");
|
||||||
metrics.ascent = cline.getAttributeInt("base");
|
metrics.ascent = cline.getAttributeInt("base");
|
||||||
metrics.height = lineHeight;
|
|
||||||
}
|
}
|
||||||
else if (tag == "page")
|
else if (tag == "page")
|
||||||
{
|
{
|
||||||
@@ -230,12 +230,12 @@ void BMFontRasterizer::parseConfig(const std::string &configtext)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lineHeight == 0)
|
|
||||||
throw love::Exception("Invalid BMFont file (missing line height attribute?)");
|
|
||||||
|
|
||||||
if (characters.size() == 0)
|
if (characters.size() == 0)
|
||||||
throw love::Exception("Invalid BMFont file (no character definitions?)");
|
throw love::Exception("Invalid BMFont file (no character definitions?)");
|
||||||
|
|
||||||
|
// Try to guess the line height if the lineheight attribute isn't found.
|
||||||
|
bool guessheight = lineHeight == 0;
|
||||||
|
|
||||||
// Verify the glyph character attributes.
|
// Verify the glyph character attributes.
|
||||||
for (const auto &cpair : characters)
|
for (const auto &cpair : characters)
|
||||||
{
|
{
|
||||||
@@ -251,7 +251,12 @@ void BMFontRasterizer::parseConfig(const std::string &configtext)
|
|||||||
|
|
||||||
if (!id->inside(c.x, c.y) || !id->inside(c.x + c.metrics.width, c.y + c.metrics.height))
|
if (!id->inside(c.x, c.y) || !id->inside(c.x + c.metrics.width, c.y + c.metrics.height))
|
||||||
throw love::Exception("Invalid BMFont character coordinates.");
|
throw love::Exception("Invalid BMFont character coordinates.");
|
||||||
|
|
||||||
|
if (guessheight)
|
||||||
|
lineHeight = std::max(lineHeight, c.metrics.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
metrics.height = lineHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BMFontRasterizer::getLineHeight() const
|
int BMFontRasterizer::getLineHeight() const
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#define LOVE_FONT_BMFONT_RASTERIZER_H
|
#define LOVE_FONT_BMFONT_RASTERIZER_H
|
||||||
|
|
||||||
// LOVE
|
// LOVE
|
||||||
|
#include "common/config.h"
|
||||||
#include "Rasterizer.h"
|
#include "Rasterizer.h"
|
||||||
#include "image/ImageData.h"
|
#include "image/ImageData.h"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user