44 #include "private/qpaintengine_raster_p.h" 45 #include <QtCore/qlibraryinfo.h> 46 #include <QtCore/qfileinfo.h> 48 #include <QtCore/qfile.h> 49 #include <QtCore/qdir.h> 50 #include <QtCore/qbuffer.h> 51 #if !defined(QT_NO_FREETYPE) 52 #include "private/qfontengine_ft_p.h" 54 #include "private/qcore_unix_p.h" 59 #include <sys/types.h> 67 #ifndef QT_NO_QWS_QPF2 74 # include "private/qwscommand_qws_p.h" 78 #include "qplatformdefs.h" 84 #if defined(DEBUG_HEADER) 85 # define DEBUG_VERIFY qDebug 87 # define DEBUG_VERIFY if (0) qDebug 90 #define READ_VERIFY(type, variable) \ 91 if (tagPtr + sizeof(type) > endPtr) { \ 92 DEBUG_VERIFY() << "read verify failed in line" << __LINE__; \ 95 variable = qFromBigEndian<type>(tagPtr); \ 96 DEBUG_VERIFY() << "read value" << variable << "of type " #type; \ 97 tagPtr += sizeof(type) 102 T value = qFromBigEndian<T>(
data);
107 #define VERIFY(condition) \ 108 if (!(condition)) { \ 109 DEBUG_VERIFY() << "condition " #condition " failed in line" << __LINE__; \ 113 #define VERIFY_TAG(condition) \ 114 if (!(condition)) { \ 115 DEBUG_VERIFY() << "verifying tag condition " #condition " failed in line" << __LINE__ << "with tag" << tag; \ 142 #if defined(DEBUG_HEADER) 144 qDebug() <<
"tag data" <<
hex << *tagPtr;
145 else if (length == 4)
146 qDebug() <<
"tag data" <<
hex << tagPtr[0] << tagPtr[1] << tagPtr[2] << tagPtr[3];
149 return tagPtr + length;
159 if (glyphPos == 0xffffffff)
161 #if defined(DEBUG_FONTENGINE) 162 qDebug() <<
"glyph" << g <<
"outside of glyphData, remapping font file";
164 #if !defined(QT_NO_FREETYPE) && !defined(QT_FONTS_ARE_RESOURCES) 177 if (header->
magic[0] !=
'Q' 178 || header->
magic[1] !=
'P' 179 || header->
magic[2] !=
'F' 180 || header->
magic[3] !=
'2')
189 while (tagPtr < tagEndPtr - 3) {
194 VERIFY(tagPtr <= tagEndPtr);
203 while (tagPtr < endPtr - 3) {
204 quint16 tag = readValue<quint16>(tagPtr);
205 quint16 length = readValue<quint16>(tagPtr);
206 if (tag == requestedTag) {
211 return QVariant(readValue<quint32>(tagPtr));
229 #endif // QT_NO_QWS_QPF2 234 #if defined(Q_WS_QWS) 247 #ifndef QT_NO_QWS_QPF2 249 #ifndef QT_FONTS_ARE_RESOURCES 263 if (lockValue && crashedClientIds.
contains(lockValue)) {
264 removedFonts.
append(fileName);
274 qDebug() <<
"list of corrupted and removed fonts:" << removedFonts;
279 static inline unsigned int getChar(
const QChar *str,
int &i,
const int len)
282 if (str[i].isHighSurrogate() && i < len-1 && str[i+1].isLowSurrogate()) {
288 #ifdef QT_FONTS_ARE_RESOURCES 311 #if defined(DEBUG_FONTENGINE) 315 #ifndef QT_FONTS_ARE_RESOURCES 317 if (!renderingFontEngine)
331 #if defined(DEBUG_FONTENGINE) 341 #if defined(DEBUG_FONTENGINE) 348 #if defined(DEBUG_FONTENGINE) 354 #if defined(DEBUG_FONTENGINE) 360 #if defined(DEBUG_FONTENGINE) 373 #if defined(DEBUG_FONTENGINE) 379 #if defined(DEBUG_FONTENGINE) 388 if (QT_FSTAT(
fd, &st)) {
389 #if defined(DEBUG_FONTENGINE) 397 fontData = (
const uchar *)::mmap(0, st.st_size, PROT_READ | (renderingFontEngine ? PROT_WRITE : 0), MAP_SHARED,
fd, 0);
399 #if defined(DEBUG_FONTENGINE) 400 perror(
"mmap failed");
405 #endif //QT_FONTS_ARE_RESOURCES 408 #if defined(DEBUG_FONTENGINE) 409 qDebug() <<
"verifyHeader failed!";
420 while (data <= endPtr - 8) {
441 #if !defined(QT_NO_FREETYPE) && !defined(QT_FONTS_ARE_RESOURCES) 445 #ifndef QT_NO_SETTINGS 458 if (!ok || length != 4
489 if (glyphDataPos == 0xffffffff)
500 #if defined(DEBUG_FONTENGINE) 507 #if defined(Q_WS_QWS) 515 #if defined(Q_WS_QWS) 520 qDebug(
"QFontEngineQPF::~QFontEngineQPF: Out of memory");
528 #if defined(DEBUG_FONTENGINE) 535 #if !defined(QT_NO_FREETYPE) 543 #if !defined(QT_NO_FREETYPE) 558 #ifndef QT_NO_FREETYPE 564 if (*nglyphs < len) {
569 #if defined(DEBUG_FONTENGINE) 578 for (
int i = 0; i < len; ++i) {
579 unsigned int uc =
getChar(str, i, len);
581 if(!glyphs->
glyphs[glyph_pos] && uc < 0x100)
586 for (
int i = 0; i < len; ++i) {
587 unsigned int uc =
getChar(str, i, len);
591 #if 0 && defined(DEBUG_FONTENGINE) 594 qDebug() <<
"glyph for character" << c <<
'/' <<
hex << uc <<
"is" <<
dec << glyphs[glyph_pos].glyph;
602 *nglyphs = glyph_pos;
610 #ifndef QT_NO_FREETYPE 613 for (
int i = 0; i < glyphs->
numGlyphs; ++i) {
633 for (
int j=0; j<256; ++j)
636 for (
int i=0; i<glyph->
height; ++i) {
656 if (glyphs.
size() == 0)
659 for(
int i = 0; i < glyphs.
size(); i++) {
667 qRound(positions[i].x) + glyph->
x,
668 qRound(positions[i].y) + glyph->
y,
686 #ifndef QT_NO_FREETYPE 697 for (
int i = 0; i < glyphs.
numGlyphs; i++) {
704 overall.
x =
qMin(overall.
x, x);
705 overall.
y =
qMin(overall.
y, y);
711 overall.
width = xmax - overall.
x;
718 #ifndef QT_NO_FREETYPE 787 for (
int i = 0; i < len; ++i) {
788 unsigned int uc =
getChar(
string, i, len);
796 for (
int i = 0; i < len; ++i) {
797 unsigned int uc =
getChar(
string, i, len);
811 #if !defined(QT_NO_FREETYPE) 820 const int xsize = ysize;
823 FT_Set_Char_Size(face, xsize, ysize, 0, 0);
827 FT_Matrix identityMatrix;
828 identityMatrix.xx = 0x10000;
829 identityMatrix.yy = 0x10000;
830 identityMatrix.xy = 0;
831 identityMatrix.yx = 0;
868 return HB_Err_Not_Covered;
890 for (
int i = 0; i < glyphs.
numGlyphs; ++i) {
908 #if defined(DEBUG_FONTENGINE) 909 qDebug() <<
"Finished rendering glyphs\n";
922 bool mono = img.
depth() == 1;
935 off_t oldSize = ::lseek(
fd, 0, SEEK_END);
936 if (oldSize == (off_t)-1)
951 #if 0 && defined(DEBUG_FONTENGINE) 952 qDebug() <<
"glyphPos for new glyph" << glyph <<
"is" << glyphPos <<
"oldSize" << oldSize <<
"glyphDataOffset" <<
glyphDataOffset;
968 lock.l_type = F_WRLCK;
969 lock.l_whence = SEEK_SET;
972 while (
fcntl(
fd, F_SETLKW, &lock) != 0) {
975 perror(
"locking qpf");
980 lock.l_type = F_UNLCK;
981 if (
fcntl(
fd, F_SETLK, &lock) != 0)
982 perror(
"unlocking possibly corrupt qpf");
985 #if defined(Q_WS_QWS) 1001 lock.l_type = F_UNLCK;
1002 lock.l_whence = SEEK_SET;
1005 if (
fcntl(
fd, F_SETLK, &lock) != 0) {
1006 perror(
"unlocking qpf");
1014 off_t newFileSize = ::lseek(
fd, 0, SEEK_END);
1015 if (newFileSize == (off_t)-1) {
1016 #ifdef DEBUG_FONTENGINE 1017 perror(
"QFontEngineQPF::remapFontData: lseek failed");
1023 #ifndef QT_NO_MREMAP 1026 # if defined(DEBUG_FONTENGINE) 1027 perror(
"QFontEngineQPF::remapFontData(): mremap failed");
1033 #endif // QT_NO_MREMAP 1037 qErrnoWarning(status,
"QFontEngineQPF::remapFomrData: munmap failed!");
1042 # if defined(DEBUG_FONTENGINE) 1043 perror(
"mmap failed");
1052 #if defined(DEBUG_FONTENGINE) 1053 qDebug() <<
"remapped the font file to" << newFileSize <<
"bytes";
1057 #endif // QT_NO_FREETYPE 1073 header.
magic[0] =
'Q';
1074 header.
magic[1] =
'P';
1075 header.
magic[2] =
'F';
1076 header.
magic[3] =
'2';
1081 dev->write((
const char *)&header,
sizeof(header));
1092 bool ok = fe->getSfntTableData(
MAKE_TAG(
'h',
'e',
'a',
'd'), data, &len);
1118 const quint64 size = dev->pos();
1119 header.dataSize = qToBigEndian<quint16>(size -
sizeof(header));
1121 dev->write((
const char *)&header,
sizeof(header));
1131 writeUInt32(glyphCount * 4);
1134 const int numBytes = glyphCount *
sizeof(
quint32);
1136 buffer.
resize(pos + numBytes);
1138 dev->seek(pos + numBytes);
1145 const int padSize = ((data.
size() + 3) / 4) * 4 - data.
size();
1146 writeUInt32(data.
size() + padSize);
1148 for (
int i = 0; i < padSize; ++i)
1155 writeUInt16(
string.length());
1162 writeUInt16(
sizeof(value));
1169 writeUInt16(
sizeof(value));
1177 writeUInt32(value.
value());
1180 #endif // QT_NO_QWS_QPF2 1214 qFatal(
"QFontEngineMultiQWS::draw should never be called!");
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
The QVariant class acts like a union for the most common Qt data types.
void ensureGlyphsLoaded(const QGlyphLayout &glyphs)
The QDir class provides access to directory structures and their contents.
static QFreetypeFace * getFace(const QFontEngine::FaceId &face_id, const QByteArray &fontData=QByteArray())
HB_Error getPointInOutline(HB_Glyph glyph, int flags, hb_uint32 point, HB_Fixed *xpos, HB_Fixed *ypos, hb_uint32 *nPoints)
bool mkpath(const QString &dirPath) const
Creates the directory path dirPath.
void sendFontCommand(int type, const QByteArray &fontName)
static QFixed fromFixed(int fixed)
void setColor(int i, QRgb c)
Sets the color at the given index in the color table, to the given to colorValue. ...
virtual QImage alphaMapForGlyph(glyph_t)
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
void addOutlineToPath(qreal x, qreal y, const QGlyphLayout &glyphs, QPainterPath *path, QTextItem::RenderFlags flags)
void draw(QPaintEngine *p, qreal x, qreal y, const QTextItemInt &si)
#define QT_END_NAMESPACE
This macro expands to.
char * data()
Returns a pointer to the data stored in the byte array.
const QByteArray & data() const
Returns the data contained in the buffer.
glyph_metrics_t boundingBox(const QGlyphLayout &glyphs)
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Q_GUI_EXPORT QWSDisplay * qt_fbdpy
QPaintEngineState * state
virtual void doKerning(QGlyphLayout *, QTextEngine::ShaperFlags) const
T readValue(const uchar *&data)
bool open(OpenMode openMode)
Reimplemented Function
QString & replace(int i, int len, QChar after)
#define at(className, varName)
The QByteArray class provides an array of bytes.
QTransform transform() const
Returns the matrix in the current paint engine state.
virtual void addOutlineToPath(qreal, qreal, const QGlyphLayout &, QPainterPath *, QTextItem::RenderFlags flags)
void close()
Reimplemented Function
QString & prepend(QChar c)
bool canRender(const QChar *string, int len)
virtual int glyphCount() const
QString fileName() const
Returns the name of the file, excluding the path.
static const uchar * getCMap(const uchar *table, uint tableSize, bool *isSymbolFont, int *cmapSize)
int byteCount() const
Returns the number of bytes occupied by the image data.
static LibLoadStatus status
QString absoluteFilePath() const
Returns an absolute path including the file name.
#define QT_END_INCLUDE_NAMESPACE
This macro is equivalent to QT_BEGIN_NAMESPACE.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int bytesPerLine() const
Returns the number of bytes per image scanline.
#define READ_VERIFY(type, variable)
qreal minRightBearing() const
bool ref()
Atomically increments the value of this QAtomicInt.
quint32 qFromBigEndian< quint32 >(const uchar *src)
The QBuffer class provides a QIODevice interface for a QByteArray.
bool getSfntTable(uint tag, uchar *buffer, uint *length) const
The QString class provides a Unicode character string.
static QFixed fromReal(qreal r)
QImage alphaMapForGlyph(glyph_t t)
QFixed lineThickness() const
virtual bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const =0
virtual Type type() const =0
The QChar class provides a 16-bit Unicode character.
static const uchar * verifyTag(const uchar *tagPtr, const uchar *endPtr)
Format format() const
Returns the format of the image.
Q_CORE_EXPORT QTextStream & hex(QTextStream &s)
bool exists() const
Returns true if the directory exists; otherwise returns false.
Q_CORE_EXPORT QTextStream & dec(QTextStream &s)
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const
void writeTaggedUInt32(QFontEngineQPF::HeaderTag tag, quint32 value)
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 ...
static QString decodeName(const QByteArray &localFileName)
This does the reverse of QFile::encodeName() using localFileName.
#define MAKE_TAG(ch1, ch2, ch3, ch4)
QFontEngineQPF(const QFontDef &def, int fd, QFontEngine *renderingFontEngine=0)
Q_CORE_EXPORT void qDebug(const char *,...)
static QString toString(Register *reg, int type, bool *ok=0)
void writeTaggedString(QFontEngineQPF::HeaderTag tag, const QByteArray &string)
void append(const T &t)
Inserts value at the end of the list.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Q_GUI_EXPORT_INLINE QRgb qRgba(int r, int g, int b, int a)
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
struct FT_FaceRec_ * FT_Face
void writeTaggedQFixed(QFontEngineQPF::HeaderTag tag, QFixed value)
void recalcAdvances(QGlyphLayout *, QTextEngine::ShaperFlags) const
int access(const char *, int)
bool contains(const T &value) const
static const QCssKnownValue positions[NumKnownPositionModes - 1]
void doKerning(QGlyphLayout *g, QTextEngine::ShaperFlags flags) const
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.
bool kerning_pairs_loaded
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
void getGlyphPositions(const QGlyphLayout &glyphs, const QTransform &matrix, QTextItem::RenderFlags flags, QVarLengthArray< glyph_t > &glyphs_out, QVarLengthArray< QFixedPoint > &positions)
QByteArray encodedFileName
QFixed underlinePosition() const
Q_CORE_EXPORT void qWarning(const char *,...)
const_iterator insert(const T &value)
The QImage class provides a hardware-independent image representation that allows direct access to th...
static QList< QByteArray > cleanUpAfterClientCrash(const QList< int > &crashedClientIds)
static const char * data(const QByteArray &arr)
QFileInfoList entryInfoList(Filters filters=NoFilter, SortFlags sort=NoSort) const
Returns a list of QFileInfo objects for all the files and directories in the directory, ordered according to the name and attribute filters previously set with setNameFilters() and setFilter(), and sorted according to the flags set with setSorting().
int depth() const
Returns the depth of the image.
virtual glyph_metrics_t boundingBox(const QGlyphLayout &glyphs)=0
QFontEngine * renderingFontEngine
virtual void removeGlyphFromCache(glyph_t)
The QPaintEngine class provides an abstract definition of how QPainter draws to a given device on a g...
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)
static QString tempPath()
Returns the absolute path of the system's temporary directory.
QFontEngineMultiQWS(QFontEngine *fe, int script, const QStringList &fallbacks)
qreal maxCharWidth() const
const Glyph * findGlyph(glyph_t g) const
const char * constData() const
Returns a pointer to the data stored in the byte array.
virtual HB_Error getPointInOutline(HB_Glyph glyph, int flags, hb_uint32 point, HB_Fixed *xpos, HB_Fixed *ypos, hb_uint32 *nPoints)
uchar * bits()
Returns a pointer to the first pixel data.
Q_CORE_EXPORT void qFatal(const char *,...)
int width() const
Returns the width of the image.
void * qMemSet(void *dest, int c, size_t n)
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
void writeTaggedUInt8(QFontEngineQPF::HeaderTag tag, quint8 value)
virtual QFixed emSquareSize() const
QString & append(QChar c)
const uchar * externalCMap
void writeBlock(QFontEngineQPF::BlockTag tag, const QByteArray &data)
void release(const QFontEngine::FaceId &face_id)
void alphaPenBlt(const void *src, int bpl, int depth, int rx, int ry, int w, int h)
static QString location(LibraryLocation)
Returns the location specified by loc.
QString qws_fontCacheDir()
#define st(var, type, card)
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
void resize(int size)
Sets the size of the byte array to size bytes.
uint toUInt(bool *ok=0) const
Returns the variant as an unsigned int if the variant has type() UInt , Bool , ByteArray ...
QByteArray freetypeCMapTable
static bool verifyHeader(const uchar *data, int size)
static QReadWriteLock lock
virtual QFixed emSquareSize() const
int height() const
Returns the height of the image.
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...
qreal minLeftBearing() const
int size() const
Returns the number of bytes in this byte array.
static unsigned int getChar(const QChar *str, int &i, const int len)
bool remove()
Removes the file specified by fileName().
void draw(QPaintEngine *p, qreal x, qreal y, const QTextItemInt &si)
#define QT_BEGIN_INCLUDE_NAMESPACE
This macro is equivalent to QT_END_NAMESPACE.
QTextStream & hex(QTextStream &stream)
Calls QTextStream::setIntegerBase(16) on stream and returns stream.
The QPaintEngineState class provides information about the active paint engine's current state...
static QByteArray encodeName(const QString &fileName)
By default, this function converts fileName to the local 8-bit encoding determined by the user's loca...
void loadKerningPairs(QFixed scalingFactor)
The QRasterPaintEngine class enables hardware acceleration of painting operations in Qt for Embedded ...
#define VERIFY_TAG(condition)
T value() const
Returns the stored value converted to the template type T.
#define VERIFY(condition)
The QFileInfo class provides system-independent file information.
#define qPrintable(string)
#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.
bool getSfntTableData(uint tag, uchar *buffer, uint *length) const
QStringList fallbackFamilies
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
void addBitmapFontToPath(qreal x, qreal y, const QGlyphLayout &, QPainterPath *, QTextItem::RenderFlags)
Q_DECL_CONSTEXPR int qRound(qreal d)
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
static qreal toReal(Register *reg, int type, bool *ok=0)
void qErrnoWarning(const char *msg,...)
void loadGlyph(glyph_t glyph)
static QStringList fallbackFamilies(const QString &family, const QFont::Style &style, const QFont::StyleHint &styleHint, const QUnicodeTables::Script &script)
QByteArray getSfntTable(uint) const
static QVariant extractHeaderField(const uchar *data, HeaderTag tag)
static QFontEngine * findFont(int script, const QFontPrivate *fp, const QFontDef &request)