File indexing completed on 2024-06-16 10:03:15

0001 /*
0002     This file is part of the KDE libraries
0003 
0004     The Original Code is WOFF font packaging code.
0005     Copyright (C) 2009 Mozilla Corporation
0006 
0007     Contributor(s):
0008       Jonathan Kew <jfkthame@gmail.com>
0009       Germain Garand <germain@ebooksfrance.org>
0010 
0011     This library is free software; you can redistribute it and/or
0012     modify it under the terms of the GNU Library General Public
0013     License as published by the Free Software Foundation; either
0014     version 2 of the License, or (at your option) any later version.
0015 
0016     This library is distributed in the hope that it will be useful,
0017     but WITHOUT ANY WARRANTY; without even the implied warranty of
0018     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0019     Library General Public License for more details.
0020 
0021     You should have received a copy of the GNU Library General Public License
0022     along with this library; see the file COPYING.LIB.  If not, write to
0023     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0024     Boston, MA 02110-1301, USA.
0025 */
0026 
0027 #ifndef WOFF_PRIVATE_H_
0028 #define WOFF_PRIVATE_H_
0029 
0030 #include "woff.h"
0031 #include <QtGlobal>
0032 
0033 /* private definitions used in the WOFF encoder/decoder functions */
0034 
0035 /* create an OT tag from 4 characters */
0036 #define TAG(a,b,c,d) ((a)<<24 | (b)<<16 | (c)<<8 | (d))
0037 
0038 #define WOFF_SIGNATURE    TAG('w','O','F','F')
0039 
0040 #define SFNT_VERSION_CFF  TAG('O','T','T','O')
0041 #define SFNT_VERSION_TT   0x00010000
0042 #define SFNT_VERSION_true TAG('t','r','u','e')
0043 
0044 #define TABLE_TAG_DSIG    TAG('D','S','I','G')
0045 #define TABLE_TAG_head    TAG('h','e','a','d')
0046 #define TABLE_TAG_bhed    TAG('b','h','e','d')
0047 
0048 #define SFNT_CHECKSUM_CALC_CONST  0xB1B0AFBAU /* from the TT/OT spec */
0049 
0050 #if Q_BYTE_ORDER == Q_BIG_ENDIAN
0051 #  define READ16BE(x) (x)
0052 #  define READ32BE(x) (x)
0053 #else
0054 #  define READ16BE(x) ((((x) & 0xff) << 8) | (((x) >> 8) & 0xff))
0055 #  define READ32BE(x) ((READ16BE((x) & 0xffff) << 16) | (READ16BE((x) >> 16)))
0056 # endif
0057 
0058 #if defined(__SUNPRO_CC)
0059 #pragma pack(1) /* no pragma stack in Sun Studio */
0060 #else
0061 #pragma pack(push,1) /* assume this is GCC compatible */
0062 #endif
0063 
0064 typedef struct {
0065     quint32 version;
0066     quint16 numTables;
0067     quint16 searchRange;
0068     quint16 entrySelector;
0069     quint16 rangeShift;
0070 } sfntHeader;
0071 
0072 typedef struct {
0073     quint32 tag;
0074     quint32 checksum;
0075     quint32 offset;
0076     quint32 length;
0077 } sfntDirEntry;
0078 
0079 typedef struct {
0080     quint32 signature;
0081     quint32 flavor;
0082     quint32 length;
0083     quint16 numTables;
0084     quint16 reserved;
0085     quint32 totalSfntSize;
0086     quint16 majorVersion;
0087     quint16 minorVersion;
0088     quint32 metaOffset;
0089     quint32 metaCompLen;
0090     quint32 metaOrigLen;
0091     quint32 privOffset;
0092     quint32 privLen;
0093 } woffHeader;
0094 
0095 typedef struct {
0096     quint32 tag;
0097     quint32 offset;
0098     quint32 compLen;
0099     quint32 origLen;
0100     quint32 checksum;
0101 } woffDirEntry;
0102 
0103 typedef struct {
0104     quint32 version;
0105     quint32 fontRevision;
0106     quint32 checkSumAdjustment;
0107     quint32 magicNumber;
0108     quint16 flags;
0109     quint16 unitsPerEm;
0110     quint32 created[2];
0111     quint32 modified[2];
0112     qint16 xMin;
0113     qint16 yMin;
0114     qint16 xMax;
0115     qint16 yMax;
0116     quint16 macStyle;
0117     quint16 lowestRecPpem;
0118     qint16 fontDirectionHint;
0119     qint16 indexToLocFormat;
0120     qint16 glyphDataFormat;
0121 } sfntHeadTable;
0122 
0123 #define HEAD_TABLE_SIZE 54 /* sizeof(sfntHeadTable) may report 56 because of alignment */
0124 
0125 typedef struct {
0126     quint32 offset;
0127     quint16 oldIndex;
0128     quint16 newIndex;
0129 } tableOrderRec;
0130 
0131 #if defined(__SUNPRO_CC)
0132 #pragma pack()
0133 #else
0134 #pragma pack(pop)
0135 #endif
0136 
0137 #endif