font rendering: reimplement tab-as-spaces support.

This commit is contained in:
Sasha Szpakowski
2022-12-28 19:46:48 -04:00
parent 7a0f6621e7
commit 9502942b7b
7 changed files with 136 additions and 78 deletions
-23
View File
@@ -61,7 +61,6 @@ Font::Font(love::font::Rasterizer *r, const SamplerState &s)
, textureHeight(128)
, samplerState()
, dpiScale(r->getDPIScale())
, useSpacesAsTab(false)
, textureCacheID(0)
{
samplerState.minFilter = s.minFilter;
@@ -92,10 +91,6 @@ Font::Font(love::font::Rasterizer *r, const SamplerState &s)
if (pixelFormat == PIXELFORMAT_LA8_UNORM && !gfx->isPixelFormatSupported(pixelFormat, PIXELFORMATUSAGEFLAGS_SAMPLE))
pixelFormat = PIXELFORMAT_RGBA8_UNORM;
uint32 tab = '\t';
if (!r->hasGlyph(tab)) // No tab character in the Rasterizer.
useSpacesAsTab = true;
loadVolatile();
++fontCount;
}
@@ -232,24 +227,6 @@ void Font::unloadVolatile()
love::font::GlyphData *Font::getRasterizerGlyphData(love::font::TextShaper::GlyphIndex glyphindex, float &dpiscale)
{
const auto &r = shaper->getRasterizers()[glyphindex.rasterizerIndex];
// Use spaces for the tab 'glyph'. FIXME
if (/*glyph == '\t' &&*/ false && useSpacesAsTab)
{
love::font::GlyphData *spacegd = r->getGlyphData(32);
PixelFormat fmt = spacegd->getFormat();
love::font::GlyphMetrics gm = {};
gm.advance = spacegd->getAdvance() * SPACES_PER_TAB;
gm.bearingX = spacegd->getBearingX();
gm.bearingY = spacegd->getBearingY();
spacegd->release();
dpiscale = r->getDPIScale();
return new love::font::GlyphData('\t', gm, fmt);
}
dpiscale = r->getDPIScale();
return r->getGlyphDataForIndex(glyphindex.index);
}
-5
View File
@@ -201,8 +201,6 @@ private:
int textureX, textureY;
int rowHeight;
bool useSpacesAsTab;
// ID which is incremented when the texture cache is invalidated.
uint32 textureCacheID;
@@ -211,9 +209,6 @@ private:
// use, for edge antialiasing.
static const int TEXTURE_PADDING = 2;
// This will be used if the Rasterizer doesn't have a tab character itself.
static const int SPACES_PER_TAB = 4;
static StringMap<AlignMode, ALIGN_MAX_ENUM>::Entry alignModeEntries[];
static StringMap<AlignMode, ALIGN_MAX_ENUM> alignModes;