1#ifndef TYPESET_FONT_FONT_SET_HPP
2#define TYPESET_FONT_FONT_SET_HPP
10#include <glyphware/Face.h>
16namespace typeset {
struct FontSpec; }
47 std::vector<glyphware::CodepointRange>
ranges;
62 std::shared_ptr<glyphware::Face>
loadFile(
const std::string& path,
63 const std::string& key = std::string(),
67 std::shared_ptr<glyphware::Face>
loadMemory(
const std::string& key,
68 const void* data,
size_t size,
79 bool has(
const std::string& key)
const;
83 std::vector<std::string>
keys()
const;
86 std::shared_ptr<glyphware::Face>
find(
const std::string& keyOrFamily);
90 std::shared_ptr<glyphware::Face>
select(
const std::string& keyOrFamily,
int weight,
bool italic,
91 const std::map<std::string, float>& variations = {});
97 std::shared_ptr<glyphware::Face>
instance(
const std::shared_ptr<glyphware::Face>& base,
98 const std::vector<glyphware::VarCoord>& coords);
106 const std::string& language = std::string(),
107 int colorPreference = 0);
123 hb_font_t*
hbFont(
const glyphware::Face& face);
126 size_t size()
const {
return entries_.size(); }
131 std::shared_ptr<glyphware::Face> face;
133 std::vector<std::string> names;
136 bool matches(
const std::string& name)
const;
137 bool languageMatches(
const std::string& language)
const;
140 Entry* entryFor(
const std::string& key);
141 void adopt(Entry& e, std::shared_ptr<glyphware::Face> face);
142 bool ensureLoaded(Entry& e);
143 bool covers(Entry& e,
char32_t cp);
145 Entry* best(
const std::string& name,
int weight,
bool italic);
146 std::shared_ptr<glyphware::Face> faceOf(Entry* e);
149 std::shared_ptr<glyphware::Face> withVariations(
const std::shared_ptr<glyphware::Face>& base,
150 int weight,
bool italic,
151 const std::map<std::string, float>& variations);
153 std::vector<std::unique_ptr<Entry>> entries_;
154 std::map<std::string, std::vector<std::string>> languageFonts_;
155 std::map<const glyphware::Face*, hb_font_t*> hbFonts_;
157 std::map<std::pair<const glyphware::Face*, std::string>, std::shared_ptr<glyphware::Face>> instances_;
161inline uint32_t
makeTag(
const std::string& s) {
163 for (
size_t i = 0; i < 4; ++i) t = (t << 8) | static_cast<uint8_t>(i < s.size() ? s[i] :
' ');
std::shared_ptr< glyphware::Face > find(const std::string &keyOrFamily)
登録済み face(キー、または family 名で。通常ウェイト・非斜体を優先。無ければ nullptr)。必要なら開く
void setLanguageFonts(const std::string &language, std::vector< std::string > families)
言語 → 先に試す family の列。"zh-Hans" のように地域・用字系まで書いた言語は、その完全一致が無ければ 主言語("zh")の表を使う。families が空なら削除
FontSet & operator=(const FontSet &)=delete
FontSet(const FontSet &)=delete
hb_font_t * hbFont(const glyphware::Face &face)
シェイピング用 hb_font(フォントユニットスケール)。FontSet が所有する
std::vector< std::string > languageFonts(const std::string &language) const
language に対応する family 列(置換表+宣言の languages にその言語を持つキー)。無ければ空
std::vector< std::string > keys() const
登録したキー(登録順)
std::shared_ptr< glyphware::Face > loadMemory(const std::string &key, const void *data, size_t size, int faceIndex=0)
メモリから開く(バイト列はコピーして保持する)
std::shared_ptr< glyphware::Face > select(const std::string &keyOrFamily, int weight, bool italic, const std::map< std::string, float > &variations={})
キー/family 名と weight / italic に最も近い face。必要なら開く。 バリアブルフォントなら wght 軸を weight に合わせたインスタンス(variations に他の...
std::shared_ptr< glyphware::Face > primary(const FontSpec &spec)
FontSpec の第一候補(行のメトリクス基準に使う。言語の置換は見ない)
std::shared_ptr< glyphware::Face > resolve(const FontSpec &spec, char32_t cp, const std::string &language=std::string(), int colorPreference=0)
FontSpec の family 列(language の置換表・宣言の languages が先)を順に見て、cp を持つ最初の face を返す。 family ごとに weight / ital...
std::shared_ptr< glyphware::Face > instance(const std::shared_ptr< glyphware::Face > &base, const std::vector< glyphware::VarCoord > &coords)
バリアブルフォントのインスタンス(軸の値を固定した別の Face)。同じ base と座標なら同じ Face を返す。 軸の無い face、座標が空ならそのまま base
bool has(const std::string &key) const
登録済みか(開いているかどうかは問わない)
std::shared_ptr< glyphware::Face > loadFile(const std::string &path, const std::string &key=std::string(), int faceIndex=0)
ファイルから開く。key を省略するとパスがキーになる。family / weight / italic は name・OS/2 から
size_t size() const
登録した数(宣言だけのものも含む)
bool declare(FontDeclaration decl)
開かずに宣言する。同じキーがあれば置き換える。ファイルは初回使用時に開く(無ければそのとき失敗し、 以後は無いものとして扱う)
bool isLoaded(const std::string &key) const
開いているか(declare しただけなら false。開くのに失敗したものも false)
font — フォント層(glyphware の薄い包み)
DecorationMetrics decorationMetrics(FontSet &fonts, const glyphware::Face &face, Pt size)
post / OS/2 から取る(hb_ot_metrics)。無ければ下線 0.1em / 太さ 0.05em、打消し線 -0.3em
void faceAscentDescent(const glyphware::Face &face, Pt size, Pt &ascent, Pt &descent)
face の ascender / descender(正・正、pt)を size で返す
uint32_t makeTag(const std::string &s)
OpenType タグ("wght")を glyphware / HarfBuzz の 32bit タグに
float unitsPerEm(const glyphware::Face &face)
face の unitsPerEm(取れなければ 1000)
int effectiveWeight(const glyphware::Face &face)
face の実効ウェイト。バリアブルフォントのインスタンスなら wght 軸の値、無ければ OS/2 の値
下線・打消し線のメトリクス(pt、size で換算)。位置はベースラインからの距離で下が正 (横組みの block 軸と同じ向き。打消し線は通常負)
フォントの宣言(開かずに登録するためのメタデータ)
std::vector< std::string > family
別名(同じ family の別ウェイトは同じ名前を書く)
std::string key
一意なキー(TextStyle の family に書く名前)
std::optional< bool > italic
nullopt でフォントから
std::string path
ファイル(初回使用時に開く)
int weight
100〜900。0 でフォントから
std::vector< glyphware::CodepointRange > ranges
カバレッジ(空なら開いて cmap を見る)
std::vector< std::string > languages
BCP47。この言語のテキストで先に試される