Qt 4.8
Classes | Functions
qabstractfontengine_qws.cpp File Reference
#include "qabstractfontengine_qws.h"
#include "qabstractfontengine_p.h"
#include <private/qtextengine_p.h>
#include <private/qpaintengine_raster_p.h>
#include <qmath.h>

Go to the source code of this file.

Classes

class  QAbstractFontEnginePrivate
 
class  QFontEngineInfoPrivate
 
class  QFontEnginePluginPrivate
 

Functions

static QImage alphaMapFromPath (QFontEngine *fe, glyph_t glyph)
 

Function Documentation

◆ alphaMapFromPath()

static QImage alphaMapFromPath ( QFontEngine fe,
glyph_t  glyph 
)
static

Definition at line 628 of file qabstractfontengine_qws.cpp.

Referenced by QProxyFontEngine::alphaMapForGlyph().

629 {
630  glyph_metrics_t gm = fe->boundingBox(glyph);
631  int glyph_x = qFloor(gm.x.toReal());
632  int glyph_y = qFloor(gm.y.toReal());
633  int glyph_width = qCeil((gm.x + gm.width).toReal()) - glyph_x;
634  int glyph_height = qCeil((gm.y + gm.height).toReal()) - glyph_y;
635 
636  if (glyph_width <= 0 || glyph_height <= 0)
637  return QImage();
638  QFixedPoint pt;
639  pt.x = 0;
640  pt.y = -glyph_y; // the baseline
641  QPainterPath path;
642  QImage im(glyph_width + qAbs(glyph_x) + 4, glyph_height, QImage::Format_ARGB32_Premultiplied);
643  im.fill(Qt::transparent);
644  QPainter p(&im);
645  p.setRenderHint(QPainter::Antialiasing);
646  fe->addGlyphsToPath(&glyph, &pt, 1, &path, 0);
647  p.setPen(Qt::NoPen);
648  p.setBrush(Qt::black);
649  p.drawPath(path);
650  p.end();
651 
652  QImage indexed(im.width(), im.height(), QImage::Format_Indexed8);
653  QVector<QRgb> colors(256);
654  for (int i=0; i<256; ++i)
655  colors[i] = qRgba(0, 0, 0, i);
656  indexed.setColorTable(colors);
657 
658  for (int y=0; y<im.height(); ++y) {
659  uchar *dst = (uchar *) indexed.scanLine(y);
660  uint *src = (uint *) im.scanLine(y);
661  for (int x=0; x<im.width(); ++x)
662  dst[x] = qAlpha(src[x]);
663  }
664 
665  return indexed;
666 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
int qCeil(qreal v)
Definition: qmath.h:63
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
int qFloor(qreal v)
Definition: qmath.h:73
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
int qAlpha(QRgb rgba)
Returns the alpha component of the ARGB quadruplet rgba.
Definition: qrgb.h:66
unsigned char uchar
Definition: qglobal.h:994
QFixed y
Definition: qfixed_p.h:191
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
unsigned int uint
Definition: qglobal.h:996
virtual glyph_metrics_t boundingBox(const QGlyphLayout &glyphs)=0
virtual void addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions, int nglyphs, QPainterPath *path, QTextItem::RenderFlags flags)
QFixed x
Definition: qfixed_p.h:190
qreal toReal() const
Definition: qfixed_p.h:77
QRgb qRgba(int r, int g, int b, int a)
Returns the ARGB quadruplet ({a}, {r}, {g}, {b}).
Definition: qrgb.h:72