build system cleanups

Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
This commit is contained in:
Ivailo Monev 2016-09-14 18:32:32 +00:00
parent 3d814aefa6
commit 908678e114
11 changed files with 6 additions and 984 deletions

View file

@ -122,17 +122,6 @@ add_feature_info(opengles2 WITH_OPENGLES2 "an open source something")
option(WITH_ACCESSIBILITY "Build accessibility support" ON)
add_feature_info(accessibility WITH_ACCESSIBILITY "an open source something")
# windows
option(WITH_ICD "Build icd support (Windows)" ON)
add_feature_info(icd WITH_ICD "an closed source something")
option(WITH_DIRECTWRITE "Build DirectWrite support (Windows)" OFF)
add_feature_info(directwrite WITH_DIRECTWRITE "an closed source something")
# mac
option(WITH_COREWLAN "Build corewlan support (Mac)" ON)
add_feature_info(corewlan WITH_COREWLAN "an closed source something")
include(mkspecs/mkspecs.cmake)
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "C++ toolkit derived from the Qt 4.8 framework")
@ -144,20 +133,10 @@ set(CPACK_PACKAGE_VERSION_MAJOR ${KATIE_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${KATIE_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${KATIE_MICRO})
set(CPACK_PACKAGE_INSTALL_DIRECTORY "Katie")
set(CPACK_SOURCE_IGNORE_FILES "/build/;/mingw/;/.git;${CPACK_SOURCE_IGNORE_FILES}")
set(CPACK_SOURCE_IGNORE_FILES "/build/;/.git;${CPACK_SOURCE_IGNORE_FILES}")
set(CPACK_STRIP_FILES TRUE)
if(WIN32 AND CMAKE_CROSSCOMPILING)
# Windows build on non-Windows host, NSIS is not manditory on such
set(CPACK_GENERATOR "ZIP")
set(CPACK_SOURCE_GENERATOR "ZIP")
elseif(WIN32)
# native Windows build, let's make a NSIS package
set(CPACK_GENERATOR "ZIP;NSIS")
set(CPACK_SOURCE_GENERATOR "ZIP")
else()
set(CPACK_GENERATOR "TXZ")
set(CPACK_SOURCE_GENERATOR "TXZ")
endif()
set(CPACK_GENERATOR "TXZ")
set(CPACK_SOURCE_GENERATOR "TXZ")
include(CPack)
# 9 minutes timeout for the tests, Travis timeouts on 10min and I do not want
@ -535,16 +514,11 @@ if(NOT WITH_TIFF OR NOT TIFF_FOUND)
katie_definition(-DQT_NO_IMAGEFORMAT_TIFF)
endif()
# conditional features
if(NOT WITH_ACCESSIBILITY)
katie_definition(-DQT_NO_ACCESSIBILITY)
endif()
if(NOT WITH_DIRECTWRITE)
katie_definition(-DQT_NO_DIRECTWRITE)
endif()
if(WITH_OPENGLES1)
katie_definition(-DQT_OPENGL_ES_1)
endif()

View file

@ -1,23 +0,0 @@
# use like this: cmake . -DCMAKE_TOOLCHAIN_FILE=cmake/archlinux-mingw.cmake
set(CMAKE_SYSTEM_NAME Windows)
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "(x86_64|amd64)")
set(mingwtriplet "x86_64-w64-mingw32")
else()
set(mingwtriplet "i686-w64-mingw32")
endif()
# which compilers to use for C and C++
set(CMAKE_C_COMPILER ${mingwtriplet}-gcc)
set(CMAKE_CXX_COMPILER ${mingwtriplet}-g++)
set(CMAKE_RC_COMPILER ${mingwtriplet}-windres)
# here is the target environment located
set(CMAKE_FIND_ROOT_PATH /usr/${mingwtriplet})
# adjust the default behaviour of the FIND_XXX() commands:
# search headers and libraries in the target environment, search
# programs in the host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

View file

@ -1,22 +0,0 @@
# use like this: cmake . -DCMAKE_TOOLCHAIN_FILE=cmake/win32-mingw.cmake
set(mingwroot "C:/MinGW")
set(gnuwin32root "C:/Program Files/GnuWin32")
# which compilers to use for C and C++
set(CMAKE_C_COMPILER ${mingwroot}/bin/gcc.exe)
set(CMAKE_CXX_COMPILER ${mingwroot}/bin/g++.exe)
set(CMAKE_RC_COMPILER ${mingwroot}/bin/windres.exe)
# here is the target environment located
set(CMAKE_FIND_ROOT_PATH "${mingwroot}" "${gnuwin32root}")
# ensure that libraries and headers from MinGW and GnuWin32 can be found
set(CMAKE_LIBRARY_PATH "${CMAKE_LIBRARY_PATH}" "${mingwroot}/bin" "${gnuwin32root}/bin")
set(CMAKE_INCLUDE_PATH "${CMAKE_INCLUDE_PATH}" "${mingwroot}/include" "${gnuwin32root}/include")
# adjust the default behaviour of the FIND_XXX() commands:
# search headers and libraries in the target environment, search
# programs in the host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

View file

@ -74,6 +74,7 @@
#define QT_NO_QWS_TRANSFORMED
#define QT_NO_QWS_VNC
#define QT_NO_AUDIO_BACKEND
#define QT_NO_DIRECTWRITE
/* Qt build specs */
#ifndef QT_EDITION

View file

@ -915,37 +915,13 @@ int QFont::pointSize() const
\o PreferVerticalHinting
\o PreferFullHinting
\row
\o Windows Vista (w/o Platform Update) and earlier
\o Full hinting
\o Full hinting
\o Full hinting
\o Full hinting
\row
\o Windows 7 and Windows Vista (w/Platform Update) and DirectWrite enabled in Qt
\o Full hinting
\o Vertical hinting
\o Vertical hinting
\o Full hinting
\row
\o FreeType
\o Operating System setting
\o No hinting
\o Vertical hinting (light)
\o Full hinting
\row
\o Cocoa on Mac OS X
\o No hinting
\o No hinting
\o No hinting
\o No hinting
\endtable
\note Please be aware that altering the hinting preference on Windows is available through
the DirectWrite font engine. This is available on Windows Vista after installing the platform
update, and on Windows 7. In order to use this extension, configure Qt using -directwrite.
The target application will then depend on the availability of DirectWrite on the target
system.
*/
/*!

View file

@ -71,10 +71,6 @@
# define FM_DEBUG if (false) qDebug
#endif
#if defined(Q_WS_WIN) && !defined(QT_NO_DIRECTWRITE)
# include <dwrite.h>
#endif
QT_BEGIN_NAMESPACE
#define SMOOTH_SCALABLE 0xffff
@ -586,20 +582,10 @@ class QFontDatabasePrivate
public:
QFontDatabasePrivate()
: count(0), families(0), reregisterAppFonts(false)
#if defined(Q_WS_WIN) && !defined(QT_NO_DIRECTWRITE)
, directWriteFactory(0)
, directWriteGdiInterop(0)
#endif
{ }
~QFontDatabasePrivate() {
free();
#if defined(Q_WS_WIN) && !defined(QT_NO_DIRECTWRITE)
if (directWriteGdiInterop)
directWriteGdiInterop->Release();
if (directWriteFactory != 0)
directWriteFactory->Release();
#endif
}
QtFontFamily *family(const QString &f, bool = false);
void free() {
@ -617,22 +603,9 @@ public:
#endif
QtFontFamily **families;
#if defined(Q_WS_WIN) && !defined(QT_NO_DIRECTWRITE)
IDWriteFactory *directWriteFactory;
IDWriteGdiInterop *directWriteGdiInterop;
#endif
struct ApplicationFont {
QString fileName;
QByteArray data;
#if defined(Q_OS_WIN)
HANDLE handle;
bool memoryFont;
QVector<FONTSIGNATURE> signatures;
#elif defined(Q_WS_MAC)
ATSFontContainerRef handle;
#endif
QStringList families;
};
QVector<ApplicationFont> applicationFonts;

View file

@ -102,18 +102,10 @@ public:
// X11 types
XLFD,
// MS Windows types
Win,
// Apple Mac OS types
Mac,
// QWS types
Freetype,
Proxy,
DirectWrite,
TestFontEngine = 0x1000
};

View file

@ -1,697 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QT_NO_DIRECTWRITE
#include "qfontenginedirectwrite_p.h"
#include <qendian.h>
#include <dwrite.h>
#include <d2d1.h>
QT_BEGIN_NAMESPACE
// Convert from design units to logical pixels
#define DESIGN_TO_LOGICAL(DESIGN_UNIT_VALUE) \
QFixed::fromReal((qreal(DESIGN_UNIT_VALUE) / qreal(m_unitsPerEm)) * fontDef.pixelSize)
namespace {
class GeometrySink: public IDWriteGeometrySink
{
public:
GeometrySink(QPainterPath *path) : m_path(path), m_refCount(0)
{
Q_ASSERT(m_path != 0);
}
IFACEMETHOD_(void, AddBeziers)(const D2D1_BEZIER_SEGMENT *beziers, UINT bezierCount);
IFACEMETHOD_(void, AddLines)(const D2D1_POINT_2F *points, UINT pointCount);
IFACEMETHOD_(void, BeginFigure)(D2D1_POINT_2F startPoint, D2D1_FIGURE_BEGIN figureBegin);
IFACEMETHOD(Close)();
IFACEMETHOD_(void, EndFigure)(D2D1_FIGURE_END figureEnd);
IFACEMETHOD_(void, SetFillMode)(D2D1_FILL_MODE fillMode);
IFACEMETHOD_(void, SetSegmentFlags)(D2D1_PATH_SEGMENT vertexFlags);
IFACEMETHOD_(unsigned long, AddRef)();
IFACEMETHOD_(unsigned long, Release)();
IFACEMETHOD(QueryInterface)(IID const &riid, void **ppvObject);
private:
inline static QPointF fromD2D1_POINT_2F(const D2D1_POINT_2F &inp)
{
return QPointF(inp.x, inp.y);
}
unsigned long m_refCount;
QPointF m_startPoint;
QPainterPath *m_path;
};
void GeometrySink::AddBeziers(const D2D1_BEZIER_SEGMENT *beziers,
UINT bezierCount)
{
for (uint i=0; i<bezierCount; ++i) {
QPointF c1 = fromD2D1_POINT_2F(beziers[i].point1);
QPointF c2 = fromD2D1_POINT_2F(beziers[i].point2);
QPointF p2 = fromD2D1_POINT_2F(beziers[i].point3);
m_path->cubicTo(c1, c2, p2);
}
}
void GeometrySink::AddLines(const D2D1_POINT_2F *points, UINT pointsCount)
{
for (uint i=0; i<pointsCount; ++i)
m_path->lineTo(fromD2D1_POINT_2F(points[i]));
}
void GeometrySink::BeginFigure(D2D1_POINT_2F startPoint,
D2D1_FIGURE_BEGIN /*figureBegin*/)
{
m_startPoint = fromD2D1_POINT_2F(startPoint);
m_path->moveTo(m_startPoint);
}
IFACEMETHODIMP GeometrySink::Close()
{
return E_NOTIMPL;
}
void GeometrySink::EndFigure(D2D1_FIGURE_END figureEnd)
{
if (figureEnd == D2D1_FIGURE_END_CLOSED)
m_path->closeSubpath();
}
void GeometrySink::SetFillMode(D2D1_FILL_MODE fillMode)
{
m_path->setFillRule(fillMode == D2D1_FILL_MODE_ALTERNATE
? Qt::OddEvenFill
: Qt::WindingFill);
}
void GeometrySink::SetSegmentFlags(D2D1_PATH_SEGMENT /*vertexFlags*/)
{
/* Not implemented */
}
IFACEMETHODIMP_(unsigned long) GeometrySink::AddRef()
{
return InterlockedIncrement(&m_refCount);
}
IFACEMETHODIMP_(unsigned long) GeometrySink::Release()
{
unsigned long newCount = InterlockedDecrement(&m_refCount);
if (newCount == 0)
{
delete this;
return 0;
}
return newCount;
}
IFACEMETHODIMP GeometrySink::QueryInterface(IID const &riid, void **ppvObject)
{
if (__uuidof(IDWriteGeometrySink) == riid) {
*ppvObject = this;
} else if (__uuidof(IUnknown) == riid) {
*ppvObject = this;
} else {
*ppvObject = NULL;
return E_FAIL;
}
AddRef();
return S_OK;
}
}
QFontEngineDirectWrite::QFontEngineDirectWrite(IDWriteFactory *directWriteFactory,
IDWriteFontFace *directWriteFontFace,
qreal pixelSize)
: m_directWriteFontFace(directWriteFontFace)
, m_directWriteFactory(directWriteFactory)
, m_directWriteBitmapRenderTarget(0)
, m_lineThickness(-1)
, m_unitsPerEm(-1)
, m_ascent(-1)
, m_descent(-1)
, m_xHeight(-1)
, m_lineGap(-1)
{
m_directWriteFactory->AddRef();
m_directWriteFontFace->AddRef();
fontDef.pixelSize = pixelSize;
collectMetrics();
}
QFontEngineDirectWrite::~QFontEngineDirectWrite()
{
m_directWriteFactory->Release();
m_directWriteFontFace->Release();
if (m_directWriteBitmapRenderTarget != 0)
m_directWriteBitmapRenderTarget->Release();
}
void QFontEngineDirectWrite::collectMetrics()
{
if (m_directWriteFontFace != 0) {
DWRITE_FONT_METRICS metrics;
m_directWriteFontFace->GetMetrics(&metrics);
m_unitsPerEm = metrics.designUnitsPerEm;
m_lineThickness = DESIGN_TO_LOGICAL(metrics.underlineThickness);
m_ascent = DESIGN_TO_LOGICAL(metrics.ascent);
m_descent = DESIGN_TO_LOGICAL(metrics.descent);
m_xHeight = DESIGN_TO_LOGICAL(metrics.xHeight);
m_lineGap = DESIGN_TO_LOGICAL(metrics.lineGap);
}
}
QFixed QFontEngineDirectWrite::lineThickness() const
{
if (m_lineThickness > 0)
return m_lineThickness;
else
return QFontEngine::lineThickness();
}
bool QFontEngineDirectWrite::getSfntTableData(uint tag, uchar *buffer, uint *length) const
{
if (m_directWriteFontFace) {
DWORD t = qbswap<quint32>(tag);
const void *tableData = 0;
void *tableContext = 0;
UINT32 tableSize;
BOOL exists;
HRESULT hr = m_directWriteFontFace->TryGetFontTable(
t, &tableData, &tableSize, &tableContext, &exists
);
if (SUCCEEDED(hr)) {
if (!exists)
return false;
if (buffer == 0) {
*length = tableSize;
return true;
} else if (*length < tableSize) {
return false;
}
memcpy(buffer, tableData, tableSize);
m_directWriteFontFace->ReleaseFontTable(tableContext);
return true;
} else {
qErrnoWarning("QFontEngineDirectWrite::getSfntTableData: TryGetFontTable failed");
}
}
return false;
}
QFixed QFontEngineDirectWrite::emSquareSize() const
{
if (m_unitsPerEm > 0)
return m_unitsPerEm;
else
return QFontEngine::emSquareSize();
}
inline unsigned int getChar(const QChar *str, int &i, const int len)
{
uint ucs4 = str[i].unicode();
if (str[i].isHighSurrogate() && i < len-1 && str[i+1].isLowSurrogate()) {
++i;
ucs4 = QChar::surrogateToUcs4( ucs4, str[i].unicode());
}
return ucs4;
}
bool QFontEngineDirectWrite::stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs,
int *nglyphs, QTextEngine::ShaperFlags flags) const
{
if (m_directWriteFontFace != 0) {
QVarLengthArray<UINT32> codePoints(len);
for (int i=0; i<len; ++i) {
codePoints[i] = getChar(str, i, len);
if (flags & QTextEngine::RightToLeft)
codePoints[i] = QChar::mirroredChar(codePoints[i]);
}
QVarLengthArray<UINT16> glyphIndices(len);
HRESULT hr = m_directWriteFontFace->GetGlyphIndicesW(codePoints.data(),
len,
glyphIndices.data());
if (SUCCEEDED(hr)) {
for (int i=0; i<len; ++i)
glyphs->glyphs[i] = glyphIndices[i];
*nglyphs = len;
if (!(flags & QTextEngine::GlyphIndicesOnly))
recalcAdvances(glyphs, 0);
return true;
} else {
qErrnoWarning("QFontEngineDirectWrite::stringToCMap: GetGlyphIndicesW failed");
}
}
return false;
}
void QFontEngineDirectWrite::recalcAdvances(QGlyphLayout *glyphs, QTextEngine::ShaperFlags) const
{
if (m_directWriteFontFace == 0)
return;
QVarLengthArray<UINT16> glyphIndices(glyphs->numGlyphs);
// ### Caching?
for(int i=0; i<glyphs->numGlyphs; i++)
glyphIndices[i] = UINT16(glyphs->glyphs[i]);
QVarLengthArray<DWRITE_GLYPH_METRICS> glyphMetrics(glyphIndices.size());
HRESULT hr = m_directWriteFontFace->GetDesignGlyphMetrics(glyphIndices.data(),
glyphIndices.size(),
glyphMetrics.data());
if (SUCCEEDED(hr)) {
for (int i=0; i<glyphs->numGlyphs; ++i) {
glyphs->advances_x[i] = DESIGN_TO_LOGICAL(glyphMetrics[i].advanceWidth);
if (fontDef.styleStrategy & QFont::ForceIntegerMetrics)
glyphs->advances_x[i] = glyphs->advances_x[i].round();
glyphs->advances_y[i] = 0;
}
} else {
qErrnoWarning("QFontEngineDirectWrite::recalcAdvances: GetDesignGlyphMetrics failed");
}
}
void QFontEngineDirectWrite::addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions, int nglyphs,
QPainterPath *path, QTextItem::RenderFlags flags)
{
if (m_directWriteFontFace == 0)
return;
QVarLengthArray<UINT16> glyphIndices(nglyphs);
QVarLengthArray<DWRITE_GLYPH_OFFSET> glyphOffsets(nglyphs);
QVarLengthArray<FLOAT> glyphAdvances(nglyphs);
for (int i=0; i<nglyphs; ++i) {
glyphIndices[i] = glyphs[i];
glyphOffsets[i].advanceOffset = positions[i].x.toReal();
glyphOffsets[i].ascenderOffset = -positions[i].y.toReal();
glyphAdvances[i] = 0.0;
}
GeometrySink geometrySink(path);
HRESULT hr = m_directWriteFontFace->GetGlyphRunOutline(
fontDef.pixelSize,
glyphIndices.data(),
glyphAdvances.data(),
glyphOffsets.data(),
nglyphs,
false,
flags & QTextItem::RightToLeft,
&geometrySink
);
if (FAILED(hr))
qErrnoWarning("QFontEngineDirectWrite::addGlyphsToPath: GetGlyphRunOutline failed");
}
glyph_metrics_t QFontEngineDirectWrite::boundingBox(const QGlyphLayout &glyphs)
{
if (glyphs.numGlyphs == 0)
return glyph_metrics_t();
bool round = fontDef.styleStrategy & QFont::ForceIntegerMetrics;
QFixed w = 0;
for (int i = 0; i < glyphs.numGlyphs; ++i) {
w += round ? glyphs.effectiveAdvance(i).round() : glyphs.effectiveAdvance(i);
}
return glyph_metrics_t(0, -m_ascent, w - lastRightBearing(glyphs), m_ascent + m_descent, w, 0);
}
glyph_metrics_t QFontEngineDirectWrite::alphaMapBoundingBox(glyph_t glyph, QFixed subPixelPosition,
const QTransform &matrix,
GlyphFormat /*format*/)
{
glyph_metrics_t bbox = QFontEngine::boundingBox(glyph, matrix); // To get transformed advance
UINT16 glyphIndex = glyph;
FLOAT glyphAdvance = 0;
DWRITE_GLYPH_OFFSET glyphOffset;
glyphOffset.advanceOffset = 0;
glyphOffset.ascenderOffset = 0;
DWRITE_GLYPH_RUN glyphRun;
glyphRun.fontFace = m_directWriteFontFace;
glyphRun.fontEmSize = fontDef.pixelSize;
glyphRun.glyphCount = 1;
glyphRun.glyphIndices = &glyphIndex;
glyphRun.glyphAdvances = &glyphAdvance;
glyphRun.isSideways = false;
glyphRun.bidiLevel = 0;
glyphRun.glyphOffsets = &glyphOffset;
DWRITE_MATRIX transform;
transform.dx = subPixelPosition.toReal();
transform.dy = 0;
transform.m11 = matrix.m11();
transform.m12 = matrix.m12();
transform.m21 = matrix.m21();
transform.m22 = matrix.m22();
IDWriteGlyphRunAnalysis *glyphAnalysis = NULL;
HRESULT hr = m_directWriteFactory->CreateGlyphRunAnalysis(
&glyphRun,
1.0f,
&transform,
DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC,
DWRITE_MEASURING_MODE_NATURAL,
0.0, 0.0,
&glyphAnalysis
);
if (SUCCEEDED(hr)) {
RECT rect;
glyphAnalysis->GetAlphaTextureBounds(DWRITE_TEXTURE_CLEARTYPE_3x1, &rect);
glyphAnalysis->Release();
return glyph_metrics_t(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
bbox.xoff, bbox.yoff);
} else {
return glyph_metrics_t();
}
}
glyph_metrics_t QFontEngineDirectWrite::boundingBox(glyph_t g)
{
if (m_directWriteFontFace == 0)
return glyph_metrics_t();
UINT16 glyphIndex = g;
DWRITE_GLYPH_METRICS glyphMetrics;
HRESULT hr = m_directWriteFontFace->GetDesignGlyphMetrics(&glyphIndex, 1, &glyphMetrics);
if (SUCCEEDED(hr)) {
QFixed advanceWidth = DESIGN_TO_LOGICAL(glyphMetrics.advanceWidth);
QFixed leftSideBearing = DESIGN_TO_LOGICAL(glyphMetrics.leftSideBearing);
QFixed rightSideBearing = DESIGN_TO_LOGICAL(glyphMetrics.rightSideBearing);
QFixed advanceHeight = DESIGN_TO_LOGICAL(glyphMetrics.advanceHeight);
QFixed verticalOriginY = DESIGN_TO_LOGICAL(glyphMetrics.verticalOriginY);
if (fontDef.styleStrategy & QFont::ForceIntegerMetrics) {
advanceWidth = advanceWidth.round();
advanceHeight = advanceHeight.round();
}
QFixed width = advanceWidth - leftSideBearing - rightSideBearing;
return glyph_metrics_t(-leftSideBearing, -verticalOriginY,
width, m_ascent + m_descent,
advanceWidth, advanceHeight);
} else {
qErrnoWarning("QFontEngineDirectWrite::boundingBox: GetDesignGlyphMetrics failed");
}
return glyph_metrics_t();
}
QFixed QFontEngineDirectWrite::ascent() const
{
return fontDef.styleStrategy & QFont::ForceIntegerMetrics
? m_ascent.round()
: m_ascent;
}
QFixed QFontEngineDirectWrite::descent() const
{
return fontDef.styleStrategy & QFont::ForceIntegerMetrics
? (m_descent - 1).round()
: (m_descent - 1);
}
QFixed QFontEngineDirectWrite::leading() const
{
return fontDef.styleStrategy & QFont::ForceIntegerMetrics
? m_lineGap.round()
: m_lineGap;
}
QFixed QFontEngineDirectWrite::xHeight() const
{
return fontDef.styleStrategy & QFont::ForceIntegerMetrics
? m_xHeight.round()
: m_xHeight;
}
qreal QFontEngineDirectWrite::maxCharWidth() const
{
// ###
return 0;
}
extern uint qt_pow_gamma[256];
QImage QFontEngineDirectWrite::alphaMapForGlyph(glyph_t glyph, QFixed subPixelPosition,
const QTransform &xform)
{
QImage im = imageForGlyph(glyph, subPixelPosition, 0, xform);
QImage indexed(im.width(), im.height(), QImage::Format_Indexed8);
QVector<QRgb> colors(256);
for (int i=0; i<256; ++i)
colors[i] = qRgba(0, 0, 0, i);
indexed.setColorTable(colors);
for (int y=0; y<im.height(); ++y) {
uint *src = (uint*) im.scanLine(y);
uchar *dst = indexed.scanLine(y);
for (int x=0; x<im.width(); ++x) {
*dst = 255 - (qt_pow_gamma[qGray(0xffffffff - *src)] * 255. / 2047.);
++dst;
++src;
}
}
return indexed;
}
bool QFontEngineDirectWrite::supportsSubPixelPositions() const
{
return true;
}
QImage QFontEngineDirectWrite::imageForGlyph(glyph_t t,
QFixed subPixelPosition,
int margin,
const QTransform &xform)
{
UINT16 glyphIndex = t;
FLOAT glyphAdvance = 0;
DWRITE_GLYPH_OFFSET glyphOffset;
glyphOffset.advanceOffset = 0;
glyphOffset.ascenderOffset = 0;
DWRITE_GLYPH_RUN glyphRun;
glyphRun.fontFace = m_directWriteFontFace;
glyphRun.fontEmSize = fontDef.pixelSize;
glyphRun.glyphCount = 1;
glyphRun.glyphIndices = &glyphIndex;
glyphRun.glyphAdvances = &glyphAdvance;
glyphRun.isSideways = false;
glyphRun.bidiLevel = 0;
glyphRun.glyphOffsets = &glyphOffset;
DWRITE_MATRIX transform;
transform.dx = subPixelPosition.toReal();
transform.dy = 0;
transform.m11 = xform.m11();
transform.m12 = xform.m12();
transform.m21 = xform.m21();
transform.m22 = xform.m22();
IDWriteGlyphRunAnalysis *glyphAnalysis = NULL;
HRESULT hr = m_directWriteFactory->CreateGlyphRunAnalysis(
&glyphRun,
1.0f,
&transform,
DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC,
DWRITE_MEASURING_MODE_NATURAL,
0.0, 0.0,
&glyphAnalysis
);
if (SUCCEEDED(hr)) {
RECT rect;
glyphAnalysis->GetAlphaTextureBounds(DWRITE_TEXTURE_CLEARTYPE_3x1, &rect);
rect.left -= margin;
rect.top -= margin;
rect.right += margin;
rect.bottom += margin;
int width = rect.right - rect.left;
int height = rect.bottom - rect.top;
int size = width * height * 3;
if (size > 0) {
BYTE *alphaValues = new BYTE[size];
memset(alphaValues, size, 0);
hr = glyphAnalysis->CreateAlphaTexture(DWRITE_TEXTURE_CLEARTYPE_3x1,
&rect,
alphaValues,
size);
if (SUCCEEDED(hr)) {
QImage img(width, height, QImage::Format_RGB32);
img.fill(0xffffffff);
for (int y=0; y<height; ++y) {
uint *dest = reinterpret_cast<uint *>(img.scanLine(y));
BYTE *src = alphaValues + width * 3 * y;
for (int x=0; x<width; ++x) {
dest[x] = *(src) << 16
| *(src + 1) << 8
| *(src + 2);
src += 3;
}
}
delete[] alphaValues;
glyphAnalysis->Release();
return img;
} else {
delete[] alphaValues;
glyphAnalysis->Release();
qErrnoWarning("QFontEngineDirectWrite::imageForGlyph: CreateAlphaTexture failed");
}
}
} else {
qErrnoWarning("QFontEngineDirectWrite::imageForGlyph: CreateGlyphRunAnalysis failed");
}
return QImage();
}
QImage QFontEngineDirectWrite::alphaRGBMapForGlyph(glyph_t t,
QFixed subPixelPosition,
int margin,
const QTransform &xform)
{
QImage mask = imageForGlyph(t, subPixelPosition, margin, xform);
return mask.depth() == 32
? mask
: mask.convertToFormat(QImage::Format_RGB32);
}
const char *QFontEngineDirectWrite::name() const
{
return 0;
}
bool QFontEngineDirectWrite::canRender(const QChar *string, int len)
{
QVarLengthArray<UINT32> codePoints(len);
int actualLength = 0;
for (int i=0; i<len; ++i, actualLength++)
codePoints[actualLength] = getChar(string, i, len);
QVarLengthArray<UINT16> glyphIndices(actualLength);
HRESULT hr = m_directWriteFontFace->GetGlyphIndices(codePoints.data(), actualLength,
glyphIndices.data());
if (FAILED(hr)) {
qErrnoWarning(hr, "QFontEngineDirectWrite::canRender: GetGlyphIndices failed");
return false;
} else {
for (int i=0; i<glyphIndices.size(); ++i) {
if (glyphIndices.at(i) == 0)
return false;
}
return true;
}
}
QFontEngine::Type QFontEngineDirectWrite::type() const
{
return QFontEngine::DirectWrite;
}
QFontEngine *QFontEngineDirectWrite::cloneWithSize(qreal pixelSize) const
{
QFontEngine *fontEngine = new QFontEngineDirectWrite(m_directWriteFactory, m_directWriteFontFace,
pixelSize);
fontEngine->fontDef = fontDef;
fontEngine->fontDef.pixelSize = pixelSize;
return fontEngine;
}
QT_END_NAMESPACE
#endif // QT_NO_DIRECTWRITE
#include <moc_qfontenginedirectwrite_p.h>

View file

@ -1,136 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QFONTENGINEDIRECTWRITE_H
#define QFONTENGINEDIRECTWRITE_H
#ifndef QT_NO_DIRECTWRITE
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
#include "qfontengine_p.h"
struct IDWriteFont ;
struct IDWriteFontFace ;
struct IDWriteFactory ;
struct IDWriteBitmapRenderTarget ;
struct IDWriteGdiInterop ;
QT_BEGIN_NAMESPACE
class QFontEngineDirectWrite : public QFontEngine
{
Q_OBJECT
public:
explicit QFontEngineDirectWrite(IDWriteFactory *directWriteFactory,
IDWriteFontFace *directWriteFontFace,
qreal pixelSize);
~QFontEngineDirectWrite();
QFixed lineThickness() const;
bool getSfntTableData(uint tag, uchar *buffer, uint *length) const;
QFixed emSquareSize() const;
bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const;
void recalcAdvances(QGlyphLayout *glyphs, QTextEngine::ShaperFlags) const;
void addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions, int nglyphs,
QPainterPath *path, QTextItem::RenderFlags flags);
glyph_metrics_t boundingBox(const QGlyphLayout &glyphs);
glyph_metrics_t boundingBox(glyph_t g);
glyph_metrics_t alphaMapBoundingBox(glyph_t glyph,
QFixed subPixelPosition,
const QTransform &matrix,
GlyphFormat format);
QFixed ascent() const;
QFixed descent() const;
QFixed leading() const;
QFixed xHeight() const;
qreal maxCharWidth() const;
const char *name() const;
bool supportsSubPixelPositions() const;
QImage alphaMapForGlyph(glyph_t, QFixed subPixelPosition, const QTransform &t);
QImage alphaRGBMapForGlyph(glyph_t t, QFixed subPixelPosition, int margin,
const QTransform &xform);
QFontEngine *cloneWithSize(qreal pixelSize) const;
bool canRender(const QChar *string, int len);
Type type() const;
private:
friend class QRawFontPrivate;
QImage imageForGlyph(glyph_t t, QFixed subPixelPosition, int margin, const QTransform &xform);
void collectMetrics();
IDWriteFontFace *m_directWriteFontFace;
IDWriteFactory *m_directWriteFactory;
IDWriteBitmapRenderTarget *m_directWriteBitmapRenderTarget;
QFixed m_lineThickness;
int m_unitsPerEm;
QFixed m_ascent;
QFixed m_descent;
QFixed m_xHeight;
QFixed m_lineGap;
FaceId m_faceId;
};
QT_END_NAMESPACE
#endif // QT_NO_DIRECTWRITE
#endif // QFONTENGINEDIRECTWRITE_H

View file

@ -80,9 +80,8 @@ QT_BEGIN_NAMESPACE
combination with the QGlyphRun class to draw specific glyph indexes at specific positions, and
also have accessors to some relevant data in the physical font.
QRawFont only provides support for the main font technologies: GDI and DirectWrite on Windows
platforms, FreeType on Symbian and Linux platforms and CoreText on Mac OS X. For other
font back-ends, the APIs will be disabled.
QRawFont only provides support for the main font technologies: FreeType on UNIX platforms. For
other font back-ends, the APIs will be disabled.
QRawFont can be constructed in a number of ways:
\list

View file

@ -110,21 +110,6 @@ if(WITH_FONTCONFIG AND FONTCONFIG_FOUND)
add_definitions(${FONTCONFIG_DEFINITIONS})
endif()
if(WITH_DIRECTWRITE)
set(GUI_HEADERS
${GUI_HEADERS}
${CMAKE_CURRENT_SOURCE_DIR}/text/qfontenginedirectwrite_p.h
)
set(GUI_SOURCES
${GUI_SOURCES}
${CMAKE_CURRENT_SOURCE_DIR}/text/qfontenginedirectwrite.cpp
)
set(EXTRA_GUI_LIBS
${EXTRA_GUI_LIBS}
dwrite
)
endif()
if(WITH_X11 AND X11_FOUND)
set(GUI_HEADERS
${GUI_HEADERS}