1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/graphite2/src/inc/Font.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,89 @@ 1.4 +/* GRAPHITE2 LICENSING 1.5 + 1.6 + Copyright 2010, SIL International 1.7 + All rights reserved. 1.8 + 1.9 + This library is free software; you can redistribute it and/or modify 1.10 + it under the terms of the GNU Lesser General Public License as published 1.11 + by the Free Software Foundation; either version 2.1 of License, or 1.12 + (at your option) any later version. 1.13 + 1.14 + This program is distributed in the hope that it will be useful, 1.15 + but WITHOUT ANY WARRANTY; without even the implied warranty of 1.16 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1.17 + Lesser General Public License for more details. 1.18 + 1.19 + You should also have received a copy of the GNU Lesser General Public 1.20 + License along with this library in the file named "LICENSE". 1.21 + If not, write to the Free Software Foundation, 51 Franklin Street, 1.22 + Suite 500, Boston, MA 02110-1335, USA or visit their web page on the 1.23 + internet at http://www.fsf.org/licenses/lgpl.html. 1.24 + 1.25 +Alternatively, the contents of this file may be used under the terms of the 1.26 +Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public 1.27 +License, as published by the Free Software Foundation, either version 2 1.28 +of the License or (at your option) any later version. 1.29 +*/ 1.30 +#pragma once 1.31 +#include <cassert> 1.32 +#include "graphite2/Font.h" 1.33 +#include "inc/Main.h" 1.34 +#include "inc/Face.h" 1.35 + 1.36 +namespace graphite2 { 1.37 + 1.38 +#define INVALID_ADVANCE -1e38f // can't be a static const because non-integral 1.39 + 1.40 +class Font 1.41 +{ 1.42 +public: 1.43 + Font(float ppm, const Face & face, const void * appFontHandle=0, const gr_font_ops * ops=0); 1.44 + virtual ~Font(); 1.45 + 1.46 + float advance(unsigned short glyphid) const; 1.47 + float scale() const; 1.48 + bool isHinted() const; 1.49 + const Face & face() const; 1.50 + 1.51 + CLASS_NEW_DELETE; 1.52 +private: 1.53 + gr_font_ops m_ops; 1.54 + const void * const m_appFontHandle; 1.55 + float * m_advances; // One advance per glyph in pixels. Nan if not defined 1.56 + const Face & m_face; 1.57 + float m_scale; // scales from design units to ppm 1.58 + bool m_hinted; 1.59 + 1.60 + Font(const Font&); 1.61 + Font& operator=(const Font&); 1.62 +}; 1.63 + 1.64 +inline 1.65 +float Font::advance(unsigned short glyphid) const 1.66 +{ 1.67 + if (m_advances[glyphid] == INVALID_ADVANCE) 1.68 + m_advances[glyphid] = (*m_ops.glyph_advance_x)(m_appFontHandle, glyphid); 1.69 + return m_advances[glyphid]; 1.70 +} 1.71 + 1.72 +inline 1.73 +float Font::scale() const 1.74 +{ 1.75 + return m_scale; 1.76 +} 1.77 + 1.78 +inline 1.79 +bool Font::isHinted() const 1.80 +{ 1.81 + return m_hinted; 1.82 +} 1.83 + 1.84 +inline 1.85 +const Face & Font::face() const 1.86 +{ 1.87 + return m_face; 1.88 +} 1.89 + 1.90 +} // namespace graphite2 1.91 + 1.92 +struct gr_font : public graphite2::Font {};