Qt 4.8
Classes | Macros | Functions | Variables
qfontengine_mac.mm File Reference
#include "qfontengine_mac_p.h"
#include <private/qapplication_p.h>
#include <private/qfontengine_p.h>
#include <private/qpainter_p.h>
#include <private/qtextengine_p.h>
#include <qbitmap.h>
#include <private/qpaintengine_mac_p.h>
#include <private/qprintengine_mac_p.h>
#include <qglobal.h>
#include <qpixmap.h>
#include <qpixmapcache.h>
#include <qvarlengtharray.h>
#include <qdebug.h>
#include <qendian.h>
#include <qmath.h>
#include <private/qimage_p.h>
#include <ApplicationServices/ApplicationServices.h>
#include <AppKit/AppKit.h>

Go to the source code of this file.

Classes

struct  QGlyphLayoutInfo
 
class  QMacFontPath
 

Macros

#define FixedToQFixed(a)   QFixed::fromFixed((a) >> 10)
 
#define QFixedToFixed(x)   ((x).value() << 10)
 

Functions

static void addGlyphsToPathHelper (ATSUStyle style, glyph_t *glyphs, QFixedPoint *positions, int numGlyphs, QPainterPath *path)
 
static OSStatus atsuPostLayoutCallback (ATSULayoutOperationSelector selector, ATSULineRef lineRef, URefCon refCon, void *operationExtraParameter, ATSULayoutOperationCallbackStatus *callbackStatus)
 
static unsigned int getChar (const QChar *str, int &i, const int len)
 

Variables

int qt_antialiasing_threshold
 

Macro Definition Documentation

◆ FixedToQFixed

#define FixedToQFixed (   a)    QFixed::fromFixed((a) >> 10)

Definition at line 73 of file qfontengine_mac.mm.

Referenced by atsuPostLayoutCallback().

◆ QFixedToFixed

#define QFixedToFixed (   x)    ((x).value() << 10)

Definition at line 74 of file qfontengine_mac.mm.

Function Documentation

◆ addGlyphsToPathHelper()

static void addGlyphsToPathHelper ( ATSUStyle  style,
glyph_t glyphs,
QFixedPoint positions,
int  numGlyphs,
QPainterPath path 
)
static

Definition at line 890 of file qfontengine_mac.mm.

Referenced by QFontEngineMac::addGlyphsToPath(), and QFontEngineMac::getUnscaledGlyph().

891 {
892  if (!numGlyphs)
893  return;
894 
895  OSStatus e;
896 
897  QMacFontPath fontpath(0, 0, path);
898  ATSCubicMoveToUPP moveTo = NewATSCubicMoveToUPP(QMacFontPath::moveTo);
899  ATSCubicLineToUPP lineTo = NewATSCubicLineToUPP(QMacFontPath::lineTo);
900  ATSCubicCurveToUPP cubicTo = NewATSCubicCurveToUPP(QMacFontPath::cubicTo);
901  ATSCubicClosePathUPP closePath = NewATSCubicClosePathUPP(QMacFontPath::closePath);
902 
903  // CTFontCreatePathForGlyph
904  for (int i = 0; i < numGlyphs; ++i) {
905  GlyphID glyph = glyphs[i];
906 
907  fontpath.setPosition(positions[i].x.toReal(), positions[i].y.toReal());
908  ATSUGlyphGetCubicPaths(style, glyph, moveTo, lineTo,
909  cubicTo, closePath, &fontpath, &e);
910  }
911 
912  DisposeATSCubicMoveToUPP(moveTo);
913  DisposeATSCubicLineToUPP(lineTo);
914  DisposeATSCubicCurveToUPP(cubicTo);
915  DisposeATSCubicClosePathUPP(closePath);
916 }
static OSStatus closePath(void *)
static OSStatus lineTo(const Float32Point *, void *)
static OSStatus cubicTo(const Float32Point *, const Float32Point *, const Float32Point *, void *)
static OSStatus moveTo(const Float32Point *, void *)
QFixed y
Definition: qfixed_p.h:191
signed long OSStatus
quint16 GlyphID
qreal toReal() const
Definition: qfixed_p.h:77

◆ atsuPostLayoutCallback()

static OSStatus atsuPostLayoutCallback ( ATSULayoutOperationSelector  selector,
ATSULineRef  lineRef,
URefCon  refCon,
void *  operationExtraParameter,
ATSULayoutOperationCallbackStatus *  callbackStatus 
)
static

Definition at line 221 of file qfontengine_mac.mm.

Referenced by QFontEngineMacMulti::stringToCMapInternal().

223 {
224  Q_UNUSED(selector);
225  Q_UNUSED(operationExtraParameter);
226 
227  QGlyphLayoutInfo *nfo = reinterpret_cast<QGlyphLayoutInfo *>(refCon);
228  nfo->callbackCalled = true;
229 
230  ATSLayoutRecord *layoutData = 0;
231  ItemCount itemCount = 0;
232 
233  OSStatus e = noErr;
234  e = ATSUDirectGetLayoutDataArrayPtrFromLineRef(lineRef, kATSUDirectDataLayoutRecordATSLayoutRecordCurrent,
235  /*iCreate =*/ false,
236  (void **) &layoutData,
237  &itemCount);
238  if (e != noErr)
239  return e;
240 
241  *nfo->numGlyphs = itemCount - 1;
242 
243  Fixed *baselineDeltas = 0;
244 
245  e = ATSUDirectGetLayoutDataArrayPtrFromLineRef(lineRef, kATSUDirectDataBaselineDeltaFixedArray,
246  /*iCreate =*/ true,
247  (void **) &baselineDeltas,
248  &itemCount);
249  if (e != noErr)
250  return e;
251 
252  int nextCharStop = -1;
253  int currentClusterGlyph = -1; // first glyph in log cluster
255  if (item->charAttributes) {
256  item = nfo->shaperItem;
257 #if !defined(QT_NO_DEBUG)
258  int surrogates = 0;
259  const QChar *str = item->string;
260  for (int i = item->from; i < item->from + item->length - 1; ++i)
261  surrogates += (str[i].isHighSurrogate() && str[i+1].isLowSurrogate());
262 #endif
263  for (nextCharStop = item->from; nextCharStop < item->from + item->length; ++nextCharStop)
264  if (item->charAttributes[nextCharStop].charStop)
265  break;
266  nextCharStop -= item->from;
267  }
268 
269  nfo->glyphs->attributes[0].clusterStart = true;
270  int glyphIdx = 0;
271  int glyphIncrement = 1;
272  if (nfo->flags & QTextEngine::RightToLeft) {
273  glyphIdx = itemCount - 2;
274  glyphIncrement = -1;
275  }
276  for (int i = 0; i < *nfo->numGlyphs; ++i, glyphIdx += glyphIncrement) {
277 
278  int charOffset = layoutData[glyphIdx].originalOffset / sizeof(UniChar);
279  const int fontIdx = nfo->mappedFonts[charOffset];
280 
281  ATSGlyphRef glyphId = layoutData[glyphIdx].glyphID;
282 
283  QFixed yAdvance = FixedToQFixed(baselineDeltas[glyphIdx]);
284  QFixed xAdvance = FixedToQFixed(layoutData[glyphIdx + 1].realPos - layoutData[glyphIdx].realPos);
285 
287  yAdvance = yAdvance.round();
288  xAdvance = xAdvance.round();
289  }
290 
291  if (glyphId != 0xffff || i == 0) {
292  if (i < nfo->glyphs->numGlyphs)
293  {
294  nfo->glyphs->glyphs[i] = (glyphId & 0x00ffffff) | (fontIdx << 24);
295 
296  nfo->glyphs->advances_y[i] = yAdvance;
297  nfo->glyphs->advances_x[i] = xAdvance;
298  }
299  } else {
300  // ATSUI gives us 0xffff as glyph id at the index in the glyph array for
301  // a character position that maps to a ligtature. Such a glyph id does not
302  // result in any visual glyph, but it may have an advance, which is why we
303  // sum up the glyph advances.
304  --i;
305  nfo->glyphs->advances_y[i] += yAdvance;
306  nfo->glyphs->advances_x[i] += xAdvance;
307  *nfo->numGlyphs -= 1;
308  }
309 
310  if (item->log_clusters) {
311  if (charOffset >= nextCharStop) {
312  nfo->glyphs->attributes[i].clusterStart = true;
313  currentClusterGlyph = i;
314 
315  ++nextCharStop;
316  for (; nextCharStop < item->length; ++nextCharStop)
317  if (item->charAttributes[item->from + nextCharStop].charStop)
318  break;
319  } else {
320  if (currentClusterGlyph == -1)
321  currentClusterGlyph = i;
322  }
323  item->log_clusters[charOffset] = currentClusterGlyph;
324 
325  // surrogate handling
326  if (charOffset < item->length - 1) {
327  QChar current = item->string[item->from + charOffset];
328  QChar next = item->string[item->from + charOffset + 1];
329  if (current.isHighSurrogate() && next.isLowSurrogate())
330  item->log_clusters[charOffset + 1] = currentClusterGlyph;
331  }
332  }
333  }
334 
335  /*
336  if (item) {
337  qDebug() << "resulting logclusters:";
338  for (int i = 0; i < item->length; ++i)
339  qDebug() << "logClusters[" << i << "] =" << item->log_clusters[i];
340  qDebug() << "clusterstarts:";
341  for (int i = 0; i < *nfo->numGlyphs; ++i)
342  qDebug() << "clusterStart[" << i << "] =" << nfo->glyphs[i].attributes.clusterStart;
343  }
344  */
345 
346  ATSUDirectReleaseLayoutDataArrayPtr(lineRef, kATSUDirectDataBaselineDeltaFixedArray,
347  (void **) &baselineDeltas);
348 
349  ATSUDirectReleaseLayoutDataArrayPtr(lineRef, kATSUDirectDataLayoutRecordATSLayoutRecordCurrent,
350  (void **) &layoutData);
351 
352  *callbackStatus = kATSULayoutOperationCallbackStatusHandled;
353  return noErr;
354 }
#define FixedToQFixed(a)
QFixed * advances_y
QFixed * advances_x
HB_Glyph * glyphs
bool isLowSurrogate() const
Returns true if the QChar is the low part of a utf16 surrogate (ie.
Definition: qchar.h:279
unsigned int styleStrategy
bool isHighSurrogate() const
Returns true if the QChar is the high part of a utf16 surrogate (ie.
Definition: qchar.h:276
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
QFixed round() const
Definition: qfixed_p.h:80
signed long OSStatus
const HB_CharAttributes * charAttributes
QFontEngineMacMulti::ShaperItem * shaperItem
QTextEngine::ShaperFlags flags
QGlyphLayout * glyphs
HB_GlyphAttributes * attributes
#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

◆ getChar()

static unsigned int getChar ( const QChar str,
int &  i,
const int  len 
)
inlinestatic

Definition at line 735 of file qfontengine_mac.mm.

Referenced by QFontEngineMac::stringToCMap().

736 {
737  uint ucs4 = str[i].unicode();
738  if (str[i].isHighSurrogate() && i < len-1 && str[i+1].isLowSurrogate()) {
739  ++i;
740  ucs4 = QChar::surrogateToUcs4(ucs4, str[i].unicode());
741  }
742  return ucs4;
743 }
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
unsigned int uint
Definition: qglobal.h:996
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...
Definition: qchar.h:297

Variable Documentation

◆ qt_antialiasing_threshold

int qt_antialiasing_threshold

Definition at line 495 of file qapplication.cpp.

Referenced by QFontEngineMac::imageForGlyph().