Thread: [Kde-cygwin-cvs] CVS: qt-3/src/kernel qapplication_win.cpp,1.1.2.30.2.95,1.1.2.30.2.96 qfontengine_w
Status: Inactive
Brought to you by:
habacker
From: Christian E. <che...@us...> - 2005-10-26 20:37:05
|
Update of /cvsroot/kde-cygwin/qt-3/src/kernel In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25879/src/kernel Modified Files: Tag: QT_WIN32_3_3_BRANCH qapplication_win.cpp qfontengine_win.cpp Log Message: more fixes Index: qapplication_win.cpp =================================================================== RCS file: /cvsroot/kde-cygwin/qt-3/src/kernel/Attic/qapplication_win.cpp,v retrieving revision 1.1.2.30.2.95 retrieving revision 1.1.2.30.2.96 diff -u -r1.1.2.30.2.95 -r1.1.2.30.2.96 --- qapplication_win.cpp 24 Oct 2005 17:33:29 -0000 1.1.2.30.2.95 +++ qapplication_win.cpp 26 Oct 2005 20:36:56 -0000 1.1.2.30.2.96 @@ -233,6 +233,10 @@ { QWidget::clearWFlags( f ); } + void markFrameStrutDirty() + { + fstrut_dirty = 1; + } bool translateMouseEvent( const MSG &msg ); @@ -505,12 +509,12 @@ smallTitleFont = qt_LOGFONTtoQFont((LOGFONT&)ncm.lfSmCaptionFont,true); }); - QApplication::setFont(menuFont, true, "QMenu"); QApplication::setFont(menuFont, true, "QMenuBar"); - QApplication::setFont(menuFont, true, "QPopupMenu"); - QApplication::setFont(menuFont, true, "QPushButton"); + QApplication::setFont(menuFont, true, "QMenuData"); +// QApplication::setFont(menuFont, true, "QPopupMenu"); +// QApplication::setFont(menuFont, true, "QPushButton"); QApplication::setFont(messageFont, true, "QMessageBox"); - QApplication::setFont(messageFont, true, "QMessageBoxLabel"); +// QApplication::setFont(messageFont, true, "QMessageBoxLabel"); QApplication::setFont(statusFont, true, "QTipLabel"); QApplication::setFont(statusFont, true, "QStatusBar"); QApplication::setFont(titleFont, true, "QTitleBar"); @@ -2876,6 +2880,13 @@ if ( area == "intl" ) QApplication::postEvent( widget, new QEvent( QEvent::LocaleChange ) ); } + if (QApplication::desktopSettingsAware() && wParam != SPI_SETWORKAREA) { + if (widget) { + widget->markFrameStrutDirty(); + if (!widget->parentWidget()) + qt_set_windows_resources(); + } + } break; #ifndef Q_OS_TEMP Index: qfontengine_win.cpp =================================================================== RCS file: /cvsroot/kde-cygwin/qt-3/src/kernel/Attic/qfontengine_win.cpp,v retrieving revision 1.1.2.35 retrieving revision 1.1.2.36 diff -u -r1.1.2.35 -r1.1.2.36 --- qfontengine_win.cpp 25 Oct 2005 19:42:14 -0000 1.1.2.35 +++ qfontengine_win.cpp 26 Oct 2005 20:36:56 -0000 1.1.2.36 @@ -30,6 +30,7 @@ ** **********************************************************************/ #include <limits.h> +#include <math.h> #include "qbitmap.h" #include "qcstring.h" @@ -55,16 +56,16 @@ //extern int qt_mib_for_xlfd_encoding( const char *encoding ); //extern int qt_xlfd_encoding_id( const char *encoding ); +typedef signed short qint16; +typedef unsigned short quint16; +typedef unsigned int quint32; + +static unsigned char *getCMap(HDC hdc, bool &); +static quint32 getGlyphIndex(unsigned char *table, unsigned int unicode); HDC shared_dc = 0; // common dc for all fonts static HFONT stock_sysfont = 0; - -static inline HFONT systemFont() -{ - if (stock_sysfont == 0) - stock_sysfont = (HFONT)GetStockObject(SYSTEM_FONT); - return stock_sysfont; -} +extern Qt::WindowsVersion qt_winver; extern void qt_draw_transformed_rect( QPainter *p, int x, int y, int w, int h, bool fill ); @@ -94,6 +95,13 @@ } } +static inline HFONT systemFont() +{ + if (stock_sysfont == 0) + stock_sysfont = (HFONT)GetStockObject(SYSTEM_FONT); + return stock_sysfont; +} + QFontEngine::~QFontEngine() { // make sure we aren't by accident still selected @@ -123,6 +131,41 @@ return pos ? pos : 1; } +void QFontEngine::getCMap() +{ + QT_WA({ + ttf = (bool)(tm.w.tmPitchAndFamily & TMPF_TRUETYPE); + } , { + ttf = (bool)(tm.a.tmPitchAndFamily & TMPF_TRUETYPE); + }); +// HDC hdc = shared_dc; +// SelectObject(hdc, hfont); + bool symb = false; + cmap = ttf ? ::getCMap(hdc, symb) : 0; + if (!cmap) { + ttf = false; + symb = false; + } + symbol = symb; + script_cache = 0; + // !Qt4 designToDevice = 1.; + // !Qt4 unitsPerEm = tm.w.tmHeight; + if(cmap) { + QT_WA( { + OUTLINETEXTMETRICW metric; + GetOutlineTextMetricsW(hdc, sizeof(OUTLINETEXTMETRICW), &metric); + // !Qt4 designToDevice = (float)metric.otmTextMetrics.tmHeight/(float)metric.otmEMSquare; + // !Qt4 unitsPerEm = metric.otmEMSquare; + }, { + OUTLINETEXTMETRICA metric; + GetOutlineTextMetricsA(hdc, sizeof(OUTLINETEXTMETRICA), &metric); + // !Qt4 designToDevice = (float)metric.otmTextMetrics.tmHeight/(float)metric.otmEMSquare; + // !Qt4 unitsPerEm = metric.otmEMSquare; + } ) + // !Qt4 kerning_pairs = getKerning(hdc, designToDevice); + } +} + // ------------------------------------------------------------------ // The box font engine // ------------------------------------------------------------------ @@ -291,80 +334,105 @@ // Win font engine // ------------------------------------------------------------------ - -#ifndef QFONTENGINE_ENABLE_QT4CODE - QFontEngineWin::QFontEngineWin( const char *nameIn, HDC hdcIn, HFONT hfIn, bool bIn, LOGFONT lfIn ) { _name = nameIn; + hfont = hfIn; + hdc = CreateCompatibleDC(hdcIn ? hdcIn : shared_dc); logfont = lfIn; - cmap = 0; - - if ( hdcIn ) { - hdc = hdcIn; - if ( HGDI_ERROR == SelectObject( hdc, hfIn ) ) { -# ifdef QFONTENGINE_WIN_LASTERROR - qlasterror ( "QFontEngineWin::QFontEngineWin(...) SelectObject:", GetLastError () ); -# endif - // what to do? - } else { - hfont = ( HFONT ) SelectObject( hdc, hfIn ); - } - QT_WA( GetTextMetricsW( hdc, &tm.w ); , GetTextMetricsA( hdc, &tm.a ); ); - } else { - hdc = GetDC( NULL ); - hfont = ( HFONT ) SelectObject( hdc, hfont ); - QT_WA( GetTextMetricsW( hdc, &tm.w ); , GetTextMetricsA( hdc, &tm.a ); ); - ReleaseDC( NULL, hdc ); - } + SelectObject( hdc, hfont ); + stockFont = false; lbearing = SHRT_MIN; rbearing = SHRT_MIN; - memset( widthCache, 0, sizeof( widthCache ) ); -} -#endif - - - + BOOL res; + QT_WA({ + res = GetTextMetricsW(shared_dc, &tm.w); + } , { + res = GetTextMetricsA(shared_dc, &tm.a); + }); + if (!res) + qWarning("QFontEngineWin: GetTextMetrics failed"); + cache_cost = tm.w.tmHeight * tm.w.tmAveCharWidth * 2000; + getCMap(); -#ifndef QFONTENGINE_ENABLE_QT4CODE + useTextOutA = false; +#ifndef Q_OS_TEMP + // 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 (qt_winver == Qt::WV_95 && !ttf && + (_name == QString("Marlett").latin1() || _name == QString("Symbol").latin1() || + _name == QString("Webdings").latin1() || _name == QString("Wingdings").latin1())) + useTextOutA = true; +#endif + memset(widthCache, 0, sizeof(widthCache)); +} -void QFontEngine::getGlyphIndexes( const QChar *ch, int numChars, glyph_t *glyphs, bool mirrored ) const +inline unsigned int getChar(const QChar *str, int &i, const int len) { - /* - TCHAR uc; - QT_WA_INLINE( uc = ch[ 0 ].unicode() , uc = ch[ 0 ].latin1() ); - */ - - if ( qt_winunicode ) { - GCP_RESULTSW gi = {0, 0, 0, 0, 0, 0, 0, 0, 0}; - gi.nGlyphs = numChars; - gi.lpGlyphs = ( LPWSTR ) glyphs; - if ( 0 == GetCharacterPlacementW( hdc, ( LPCWSTR ) QString ( ch, numChars ).ucs2 (), numChars, 0, &gi, 0 ) ) { -#ifdef QFONTENGINE_WIN_LASTERROR - qlasterror( "QFontEngineWin::getGlyphIndexes(...) GetCharacterPlacementW:", GetLastError() ); -#endif + unsigned int uc = str[i].unicode(); + if (uc >= 0xd800 && uc < 0xdc00 && i < len-1) { + uint low = str[i+1].unicode(); + if (low >= 0xdc00 && low < 0xe000) { + uc = (uc - 0xd800)*0x400 + (low - 0xdc00) + 0x10000; + ++i; + } + } + return uc; +} +void QFontEngine::getGlyphIndexes( const QChar *str, int numChars, glyph_t *glyphs, bool mirrored ) const +{ + if (mirrored) { + if (symbol) { + for (int i = 0; i < numChars; ++i) { + unsigned int uc = getChar(str, i, numChars); + *glyphs = getGlyphIndex(cmap, uc); + if(!*glyphs && uc < 0x100) + *glyphs = getGlyphIndex(cmap, uc + 0xf000); + glyphs++; + } + } else if (ttf) { + for (int i = 0; i < numChars; ++i) { + unsigned int uc = getChar(str, i, numChars); + *glyphs = getGlyphIndex(cmap, ::mirroredChar(uc).unicode()); + glyphs++; + } + } else { + for (int i = 0; i < numChars; ++i) { + *glyphs = ::mirroredChar(str->unicode()).unicode(); + glyphs++; + str++; + } } } else { - GCP_RESULTSA gi = {0, 0, 0, 0, 0, 0, 0, 0, 0}; - gi.nGlyphs = numChars; - gi.lpGlyphs = ( LPWSTR ) glyphs; - if ( 0 == GetCharacterPlacementA( hdc, ( LPCSTR ) QString ( ch, numChars ).latin1 (), numChars, 0, &gi, 0 ) ) { -#ifdef QFONTENGINE_WIN_LASTERROR - qlasterror( "QFontEngineWin::getGlyphIndexes(...) GetCharacterPlacementA:", GetLastError() ); -#endif - + if (symbol) { + for (int i = 0; i < numChars; ++i) { + unsigned int uc = getChar(str, i, numChars); + *glyphs = getGlyphIndex(cmap, uc); + if(!*glyphs && uc < 0x100) + *glyphs = getGlyphIndex(cmap, uc + 0xf000); + glyphs++; + } + } else if (ttf) { + for (int i = 0; i < numChars; ++i) { + unsigned int uc = getChar(str, i, numChars); + *glyphs = getGlyphIndex(cmap, uc); + glyphs++; + } + } else { + for (int i = 0; i < numChars; ++i) { + *glyphs = str->unicode(); + glyphs++; + str++; + } } } + return; } -#endif //QFONTENGINE_ENABLE_QT4CODE - - -#ifndef QFONTENGINE_ENABLE_QT4CODE_2 QFontEngine::Error QFontEngineWin::stringToCMap( const QChar *str, int len, glyph_t *glyphs, advance_t *advances, int *nglyphs, bool mirrored ) const { @@ -439,12 +507,6 @@ return NoError; } -#endif - - - -#include <math.h> - // CCJ: TODO: doesn't support scaling, etc. void QFontEngineWin::draw( QPainter *p, int x, int y, const QTextEngine *engine, const QScriptItem *si, int textFlags ) { @@ -671,42 +733,36 @@ glyph_metrics_t QFontEngineWin::boundingBox( glyph_t glyph ) { - /* - XGlyphInfo xgi; - getGlyphInfo( &xgi, _font, glyph ); - glyph_metrics_t gm = glyph_metrics_t( -xgi.x, -xgi.y, xgi.width, xgi.height, xgi.xOff, -xgi.yOff ); - if ( _scale != 1. ) { - gm.x = qRound(gm.x * _scale); - gm.y = qRound(gm.y * _scale); - gm.height = qRound(gm.height * _scale); - gm.width = qRound(gm.width * _scale); - gm.xoff = qRound(gm.xoff * _scale); - gm.yoff = qRound(gm.yoff * _scale); - } - return gm; - */ - GLYPHMETRICS gmw = {0}; - MAT2 mat; - ZeroMemory( &mat, sizeof mat ); - mat.eM11.value = mat.eM22.value = 1; - if ( GDI_ERROR == GetGlyphOutline( hdc, glyph, GGO_METRICS | GGO_GLYPH_INDEX, &gmw, 0, 0, &mat ) ) { -#ifdef QFONTENGINE_WIN_LASTERROR - //qDebug ("QFontEngineWin::boundingBox( glyph_t ) glyph: %d ", glyph); - qlasterror( "QFontEngineWin::boundingBox( glyph_t ) GetGlyphOutline:", GetLastError() ); -#endif +#ifndef Q_OS_TEMP + GLYPHMETRICS gm; +// HDC hdc = shared_dc; +// SelectObject(hdc, hfont); + if(!ttf) { + SIZE s = {0, 0}; + WCHAR ch = glyph; + BOOL res = GetTextExtentPoint32W(hdc, &ch, 1, &s); + Q_UNUSED(res); + int overhang = (qt_winver & Qt::WV_DOS_based) ? tm.a.tmOverhang : 0; + return glyph_metrics_t(0, -tm.a.tmAscent, s.cx, tm.a.tmHeight, s.cx-overhang, 0); + } else { + DWORD res = 0; + 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) + return glyph_metrics_t(gm.gmptGlyphOrigin.x, -gm.gmptGlyphOrigin.y, + gm.gmBlackBoxX, gm.gmBlackBoxY, gm.gmCellIncX, gm.gmCellIncY); } - - glyph_metrics_t gm; - - gm.x = - gmw.gmptGlyphOrigin.x; - gm.y = - gmw.gmptGlyphOrigin.y; - gm.width = gmw.gmBlackBoxX; - gm.height = gmw.gmBlackBoxY; - gm.xoff = + gmw.gmCellIncX; - gm.yoff = - gmw.gmCellIncY; - - return gm; +#endif + return glyph_metrics_t(); } @@ -828,13 +884,12 @@ - - -#ifdef QFONTENGINE_ENABLE_QT4CODE - -typedef short qint16; -typedef unsigned short quint16; -typedef unsigned int quint32; +#define MAKE_TAG(ch1, ch2, ch3, ch4) (\ + (((DWORD)(ch4)) << 24) | \ + (((DWORD)(ch3)) << 16) | \ + (((DWORD)(ch2)) << 8) | \ + ((DWORD)(ch1)) \ + ) static inline quint32 getUInt(unsigned char *p) { @@ -856,182 +911,15 @@ return val; } -#define MAKE_TAG(ch1, ch2, ch3, ch4) (\ -(((DWORD)(ch4)) << 24) | \ -(((DWORD)(ch3)) << 16) | \ -(((DWORD)(ch2)) << 8) | \ -((DWORD)(ch1)) \ -) - -static unsigned char *getCMap(HDC hdc, bool &symbol) -{ - const DWORD CMAP = MAKE_TAG('c', 'm', 'a', 'p'); - - unsigned char header[8]; - - // get the CMAP header and the number of encoding tables - DWORD bytes = -#ifndef Q_OS_TEMP - GetFontData(hdc, CMAP, 0, &header, 4); -#else - 0; -#endif - if (bytes == GDI_ERROR) - return 0; - { - unsigned short version = getUShort(header); - if (version != 0) - return 0; - } - - unsigned short numTables = getUShort(header+2); - unsigned char *maps = new unsigned char[8*numTables]; - - // get the encoding table and look for Unicode -#ifndef Q_OS_TEMP - bytes = GetFontData(hdc, CMAP, 4, maps, 8*numTables); -#endif - if (bytes == GDI_ERROR) - return 0; - - quint32 version = 0; - unsigned int unicode_table = 0; - for (int n = 0; n < numTables; n++) { - quint32 v = getUInt(maps + 8*n); - // accept both symbol and Unicode encodings. prefer unicode. - if(v == 0x00030001 || v == 0x00030000 || v == 0x0003000a) { - if (v > version) { - version = v; - unicode_table = getUInt(maps + 8*n + 4); - } - } - } - symbol = version == 0x00030000; - - if (!unicode_table) { - // qDebug("no unicode table found"); - return 0; - } - - delete [] maps; - - // get the header of the unicode table -#ifndef Q_OS_TEMP - bytes = GetFontData(hdc, CMAP, unicode_table, &header, 8); -#endif - if (bytes == GDI_ERROR) - return 0; - - unsigned short format = getUShort(header); - unsigned int length; - if(format < 8) - length = getUShort(header+2); - else - length = getUInt(header+4); - unsigned char *unicode_data = new unsigned char[length]; - - // get the cmap table itself -#ifndef Q_OS_TEMP - bytes = GetFontData(hdc, CMAP, unicode_table, unicode_data, length); -#endif - if (bytes == GDI_ERROR) { - delete [] unicode_data; - return 0; - } - return unicode_data; -} - -void QFontEngine::getCMap() -{ - QT_WA({ - ttf = (bool)(tm.w.tmPitchAndFamily & TMPF_TRUETYPE); - } , { - ttf = (bool)(tm.a.tmPitchAndFamily & TMPF_TRUETYPE); - }); - HDC hdc = shared_dc; - SelectObject(hdc, hfont); - bool symb = false; - cmap = ttf ? ::getCMap(hdc, symb) : 0; - if (!cmap) { - ttf = false; - symb = false; - } - symbol = symb; - script_cache = 0; - // !Qt4 designToDevice = 1.; - // !Qt4 unitsPerEm = tm.w.tmHeight; - if(cmap) { - QT_WA( { - OUTLINETEXTMETRICW metric; - GetOutlineTextMetricsW(hdc, sizeof(OUTLINETEXTMETRICW), &metric); - // !Qt4 designToDevice = (float)metric.otmTextMetrics.tmHeight/(float)metric.otmEMSquare; - // !Qt4 unitsPerEm = metric.otmEMSquare; - }, { - OUTLINETEXTMETRICA metric; - GetOutlineTextMetricsA(hdc, sizeof(OUTLINETEXTMETRICA), &metric); - // !Qt4 designToDevice = (float)metric.otmTextMetrics.tmHeight/(float)metric.otmEMSquare; - // !Qt4 unitsPerEm = metric.otmEMSquare; - } ) - // !Qt4 kerning_pairs = getKerning(hdc, designToDevice); - } -} - -inline unsigned int getChar(const QChar *str, int &i, const int len) +static inline void tag_to_string(char *string, quint32 tag) { - unsigned int uc = str[i].unicode(); - if (uc >= 0xd800 && uc < 0xdc00 && i < len-1) { - uint low = str[i+1].unicode(); - if (low >= 0xdc00 && low < 0xe000) { - uc = (uc - 0xd800)*0x400 + (low - 0xdc00) + 0x10000; - ++i; - } - } - return uc; + string[0] = (tag >> 24)&0xff; + string[1] = (tag >> 16)&0xff; + string[2] = (tag >> 8)&0xff; + string[3] = tag&0xff; + string[4] = 0; } -//QFontEngineWin::QFontEngineWin(const QString &name, HFONT _hfont, bool stockFont, LOGFONT lf) -QFontEngineWin::QFontEngineWin(const char *name3, HDC shared_dc, HFONT _hfont, bool stockFont, LOGFONT lf) -{ - QString name(name3); // !Qt4 - _name = name; - - qDebug("regular windows font engine created: font='%s', size=%d", name, lf.lfHeight); - - hfont = _hfont; - logfont = lf; - SelectObject(shared_dc, hfont); - this->stockFont = stockFont; - - lbearing = SHRT_MIN; - rbearing = SHRT_MIN; - - BOOL res; - QT_WA({ - res = GetTextMetricsW(shared_dc, &tm.w); - } , { - res = GetTextMetricsA(shared_dc, &tm.a); - }); - if (!res) - qWarning("QFontEngineWin: GetTextMetrics failed"); // !Qt4 - - cache_cost = tm.w.tmHeight * tm.w.tmAveCharWidth * 2000; - getCMap(); - - useTextOutA = false; -#ifndef Q_OS_TEMP - // TextOutW doesn't work for symbol fonts on Windows 95! - // since we're using glyph indices we don't care for ttfs about this! - // !Qt4 if (QSysInfo::WindowsVersion == QSysInfo::WV_95 && !ttf && - // !Qt4 (_name == QLatin1String("Marlett") || _name == QLatin1String("Symbol") || - // !Qt4 _name == QLatin1String("Webdings") || _name == QLatin1String("Wingdings"))) - // !Qt4 useTextOutA = true; -#endif - memset(widthCache, 0, sizeof(widthCache)); - // !Qt4 designAdvances = 0; - // !Qt4 designAdvancesSize = 0; -} - - static quint32 getGlyphIndex(unsigned char *table, unsigned int unicode) { unsigned short format = getUShort(table); @@ -1095,164 +983,81 @@ return 0; } +static unsigned char *getCMap(HDC hdc, bool &symbol) +{ + const DWORD CMAP = MAKE_TAG('c', 'm', 'a', 'p'); + unsigned char header[8]; -// !Qt4 : -struct BackPortGlyph -{ - glyph_t glyph; - advance_t *advances; -}; + // get the CMAP header and the number of encoding tables + DWORD bytes = +#ifndef Q_OS_TEMP + GetFontData(hdc, CMAP, 0, &header, 4); +#else + 0; +#endif + if (bytes == GDI_ERROR) + return 0; + { + unsigned short version = getUShort(header); + if (version != 0) + return 0; + } -//int QFontEngine::getGlyphIndexes(const QChar *str, int numChars, QGlyphLayout *glyphs, bool mirrored) const // Qt4 -void QFontEngine::getGlyphIndexes( const QChar *str, int numChars, glyph_t *glyphs3, bool mirrored) const -{ - BackPortGlyph glyphs4; // !Qt4 - BackPortGlyph* glyphs = &glyphs4; // !Qt4 - glyphs->glyph = *glyphs3; // !Qt4 + unsigned short numTables = getUShort(header+2); + unsigned char *maps = new unsigned char[8*numTables]; + // get the encoding table and look for Unicode +#ifndef Q_OS_TEMP + bytes = GetFontData(hdc, CMAP, 4, maps, 8*numTables); +#endif + if (bytes == GDI_ERROR) + return 0; - //QGlyphLayout *g = glyphs; // !Qt4 - if (mirrored) { - if (symbol) { - for (int i = 0; i < numChars; ++i) { - unsigned int uc = getChar(str, i, numChars); - glyphs->glyph = getGlyphIndex(cmap, uc); - if(!glyphs->glyph && uc < 0x100) - glyphs->glyph = getGlyphIndex(cmap, uc + 0xf000); - glyphs++; - } - } else if (ttf) { - for (int i = 0; i < numChars; ++i) { - unsigned int uc = getChar(str, i, numChars); - glyphs->glyph = getGlyphIndex(cmap, ::mirroredChar(uc).unicode()); - glyphs++; - } - } else { - for (int i = 0; i < numChars; ++i) { - glyphs->glyph = ::mirroredChar(str->unicode()).unicode(); - glyphs++; - str++; - } - } - } else { - if (symbol) { - for (int i = 0; i < numChars; ++i) { - unsigned int uc = getChar(str, i, numChars); - glyphs->glyph = getGlyphIndex(cmap, uc); - if(!glyphs->glyph && uc < 0x100) - glyphs->glyph = getGlyphIndex(cmap, uc + 0xf000); - glyphs++; - } - } else if (ttf) { - for (int i = 0; i < numChars; ++i) { - unsigned int uc = getChar(str, i, numChars); - glyphs->glyph = getGlyphIndex(cmap, uc); - glyphs++; - } - } else { - for (int i = 0; i < numChars; ++i) { - glyphs->glyph = str->unicode(); - glyphs++; - str++; + quint32 version = 0; + unsigned int unicode_table = 0; + for (int n = 0; n < numTables; n++) { + quint32 v = getUInt(maps + 8*n); + // accept both symbol and Unicode encodings. prefer unicode. + if(v == 0x00030001 || v == 0x00030000 || v == 0x0003000a) { + if (v > version) { + version = v; + unicode_table = getUInt(maps + 8*n + 4); } } } - - //return glyphs - g; // !QT4 -} - -#endif - - - - - -#if defined(QFONTENGINE_ENABLE_QT4CODE_2) && defined(QFONTENGINE_ENABLE_QT4CODE) - -enum ShaperFlag { - RightToLeft = 0x0001, - Mirrored = 0x0001, - DesignMetrics = 0x0002 -}; - - -//bool QFontEngineWin::stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const -QFontEngine::Error QFontEngineWin::stringToCMap(const QChar *str, int len, glyph_t *glyphs3, advance_t *advances, int *nglyphs, bool mirrored) const -{ - BackPortGlyph glyphs4; - BackPortGlyph* glyphs = &glyphs4; - glyphs->glyph = *glyphs3; + symbol = version == 0x00030000; - if (*nglyphs < len) { - *nglyphs = len; - return false; + if (!unicode_table) { + // qDebug("no unicode table found"); + return 0; } - *nglyphs = getGlyphIndexes(str, len, glyphs, flags & QTextEngine::RightToLeft); + delete [] maps; - HDC hdc = shared_dc; - if (flags & QTextEngine::DesignMetrics) { - HGDIOBJ oldFont = 0; - float 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 - && str[i+1].unicode() >= 0xdc00 && str[i+1].unicode() < 0xe000); - unsigned int glyph = glyphs[glyph_pos].glyph; - if(int(glyph) >= designAdvancesSize) { - int newSize = (glyph + 256) >> 8 << 8; - designAdvances = (float *)realloc(designAdvances, newSize*sizeof(float)); - for(int i = designAdvancesSize; i < newSize; ++i) - designAdvances[i] = -1000000; - designAdvancesSize = newSize; - } - if(designAdvances[glyph] < -999999) { - if(!oldFont) - oldFont = selectDesignFont(&overhang); - SIZE size = {0, 0}; - GetTextExtentPoint32W(hdc, (wchar_t *)(str+i), surrogate ? 2 : 1, &size); - designAdvances[glyph] = size.cx*designToDevice; - } - glyphs[glyph_pos].advance.setX(designAdvances[glyph]); - glyphs[glyph_pos].advance.setY(0); - if (surrogate) - ++i; - ++glyph_pos; - } - if(oldFont) - DeleteObject(SelectObject(hdc, oldFont)); - } else { - HGDIOBJ oldFont = SelectObject(hdc, hfont); - int overhang = (QSysInfo::WindowsVersion & QSysInfo::WV_DOS_based) ? tm.a.tmOverhang : 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 - && str[i+1].unicode() >= 0xdc00 && str[i+1].unicode() < 0xe000); - unsigned int glyph = glyphs[i].glyph; - glyphs[glyph_pos].advance.setX((glyph < widthCacheSize) ? widthCache[glyph] : 0); - glyphs[glyph_pos].advance.setY(0); - // font-width cache failed - if (!glyphs[glyph_pos].advance.x()) { - SIZE size = {0, 0}; - GetTextExtentPoint32W(hdc, (wchar_t *)str + i, surrogate ? 2 : 1, &size); - size.cx -= overhang; - glyphs[glyph_pos].advance.setX(size.cx); - // if glyph's within cache range, store it for later - if (glyph < widthCacheSize && size.cx > 0 && size.cx < 0x100) - widthCache[glyph] = size.cx; - } - if (surrogate) - ++i; - ++glyph_pos; - } - SelectObject(hdc, oldFont); - } - return true; + // get the header of the unicode table +#ifndef Q_OS_TEMP + bytes = GetFontData(hdc, CMAP, unicode_table, &header, 8); +#endif + if (bytes == GDI_ERROR) + return 0; + unsigned short format = getUShort(header); + unsigned int length; + if(format < 8) + length = getUShort(header+2); + else + length = getUInt(header+4); + unsigned char *unicode_data = new unsigned char[length]; - return NoError; //!Qt4 + // get the cmap table itself +#ifndef Q_OS_TEMP + bytes = GetFontData(hdc, CMAP, unicode_table, unicode_data, length); +#endif + if (bytes == GDI_ERROR) { + delete [] unicode_data; + return 0; + } + return unicode_data; } -#endif \ No newline at end of file |