Fix font printing on Windows using the native engine.
- Add HFONT, LOGFONT, trueType as properties of the Windows font engine, make it a real Q_OBJECT. - Query properties in the Windows print engine and use the HFONT, LOGFONT there. Change-Id: I5c35275b32ef6580d7fa15ed83c6e79e33dc3334 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
This commit is contained in:
parent
c241d8921e
commit
8b4bf5f816
@ -1115,6 +1115,12 @@ void QWindowsFontDatabase::populate(const QString &family)
|
|||||||
QWindowsFontDatabase::QWindowsFontDatabase() :
|
QWindowsFontDatabase::QWindowsFontDatabase() :
|
||||||
m_fontEngineData(new QWindowsFontEngineData)
|
m_fontEngineData(new QWindowsFontEngineData)
|
||||||
{
|
{
|
||||||
|
// Properties accessed by QWin32PrintEngine (QtPrintSupport)
|
||||||
|
static const int hfontMetaTypeId = qRegisterMetaType<HFONT>();
|
||||||
|
static const int logFontMetaTypeId = qRegisterMetaType<LOGFONT>();
|
||||||
|
Q_UNUSED(hfontMetaTypeId)
|
||||||
|
Q_UNUSED(logFontMetaTypeId)
|
||||||
|
|
||||||
if (QWindowsContext::verboseFonts)
|
if (QWindowsContext::verboseFonts)
|
||||||
qDebug() << __FUNCTION__ << "Clear type: "
|
qDebug() << __FUNCTION__ << "Clear type: "
|
||||||
<< m_fontEngineData->clearTypeEnabled << "gamma: "
|
<< m_fontEngineData->clearTypeEnabled << "gamma: "
|
||||||
|
@ -283,7 +283,7 @@ int QWindowsFontEngine::getGlyphIndexes(const QChar *str, int numChars, QGlyphLa
|
|||||||
|
|
||||||
QWindowsFontEngine::QWindowsFontEngine(const QString &name,
|
QWindowsFontEngine::QWindowsFontEngine(const QString &name,
|
||||||
HFONT _hfont, bool stockFontIn, LOGFONT lf,
|
HFONT _hfont, bool stockFontIn, LOGFONT lf,
|
||||||
QSharedPointer<QWindowsFontEngineData> fontEngineData) :
|
const QSharedPointer<QWindowsFontEngineData> &fontEngineData) :
|
||||||
m_fontEngineData(fontEngineData),
|
m_fontEngineData(fontEngineData),
|
||||||
_name(name),
|
_name(name),
|
||||||
hfont(_hfont),
|
hfont(_hfont),
|
||||||
@ -1318,7 +1318,7 @@ void QWindowsMultiFontEngine::loadEngine(int at)
|
|||||||
|
|
||||||
const QString fam = fallbacks.at(at-1);
|
const QString fam = fallbacks.at(at-1);
|
||||||
QWindowsFontEngine *fe = static_cast<QWindowsFontEngine*>(engines.at(0));
|
QWindowsFontEngine *fe = static_cast<QWindowsFontEngine*>(engines.at(0));
|
||||||
LOGFONT lf = fe->logfont();
|
LOGFONT lf = fe->logFont();
|
||||||
memcpy(lf.lfFaceName, fam.utf16(), sizeof(wchar_t) * qMin(fam.length() + 1, 32)); // 32 = Windows hard-coded
|
memcpy(lf.lfFaceName, fam.utf16(), sizeof(wchar_t) * qMin(fam.length() + 1, 32)); // 32 = Windows hard-coded
|
||||||
HFONT hfont = CreateFontIndirect(&lf);
|
HFONT hfont = CreateFontIndirect(&lf);
|
||||||
|
|
||||||
|
@ -57,6 +57,7 @@
|
|||||||
|
|
||||||
#include <QtGui/QImage>
|
#include <QtGui/QImage>
|
||||||
#include <QtCore/QSharedPointer>
|
#include <QtCore/QSharedPointer>
|
||||||
|
#include <QtCore/QMetaType>
|
||||||
|
|
||||||
#include "qtwindows_additional.h"
|
#include "qtwindows_additional.h"
|
||||||
|
|
||||||
@ -67,10 +68,14 @@ class QWindowsFontEngineData;
|
|||||||
|
|
||||||
class QWindowsFontEngine : public QFontEngine
|
class QWindowsFontEngine : public QFontEngine
|
||||||
{
|
{
|
||||||
Q_DISABLE_COPY(QWindowsFontEngine)
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(HFONT hFont READ hFont STORED false)
|
||||||
|
Q_PROPERTY(LOGFONT logFont READ logFont STORED false)
|
||||||
|
Q_PROPERTY(bool trueType READ trueType STORED false)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QWindowsFontEngine(const QString &name, HFONT, bool, LOGFONT,
|
QWindowsFontEngine(const QString &name, HFONT, bool, LOGFONT,
|
||||||
QSharedPointer<QWindowsFontEngineData> fontEngineData);
|
const QSharedPointer<QWindowsFontEngineData> &fontEngineData);
|
||||||
|
|
||||||
~QWindowsFontEngine();
|
~QWindowsFontEngine();
|
||||||
void initFontInfo(const QFontDef &request,
|
void initFontInfo(const QFontDef &request,
|
||||||
@ -128,8 +133,13 @@ public:
|
|||||||
|
|
||||||
bool getOutlineMetrics(glyph_t glyph, const QTransform &t, glyph_metrics_t *metrics) const;
|
bool getOutlineMetrics(glyph_t glyph, const QTransform &t, glyph_metrics_t *metrics) const;
|
||||||
|
|
||||||
QSharedPointer<QWindowsFontEngineData> fontEngineData() const { return m_fontEngineData; }
|
const QSharedPointer<QWindowsFontEngineData> &fontEngineData() const { return m_fontEngineData; }
|
||||||
LOGFONT logfont() const { return m_logfont; }
|
|
||||||
|
// Properties accessed by QWin32PrintEngine (QtPrintSupport)
|
||||||
|
LOGFONT logFont() const { return m_logfont; }
|
||||||
|
HFONT hFont() const { return hfont; }
|
||||||
|
bool trueType() const { return ttf; }
|
||||||
|
|
||||||
void setUniqueFamilyName(const QString &newName) { uniqueFamilyName = newName; }
|
void setUniqueFamilyName(const QString &newName) { uniqueFamilyName = newName; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -176,5 +186,8 @@ public:
|
|||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(HFONT)
|
||||||
|
Q_DECLARE_METATYPE(LOGFONT)
|
||||||
|
|
||||||
#endif // QWINDOWSFONTENGINE_H
|
#endif // QWINDOWSFONTENGINE_H
|
||||||
|
|
||||||
|
@ -57,6 +57,11 @@
|
|||||||
#include <qpa/qplatformpixmap.h>
|
#include <qpa/qplatformpixmap.h>
|
||||||
#include <private/qpicture_p.h>
|
#include <private/qpicture_p.h>
|
||||||
#include <private/qpixmap_raster_p.h>
|
#include <private/qpixmap_raster_p.h>
|
||||||
|
#include <QtCore/QMetaType>
|
||||||
|
#include <QtCore/qt_windows.h>
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(HFONT)
|
||||||
|
Q_DECLARE_METATYPE(LOGFONT)
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
@ -349,22 +354,22 @@ void QWin32PrintEngine::drawTextItem(const QPointF &p, const QTextItem &textItem
|
|||||||
|| d->txop >= QTransform::TxProject
|
|| d->txop >= QTransform::TxProject
|
||||||
|| ti.fontEngine->type() != QFontEngine::Win;
|
|| ti.fontEngine->type() != QFontEngine::Win;
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
if (!fallBack) {
|
if (!fallBack) {
|
||||||
QFontEngineWin *fe = static_cast<QFontEngineWin *>(ti.fontEngine);
|
const QVariant hFontV = ti.fontEngine->property("hFont");
|
||||||
|
const QVariant logFontV = ti.fontEngine->property("logFont");
|
||||||
|
if (hFontV.canConvert<HFONT>() && logFontV.canConvert<LOGFONT>()) {
|
||||||
|
const HFONT hfont = hFontV.value<HFONT>();
|
||||||
|
const LOGFONT logFont = logFontV.value<LOGFONT>();
|
||||||
// Try selecting the font to see if we get a substitution font
|
// Try selecting the font to see if we get a substitution font
|
||||||
SelectObject(d->hdc, fe->hfont);
|
SelectObject(d->hdc, hfont);
|
||||||
|
|
||||||
if (GetDeviceCaps(d->hdc, TECHNOLOGY) != DT_CHARSTREAM) {
|
if (GetDeviceCaps(d->hdc, TECHNOLOGY) != DT_CHARSTREAM) {
|
||||||
wchar_t n[64];
|
wchar_t n[64];
|
||||||
GetTextFace(d->hdc, 64, n);
|
GetTextFace(d->hdc, 64, n);
|
||||||
fallBack = QString::fromWCharArray(n)
|
fallBack = QString::fromWCharArray(n)
|
||||||
!= QString::fromWCharArray(fe->logfont.lfFaceName);
|
!= QString::fromWCharArray(logFont.lfFaceName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
if (fallBack) {
|
if (fallBack) {
|
||||||
@ -1680,19 +1685,22 @@ static void draw_text_item_win(const QPointF &pos, const QTextItemInt &ti, HDC h
|
|||||||
SetTextAlign(hdc, TA_BASELINE);
|
SetTextAlign(hdc, TA_BASELINE);
|
||||||
SetBkMode(hdc, TRANSPARENT);
|
SetBkMode(hdc, TRANSPARENT);
|
||||||
|
|
||||||
bool has_kerning = ti.f && ti.f->kerning();
|
const bool has_kerning = ti.f && ti.f->kerning();
|
||||||
// ### TODO
|
|
||||||
// QFontEngineWin *winfe = (fe->type() == QFontEngine::Win) ? static_cast<QFontEngineWin *>(fe) : 0;
|
|
||||||
|
|
||||||
HFONT hfont;
|
HFONT hfont = 0;
|
||||||
bool ttf = false;
|
bool ttf = false;
|
||||||
|
|
||||||
// if (winfe) {
|
if (ti.fontEngine->type() == QFontEngine::Win) {
|
||||||
// hfont = winfe->hfont;
|
const QVariant hfontV = ti.fontEngine->property("hFont");
|
||||||
// ttf = winfe->ttf;
|
const QVariant ttfV = ti.fontEngine->property("trueType");
|
||||||
// } else {
|
if (ttfV.type() == QVariant::Bool && hfontV.canConvert<HFONT>()) {
|
||||||
|
hfont = hfontV.value<HFONT>();
|
||||||
|
ttf = ttfV.toBool();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hfont)
|
||||||
hfont = (HFONT)GetStockObject(ANSI_VAR_FONT);
|
hfont = (HFONT)GetStockObject(ANSI_VAR_FONT);
|
||||||
// }
|
|
||||||
|
|
||||||
HGDIOBJ old_font = SelectObject(hdc, hfont);
|
HGDIOBJ old_font = SelectObject(hdc, hfont);
|
||||||
unsigned int options = (ttf && !convertToText) ? ETO_GLYPH_INDEX : 0;
|
unsigned int options = (ttf && !convertToText) ? ETO_GLYPH_INDEX : 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user