42 #ifndef QT_NO_DIRECTWRITE 48 #include <private/qnativeimage_p.h> 55 #define DESIGN_TO_LOGICAL(DESIGN_UNIT_VALUE) \ 56 QFixed::fromReal((qreal(DESIGN_UNIT_VALUE) / qreal(m_unitsPerEm)) * fontDef.pixelSize) 60 class GeometrySink:
public IDWriteGeometrySink
63 GeometrySink(
QPainterPath *path) : m_path(path), m_refCount(0)
68 IFACEMETHOD_(
void, AddBeziers)(
const D2D1_BEZIER_SEGMENT *beziers, UINT bezierCount);
69 IFACEMETHOD_(
void, AddLines)(
const D2D1_POINT_2F *points, UINT pointCount);
70 IFACEMETHOD_(
void, BeginFigure)(D2D1_POINT_2F startPoint, D2D1_FIGURE_BEGIN figureBegin);
72 IFACEMETHOD_(
void, EndFigure)(D2D1_FIGURE_END figureEnd);
73 IFACEMETHOD_(
void, SetFillMode)(D2D1_FILL_MODE fillMode);
74 IFACEMETHOD_(
void, SetSegmentFlags)(D2D1_PATH_SEGMENT vertexFlags);
76 IFACEMETHOD_(
unsigned long, AddRef)();
77 IFACEMETHOD_(
unsigned long,
Release)();
78 IFACEMETHOD(QueryInterface)(IID
const &riid,
void **ppvObject);
81 inline static QPointF fromD2D1_POINT_2F(
const D2D1_POINT_2F &inp)
86 unsigned long m_refCount;
91 void GeometrySink::AddBeziers(
const D2D1_BEZIER_SEGMENT *beziers,
94 for (
uint i=0; i<bezierCount; ++i) {
95 QPointF c1 = fromD2D1_POINT_2F(beziers[i].point1);
96 QPointF c2 = fromD2D1_POINT_2F(beziers[i].point2);
97 QPointF p2 = fromD2D1_POINT_2F(beziers[i].point3);
99 m_path->cubicTo(c1, c2, p2);
103 void GeometrySink::AddLines(
const D2D1_POINT_2F *points, UINT pointsCount)
105 for (
uint i=0; i<pointsCount; ++i)
106 m_path->lineTo(fromD2D1_POINT_2F(points[i]));
109 void GeometrySink::BeginFigure(D2D1_POINT_2F startPoint,
112 m_startPoint = fromD2D1_POINT_2F(startPoint);
113 m_path->moveTo(m_startPoint);
116 IFACEMETHODIMP GeometrySink::Close()
121 void GeometrySink::EndFigure(D2D1_FIGURE_END figureEnd)
123 if (figureEnd == D2D1_FIGURE_END_CLOSED)
124 m_path->closeSubpath();
127 void GeometrySink::SetFillMode(D2D1_FILL_MODE fillMode)
129 m_path->setFillRule(fillMode == D2D1_FILL_MODE_ALTERNATE
134 void GeometrySink::SetSegmentFlags(D2D1_PATH_SEGMENT )
139 IFACEMETHODIMP_(
unsigned long) GeometrySink::AddRef()
141 return InterlockedIncrement(&m_refCount);
146 unsigned long newCount = InterlockedDecrement(&m_refCount);
156 IFACEMETHODIMP GeometrySink::QueryInterface(IID
const &riid,
void **ppvObject)
158 if (__uuidof(IDWriteGeometrySink) == riid) {
160 }
else if (__uuidof(IUnknown) == riid) {
174 IDWriteFontFace *directWriteFontFace,
176 : m_directWriteFontFace(directWriteFontFace)
177 , m_directWriteFactory(directWriteFactory)
178 , m_directWriteBitmapRenderTarget(0)
179 , m_lineThickness(-1)
205 DWRITE_FONT_METRICS metrics;
231 const void *tableData = 0;
232 void *tableContext = 0;
236 t, &tableData, &tableSize, &tableContext, &exists
246 }
else if (*length < tableSize) {
250 qMemCopy(buffer, tableData, tableSize);
255 qErrnoWarning(
"QFontEngineDirectWrite::getSfntTableData: TryGetFontTable failed");
273 if (str[i].isHighSurrogate() && i < len-1 && str[i+1].isLowSurrogate()) {
281 int *nglyphs, QTextEngine::ShaperFlags flags)
const 285 for (
int i=0; i<len; ++i) {
286 codePoints[i] =
getChar(str, i, len);
294 glyphIndices.
data());
297 for (
int i=0; i<len; ++i)
298 glyphs->
glyphs[i] = glyphIndices[i];
307 qErrnoWarning(
"QFontEngineDirectWrite::stringToCMap: GetGlyphIndicesW failed");
323 glyphIndices[i] = UINT16(glyphs->
glyphs[i]);
328 glyphMetrics.data());
330 for (
int i=0; i<glyphs->
numGlyphs; ++i) {
337 qErrnoWarning(
"QFontEngineDirectWrite::recalcAdvances: GetDesignGlyphMetrics failed");
351 for (
int i=0; i<nglyphs; ++i) {
352 glyphIndices[i] = glyphs[i];
353 glyphOffsets[i].advanceOffset = positions[i].
x.
toReal();
354 glyphOffsets[i].ascenderOffset = -positions[i].
y.
toReal();
355 glyphAdvances[i] = 0.0;
358 GeometrySink geometrySink(path);
362 glyphAdvances.
data(),
371 qErrnoWarning(
"QFontEngineDirectWrite::addGlyphsToPath: GetGlyphRunOutline failed");
382 for (
int i = 0; i < glyphs.
numGlyphs; ++i) {
396 UINT16 glyphIndex = glyph;
397 FLOAT glyphAdvance = 0;
399 DWRITE_GLYPH_OFFSET glyphOffset;
400 glyphOffset.advanceOffset = 0;
401 glyphOffset.ascenderOffset = 0;
403 DWRITE_GLYPH_RUN glyphRun;
406 glyphRun.glyphCount = 1;
407 glyphRun.glyphIndices = &glyphIndex;
408 glyphRun.glyphAdvances = &glyphAdvance;
409 glyphRun.isSideways =
false;
410 glyphRun.bidiLevel = 0;
411 glyphRun.glyphOffsets = &glyphOffset;
413 DWRITE_MATRIX transform;
414 transform.dx = subPixelPosition.
toReal();
416 transform.m11 = matrix.
m11();
417 transform.m12 = matrix.
m12();
418 transform.m21 = matrix.
m21();
419 transform.m22 = matrix.
m22();
421 IDWriteGlyphRunAnalysis *glyphAnalysis = NULL;
426 DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC,
427 DWRITE_MEASURING_MODE_NATURAL,
434 glyphAnalysis->GetAlphaTextureBounds(DWRITE_TEXTURE_CLEARTYPE_3x1, &rect);
435 glyphAnalysis->Release();
437 return glyph_metrics_t(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
449 UINT16 glyphIndex = g;
451 DWRITE_GLYPH_METRICS glyphMetrics;
461 advanceWidth = advanceWidth.
round();
462 advanceHeight = advanceHeight.
round();
465 QFixed width = advanceWidth - leftSideBearing - rightSideBearing;
469 advanceWidth, advanceHeight);
471 qErrnoWarning(
"QFontEngineDirectWrite::boundingBox: GetDesignGlyphMetrics failed");
520 for (
int i=0; i<256; ++i)
521 colors[i] =
qRgba(0, 0, 0, i);
522 indexed.setColorTable(colors);
524 for (
int y=0; y<im.
height(); ++y) {
526 uchar *dst = indexed.scanLine(y);
527 for (
int x=0; x<im.
width(); ++x) {
547 UINT16 glyphIndex = t;
548 FLOAT glyphAdvance = 0;
550 DWRITE_GLYPH_OFFSET glyphOffset;
551 glyphOffset.advanceOffset = 0;
552 glyphOffset.ascenderOffset = 0;
554 DWRITE_GLYPH_RUN glyphRun;
557 glyphRun.glyphCount = 1;
558 glyphRun.glyphIndices = &glyphIndex;
559 glyphRun.glyphAdvances = &glyphAdvance;
560 glyphRun.isSideways =
false;
561 glyphRun.bidiLevel = 0;
562 glyphRun.glyphOffsets = &glyphOffset;
564 DWRITE_MATRIX transform;
565 transform.dx = subPixelPosition.
toReal();
567 transform.m11 = xform.
m11();
568 transform.m12 = xform.
m12();
569 transform.m21 = xform.
m21();
570 transform.m22 = xform.
m22();
572 IDWriteGlyphRunAnalysis *glyphAnalysis = NULL;
577 DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC,
578 DWRITE_MEASURING_MODE_NATURAL,
585 glyphAnalysis->GetAlphaTextureBounds(DWRITE_TEXTURE_CLEARTYPE_3x1, &rect);
589 rect.right += margin;
590 rect.bottom += margin;
592 int width = rect.right - rect.left;
593 int height = rect.bottom - rect.top;
595 int size = width * height * 3;
600 hr = glyphAnalysis->CreateAlphaTexture(DWRITE_TEXTURE_CLEARTYPE_3x1,
607 img.
fill(0xffffffff);
609 for (
int y=0; y<height; ++y) {
611 BYTE *src = alphaValues + width * 3 * y;
613 for (
int x=0; x<width; ++x) {
614 dest[x] = *(src) << 16
622 delete[] alphaValues;
623 glyphAnalysis->Release();
627 delete[] alphaValues;
628 glyphAnalysis->Release();
630 qErrnoWarning(
"QFontEngineDirectWrite::imageForGlyph: CreateAlphaTexture failed");
634 qErrnoWarning(
"QFontEngineDirectWrite::imageForGlyph: CreateGlyphRunAnalysis failed");
646 return mask.
depth() == 32
659 int actualLength = 0;
660 for (
int i=0; i<len; ++i, actualLength++)
661 codePoints[actualLength] =
getChar(
string, i, len);
665 glyphIndices.
data());
667 qErrnoWarning(hr,
"QFontEngineDirectWrite::canRender: GetGlyphIndices failed");
670 for (
int i=0; i<glyphIndices.
size(); ++i) {
671 if (glyphIndices.
at(i) == 0)
697 #endif // QT_NO_DIRECTWRITE virtual QFixed lineThickness() const
qreal maxCharWidth() const
#define QT_END_NAMESPACE
This macro expands to.
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
void fill(uint pixel)
Fills the entire image with the given pixelValue.
unsigned int getChar(const QChar *str, int &i, const int len)
The QPointF class defines a point in the plane using floating point precision.
IDWriteFontFace * m_directWriteFontFace
QFixed lineThickness() const
void recalcAdvances(QGlyphLayout *glyphs, QTextEngine::ShaperFlags) const
void addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions, int nglyphs, QPainterPath *path, QTextItem::RenderFlags flags)
IDWriteBitmapRenderTarget * m_directWriteBitmapRenderTarget
The QChar class provides a 16-bit Unicode character.
QImage imageForGlyph(glyph_t t, QFixed subPixelPosition, int margin, const QTransform &xform)
QImage alphaRGBMapForGlyph(glyph_t t, QFixed subPixelPosition, int margin, const QTransform &xform)
IDWriteFactory * m_directWriteFactory
QFixed lastRightBearing(const QGlyphLayout &glyphs, bool round=false)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Q_GUI_EXPORT_INLINE QRgb qRgba(int r, int g, int b, int a)
static float pixelSize(const QFontDef &request, int dpi)
bool supportsSubPixelPositions() const
static const QCssKnownValue positions[NumKnownPositionModes - 1]
QChar mirroredChar() const
Returns the mirrored character if this character is a mirrored character; otherwise returns the chara...
bool getSfntTableData(uint tag, uchar *buffer, uint *length) const
The QImage class provides a hardware-independent image representation that allows direct access to th...
#define DESIGN_TO_LOGICAL(DESIGN_UNIT_VALUE)
int depth() const
Returns the depth of the image.
virtual glyph_metrics_t boundingBox(const QGlyphLayout &glyphs)=0
const T & at(int idx) const
~QFontEngineDirectWrite()
glyph_metrics_t boundingBox(const QGlyphLayout &glyphs)
QImage alphaMapForGlyph(glyph_t, QFixed subPixelPosition, const QTransform &t)
bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const
void * qMemCopy(void *dest, const void *src, size_t n)
Q_GUI_EXPORT_INLINE int qGray(int r, int g, int b)
QFontEngine * cloneWithSize(qreal pixelSize) const
int width() const
Returns the width of the image.
void * qMemSet(void *dest, int c, size_t n)
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
QFontEngineDirectWrite(IDWriteFactory *directWriteFactory, IDWriteFontFace *directWriteFontFace, qreal pixelSize)
glyph_metrics_t alphaMapBoundingBox(glyph_t glyph, QFixed subPixelPosition, const QTransform &matrix, GlyphFormat format)
if(void) toggleToolbarShown
virtual QFixed emSquareSize() const
int height() const
Returns the height of the image.
static uint surrogateToUcs4(ushort high, ushort low)
Converts a UTF16 surrogate pair with the given high and low values to its UCS-4 code point...
QFixed effectiveAdvance(int item) const
QFixed emSquareSize() const
quint32 qbswap< quint32 >(quint32 source)
bool canRender(const QChar *string, int len)
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
const char * name() const
void qErrnoWarning(const char *msg,...)