1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2016 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of the tools applications of the Qt Toolkit. 7 ** 8 ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ 9 ** Commercial License Usage 10 ** Licensees holding valid commercial Qt licenses may use this file in 11 ** accordance with the commercial license agreement provided with the 12 ** Software or, alternatively, in accordance with the terms contained in 13 ** a written agreement between you and The Qt Company. For licensing terms 14 ** and conditions see https://www.qt.io/terms-conditions. For further 15 ** information use the contact form at https://www.qt.io/contact-us. 16 ** 17 ** GNU General Public License Usage 18 ** Alternatively, this file may be used under the terms of the GNU 19 ** General Public License version 3 as published by the Free Software 20 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 21 ** included in the packaging of this file. Please review the following 22 ** information to ensure the GNU General Public License requirements will 23 ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 24 ** 25 ** $QT_END_LICENSE$ 26 ** 27 ****************************************************************************/ 28 29 #ifndef QPF2_H 30 #define QPF2_H 31 32 #include <private/qfontengine_qpf2_p.h> 33 #include <qmetatype.h> 34 35 QT_BEGIN_NAMESPACE 36 37 class QFontEngine; 38 39 class QPF 40 { 41 public: 42 static int debugVerbosity; 43 44 enum GenerationOption { 45 IncludeCMap = 0x1, 46 RenderGlyphs = 0x2 47 }; 48 49 struct CharacterRange 50 { CharacterRangeCharacterRange51 inline CharacterRange() : start(0), end(0x10000) {} 52 uint start; 53 uint end; 54 }; 55 56 static QString fileNameForFont(const QFont &f); 57 58 static QByteArray generate(const QFont &font, int options, 59 const QList<CharacterRange> &ranges, 60 QString *originalFontFile = 0); 61 static QByteArray generate(QFontEngine *fontEngine, int options, const QList<CharacterRange> &ranges); 62 void addHeader(QFontEngine *fontEngine); 63 void addCMap(QFontEngine *fontEngine); 64 void addGlyphs(QFontEngine *fontEngine, const QList<CharacterRange> &ranges); 65 void addBlock(QFontEngineQPF2::BlockTag tag, const QByteArray &data); 66 67 void addTaggedString(QFontEngineQPF2::HeaderTag tag, const QByteArray &string); 68 void addTaggedQFixed(QFontEngineQPF2::HeaderTag tag, QFixed value); 69 void addTaggedUInt8(QFontEngineQPF2::HeaderTag tag, quint8 value); 70 void addTaggedInt8(QFontEngineQPF2::HeaderTag tag, qint8 value); 71 void addTaggedUInt16(QFontEngineQPF2::HeaderTag tag, quint16 value); 72 void addTaggedUInt32(QFontEngineQPF2::HeaderTag tag, quint32 value); 73 74 static void dump(const QByteArray &qpf); 75 const uchar *dumpHeader(const uchar *data); 76 const uchar *dumpHeaderTag(const uchar *data); 77 void dumpGMapBlock(const quint32 *gmap, int glyphCount); 78 void dumpGlyphBlock(const quint32 *gmap, int glyphCount, const uchar *data, const uchar *endPtr); 79 void dumpGlyph(const uchar *data, const QFontEngineQPF2::Glyph *glyph); 80 addUInt16(quint16 value)81 void addUInt16(quint16 value) { qToBigEndian(value, addBytes(sizeof(value))); } addUInt32(quint32 value)82 void addUInt32(quint32 value) { qToBigEndian(value, addBytes(sizeof(value))); } addUInt8(quint8 value)83 void addUInt8(quint8 value) { *addBytes(sizeof(value)) = value; } addInt8(qint8 value)84 void addInt8(qint8 value) { *addBytes(sizeof(value)) = quint8(value); } addByteArray(const QByteArray & string)85 void addByteArray(const QByteArray &string) { 86 uchar *data = addBytes(string.length()); 87 qMemCopy(data, string.constData(), string.length()); 88 } 89 align4()90 void align4() { while (qpf.size() & 3) { addUInt8('\0'); } } 91 addBytes(int size)92 uchar *addBytes(int size) { 93 const int oldSize = qpf.size(); 94 qpf.resize(qpf.size() + size); 95 return reinterpret_cast<uchar *>(qpf.data() + oldSize); 96 } 97 98 QByteArray qpf; 99 int options; 100 }; 101 102 QT_END_NAMESPACE 103 104 Q_DECLARE_METATYPE(QPF::CharacterRange) 105 106 #endif // QPF2_H 107