Skip to content

Commit

Permalink
Tweak font spacing to be more vanilla-like
Browse files Browse the repository at this point in the history
  • Loading branch information
SupSuper committed Mar 12, 2019
1 parent 55a9e95 commit e9048f2
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion data/fonts/bigfont.font
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<openapoc>
<apocfont name="bigfont" path="fonts/bigfont_new.dat" height="24" width="14" spacewidth="6" palette="ui/ui_palette.png">
<apocfont name="bigfont" path="fonts/bigfont_new.dat" height="24" width="14" spacewidth="12" kerning="3" palette="ui/ui_palette.png">
<glyph string="!" glyph="RAW:fonts/bigfont_new.dat:14:24:0"/>
<glyph string="&quot;" glyph="RAW:fonts/bigfont_new.dat:14:24:1"/>
<glyph string="#" glyph="RAW:fonts/bigfont_new.dat:14:24:2"/>
Expand Down
2 changes: 1 addition & 1 deletion data/fonts/smalfont.font
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<openapoc>
<apocfont name="smalfont" path="fonts/smalfont_new.dat" height="15" width="14" spacewidth="3" palette="ui/ui_palette.png">
<apocfont name="smalfont" path="fonts/smalfont_new.dat" height="15" width="14" spacewidth="6" kerning="2" palette="ui/ui_palette.png">
<glyph string="!" glyph="RAW:fonts/smalfont_new.dat:14:15:0"/>
<glyph string="&quot;" glyph="RAW:fonts/smalfont_new.dat:14:15:1"/>
<glyph string="#" glyph="RAW:fonts/smalfont_new.dat:14:15:2"/>
Expand Down
2 changes: 1 addition & 1 deletion data/fonts/smallset.font
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<openapoc>
<apocfont name="smallset" path="fonts/smallset_new.dat" height="14" width="9" spacewidth="3" palette="ui/ui_palette.png">
<apocfont name="smallset" path="fonts/smallset_new.dat" height="14" width="9" spacewidth="4" kerning="1" palette="ui/ui_palette.png">
<glyph string="!" glyph="RAW:fonts/smallset_new.dat:9:14:0"/>
<glyph string="&quot;" glyph="RAW:fonts/smallset_new.dat:9:14:1"/>
<glyph string="#" glyph="RAW:fonts/smallset_new.dat:9:14:2"/>
Expand Down
9 changes: 8 additions & 1 deletion framework/apocresources/apocfont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ sp<BitmapFont> ApocalypseFont::loadFont(const UString &fontDescPath)

int spacewidth = 0;
int height = 0;
int kerning = 0;
UString fontName;

std::map<UniChar, UString> charMap;
Expand All @@ -83,6 +84,12 @@ sp<BitmapFont> ApocalypseFont::loadFont(const UString &fontDescPath)
LogError("apocfont \"%s\" with invalid \"spacewidth\" attribute", fontName);
return nullptr;
}
kerning = fontNode.attribute("kerning").as_int();
if (kerning <= 0)
{
LogError("apocfont \"%s\" with invalid \"kerning\" attribute", fontName);
return nullptr;
}

for (auto glyphNode = fontNode.child("glyph"); glyphNode;
glyphNode = glyphNode.next_sibling("glyph"))
Expand Down Expand Up @@ -123,7 +130,7 @@ sp<BitmapFont> ApocalypseFont::loadFont(const UString &fontDescPath)
charMap[c] = glyphPath;
}

auto font = BitmapFont::loadFont(charMap, spacewidth, height, fontName,
auto font = BitmapFont::loadFont(charMap, spacewidth, height, kerning, fontName,
fw().data->loadPalette(fontNode.attribute("palette").value()));
return font;
}
Expand Down
8 changes: 5 additions & 3 deletions framework/font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,14 @@ sp<PaletteImage> BitmapFont::getGlyph(UniChar codepoint)
sp<Palette> BitmapFont::getPalette() const { return this->palette; }

sp<BitmapFont> BitmapFont::loadFont(const std::map<UniChar, UString> &glyphMap, int spaceWidth,
int fontHeight, UString fontName, sp<Palette> defaultPalette)
int fontHeight, int kerning, UString fontName,
sp<Palette> defaultPalette)
{
auto font = mksp<BitmapFont>();

font->spacewidth = spaceWidth;
font->fontheight = fontHeight;
font->kerning = kerning;
font->averagecharacterwidth = 0;
font->name = fontName;
font->palette = defaultPalette;
Expand Down Expand Up @@ -121,8 +123,8 @@ sp<BitmapFont> BitmapFont::loadFont(const std::map<UniChar, UString> &glyphMap,
}
}
}
// Trim the glyph to the max non-transparent width + 2 px
auto trimmedGlyph = mksp<PaletteImage>(Vec2<int>{maxWidth + 2, fontHeight});
// Trim the glyph to the max non-transparent width
auto trimmedGlyph = mksp<PaletteImage>(Vec2<int>{maxWidth + kerning, fontHeight});
PaletteImage::blit(paletteImage, trimmedGlyph);

font->fontbitmaps[p.first] = trimmedGlyph;
Expand Down
4 changes: 3 additions & 1 deletion framework/font.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class BitmapFont
int spacewidth;
int fontheight;
int averagecharacterwidth;
int kerning;
std::map<UniChar, sp<PaletteImage>> fontbitmaps;
UString name;
sp<Palette> palette;
Expand All @@ -34,7 +35,8 @@ class BitmapFont

/* Reads in set of "Character":"glyph description string" pairs */
static sp<BitmapFont> loadFont(const std::map<UniChar, UString> &charMap, int spaceWidth,
int fontHeight, UString fontName, sp<Palette> defaultPalette);
int fontHeight, int kerning, UString fontName,
sp<Palette> defaultPalette);
};

}; // namespace OpenApoc

0 comments on commit e9048f2

Please sign in to comment.