gfx/graphite2/src/inc/Face.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* GRAPHITE2 LICENSING
michael@0 2
michael@0 3 Copyright 2010, SIL International
michael@0 4 All rights reserved.
michael@0 5
michael@0 6 This library is free software; you can redistribute it and/or modify
michael@0 7 it under the terms of the GNU Lesser General Public License as published
michael@0 8 by the Free Software Foundation; either version 2.1 of License, or
michael@0 9 (at your option) any later version.
michael@0 10
michael@0 11 This program is distributed in the hope that it will be useful,
michael@0 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
michael@0 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
michael@0 14 Lesser General Public License for more details.
michael@0 15
michael@0 16 You should also have received a copy of the GNU Lesser General Public
michael@0 17 License along with this library in the file named "LICENSE".
michael@0 18 If not, write to the Free Software Foundation, 51 Franklin Street,
michael@0 19 Suite 500, Boston, MA 02110-1335, USA or visit their web page on the
michael@0 20 internet at http://www.fsf.org/licenses/lgpl.html.
michael@0 21
michael@0 22 Alternatively, the contents of this file may be used under the terms of the
michael@0 23 Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public
michael@0 24 License, as published by the Free Software Foundation, either version 2
michael@0 25 of the License or (at your option) any later version.
michael@0 26 */
michael@0 27 #pragma once
michael@0 28
michael@0 29 #include <stdio.h>
michael@0 30
michael@0 31 #include "graphite2/Font.h"
michael@0 32
michael@0 33 #include "inc/Main.h"
michael@0 34 #include "inc/FeatureMap.h"
michael@0 35 #include "inc/TtfUtil.h"
michael@0 36 #include "inc/Silf.h"
michael@0 37 #include "inc/Error.h"
michael@0 38
michael@0 39 namespace graphite2 {
michael@0 40
michael@0 41 class Cmap;
michael@0 42 class FileFace;
michael@0 43 class GlyphCache;
michael@0 44 class NameTable;
michael@0 45 class json;
michael@0 46
michael@0 47
michael@0 48 using TtfUtil::Tag;
michael@0 49
michael@0 50 // These are the actual tags, as distinct from the consecutive IDs in TtfUtil.h
michael@0 51
michael@0 52 class Face
michael@0 53 {
michael@0 54 // Prevent any kind of copying
michael@0 55 Face(const Face&);
michael@0 56 Face& operator=(const Face&);
michael@0 57
michael@0 58 public:
michael@0 59 class Table;
michael@0 60 static float default_glyph_advance(const void* face_ptr, gr_uint16 glyphid);
michael@0 61
michael@0 62 Face(const void* appFaceHandle/*non-NULL*/, const gr_face_ops & ops);
michael@0 63 virtual ~Face();
michael@0 64
michael@0 65 virtual bool runGraphite(Segment *seg, const Silf *silf) const;
michael@0 66
michael@0 67 public:
michael@0 68 bool readGlyphs(uint32 faceOptions);
michael@0 69 bool readGraphite(const Table & silf);
michael@0 70 bool readFeatures();
michael@0 71 void takeFileFace(FileFace* pFileFace/*takes ownership*/);
michael@0 72
michael@0 73 const SillMap & theSill() const;
michael@0 74 const GlyphCache & glyphs() const;
michael@0 75 Cmap & cmap() const;
michael@0 76 NameTable * nameTable() const;
michael@0 77 void setLogger(FILE *log_file);
michael@0 78 json * logger() const throw();
michael@0 79
michael@0 80 const Silf * chooseSilf(uint32 script) const;
michael@0 81 uint16 languageForLocale(const char * locale) const;
michael@0 82
michael@0 83 // Features
michael@0 84 uint16 numFeatures() const;
michael@0 85 const FeatureRef * featureById(uint32 id) const;
michael@0 86 const FeatureRef * feature(uint16 index) const;
michael@0 87
michael@0 88 // Glyph related
michael@0 89 uint16 getGlyphMetric(uint16 gid, uint8 metric) const;
michael@0 90 uint16 findPseudo(uint32 uid) const;
michael@0 91
michael@0 92 // Errors
michael@0 93 unsigned int error() const { return m_error; }
michael@0 94 bool error(Error e) { m_error = e.error(); return false; }
michael@0 95 unsigned int error_context() const { return m_error; }
michael@0 96 void error_context(unsigned int errcntxt) { m_errcntxt = errcntxt; }
michael@0 97
michael@0 98 CLASS_NEW_DELETE;
michael@0 99 private:
michael@0 100 SillMap m_Sill;
michael@0 101 gr_face_ops m_ops;
michael@0 102 const void * m_appFaceHandle; // non-NULL
michael@0 103 FileFace * m_pFileFace; //owned
michael@0 104 mutable GlyphCache * m_pGlyphFaceCache; // owned - never NULL
michael@0 105 mutable Cmap * m_cmap; // cmap cache if available
michael@0 106 mutable NameTable * m_pNames;
michael@0 107 mutable json * m_logger;
michael@0 108 unsigned int m_error;
michael@0 109 unsigned int m_errcntxt;
michael@0 110 protected:
michael@0 111 Silf * m_silfs; // silf subtables.
michael@0 112 uint16 m_numSilf; // num silf subtables in the silf table
michael@0 113 private:
michael@0 114 uint16 m_ascent,
michael@0 115 m_descent;
michael@0 116 #ifdef GRAPHITE2_TELEMETRY
michael@0 117 public:
michael@0 118 mutable telemetry tele;
michael@0 119 #endif
michael@0 120 };
michael@0 121
michael@0 122
michael@0 123
michael@0 124 inline
michael@0 125 const SillMap & Face::theSill() const
michael@0 126 {
michael@0 127 return m_Sill;
michael@0 128 }
michael@0 129
michael@0 130 inline
michael@0 131 uint16 Face::numFeatures() const
michael@0 132 {
michael@0 133 return m_Sill.theFeatureMap().numFeats();
michael@0 134 }
michael@0 135
michael@0 136 inline
michael@0 137 const FeatureRef * Face::featureById(uint32 id) const
michael@0 138 {
michael@0 139 return m_Sill.theFeatureMap().findFeatureRef(id);
michael@0 140 }
michael@0 141
michael@0 142 inline
michael@0 143 const FeatureRef *Face::feature(uint16 index) const
michael@0 144 {
michael@0 145 return m_Sill.theFeatureMap().feature(index);
michael@0 146 }
michael@0 147
michael@0 148 inline
michael@0 149 const GlyphCache & Face::glyphs() const
michael@0 150 {
michael@0 151 return *m_pGlyphFaceCache;
michael@0 152 }
michael@0 153
michael@0 154 inline
michael@0 155 Cmap & Face::cmap() const
michael@0 156 {
michael@0 157 return *m_cmap;
michael@0 158 };
michael@0 159
michael@0 160 inline
michael@0 161 json * Face::logger() const throw()
michael@0 162 {
michael@0 163 return m_logger;
michael@0 164 }
michael@0 165
michael@0 166
michael@0 167
michael@0 168 class Face::Table
michael@0 169 {
michael@0 170 const Face * _f;
michael@0 171 mutable const byte * _p;
michael@0 172 uint32 _sz;
michael@0 173
michael@0 174 public:
michael@0 175 Table() throw();
michael@0 176 Table(const Face & face, const Tag n) throw();
michael@0 177 Table(const Table & rhs) throw();
michael@0 178 ~Table() throw();
michael@0 179
michael@0 180 operator const byte * () const throw();
michael@0 181
michael@0 182 Table & operator = (const Table & rhs) throw();
michael@0 183 size_t size() const throw();
michael@0 184 };
michael@0 185
michael@0 186 inline
michael@0 187 Face::Table::Table() throw()
michael@0 188 : _f(0), _p(0), _sz(0)
michael@0 189 {
michael@0 190 }
michael@0 191
michael@0 192 inline
michael@0 193 Face::Table::Table(const Table & rhs) throw()
michael@0 194 : _f(rhs._f), _p(rhs._p), _sz(rhs._sz)
michael@0 195 {
michael@0 196 rhs._p = 0;
michael@0 197 }
michael@0 198
michael@0 199 inline
michael@0 200 Face::Table::~Table() throw()
michael@0 201 {
michael@0 202 if (_p && _f->m_ops.release_table)
michael@0 203 (*_f->m_ops.release_table)(_f->m_appFaceHandle, _p);
michael@0 204 }
michael@0 205
michael@0 206 inline
michael@0 207 Face::Table::operator const byte * () const throw()
michael@0 208 {
michael@0 209 return _p;
michael@0 210 }
michael@0 211
michael@0 212 inline
michael@0 213 size_t Face::Table::size() const throw()
michael@0 214 {
michael@0 215 return _sz;
michael@0 216 }
michael@0 217
michael@0 218 } // namespace graphite2
michael@0 219
michael@0 220 struct gr_face : public graphite2::Face {};

mercurial