FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Support load multiple fonts from .ttc by RainbowC0 · Pull Request #1765 · solvespace/solvespace · GitHub

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .cpp  (1) .h  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
26 changes: 22 additions & 4 deletions src/ttf.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,28 @@ void TtfFontList::LoadAll() {
for(const Platform::Path &font : Platform::GetFontFiles()) {
TtfFont tf = {};
tf.fontFile = font;
if(tf.LoadFromFile(fontLibrary))
tf.faceIndex = 0;
if(tf.LoadFromFile(fontLibrary, true)) {
// load all fonts in .ttc
long nface = tf.fontFace->num_faces;
FT_Done_Face(tf.fontFace);
tf.fontFace = NULL;
l.Add(&tf);
for (long i=1; i<nface; i++) {
TtfFont tf = {};
tf.fontFile = font;
tf.faceIndex = i;
if (tf.LoadFromFile(fontLibrary, false)) {
l.Add(&tf);
}
}
}
}

// Add builtin font to end of font list so it is displayed first in the UI
{
TtfFont tf = {};
tf.faceIndex = 0;
tf.SetResourceID("fonts/BitstreamVeraSans-Roman-builtin.ttf");
if(tf.LoadFromResource(fontLibrary))
l.Add(&tf);
Expand Down Expand Up @@ -137,7 +152,10 @@ double TtfFontList::AspectRatio(const std::string &font, const std::string &str,
// entities that reference us will store it.
//-----------------------------------------------------------------------------
std::string TtfFont::FontFileBaseName() const {
return fontFile.FileName();
std::string name = fontFile.FileName();
if (faceIndex > 0)
name = name + "#" + std::to_string(faceIndex);
return name;
}

//-----------------------------------------------------------------------------
Expand All @@ -164,7 +182,7 @@ bool TtfFont::LoadFromFile(FT_Library fontLibrary, bool keepOpen) {
// We don't use OpenFile() here to let freetype do its own memory management.
// This is OK because on Linux/OS X we just delegate to fopen and on Windows
// we only look into C:\Windows\Fonts, which has a known short path.
if(int fterr = FT_Open_Face(fontLibrary, &args, 0, &fontFace)) {
if(int fterr = FT_Open_Face(fontLibrary, &args, faceIndex, &fontFace)) {
dbp("freetype: loading font from file '%s' failed: %s",
fontFile.raw.c_str(), ft_error_string(fterr));
return false;
Expand All @@ -189,7 +207,7 @@ bool TtfFont::LoadFromResource(FT_Library fontLibrary, bool keepOpen) {
FT_Long size = static_cast<FT_Long>(_size);
const FT_Byte *buffer = reinterpret_cast<const FT_Byte*>(_buffer);

if(int fterr = FT_New_Memory_Face(fontLibrary, buffer, size, 0, &fontFace)) {
if(int fterr = FT_New_Memory_Face(fontLibrary, buffer, size, faceIndex, &fontFace)) {
dbp("freetype: loading font '%s' from memory failed: %s",
fontFile.raw.c_str(), ft_error_string(fterr));
return false;
Expand Down
1 change: 1 addition & 0 deletions src/ttf.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class TtfFont {
Platform::Path fontFile; // or resource path/name as res://<path>
std::string name;
FT_FaceRec_ *fontFace;
long faceIndex;
double capHeight;

void SetResourceID(const std::string &resource);
Expand Down

Back | FazBrowse Home | New Git URL