Added -allglyphs option
This commit is contained in:
parent
3cf874b39a
commit
f1ad23f7c4
|
|
@ -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.
|
- Alternatively, use `-varfont <fontfile.ttf/otf?var0=value0&var1=value1>` to configure a variable font.
|
||||||
- `-charset <charset.txt>` – sets the character set. The ASCII charset will be used if not specified. See [the syntax specification](#character-set-specification-syntax) of `charset.txt`.
|
- `-charset <charset.txt>` – 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>` – sets the set of input glyphs using their indices within the font file. See [the syntax specification](#glyph-set-specification).
|
- `-glyphset <glyphset.txt>` – sets the set of input glyphs using their indices within the font file. See [the syntax specification](#glyph-set-specification).
|
||||||
|
- `-allglyphs` – sets the set of input glyphs to all glyphs present within the font file.
|
||||||
- `-fontscale <scale>` – 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).
|
- `-fontscale <scale>` – 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>` – sets a name for the font that will be stored in certain output files as metadata.
|
- `-fontname <name>` – sets a name for the font that will be stored in certain output files as metadata.
|
||||||
- `-and` – separates multiple inputs to be combined into a single atlas.
|
- `-and` – separates multiple inputs to be combined into a single atlas.
|
||||||
|
|
|
||||||
|
|
@ -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()) { }
|
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) {
|
int FontGeometry::loadGlyphset(msdfgen::FontHandle *font, double fontScale, const Charset &glyphset, bool preprocessGeometry, bool enableKerning) {
|
||||||
if (!(glyphs->size() == rangeEnd && loadMetrics(font, fontScale)))
|
if (!(glyphs->size() == rangeEnd && loadMetrics(font, fontScale)))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,8 @@ public:
|
||||||
FontGeometry();
|
FontGeometry();
|
||||||
explicit FontGeometry(std::vector<GlyphGeometry> *glyphStorage);
|
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
|
/// 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);
|
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
|
/// Loads all glyphs in a charset (Charset elements are Unicode codepoints), returns the number of successfully loaded glyphs
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,8 @@ INPUT SPECIFICATION
|
||||||
Specifies the input character set. Refer to the documentation for format of charset specification. Defaults to ASCII.
|
Specifies the input character set. Refer to the documentation for format of charset specification. Defaults to ASCII.
|
||||||
-glyphset <filename>
|
-glyphset <filename>
|
||||||
Specifies the set of input glyphs as glyph indices within the font file.
|
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>
|
-fontscale <scale>
|
||||||
Specifies the scale to be applied to the glyph geometry of the font.
|
Specifies the scale to be applied to the glyph geometry of the font.
|
||||||
-fontname <name>
|
-fontname <name>
|
||||||
|
|
@ -419,6 +421,12 @@ int main(int argc, const char * const *argv) {
|
||||||
++argPos;
|
++argPos;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
ARG_CASE("-allglyphs", 0) {
|
||||||
|
fontInput.charsetFilename = nullptr;
|
||||||
|
fontInput.glyphIdentifierType = GlyphIdentifierType::GLYPH_INDEX;
|
||||||
|
++argPos;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
ARG_CASE("-fontscale", 1) {
|
ARG_CASE("-fontscale", 1) {
|
||||||
double fs;
|
double fs;
|
||||||
if (!(parseDouble(fs, argv[++argPos]) && fs > 0))
|
if (!(parseDouble(fs, argv[++argPos]) && fs > 0))
|
||||||
|
|
@ -866,20 +874,24 @@ int main(int argc, const char * const *argv) {
|
||||||
|
|
||||||
// Load character set
|
// Load character set
|
||||||
Charset charset;
|
Charset charset;
|
||||||
|
unsigned allGlyphCount = 0;
|
||||||
if (fontInput.charsetFilename) {
|
if (fontInput.charsetFilename) {
|
||||||
if (!charset.load(fontInput.charsetFilename, fontInput.glyphIdentifierType != GlyphIdentifierType::UNICODE_CODEPOINT))
|
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.");
|
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;
|
charset = Charset::ASCII;
|
||||||
fontInput.glyphIdentifierType = GlyphIdentifierType::UNICODE_CODEPOINT;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load glyphs
|
// Load glyphs
|
||||||
FontGeometry fontGeometry(&glyphs);
|
FontGeometry fontGeometry(&glyphs);
|
||||||
int glyphsLoaded = -1;
|
int glyphsLoaded = -1;
|
||||||
switch (fontInput.glyphIdentifierType) {
|
switch (fontInput.glyphIdentifierType) {
|
||||||
case GlyphIdentifierType::GLYPH_INDEX:
|
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;
|
break;
|
||||||
case GlyphIdentifierType::UNICODE_CODEPOINT:
|
case GlyphIdentifierType::UNICODE_CODEPOINT:
|
||||||
glyphsLoaded = fontGeometry.loadCharset(font, fontInput.fontScale, charset, config.preprocessGeometry, config.kerning);
|
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)
|
if (glyphsLoaded < 0)
|
||||||
ABORT("Failed to load glyphs from font.");
|
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)
|
if (fontInputs.size() > 1)
|
||||||
printf(" from font \"%s\"", fontInput.fontFilename);
|
printf(" from font \"%s\"", fontInput.fontFilename);
|
||||||
printf(".\n");
|
printf(".\n");
|
||||||
|
|
@ -909,6 +921,13 @@ int main(int argc, const char * const *argv) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
fprintf(stderr, "\n");
|
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)
|
if (fontInput.fontName)
|
||||||
|
|
|
||||||
2
msdfgen
2
msdfgen
|
|
@ -1 +1 @@
|
||||||
Subproject commit 16f2057bbcdc2f634e6fb6f573d2d176c9dd1a73
|
Subproject commit 682381a03c5876cffcad256a59eab7efd83c3f4e
|
||||||
Loading…
Reference in New Issue