Added -fontname argument
This commit is contained in:
parent
6649e2b6fa
commit
153dcb9c46
|
|
@ -42,10 +42,11 @@ Use the following command line arguments for the standalone version of the atlas
|
|||
|
||||
### Input
|
||||
|
||||
- `-font <fontfile.ttf/otf>` – sets the input font file.
|
||||
- `-font <fontfile.ttf/otf>` (required) – sets the input font file.
|
||||
- `-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).
|
||||
- `-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.
|
||||
- `-and` – separates multiple inputs to be combined into a single atlas.
|
||||
|
||||
### Bitmap atlas type
|
||||
|
|
@ -89,7 +90,7 @@ Alternativelly, the minimum possible dimensions may be selected automatically if
|
|||
|
||||
### Outputs
|
||||
|
||||
Any subset of the following may be specified:
|
||||
Any non-empty subset of the following may be specified:
|
||||
|
||||
- `-imageout <filename.*>` – saves the atlas bitmap as a plain image file. Format matches `-format`
|
||||
- `-json <filename.json>` – writes the atlas's layout data as well as other metrics into a structured JSON file
|
||||
|
|
|
|||
|
|
@ -113,6 +113,13 @@ int FontGeometry::loadKerning(msdfgen::FontHandle *font) {
|
|||
return loaded;
|
||||
}
|
||||
|
||||
void FontGeometry::setName(const char *name) {
|
||||
if (name)
|
||||
this->name = name;
|
||||
else
|
||||
this->name.clear();
|
||||
}
|
||||
|
||||
double FontGeometry::getGeometryScale() const {
|
||||
return geometryScale;
|
||||
}
|
||||
|
|
@ -169,4 +176,10 @@ const std::map<std::pair<int, int>, double> & FontGeometry::getKerning() const {
|
|||
return kerning;
|
||||
}
|
||||
|
||||
const char * FontGeometry::getName() const {
|
||||
if (name.empty())
|
||||
return nullptr;
|
||||
return name.c_str();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <msdfgen.h>
|
||||
#include <msdfgen-ext.h>
|
||||
|
|
@ -46,6 +47,8 @@ public:
|
|||
bool addGlyph(GlyphGeometry &&glyph);
|
||||
/// Loads kerning pairs for all glyphs that are currently present, returns the number of loaded kerning pairs
|
||||
int loadKerning(msdfgen::FontHandle *font);
|
||||
/// Sets a name to be associated with the font
|
||||
void setName(const char *name);
|
||||
|
||||
/// Returns the geometry scale to be used when loading glyphs
|
||||
double getGeometryScale() const;
|
||||
|
|
@ -63,6 +66,8 @@ public:
|
|||
bool getAdvance(double &advance, unicode_t codepoint1, unicode_t codepoint2) const;
|
||||
/// Returns the complete mapping of kerning pairs (by glyph indices) and their respective advance values
|
||||
const std::map<std::pair<int, int>, double> & getKerning() const;
|
||||
/// Returns the name associated with the font or null if not set
|
||||
const char * getName() const;
|
||||
|
||||
private:
|
||||
double geometryScale;
|
||||
|
|
@ -74,6 +79,7 @@ private:
|
|||
std::map<unicode_t, size_t> glyphsByCodepoint;
|
||||
std::map<std::pair<int, int>, double> kerning;
|
||||
std::vector<GlyphGeometry> ownGlyphs;
|
||||
std::string name;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -74,6 +74,9 @@ bool exportArteryFont(const FontGeometry *fonts, int fontCount, const msdfgen::B
|
|||
fontVariant.metrics.lineHeight = REAL(fontMetrics.lineHeight);
|
||||
fontVariant.metrics.underlineY = REAL(fontMetrics.underlineY);
|
||||
fontVariant.metrics.underlineThickness = REAL(fontMetrics.underlineThickness);
|
||||
const char *name = font.getName();
|
||||
if (name)
|
||||
fontVariant.name.string = name;
|
||||
fontVariant.glyphs = artery_font::StdList<artery_font::Glyph<REAL> >(font.getGlyphs().size());
|
||||
int j = 0;
|
||||
for (const GlyphGeometry &glyphGeom : font.getGlyphs()) {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,45 @@
|
|||
|
||||
#include "json-export.h"
|
||||
|
||||
#include <string>
|
||||
#include "GlyphGeometry.h"
|
||||
|
||||
namespace msdf_atlas {
|
||||
|
||||
static std::string escapeJsonString(const char *str) {
|
||||
char uval[7] = "\\u0000";
|
||||
std::string outStr;
|
||||
while (*str) {
|
||||
switch (*str) {
|
||||
case '\\':
|
||||
outStr += "\\\\";
|
||||
break;
|
||||
case '"':
|
||||
outStr += "\\\"";
|
||||
break;
|
||||
case '\n':
|
||||
outStr += "\\n";
|
||||
break;
|
||||
case '\r':
|
||||
outStr += "\\r";
|
||||
break;
|
||||
case '\t':
|
||||
outStr += "\\t";
|
||||
break;
|
||||
case 0x00: case 0x01: case 0x02: case 0x03: case 0x04: case 0x05: case 0x06: case 0x07: case 0x08: /* \\t */ /* \\n */ case 0x0b: case 0x0c: /* \\r */ case 0x0e: case 0x0f:
|
||||
case 0x10: case 0x11: case 0x12: case 0x13: case 0x14: case 0x15: case 0x16: case 0x17: case 0x18: case 0x19: case 0x1a: case 0x1b: case 0x1c: case 0x1d: case 0x1e: case 0x1f:
|
||||
uval[4] = '0'+(*str >= 0x10);
|
||||
uval[5] = "0123456789abcdef"[*str&0x0f];
|
||||
outStr += uval;
|
||||
break;
|
||||
default:
|
||||
outStr.push_back(*str);
|
||||
}
|
||||
++str;
|
||||
}
|
||||
return outStr;
|
||||
}
|
||||
|
||||
static const char * imageTypeString(ImageType type) {
|
||||
switch (type) {
|
||||
case ImageType::HARD_MASK:
|
||||
|
|
@ -47,6 +82,11 @@ bool exportJSON(const FontGeometry *fonts, int fontCount, double fontSize, doubl
|
|||
if (fontCount > 1)
|
||||
fputs(i == 0 ? "{" : ",{", f);
|
||||
|
||||
// Font name
|
||||
const char *name = font.getName();
|
||||
if (name)
|
||||
fprintf(f, "\"name\":\"%s\",", escapeJsonString(name).c_str());
|
||||
|
||||
// Font metrics
|
||||
fputs("\"metrics\":{", f); {
|
||||
const msdfgen::FontMetrics &metrics = font.getMetrics();
|
||||
|
|
|
|||
|
|
@ -49,6 +49,8 @@ INPUT SPECIFICATION
|
|||
Specifies the set of input glyphs as glyph indices within the font file.
|
||||
-fontscale <scale>
|
||||
Specifies the scale to be applied to the glyph geometry of the font.
|
||||
-fontname <name>
|
||||
Specifies a name for the font that will be propagated into the output files as metadata.
|
||||
-and
|
||||
Separates multiple inputs to be combined into a single atlas.
|
||||
|
||||
|
|
@ -159,6 +161,7 @@ struct FontInput {
|
|||
GlyphIdentifierType glyphIdentifierType;
|
||||
const char *charsetFilename;
|
||||
double fontScale;
|
||||
const char *fontName;
|
||||
};
|
||||
|
||||
struct Configuration {
|
||||
|
|
@ -330,12 +333,18 @@ int main(int argc, const char * const *argv) {
|
|||
++argPos;
|
||||
continue;
|
||||
}
|
||||
ARG_CASE("-fontname", 1) {
|
||||
fontInput.fontName = argv[++argPos];
|
||||
++argPos;
|
||||
continue;
|
||||
}
|
||||
ARG_CASE("-and", 0) {
|
||||
if (!fontInput.fontFilename && !fontInput.charsetFilename && fontInput.fontScale < 0)
|
||||
ABORT("No font, character set, or font scale specified before -and separator.");
|
||||
if (!fontInputs.empty() && !memcmp(&fontInputs.back(), &fontInput, sizeof(FontInput)))
|
||||
ABORT("No changes between subsequent inputs. A different font, character set, or font scale must be set inbetween -and separators.");
|
||||
fontInputs.push_back(fontInput);
|
||||
fontInput.fontName = nullptr;
|
||||
++argPos;
|
||||
continue;
|
||||
}
|
||||
|
|
@ -724,6 +733,9 @@ int main(int argc, const char * const *argv) {
|
|||
printf("\n");
|
||||
}
|
||||
|
||||
if (fontInput.fontName)
|
||||
fontGeometry.setName(fontInput.fontName);
|
||||
|
||||
fonts.push_back((FontGeometry &&) fontGeometry);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue