Added -allglyphs option

This commit is contained in:
Chlumsky 2024-02-06 20:26:24 +01:00
parent 3cf874b39a
commit f1ad23f7c4
5 changed files with 46 additions and 6 deletions

View File

@ -49,6 +49,7 @@ Use the following command line arguments for the standalone version of the atlas
- Alternatively, use `-varfont <fontfile.ttf/otf?var0=value0&var1=value1>` to configure a variable font.
- `-charset <charset.txt>` &ndash; sets the character set. The ASCII charset will be used if not specified. See [the syntax specification](#character-set-specification-syntax) of `charset.txt`.
- `-glyphset <glyphset.txt>` &ndash; sets the set of input glyphs using their indices within the font file. See [the syntax specification](#glyph-set-specification).
- `-allglyphs` &ndash; sets the set of input glyphs to all glyphs present within the font file.
- `-fontscale <scale>` &ndash; applies a scaling transformation to the font's glyphs. Mainly to be used to generate multiple sizes in a single atlas, otherwise use [`-size`](#glyph-configuration).
- `-fontname <name>` &ndash; sets a name for the font that will be stored in certain output files as metadata.
- `-and` &ndash; separates multiple inputs to be combined into a single atlas.

View File

@ -27,6 +27,24 @@ FontGeometry::FontGeometry() : geometryScale(1), metrics(), preferredIdentifierT
FontGeometry::FontGeometry(std::vector<GlyphGeometry> *glyphStorage) : geometryScale(1), metrics(), preferredIdentifierType(GlyphIdentifierType::UNICODE_CODEPOINT), glyphs(glyphStorage), rangeStart(glyphs->size()), rangeEnd(glyphs->size()) { }
int FontGeometry::loadGlyphRange(msdfgen::FontHandle *font, double fontScale, unsigned rangeStart, unsigned rangeEnd, bool preprocessGeometry, bool enableKerning) {
if (!(glyphs->size() == this->rangeEnd && loadMetrics(font, fontScale)))
return -1;
glyphs->reserve(glyphs->size()+(rangeEnd-rangeStart));
int loaded = 0;
for (unsigned index = rangeStart; index < rangeEnd; ++index) {
GlyphGeometry glyph;
if (glyph.load(font, geometryScale, msdfgen::GlyphIndex(index), preprocessGeometry)) {
addGlyph((GlyphGeometry &&) glyph);
++loaded;
}
}
if (enableKerning)
loadKerning(font);
preferredIdentifierType = GlyphIdentifierType::GLYPH_INDEX;
return loaded;
}
int FontGeometry::loadGlyphset(msdfgen::FontHandle *font, double fontScale, const Charset &glyphset, bool preprocessGeometry, bool enableKerning) {
if (!(glyphs->size() == rangeEnd && loadMetrics(font, fontScale)))
return -1;

View File

@ -35,6 +35,8 @@ public:
FontGeometry();
explicit FontGeometry(std::vector<GlyphGeometry> *glyphStorage);
/// Loads the consecutive range of glyphs between rangeStart (inclusive) and rangeEnd (exclusive), returns the number of successfully loaded glyphs
int loadGlyphRange(msdfgen::FontHandle *font, double fontScale, unsigned rangeStart, unsigned rangeEnd, bool preprocessGeometry = true, bool enableKerning = true);
/// Loads all glyphs in a glyphset (Charset elements are glyph indices), returns the number of successfully loaded glyphs
int loadGlyphset(msdfgen::FontHandle *font, double fontScale, const Charset &glyphset, bool preprocessGeometry = true, bool enableKerning = true);
/// Loads all glyphs in a charset (Charset elements are Unicode codepoints), returns the number of successfully loaded glyphs

View File

@ -64,6 +64,8 @@ INPUT SPECIFICATION
Specifies the input character set. Refer to the documentation for format of charset specification. Defaults to ASCII.
-glyphset <filename>
Specifies the set of input glyphs as glyph indices within the font file.
-allglyphs
Specifies that all glyphs within the font file are to be processed.
-fontscale <scale>
Specifies the scale to be applied to the glyph geometry of the font.
-fontname <name>
@ -419,6 +421,12 @@ int main(int argc, const char * const *argv) {
++argPos;
continue;
}
ARG_CASE("-allglyphs", 0) {
fontInput.charsetFilename = nullptr;
fontInput.glyphIdentifierType = GlyphIdentifierType::GLYPH_INDEX;
++argPos;
continue;
}
ARG_CASE("-fontscale", 1) {
double fs;
if (!(parseDouble(fs, argv[++argPos]) && fs > 0))
@ -866,20 +874,24 @@ int main(int argc, const char * const *argv) {
// Load character set
Charset charset;
unsigned allGlyphCount = 0;
if (fontInput.charsetFilename) {
if (!charset.load(fontInput.charsetFilename, fontInput.glyphIdentifierType != GlyphIdentifierType::UNICODE_CODEPOINT))
ABORT(fontInput.glyphIdentifierType == GlyphIdentifierType::GLYPH_INDEX ? "Failed to load glyph set specification." : "Failed to load character set specification.");
} else {
} else if (fontInput.glyphIdentifierType == GlyphIdentifierType::GLYPH_INDEX)
msdfgen::getGlyphCount(allGlyphCount, font);
else
charset = Charset::ASCII;
fontInput.glyphIdentifierType = GlyphIdentifierType::UNICODE_CODEPOINT;
}
// Load glyphs
FontGeometry fontGeometry(&glyphs);
int glyphsLoaded = -1;
switch (fontInput.glyphIdentifierType) {
case GlyphIdentifierType::GLYPH_INDEX:
glyphsLoaded = fontGeometry.loadGlyphset(font, fontInput.fontScale, charset, config.preprocessGeometry, config.kerning);
if (allGlyphCount)
glyphsLoaded = fontGeometry.loadGlyphRange(font, fontInput.fontScale, 0, allGlyphCount, config.preprocessGeometry, config.kerning);
else
glyphsLoaded = fontGeometry.loadGlyphset(font, fontInput.fontScale, charset, config.preprocessGeometry, config.kerning);
break;
case GlyphIdentifierType::UNICODE_CODEPOINT:
glyphsLoaded = fontGeometry.loadCharset(font, fontInput.fontScale, charset, config.preprocessGeometry, config.kerning);
@ -888,7 +900,7 @@ int main(int argc, const char * const *argv) {
}
if (glyphsLoaded < 0)
ABORT("Failed to load glyphs from font.");
printf("Loaded geometry of %d out of %d glyphs", glyphsLoaded, (int) charset.size());
printf("Loaded geometry of %d out of %d glyphs", glyphsLoaded, (int) (allGlyphCount+charset.size()));
if (fontInputs.size() > 1)
printf(" from font \"%s\"", fontInput.fontFilename);
printf(".\n");
@ -909,6 +921,13 @@ int main(int argc, const char * const *argv) {
break;
}
fprintf(stderr, "\n");
} else if (glyphsLoaded < (int) allGlyphCount) {
fprintf(stderr, "Missing %d glyphs", (int) allGlyphCount-glyphsLoaded);
bool first = true;
for (unsigned i = 0; i < allGlyphCount; ++i)
if (!fontGeometry.getGlyph(msdfgen::GlyphIndex(i)))
fprintf(stderr, "%c 0x%02X", first ? ((first = false), ':') : ',', i);
fprintf(stderr, "\n");
}
if (fontInput.fontName)

@ -1 +1 @@
Subproject commit 16f2057bbcdc2f634e6fb6f573d2d176c9dd1a73
Subproject commit 682381a03c5876cffcad256a59eab7efd83c3f4e