44 #include <QtCore/QFile> 45 #include <QtCore/QFileInfo> 46 #include <QtCore/QDir> 47 #include <QtCore/QBuffer> 49 #include <QtGui/private/qapplication_p.h> 50 #include <QtGui/QPlatformFontDatabase> 51 #include <QtGui/private/qpaintengine_raster_p.h> 83 #if defined(DEBUG_HEADER) 84 # define DEBUG_VERIFY qDebug 86 # define DEBUG_VERIFY if (0) qDebug 89 #define READ_VERIFY(type, variable) \ 90 if (tagPtr + sizeof(type) > endPtr) { \ 91 DEBUG_VERIFY() << "read verify failed in line" << __LINE__; \ 94 variable = qFromBigEndian<type>(tagPtr); \ 95 DEBUG_VERIFY() << "read value" << variable << "of type " #type; \ 96 tagPtr += sizeof(type) 101 T value = qFromBigEndian<T>(
data);
106 #define VERIFY(condition) \ 107 if (!(condition)) { \ 108 DEBUG_VERIFY() << "condition " #condition " failed in line" << __LINE__; \ 112 #define VERIFY_TAG(condition) \ 113 if (!(condition)) { \ 114 DEBUG_VERIFY() << "verifying tag condition " #condition " failed in line" << __LINE__ << "with tag" << tag; \ 141 #if defined(DEBUG_HEADER) 143 qDebug() <<
"tag data" <<
hex << *tagPtr;
144 else if (length == 4)
145 qDebug() <<
"tag data" <<
hex << tagPtr[0] << tagPtr[1] << tagPtr[2] << tagPtr[3];
148 return tagPtr + length;
158 if (glyphPos == 0xffffffff)
160 #if defined(DEBUG_FONTENGINE) 161 qDebug() <<
"glyph" << g <<
"outside of glyphData, remapping font file";
173 if (header->
magic[0] !=
'Q' 174 || header->
magic[1] !=
'P' 175 || header->
magic[2] !=
'F' 176 || header->
magic[3] !=
'2')
185 while (tagPtr < tagEndPtr - 3) {
190 VERIFY(tagPtr <= tagEndPtr);
199 while (tagPtr < endPtr - 3) {
200 quint16 tag = readValue<quint16>(tagPtr);
201 quint16 length = readValue<quint16>(tagPtr);
202 if (tag == requestedTag) {
207 return QVariant(readValue<quint32>(tagPtr));
227 static inline unsigned int getChar(
const QChar *str,
int &i,
const int len)
230 if (str[i].isHighSurrogate() && i < len-1 && str[i+1].isLowSurrogate()) {
252 #if defined(DEBUG_FONTENGINE) 253 qDebug() <<
"QFontEngineQPA::QFontEngineQPA( fd =" << fd <<
", renderingFontEngine =" << renderingFontEngine <<
')';
257 #if defined(DEBUG_FONTENGINE) 258 qDebug() <<
"verifyHeader failed!";
269 while (imgData <= endPtr - 8) {
270 quint16 blockTag = readValue<quint16>(imgData);
309 if (glyphDataPos == 0xffffffff)
320 #if defined(DEBUG_FONTENGINE) 343 if (*nglyphs < len) {
348 #if defined(DEBUG_FONTENGINE) 357 for (
int i = 0; i < len; ++i) {
358 unsigned int uc =
getChar(str, i, len);
362 if(!glyphs->
glyphs[glyph_pos] && uc < 0x100)
367 for (
int i = 0; i < len; ++i) {
368 unsigned int uc =
getChar(str, i, len);
372 #if 0 && defined(DEBUG_FONTENGINE) 375 qDebug() <<
"glyph for character" << c <<
'/' <<
hex << uc <<
"is" <<
dec << glyphs[glyph_pos].glyph;
383 *nglyphs = glyph_pos;
391 for (
int i = 0; i < glyphs->
numGlyphs; ++i) {
429 for (
int i = 0; i < glyphs.
numGlyphs; i++) {
436 overall.
x =
qMin(overall.
x, x);
437 overall.
y =
qMin(overall.
y, y);
443 overall.
width = xmax - overall.
x;
512 for (
int i = 0; i < len; ++i) {
513 unsigned int uc =
getChar(
string, i, len);
521 for (
int i = 0; i < len; ++i) {
522 unsigned int uc =
getChar(
string, i, len);
550 header.
magic[0] =
'Q';
551 header.
magic[1] =
'P';
552 header.
magic[2] =
'F';
553 header.
magic[3] =
'2';
558 dev->write((
const char *)&header,
sizeof(header));
569 bool ok = fe->getSfntTableData(
MAKE_TAG(
'h',
'e',
'a',
'd'), data, &len);
595 const quint64 size = dev->pos();
596 header.dataSize = qToBigEndian<quint16>(size -
sizeof(header));
598 dev->write((
const char *)&header,
sizeof(header));
608 writeUInt32(glyphCount * 4);
611 const int numBytes = glyphCount *
sizeof(
quint32);
613 buffer.
resize(pos + numBytes);
615 dev->seek(pos + numBytes);
622 const int padSize = ((data.
size() + 3) / 4) * 4 - data.
size();
623 writeUInt32(data.
size() + padSize);
625 for (
int i = 0; i < padSize; ++i)
632 writeUInt16(
string.length());
639 writeUInt16(
sizeof(value));
646 writeUInt16(
sizeof(value));
654 writeUInt32(value.
value());
bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const
The QVariant class acts like a union for the most common Qt data types.
void addOutlineToPath(qreal x, qreal y, const QGlyphLayout &glyphs, QPainterPath *path, QTextItem::RenderFlags flags)
qreal minRightBearing() const
static QFixed fromFixed(int fixed)
QImage alphaMapForGlyph(glyph_t t)
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
#define QT_END_NAMESPACE
This macro expands to.
qreal minLeftBearing() const
char * data()
Returns a pointer to the data stored in the byte array.
void writeTaggedQFixed(QFontEngineQPA::HeaderTag tag, QFixed value)
bool kerning_pairs_loaded
bool getSfntTableData(uint tag, uchar *buffer, uint *length) const
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
T readValue(const uchar *&data)
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
#define at(className, varName)
The QByteArray class provides an array of bytes.
QFixed lineThickness() const
QFixed underlinePosition() const
static const uchar * getCMap(const uchar *table, uint tableSize, bool *isSymbolFont, int *cmapSize)
void recalcAdvances(QGlyphLayout *, QTextEngine::ShaperFlags) const
bool ref()
Atomically increments the value of this QAtomicInt.
quint32 qFromBigEndian< quint32 >(const uchar *src)
#define READ_VERIFY(type, variable)
QFontEngineMultiQPA(QFontEngine *fe, int script, const QStringList &fallbacks)
static QFixed fromReal(qreal r)
static const uchar * verifyTag(const uchar *tagPtr, const uchar *endPtr)
qreal maxCharWidth() const
The QChar class provides a 16-bit Unicode character.
static QVariant extractHeaderField(const uchar *data, HeaderTag tag)
Q_CORE_EXPORT QTextStream & hex(QTextStream &s)
Q_CORE_EXPORT QTextStream & dec(QTextStream &s)
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
static quint32 getTrueTypeGlyphIndex(const uchar *cmap, uint unicode)
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
#define MAKE_TAG(ch1, ch2, ch3, ch4)
Q_CORE_EXPORT void qDebug(const char *,...)
static QString toString(Register *reg, int type, bool *ok=0)
#define QT_BEGIN_NAMESPACE
This macro expands to.
bool contains(const T &value) const
void writeTaggedUInt32(QFontEngineQPA::HeaderTag tag, quint32 value)
const uchar * externalCMap
const T & at(int i) const
Returns the item at index position i in the list.
QChar mirroredChar() const
Returns the mirrored character if this character is a mirrored character; otherwise returns the chara...
The QStringList class provides a list of strings.
void writeTaggedUInt8(QFontEngineQPA::HeaderTag tag, quint8 value)
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
const_iterator insert(const T &value)
The QImage class provides a hardware-independent image representation that allows direct access to th...
void writeBlock(QFontEngineQPA::BlockTag tag, const QByteArray &data)
static const char * data(const QByteArray &arr)
void writeTaggedString(QFontEngineQPA::HeaderTag tag, const QByteArray &string)
Q_CORE_EXPORT int QT_FASTCALL script(uint ucs4)
const T & at(int i) const
Returns the item at index position i in the vector.
QVector< QFontEngine * > engines
static QFontEngineQPA::TagType tagTypes[QFontEngineQPA::NumTags]
quint16 qFromBigEndian< quint16 >(const uchar *src)
void * qMemSet(void *dest, int c, size_t n)
QFontEngineQPA(const QFontDef &def, const QByteArray &data)
static bool verifyHeader(const uchar *data, int size)
virtual int glyphCount() const
const Glyph * findGlyph(glyph_t g) const
void resize(int size)
Sets the size of the byte array to size bytes.
glyph_metrics_t boundingBox(const QGlyphLayout &glyphs)
static uint surrogateToUcs4(ushort high, ushort low)
Converts a UTF16 surrogate pair with the given high and low values to its UCS-4 code point...
int size() const
Returns the number of bytes in this byte array.
QStringList fallbackFamilies
QTextStream & hex(QTextStream &stream)
Calls QTextStream::setIntegerBase(16) on stream and returns stream.
static QByteArray encodeName(const QString &fileName)
By default, this function converts fileName to the local 8-bit encoding determined by the user's loca...
static unsigned int getChar(const QChar *str, int &i, const int len)
T value() const
Returns the stored value converted to the template type T.
#define VERIFY_TAG(condition)
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
int size() const
Returns the number of items in the vector.
void addBitmapFontToPath(qreal x, qreal y, const QGlyphLayout &, QPainterPath *, QTextItem::RenderFlags)
#define VERIFY(condition)
static qreal toReal(Register *reg, int type, bool *ok=0)
static QStringList fallbackFamilies(const QString &family, const QFont::Style &style, const QFont::StyleHint &styleHint, const QUnicodeTables::Script &script)
bool canRender(const QChar *string, int len)
static QFontEngine * findFont(int script, const QFontPrivate *fp, const QFontDef &request)