Windows QPA/font code: Fix warnings as shown by Qt Creator's Clang based code model.
Introduce C++ casts and add some conversions. Where possible, increase const-correctness. Task-number: QTBUG-50804 Change-Id: Idd73730ae83b837c065c8c80f500d5336570f228 Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>bb10
parent
bb8f01c601
commit
8917cdf13b
|
|
@ -269,10 +269,10 @@ namespace {
|
|||
quint16 nameIds[requiredRecordCount] = { 1, 2, 3, 4, 6 };
|
||||
|
||||
int sizeOfHeader = sizeof(NameTable) + sizeof(NameRecord) * requiredRecordCount;
|
||||
int newFamilyNameSize = newFamilyName.size() * sizeof(quint16);
|
||||
int newFamilyNameSize = newFamilyName.size() * int(sizeof(quint16));
|
||||
|
||||
const QString regularString = QString::fromLatin1("Regular");
|
||||
int regularStringSize = regularString.size() * sizeof(quint16);
|
||||
int regularStringSize = regularString.size() * int(sizeof(quint16));
|
||||
|
||||
// Align table size of table to 32 bits (pad with 0)
|
||||
int fullSize = ((sizeOfHeader + newFamilyNameSize + regularStringSize) & ~3) + 4;
|
||||
|
|
@ -792,7 +792,7 @@ static QString getEnglishName(const uchar *table, quint32 bytes)
|
|||
|
||||
length /= 2;
|
||||
i18n_name.resize(length);
|
||||
QChar *uc = (QChar *) i18n_name.unicode();
|
||||
QChar *uc = const_cast<QChar *>(i18n_name.unicode());
|
||||
const unsigned char *string = table + string_offset + offset;
|
||||
for (int i = 0; i < length; ++i)
|
||||
uc[i] = getUShort(string + 2*i);
|
||||
|
|
@ -800,10 +800,10 @@ static QString getEnglishName(const uchar *table, quint32 bytes)
|
|||
// Apple Roman
|
||||
|
||||
i18n_name.resize(length);
|
||||
QChar *uc = (QChar *) i18n_name.unicode();
|
||||
QChar *uc = const_cast<QChar *>(i18n_name.unicode());
|
||||
const unsigned char *string = table + string_offset + offset;
|
||||
for (int i = 0; i < length; ++i)
|
||||
uc[i] = QLatin1Char(string[i]);
|
||||
uc[i] = QLatin1Char(char(string[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1154,8 +1154,9 @@ QT_WARNING_POP
|
|||
|
||||
DWORD count = 0;
|
||||
QByteArray newFontData = font.data();
|
||||
HANDLE fontHandle = AddFontMemResourceEx((void *)newFontData.constData(), newFontData.size(), 0,
|
||||
&count);
|
||||
HANDLE fontHandle =
|
||||
AddFontMemResourceEx(const_cast<char *>(newFontData.constData()),
|
||||
DWORD(newFontData.size()), 0, &count);
|
||||
if (count == 0 && fontHandle != 0) {
|
||||
RemoveFontMemResourceEx(fontHandle);
|
||||
fontHandle = 0;
|
||||
|
|
@ -1373,8 +1374,9 @@ QStringList QWindowsFontDatabase::addApplicationFont(const QByteArray &fontData,
|
|||
return families;
|
||||
|
||||
DWORD dummy = 0;
|
||||
font.handle = AddFontMemResourceEx((void *)fontData.constData(), fontData.size(), 0,
|
||||
&dummy);
|
||||
font.handle =
|
||||
AddFontMemResourceEx(const_cast<char *>(fontData.constData()),
|
||||
DWORD(fontData.size()), 0, &dummy);
|
||||
if (font.handle == 0)
|
||||
return QStringList();
|
||||
|
||||
|
|
|
|||
|
|
@ -159,6 +159,12 @@ bool QWindowsFontEngine::hasEbdtTable() const
|
|||
return GetFontData(hdc, MAKE_TAG('E', 'B', 'D', 'T'), 0, 0, 0) != GDI_ERROR;
|
||||
}
|
||||
|
||||
static inline QString stringFromOutLineTextMetric(const OUTLINETEXTMETRIC *otm, PSTR offset)
|
||||
{
|
||||
const uchar *p = reinterpret_cast<const uchar *>(otm) + quintptr(offset);
|
||||
return QString::fromWCharArray(reinterpret_cast<const wchar_t *>(p));
|
||||
}
|
||||
|
||||
void QWindowsFontEngine::getCMap()
|
||||
{
|
||||
ttf = (bool)(tm.tmPitchAndFamily & TMPF_TRUETYPE) || hasCMapTable();
|
||||
|
|
@ -182,11 +188,12 @@ void QWindowsFontEngine::getCMap()
|
|||
_faceId.index = 0;
|
||||
if(cmap) {
|
||||
OUTLINETEXTMETRIC *otm = getOutlineTextMetric(hdc);
|
||||
designToDevice = QFixed((int)otm->otmEMSquare)/QFixed::fromReal(fontDef.pixelSize);
|
||||
unitsPerEm = otm->otmEMSquare;
|
||||
x_height = (int)otm->otmsXHeight;
|
||||
loadKerningPairs(QFixed((int)otm->otmEMSquare)/int(otm->otmTextMetrics.tmHeight));
|
||||
_faceId.filename = QFile::encodeName(QString::fromWCharArray((wchar_t *)((char *)otm + (quintptr)otm->otmpFullName)));
|
||||
unitsPerEm = int(otm->otmEMSquare);
|
||||
const QFixed unitsPerEmF(unitsPerEm);
|
||||
designToDevice = unitsPerEmF / QFixed::fromReal(fontDef.pixelSize);
|
||||
x_height = int(otm->otmsXHeight);
|
||||
loadKerningPairs(unitsPerEmF / int(otm->otmTextMetrics.tmHeight));
|
||||
_faceId.filename = QFile::encodeName(stringFromOutLineTextMetric(otm, otm->otmpFullName));
|
||||
lineWidth = otm->otmsUnderscoreSize;
|
||||
fsType = otm->otmfsType;
|
||||
free(otm);
|
||||
|
|
@ -387,9 +394,9 @@ void QWindowsFontEngine::recalcAdvances(QGlyphLayout *glyphs, QFontEngine::Shape
|
|||
for(int i = 0; i < glyphs->numGlyphs; i++) {
|
||||
unsigned int glyph = glyphs->glyphs[i];
|
||||
if(int(glyph) >= designAdvancesSize) {
|
||||
int newSize = (glyph + 256) >> 8 << 8;
|
||||
designAdvances = q_check_ptr((QFixed *)realloc(designAdvances,
|
||||
newSize*sizeof(QFixed)));
|
||||
const int newSize = int(glyph + 256) >> 8 << 8;
|
||||
designAdvances = reinterpret_cast<QFixed *>(realloc(designAdvances, size_t(newSize) * sizeof(QFixed)));
|
||||
Q_CHECK_PTR(designAdvances);
|
||||
for(int i = designAdvancesSize; i < newSize; ++i)
|
||||
designAdvances[i] = -1000000;
|
||||
designAdvancesSize = newSize;
|
||||
|
|
@ -411,9 +418,9 @@ void QWindowsFontEngine::recalcAdvances(QGlyphLayout *glyphs, QFontEngine::Shape
|
|||
unsigned int glyph = glyphs->glyphs[i];
|
||||
|
||||
if (glyph >= widthCacheSize) {
|
||||
int newSize = (glyph + 256) >> 8 << 8;
|
||||
widthCache = q_check_ptr((unsigned char *)realloc(widthCache,
|
||||
newSize*sizeof(QFixed)));
|
||||
const uint newSize = (glyph + 256) >> 8 << 8;
|
||||
widthCache = reinterpret_cast<unsigned char *>(realloc(widthCache, newSize * sizeof(QFixed)));
|
||||
Q_CHECK_PTR(widthCache);
|
||||
memset(widthCache + widthCacheSize, 0, newSize - widthCacheSize);
|
||||
widthCacheSize = newSize;
|
||||
}
|
||||
|
|
@ -433,7 +440,7 @@ void QWindowsFontEngine::recalcAdvances(QGlyphLayout *glyphs, QFontEngine::Shape
|
|||
++chrLen;
|
||||
}
|
||||
SIZE size = {0, 0};
|
||||
GetTextExtentPoint32(hdc, (wchar_t *)ch, chrLen, &size);
|
||||
GetTextExtentPoint32(hdc, reinterpret_cast<const wchar_t *>(ch), chrLen, &size);
|
||||
width = size.cx;
|
||||
} else {
|
||||
calculateTTFGlyphWidth(hdc, glyph, width);
|
||||
|
|
@ -441,7 +448,7 @@ void QWindowsFontEngine::recalcAdvances(QGlyphLayout *glyphs, QFontEngine::Shape
|
|||
glyphs->advances[i] = width;
|
||||
// if glyph's within cache range, store it for later
|
||||
if (width > 0 && width < 0x100)
|
||||
widthCache[glyph] = width;
|
||||
widthCache[glyph] = uchar(width);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -482,10 +489,10 @@ bool QWindowsFontEngine::getOutlineMetrics(glyph_t glyph, const QTransform &t, g
|
|||
// results provided when transforming via MAT2 does not
|
||||
// match the glyphs that are drawn using a WorldTransform
|
||||
XFORM xform;
|
||||
xform.eM11 = t.m11();
|
||||
xform.eM12 = t.m12();
|
||||
xform.eM21 = t.m21();
|
||||
xform.eM22 = t.m22();
|
||||
xform.eM11 = FLOAT(t.m11());
|
||||
xform.eM12 = FLOAT(t.m12());
|
||||
xform.eM21 = FLOAT(t.m21());
|
||||
xform.eM22 = FLOAT(t.m22());
|
||||
xform.eDx = 0;
|
||||
xform.eDy = 0;
|
||||
SetGraphicsMode(hdc, GM_ADVANCED);
|
||||
|
|
@ -507,7 +514,8 @@ bool QWindowsFontEngine::getOutlineMetrics(glyph_t glyph, const QTransform &t, g
|
|||
|
||||
if (res != GDI_ERROR) {
|
||||
*metrics = glyph_metrics_t(gm.gmptGlyphOrigin.x, -gm.gmptGlyphOrigin.y,
|
||||
(int)gm.gmBlackBoxX, (int)gm.gmBlackBoxY, gm.gmCellIncX, gm.gmCellIncY);
|
||||
int(gm.gmBlackBoxX), int(gm.gmBlackBoxY),
|
||||
gm.gmCellIncX, gm.gmCellIncY);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
|
@ -526,7 +534,7 @@ glyph_metrics_t QWindowsFontEngine::boundingBox(glyph_t glyph, const QTransform
|
|||
|
||||
if (!ttf && !success) {
|
||||
// Bitmap fonts
|
||||
wchar_t ch = glyph;
|
||||
wchar_t ch = wchar_t(glyph);
|
||||
ABCFLOAT abc;
|
||||
GetCharABCWidthsFloat(hdc, ch, ch, &abc);
|
||||
int width = qRound(abc.abcfB);
|
||||
|
|
@ -791,7 +799,7 @@ static bool addGlyphToPath(glyph_t glyph, const QFixedPoint &position, HDC hdc,
|
|||
return false;
|
||||
// #### obey scale
|
||||
*metric = glyph_metrics_t(gMetric.gmptGlyphOrigin.x, -gMetric.gmptGlyphOrigin.y,
|
||||
(int)gMetric.gmBlackBoxX, (int)gMetric.gmBlackBoxY,
|
||||
int(gMetric.gmBlackBoxX), int(gMetric.gmBlackBoxY),
|
||||
gMetric.gmCellIncX, gMetric.gmCellIncY);
|
||||
}
|
||||
#endif
|
||||
|
|
@ -801,17 +809,15 @@ static bool addGlyphToPath(glyph_t glyph, const QFixedPoint &position, HDC hdc,
|
|||
if (ttf)
|
||||
glyphFormat |= GGO_GLYPH_INDEX;
|
||||
|
||||
int bufferSize = GDI_ERROR;
|
||||
bufferSize = GetGlyphOutline(hdc, glyph, glyphFormat, &gMetric, 0, 0, &mat);
|
||||
if ((DWORD)bufferSize == GDI_ERROR) {
|
||||
const DWORD bufferSize = GetGlyphOutline(hdc, glyph, glyphFormat, &gMetric, 0, 0, &mat);
|
||||
if (bufferSize == GDI_ERROR)
|
||||
return false;
|
||||
}
|
||||
|
||||
void *dataBuffer = new char[bufferSize];
|
||||
char *dataBuffer = new char[bufferSize];
|
||||
DWORD ret = GDI_ERROR;
|
||||
ret = GetGlyphOutline(hdc, glyph, glyphFormat, &gMetric, bufferSize, dataBuffer, &mat);
|
||||
if (ret == GDI_ERROR) {
|
||||
delete [](char *)dataBuffer;
|
||||
delete [] dataBuffer;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -824,20 +830,18 @@ static bool addGlyphToPath(glyph_t glyph, const QFixedPoint &position, HDC hdc,
|
|||
}
|
||||
#endif
|
||||
|
||||
int offset = 0;
|
||||
int headerOffset = 0;
|
||||
TTPOLYGONHEADER *ttph = 0;
|
||||
DWORD offset = 0;
|
||||
DWORD headerOffset = 0;
|
||||
|
||||
QPointF oset = position.toPointF();
|
||||
while (headerOffset < bufferSize) {
|
||||
ttph = (TTPOLYGONHEADER*)((char *)dataBuffer + headerOffset);
|
||||
const TTPOLYGONHEADER *ttph = reinterpret_cast<const TTPOLYGONHEADER *>(dataBuffer + headerOffset);
|
||||
|
||||
QPointF lastPoint(qt_to_qpointf(ttph->pfxStart, scale));
|
||||
path->moveTo(lastPoint + oset);
|
||||
offset += sizeof(TTPOLYGONHEADER);
|
||||
TTPOLYCURVE *curve;
|
||||
while (offset<int(headerOffset + ttph->cb)) {
|
||||
curve = (TTPOLYCURVE*)((char*)(dataBuffer) + offset);
|
||||
while (offset < headerOffset + ttph->cb) {
|
||||
const TTPOLYCURVE *curve = reinterpret_cast<const TTPOLYCURVE *>(dataBuffer + offset);
|
||||
switch (curve->wType) {
|
||||
case TT_PRIM_LINE: {
|
||||
for (int i=0; i<curve->cpfx; ++i) {
|
||||
|
|
@ -882,7 +886,7 @@ static bool addGlyphToPath(glyph_t glyph, const QFixedPoint &position, HDC hdc,
|
|||
path->closeSubpath();
|
||||
headerOffset += ttph->cb;
|
||||
}
|
||||
delete [] (char*)dataBuffer;
|
||||
delete [] dataBuffer;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -980,15 +984,15 @@ QFontEngine::Properties QWindowsFontEngine::properties() const
|
|||
Properties p;
|
||||
p.emSquare = unitsPerEm;
|
||||
p.italicAngle = otm->otmItalicAngle;
|
||||
p.postscriptName = QString::fromWCharArray((wchar_t *)((char *)otm + (quintptr)otm->otmpFamilyName)).toLatin1();
|
||||
p.postscriptName += QString::fromWCharArray((wchar_t *)((char *)otm + (quintptr)otm->otmpStyleName)).toLatin1();
|
||||
p.postscriptName = QFontEngine::convertToPostscriptFontFamilyName(p.postscriptName);
|
||||
const QByteArray name = stringFromOutLineTextMetric(otm, otm->otmpFamilyName).toLatin1()
|
||||
+ stringFromOutLineTextMetric(otm, otm->otmpStyleName).toLatin1();
|
||||
p.postscriptName = QFontEngine::convertToPostscriptFontFamilyName(name);
|
||||
p.boundingBox = QRectF(otm->otmrcFontBox.left, -otm->otmrcFontBox.top,
|
||||
otm->otmrcFontBox.right - otm->otmrcFontBox.left,
|
||||
otm->otmrcFontBox.top - otm->otmrcFontBox.bottom);
|
||||
p.ascent = otm->otmAscent;
|
||||
p.descent = -otm->otmDescent;
|
||||
p.leading = (int)otm->otmLineGap;
|
||||
p.leading = int(otm->otmLineGap);
|
||||
p.capHeight = 0;
|
||||
p.lineWidth = otm->otmsUnderscoreSize;
|
||||
free(otm);
|
||||
|
|
@ -1054,10 +1058,10 @@ QWindowsNativeImage *QWindowsFontEngine::drawGDIGlyph(HFONT font, glyph_t glyph,
|
|||
XFORM xform;
|
||||
|
||||
if (has_transformation) {
|
||||
xform.eM11 = t.m11();
|
||||
xform.eM12 = t.m12();
|
||||
xform.eM21 = t.m21();
|
||||
xform.eM22 = t.m22();
|
||||
xform.eM11 = FLOAT(t.m11());
|
||||
xform.eM12 = FLOAT(t.m12());
|
||||
xform.eM21 = FLOAT(t.m21());
|
||||
xform.eM22 = FLOAT(t.m22());
|
||||
xform.eDx = margin;
|
||||
xform.eDy = margin;
|
||||
|
||||
|
|
@ -1067,7 +1071,7 @@ QWindowsNativeImage *QWindowsFontEngine::drawGDIGlyph(HFONT font, glyph_t glyph,
|
|||
SetWorldTransform(hdc, &xform);
|
||||
HGDIOBJ old_font = SelectObject(hdc, font);
|
||||
|
||||
int ggo_options = GGO_METRICS | (ttf ? GGO_GLYPH_INDEX : 0);
|
||||
const UINT ggo_options = GGO_METRICS | (ttf ? GGO_GLYPH_INDEX : 0);
|
||||
GLYPHMETRICS tgm;
|
||||
MAT2 mat;
|
||||
memset(&mat, 0, sizeof(mat));
|
||||
|
|
@ -1081,13 +1085,13 @@ QWindowsNativeImage *QWindowsFontEngine::drawGDIGlyph(HFONT font, glyph_t glyph,
|
|||
SelectObject(hdc, old_font);
|
||||
|
||||
if (result == GDI_ERROR) {
|
||||
const int errorCode = GetLastError();
|
||||
const int errorCode = int(GetLastError());
|
||||
qErrnoWarning(errorCode, "QWinFontEngine: unable to query transformed glyph metrics (GetGlyphOutline() failed, error %d)...", errorCode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
iw = tgm.gmBlackBoxX;
|
||||
ih = tgm.gmBlackBoxY;
|
||||
iw = int(tgm.gmBlackBoxX);
|
||||
ih = int(tgm.gmBlackBoxY);
|
||||
|
||||
xform.eDx -= tgm.gmptGlyphOrigin.x;
|
||||
xform.eDy += tgm.gmptGlyphOrigin.y;
|
||||
|
|
@ -1124,11 +1128,11 @@ QWindowsNativeImage *QWindowsFontEngine::drawGDIGlyph(HFONT font, glyph_t glyph,
|
|||
if (has_transformation) {
|
||||
SetGraphicsMode(hdc, GM_ADVANCED);
|
||||
SetWorldTransform(hdc, &xform);
|
||||
ExtTextOut(hdc, 0, 0, options, 0, (LPCWSTR) &glyph, 1, 0);
|
||||
ExtTextOut(hdc, 0, 0, options, 0, reinterpret_cast<LPCWSTR>(&glyph), 1, 0);
|
||||
} else
|
||||
#endif // !Q_OS_WINCE
|
||||
{
|
||||
ExtTextOut(hdc, -gx + margin, -gy + margin, options, 0, (LPCWSTR) &glyph, 1, 0);
|
||||
ExtTextOut(hdc, -gx + margin, -gy + margin, options, 0, reinterpret_cast<LPCWSTR>(&glyph), 1, 0);
|
||||
}
|
||||
|
||||
SelectObject(hdc, old_font);
|
||||
|
|
@ -1159,7 +1163,7 @@ QImage QWindowsFontEngine::alphaMapForGlyph(glyph_t glyph, const QTransform &xfo
|
|||
QImage::Format mask_format = QWindowsNativeImage::systemFormat();
|
||||
mask_format = QImage::Format_RGB32;
|
||||
|
||||
QWindowsNativeImage *mask = drawGDIGlyph(font, glyph, 0, xform, mask_format);
|
||||
const QWindowsNativeImage *mask = drawGDIGlyph(font, glyph, 0, xform, mask_format);
|
||||
if (mask == 0) {
|
||||
if (m_fontEngineData->clearTypeEnabled)
|
||||
DeleteObject(font);
|
||||
|
|
@ -1206,11 +1210,11 @@ QImage QWindowsFontEngine::alphaRGBMapForGlyph(glyph_t glyph, QFixed, const QTra
|
|||
|
||||
UINT contrast;
|
||||
SystemParametersInfo(SPI_GETFONTSMOOTHINGCONTRAST, 0, &contrast, 0);
|
||||
SystemParametersInfo(SPI_SETFONTSMOOTHINGCONTRAST, 0, (void *) 1000, 0);
|
||||
SystemParametersInfo(SPI_SETFONTSMOOTHINGCONTRAST, 0, reinterpret_cast<void *>(quintptr(1000)), 0);
|
||||
|
||||
int margin = glyphMargin(QFontEngine::Format_A32);
|
||||
QWindowsNativeImage *mask = drawGDIGlyph(font, glyph, margin, t, QImage::Format_RGB32);
|
||||
SystemParametersInfo(SPI_SETFONTSMOOTHINGCONTRAST, 0, (void *) quintptr(contrast), 0);
|
||||
SystemParametersInfo(SPI_SETFONTSMOOTHINGCONTRAST, 0, reinterpret_cast<void *>(quintptr(contrast)), 0);
|
||||
|
||||
if (mask == 0)
|
||||
return QImage();
|
||||
|
|
|
|||
Loading…
Reference in New Issue