22 #ifndef STLL_LAYOUTER_FONT_H
23 #define STLL_LAYOUTER_FONT_H
31 #include "internal/layouterFont_internal.h"
33 #include <boost/utility.hpp>
44 struct FT_LibraryRec_;
45 struct FT_GlyphSlotRec_;
76 class FreeTypeLibrary_c;
90 std::vector<internal::FontFileResource_c> resources;
95 template <
typename... Args>
104 resources.emplace_back(internal::FontFileResource_c(pathname));
113 void addFont(std::pair<std::shared_ptr<uint8_t>,
size_t> data,
const std::string & descr)
115 resources.emplace_back(internal::FontFileResource_c(data.first, data.second, descr));
120 size_t size(
void)
const {
return resources.size(); }
123 auto begin(
void)
const {
return resources.begin(); }
124 auto end(
void)
const {
return resources.end(); }
134 internal::FontFileResource_c
getRessource(
size_t idx)
const {
return resources[idx]; }
139 return std::lexicographical_compare(resources.begin(), resources.end(), b.resources.begin(), b.resources.end());
158 GlyphSlot_c(
int width,
int height) : w(width), h(height), top(0), left(0), pitch(0), data(0) {}
161 FontFace_c(std::shared_ptr<FreeTypeLibrary_c> l,
const internal::FontFileResource_c & r, uint32_t size);
168 FT_FaceRec_ *
getFace(
void)
const {
return f; }
179 const internal::FontFileResource_c &
getResource(
void)
const {
return rec; }
223 std::shared_ptr<FreeTypeLibrary_c> lib;
224 internal::FontFileResource_c rec;
239 void add(std::shared_ptr<FontFace_c> f) { fonts.emplace_back(std::move(f)); }
242 auto begin(
void)
const {
return fonts.begin(); }
243 auto end(
void)
const {
return fonts.end(); }
247 std::shared_ptr<FontFace_c>
get(char32_t codepoint)
const;
251 uint32_t
getHeight(
void)
const {
return fonts[0]->getHeight(); }
252 int32_t
getAscender(
void)
const {
return fonts[0]->getAscender(); }
258 explicit operator bool()
const {
return fonts.size() > 0; }
261 bool operator==(
const Font_c & rhs)
const {
return std::equal(fonts.begin(), fonts.end(), rhs.fonts.begin(), rhs.fonts.end()); }
264 std::vector<std::shared_ptr<FontFace_c>> fonts;
292 FT_FaceRec_ *
newFace(
const internal::FontFileResource_c & r, uint32_t size);
341 std::shared_ptr<FontFace_c>
getFont(
const internal::FontFileResource_c & res, uint32_t size);
348 for(
auto it = fonts.begin(); it != fonts.end(); )
350 if(it->second.use_count() == 1)
352 it = fonts.erase(it);
363 class FontFaceParameter_c
366 internal::FontFileResource_c res;
369 FontFaceParameter_c(
const internal::FontFileResource_c r, uint32_t s) : res(std::move(r)), size(s) {}
371 bool operator<(
const FontFaceParameter_c & b)
const
373 if (res < b.res)
return true;
374 if (b.res < res)
return false;
376 if (size < b.size)
return true;
383 std::map<FontFaceParameter_c, std::shared_ptr<FontFace_c> > fonts;
386 std::shared_ptr<FreeTypeLibrary_c> lib;
405 class FontFamilyParameter_c
413 bool operator<(
const FontFamilyParameter_c & b)
const
415 if (style < b.style)
return true;
416 if (style > b.style)
return false;
417 if (variant < b.variant)
return true;
418 if (variant > b.variant)
return false;
419 if (weight < b.weight)
return true;
420 if (weight > b.weight)
return false;
421 if (stretch < b.stretch)
return true;
450 const std::string & style =
"normal",
451 const std::string & variant =
"normal",
452 const std::string & weight =
"normal",
453 const std::string & stretch =
"normal");
464 const std::string & style =
"normal",
465 const std::string & variant =
"normal",
466 const std::string & weight =
"normal",
467 const std::string & stretch =
"normal");
470 std::map<FontFamilyParameter_c, FontResource_c> fonts;
471 std::shared_ptr<FontCache_c> cache;
int h
Definition: layouterFont.h:152
int left
Definition: layouterFont.h:153
auto end(void) const
Definition: layouterFont.h:243
Definition: layouterFont.h:149
This class represents a font resource.
Definition: layouterFont.h:87
int32_t getUnderlineThickness(void) const
Definition: layouterFont.h:255
uint32_t glyphIndex_t
type used for all glyph indices. Right now there is no font with more than 2^16 fonts, so 2^32 should be on the safe side. Also HarfBuzz also uses only 2^32 codepoints.
Definition: layouterFont.h:53
bool operator<(const FontResource_c &b) const
Definition: layouterFont.h:137
int pitch
Definition: layouterFont.h:154
Font_c getFont(const FontResource_c &res, uint32_t size)
Get a font face from this cache with the given resource and size.
contains all the FontFaces_c of one FontRessource_c
Definition: layouterFont.h:232
a class contains all resources for a family of fonts
Definition: layouterFont.h:398
int32_t getDescender(void) const
Get the descender of the font with multiplication factor of 64.
auto begin(void) const
Definition: layouterFont.h:242
FontResource_c(void)
Definition: layouterFont.h:130
FT_FaceRec_ * newFace(const internal::FontFileResource_c &r, uint32_t size)
Font_c getFont(uint32_t size, const std::string &style="normal", const std::string &variant="normal", const std::string &weight="normal", const std::string &stretch="normal")
Get a font instance from the family.
Font_c(void)
Definition: layouterFont.h:236
internal::FontFileResource_c getRessource(size_t idx) const
Definition: layouterFont.h:134
use vertical BGR (top to bottom)
Definition: layouterFont.h:65
FontFamily_c(void)
Initialize an empty family, using font cache created specifically for this family.
Definition: layouterFont.h:438
FontResource_c(Args...par)
Definition: layouterFont.h:96
void doneFace(FT_FaceRec_ *f)
uint32_t getHeight(void) const
Definition: layouterFont.h:251
int32_t getUnderlinePosition(void) const
Get the underline position of the font with multiplication factor of 64.
use horizontal RGB
Definition: layouterFont.h:62
FontFamily_c(std::shared_ptr< FontCache_c > c)
Initialize an empty family, using the given font cache to get the fonts.
Definition: layouterFont.h:430
GlyphSlot_c(const FT_GlyphSlotRec_ *g)
uint32_t getHeight(void) const
Get the height of the font with multiplication factor of 64.
bool containsGlyph(char32_t ch)
check if a given character is available within this font
this class encapsulates open fonts of a single library, it makes sure that each font is open only onc...
Definition: layouterFont.h:310
FreetypeException_c(const std::string &what_arg)
Definition: layouterFont.h:73
void addFont(std::pair< std::shared_ptr< uint8_t >, size_t > data, const std::string &descr)
Definition: layouterFont.h:113
SubPixelArrangement
define, which sub-pixel arrangement you want to use for sub-pixel output
Definition: layouterFont.h:59
use horizontal BGR
Definition: layouterFont.h:63
FontCache_c(std::shared_ptr< FreeTypeLibrary_c > l)
Create a cache using a specific library.
Definition: layouterFont.h:319
FontFace_c(std::shared_ptr< FreeTypeLibrary_c > l, const internal::FontFileResource_c &r, uint32_t size)
FontCache_c(void)
Create a cache using an instance of the FreeType library that is created specifically for this cache ...
Definition: layouterFont.h:327
auto begin(void) const
Definition: layouterFont.h:123
const uint8_t * data
Definition: layouterFont.h:155
int w
Definition: layouterFont.h:152
GlyphSlot_c renderGlyph(glyphIndex_t glyphIndex, SubPixelArrangement sp)
render a glyph of this font
int32_t getUnderlineThickness(void) const
Get the underline thickness of the font with multiplication factor of 64.
FT_FaceRec_ * getFace(void) const
Get the FreeType structure for this font.
Definition: layouterFont.h:168
The namespace for the library. Every function and class is within this namespace. ...
Definition: color.h:31
FreeTypeLibrary_c()
Create an instance of the FreeType library.
size_t size(void) const
Definition: layouterFont.h:120
int32_t getAscender(void) const
Definition: layouterFont.h:252
void addFont(const FontResource_c &res, const std::string &style="normal", const std::string &variant="normal", const std::string &weight="normal", const std::string &stretch="normal")
Add a font to the family.
void addFont(const std::string &pathname)
Definition: layouterFont.h:102
auto end(void) const
Definition: layouterFont.h:124
uint32_t getSize(void) const
get the size of the font
Definition: layouterFont.h:175
int top
Definition: layouterFont.h:153
bool operator==(const Font_c &rhs) const
Definition: layouterFont.h:261
int32_t getDescender(void) const
Definition: layouterFont.h:253
use vertical RGB (top to bottom)
Definition: layouterFont.h:64
GlyphSlot_c(int width, int height)
Definition: layouterFont.h:158
This class is thrown on problems with the FreeType library.
Definition: layouterFont.h:70
This class represents one font, made out of one font file resource with a certain size...
Definition: layouterFont.h:145
const internal::FontFileResource_c & getResource(void) const
get the font resource that was used to create this font
Definition: layouterFont.h:179
This class encapsulates an instance of the FreeType library.
Definition: layouterFont.h:275
don't use sub-pixel output (e.g. non LCD)
Definition: layouterFont.h:61
int32_t getAscender(void) const
Get the ascender of the font with multiplication factor of 64.
~FreeTypeLibrary_c()
Destroy the library instance.
void add(std::shared_ptr< FontFace_c > f)
Definition: layouterFont.h:239
int32_t getUnderlinePosition(void) const
Definition: layouterFont.h:254
void clear(void)
remove all fonts from the cache, fonts that are still in use will be kept, but all others are removed...
Definition: layouterFont.h:346