Qt 4.8
Classes | Public Functions | Protected Functions | Private Functions | Properties | Friends | List of all members
QFontEngineMacMulti Class Reference

#include <qfontengine_mac_p.h>

Inheritance diagram for QFontEngineMacMulti:
QFontEngineMulti QFontEngine QObject

Classes

struct  ShaperItem
 

Public Functions

virtual bool canRender (const QChar *string, int len)
 
virtual void doKerning (QGlyphLayout *, QTextEngine::ShaperFlags) const
 
ATSUFontID macFontID () const
 
virtual const char * name () const
 
 QFontEngineMacMulti (const ATSFontFamilyRef &atsFamily, const ATSFontRef &atsFontRef, const QFontDef &fontDef, bool kerning)
 
virtual void recalcAdvances (QGlyphLayout *, QTextEngine::ShaperFlags) const
 
virtual bool stringToCMap (const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const
 
bool stringToCMap (const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags, unsigned short *logClusters, const HB_CharAttributes *charAttributes, QScriptItem *) const
 
virtual ~QFontEngineMacMulti ()
 
- Public Functions inherited from QFontEngineMulti
virtual void addOutlineToPath (qreal, qreal, const QGlyphLayout &, QPainterPath *, QTextItem::RenderFlags flags)
 
virtual QImage alphaMapForGlyph (glyph_t)
 
virtual QFixed ascent () const
 
virtual QFixed averageCharWidth () const
 
virtual glyph_metrics_t boundingBox (const QGlyphLayout &glyphs)
 
virtual glyph_metrics_t boundingBox (glyph_t glyph)
 
virtual QFixed descent () const
 
QFontEngineengine (int at) const
 
virtual void getGlyphBearings (glyph_t glyph, qreal *leftBearing=0, qreal *rightBearing=0)
 
virtual QFixed leading () const
 
virtual QFixed lineThickness () const
 
virtual qreal maxCharWidth () const
 
virtual qreal minLeftBearing () const
 
virtual qreal minRightBearing () const
 
 QFontEngineMulti (int engineCount)
 
virtual Type type () const
 
virtual QFixed underlinePosition () const
 
virtual QFixed xHeight () const
 
 ~QFontEngineMulti ()
 
- Public Functions inherited from QFontEngine
void addBitmapFontToPath (qreal x, qreal y, const QGlyphLayout &, QPainterPath *, QTextItem::RenderFlags)
 
virtual void addGlyphsToPath (glyph_t *glyphs, QFixedPoint *positions, int nglyphs, QPainterPath *path, QTextItem::RenderFlags flags)
 
virtual glyph_metrics_t alphaMapBoundingBox (glyph_t glyph, QFixed, const QTransform &matrix, GlyphFormat)
 
virtual QImage alphaMapForGlyph (glyph_t glyph, QFixed subPixelPosition)
 
virtual QImage alphaMapForGlyph (glyph_t, const QTransform &t)
 
virtual QImage alphaMapForGlyph (glyph_t, QFixed subPixelPosition, const QTransform &t)
 
virtual QImage alphaRGBMapForGlyph (glyph_t, QFixed subPixelPosition, int margin, const QTransform &t)
 
virtual glyph_metrics_t boundingBox (glyph_t glyph, const QTransform &matrix)
 
virtual QFontEnginecloneWithSize (qreal) const
 
virtual QFixed emSquareSize () const
 
virtual FaceId faceId () const
 
void getGlyphPositions (const QGlyphLayout &glyphs, const QTransform &matrix, QTextItem::RenderFlags flags, QVarLengthArray< glyph_t > &glyphs_out, QVarLengthArray< QFixedPoint > &positions)
 
virtual HB_Error getPointInOutline (HB_Glyph glyph, int flags, hb_uint32 point, HB_Fixed *xpos, HB_Fixed *ypos, hb_uint32 *nPoints)
 
QByteArray getSfntTable (uint) const
 
virtual bool getSfntTableData (uint, uchar *, uint *) const
 
virtual void getUnscaledGlyph (glyph_t glyph, QPainterPath *path, glyph_metrics_t *metrics)
 
QFontEngineGlyphCacheglyphCache (void *key, QFontEngineGlyphCache::Type type, const QTransform &transform) const
 
virtual int glyphCount () const
 
HB_Face harfbuzzFace () const
 
HB_Font harfbuzzFont () const
 
void loadKerningPairs (QFixed scalingFactor)
 
virtual Properties properties () const
 
 QFontEngine ()
 
virtual void removeGlyphFromCache (glyph_t)
 
void setGlyphCache (void *key, QFontEngineGlyphCache *data)
 
virtual bool supportsSubPixelPositions () const
 
virtual int synthesized () const
 
glyph_metrics_t tightBoundingBox (const QGlyphLayout &glyphs)
 
virtual ~QFontEngine ()
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Protected Functions

virtual void loadEngine (int at)
 
- Protected Functions inherited from QFontEngine
QFixed lastRightBearing (const QGlyphLayout &glyphs, bool round=false)
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 

Private Functions

const QFontEngineMacengineAt (int i) const
 
int fontIndexForFontID (ATSUFontID id) const
 
bool stringToCMapInternal (const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags, ShaperItem *item) const
 

Properties

ATSUFontID fontID
 
uint kerning: 1
 
ATSUStyle style
 
ATSUTextLayout textLayout
 
CGAffineTransform transform
 

Friends

class QFontEngineMac
 

Additional Inherited Members

- Public Types inherited from QFontEngine
enum  GlyphFormat {
  Format_None, Format_Render = Format_None, Format_Mono, Format_A8,
  Format_A32
}
 
enum  SynthesizedFlags { SynthesizedItalic = 0x1, SynthesizedBold = 0x2, SynthesizedStretch = 0x4 }
 
enum  Type {
  Box, Multi, XLFD, Win,
  Mac, Freetype, QPF1, QPF2,
  Proxy, S60FontEngine, DirectWrite, TestFontEngine = 0x1000
}
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 
- Static Public Functions inherited from QFontEngine
static QByteArray convertToPostscriptFontFamilyName (const QByteArray &fontFamily)
 
static const uchargetCMap (const uchar *table, uint tableSize, bool *isSymbolFont, int *cmapSize)
 
static quint32 getTrueTypeGlyphIndex (const uchar *cmap, uint unicode)
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Public Variables inherited from QFontEngine
uint cache_cost
 
int cache_count
 
QFontDef fontDef
 
uint fsType: 16
 
int glyphFormat
 
HB_Face hbFace
 
HB_FontRec hbFont
 
QVector< KernPairkerning_pairs
 
QAtomicInt ref
 
bool symbol
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Static Protected Functions inherited from QFontEngine
static const QVector< QRgb > & grayPalette ()
 
- Protected Variables inherited from QFontEngineMulti
QVector< QFontEngine * > engines
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 113 of file qfontengine_mac_p.h.

Constructors and Destructors

◆ QFontEngineMacMulti()

QFontEngineMacMulti::QFontEngineMacMulti ( const ATSFontFamilyRef &  atsFamily,
const ATSFontRef &  atsFontRef,
const QFontDef fontDef,
bool  kerning 
)

Definition at line 126 of file qfontengine_mac.mm.

127  : QFontEngineMulti(0)
128 {
129  this->fontDef = fontDef;
130  this->kerning = kerning;
131 
132  // hopefully (CTFontCreateWithName or CTFontCreateWithFontDescriptor) + CTFontCreateCopyWithSymbolicTraits
133  // (or CTFontCreateWithQuickdrawInstance)
134  FMFontFamily fmFamily;
135  FMFontStyle fntStyle = 0;
136  fmFamily = FMGetFontFamilyFromATSFontFamilyRef(atsFamily);
137  if (fmFamily == kInvalidFontFamily) {
138  // Use the ATSFont then...
139  fontID = FMGetFontFromATSFontRef(atsFontRef);
140  } else {
141  if (fontDef.weight >= QFont::Bold)
142  fntStyle |= ::bold;
143  if (fontDef.style != QFont::StyleNormal)
144  fntStyle |= ::italic;
145 
146  FMFontStyle intrinsicStyle;
147  FMFont fnt = 0;
148  if (FMGetFontFromFontFamilyInstance(fmFamily, fntStyle, &fnt, &intrinsicStyle) == noErr)
149  fontID = FMGetATSFontRefFromFont(fnt);
150  }
151 
152  // CFDictionaryRef, <CTStringAttributes.h>
154 
155  status = ATSUCreateTextLayout(&textLayout);
156  Q_ASSERT(status == noErr);
157 
158  const int maxAttributeCount = 5;
159  ATSUAttributeTag tags[maxAttributeCount + 1];
160  ByteCount sizes[maxAttributeCount + 1];
161  ATSUAttributeValuePtr values[maxAttributeCount + 1];
162  int attributeCount = 0;
163 
164  Fixed size = FixRatio(fontDef.pixelSize, 1);
165  tags[attributeCount] = kATSUSizeTag;
166  sizes[attributeCount] = sizeof(size);
167  values[attributeCount] = &size;
168  ++attributeCount;
169 
170  tags[attributeCount] = kATSUFontTag;
171  sizes[attributeCount] = sizeof(fontID);
172  values[attributeCount] = &this->fontID;
173  ++attributeCount;
174 
175  transform = CGAffineTransformIdentity;
176  if (fontDef.stretch != 100) {
177  transform = CGAffineTransformMakeScale(float(fontDef.stretch) / float(100), 1);
178  tags[attributeCount] = kATSUFontMatrixTag;
179  sizes[attributeCount] = sizeof(transform);
180  values[attributeCount] = &transform;
181  ++attributeCount;
182  }
183 
184  status = ATSUCreateStyle(&style);
185  Q_ASSERT(status == noErr);
186 
187  Q_ASSERT(attributeCount < maxAttributeCount + 1);
188  status = ATSUSetAttributes(style, attributeCount, tags, sizes, values);
189  Q_ASSERT(status == noErr);
190 
191  QFontEngineMac *fe = new QFontEngineMac(style, fontID, fontDef, this);
192  fe->ref.ref();
193  engines.append(fe);
194 }
QAtomicInt ref
ATSUTextLayout textLayout
static LibLoadStatus status
Definition: qlocale_icu.cpp:69
bool ref()
Atomically increments the value of this QAtomicInt.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
uint weight
Definition: qfont_p.h:95
quint16 values[128]
signed long OSStatus
qreal pixelSize
Definition: qfont_p.h:90
QVector< QFontEngine * > engines
friend class QFontEngineMac
uint style
Definition: qfont_p.h:97
uint stretch
Definition: qfont_p.h:98
CGAffineTransform transform
QFontDef fontDef
QFontEngineMulti(int engineCount)

◆ ~QFontEngineMacMulti()

QFontEngineMacMulti::~QFontEngineMacMulti ( )
virtual

Definition at line 196 of file qfontengine_mac.mm.

197 {
198  ATSUDisposeTextLayout(textLayout);
199  ATSUDisposeStyle(style);
200 
201  for (int i = 0; i < engines.count(); ++i) {
202  QFontEngineMac *fe = const_cast<QFontEngineMac *>(static_cast<const QFontEngineMac *>(engines.at(i)));
203  fe->multiEngine = 0;
204  if (!fe->ref.deref())
205  delete fe;
206  }
207  engines.clear();
208 }
QAtomicInt ref
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
ATSUTextLayout textLayout
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
Definition: qvector.h:347
QFontEngineMacMulti * multiEngine
bool deref()
Atomically decrements the value of this QAtomicInt.
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QVector< QFontEngine * > engines

Functions

◆ canRender()

bool QFontEngineMacMulti::canRender ( const QChar string,
int  len 
)
virtual

Reimplemented from QFontEngineMulti.

Definition at line 601 of file qfontengine_mac.mm.

602 {
603  ATSUSetTextPointerLocation(textLayout, reinterpret_cast<const UniChar *>(string), 0, len, len);
604  ATSUSetRunStyle(textLayout, style, 0, len);
605 
606  OSStatus e = noErr;
607  int pos = 0;
608  do {
609  FMFont substFont = 0;
610  UniCharArrayOffset changedOffset = 0;
611  UniCharCount changeCount = 0;
612 
613  // CTFontCreateForString
614  e = ATSUMatchFontsToText(textLayout, pos, len - pos,
615  &substFont, &changedOffset,
616  &changeCount);
617  if (e == kATSUFontsMatched) {
618  pos = changedOffset + changeCount;
619  } else if (e == kATSUFontsNotMatched) {
620  break;
621  }
622  } while (pos < len && e != noErr);
623 
624  return e == noErr || e == kATSUFontsMatched;
625 }
ATSUTextLayout textLayout
signed long OSStatus

◆ doKerning()

void QFontEngineMacMulti::doKerning ( QGlyphLayout ,
QTextEngine::ShaperFlags   
) const
virtual

Reimplemented from QFontEngineMulti.

Definition at line 590 of file qfontengine_mac.mm.

591 {
592  //Q_ASSERT(false);
593 }

◆ engineAt()

const QFontEngineMac* QFontEngineMacMulti::engineAt ( int  i) const
inlineprivate

Definition at line 152 of file qfontengine_mac_p.h.

Referenced by fontIndexForFontID(), and stringToCMapInternal().

153  { return static_cast<const QFontEngineMac *>(engines.at(i)); }
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QVector< QFontEngine * > engines

◆ fontIndexForFontID()

int QFontEngineMacMulti::fontIndexForFontID ( ATSUFontID  id) const
private

Definition at line 356 of file qfontengine_mac.mm.

Referenced by stringToCMapInternal().

357 {
358  for (int i = 0; i < engines.count(); ++i) {
359  if (engineAt(i)->fontID == id)
360  return i;
361  }
362 
363  QFontEngineMacMulti *that = const_cast<QFontEngineMacMulti *>(this);
364  QFontEngineMac *fe = new QFontEngineMac(style, id, fontDef, that);
365  fe->ref.ref();
366  that->engines.append(fe);
367  return engines.count() - 1;
368 }
QAtomicInt ref
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
bool ref()
Atomically increments the value of this QAtomicInt.
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
QVector< QFontEngine * > engines
friend class QFontEngineMac
const QFontEngineMac * engineAt(int i) const
QFontDef fontDef

◆ loadEngine()

void QFontEngineMacMulti::loadEngine ( int  at)
protectedvirtual

Implements QFontEngineMulti.

Definition at line 595 of file qfontengine_mac.mm.

596 {
597  // should never be called!
598  Q_ASSERT(false);
599 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823

◆ macFontID()

ATSUFontID QFontEngineMacMulti::macFontID ( ) const
inline

Definition at line 146 of file qfontengine_mac_p.h.

146 { return fontID; }

◆ name()

virtual const char* QFontEngineMacMulti::name ( ) const
inlinevirtual

Reimplemented from QFontEngineMulti.

Definition at line 142 of file qfontengine_mac_p.h.

142 { return "ATSUI"; }

◆ recalcAdvances()

void QFontEngineMacMulti::recalcAdvances ( QGlyphLayout ,
QTextEngine::ShaperFlags   
) const
virtual

This is a callback from harfbuzz. The font engine uses the font-system in use to find out the advances of each glyph and set it on the layout.

Reimplemented from QFontEngineMulti.

Definition at line 583 of file qfontengine_mac.mm.

584 {
585  Q_ASSERT(false);
586  Q_UNUSED(glyphs);
587  Q_UNUSED(flags);
588 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ stringToCMap() [1/2]

bool QFontEngineMacMulti::stringToCMap ( const QChar str,
int  len,
QGlyphLayout glyphs,
int *  nglyphs,
QTextEngine::ShaperFlags  flags 
) const
virtual

Reimplemented from QFontEngineMulti.

Definition at line 370 of file qfontengine_mac.mm.

371 {
372  return stringToCMap(str, len, glyphs, nglyphs, flags, /*logClusters=*/0, /*charAttributes=*/0, /*si=*/0);
373 }
virtual bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const

◆ stringToCMap() [2/2]

bool QFontEngineMacMulti::stringToCMap ( const QChar str,
int  len,
QGlyphLayout glyphs,
int *  nglyphs,
QTextEngine::ShaperFlags  flags,
unsigned short *  logClusters,
const HB_CharAttributes *  charAttributes,
QScriptItem  
) const

Definition at line 375 of file qfontengine_mac.mm.

377 {
378  if (*nglyphs < len) {
379  *nglyphs = len;
380  return false;
381  }
382 
383  ShaperItem shaperItem;
384  shaperItem.string = str;
385  shaperItem.from = 0;
386  shaperItem.length = len;
387  shaperItem.glyphs = *glyphs;
388  shaperItem.glyphs.numGlyphs = *nglyphs;
389  shaperItem.flags = flags;
390  shaperItem.log_clusters = logClusters;
391  shaperItem.charAttributes = charAttributes;
392 
393  const int maxChars = qMax(1,
394  int(SHRT_MAX / maxCharWidth())
395  - 10 // subtract a few to be on the safe side
396  );
397  if (len < maxChars || !charAttributes)
398  return stringToCMapInternal(str, len, glyphs, nglyphs, flags, &shaperItem);
399 
400  int charIdx = 0;
401  int glyphIdx = 0;
402  ShaperItem tmpItem = shaperItem;
403 
404  do {
405  tmpItem.from = shaperItem.from + charIdx;
406 
407  int charCount = qMin(maxChars, len - charIdx);
408 
409  int lastWhitespace = tmpItem.from + charCount - 1;
410  int lastSoftBreak = lastWhitespace;
411  int lastCharStop = lastSoftBreak;
412  for (int i = lastCharStop; i >= tmpItem.from; --i) {
413  if (tmpItem.charAttributes[i].whiteSpace) {
414  lastWhitespace = i;
415  break;
416  } if (tmpItem.charAttributes[i].lineBreakType != HB_NoBreak) {
417  lastSoftBreak = i;
418  } if (tmpItem.charAttributes[i].charStop) {
419  lastCharStop = i;
420  }
421  }
422  charCount = qMin(lastWhitespace, qMin(lastSoftBreak, lastCharStop)) - tmpItem.from + 1;
423 
424  int glyphCount = shaperItem.glyphs.numGlyphs - glyphIdx;
425  if (glyphCount <= 0)
426  return false;
427  tmpItem.length = charCount;
428  tmpItem.glyphs = shaperItem.glyphs.mid(glyphIdx, glyphCount);
429  tmpItem.log_clusters = shaperItem.log_clusters + charIdx;
430  if (!stringToCMapInternal(tmpItem.string + tmpItem.from, tmpItem.length,
431  &tmpItem.glyphs, &glyphCount, flags,
432  &tmpItem)) {
433  *nglyphs = glyphIdx + glyphCount;
434  return false;
435  }
436  for (int i = 0; i < charCount; ++i)
437  tmpItem.log_clusters[i] += glyphIdx;
438  glyphIdx += glyphCount;
439  charIdx += charCount;
440  } while (charIdx < len);
441  *nglyphs = glyphIdx;
442  glyphs->numGlyphs = glyphIdx;
443 
444  return true;
445 }
virtual int glyphCount() const
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
HB_Glyph * glyphs
bool stringToCMapInternal(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags, ShaperItem *item) const
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
virtual qreal maxCharWidth() const

◆ stringToCMapInternal()

bool QFontEngineMacMulti::stringToCMapInternal ( const QChar str,
int  len,
QGlyphLayout glyphs,
int *  nglyphs,
QTextEngine::ShaperFlags  flags,
ShaperItem item 
) const
private

Definition at line 447 of file qfontengine_mac.mm.

Referenced by stringToCMap().

448 {
449  //qDebug() << "stringToCMap" << QString(str, len);
450 
451  OSStatus e = noErr;
452 
453  e = ATSUSetTextPointerLocation(textLayout, (UniChar *)(str), 0, len, len);
454  if (e != noErr) {
455  qWarning("Qt: internal: %ld: Error ATSUSetTextPointerLocation %s: %d", long(e), __FILE__, __LINE__);
456  return false;
457  }
458 
459  QGlyphLayoutInfo nfo;
460  nfo.glyphs = glyphs;
461  nfo.numGlyphs = nglyphs;
462  nfo.callbackCalled = false;
463  nfo.flags = flags;
464  nfo.shaperItem = shaperItem;
466 
467  int prevNumGlyphs = *nglyphs;
468 
469  QVarLengthArray<int> mappedFonts(len);
470  for (int i = 0; i < len; ++i)
471  mappedFonts[i] = 0;
472  nfo.mappedFonts = mappedFonts.data();
473 
474  Q_ASSERT(sizeof(void *) <= sizeof(URefCon));
475  e = ATSUSetTextLayoutRefCon(textLayout, (URefCon)&nfo);
476  if (e != noErr) {
477  qWarning("Qt: internal: %ld: Error ATSUSetTextLayoutRefCon %s: %d", long(e), __FILE__, __LINE__);
478  return false;
479  }
480 
481  {
482  const int maxAttributeCount = 3;
483  ATSUAttributeTag tags[maxAttributeCount + 1];
484  ByteCount sizes[maxAttributeCount + 1];
485  ATSUAttributeValuePtr values[maxAttributeCount + 1];
486  int attributeCount = 0;
487 
488  tags[attributeCount] = kATSULineLayoutOptionsTag;
489  ATSLineLayoutOptions layopts = kATSLineHasNoOpticalAlignment
490  | kATSLineIgnoreFontLeading
491  | kATSLineNoSpecialJustification // we do kashidas ourselves
492  | kATSLineDisableAllJustification
493  ;
494 
496  layopts |= kATSLineNoAntiAliasing;
497 
498  if (!kerning)
499  layopts |= kATSLineDisableAllKerningAdjustments;
500 
501  values[attributeCount] = &layopts;
502  sizes[attributeCount] = sizeof(layopts);
503  ++attributeCount;
504 
505  tags[attributeCount] = kATSULayoutOperationOverrideTag;
506  ATSULayoutOperationOverrideSpecifier spec;
507  spec.operationSelector = kATSULayoutOperationPostLayoutAdjustment;
508  spec.overrideUPP = atsuPostLayoutCallback;
509  values[attributeCount] = &spec;
510  sizes[attributeCount] = sizeof(spec);
511  ++attributeCount;
512 
513  // CTWritingDirection
515  if (flags & QTextEngine::RightToLeft)
516  direction = kATSURightToLeftBaseDirection;
517  else
518  direction = kATSULeftToRightBaseDirection;
519  tags[attributeCount] = kATSULineDirectionTag;
520  values[attributeCount] = &direction;
521  sizes[attributeCount] = sizeof(direction);
522  ++attributeCount;
523 
524  Q_ASSERT(attributeCount < maxAttributeCount + 1);
525  e = ATSUSetLayoutControls(textLayout, attributeCount, tags, sizes, values);
526  if (e != noErr) {
527  qWarning("Qt: internal: %ld: Error ATSUSetLayoutControls %s: %d", long(e), __FILE__, __LINE__);
528  return false;
529  }
530 
531  }
532 
533  e = ATSUSetRunStyle(textLayout, style, 0, len);
534  if (e != noErr) {
535  qWarning("Qt: internal: %ld: Error ATSUSetRunStyle %s: %d", long(e), __FILE__, __LINE__);
536  return false;
537  }
538 
540  int pos = 0;
541  do {
542  ATSUFontID substFont = 0;
543  UniCharArrayOffset changedOffset = 0;
544  UniCharCount changeCount = 0;
545 
546  e = ATSUMatchFontsToText(textLayout, pos, len - pos,
547  &substFont, &changedOffset,
548  &changeCount);
549  if (e == kATSUFontsMatched) {
550  int fontIdx = fontIndexForFontID(substFont);
551  for (uint i = 0; i < changeCount; ++i)
552  mappedFonts[changedOffset + i] = fontIdx;
553  pos = changedOffset + changeCount;
554  ATSUSetRunStyle(textLayout, engineAt(fontIdx)->style, changedOffset, changeCount);
555  } else if (e == kATSUFontsNotMatched) {
556  pos = changedOffset + changeCount;
557  }
558  } while (pos < len && e != noErr);
559  }
560  { // trigger the a layout
561  // CFAttributedStringCreate, CTFramesetterCreateWithAttributedString (or perhaps Typesetter)
562  Rect rect;
563  e = ATSUMeasureTextImage(textLayout, kATSUFromTextBeginning, kATSUToTextEnd,
564  /*iLocationX =*/ 0, /*iLocationY =*/ 0,
565  &rect);
566  if (e != noErr) {
567  qWarning("Qt: internal: %ld: Error ATSUMeasureTextImage %s: %d", long(e), __FILE__, __LINE__);
568  return false;
569  }
570  }
571 
572  if (!nfo.callbackCalled) {
573  qWarning("Qt: internal: %ld: Error ATSUMeasureTextImage did not trigger callback %s: %d", long(e), __FILE__, __LINE__);
574  return false;
575  }
576 
577  ATSUClearLayoutCache(textLayout, kATSUFromTextBeginning);
578  if (prevNumGlyphs < *nfo.numGlyphs)
579  return false;
580  return true;
581 }
ATSUTextLayout textLayout
unsigned int styleStrategy
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
int fontIndexForFontID(ATSUFontID id) const
Q_CORE_EXPORT void qWarning(const char *,...)
unsigned int uint
Definition: qglobal.h:996
quint16 values[128]
signed long OSStatus
QFontEngineMacMulti::ShaperItem * shaperItem
QTextEngine::ShaperFlags flags
QGlyphLayout * glyphs
static OSStatus atsuPostLayoutCallback(ATSULayoutOperationSelector selector, ATSULineRef lineRef, URefCon refCon, void *operationExtraParameter, ATSULayoutOperationCallbackStatus *callbackStatus)
const QFontEngineMac * engineAt(int i) const
QFontDef fontDef
uint styleStrategy
Definition: qfont_p.h:92
Qt::LayoutDirection direction

Friends and Related Functions

◆ QFontEngineMac

friend class QFontEngineMac
friend

Definition at line 115 of file qfontengine_mac_p.h.

Referenced by fontIndexForFontID(), and QFontEngineMacMulti().

Properties

◆ fontID

ATSUFontID QFontEngineMacMulti::fontID
private

Definition at line 159 of file qfontengine_mac_p.h.

Referenced by QFontEngineMacMulti().

◆ kerning

uint QFontEngineMacMulti::kerning
private

Definition at line 160 of file qfontengine_mac_p.h.

Referenced by QFontEngineMacMulti(), and stringToCMapInternal().

◆ style

ATSUStyle QFontEngineMacMulti::style
mutableprivate

◆ textLayout

ATSUTextLayout QFontEngineMacMulti::textLayout
mutableprivate

◆ transform

CGAffineTransform QFontEngineMacMulti::transform
private

Definition at line 164 of file qfontengine_mac_p.h.

Referenced by QFontEngineMac::QFontEngineMac(), and QFontEngineMacMulti().


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