| 1 |
// SPDX-License-Identifier: MIT OR MPL-2.0 OR LGPL-2.1-or-later OR GPL-2.0-or-later |
| 2 |
// Copyright 2010, SIL International, All rights reserved. |
| 3 |
|
| 4 |
#pragma once |
| 5 |
#include <cassert> |
| 6 |
#include "graphite2/Font.h" |
| 7 |
#include "inc/Main.h" |
| 8 |
#include "inc/Face.h" |
| 9 |
|
| 10 |
namespace graphite2 { |
| 11 |
|
| 12 |
#define INVALID_ADVANCE -1e38f // can't be a static const because non-integral |
| 13 |
|
| 14 |
class Font |
| 15 |
{ |
| 16 |
public: |
| 17 |
Font(float ppm, const Face & face, const void * appFontHandle=0, const gr_font_ops * ops=0); |
| 18 |
virtual ~Font(); |
| 19 |
|
| 20 |
float advance(unsigned short glyphid) const; |
| 21 |
float scale() const; |
| 22 |
bool isHinted() const; |
| 23 |
const Face & face() const; |
| 24 |
operator bool () const throw() { return m_advances; } |
| 25 |
|
| 26 |
CLASS_NEW_DELETE; |
| 27 |
private: |
| 28 |
gr_font_ops m_ops; |
| 29 |
const void * const m_appFontHandle; |
| 30 |
float * m_advances; // One advance per glyph in pixels. Nan if not defined |
| 31 |
const Face & m_face; |
| 32 |
float m_scale; // scales from design units to ppm |
| 33 |
bool m_hinted; |
| 34 |
|
| 35 |
Font(const Font&); |
| 36 |
Font& operator=(const Font&); |
| 37 |
}; |
| 38 |
|
| 39 |
inline |
| 40 |
float Font::advance(unsigned short glyphid) const |
| 41 |
{ |
| 42 |
if (m_advances[glyphid] == INVALID_ADVANCE) |
| 43 |
m_advances[glyphid] = (*m_ops.glyph_advance_x)(m_appFontHandle, glyphid); |
| 44 |
return m_advances[glyphid]; |
| 45 |
} |
| 46 |
|
| 47 |
inline |
| 48 |
float Font::scale() const |
| 49 |
{ |
| 50 |
return m_scale; |
| 51 |
} |
| 52 |
|
| 53 |
inline |
| 54 |
bool Font::isHinted() const |
| 55 |
{ |
| 56 |
return m_hinted; |
| 57 |
} |
| 58 |
|
| 59 |
inline |
| 60 |
const Face & Font::face() const |
| 61 |
{ |
| 62 |
return m_face; |
| 63 |
} |
| 64 |
|
| 65 |
} // namespace graphite2 |
| 66 |
|
| 67 |
struct gr_font : public graphite2::Font {}; |