Qt 4.8
Public Functions | Properties | List of all members
QImageTextureGlyphCache Class Reference

#include <qtextureglyphcache_p.h>

Inheritance diagram for QImageTextureGlyphCache:
QTextureGlyphCache QFontEngineGlyphCache QSharedData QGLTextureGlyphCache

Public Functions

virtual void createTextureData (int width, int height)
 
virtual void fillTexture (const Coord &c, glyph_t glyph, QFixed subPixelPosition)
 
virtual int glyphMargin () const
 
const QImageimage () const
 
 QImageTextureGlyphCache (QFontEngineGlyphCache::Type type, const QTransform &matrix)
 
virtual void resizeTextureData (int width, int height)
 
- Public Functions inherited from QTextureGlyphCache
void createCache (int width, int height)
 
void fillInPendingGlyphs ()
 
virtual int glyphPadding () const
 
bool isNull () const
 
virtual int maxTextureHeight () const
 
virtual int maxTextureWidth () const
 
bool populate (QFontEngine *fontEngine, int numGlyphs, const glyph_t *glyphs, const QFixedPoint *positions)
 
 QTextureGlyphCache (QFontEngineGlyphCache::Type type, const QTransform &matrix)
 
void resizeCache (int width, int height)
 
QFixed subPixelPositionForX (QFixed x) const
 
QImage textureMapForGlyph (glyph_t g, QFixed subPixelPosition) const
 
virtual ~QTextureGlyphCache ()
 
- Public Functions inherited from QFontEngineGlyphCache
Type cacheType () const
 
 QFontEngineGlyphCache (const QTransform &matrix, Type type)
 
virtual ~QFontEngineGlyphCache ()
 
- Public Functions inherited from QSharedData
 QSharedData ()
 Constructs a QSharedData object with a reference count of 0. More...
 
 QSharedData (const QSharedData &)
 Constructs a QSharedData object with reference count 0. More...
 

Properties

QImage m_image
 

Additional Inherited Members

- Public Types inherited from QFontEngineGlyphCache
enum  Type { Raster_RGBMask, Raster_A8, Raster_Mono }
 
- Public Variables inherited from QTextureGlyphCache
QHash< GlyphAndSubPixelPosition, Coordcoords
 
- Public Variables inherited from QFontEngineGlyphCache
QTransform m_transform
 
QFontEngineGlyphCache::Type m_type
 
- Public Variables inherited from QSharedData
QAtomicInt ref
 
- Protected Functions inherited from QTextureGlyphCache
int calculateSubPixelPositionCount (glyph_t) const
 
- Protected Variables inherited from QTextureGlyphCache
QFontEnginem_current_fontengine
 
int m_currentRowHeight
 
int m_cx
 
int m_cy
 
int m_h
 
QHash< GlyphAndSubPixelPosition, Coordm_pendingGlyphs
 
int m_subPixelPositionCount
 
int m_w
 

Detailed Description

Definition at line 171 of file qtextureglyphcache_p.h.

Constructors and Destructors

◆ QImageTextureGlyphCache()

QImageTextureGlyphCache::QImageTextureGlyphCache ( QFontEngineGlyphCache::Type  type,
const QTransform matrix 
)
inline

Definition at line 174 of file qtextureglyphcache_p.h.

175  : QTextureGlyphCache(type, matrix) { }
int type
Definition: qmetatype.cpp:239
QTextureGlyphCache(QFontEngineGlyphCache::Type type, const QTransform &matrix)

Functions

◆ createTextureData()

void QImageTextureGlyphCache::createTextureData ( int  width,
int  height 
)
virtual

Implements QTextureGlyphCache.

Reimplemented in QGLTextureGlyphCache.

Definition at line 347 of file qtextureglyphcache.cpp.

Referenced by QGLTextureGlyphCache::createTextureData().

348 {
349  switch (m_type) {
351  m_image = QImage(width, height, QImage::Format_Mono);
352  break;
354  m_image = QImage(width, height, QImage::Format_Indexed8);
355  m_image.fill(0);
356  QVector<QRgb> colors(256);
357  QRgb *it = colors.data();
358  for (int i=0; i<256; ++i, ++it)
359  *it = 0xff000000 | i | (i<<8) | (i<<16);
360  m_image.setColorTable(colors);
361  break; }
363  m_image = QImage(width, height, QImage::Format_RGB32);
364  break;
365  }
366 }
unsigned int QRgb
Definition: qrgb.h:53
void setColorTable(const QVector< QRgb > colors)
Sets the color table used to translate color indexes to QRgb values, to the specified colors...
Definition: qimage.cpp:1744
#define it(className, varName)
void fill(uint pixel)
Fills the entire image with the given pixelValue.
Definition: qimage.cpp:2032
QFontEngineGlyphCache::Type m_type
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87

◆ fillTexture()

void QImageTextureGlyphCache::fillTexture ( const Coord c,
glyph_t  glyph,
QFixed  subPixelPosition 
)
virtual

Implements QTextureGlyphCache.

Reimplemented in QGLTextureGlyphCache.

Definition at line 377 of file qtextureglyphcache.cpp.

Referenced by QGLTextureGlyphCache::fillTexture().

378 {
379  QImage mask = textureMapForGlyph(g, subPixelPosition);
380 
381 #ifdef CACHE_DEBUG
382  printf("fillTexture of %dx%d at %d,%d in the cache of %dx%d\n", c.w, c.h, c.x, c.y, m_image.width(), m_image.height());
383  if (mask.width() > c.w || mask.height() > c.h) {
384  printf(" ERROR; mask is bigger than reserved space! %dx%d instead of %dx%d\n", mask.width(), mask.height(), c.w,c.h);
385  return;
386  }
387 #endif
388 
390  QImage ref(m_image.bits() + (c.x * 4 + c.y * m_image.bytesPerLine()),
391  qMax(mask.width(), c.w), qMax(mask.height(), c.h), m_image.bytesPerLine(),
392  m_image.format());
393  QPainter p(&ref);
394  p.setCompositionMode(QPainter::CompositionMode_Source);
395  p.fillRect(0, 0, c.w, c.h, QColor(0,0,0,0)); // TODO optimize this
396  p.drawImage(0, 0, mask);
397  p.end();
399  if (mask.depth() > 1) {
400  // TODO optimize this
401  mask = mask.alphaChannel();
402  mask.invertPixels();
404  }
405 
406  int mw = qMin(mask.width(), c.w);
407  int mh = qMin(mask.height(), c.h);
408  uchar *d = m_image.bits();
409  int dbpl = m_image.bytesPerLine();
410 
411  for (int y = 0; y < c.h; ++y) {
412  uchar *dest = d + (c.y + y) *dbpl + c.x/8;
413 
414  if (y < mh) {
415  uchar *src = mask.scanLine(y);
416  for (int x = 0; x < c.w/8; ++x) {
417  if (x < (mw+7)/8)
418  dest[x] = src[x];
419  else
420  dest[x] = 0;
421  }
422  } else {
423  for (int x = 0; x < c.w/8; ++x)
424  dest[x] = 0;
425  }
426  }
427  } else { // A8
428  int mw = qMin(mask.width(), c.w);
429  int mh = qMin(mask.height(), c.h);
430  uchar *d = m_image.bits();
431  int dbpl = m_image.bytesPerLine();
432 
433  if (mask.depth() == 1) {
434  for (int y = 0; y < c.h; ++y) {
435  uchar *dest = d + (c.y + y) *dbpl + c.x;
436  if (y < mh) {
437  uchar *src = (uchar *) mask.scanLine(y);
438  for (int x = 0; x < c.w; ++x) {
439  if (x < mw)
440  dest[x] = (src[x >> 3] & (1 << (7 - (x & 7)))) > 0 ? 255 : 0;
441  }
442  }
443  }
444  } else if (mask.depth() == 8) {
445  for (int y = 0; y < c.h; ++y) {
446  uchar *dest = d + (c.y + y) *dbpl + c.x;
447  if (y < mh) {
448  uchar *src = (uchar *) mask.scanLine(y);
449  for (int x = 0; x < c.w; ++x) {
450  if (x < mw)
451  dest[x] = src[x];
452  }
453  }
454  }
455  }
456  }
457 
458 #ifdef CACHE_DEBUG
459 // QPainter p(&m_image);
460 // p.drawLine(
461  QPoint base(c.x + glyphMargin(), c.y + glyphMargin() + c.baseLineY-1);
462  if (m_image.rect().contains(base))
463  m_image.setPixel(base, 255);
464  m_image.save(QString::fromLatin1("cache-%1.png").arg(qint64(this)));
465 #endif
466 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
QAtomicInt ref
Definition: qshareddata.h:59
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double d
Definition: qnumeric_p.h:62
unsigned char c[8]
Definition: qnumeric_p.h:62
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
bool save(const QString &fileName, const char *format=0, int quality=-1) const
Saves the image to the file with the given fileName, using the given image file format and quality fa...
Definition: qimage.cpp:5346
int bytesPerLine() const
Returns the number of bytes per image scanline.
Definition: qimage.cpp:1812
QRect rect() const
Returns the enclosing rectangle (0, 0, width(), height()) of the image.
Definition: qimage.cpp:1603
QImage textureMapForGlyph(glyph_t g, QFixed subPixelPosition) const
static const uint base
Definition: qurl.cpp:268
QFontEngineGlyphCache::Type m_type
Format format() const
Returns the format of the image.
Definition: qimage.cpp:2305
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
unsigned char uchar
Definition: qglobal.h:994
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
int depth() const
Returns the depth of the image.
Definition: qimage.cpp:1620
__int64 qint64
Definition: qglobal.h:942
QImage alphaChannel() const
Returns the alpha channel of the image as a new grayscale QImage in which each pixel&#39;s red...
Definition: qimage.cpp:6430
bool contains(const QPoint &p, bool proper=false) const
Returns true if the given point is inside or on the edge of the rectangle, otherwise returns false...
Definition: qrect.cpp:1101
uchar * bits()
Returns a pointer to the first pixel data.
Definition: qimage.cpp:1946
void setPixel(int x, int y, uint index_or_rgb)
Sets the pixel index or color at (x, y) to index_or_rgb.
Definition: qimage.cpp:4311
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
Definition: qimage.cpp:3966
virtual int glyphMargin() const
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
if(void) toggleToolbarShown
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
void invertPixels(InvertMode=InvertRgb)
Inverts all pixel values in the image.
Definition: qimage.cpp:2179
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
Definition: qimage.cpp:1886

◆ glyphMargin()

int QImageTextureGlyphCache::glyphMargin ( ) const
virtual

Reimplemented from QTextureGlyphCache.

Definition at line 368 of file qtextureglyphcache.cpp.

Referenced by QGL2PaintEngineExPrivate::drawCachedGlyphs(), and QRasterPaintEngine::drawCachedGlyphs().

369 {
370 #if (defined(Q_WS_MAC) && defined(QT_MAC_USE_COCOA)) || defined(Q_WS_X11)
371  return 0;
372 #else
374 #endif
375 }
QFontEngineGlyphCache::Type m_type

◆ image()

const QImage& QImageTextureGlyphCache::image ( ) const
inline

◆ resizeTextureData()

void QImageTextureGlyphCache::resizeTextureData ( int  width,
int  height 
)
virtual

Implements QTextureGlyphCache.

Reimplemented in QGLTextureGlyphCache.

Definition at line 342 of file qtextureglyphcache.cpp.

Referenced by QGLTextureGlyphCache::resizeTextureData().

343 {
344  m_image = m_image.copy(0, 0, width, height);
345 }
QImage copy(const QRect &rect=QRect()) const
Returns a sub-area of the image as a new image.
Definition: qimage.cpp:1410

Properties

◆ m_image

QImage QImageTextureGlyphCache::m_image
private

Definition at line 184 of file qtextureglyphcache_p.h.


The documentation for this class was generated from the following files: