summaryrefslogtreecommitdiffstats
path: root/src/gui/text
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/text')
-rw-r--r--src/gui/text/qabstracttextdocumentlayout.cpp1
-rw-r--r--src/gui/text/qcssparser.cpp10
-rw-r--r--src/gui/text/qcssparser_p.h2
-rw-r--r--src/gui/text/qfont_win.cpp8
-rw-r--r--src/gui/text/qfontdatabase_qws.cpp5
-rw-r--r--src/gui/text/qfontdatabase_win.cpp261
-rw-r--r--src/gui/text/qfontengine_qpf.cpp15
-rw-r--r--src/gui/text/qfontengine_qws.cpp5
-rw-r--r--src/gui/text/qfontengine_win.cpp450
-rw-r--r--src/gui/text/qfontengine_win_p.h18
-rw-r--r--src/gui/text/qsyntaxhighlighter.cpp42
-rw-r--r--src/gui/text/qsyntaxhighlighter.h1
-rw-r--r--src/gui/text/qtextcontrol.cpp3
-rw-r--r--src/gui/text/qtextcursor.cpp2
-rw-r--r--src/gui/text/qtextdocument.cpp7
-rw-r--r--src/gui/text/qtextdocumentlayout.cpp6
-rw-r--r--src/gui/text/qtextformat.cpp2
-rw-r--r--src/gui/text/qtextformat.h2
-rw-r--r--src/gui/text/qtexthtmlparser.cpp6
-rw-r--r--src/gui/text/qtextlist.cpp49
-rw-r--r--src/gui/text/qtextodfwriter.cpp8
-rw-r--r--src/gui/text/qzip.cpp20
22 files changed, 326 insertions, 597 deletions
diff --git a/src/gui/text/qabstracttextdocumentlayout.cpp b/src/gui/text/qabstracttextdocumentlayout.cpp
index 8d7540c..04df2aa 100644
--- a/src/gui/text/qabstracttextdocumentlayout.cpp
+++ b/src/gui/text/qabstracttextdocumentlayout.cpp
@@ -79,6 +79,7 @@ QT_BEGIN_NAMESPACE
\class QTextObjectInterface
\brief The QTextObjectInterface class allows drawing of
custom text objects in \l{QTextDocument}s.
+ \since 4.5
A text object describes the structure of one or more elements in a
text document; for instance, images imported from HTML are
diff --git a/src/gui/text/qcssparser.cpp b/src/gui/text/qcssparser.cpp
index e6bdcc6..99374b5 100644
--- a/src/gui/text/qcssparser.cpp
+++ b/src/gui/text/qcssparser.cpp
@@ -200,6 +200,7 @@ static const QCssKnownValue values[NumKnownValues - 1] = {
{ "link", Value_Link },
{ "link-visited", Value_LinkVisited },
{ "lower-alpha", Value_LowerAlpha },
+ { "lower-roman", Value_LowerRoman },
{ "lowercase", Value_Lowercase },
{ "medium", Value_Medium },
{ "mid", Value_Mid },
@@ -231,6 +232,7 @@ static const QCssKnownValue values[NumKnownValues - 1] = {
{ "transparent", Value_Transparent },
{ "underline", Value_Underline },
{ "upper-alpha", Value_UpperAlpha },
+ { "upper-roman", Value_UpperRoman },
{ "uppercase", Value_Uppercase },
{ "wave", Value_Wave },
{ "window", Value_Window },
@@ -240,10 +242,10 @@ static const QCssKnownValue values[NumKnownValues - 1] = {
};
//Map id to strings as they appears in the 'values' array above
-static const short indexOfId[NumKnownValues] = { 0, 40, 47, 41, 48, 53, 34, 26, 68, 69, 25, 42, 5, 62, 46,
- 29, 57, 58, 27, 50, 60, 6, 10, 38, 55, 19, 13, 17, 18, 20, 21, 49, 24, 45, 65, 36, 3, 2, 39, 61, 16,
- 11, 56, 14, 32, 63, 54, 64, 33, 67, 8, 28, 37, 12, 35, 59, 7, 9, 4, 66, 52, 22, 23, 30, 31, 1, 15, 0,
- 51, 44, 43 };
+static const short indexOfId[NumKnownValues] = { 0, 41, 48, 42, 49, 54, 35, 26, 70, 71, 25, 43, 5, 63, 47,
+ 29, 58, 59, 27, 51, 61, 6, 10, 39, 56, 19, 13, 17, 18, 20, 21, 50, 24, 46, 67, 37, 3, 2, 40, 62, 16,
+ 11, 57, 14, 32, 64, 33, 65, 55, 66, 34, 69, 8, 28, 38, 12, 36, 60, 7, 9, 4, 68, 53, 22, 23, 30, 31,
+ 1, 15, 0, 52, 45, 44 };
QString Value::toString() const
{
diff --git a/src/gui/text/qcssparser_p.h b/src/gui/text/qcssparser_p.h
index 8056f4d..b07acd5 100644
--- a/src/gui/text/qcssparser_p.h
+++ b/src/gui/text/qcssparser_p.h
@@ -223,6 +223,8 @@ enum KnownValue {
Value_Decimal,
Value_LowerAlpha,
Value_UpperAlpha,
+ Value_LowerRoman,
+ Value_UpperRoman,
Value_SmallCaps,
Value_Uppercase,
Value_Lowercase,
diff --git a/src/gui/text/qfont_win.cpp b/src/gui/text/qfont_win.cpp
index 2c27c9b..2293973 100644
--- a/src/gui/text/qfont_win.cpp
+++ b/src/gui/text/qfont_win.cpp
@@ -39,11 +39,6 @@
**
****************************************************************************/
-// the miscrosoft platform SDK says that the Unicode versions of
-// TextOut and GetTextExtentsPoint32 are supported on all platforms, so we use them
-// exclusively to simplify code, save a lot of conversions into the local encoding
-// and have generally better unicode support :)
-
#include "qfont.h"
#include "qfont_p.h"
#include "qfontengine_p.h"
@@ -67,8 +62,7 @@ extern HDC shared_dc(); // common dc for all fonts
// ### maybe move to qapplication_win
QFont qt_LOGFONTtoQFont(LOGFONT& lf, bool /*scale*/)
{
- QString family = QT_WA_INLINE(QString::fromUtf16((ushort*)lf.lfFaceName),
- QString::fromLocal8Bit((char*)lf.lfFaceName));
+ QString family = QString::fromWCharArray(lf.lfFaceName);
QFont qf(family);
qf.setItalic(lf.lfItalic);
if (lf.lfWeight != FW_DONTCARE) {
diff --git a/src/gui/text/qfontdatabase_qws.cpp b/src/gui/text/qfontdatabase_qws.cpp
index 1ac87ea..ff6af98 100644
--- a/src/gui/text/qfontdatabase_qws.cpp
+++ b/src/gui/text/qfontdatabase_qws.cpp
@@ -54,6 +54,7 @@
#endif
#include "qfontengine_qpf_p.h"
#include "private/qfactoryloader_p.h"
+#include "private/qcore_unix_p.h" // overrides QT_OPEN
#include "qabstractfontengine_qws.h"
#include "qabstractfontengine_p.h"
#include <qdatetime.h>
@@ -90,7 +91,7 @@ void QFontDatabasePrivate::addQPF2File(const QByteArray &file)
struct stat st;
if (stat(file.constData(), &st))
return;
- int f = ::open(file, O_RDONLY, 0);
+ int f = QT_OPEN(file, O_RDONLY, 0);
if (f < 0)
return;
const uchar *data = (const uchar *)mmap(0, st.st_size, PROT_READ, MAP_SHARED, f, 0);
@@ -138,7 +139,7 @@ void QFontDatabasePrivate::addQPF2File(const QByteArray &file)
#endif
}
#ifndef QT_FONTS_ARE_RESOURCES
- ::close(f);
+ QT_CLOSE(f);
#endif
}
#endif // QT_NO_QWS_QPF2
diff --git a/src/gui/text/qfontdatabase_win.cpp b/src/gui/text/qfontdatabase_win.cpp
index 2c0223b..974b955 100644
--- a/src/gui/text/qfontdatabase_win.cpp
+++ b/src/gui/text/qfontdatabase_win.cpp
@@ -195,21 +195,12 @@ static QString getEnglishName(const QString &familyName)
QString i18n_name;
HDC hdc = GetDC( 0 );
- HFONT hfont;
- QT_WA( {
- LOGFONTW lf;
- memset( &lf, 0, sizeof( LOGFONTW ) );
- memcpy( lf.lfFaceName, familyName.utf16(), qMin(LF_FACESIZE, familyName.length())*sizeof(QChar) );
- lf.lfCharSet = DEFAULT_CHARSET;
- hfont = CreateFontIndirectW( &lf );
- }, {
- LOGFONTA lf;
- memset( &lf, 0, sizeof( LOGFONTA ) );
- QByteArray lfam = familyName.toLocal8Bit();
- memcpy( lf.lfFaceName, lfam, qMin(LF_FACESIZE, lfam.size()) );
- lf.lfCharSet = DEFAULT_CHARSET;
- hfont = CreateFontIndirectA( &lf );
- } );
+ LOGFONT lf;
+ memset(&lf, 0, sizeof(LOGFONT));
+ memcpy(lf.lfFaceName, familyName.utf16(), qMin(LF_FACESIZE, familyName.length()) * sizeof(wchar_t));
+ lf.lfCharSet = DEFAULT_CHARSET;
+ HFONT hfont = CreateFontIndirect(&lf);
+
if(!hfont) {
ReleaseDC(0, hdc);
return QString();
@@ -245,32 +236,6 @@ error:
return i18n_name;
}
-static void getFontSignature(const QString &familyName,
- NEWTEXTMETRICEX *textmetric,
- FONTSIGNATURE *signature)
-{
- QT_WA({
- Q_UNUSED(familyName);
- *signature = textmetric->ntmFontSig;
- }, {
- // the textmetric structure we get from EnumFontFamiliesEx on Win9x has
- // a FONTSIGNATURE, but that one is uninitialized and doesn't work. Have to go
- // the hard way and load the font to find out.
- HDC hdc = GetDC(0);
- LOGFONTA lf;
- memset(&lf, 0, sizeof(LOGFONTA));
- QByteArray lfam = familyName.toLocal8Bit();
- memcpy(lf.lfFaceName, lfam.data(), qMin(LF_FACESIZE, lfam.length()));
- lf.lfCharSet = DEFAULT_CHARSET;
- HFONT hfont = CreateFontIndirectA(&lf);
- HGDIOBJ oldobj = SelectObject(hdc, hfont);
- GetTextCharsetInfo(hdc, signature, 0);
- SelectObject(hdc, oldobj);
- DeleteObject(hfont);
- ReleaseDC(0, hdc);
- });
-}
-
static
void addFontToDatabase(QString familyName, const QString &scriptName,
TEXTMETRIC *textmetric,
@@ -288,26 +253,17 @@ void addFontToDatabase(QString familyName, const QString &scriptName,
bool scalable;
int size;
-// QString escript = QString::fromUtf16((ushort *)f->elfScript);
+// QString escript = QString::fromWCharArray(f->elfScript);
// qDebug("script=%s", escript.latin1());
- QT_WA({
- NEWTEXTMETRIC *tm = (NEWTEXTMETRIC *)textmetric;
- fixed = !(tm->tmPitchAndFamily & TMPF_FIXED_PITCH);
- ttf = (tm->tmPitchAndFamily & TMPF_TRUETYPE);
- scalable = tm->tmPitchAndFamily & (TMPF_VECTOR|TMPF_TRUETYPE);
- size = scalable ? SMOOTH_SCALABLE : tm->tmHeight;
- italic = tm->tmItalic;
- weight = tm->tmWeight;
- } , {
- NEWTEXTMETRICA *tm = (NEWTEXTMETRICA *)textmetric;
- fixed = !(tm->tmPitchAndFamily & TMPF_FIXED_PITCH);
- ttf = (tm->tmPitchAndFamily & TMPF_TRUETYPE);
- scalable = tm->tmPitchAndFamily & (TMPF_VECTOR|TMPF_TRUETYPE);
- size = scalable ? SMOOTH_SCALABLE : tm->tmHeight;
- italic = tm->tmItalic;
- weight = tm->tmWeight;
- });
+ NEWTEXTMETRIC *tm = (NEWTEXTMETRIC *)textmetric;
+ fixed = !(tm->tmPitchAndFamily & TMPF_FIXED_PITCH);
+ ttf = (tm->tmPitchAndFamily & TMPF_TRUETYPE);
+ scalable = tm->tmPitchAndFamily & (TMPF_VECTOR|TMPF_TRUETYPE);
+ size = scalable ? SMOOTH_SCALABLE : tm->tmHeight;
+ italic = tm->tmItalic;
+ weight = tm->tmWeight;
+
// the "@family" fonts are just the same as "family". Ignore them.
if (familyName[0] != QLatin1Char('@') && !familyName.startsWith(QLatin1String("WST_"))) {
QtFontStyle::Key styleKey;
@@ -420,18 +376,10 @@ static
int CALLBACK
storeFont(ENUMLOGFONTEX* f, NEWTEXTMETRICEX *textmetric, int type, LPARAM /*p*/)
{
- QString familyName;
- QT_WA({
- familyName = QString::fromUtf16((ushort*)f->elfLogFont.lfFaceName);
- },{
- ENUMLOGFONTEXA *fa = (ENUMLOGFONTEXA *)f;
- familyName = QString::fromLocal8Bit(fa->elfLogFont.lfFaceName);
- });
- QString script = QT_WA_INLINE(QString::fromUtf16((const ushort *)f->elfScript),
- QString::fromLocal8Bit((const char *)((ENUMLOGFONTEXA *)f)->elfScript));
-
- FONTSIGNATURE signature;
- getFontSignature(familyName, textmetric, &signature);
+ QString familyName = QString::fromWCharArray(f->elfLogFont.lfFaceName);
+ QString script = QString::fromWCharArray(f->elfScript);
+
+ FONTSIGNATURE signature = textmetric->ntmFontSig;
// NEWTEXTMETRICEX is a NEWTEXTMETRIC, which according to the documentation is
// identical to a TEXTMETRIC except for the last four members, which we don't use
@@ -459,33 +407,17 @@ void populate_database(const QString& fam)
HDC dummy = GetDC(0);
- QT_WA({
- LOGFONT lf;
- lf.lfCharSet = DEFAULT_CHARSET;
- if (fam.isNull()) {
- lf.lfFaceName[0] = 0;
- } else {
- memcpy(lf.lfFaceName, fam.utf16(), sizeof(TCHAR)*qMin(fam.length()+1,32)); // 32 = Windows hard-coded
- }
- lf.lfPitchAndFamily = 0;
-
- EnumFontFamiliesEx(dummy, &lf,
- (FONTENUMPROC)storeFont, (LPARAM)privateDb(), 0);
- } , {
- LOGFONTA lf;
- lf.lfCharSet = DEFAULT_CHARSET;
- if (fam.isNull()) {
- lf.lfFaceName[0] = 0;
- } else {
- QByteArray lname = fam.toLocal8Bit();
- memcpy(lf.lfFaceName,lname.data(),
- qMin(lname.length()+1,32)); // 32 = Windows hard-coded
- }
- lf.lfPitchAndFamily = 0;
+ LOGFONT lf;
+ lf.lfCharSet = DEFAULT_CHARSET;
+ if (fam.isNull()) {
+ lf.lfFaceName[0] = 0;
+ } else {
+ memcpy(lf.lfFaceName, fam.utf16(), sizeof(wchar_t) * qMin(fam.length() + 1, 32)); // 32 = Windows hard-coded
+ }
+ lf.lfPitchAndFamily = 0;
- EnumFontFamiliesExA(dummy, &lf,
- (FONTENUMPROCA)storeFont, (LPARAM)privateDb(), 0);
- });
+ EnumFontFamiliesEx(dummy, &lf,
+ (FONTENUMPROC)storeFont, (LPARAM)privateDb(), 0);
ReleaseDC(0, dummy);
@@ -496,21 +428,11 @@ void populate_database(const QString& fam)
for (int j = 0; j < fnt.families.count(); ++j) {
const QString familyName = fnt.families.at(j);
HDC hdc = GetDC(0);
- HFONT hfont;
- QT_WA({
- LOGFONTW lf;
- memset(&lf, 0, sizeof(LOGFONTW));
- memcpy(lf.lfFaceName, familyName.utf16(), qMin(LF_FACESIZE, familyName.size()));
- lf.lfCharSet = DEFAULT_CHARSET;
- hfont = CreateFontIndirectW(&lf);
- } , {
- LOGFONTA lf;
- memset(&lf, 0, sizeof(LOGFONTA));
- QByteArray lfam = familyName.toLocal8Bit();
- memcpy(lf.lfFaceName, lfam.data(), qMin(LF_FACESIZE, lfam.length()));
- lf.lfCharSet = DEFAULT_CHARSET;
- hfont = CreateFontIndirectA(&lf);
- });
+ LOGFONT lf;
+ memset(&lf, 0, sizeof(LOGFONT));
+ memcpy(lf.lfFaceName, familyName.utf16(), sizeof(wchar_t) * qMin(LF_FACESIZE, familyName.size()));
+ lf.lfCharSet = DEFAULT_CHARSET;
+ HFONT hfont = CreateFontIndirect(&lf);
HGDIOBJ oldobj = SelectObject(hdc, hfont);
TEXTMETRIC textMetrics;
@@ -598,17 +520,10 @@ static void initFontInfo(QFontEngineWin *fe, const QFontDef &request, const QFon
HDC dc = ((request.styleStrategy & QFont::PreferDevice) && fp->hdc) ? fp->hdc : shared_dc();
SelectObject(dc, fe->hfont);
- QT_WA({
- TCHAR n[64];
- GetTextFaceW(dc, 64, n);
- fe->fontDef.family = QString::fromUtf16((ushort*)n);
- fe->fontDef.fixedPitch = !(fe->tm.w.tmPitchAndFamily & TMPF_FIXED_PITCH);
- } , {
- char an[64];
- GetTextFaceA(dc, 64, an);
- fe->fontDef.family = QString::fromLocal8Bit(an);
- fe->fontDef.fixedPitch = !(fe->tm.a.tmPitchAndFamily & TMPF_FIXED_PITCH);
- });
+ wchar_t n[64];
+ GetTextFace(dc, 64, n);
+ fe->fontDef.family = QString::fromWCharArray(n);
+ fe->fontDef.fixedPitch = !(fe->tm.tmPitchAndFamily & TMPF_FIXED_PITCH);
if (fe->fontDef.pointSize < 0) {
fe->fontDef.pointSize = fe->fontDef.pixelSize * 72. / fp->dpi;
} else if (fe->fontDef.pixelSize == -1) {
@@ -704,12 +619,7 @@ QFontEngine *loadEngine(int script, const QFontPrivate *fp, const QFontDef &requ
HFONT hfont = 0;
if (fp->rawMode) { // will choose a stock font
- int f, deffnt;
- // ### why different?
- if ((QSysInfo::WindowsVersion & QSysInfo::WV_NT_based) || QSysInfo::WindowsVersion == QSysInfo::WV_32s)
- deffnt = SYSTEM_FONT;
- else
- deffnt = DEFAULT_GUI_FONT;
+ int f, deffnt = SYSTEM_FONT;
QString fam = desc->family->name.toLower();
if (fam == QLatin1String("default"))
f = deffnt;
@@ -778,11 +688,7 @@ QFontEngine *loadEngine(int script, const QFontPrivate *fp, const QFontDef &requ
} else if (request.styleStrategy & QFont::PreferDevice) {
strat = OUT_DEVICE_PRECIS;
} else if (request.styleStrategy & QFont::PreferOutline) {
- QT_WA({
- strat = OUT_OUTLINE_PRECIS;
- } , {
- strat = OUT_TT_PRECIS;
- });
+ strat = OUT_OUTLINE_PRECIS;
} else if (request.styleStrategy & QFont::ForceOutline) {
strat = OUT_TT_ONLY_PRECIS;
#endif
@@ -801,7 +707,7 @@ QFontEngine *loadEngine(int script, const QFontPrivate *fp, const QFontDef &requ
if (request.styleStrategy & QFont::PreferAntialias) {
if (QSysInfo::WindowsVersion >= QSysInfo::WV_XP) {
- qual = 5; // == CLEARTYPE_QUALITY;
+ qual = CLEARTYPE_QUALITY;
preferClearTypeAA = true;
} else {
qual = ANTIALIASED_QUALITY;
@@ -827,16 +733,8 @@ QFontEngine *loadEngine(int script, const QFontPrivate *fp, const QFontDef &requ
if (fam == QLatin1String("Courier") && !(request.styleStrategy & QFont::PreferBitmap))
fam = QLatin1String("Courier New");
- QT_WA({
- memcpy(lf.lfFaceName, fam.utf16(), sizeof(TCHAR)*qMin(fam.length()+1,32)); // 32 = Windows hard-coded
- hfont = CreateFontIndirect(&lf);
- } , {
- // LOGFONTA and LOGFONTW are binary compatible
- QByteArray lname = fam.toLocal8Bit();
- memcpy(lf.lfFaceName,lname.data(),
- qMin(lname.length()+1,32)); // 32 = Windows hard-coded
- hfont = CreateFontIndirectA((LOGFONTA*)&lf);
- });
+ memcpy(lf.lfFaceName, fam.utf16(), sizeof(wchar_t) * qMin(fam.length() + 1, 32)); // 32 = Windows hard-coded
+ hfont = CreateFontIndirect(&lf);
if (!hfont)
qErrnoWarning("QFontEngine::loadEngine: CreateFontIndirect failed");
@@ -845,17 +743,12 @@ QFontEngine *loadEngine(int script, const QFontPrivate *fp, const QFontDef &requ
int avWidth = 0;
BOOL res;
HGDIOBJ oldObj = SelectObject(hdc, hfont);
- QT_WA({
- TEXTMETRICW tm;
- res = GetTextMetricsW(hdc, &tm);
- avWidth = tm.tmAveCharWidth;
- ttf = tm.tmPitchAndFamily & TMPF_TRUETYPE;
- } , {
- TEXTMETRICA tm;
- res = GetTextMetricsA(hdc, &tm);
- avWidth = tm.tmAveCharWidth;
- ttf = tm.tmPitchAndFamily & TMPF_TRUETYPE;
- });
+
+ TEXTMETRIC tm;
+ res = GetTextMetrics(hdc, &tm);
+ avWidth = tm.tmAveCharWidth;
+ ttf = tm.tmPitchAndFamily & TMPF_TRUETYPE;
+
SelectObject(hdc, oldObj);
if (hfont && (!ttf || request.stretch != 100)) {
@@ -863,11 +756,7 @@ QFontEngine *loadEngine(int script, const QFontPrivate *fp, const QFontDef &requ
if (!res)
qErrnoWarning("QFontEngine::loadEngine: GetTextMetrics failed");
lf.lfWidth = avWidth * request.stretch/100;
- QT_WA({
- hfont = CreateFontIndirect(&lf);
- } , {
- hfont = CreateFontIndirectA((LOGFONTA*)&lf);
- });
+ hfont = CreateFontIndirect(&lf);
if (!hfont)
qErrnoWarning("QFontEngine::loadEngine: CreateFontIndirect with stretch failed");
}
@@ -969,12 +858,6 @@ static QFontEngine *loadWin(const QFontPrivate *d, int script, const QFontDef &r
// list of families to try
QStringList family_list = familyList(req);
- if(QSysInfo::WindowsVersion & QSysInfo::WV_DOS_based && req.family.toLower() == QLatin1String("ms sans serif")) {
- // small hack for Dos based machines to get the right font for non
- // latin text when using the default font.
- family_list << QLatin1String("Arial");
- }
-
const char *stylehint = styleHint(d->request);
if (stylehint)
family_list << QLatin1String(stylehint);
@@ -1143,6 +1026,8 @@ static void getFamiliesAndSignatures(const QByteArray &fontData, QFontDatabasePr
signature.fsCsb[0] = qFromBigEndian<quint32>(table + 78);
signature.fsCsb[1] = qFromBigEndian<quint32>(table + 82);
+ } else {
+ memset(&signature, 0, sizeof(signature));
}
appFont->signatures << signature;
}
@@ -1165,21 +1050,21 @@ static void registerFont(QFontDatabasePrivate::ApplicationFont *fnt)
HANDLE handle = 0;
{
-#ifdef QT_NO_TEMPORARYFILE
- TCHAR lpBuffer[MAX_PATH];
+#ifdef QT_NO_TEMPORARYFILE
+ wchar_t lpBuffer[MAX_PATH];
GetTempPath(MAX_PATH, lpBuffer);
- QString s = QString::fromUtf16((const ushort *) lpBuffer);
+ QString s = QString::fromWCharArray(lpBuffer);
QFile tempfile(s + QLatin1String("/font") + QString::number(GetTickCount()) + QLatin1String(".ttf"));
if (!tempfile.open(QIODevice::ReadWrite))
#else
QTemporaryFile tempfile(QLatin1String("XXXXXXXX.ttf"));
if (!tempfile.open())
-#endif
+#endif // QT_NO_TEMPORARYFILE
return;
if (tempfile.write(fnt->data) == -1)
return;
-#ifndef QT_NO_TEMPORARYFILE
+#ifndef QT_NO_TEMPORARYFILE
tempfile.setAutoRemove(false);
#endif
fnt->fileName = QFileInfo(tempfile.fileName()).absoluteFilePath();
@@ -1191,13 +1076,11 @@ static void registerFont(QFontDatabasePrivate::ApplicationFont *fnt)
}
#else
DWORD dummy = 0;
- HANDLE handle = ptrAddFontMemResourceEx((void *)fnt->data.constData(),
- fnt->data.size(),
- 0,
- &dummy);
+ HANDLE handle = ptrAddFontMemResourceEx((void *)fnt->data.constData(), fnt->data.size(), 0,
+ &dummy);
if (handle == 0)
return;
-#endif
+#endif // Q_OS_WINCE
fnt->handle = handle;
fnt->data = QByteArray();
@@ -1219,12 +1102,10 @@ static void registerFont(QFontDatabasePrivate::ApplicationFont *fnt)
// supported from 2000 on, so no need to deal with the *A variant
PtrAddFontResourceExW ptrAddFontResourceExW = (PtrAddFontResourceExW)QLibrary::resolve(QLatin1String("gdi32"),
"AddFontResourceExW");
- if (!ptrAddFontResourceExW)
+ if (!ptrAddFontResourceExW
+ || ptrAddFontResourceExW((wchar_t*)fnt->fileName.utf16(), FR_PRIVATE, 0) == 0)
return;
-
- if (ptrAddFontResourceExW((LPCWSTR)fnt->fileName.utf16(), FR_PRIVATE, 0) == 0)
- return;
-#endif
+#endif // Q_OS_WINCE
fnt->memoryFont = false;
}
@@ -1250,12 +1131,10 @@ bool QFontDatabase::removeApplicationFont(int handle)
#else
PtrRemoveFontMemResourceEx ptrRemoveFontMemResourceEx = (PtrRemoveFontMemResourceEx)QLibrary::resolve(QLatin1String("gdi32"),
"RemoveFontMemResourceEx");
- if (!ptrRemoveFontMemResourceEx)
- return false;
-
- if (!ptrRemoveFontMemResourceEx(font.handle))
+ if (!ptrRemoveFontMemResourceEx
+ || !ptrRemoveFontMemResourceEx(font.handle))
return false;
-#endif
+#endif // Q_OS_WINCE
} else {
#ifdef Q_OS_WINCE
if (!RemoveFontResource((LPCWSTR)font.fileName.utf16()))
@@ -1263,12 +1142,10 @@ bool QFontDatabase::removeApplicationFont(int handle)
#else
PtrRemoveFontResourceExW ptrRemoveFontResourceExW = (PtrRemoveFontResourceExW)QLibrary::resolve(QLatin1String("gdi32"),
"RemoveFontResourceExW");
- if (!ptrRemoveFontResourceExW)
- return false;
-
- if (!ptrRemoveFontResourceExW((LPCWSTR)font.fileName.utf16(), FR_PRIVATE, 0))
+ if (!ptrRemoveFontResourceExW
+ || !ptrRemoveFontResourceExW((LPCWSTR)font.fileName.utf16(), FR_PRIVATE, 0))
return false;
-#endif
+#endif // Q_OS_WINCE
}
db->invalidate();
diff --git a/src/gui/text/qfontengine_qpf.cpp b/src/gui/text/qfontengine_qpf.cpp
index 9aaa1ac..232f839 100644
--- a/src/gui/text/qfontengine_qpf.cpp
+++ b/src/gui/text/qfontengine_qpf.cpp
@@ -51,6 +51,7 @@
#if !defined(QT_NO_FREETYPE)
#include "private/qfontengine_ft_p.h"
#endif
+#include "private/qcore_unix_p.h" // overrides QT_OPEN
// for mmap
#include <stdlib.h>
@@ -252,7 +253,7 @@ QList<QByteArray> QFontEngineQPF::cleanUpAfterClientCrash(const QList<int> &cras
for (int i = 0; i < int(dir.count()); ++i) {
const QByteArray fileName = QFile::encodeName(dir.absoluteFilePath(dir[i]));
- int fd = ::open(fileName.constData(), O_RDONLY, 0);
+ int fd = QT_OPEN(fileName.constData(), O_RDONLY, 0);
if (fd >= 0) {
void *header = ::mmap(0, sizeof(QFontEngineQPF::Header), PROT_READ, MAP_SHARED, fd, 0);
if (header && header != MAP_FAILED) {
@@ -265,7 +266,7 @@ QList<QByteArray> QFontEngineQPF::cleanUpAfterClientCrash(const QList<int> &cras
::munmap(header, sizeof(QFontEngineQPF::Header));
}
- ::close(fd);
+ QT_CLOSE(fd);
}
}
if (!removedFonts.isEmpty())
@@ -330,16 +331,16 @@ QFontEngineQPF::QFontEngineQPF(const QFontDef &def, int fileDescriptor, QFontEng
#if defined(DEBUG_FONTENGINE)
qDebug() << "found existing qpf:" << fileName;
#endif
- if (::access(encodedFileName, W_OK | R_OK) == 0)
- fd = ::open(encodedFileName, O_RDWR, 0);
- else if (::access(encodedFileName, R_OK) == 0)
- fd = ::open(encodedFileName, O_RDONLY, 0);
+ if (::access(encodedName, W_OK | R_OK) == 0)
+ fd = QT_OPEN(encodedName, O_RDWR, 0);
+ else if (::access(encodedName, R_OK) == 0)
+ fd = QT_OPEN(encodedName, O_RDONLY, 0);
} else {
#if defined(DEBUG_FONTENGINE)
qDebug() << "creating qpf on the fly:" << fileName;
#endif
if (::access(QFile::encodeName(qws_fontCacheDir()), W_OK) == 0) {
- fd = ::open(encodedFileName, O_RDWR | O_EXCL | O_CREAT, 0644);
+ fd = QT_OPEN(encodedName, O_RDWR | O_EXCL | O_CREAT, 0644);
QBuffer buffer;
buffer.open(QIODevice::ReadWrite);
diff --git a/src/gui/text/qfontengine_qws.cpp b/src/gui/text/qfontengine_qws.cpp
index 6fb4f15..70ce8f9 100644
--- a/src/gui/text/qfontengine_qws.cpp
+++ b/src/gui/text/qfontengine_qws.cpp
@@ -47,6 +47,7 @@
#include <private/qpaintengine_raster_p.h>
#include <private/qpdf_p.h>
#include "qtextengine_p.h"
+#include "private/qcore_unix_p.h" // overrides QT_OPEN
#include <qdebug.h>
@@ -387,7 +388,7 @@ QFontEngineQPF1::QFontEngineQPF1(const QFontDef&, const QString &fn)
{
cache_cost = 1;
- int f = ::open( QFile::encodeName(fn), O_RDONLY, 0);
+ int f = QT_OPEN( QFile::encodeName(fn), O_RDONLY, 0);
Q_ASSERT(f>=0);
QT_STATBUF st;
if ( QT_FSTAT( f, &st ) )
@@ -406,7 +407,7 @@ QFontEngineQPF1::QFontEngineQPF1(const QFontDef&, const QString &fn)
#endif
if ( !data || data == (uchar*)MAP_FAILED )
qFatal("Failed to mmap %s",QFile::encodeName(fn).data());
- ::close(f);
+ QT_CLOSE(f);
d = new QFontEngineQPF1Data;
memcpy(reinterpret_cast<char*>(&d->fm),data,sizeof(d->fm));
diff --git a/src/gui/text/qfontengine_win.cpp b/src/gui/text/qfontengine_win.cpp
index 9715aef..c6717e3 100644
--- a/src/gui/text/qfontengine_win.cpp
+++ b/src/gui/text/qfontengine_win.cpp
@@ -48,7 +48,6 @@
#include <qlibrary.h>
#include <qpaintdevice.h>
#include <qpainter.h>
-#include <qlibrary.h>
#include <limits.h>
#include <qendian.h>
@@ -85,8 +84,6 @@
((quint32)(ch1)) \
)
-typedef BOOL (WINAPI *PtrGetCharWidthI)(HDC, UINT, UINT, LPWORD, LPINT);
-
// common DC for all fonts
QT_BEGIN_NAMESPACE
@@ -128,8 +125,7 @@ HDC shared_dc()
}
#endif
-static HFONT stock_sysfont = 0;
-
+typedef BOOL (WINAPI *PtrGetCharWidthI)(HDC, UINT, UINT, LPWORD, LPINT);
static PtrGetCharWidthI ptrGetCharWidthI = 0;
static bool resolvedGetCharWidthI = false;
@@ -141,27 +137,6 @@ static void resolveGetCharWidthI()
ptrGetCharWidthI = (PtrGetCharWidthI)QLibrary::resolve(QLatin1String("gdi32"), "GetCharWidthI");
}
-// Copy a LOGFONTW struct into a LOGFONTA by converting the face name to an 8 bit value.
-// This is needed when calling CreateFontIndirect on non-unicode windowses.
-inline static void wa_copy_logfont(LOGFONTW *lfw, LOGFONTA *lfa)
-{
- lfa->lfHeight = lfw->lfHeight;
- lfa->lfWidth = lfw->lfWidth;
- lfa->lfEscapement = lfw->lfEscapement;
- lfa->lfOrientation = lfw->lfOrientation;
- lfa->lfWeight = lfw->lfWeight;
- lfa->lfItalic = lfw->lfItalic;
- lfa->lfUnderline = lfw->lfUnderline;
- lfa->lfCharSet = lfw->lfCharSet;
- lfa->lfOutPrecision = lfw->lfOutPrecision;
- lfa->lfClipPrecision = lfw->lfClipPrecision;
- lfa->lfQuality = lfw->lfQuality;
- lfa->lfPitchAndFamily = lfw->lfPitchAndFamily;
-
- QString fam = QString::fromUtf16((const ushort*)lfw->lfFaceName);
- memcpy(lfa->lfFaceName, fam.toLocal8Bit().constData(), fam.length() + 1);
-}
-
// defined in qtextengine_win.cpp
typedef void *SCRIPT_CACHE;
typedef HRESULT (WINAPI *fScriptFreeCache)(SCRIPT_CACHE *);
@@ -187,14 +162,6 @@ static inline quint16 getUShort(unsigned char *p)
return val;
}
-static inline HFONT systemFont()
-{
- if (stock_sysfont == 0)
- stock_sysfont = (HFONT)GetStockObject(SYSTEM_FONT);
- return stock_sysfont;
-}
-
-
// general font engine
QFixed QFontEngineWin::lineThickness() const
@@ -205,33 +172,18 @@ QFixed QFontEngineWin::lineThickness() const
return QFontEngine::lineThickness();
}
-#if defined(Q_WS_WINCE)
-static OUTLINETEXTMETRICW *getOutlineTextMetric(HDC hdc)
-{
- int size;
- size = GetOutlineTextMetricsW(hdc, 0, 0);
- OUTLINETEXTMETRICW *otm = (OUTLINETEXTMETRICW *)malloc(size);
- GetOutlineTextMetricsW(hdc, size, otm);
- return otm;
-}
-#else
-static OUTLINETEXTMETRICA *getOutlineTextMetric(HDC hdc)
+static OUTLINETEXTMETRIC *getOutlineTextMetric(HDC hdc)
{
int size;
- size = GetOutlineTextMetricsA(hdc, 0, 0);
- OUTLINETEXTMETRICA *otm = (OUTLINETEXTMETRICA *)malloc(size);
- GetOutlineTextMetricsA(hdc, size, otm);
+ size = GetOutlineTextMetrics(hdc, 0, 0);
+ OUTLINETEXTMETRIC *otm = (OUTLINETEXTMETRIC *)malloc(size);
+ GetOutlineTextMetrics(hdc, size, otm);
return otm;
}
-#endif
void QFontEngineWin::getCMap()
{
- QT_WA({
- ttf = (bool)(tm.w.tmPitchAndFamily & TMPF_TRUETYPE);
- } , {
- ttf = (bool)(tm.a.tmPitchAndFamily & TMPF_TRUETYPE);
- });
+ ttf = (bool)(tm.tmPitchAndFamily & TMPF_TRUETYPE);
HDC hdc = shared_dc();
SelectObject(hdc, hfont);
bool symb = false;
@@ -249,11 +201,7 @@ void QFontEngineWin::getCMap()
designToDevice = 1;
_faceId.index = 0;
if(cmap) {
-#if defined(Q_WS_WINCE)
- OUTLINETEXTMETRICW *otm = getOutlineTextMetric(hdc);
-#else
- OUTLINETEXTMETRICA *otm = getOutlineTextMetric(hdc);
-#endif
+ OUTLINETEXTMETRIC *otm = getOutlineTextMetric(hdc);
designToDevice = QFixed((int)otm->otmEMSquare)/int(otm->otmTextMetrics.tmHeight);
unitsPerEm = otm->otmEMSquare;
x_height = (int)otm->otmsXHeight;
@@ -263,7 +211,7 @@ void QFontEngineWin::getCMap()
fsType = otm->otmfsType;
free(otm);
} else {
- unitsPerEm = tm.w.tmHeight;
+ unitsPerEm = tm.tmHeight;
}
}
@@ -303,19 +251,14 @@ int QFontEngineWin::getGlyphIndexes(const QChar *str, int numChars, QGlyphLayout
}
} else {
#endif
- ushort first, last;
- QT_WA({
- first = tm.w.tmFirstChar;
- last = tm.w.tmLastChar;
- }, {
- first = tm.a.tmFirstChar;
- last = tm.a.tmLastChar;
- });
+ wchar_t first = tm.tmFirstChar;
+ wchar_t last = tm.tmLastChar;
+
for (; i < numChars; ++i, ++glyph_pos) {
uint ucs = QChar::mirroredChar(getChar(str, i, numChars));
if (
#ifdef Q_WS_WINCE
- tm.w.tmFirstChar > 60000 || // see line 375
+ tm.tmFirstChar > 60000 || // see line 375
#endif
ucs >= first && ucs <= last)
glyphs->glyphs[glyph_pos] = ucs;
@@ -341,19 +284,14 @@ int QFontEngineWin::getGlyphIndexes(const QChar *str, int numChars, QGlyphLayout
}
} else {
#endif
- ushort first, last;
- QT_WA({
- first = tm.w.tmFirstChar;
- last = tm.w.tmLastChar;
- }, {
- first = tm.a.tmFirstChar;
- last = tm.a.tmLastChar;
- });
+ wchar_t first = tm.tmFirstChar;
+ wchar_t last = tm.tmLastChar;
+
for (; i < numChars; ++i, ++glyph_pos) {
uint uc = getChar(str, i, numChars);
if (
#ifdef Q_WS_WINCE
- tm.w.tmFirstChar > 60000 || // see comment in QFontEngineWin
+ tm.tmFirstChar > 60000 || // see comment in QFontEngineWin
#endif
uc >= first && uc <= last)
glyphs->glyphs[glyph_pos] = uc;
@@ -387,28 +325,14 @@ QFontEngineWin::QFontEngineWin(const QString &name, HFONT _hfont, bool stockFont
lineWidth = -1;
x_height = -1;
- BOOL res;
- QT_WA({
- res = GetTextMetricsW(hdc, &tm.w);
- } , {
- res = GetTextMetricsA(hdc, &tm.a);
- });
- fontDef.fixedPitch = !(tm.w.tmPitchAndFamily & TMPF_FIXED_PITCH);
+ BOOL res = GetTextMetrics(hdc, &tm);
+ fontDef.fixedPitch = !(tm.tmPitchAndFamily & TMPF_FIXED_PITCH);
if (!res)
qErrnoWarning("QFontEngineWin: GetTextMetrics failed");
- cache_cost = tm.w.tmHeight * tm.w.tmAveCharWidth * 2000;
+ cache_cost = tm.tmHeight * tm.tmAveCharWidth * 2000;
getCMap();
- useTextOutA = false;
-#ifndef Q_OS_WINCE
- // TextOutW doesn't work for symbol fonts on Windows 95!
- // since we're using glyph indices we don't care for ttfs about this!
- if (QSysInfo::WindowsVersion == QSysInfo::WV_95 && !ttf &&
- (_name == QLatin1String("Marlett") || _name == QLatin1String("Symbol") ||
- _name == QLatin1String("Webdings") || _name == QLatin1String("Wingdings")))
- useTextOutA = true;
-#endif
widthCache = 0;
widthCacheSize = 0;
designAdvances = 0;
@@ -427,7 +351,7 @@ QFontEngineWin::~QFontEngineWin()
free(widthCache);
// make sure we aren't by accident still selected
- SelectObject(shared_dc(), systemFont());
+ SelectObject(shared_dc(), (HFONT)GetStockObject(SYSTEM_FONT));
if (!stockFont) {
if (!DeleteObject(hfont))
@@ -435,39 +359,12 @@ QFontEngineWin::~QFontEngineWin()
}
}
-HGDIOBJ QFontEngineWin::selectDesignFont(QFixed *overhang) const
+HGDIOBJ QFontEngineWin::selectDesignFont() const
{
LOGFONT f = logfont;
f.lfHeight = unitsPerEm;
- HFONT designFont;
- QT_WA({
- designFont = CreateFontIndirectW(&f);
- }, {
- LOGFONTA fa;
- wa_copy_logfont(&f, &fa);
- designFont = CreateFontIndirectA(&fa);
- });
- HGDIOBJ oldFont = SelectObject(shared_dc(), designFont);
-
- if (QSysInfo::WindowsVersion & QSysInfo::WV_DOS_based) {
- BOOL res;
- QT_WA({
- TEXTMETRICW tm;
- res = GetTextMetricsW(shared_dc(), &tm);
- if (!res)
- qErrnoWarning("QFontEngineWin: GetTextMetrics failed");
- *overhang = QFixed((int)tm.tmOverhang) / designToDevice;
- } , {
- TEXTMETRICA tm;
- res = GetTextMetricsA(shared_dc(), &tm);
- if (!res)
- qErrnoWarning("QFontEngineWin: GetTextMetrics failed");
- *overhang = QFixed((int)tm.tmOverhang) / designToDevice;
- });
- } else {
- *overhang = 0;
- }
- return oldFont;
+ HFONT designFont = CreateFontIndirect(&f);
+ return SelectObject(shared_dc(), designFont);
}
bool QFontEngineWin::stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const
@@ -486,8 +383,6 @@ bool QFontEngineWin::stringToCMap(const QChar *str, int len, QGlyphLayout *glyph
HDC hdc = shared_dc();
if (flags & QTextEngine::DesignMetrics) {
HGDIOBJ oldFont = 0;
- QFixed overhang = 0;
-
int glyph_pos = 0;
for(register int i = 0; i < len; i++) {
bool surrogate = (str[i].unicode() >= 0xd800 && str[i].unicode() < 0xdc00 && i < len-1
@@ -502,9 +397,9 @@ bool QFontEngineWin::stringToCMap(const QChar *str, int len, QGlyphLayout *glyph
}
if(designAdvances[glyph] < -999999) {
if(!oldFont)
- oldFont = selectDesignFont(&overhang);
+ oldFont = selectDesignFont();
SIZE size = {0, 0};
- GetTextExtentPoint32W(hdc, (wchar_t *)(str+i), surrogate ? 2 : 1, &size);
+ GetTextExtentPoint32(hdc, (wchar_t *)(str+i), surrogate ? 2 : 1, &size);
designAdvances[glyph] = QFixed((int)size.cx)/designToDevice;
}
glyphs->advances_x[glyph_pos] = designAdvances[glyph];
@@ -538,7 +433,7 @@ bool QFontEngineWin::stringToCMap(const QChar *str, int len, QGlyphLayout *glyph
SIZE size = {0, 0};
if (!oldFont)
oldFont = SelectObject(hdc, hfont);
- GetTextExtentPoint32W(hdc, (wchar_t *)str + i, surrogate ? 2 : 1, &size);
+ GetTextExtentPoint32(hdc, (wchar_t *)str + i, surrogate ? 2 : 1, &size);
glyphs->advances_x[glyph_pos] = size.cx;
// if glyph's within cache range, store it for later
if (size.cx > 0 && size.cx < 0x100)
@@ -564,8 +459,6 @@ void QFontEngineWin::recalcAdvances(QGlyphLayout *glyphs, QTextEngine::ShaperFla
HGDIOBJ oldFont = 0;
HDC hdc = shared_dc();
if (ttf && (flags & QTextEngine::DesignMetrics)) {
- QFixed overhang = 0;
-
for(int i = 0; i < glyphs->numGlyphs; i++) {
unsigned int glyph = glyphs->glyphs[i];
if(int(glyph) >= designAdvancesSize) {
@@ -575,35 +468,14 @@ void QFontEngineWin::recalcAdvances(QGlyphLayout *glyphs, QTextEngine::ShaperFla
designAdvances[i] = -1000000;
designAdvancesSize = newSize;
}
- if(designAdvances[glyph] < -999999) {
- if(!oldFont)
- oldFont = selectDesignFont(&overhang);
+ if (designAdvances[glyph] < -999999) {
+ if (!oldFont)
+ oldFont = selectDesignFont();
- if (ptrGetCharWidthI) {
- int width = 0;
+ int width = 0;
+ if (ptrGetCharWidthI)
ptrGetCharWidthI(hdc, glyph, 1, 0, &width);
-
- designAdvances[glyph] = QFixed(width) / designToDevice;
- } else {
-#ifndef Q_WS_WINCE
- GLYPHMETRICS gm;
- DWORD res = GDI_ERROR;
- MAT2 mat;
- mat.eM11.value = mat.eM22.value = 1;
- mat.eM11.fract = mat.eM22.fract = 0;
- mat.eM21.value = mat.eM12.value = 0;
- mat.eM21.fract = mat.eM12.fract = 0;
- QT_WA({
- res = GetGlyphOutlineW(hdc, glyph, GGO_METRICS|GGO_GLYPH_INDEX|GGO_NATIVE, &gm, 0, 0, &mat);
- } , {
- res = GetGlyphOutlineA(hdc, glyph, GGO_METRICS|GGO_GLYPH_INDEX|GGO_NATIVE, &gm, 0, 0, &mat);
- });
-
- if (res != GDI_ERROR) {
- designAdvances[glyph] = QFixed(gm.gmCellIncX) / designToDevice;
- }
-#endif
- }
+ designAdvances[glyph] = QFixed(width) / designToDevice;
}
glyphs->advances_x[i] = designAdvances[glyph];
glyphs->advances_y[i] = 0;
@@ -611,8 +483,6 @@ void QFontEngineWin::recalcAdvances(QGlyphLayout *glyphs, QTextEngine::ShaperFla
if(oldFont)
DeleteObject(SelectObject(hdc, oldFont));
} else {
- int overhang = (QSysInfo::WindowsVersion & QSysInfo::WV_DOS_based) ? tm.a.tmOverhang : 0;
-
for(int i = 0; i < glyphs->numGlyphs; i++) {
unsigned int glyph = glyphs->glyphs[i];
@@ -640,31 +510,10 @@ void QFontEngineWin::recalcAdvances(QGlyphLayout *glyphs, QTextEngine::ShaperFla
++chrLen;
}
SIZE size = {0, 0};
- GetTextExtentPoint32W(hdc, (wchar_t *)ch, chrLen, &size);
+ GetTextExtentPoint32(hdc, (wchar_t *)ch, chrLen, &size);
width = size.cx;
} else if (ptrGetCharWidthI) {
ptrGetCharWidthI(hdc, glyph, 1, 0, &width);
-
- width -= overhang;
- } else {
-#ifndef Q_WS_WINCE
- GLYPHMETRICS gm;
- DWORD res = GDI_ERROR;
- MAT2 mat;
- mat.eM11.value = mat.eM22.value = 1;
- mat.eM11.fract = mat.eM22.fract = 0;
- mat.eM21.value = mat.eM12.value = 0;
- mat.eM21.fract = mat.eM12.fract = 0;
- QT_WA({
- res = GetGlyphOutlineW(hdc, glyph, GGO_METRICS|GGO_GLYPH_INDEX, &gm, 0, 0, &mat);
- } , {
- res = GetGlyphOutlineA(hdc, glyph, GGO_METRICS|GGO_GLYPH_INDEX, &gm, 0, 0, &mat);
- });
-
- if (res != GDI_ERROR) {
- width = gm.gmCellIncX;
- }
-#endif
}
glyphs->advances_x[i] = width;
// if glyph's within cache range, store it for later
@@ -687,17 +536,10 @@ glyph_metrics_t QFontEngineWin::boundingBox(const QGlyphLayout &glyphs)
for (int i = 0; i < glyphs.numGlyphs; ++i)
w += glyphs.effectiveAdvance(i);
- return glyph_metrics_t(0, -tm.w.tmAscent, w, tm.w.tmHeight, w, 0);
+ return glyph_metrics_t(0, -tm.tmAscent, w, tm.tmHeight, w, 0);
}
-
-
-#ifndef Q_WS_WINCE
-typedef HRESULT (WINAPI *pGetCharABCWidthsFloat)(HDC, UINT, UINT, LPABCFLOAT);
-static pGetCharABCWidthsFloat qt_GetCharABCWidthsFloat = 0;
-#endif
-
glyph_metrics_t QFontEngineWin::boundingBox(glyph_t glyph, const QTransform &t)
{
#ifndef Q_WS_WINCE
@@ -705,30 +547,13 @@ glyph_metrics_t QFontEngineWin::boundingBox(glyph_t glyph, const QTransform &t)
HDC hdc = shared_dc();
SelectObject(hdc, hfont);
- if(!ttf) {
- SIZE s = {0, 0};
- WCHAR ch = glyph;
- int width;
- int overhang = 0;
- static bool resolved = false;
- if (!resolved) {
- QLibrary lib(QLatin1String("gdi32"));
- qt_GetCharABCWidthsFloat = (pGetCharABCWidthsFloat) lib.resolve("GetCharABCWidthsFloatW");
- resolved = true;
- }
- if (QT_WA_INLINE(true, false) && qt_GetCharABCWidthsFloat) {
- ABCFLOAT abc;
- qt_GetCharABCWidthsFloat(hdc, ch, ch, &abc);
- width = qRound(abc.abcfB);
- } else {
- GetTextExtentPoint32W(hdc, &ch, 1, &s);
- overhang = (QSysInfo::WindowsVersion & QSysInfo::WV_DOS_based) ? tm.a.tmOverhang : 0;
- width = s.cx;
- }
+ if (!ttf) {
+ wchar_t ch = glyph;
+ ABCFLOAT abc;
+ GetCharABCWidthsFloat(hdc, ch, ch, &abc);
+ int width = qRound(abc.abcfB);
- return glyph_metrics_t(0, -tm.a.tmAscent,
- width, tm.a.tmHeight,
- width-overhang, 0).transformed(t);
+ return glyph_metrics_t(0, -tm.tmAscent, width, tm.tmHeight, width, 0).transformed(t);
} else {
DWORD res = 0;
MAT2 mat;
@@ -753,11 +578,8 @@ glyph_metrics_t QFontEngineWin::boundingBox(glyph_t glyph, const QTransform &t)
SetWorldTransform(hdc, &xform);
}
- QT_WA({
- res = GetGlyphOutlineW(hdc, glyph, GGO_METRICS|GGO_GLYPH_INDEX, &gm, 0, 0, &mat);
- } , {
- res = GetGlyphOutlineA(hdc, glyph, GGO_METRICS|GGO_GLYPH_INDEX, &gm, 0, 0, &mat);
- });
+ res = GetGlyphOutline(hdc, glyph, GGO_METRICS | GGO_GLYPH_INDEX, &gm, 0, 0, &mat);
+
if (t.type() > QTransform::TxTranslate) {
XFORM xform;
xform.eM11 = xform.eM22 = 1;
@@ -793,28 +615,28 @@ glyph_metrics_t QFontEngineWin::boundingBox(glyph_t glyph, const QTransform &t)
else
#endif
{ // fallback
- width = tm.w.tmMaxCharWidth;
+ width = tm.tmMaxCharWidth;
advance = width;
}
SelectObject(hdc, oldFont);
- return glyph_metrics_t(0, -tm.w.tmAscent, width, tm.w.tmHeight, advance, 0).transformed(t);
+ return glyph_metrics_t(0, -tm.tmAscent, width, tm.tmHeight, advance, 0).transformed(t);
#endif
}
QFixed QFontEngineWin::ascent() const
{
- return tm.w.tmAscent;
+ return tm.tmAscent;
}
QFixed QFontEngineWin::descent() const
{
- return tm.w.tmDescent;
+ return tm.tmDescent;
}
QFixed QFontEngineWin::leading() const
{
- return tm.w.tmExternalLeading;
+ return tm.tmExternalLeading;
}
@@ -827,12 +649,12 @@ QFixed QFontEngineWin::xHeight() const
QFixed QFontEngineWin::averageCharWidth() const
{
- return tm.w.tmAveCharWidth;
+ return tm.tmAveCharWidth;
}
qreal QFontEngineWin::maxCharWidth() const
{
- return tm.w.tmMaxCharWidth;
+ return tm.tmMaxCharWidth;
}
enum { max_font_count = 256 };
@@ -879,10 +701,10 @@ qreal QFontEngineWin::minRightBearing() const
SelectObject(hdc, hfont);
if (ttf) {
ABC *abc = 0;
- int n = QT_WA_INLINE(tm.w.tmLastChar - tm.w.tmFirstChar, tm.a.tmLastChar - tm.a.tmFirstChar);
+ int n = tm.tmLastChar - tm.tmFirstChar;
if (n <= max_font_count) {
abc = new ABC[n+1];
- GetCharABCWidths(hdc, tm.w.tmFirstChar, tm.w.tmLastChar, abc);
+ GetCharABCWidths(hdc, tm.tmFirstChar, tm.tmLastChar, abc);
} else {
abc = new ABC[char_table_entries+1];
for(int i = 0; i < char_table_entries; i++)
@@ -898,9 +720,6 @@ qreal QFontEngineWin::minRightBearing() const
}
}
delete [] abc;
- } else {
- ml = 0;
- mr = -tm.a.tmOverhang;
}
lbearing = ml;
rbearing = mr;
@@ -915,28 +734,14 @@ qreal QFontEngineWin::minRightBearing() const
SelectObject(hdc, hfont);
if (ttf) {
ABC *abc = 0;
- int n = QT_WA_INLINE(tm.w.tmLastChar - tm.w.tmFirstChar, tm.a.tmLastChar - tm.a.tmFirstChar);
+ int n = tm.tmLastChar - tm.tmFirstChar;
if (n <= max_font_count) {
abc = new ABC[n+1];
- QT_WA({
- GetCharABCWidths(hdc, tm.w.tmFirstChar, tm.w.tmLastChar, abc);
- }, {
- GetCharABCWidthsA(hdc,tm.a.tmFirstChar,tm.a.tmLastChar,abc);
- });
+ GetCharABCWidths(hdc, tm.tmFirstChar, tm.tmLastChar, abc);
} else {
abc = new ABC[char_table_entries+1];
- QT_WA({
- for(int i = 0; i < char_table_entries; i++)
- GetCharABCWidths(hdc, char_table[i], char_table[i], abc+i);
- }, {
- for(int i = 0; i < char_table_entries; i++) {
- QByteArray w = QString(QChar(char_table[i])).toLocal8Bit();
- if (w.length() == 1) {
- uint ch8 = (uchar)w[0];
- GetCharABCWidthsA(hdc, ch8, ch8, abc+i);
- }
- }
- });
+ for(int i = 0; i < char_table_entries; i++)
+ GetCharABCWidths(hdc, char_table[i], char_table[i], abc + i);
n = char_table_entries;
}
ml = abc[0].abcA;
@@ -949,33 +754,28 @@ qreal QFontEngineWin::minRightBearing() const
}
delete [] abc;
} else {
- QT_WA({
- ABCFLOAT *abc = 0;
- int n = tm.w.tmLastChar - tm.w.tmFirstChar+1;
- if (n <= max_font_count) {
- abc = new ABCFLOAT[n];
- GetCharABCWidthsFloat(hdc, tm.w.tmFirstChar, tm.w.tmLastChar, abc);
- } else {
- abc = new ABCFLOAT[char_table_entries];
- for(int i = 0; i < char_table_entries; i++)
- GetCharABCWidthsFloat(hdc, char_table[i], char_table[i], abc+i);
- n = char_table_entries;
- }
- float fml = abc[0].abcfA;
- float fmr = abc[0].abcfC;
- for (int i=1; i<n; i++) {
- if (abc[i].abcfA + abc[i].abcfB + abc[i].abcfC != 0) {
- fml = qMin(fml,abc[i].abcfA);
- fmr = qMin(fmr,abc[i].abcfC);
- }
+ ABCFLOAT *abc = 0;
+ int n = tm.tmLastChar - tm.tmFirstChar+1;
+ if (n <= max_font_count) {
+ abc = new ABCFLOAT[n];
+ GetCharABCWidthsFloat(hdc, tm.tmFirstChar, tm.tmLastChar, abc);
+ } else {
+ abc = new ABCFLOAT[char_table_entries];
+ for(int i = 0; i < char_table_entries; i++)
+ GetCharABCWidthsFloat(hdc, char_table[i], char_table[i], abc+i);
+ n = char_table_entries;
+ }
+ float fml = abc[0].abcfA;
+ float fmr = abc[0].abcfC;
+ for (int i=1; i<n; i++) {
+ if (abc[i].abcfA + abc[i].abcfB + abc[i].abcfC != 0) {
+ fml = qMin(fml,abc[i].abcfA);
+ fmr = qMin(fmr,abc[i].abcfC);
}
- ml = int(fml-0.9999);
- mr = int(fmr-0.9999);
- delete [] abc;
- } , {
- ml = 0;
- mr = -tm.a.tmOverhang;
- });
+ }
+ ml = int(fml - 0.9999);
+ mr = int(fmr - 0.9999);
+ delete [] abc;
}
lbearing = ml;
rbearing = mr;
@@ -1012,17 +812,10 @@ bool QFontEngineWin::canRender(const QChar *string, int len)
return false;
}
} else {
- QT_WA({
- while(len--) {
- if (tm.w.tmFirstChar > string->unicode() || tm.w.tmLastChar < string->unicode())
- return false;
- }
- }, {
- while(len--) {
- if (tm.a.tmFirstChar > string->unicode() || tm.a.tmLastChar < string->unicode())
- return false;
- }
- });
+ while(len--) {
+ if (tm.tmFirstChar > string->unicode() || tm.tmLastChar < string->unicode())
+ return false;
+ }
}
return true;
}
@@ -1065,11 +858,7 @@ static bool addGlyphToPath(glyph_t glyph, const QFixedPoint &position, HDC hdc,
memset(&gMetric, 0, sizeof(GLYPHMETRICS));
int bufferSize = GDI_ERROR;
#if !defined(Q_WS_WINCE)
- QT_WA( {
- bufferSize = GetGlyphOutlineW(hdc, glyph, glyphFormat, &gMetric, 0, 0, &mat);
- }, {
- bufferSize = GetGlyphOutlineA(hdc, glyph, glyphFormat, &gMetric, 0, 0, &mat);
- });
+ bufferSize = GetGlyphOutline(hdc, glyph, glyphFormat, &gMetric, 0, 0, &mat);
#endif
if ((DWORD)bufferSize == GDI_ERROR) {
return false;
@@ -1078,13 +867,7 @@ static bool addGlyphToPath(glyph_t glyph, const QFixedPoint &position, HDC hdc,
void *dataBuffer = new char[bufferSize];
DWORD ret = GDI_ERROR;
#if !defined(Q_WS_WINCE)
- QT_WA( {
- ret = GetGlyphOutlineW(hdc, glyph, glyphFormat, &gMetric, bufferSize,
- dataBuffer, &mat);
- }, {
- ret = GetGlyphOutlineA(hdc, glyph, glyphFormat, &gMetric, bufferSize,
- dataBuffer, &mat);
- } );
+ ret = GetGlyphOutline(hdc, glyph, glyphFormat, &gMetric, bufferSize, dataBuffer, &mat);
#endif
if (ret == GDI_ERROR) {
delete [](char *)dataBuffer;
@@ -1171,14 +954,7 @@ void QFontEngineWin::addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions, in
// font at the correct pixel size.
lf.lfHeight = -unitsPerEm;
lf.lfWidth = 0;
- HFONT hf;
- QT_WA({
- hf = CreateFontIndirectW(&lf);
- }, {
- LOGFONTA lfa;
- wa_copy_logfont(&lf, &lfa);
- hf = CreateFontIndirectA(&lfa);
- });
+ HFONT hf = CreateFontIndirect(&lf);
HDC hdc = shared_dc();
HGDIOBJ oldfont = SelectObject(hdc, hf);
@@ -1200,7 +976,7 @@ void QFontEngineWin::addOutlineToPath(qreal x, qreal y, const QGlyphLayout &glyp
QPainterPath *path, QTextItem::RenderFlags flags)
{
#if !defined(Q_WS_WINCE)
- if(tm.w.tmPitchAndFamily & (TMPF_TRUETYPE | TMPF_VECTOR)) {
+ if(tm.tmPitchAndFamily & (TMPF_TRUETYPE | TMPF_VECTOR)) {
hasOutline = true;
QFontEngine::addOutlineToPath(x, y, glyphs, path, flags);
if (hasOutline) {
@@ -1234,11 +1010,11 @@ int QFontEngineWin::synthesized() const
uchar data[4];
GetFontData(hdc, HEAD, 44, &data, 4);
USHORT macStyle = getUShort(data);
- if (tm.w.tmItalic && !(macStyle & 2))
+ if (tm.tmItalic && !(macStyle & 2))
synthesized_flags = SynthesizedItalic;
if (fontDef.stretch != 100 && ttf)
synthesized_flags |= SynthesizedStretch;
- if (tm.w.tmWeight >= 500 && !(macStyle & 1))
+ if (tm.tmWeight >= 500 && !(macStyle & 1))
synthesized_flags |= SynthesizedBold;
//qDebug() << "font is" << _name <<
// "it=" << (macStyle & 2) << fontDef.style << "flags=" << synthesized_flags;
@@ -1254,24 +1030,12 @@ QFixed QFontEngineWin::emSquareSize() const
QFontEngine::Properties QFontEngineWin::properties() const
{
-
LOGFONT lf = logfont;
lf.lfHeight = unitsPerEm;
- HFONT hf;
- QT_WA({
- hf = CreateFontIndirectW(&lf);
- }, {
- LOGFONTA lfa;
- wa_copy_logfont(&lf, &lfa);
- hf = CreateFontIndirectA(&lfa);
- });
+ HFONT hf = CreateFontIndirect(&lf);
HDC hdc = shared_dc();
HGDIOBJ oldfont = SelectObject(hdc, hf);
-#if defined(Q_WS_WINCE)
- OUTLINETEXTMETRICW *otm = getOutlineTextMetric(hdc);
-#else
- OUTLINETEXTMETRICA *otm = getOutlineTextMetric(hdc);
-#endif
+ OUTLINETEXTMETRIC *otm = getOutlineTextMetric(hdc);
Properties p;
p.emSquare = unitsPerEm;
p.italicAngle = otm->otmItalicAngle;
@@ -1301,14 +1065,7 @@ void QFontEngineWin::getUnscaledGlyph(glyph_t glyph, QPainterPath *path, glyph_m
if(flags & SynthesizedItalic)
lf.lfItalic = false;
lf.lfWidth = 0;
- HFONT hf;
- QT_WA({
- hf = CreateFontIndirectW(&lf);
- }, {
- LOGFONTA lfa;
- wa_copy_logfont(&lf, &lfa);
- hf = CreateFontIndirectA(&lfa);
- });
+ HFONT hf = CreateFontIndirect(&lf);
HDC hdc = shared_dc();
HGDIOBJ oldfont = SelectObject(hdc, hf);
QFixedPoint p;
@@ -1377,14 +1134,7 @@ QNativeImage *QFontEngineWin::drawGDIGlyph(HFONT font, glyph_t glyph, int margin
memset(&mat, 0, sizeof(mat));
mat.eM11.value = mat.eM22.value = 1;
- int error = 0;
- QT_WA( {
- error = GetGlyphOutlineW(hdc, glyph, ggo_options, &tgm, 0, 0, &mat);
- }, {
- error = GetGlyphOutlineA(hdc, glyph, ggo_options, &tgm, 0, 0, &mat);
- } );
-
- if (error == GDI_ERROR) {
+ if (GetGlyphOutline(hdc, glyph, ggo_options, &tgm, 0, 0, &mat) == GDI_ERROR) {
qWarning("QWinFontEngine: unable to query transformed glyph metrics...");
return 0;
}
@@ -1430,11 +1180,11 @@ QNativeImage *QFontEngineWin::drawGDIGlyph(HFONT font, glyph_t glyph, int margin
if (has_transformation) {
SetGraphicsMode(hdc, GM_ADVANCED);
SetWorldTransform(hdc, &xform);
- ExtTextOutW(hdc, 0, 0, options, 0, (LPCWSTR) &glyph, 1, 0);
+ ExtTextOut(hdc, 0, 0, options, 0, (LPCWSTR) &glyph, 1, 0);
} else
#endif
{
- ExtTextOutW(hdc, -gx + margin, -gy + margin, options, 0, (LPCWSTR) &glyph, 1, 0);
+ ExtTextOut(hdc, -gx + margin, -gy + margin, options, 0, (LPCWSTR) &glyph, 1, 0);
}
SelectObject(hdc, old_font);
@@ -1450,7 +1200,7 @@ QImage QFontEngineWin::alphaMapForGlyph(glyph_t glyph, const QTransform &xform)
if (qt_cleartype_enabled) {
LOGFONT lf = logfont;
lf.lfQuality = ANTIALIASED_QUALITY;
- font = CreateFontIndirectW(&lf);
+ font = CreateFontIndirect(&lf);
}
QImage::Format mask_format = QNativeImage::systemFormat();
#ifndef Q_OS_WINCE
@@ -1557,17 +1307,9 @@ void QFontEngineMultiWin::loadEngine(int at)
QString fam = fallbacks.at(at-1);
LOGFONT lf = static_cast<QFontEngineWin *>(engines.at(0))->logfont;
- HFONT hfont;
- QT_WA({
- memcpy(lf.lfFaceName, fam.utf16(), sizeof(TCHAR)*qMin(fam.length()+1,32)); // 32 = Windows hard-coded
- hfont = CreateFontIndirectW(&lf);
- } , {
- // LOGFONTA and LOGFONTW are binary compatible
- QByteArray lname = fam.toLocal8Bit();
- memcpy(lf.lfFaceName,lname.data(),
- qMin(lname.length()+1,32)); // 32 = Windows hard-coded
- hfont = CreateFontIndirectA((LOGFONTA*)&lf);
- });
+ memcpy(lf.lfFaceName, fam.utf16(), sizeof(wchar_t) * qMin(fam.length() + 1, 32)); // 32 = Windows hard-coded
+ HFONT hfont = CreateFontIndirect(&lf);
+
bool stockFont = false;
if (hfont == 0) {
hfont = (HFONT)GetStockObject(ANSI_VAR_FONT);
diff --git a/src/gui/text/qfontengine_win_p.h b/src/gui/text/qfontengine_win_p.h
index a8da78a..b86bd00 100644
--- a/src/gui/text/qfontengine_win_p.h
+++ b/src/gui/text/qfontengine_win_p.h
@@ -80,7 +80,7 @@ public:
virtual void addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions, int nglyphs,
QPainterPath *path, QTextItem::RenderFlags flags);
- HGDIOBJ selectDesignFont(QFixed *) const;
+ HGDIOBJ selectDesignFont() const;
virtual glyph_metrics_t boundingBox(const QGlyphLayout &glyphs);
virtual glyph_metrics_t boundingBox(glyph_t g) { return boundingBox(g, QTransform()); }
@@ -109,18 +109,14 @@ public:
int getGlyphIndexes(const QChar *ch, int numChars, QGlyphLayout *glyphs, bool mirrored) const;
void getCMap();
- QString _name;
- HFONT hfont;
+ QString _name;
+ HFONT hfont;
LOGFONT logfont;
- uint stockFont : 1;
- uint useTextOutA : 1;
- uint ttf : 1;
+ uint stockFont : 1;
+ uint ttf : 1;
uint hasOutline : 1;
- union {
- TEXTMETRICW w;
- TEXTMETRICA a;
- } tm;
- int lw;
+ TEXTMETRIC tm;
+ int lw;
const unsigned char *cmap;
QByteArray cmapTable;
mutable qreal lbearing;
diff --git a/src/gui/text/qsyntaxhighlighter.cpp b/src/gui/text/qsyntaxhighlighter.cpp
index db1a38e..56c7ca1 100644
--- a/src/gui/text/qsyntaxhighlighter.cpp
+++ b/src/gui/text/qsyntaxhighlighter.cpp
@@ -65,6 +65,18 @@ public:
void _q_reformatBlocks(int from, int charsRemoved, int charsAdded);
void reformatBlock(QTextBlock block);
+
+ inline void rehighlight(QTextCursor &cursor, QTextCursor::MoveOperation operation) {
+ QObject::disconnect(doc, SIGNAL(contentsChange(int,int,int)),
+ q_func(), SLOT(_q_reformatBlocks(int,int,int)));
+ cursor.beginEditBlock();
+ int from = cursor.position();
+ cursor.movePosition(operation);
+ _q_reformatBlocks(from, 0, cursor.position() - from);
+ cursor.endEditBlock();
+ QObject::connect(doc, SIGNAL(contentsChange(int,int,int)),
+ q_func(), SLOT(_q_reformatBlocks(int,int,int)));
+ }
inline void _q_delayedRehighlight() {
if (!rehighlightPending)
@@ -355,7 +367,9 @@ QTextDocument *QSyntaxHighlighter::document() const
/*!
\since 4.2
- Redoes the highlighting of the whole document.
+ Reapplies the highlighting to the whole document.
+
+ \sa rehighlightBlock()
*/
void QSyntaxHighlighter::rehighlight()
{
@@ -363,15 +377,25 @@ void QSyntaxHighlighter::rehighlight()
if (!d->doc)
return;
- disconnect(d->doc, SIGNAL(contentsChange(int,int,int)),
- this, SLOT(_q_reformatBlocks(int,int,int)));
QTextCursor cursor(d->doc);
- cursor.beginEditBlock();
- cursor.movePosition(QTextCursor::End);
- d->_q_reformatBlocks(0, 0, cursor.position());
- cursor.endEditBlock();
- connect(d->doc, SIGNAL(contentsChange(int,int,int)),
- this, SLOT(_q_reformatBlocks(int,int,int)));
+ d->rehighlight(cursor, QTextCursor::End);
+}
+
+/*!
+ \since 4.6
+
+ Reapplies the highlighting to the given QTextBlock \a block.
+
+ \sa rehighlight()
+*/
+void QSyntaxHighlighter::rehighlightBlock(const QTextBlock &block)
+{
+ Q_D(QSyntaxHighlighter);
+ if (!d->doc)
+ return;
+
+ QTextCursor cursor(block);
+ d->rehighlight(cursor, QTextCursor::EndOfBlock);
}
/*!
diff --git a/src/gui/text/qsyntaxhighlighter.h b/src/gui/text/qsyntaxhighlighter.h
index 4e5271b..ee249b8 100644
--- a/src/gui/text/qsyntaxhighlighter.h
+++ b/src/gui/text/qsyntaxhighlighter.h
@@ -78,6 +78,7 @@ public:
public Q_SLOTS:
void rehighlight();
+ void rehighlightBlock(const QTextBlock &block);
protected:
virtual void highlightBlock(const QString &text) = 0;
diff --git a/src/gui/text/qtextcontrol.cpp b/src/gui/text/qtextcontrol.cpp
index 88f8028..78fd13b 100644
--- a/src/gui/text/qtextcontrol.cpp
+++ b/src/gui/text/qtextcontrol.cpp
@@ -1245,7 +1245,8 @@ void QTextControlPrivate::keyPressEvent(QKeyEvent *e)
process:
{
QString text = e->text();
- if (!text.isEmpty() && (text.at(0).isPrint() || text.at(0) == QLatin1Char('\t'))) {
+ if (!text.isEmpty() && (text.at(0).isPrint() || text.at(0) == QLatin1Char('\t')) &&
+ ((e->modifiers() & (Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier)) == Qt::NoModifier)) {
if (overwriteMode
// no need to call deleteChar() if we have a selection, insertText
// does it already
diff --git a/src/gui/text/qtextcursor.cpp b/src/gui/text/qtextcursor.cpp
index 0e3cb56..19d4cc4 100644
--- a/src/gui/text/qtextcursor.cpp
+++ b/src/gui/text/qtextcursor.cpp
@@ -1856,6 +1856,8 @@ bool QTextCursor::atStart() const
}
/*!
+ \since 4.6
+
Returns true if the cursor is at the end of the document;
otherwise returns false.
diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp
index 3287f31..3531699 100644
--- a/src/gui/text/qtextdocument.cpp
+++ b/src/gui/text/qtextdocument.cpp
@@ -2416,7 +2416,10 @@ void QTextHtmlExporter::emitFragment(const QTextFragment &fragment)
static bool isOrderedList(int style)
{
return style == QTextListFormat::ListDecimal || style == QTextListFormat::ListLowerAlpha
- || style == QTextListFormat::ListUpperAlpha;
+ || style == QTextListFormat::ListUpperAlpha
+ || style == QTextListFormat::ListUpperRoman
+ || style == QTextListFormat::ListLowerRoman
+ ;
}
void QTextHtmlExporter::emitBlockAttributes(const QTextBlock &block)
@@ -2513,6 +2516,8 @@ void QTextHtmlExporter::emitBlock(const QTextBlock &block)
case QTextListFormat::ListSquare: html += QLatin1String("<ul type=\"square\""); break;
case QTextListFormat::ListLowerAlpha: html += QLatin1String("<ol type=\"a\""); break;
case QTextListFormat::ListUpperAlpha: html += QLatin1String("<ol type=\"A\""); break;
+ case QTextListFormat::ListLowerRoman: html += QLatin1String("<ol type=\"i\""); break;
+ case QTextListFormat::ListUpperRoman: html += QLatin1String("<ol type=\"I\""); break;
default: html += QLatin1String("<ul"); // ### should not happen
}
diff --git a/src/gui/text/qtextdocumentlayout.cpp b/src/gui/text/qtextdocumentlayout.cpp
index 125d74c..f1d9091 100644
--- a/src/gui/text/qtextdocumentlayout.cpp
+++ b/src/gui/text/qtextdocumentlayout.cpp
@@ -1383,6 +1383,8 @@ void QTextDocumentLayoutPrivate::drawListItem(const QPointF &offset, QPainter *p
case QTextListFormat::ListDecimal:
case QTextListFormat::ListLowerAlpha:
case QTextListFormat::ListUpperAlpha:
+ case QTextListFormat::ListLowerRoman:
+ case QTextListFormat::ListUpperRoman:
itemText = static_cast<QTextList *>(object)->itemText(bl);
size.setWidth(fontMetrics.width(itemText));
size.setHeight(fontMetrics.height());
@@ -1426,7 +1428,9 @@ void QTextDocumentLayoutPrivate::drawListItem(const QPointF &offset, QPainter *p
switch (style) {
case QTextListFormat::ListDecimal:
case QTextListFormat::ListLowerAlpha:
- case QTextListFormat::ListUpperAlpha: {
+ case QTextListFormat::ListUpperAlpha:
+ case QTextListFormat::ListLowerRoman:
+ case QTextListFormat::ListUpperRoman: {
QTextLayout layout(itemText, font, q->paintDevice());
layout.setCacheEnabled(true);
QTextOption option(Qt::AlignLeft | Qt::AlignAbsolute);
diff --git a/src/gui/text/qtextformat.cpp b/src/gui/text/qtextformat.cpp
index 9bc62b1..4e43418 100644
--- a/src/gui/text/qtextformat.cpp
+++ b/src/gui/text/qtextformat.cpp
@@ -2078,6 +2078,8 @@ QList<QTextOption::Tab> QTextBlockFormat::tabPositions() const
\value ListDecimal decimal values in ascending order
\value ListLowerAlpha lower case Latin characters in alphabetical order
\value ListUpperAlpha upper case Latin characters in alphabetical order
+ \value ListLowerRoman lower case roman numerals (supports up to 4999 items only)
+ \value ListUpperRoman upper case roman numerals (supports up to 4999 items only)
\omitvalue ListStyleUndefined
*/
diff --git a/src/gui/text/qtextformat.h b/src/gui/text/qtextformat.h
index d269687..9697105 100644
--- a/src/gui/text/qtextformat.h
+++ b/src/gui/text/qtextformat.h
@@ -604,6 +604,8 @@ public:
ListDecimal = -4,
ListLowerAlpha = -5,
ListUpperAlpha = -6,
+ ListLowerRoman = -7,
+ ListUpperRoman = -8,
ListStyleUndefined = 0
};
diff --git a/src/gui/text/qtexthtmlparser.cpp b/src/gui/text/qtexthtmlparser.cpp
index 1bff162..a88cd17 100644
--- a/src/gui/text/qtexthtmlparser.cpp
+++ b/src/gui/text/qtexthtmlparser.cpp
@@ -1206,6 +1206,8 @@ void QTextHtmlParserNode::setListStyle(const QVector<QCss::Value> &cssValues)
case QCss::Value_Decimal: hasOwnListStyle = true; listStyle = QTextListFormat::ListDecimal; break;
case QCss::Value_LowerAlpha: hasOwnListStyle = true; listStyle = QTextListFormat::ListLowerAlpha; break;
case QCss::Value_UpperAlpha: hasOwnListStyle = true; listStyle = QTextListFormat::ListUpperAlpha; break;
+ case QCss::Value_LowerRoman: hasOwnListStyle = true; listStyle = QTextListFormat::ListLowerRoman; break;
+ case QCss::Value_UpperRoman: hasOwnListStyle = true; listStyle = QTextListFormat::ListUpperRoman; break;
default: break;
}
}
@@ -1540,6 +1542,10 @@ void QTextHtmlParser::applyAttributes(const QStringList &attributes)
node->listStyle = QTextListFormat::ListLowerAlpha;
} else if (value == QLatin1String("A")) {
node->listStyle = QTextListFormat::ListUpperAlpha;
+ } else if (value == QLatin1String("i")) {
+ node->listStyle = QTextListFormat::ListLowerRoman;
+ } else if (value == QLatin1String("I")) {
+ node->listStyle = QTextListFormat::ListUpperRoman;
} else {
value = value.toLower();
if (value == QLatin1String("square"))
diff --git a/src/gui/text/qtextlist.cpp b/src/gui/text/qtextlist.cpp
index addd7a5..02b1c63 100644
--- a/src/gui/text/qtextlist.cpp
+++ b/src/gui/text/qtextlist.cpp
@@ -212,6 +212,55 @@ QString QTextList::itemText(const QTextBlock &blockIt) const
}
}
break;
+ case QTextListFormat::ListLowerRoman:
+ case QTextListFormat::ListUpperRoman:
+ {
+ if (item < 5000) {
+ QByteArray romanNumeral;
+
+ // works for up to 4999 items
+ static const char romanSymbolsLower[] = "iiivixxxlxcccdcmmmm";
+ static const char romanSymbolsUpper[] = "IIIVIXXXLXCCCDCMMMM";
+ QByteArray romanSymbols; // wrap to have "mid"
+ if (style == QTextListFormat::ListLowerRoman)
+ romanSymbols = QByteArray::fromRawData(romanSymbolsLower, sizeof(romanSymbolsLower));
+ else
+ romanSymbols = QByteArray::fromRawData(romanSymbolsUpper, sizeof(romanSymbolsUpper));
+
+ int c[] = { 1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000 };
+ int n = item;
+ for (int i = 12; i >= 0; n %= c[i], i--) {
+ int q = n / c[i];
+ if (q > 0) {
+ int startDigit = i + (i+3)/4;
+ int numDigits;
+ if (i % 4) {
+ // c[i] == 4|5|9|40|50|90|400|500|900
+ if ((i-2) % 4) {
+ // c[i] == 4|9|40|90|400|900 => with substraction (IV, IX, XL, XC, ...)
+ numDigits = 2;
+ }
+ else {
+ // c[i] == 5|50|500 (V, L, D)
+ numDigits = 1;
+ }
+ }
+ else {
+ // c[i] == 1|10|100|1000 (I, II, III, X, XX, ...)
+ numDigits = q;
+ }
+
+ romanNumeral.append(romanSymbols.mid(startDigit, numDigits));
+ }
+ }
+ result = QString::fromLatin1(romanNumeral);
+ }
+ else {
+ result = QLatin1String("?");
+ }
+
+ }
+ break;
default:
Q_ASSERT(false);
}
diff --git a/src/gui/text/qtextodfwriter.cpp b/src/gui/text/qtextodfwriter.cpp
index b0c16ee..883cf80 100644
--- a/src/gui/text/qtextodfwriter.cpp
+++ b/src/gui/text/qtextodfwriter.cpp
@@ -174,6 +174,10 @@ static QString bulletChar(QTextListFormat::Style style)
return QString::fromLatin1("a");
case QTextListFormat::ListUpperAlpha:
return QString::fromLatin1("A");
+ case QTextListFormat::ListLowerRoman:
+ return QString::fromLatin1("i");
+ case QTextListFormat::ListUpperRoman:
+ return QString::fromLatin1("I");
default:
case QTextListFormat::ListStyleUndefined:
return QString();
@@ -619,7 +623,9 @@ void QTextOdfWriter::writeListFormat(QXmlStreamWriter &writer, QTextListFormat f
QTextListFormat::Style style = format.style();
if (style == QTextListFormat::ListDecimal || style == QTextListFormat::ListLowerAlpha
- || style == QTextListFormat::ListUpperAlpha) {
+ || style == QTextListFormat::ListUpperAlpha
+ || style == QTextListFormat::ListLowerRoman
+ || style == QTextListFormat::ListUpperRoman) {
writer.writeStartElement(textNS, QString::fromLatin1("list-level-style-number"));
writer.writeAttribute(styleNS, QString::fromLatin1("num-format"), bulletChar(style));
writer.writeAttribute(styleNS, QString::fromLatin1("num-suffix"), QString::fromLatin1("."));
diff --git a/src/gui/text/qzip.cpp b/src/gui/text/qzip.cpp
index 75ce713..e4e54cf 100644
--- a/src/gui/text/qzip.cpp
+++ b/src/gui/text/qzip.cpp
@@ -56,13 +56,23 @@
#if defined(Q_OS_WIN)
#undef S_IFREG
#define S_IFREG 0100000
-# define S_ISDIR(x) ((x) & 0040000) > 0
-# define S_ISREG(x) ((x) & 0170000) == S_IFREG
+# ifndef S_ISDIR
+# define S_ISDIR(x) ((x) & 0040000) > 0
+# endif
+# ifndef S_ISREG
+# define S_ISREG(x) ((x) & 0170000) == S_IFREG
+# endif
# define S_IFLNK 020000
# define S_ISLNK(x) ((x) & S_IFLNK) > 0
-# define S_IRUSR 0400
-# define S_IWUSR 0200
-# define S_IXUSR 0100
+# ifndef S_IRUSR
+# define S_IRUSR 0400
+# endif
+# ifndef S_IWUSR
+# define S_IWUSR 0200
+# endif
+# ifndef S_IXUSR
+# define S_IXUSR 0100
+# endif
# define S_IRGRP 0040
# define S_IWGRP 0020
# define S_IXGRP 0010