summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qfontenginedirectwrite.cpp
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2011-03-22 10:57:59 +0100
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2011-04-19 09:59:46 +0200
commit47819dc7257c60e0feb1d02177622593ec0c2d15 (patch)
treed97eff0acbe7f7361c8d7f805b4af7313dcfcc90 /src/gui/text/qfontenginedirectwrite.cpp
parent404568a382d09e603013734533239e18d2bf8957 (diff)
Long live QRawFont!
The QGlyphs API was initially attempted with a bastardization of QFont which was meant to encapsulate a single, physical font instance (a QFontEngine) where a set of glyph indexes would make sense. This is not how QFont was intended to be used, and it caused several issues. At the same time, the requirement for loading a font from ttf/otf data and be able to access it and use it without polluting the rest of the process with the font arose. To support these two APIs we introduce QRawFont, which is an abstraction on top of a single physical font. Done-with: Jiang Jiang
Diffstat (limited to 'src/gui/text/qfontenginedirectwrite.cpp')
-rw-r--r--src/gui/text/qfontenginedirectwrite.cpp54
1 files changed, 24 insertions, 30 deletions
diff --git a/src/gui/text/qfontenginedirectwrite.cpp b/src/gui/text/qfontenginedirectwrite.cpp
index af5bab2ffe..f0a3644865 100644
--- a/src/gui/text/qfontenginedirectwrite.cpp
+++ b/src/gui/text/qfontenginedirectwrite.cpp
@@ -170,17 +170,12 @@ namespace {
}
-QFontEngineDirectWrite::QFontEngineDirectWrite(const QString &name,
- IDWriteFactory *directWriteFactory,
- IDWriteGdiInterop *directWriteGdiInterop,
- IDWriteFont *directWriteFont,
+QFontEngineDirectWrite::QFontEngineDirectWrite(IDWriteFactory *directWriteFactory,
+ IDWriteFontFace *directWriteFontFace,
qreal pixelSize)
- : m_name(name)
- , m_directWriteFont(directWriteFont)
- , m_directWriteFontFace(0)
+ : m_directWriteFontFace(directWriteFontFace)
, m_directWriteFactory(directWriteFactory)
, m_directWriteBitmapRenderTarget(0)
- , m_directWriteGdiInterop(directWriteGdiInterop)
, m_lineThickness(-1)
, m_unitsPerEm(-1)
, m_ascent(-1)
@@ -188,24 +183,17 @@ QFontEngineDirectWrite::QFontEngineDirectWrite(const QString &name,
, m_xHeight(-1)
, m_lineGap(-1)
{
- m_directWriteFont->AddRef();
m_directWriteFactory->AddRef();
- m_directWriteGdiInterop->AddRef();
+ m_directWriteFontFace->AddRef();
fontDef.pixelSize = pixelSize;
-
- HRESULT hr = m_directWriteFont->CreateFontFace(&m_directWriteFontFace);
- if (FAILED(hr))
- qErrnoWarning("QFontEngineDirectWrite: CreateFontFace failed");
-
collectMetrics();
}
QFontEngineDirectWrite::~QFontEngineDirectWrite()
{
- m_directWriteFont->Release();
m_directWriteFactory->Release();
- m_directWriteGdiInterop->Release();
+ m_directWriteFontFace->Release();
if (m_directWriteBitmapRenderTarget != 0)
m_directWriteBitmapRenderTarget->Release();
@@ -213,10 +201,10 @@ QFontEngineDirectWrite::~QFontEngineDirectWrite()
void QFontEngineDirectWrite::collectMetrics()
{
- if (m_directWriteFont != 0) {
+ if (m_directWriteFontFace != 0) {
DWRITE_FONT_METRICS metrics;
- m_directWriteFont->GetMetrics(&metrics);
+ m_directWriteFontFace->GetMetrics(&metrics);
m_unitsPerEm = metrics.designUnitsPerEm;
m_lineThickness = DESIGN_TO_LOGICAL(metrics.underlineThickness);
@@ -616,19 +604,25 @@ const char *QFontEngineDirectWrite::name() const
bool QFontEngineDirectWrite::canRender(const QChar *string, int len)
{
- for (int i=0; i<len; ++i) {
- BOOL exists;
- UINT32 codePoint = getChar(string, i, len);
- HRESULT hr = m_directWriteFont->HasCharacter(codePoint, &exists);
- if (FAILED(hr)) {
- qErrnoWarning("QFontEngineDirectWrite::canRender: HasCharacter failed");
- return false;
- } else if (!exists) {
- return false;
+ 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;
+ return true;
+ }
}
QFontEngine::Type QFontEngineDirectWrite::type() const