Load font name by STBTT

This commit is contained in:
Filip Sykala 2021-09-13 09:13:14 +02:00
parent df50110ba7
commit 20645264f8
4 changed files with 166 additions and 81 deletions

View file

@ -23,8 +23,17 @@ public:
{
std::string name;
std::string path;
enum class Type;
Type type;
FontItem(const std::string &name, const std::string &path);
FontItem(const std::string &name, const std::string &path, Type type);
FontItem(const std::wstring &name, const std::wstring &path);
// way of load font described in path string
enum class Type {
file_path, // path is file loacation on computer - no move between computers
wx_font_descr // path is font descriptor generated by wxWidgets - limits for os/language move
};
};
using FontList = std::vector<FontItem>;
@ -46,21 +55,6 @@ public:
/// <returns>File path to font when found</returns>
static std::optional<std::wstring> get_font_path(const std::wstring &font_face_name);
/// <summary>
/// keep information from file about font
/// </summary>
struct Font
{
// loaded data from font file
std::vector<unsigned char> buffer;
unsigned int index=0; // index of actual file info in collection
unsigned int count=0; // count of fonts in file collection
// vertical position is "scale*(ascent - descent + lineGap)"
int ascent=0, descent=0, linegap=0;
};
// user defined font property
struct FontProp
{
@ -83,6 +77,25 @@ public:
};
// cache for glyph by unicode
using Glyphs = std::map<int, Glyph>;
/// <summary>
/// keep information from file about font
/// </summary>
struct Font
{
// loaded data from font file
std::vector<unsigned char> buffer;
unsigned int index = 0; // index of actual file info in collection
unsigned int count = 0; // count of fonts in file collection
// vertical position is "scale*(ascent - descent + lineGap)"
int ascent = 0, descent = 0, linegap = 0;
std::string name;
Emboss::Glyphs cache;
};
/// <summary>
/// Load font file into buffer
@ -110,15 +123,13 @@ public:
/// <summary>
/// Convert text into polygons
/// </summary>
/// <param name="font">Define fonts</param>
/// <param name="font">Define fonts + cache, which could extend</param>
/// <param name="text">Characters to convert</param>
/// <param name="font_prop">User defined property of the font</param>
/// <param name="cache">Cache for letter polygons</param>
/// <returns>Inner polygon cw(outer ccw)</returns>
static Polygons text2polygons(const Font & font,
static Polygons text2polygons(Font & font,
const char * text,
const FontProp &font_prop,
Glyphs * cache = nullptr);
const FontProp &font_prop);
/// <summary>
/// Project 2d point into space