1 : /* GRAPHITE2 LICENSING
2 :
3 : Copyright 2010, SIL International
4 : All rights reserved.
5 :
6 : This library is free software; you can redistribute it and/or modify
7 : it under the terms of the GNU Lesser General Public License as published
8 : by the Free Software Foundation; either version 2.1 of License, or
9 : (at your option) any later version.
10 :
11 : This program is distributed in the hope that it will be useful,
12 : but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 : Lesser General Public License for more details.
15 :
16 : You should also have received a copy of the GNU Lesser General Public
17 : License along with this library in the file named "LICENSE".
18 : If not, write to the Free Software Foundation, 51 Franklin Street,
19 : Suite 500, Boston, MA 02110-1335, USA or visit their web page on the
20 : internet at http://www.fsf.org/licenses/lgpl.html.
21 :
22 : Alternatively, the contents of this file may be used under the terms of the
23 : Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public
24 : License, as published by the Free Software Foundation, either version 2
25 : of the License or (at your option) any later version.
26 : */
27 : #include "inc/Font.h"
28 :
29 :
30 : using namespace graphite2;
31 :
32 0 : Font::Font(float ppm, const Face *face/*needed for scaling*/) :
33 0 : m_scale(ppm / face->upem())
34 : {
35 0 : size_t nGlyphs=face->numGlyphs();
36 0 : m_advances = gralloc<float>(nGlyphs);
37 0 : if (m_advances)
38 : {
39 0 : float *advp = m_advances;
40 0 : for (size_t i = 0; i < nGlyphs; i++)
41 0 : { *advp++ = INVALID_ADVANCE; }
42 : }
43 0 : }
44 :
45 :
46 0 : /*virtual*/ Font::~Font()
47 : {
48 0 : free(m_advances);
49 0 : }
50 :
51 :
52 0 : SimpleFont::SimpleFont(float ppm/*pixels per em*/, const Face *face) :
53 : Font(ppm, face),
54 0 : m_face(face)
55 : {
56 0 : }
57 :
58 :
59 0 : /*virtual*/ float SimpleFont::computeAdvance(unsigned short glyphid) const
60 : {
61 0 : return m_face->getAdvance(glyphid, m_scale);
62 : }
63 :
64 :
65 :
66 0 : HintedFont::HintedFont(float ppm/*pixels per em*/, const void* appFontHandle/*non-NULL*/, gr_advance_fn advance2, const Face *face/*needed for scaling*/) :
67 : Font(ppm, face),
68 : m_appFontHandle(appFontHandle),
69 0 : m_advance(advance2)
70 : {
71 0 : }
72 :
73 :
74 0 : /*virtual*/ float HintedFont::computeAdvance(unsigned short glyphid) const
75 : {
76 0 : return (*m_advance)(m_appFontHandle, glyphid);
77 : }
78 :
79 :
80 :
|