Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/graphite/src/Font.cpp
9902 views
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
#include "inc/Face.h"
5
#include "inc/Font.h"
6
#include "inc/GlyphCache.h"
7
8
using namespace graphite2;
9
10
Font::Font(float ppm, const Face & f, const void * appFontHandle, const gr_font_ops * ops)
11
: m_appFontHandle(appFontHandle ? appFontHandle : this),
12
m_face(f),
13
m_scale(ppm / f.glyphs().unitsPerEm()),
14
m_hinted(appFontHandle && ops && (ops->glyph_advance_x || ops->glyph_advance_y))
15
{
16
memset(&m_ops, 0, sizeof m_ops);
17
if (m_hinted && ops)
18
memcpy(&m_ops, ops, min(sizeof m_ops, ops->size));
19
else
20
m_ops.glyph_advance_x = &Face::default_glyph_advance;
21
22
size_t nGlyphs = f.glyphs().numGlyphs();
23
m_advances = gralloc<float>(nGlyphs);
24
if (m_advances)
25
{
26
for (float *advp = m_advances; nGlyphs; --nGlyphs, ++advp)
27
*advp = INVALID_ADVANCE;
28
}
29
}
30
31
32
/*virtual*/ Font::~Font()
33
{
34
free(m_advances);
35
}
36
37