Copyright 2012, SIL International All rights reserved.
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should also have received a copy of the GNU Lesser General Public License along with this library in the file named "LICENSE". If not, write to the Free Software Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA or visit their web page on the internet at http://www.fsf.org/licenses/lgpl.html.
Alternatively, the contents of this file may be used under the terms of the Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public License, as published by the Free Software Foundation, either version 2 of the License or (at your option) any later version.
*/ #include"graphite2/Font.h"
#include"inc/Main.h" #include"inc/Face.h"//for the tags #include"inc/GlyphCache.h" #include"inc/GlyphFace.h" #include"inc/Endian.h" #include"inc/bits.h"
usingnamespace graphite2;
namespace
{ // Iterator over version 1 or 2 glat entries which consist of a series of // +-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+ // v1 |k|n|v1 |v2 |...|vN | or v2 | k | n |v1 |v2 |...|vN | // +-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+ // variable length structures.
// This is strictly a >= operator. A true == operator could be // implemented that test for overlap but it would be more expensive a // test. booloperator == (const _glat_iterator<W> & rhs) { return _v >= rhs._e - 1; } booloperator != (const _glat_iterator<W> & rhs) { return !operator==(rhs); }
// The 0 glyph is definately required.
_glyphs[0] = _glyph_loader->read_glyph(0, glyphs[0], &numsubs);
// glyphs[0] has the same address as the glyphs array just allocated, // thus assigning the &glyphs[0] to _glyphs[0] means _glyphs[0] points // to the entire array. const GlyphFace * loaded = _glyphs[0]; for (uint16 gid = 1; loaded && gid != _num_glyphs; ++gid)
_glyphs[gid] = loaded = _glyph_loader->read_glyph(gid, glyphs[gid], &numsubs);
for (uint16 gid = 0; currbox && gid != _num_glyphs; ++gid)
{
_boxes[gid] = currbox;
currbox = _glyph_loader->read_box(gid, currbox, *_glyphs[gid]);
} if (!currbox)
{
free(boxes);
_boxes[0] = 0;
}
} delete _glyph_loader;
_glyph_loader = 0; // coverity[leaked_storage : FALSE] - calling read_glyph on index 0 saved // glyphs as _glyphs[0]. Setting _glyph_loader to nullptr here flags that // the dtor needs to call delete[] on _glyphs[0] to release what was allocated // as glyphs
}
_num_glyphs_graphics = static_cast<unsignedshort>(TtfUtil::GlyphCount(maxp)); // This will fail if the number of glyphs is wildly out of range. if (_glyf && TtfUtil::LocaLookup(_num_glyphs_graphics-1, _loca, _loca.size(), _head) == size_t(-2))
{
_head = Face::Table(); return;
}
if ((m_pGlat = Face::Table(face, Tag::Glat, 0x00030000)) == NULL
|| (m_pGloc = Face::Table(face, Tag::Gloc)) == NULL
|| m_pGloc.size() < 8)
{
_head = Face::Table(); return;
} const byte * p = m_pGloc; int version = be::read<uint32>(p); const uint16 flags = be::read<uint16>(p);
_num_attrs = be::read<uint16>(p); // We can accurately calculate the number of attributed glyphs by // subtracting the length of the attribids array (numAttribs long if present) // and dividing by either 2 or 4 depending on shor or lonf format
_long_fmt = flags & 1;
ptrdiff_t tmpnumgattrs = (m_pGloc.size()
- (p - m_pGloc)
- sizeof(uint16)*(flags & 0x2 ? _num_attrs : 0))
/ (_long_fmt ? sizeof(uint32) : sizeof(uint16)) - 1;
if (version >= 0x00020000 || tmpnumgattrs < 0 || tmpnumgattrs > 65535
|| _num_attrs == 0 || _num_attrs > 0x3000 // is this hard limit appropriate?
|| _num_glyphs_graphics > tmpnumgattrs
|| m_pGlat.size() < 4)
{
_head = Face::Table(); return;
}
_num_glyphs_attributes = static_cast<unsignedshort>(tmpnumgattrs);
p = m_pGlat;
version = be::read<uint32>(p); if (version >= 0x00040000 || (version >= 0x00030000 && m_pGlat.size() < 8)) // reject Glat tables that are too new
{
_head = Face::Table(); return;
} elseif (version >= 0x00030000)
{ unsignedint glatflags = be::read<uint32>(p);
_has_boxes = glatflags & 1; // delete this once the compiler is fixed
_has_boxes = true;
}
}
const GlyphFace * GlyphCache::Loader::read_glyph(unsignedshort glyphid, GlyphFace & glyph, int *numsubs) constthrow()
{
Rect bbox;
Position advance;
if (glyphid < _num_glyphs_graphics)
{ int nLsb; unsignedint nAdvWid; if (_glyf)
{ int xMin, yMin, xMax, yMax;
size_t locidx = TtfUtil::LocaLookup(glyphid, _loca, _loca.size(), _head); void *pGlyph = TtfUtil::GlyfLookup(_glyf, locidx, _glyf.size());
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.