author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 06 Jul 2010 15:10:48 +0300 | |
changeset 30 | 5dc02b23752f |
parent 18 | 2f34d5167611 |
child 33 | 3e2da88830cd |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtGui module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include <private/qapplication_p.h> |
|
43 |
#include <private/qfontengine_p.h> |
|
44 |
#include <private/qpainter_p.h> |
|
45 |
#include <private/qtextengine_p.h> |
|
46 |
#include <qbitmap.h> |
|
47 |
#include <private/qpaintengine_mac_p.h> |
|
48 |
#include <private/qprintengine_mac_p.h> |
|
49 |
#include <private/qpdf_p.h> |
|
50 |
#include <qglobal.h> |
|
51 |
#include <qpixmap.h> |
|
52 |
#include <qpixmapcache.h> |
|
53 |
#include <qvarlengtharray.h> |
|
54 |
#include <qdebug.h> |
|
55 |
#include <qendian.h> |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
56 |
#include <qmath.h> |
0 | 57 |
|
58 |
#include <ApplicationServices/ApplicationServices.h> |
|
59 |
#include <AppKit/AppKit.h> |
|
60 |
||
61 |
QT_BEGIN_NAMESPACE |
|
62 |
||
63 |
/***************************************************************************** |
|
64 |
QFontEngine debug facilities |
|
65 |
*****************************************************************************/ |
|
66 |
//#define DEBUG_ADVANCES |
|
67 |
||
68 |
extern int qt_antialiasing_threshold; // QApplication.cpp |
|
69 |
||
70 |
#ifndef FixedToQFixed |
|
71 |
#define FixedToQFixed(a) QFixed::fromFixed((a) >> 10) |
|
72 |
#define QFixedToFixed(x) ((x).value() << 10) |
|
73 |
#endif |
|
74 |
||
75 |
class QMacFontPath |
|
76 |
{ |
|
77 |
float x, y; |
|
78 |
QPainterPath *path; |
|
79 |
public: |
|
80 |
inline QMacFontPath(float _x, float _y, QPainterPath *_path) : x(_x), y(_y), path(_path) { } |
|
81 |
inline void setPosition(float _x, float _y) { x = _x; y = _y; } |
|
82 |
inline void advance(float _x) { x += _x; } |
|
83 |
static OSStatus lineTo(const Float32Point *, void *); |
|
84 |
static OSStatus cubicTo(const Float32Point *, const Float32Point *, |
|
85 |
const Float32Point *, void *); |
|
86 |
static OSStatus moveTo(const Float32Point *, void *); |
|
87 |
static OSStatus closePath(void *); |
|
88 |
}; |
|
89 |
||
90 |
OSStatus QMacFontPath::lineTo(const Float32Point *pt, void *data) |
|
91 |
||
92 |
{ |
|
93 |
QMacFontPath *p = static_cast<QMacFontPath*>(data); |
|
94 |
p->path->lineTo(p->x + pt->x, p->y + pt->y); |
|
95 |
return noErr; |
|
96 |
} |
|
97 |
||
98 |
OSStatus QMacFontPath::cubicTo(const Float32Point *cp1, const Float32Point *cp2, |
|
99 |
const Float32Point *ep, void *data) |
|
100 |
||
101 |
{ |
|
102 |
QMacFontPath *p = static_cast<QMacFontPath*>(data); |
|
103 |
p->path->cubicTo(p->x + cp1->x, p->y + cp1->y, |
|
104 |
p->x + cp2->x, p->y + cp2->y, |
|
105 |
p->x + ep->x, p->y + ep->y); |
|
106 |
return noErr; |
|
107 |
} |
|
108 |
||
109 |
OSStatus QMacFontPath::moveTo(const Float32Point *pt, void *data) |
|
110 |
{ |
|
111 |
QMacFontPath *p = static_cast<QMacFontPath*>(data); |
|
112 |
p->path->moveTo(p->x + pt->x, p->y + pt->y); |
|
113 |
return noErr; |
|
114 |
} |
|
115 |
||
116 |
OSStatus QMacFontPath::closePath(void *data) |
|
117 |
{ |
|
118 |
static_cast<QMacFontPath*>(data)->path->closeSubpath(); |
|
119 |
return noErr; |
|
120 |
} |
|
121 |
||
122 |
||
123 |
||
124 |
void qmacfontengine_gamma_correct(QImage *image) |
|
125 |
{ |
|
126 |
extern uchar qt_pow_rgb_gamma[256]; |
|
127 |
||
128 |
// gamma correct the pixels back to linear color space... |
|
129 |
int h = image->height(); |
|
130 |
int w = image->width(); |
|
131 |
||
132 |
for (int y=0; y<h; ++y) { |
|
133 |
uint *pixels = (uint *) image->scanLine(y); |
|
134 |
for (int x=0; x<w; ++x) { |
|
135 |
uint p = pixels[x]; |
|
136 |
uint r = qt_pow_rgb_gamma[qRed(p)]; |
|
137 |
uint g = qt_pow_rgb_gamma[qGreen(p)]; |
|
138 |
uint b = qt_pow_rgb_gamma[qBlue(p)]; |
|
139 |
pixels[x] = (r << 16) | (g << 8) | b | 0xff000000; |
|
140 |
} |
|
141 |
} |
|
142 |
} |
|
143 |
||
144 |
||
145 |
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 |
|
146 |
QCoreTextFontEngineMulti::QCoreTextFontEngineMulti(const ATSFontFamilyRef &, const ATSFontRef &atsFontRef, const QFontDef &fontDef, bool kerning) |
|
147 |
: QFontEngineMulti(0) |
|
148 |
{ |
|
149 |
this->fontDef = fontDef; |
|
150 |
CTFontSymbolicTraits symbolicTraits = 0; |
|
151 |
if (fontDef.weight >= QFont::Bold) |
|
152 |
symbolicTraits |= kCTFontBoldTrait; |
|
153 |
switch (fontDef.style) { |
|
154 |
case QFont::StyleNormal: |
|
155 |
break; |
|
156 |
case QFont::StyleItalic: |
|
157 |
case QFont::StyleOblique: |
|
158 |
symbolicTraits |= kCTFontItalicTrait; |
|
159 |
break; |
|
160 |
} |
|
161 |
||
162 |
QCFString name; |
|
163 |
ATSFontGetName(atsFontRef, kATSOptionFlagsDefault, &name); |
|
164 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
165 |
transform = CGAffineTransformIdentity; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
166 |
if (fontDef.stretch != 100) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
167 |
transform = CGAffineTransformMakeScale(float(fontDef.stretch) / float(100), 1); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
168 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
169 |
|
0 | 170 |
QCFType<CTFontDescriptorRef> descriptor = CTFontDescriptorCreateWithNameAndSize(name, fontDef.pixelSize); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
171 |
QCFType<CTFontRef> baseFont = CTFontCreateWithFontDescriptor(descriptor, fontDef.pixelSize, &transform); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
172 |
ctfont = CTFontCreateCopyWithSymbolicTraits(baseFont, fontDef.pixelSize, &transform, symbolicTraits, symbolicTraits); |
0 | 173 |
|
174 |
// CTFontCreateCopyWithSymbolicTraits returns NULL if we ask for a trait that does |
|
175 |
// not exist for the given font. (for example italic) |
|
176 |
if (ctfont == 0) { |
|
177 |
ctfont = baseFont; |
|
178 |
CFRetain(ctfont); |
|
179 |
} |
|
180 |
||
181 |
attributeDict = CFDictionaryCreateMutable(0, 2, |
|
182 |
&kCFTypeDictionaryKeyCallBacks, |
|
183 |
&kCFTypeDictionaryValueCallBacks); |
|
184 |
CFDictionaryAddValue(attributeDict, NSFontAttributeName, ctfont); |
|
185 |
if (!kerning) { |
|
186 |
float zero = 0.0; |
|
187 |
QCFType<CFNumberRef> noKern = CFNumberCreate(kCFAllocatorDefault, kCFNumberFloatType, &zero); |
|
188 |
CFDictionaryAddValue(attributeDict, kCTKernAttributeName, noKern); |
|
189 |
} |
|
190 |
||
191 |
QCoreTextFontEngine *fe = new QCoreTextFontEngine(ctfont, fontDef, this); |
|
192 |
fe->ref.ref(); |
|
193 |
engines.append(fe); |
|
194 |
||
195 |
} |
|
196 |
||
197 |
QCoreTextFontEngineMulti::~QCoreTextFontEngineMulti() |
|
198 |
{ |
|
199 |
CFRelease(ctfont); |
|
200 |
} |
|
201 |
||
202 |
uint QCoreTextFontEngineMulti::fontIndexForFont(CTFontRef id) const |
|
203 |
{ |
|
204 |
for (int i = 0; i < engines.count(); ++i) { |
|
205 |
if (CFEqual(engineAt(i)->ctfont, id)) |
|
206 |
return i; |
|
207 |
} |
|
208 |
||
209 |
QCoreTextFontEngineMulti *that = const_cast<QCoreTextFontEngineMulti *>(this); |
|
210 |
QCoreTextFontEngine *fe = new QCoreTextFontEngine(id, fontDef, that); |
|
211 |
fe->ref.ref(); |
|
212 |
that->engines.append(fe); |
|
213 |
return engines.count() - 1; |
|
214 |
} |
|
215 |
||
216 |
bool QCoreTextFontEngineMulti::stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags, |
|
217 |
unsigned short *logClusters, const HB_CharAttributes *) const |
|
218 |
{ |
|
219 |
QCFType<CFStringRef> cfstring = CFStringCreateWithCharactersNoCopy(0, |
|
220 |
reinterpret_cast<const UniChar *>(str), |
|
221 |
len, kCFAllocatorNull); |
|
222 |
QCFType<CFAttributedStringRef> attributedString = CFAttributedStringCreate(0, cfstring, attributeDict); |
|
223 |
QCFType<CTTypesetterRef> typeSetter = CTTypesetterCreateWithAttributedString(attributedString); |
|
224 |
CFRange range = {0, 0}; |
|
225 |
QCFType<CTLineRef> line = CTTypesetterCreateLine(typeSetter, range); |
|
226 |
CFArrayRef array = CTLineGetGlyphRuns(line); |
|
227 |
uint arraySize = CFArrayGetCount(array); |
|
228 |
glyph_t *outGlyphs = glyphs->glyphs; |
|
229 |
HB_GlyphAttributes *outAttributes = glyphs->attributes; |
|
230 |
QFixed *outAdvances_x = glyphs->advances_x; |
|
231 |
QFixed *outAdvances_y = glyphs->advances_y; |
|
232 |
glyph_t *initialGlyph = outGlyphs; |
|
233 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
234 |
if (arraySize == 0) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
235 |
// CoreText failed to shape the text we gave it, so we assume one glyph |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
236 |
// per character and build a list of invalid glyphs with zero advance |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
237 |
*nglyphs = len; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
238 |
for (int i = 0; i < len; ++i) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
239 |
outGlyphs[i] = 0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
240 |
logClusters[i] = i; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
241 |
outAdvances_x[i] = QFixed(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
242 |
outAdvances_y[i] = QFixed(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
243 |
outAttributes[i].clusterStart = true; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
244 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
245 |
return true; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
246 |
} |
0 | 247 |
|
248 |
const bool rtl = (CTRunGetStatus(static_cast<CTRunRef>(CFArrayGetValueAtIndex(array, 0))) & kCTRunStatusRightToLeft); |
|
249 |
||
250 |
bool outOBounds = false; |
|
251 |
for (uint i = 0; i < arraySize; ++i) { |
|
252 |
CTRunRef run = static_cast<CTRunRef>(CFArrayGetValueAtIndex(array, rtl ? (arraySize - 1 - i) : i)); |
|
253 |
CFIndex glyphCount = CTRunGetGlyphCount(run); |
|
254 |
if (glyphCount == 0) |
|
255 |
continue; |
|
256 |
||
257 |
Q_ASSERT((CTRunGetStatus(run) & kCTRunStatusRightToLeft) == rtl); |
|
258 |
||
259 |
if (!outOBounds && outGlyphs + glyphCount - initialGlyph > *nglyphs) { |
|
260 |
outOBounds = true; |
|
261 |
} |
|
262 |
if (!outOBounds) { |
|
263 |
CFDictionaryRef runAttribs = CTRunGetAttributes(run); |
|
264 |
//NSLog(@"Dictionary %@", runAttribs); |
|
265 |
if (!runAttribs) |
|
266 |
runAttribs = attributeDict; |
|
267 |
CTFontRef runFont = static_cast<CTFontRef>(CFDictionaryGetValue(runAttribs, NSFontAttributeName)); |
|
268 |
const uint fontIndex = (fontIndexForFont(runFont) << 24); |
|
269 |
//NSLog(@"Run Font Name = %@", CTFontCopyFamilyName(runFont)); |
|
270 |
QVarLengthArray<CGGlyph, 512> cgglyphs(0); |
|
271 |
const CGGlyph *tmpGlyphs = CTRunGetGlyphsPtr(run); |
|
272 |
if (!tmpGlyphs) { |
|
273 |
cgglyphs.resize(glyphCount); |
|
274 |
CTRunGetGlyphs(run, range, cgglyphs.data()); |
|
275 |
tmpGlyphs = cgglyphs.constData(); |
|
276 |
} |
|
277 |
QVarLengthArray<CGPoint, 512> cgpoints(0); |
|
278 |
const CGPoint *tmpPoints = CTRunGetPositionsPtr(run); |
|
279 |
if (!tmpPoints) { |
|
280 |
cgpoints.resize(glyphCount); |
|
281 |
CTRunGetPositions(run, range, cgpoints.data()); |
|
282 |
tmpPoints = cgpoints.constData(); |
|
283 |
} |
|
284 |
||
285 |
const int rtlOffset = rtl ? (glyphCount - 1) : 0; |
|
286 |
const int rtlSign = rtl ? -1 : 1; |
|
287 |
||
288 |
if (logClusters) { |
|
289 |
CFRange stringRange = CTRunGetStringRange(run); |
|
290 |
QVarLengthArray<CFIndex, 512> stringIndices(0); |
|
291 |
const CFIndex *tmpIndices = CTRunGetStringIndicesPtr(run); |
|
292 |
if (!tmpIndices) { |
|
293 |
stringIndices.resize(glyphCount); |
|
294 |
CTRunGetStringIndices(run, range, stringIndices.data()); |
|
295 |
tmpIndices = stringIndices.constData(); |
|
296 |
} |
|
297 |
||
298 |
const int firstGlyphIndex = outGlyphs - initialGlyph; |
|
299 |
outAttributes[0].clusterStart = true; |
|
300 |
||
301 |
CFIndex k = 0; |
|
302 |
CFIndex i = 0; |
|
303 |
for (i = stringRange.location; |
|
304 |
(i < stringRange.location + stringRange.length) && (k < glyphCount); ++i) { |
|
305 |
if (tmpIndices[k * rtlSign + rtlOffset] == i || i == stringRange.location) { |
|
306 |
logClusters[i] = k + firstGlyphIndex; |
|
307 |
outAttributes[k].clusterStart = true; |
|
308 |
++k; |
|
309 |
} else { |
|
310 |
logClusters[i] = k + firstGlyphIndex - 1; |
|
311 |
} |
|
312 |
} |
|
313 |
// in case of a ligature at the end, fill the remaining logcluster entries |
|
314 |
for (;i < stringRange.location + stringRange.length; i++) { |
|
315 |
logClusters[i] = k + firstGlyphIndex - 1; |
|
316 |
} |
|
317 |
} |
|
318 |
for (CFIndex i = 0; i < glyphCount - 1; ++i) { |
|
319 |
int idx = rtlOffset + rtlSign * i; |
|
320 |
outGlyphs[idx] = tmpGlyphs[i] | fontIndex; |
|
321 |
outAdvances_x[idx] = QFixed::fromReal(tmpPoints[i + 1].x - tmpPoints[i].x); |
|
322 |
outAdvances_y[idx] = QFixed::fromReal(tmpPoints[i + 1].y - tmpPoints[i].y); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
323 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
324 |
if (fontDef.styleStrategy & QFont::ForceIntegerMetrics) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
325 |
outAdvances_x[idx] = outAdvances_x[idx].round(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
326 |
outAdvances_y[idx] = outAdvances_y[idx].round(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
327 |
} |
0 | 328 |
} |
329 |
CGSize lastGlyphAdvance; |
|
330 |
CTFontGetAdvancesForGlyphs(runFont, kCTFontHorizontalOrientation, tmpGlyphs + glyphCount - 1, &lastGlyphAdvance, 1); |
|
331 |
||
332 |
outGlyphs[rtl ? 0 : (glyphCount - 1)] = tmpGlyphs[glyphCount - 1] | fontIndex; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
333 |
outAdvances_x[rtl ? 0 : (glyphCount - 1)] = |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
334 |
(fontDef.styleStrategy & QFont::ForceIntegerMetrics) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
335 |
? QFixed::fromReal(lastGlyphAdvance.width).round() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
336 |
: QFixed::fromReal(lastGlyphAdvance.width); |
0 | 337 |
} |
338 |
outGlyphs += glyphCount; |
|
339 |
outAttributes += glyphCount; |
|
340 |
outAdvances_x += glyphCount; |
|
341 |
outAdvances_y += glyphCount; |
|
342 |
} |
|
343 |
*nglyphs = (outGlyphs - initialGlyph); |
|
344 |
return !outOBounds; |
|
345 |
} |
|
346 |
||
347 |
bool QCoreTextFontEngineMulti::stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, |
|
348 |
int *nglyphs, QTextEngine::ShaperFlags flags) const |
|
349 |
{ |
|
350 |
return stringToCMap(str, len, glyphs, nglyphs, flags, 0, 0); |
|
351 |
} |
|
352 |
||
353 |
void QCoreTextFontEngineMulti::recalcAdvances(int , QGlyphLayout *, QTextEngine::ShaperFlags) const |
|
354 |
{ |
|
355 |
} |
|
356 |
void QCoreTextFontEngineMulti::doKerning(int , QGlyphLayout *, QTextEngine::ShaperFlags) const |
|
357 |
{ |
|
358 |
} |
|
359 |
||
360 |
void QCoreTextFontEngineMulti::loadEngine(int) |
|
361 |
{ |
|
362 |
// Do nothing |
|
363 |
Q_ASSERT(false); |
|
364 |
} |
|
365 |
||
366 |
||
367 |
||
368 |
QCoreTextFontEngine::QCoreTextFontEngine(CTFontRef font, const QFontDef &def, |
|
369 |
QCoreTextFontEngineMulti *multiEngine) |
|
370 |
{ |
|
371 |
fontDef = def; |
|
372 |
parentEngine = multiEngine; |
|
373 |
synthesisFlags = 0; |
|
374 |
ctfont = font; |
|
375 |
CFRetain(ctfont); |
|
376 |
ATSFontRef atsfont = CTFontGetPlatformFont(ctfont, 0); |
|
377 |
cgFont = CGFontCreateWithPlatformFont(&atsfont); |
|
378 |
CTFontSymbolicTraits traits = CTFontGetSymbolicTraits(ctfont); |
|
379 |
if (fontDef.weight >= QFont::Bold && !(traits & kCTFontBoldTrait)) { |
|
380 |
synthesisFlags |= SynthesizedBold; |
|
381 |
} |
|
382 |
||
383 |
if (fontDef.style != QFont::StyleNormal && !(traits & kCTFontItalicTrait)) { |
|
384 |
synthesisFlags |= SynthesizedItalic; |
|
385 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
386 |
transform = CGAffineTransformIdentity; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
387 |
if (fontDef.stretch != 100) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
388 |
transform = CGAffineTransformMakeScale(float(fontDef.stretch) / float(100), 1); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
389 |
} |
0 | 390 |
QByteArray os2Table = getSfntTable(MAKE_TAG('O', 'S', '/', '2')); |
391 |
if (os2Table.size() >= 10) |
|
392 |
fsType = qFromBigEndian<quint16>(reinterpret_cast<const uchar *>(os2Table.constData() + 8)); |
|
393 |
} |
|
394 |
||
395 |
QCoreTextFontEngine::~QCoreTextFontEngine() |
|
396 |
{ |
|
397 |
CFRelease(ctfont); |
|
398 |
CFRelease(cgFont); |
|
399 |
} |
|
400 |
||
401 |
bool QCoreTextFontEngine::stringToCMap(const QChar *, int, QGlyphLayout *, int *, QTextEngine::ShaperFlags) const |
|
402 |
{ |
|
403 |
return false; |
|
404 |
} |
|
405 |
||
406 |
glyph_metrics_t QCoreTextFontEngine::boundingBox(const QGlyphLayout &glyphs) |
|
407 |
{ |
|
408 |
QFixed w; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
409 |
for (int i = 0; i < glyphs.numGlyphs; ++i) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
410 |
w += (fontDef.styleStrategy & QFont::ForceIntegerMetrics) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
411 |
? glyphs.effectiveAdvance(i).round() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
412 |
: glyphs.effectiveAdvance(i); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
413 |
} |
0 | 414 |
return glyph_metrics_t(0, -(ascent()), w, ascent()+descent(), w, 0); |
415 |
} |
|
416 |
glyph_metrics_t QCoreTextFontEngine::boundingBox(glyph_t glyph) |
|
417 |
{ |
|
418 |
glyph_metrics_t ret; |
|
419 |
CGGlyph g = glyph; |
|
420 |
CGRect rect = CTFontGetBoundingRectsForGlyphs(ctfont, kCTFontHorizontalOrientation, &g, 0, 1); |
|
421 |
ret.width = QFixed::fromReal(rect.size.width); |
|
422 |
ret.height = QFixed::fromReal(rect.size.height); |
|
423 |
ret.x = QFixed::fromReal(rect.origin.x); |
|
424 |
ret.y = -QFixed::fromReal(rect.origin.y) - ret.height; |
|
425 |
CGSize advances[1]; |
|
426 |
CTFontGetAdvancesForGlyphs(ctfont, kCTFontHorizontalOrientation, &g, advances, 1); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
427 |
ret.xoff = QFixed::fromReal(advances[0].width); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
428 |
ret.yoff = QFixed::fromReal(advances[0].height); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
429 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
430 |
if (fontDef.styleStrategy & QFont::ForceIntegerMetrics) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
431 |
ret.xoff = ret.xoff.round(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
432 |
ret.yoff = ret.yoff.round(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
433 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
434 |
|
0 | 435 |
return ret; |
436 |
} |
|
437 |
||
438 |
QFixed QCoreTextFontEngine::ascent() const |
|
439 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
440 |
return (fontDef.styleStrategy & QFont::ForceIntegerMetrics) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
441 |
? QFixed::fromReal(CTFontGetAscent(ctfont)).round() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
442 |
: QFixed::fromReal(CTFontGetAscent(ctfont)); |
0 | 443 |
} |
444 |
QFixed QCoreTextFontEngine::descent() const |
|
445 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
446 |
QFixed d = QFixed::fromReal(CTFontGetDescent(ctfont)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
447 |
if (fontDef.styleStrategy & QFont::ForceIntegerMetrics) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
448 |
d = d.round(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
449 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
450 |
// subtract a pixel to even out the historical +1 in QFontMetrics::height(). |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
451 |
// Fix in Qt 5. |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
452 |
return d - 1; |
0 | 453 |
} |
454 |
QFixed QCoreTextFontEngine::leading() const |
|
455 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
456 |
return (fontDef.styleStrategy & QFont::ForceIntegerMetrics) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
457 |
? QFixed::fromReal(CTFontGetLeading(ctfont)).round() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
458 |
: QFixed::fromReal(CTFontGetLeading(ctfont)); |
0 | 459 |
} |
460 |
QFixed QCoreTextFontEngine::xHeight() const |
|
461 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
462 |
return (fontDef.styleStrategy & QFont::ForceIntegerMetrics) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
463 |
? QFixed::fromReal(CTFontGetXHeight(ctfont)).round() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
464 |
: QFixed::fromReal(CTFontGetXHeight(ctfont)); |
0 | 465 |
} |
466 |
QFixed QCoreTextFontEngine::averageCharWidth() const |
|
467 |
{ |
|
468 |
// ### Need to implement properly and get the information from the OS/2 Table. |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
469 |
return (fontDef.styleStrategy & QFont::ForceIntegerMetrics) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
470 |
? QFontEngine::averageCharWidth().round() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
471 |
: QFontEngine::averageCharWidth(); |
0 | 472 |
} |
473 |
||
474 |
qreal QCoreTextFontEngine::maxCharWidth() const |
|
475 |
{ |
|
476 |
// ### Max Help! |
|
477 |
return 0; |
|
478 |
||
479 |
} |
|
480 |
qreal QCoreTextFontEngine::minLeftBearing() const |
|
481 |
{ |
|
482 |
// ### Min Help! |
|
483 |
return 0; |
|
484 |
||
485 |
} |
|
486 |
qreal QCoreTextFontEngine::minRightBearing() const |
|
487 |
{ |
|
488 |
// ### Max Help! (even thought it's right) |
|
489 |
return 0; |
|
490 |
||
491 |
} |
|
492 |
||
493 |
void QCoreTextFontEngine::draw(CGContextRef ctx, qreal x, qreal y, const QTextItemInt &ti, int paintDeviceHeight) |
|
494 |
{ |
|
495 |
QVarLengthArray<QFixedPoint> positions; |
|
496 |
QVarLengthArray<glyph_t> glyphs; |
|
497 |
QTransform matrix; |
|
498 |
matrix.translate(x, y); |
|
499 |
getGlyphPositions(ti.glyphs, matrix, ti.flags, glyphs, positions); |
|
500 |
if (glyphs.size() == 0) |
|
501 |
return; |
|
502 |
||
503 |
CGContextSetFontSize(ctx, fontDef.pixelSize); |
|
504 |
||
505 |
CGAffineTransform oldTextMatrix = CGContextGetTextMatrix(ctx); |
|
506 |
||
507 |
CGAffineTransform cgMatrix = CGAffineTransformMake(1, 0, 0, -1, 0, -paintDeviceHeight); |
|
508 |
||
509 |
CGAffineTransformConcat(cgMatrix, oldTextMatrix); |
|
510 |
||
511 |
if (synthesisFlags & QFontEngine::SynthesizedItalic) |
|
512 |
cgMatrix = CGAffineTransformConcat(cgMatrix, CGAffineTransformMake(1, 0, -tanf(14 * acosf(0) / 90), 1, 0, 0)); |
|
513 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
514 |
cgMatrix = CGAffineTransformConcat(cgMatrix, transform); |
0 | 515 |
|
516 |
CGContextSetTextMatrix(ctx, cgMatrix); |
|
517 |
||
518 |
CGContextSetTextDrawingMode(ctx, kCGTextFill); |
|
519 |
||
520 |
||
521 |
QVarLengthArray<CGSize> advances(glyphs.size()); |
|
522 |
QVarLengthArray<CGGlyph> cgGlyphs(glyphs.size()); |
|
523 |
||
524 |
for (int i = 0; i < glyphs.size() - 1; ++i) { |
|
525 |
advances[i].width = (positions[i + 1].x - positions[i].x).toReal(); |
|
526 |
advances[i].height = (positions[i + 1].y - positions[i].y).toReal(); |
|
527 |
cgGlyphs[i] = glyphs[i]; |
|
528 |
} |
|
529 |
advances[glyphs.size() - 1].width = 0; |
|
530 |
advances[glyphs.size() - 1].height = 0; |
|
531 |
cgGlyphs[glyphs.size() - 1] = glyphs[glyphs.size() - 1]; |
|
532 |
||
533 |
CGContextSetFont(ctx, cgFont); |
|
534 |
//NSLog(@"Font inDraw %@ ctfont %@", CGFontCopyFullName(cgFont), CTFontCopyFamilyName(ctfont)); |
|
535 |
||
536 |
CGContextSetTextPosition(ctx, positions[0].x.toReal(), positions[0].y.toReal()); |
|
537 |
||
538 |
CGContextShowGlyphsWithAdvances(ctx, cgGlyphs.data(), advances.data(), glyphs.size()); |
|
539 |
||
540 |
if (synthesisFlags & QFontEngine::SynthesizedBold) { |
|
541 |
CGContextSetTextPosition(ctx, positions[0].x.toReal() + 0.5 * lineThickness().toReal(), |
|
542 |
positions[0].y.toReal()); |
|
543 |
||
544 |
CGContextShowGlyphsWithAdvances(ctx, cgGlyphs.data(), advances.data(), glyphs.size()); |
|
545 |
} |
|
546 |
||
547 |
CGContextSetTextMatrix(ctx, oldTextMatrix); |
|
548 |
} |
|
549 |
||
550 |
struct ConvertPathInfo |
|
551 |
{ |
|
552 |
ConvertPathInfo(QPainterPath *newPath, const QPointF &newPos) : path(newPath), pos(newPos) {} |
|
553 |
QPainterPath *path; |
|
554 |
QPointF pos; |
|
555 |
}; |
|
556 |
||
557 |
static void convertCGPathToQPainterPath(void *info, const CGPathElement *element) |
|
558 |
{ |
|
559 |
ConvertPathInfo *myInfo = static_cast<ConvertPathInfo *>(info); |
|
560 |
switch(element->type) { |
|
561 |
case kCGPathElementMoveToPoint: |
|
562 |
myInfo->path->moveTo(element->points[0].x + myInfo->pos.x(), |
|
563 |
element->points[0].y + myInfo->pos.y()); |
|
564 |
break; |
|
565 |
case kCGPathElementAddLineToPoint: |
|
566 |
myInfo->path->lineTo(element->points[0].x + myInfo->pos.x(), |
|
567 |
element->points[0].y + myInfo->pos.y()); |
|
568 |
break; |
|
569 |
case kCGPathElementAddQuadCurveToPoint: |
|
570 |
myInfo->path->quadTo(element->points[0].x + myInfo->pos.x(), |
|
571 |
element->points[0].y + myInfo->pos.y(), |
|
572 |
element->points[1].x + myInfo->pos.x(), |
|
573 |
element->points[1].y + myInfo->pos.y()); |
|
574 |
break; |
|
575 |
case kCGPathElementAddCurveToPoint: |
|
576 |
myInfo->path->cubicTo(element->points[0].x + myInfo->pos.x(), |
|
577 |
element->points[0].y + myInfo->pos.y(), |
|
578 |
element->points[1].x + myInfo->pos.x(), |
|
579 |
element->points[1].y + myInfo->pos.y(), |
|
580 |
element->points[2].x + myInfo->pos.x(), |
|
581 |
element->points[2].y + myInfo->pos.y()); |
|
582 |
break; |
|
583 |
case kCGPathElementCloseSubpath: |
|
584 |
myInfo->path->closeSubpath(); |
|
585 |
break; |
|
586 |
default: |
|
587 |
qDebug() << "Unhandled path transform type: " << element->type; |
|
588 |
} |
|
589 |
||
590 |
} |
|
591 |
||
592 |
void QCoreTextFontEngine::addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions, int nGlyphs, |
|
593 |
QPainterPath *path, QTextItem::RenderFlags) |
|
594 |
{ |
|
595 |
||
596 |
CGAffineTransform cgMatrix = CGAffineTransformIdentity; |
|
597 |
cgMatrix = CGAffineTransformScale(cgMatrix, 1, -1); |
|
598 |
||
599 |
if (synthesisFlags & QFontEngine::SynthesizedItalic) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
600 |
cgMatrix = CGAffineTransformConcat(cgMatrix, CGAffineTransformMake(1, 0, -tanf(14 * acosf(0) / 90), 1, 0, 0)); |
0 | 601 |
|
602 |
||
603 |
for (int i = 0; i < nGlyphs; ++i) { |
|
604 |
QCFType<CGPathRef> cgpath = CTFontCreatePathForGlyph(ctfont, glyphs[i], &cgMatrix); |
|
605 |
ConvertPathInfo info(path, positions[i].toPointF()); |
|
606 |
CGPathApply(cgpath, &info, convertCGPathToQPainterPath); |
|
607 |
} |
|
608 |
} |
|
609 |
||
610 |
QImage QCoreTextFontEngine::imageForGlyph(glyph_t glyph, int margin, bool aa) |
|
611 |
{ |
|
612 |
const glyph_metrics_t br = boundingBox(glyph); |
|
613 |
QImage im(qRound(br.width)+2, qRound(br.height)+2, QImage::Format_RGB32); |
|
614 |
im.fill(0); |
|
615 |
||
616 |
CGColorSpaceRef colorspace = QCoreGraphicsPaintEngine::macGenericColorSpace(); |
|
617 |
uint cgflags = kCGImageAlphaNoneSkipFirst; |
|
618 |
#ifdef kCGBitmapByteOrder32Host //only needed because CGImage.h added symbols in the minor version |
|
619 |
cgflags |= kCGBitmapByteOrder32Host; |
|
620 |
#endif |
|
621 |
CGContextRef ctx = CGBitmapContextCreate(im.bits(), im.width(), im.height(), |
|
622 |
8, im.bytesPerLine(), colorspace, |
|
623 |
cgflags); |
|
624 |
CGContextSetFontSize(ctx, fontDef.pixelSize); |
|
625 |
CGContextSetShouldAntialias(ctx, aa || |
|
626 |
(fontDef.pointSize > qt_antialiasing_threshold |
|
627 |
&& !(fontDef.styleStrategy & QFont::NoAntialias))); |
|
628 |
CGContextSetShouldSmoothFonts(ctx, aa); |
|
629 |
CGAffineTransform oldTextMatrix = CGContextGetTextMatrix(ctx); |
|
630 |
CGAffineTransform cgMatrix = CGAffineTransformMake(1, 0, 0, 1, 0, 0); |
|
631 |
||
632 |
CGAffineTransformConcat(cgMatrix, oldTextMatrix); |
|
633 |
||
634 |
if (synthesisFlags & QFontEngine::SynthesizedItalic) |
|
635 |
cgMatrix = CGAffineTransformConcat(cgMatrix, CGAffineTransformMake(1, 0, tanf(14 * acosf(0) / 90), 1, 0, 0)); |
|
636 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
637 |
cgMatrix = CGAffineTransformConcat(cgMatrix, transform); |
0 | 638 |
|
639 |
CGContextSetTextMatrix(ctx, cgMatrix); |
|
640 |
CGContextSetRGBFillColor(ctx, 1, 1, 1, 1); |
|
641 |
CGContextSetTextDrawingMode(ctx, kCGTextFill); |
|
642 |
||
643 |
ATSFontRef atsfont = CTFontGetPlatformFont(ctfont, 0); |
|
644 |
QCFType<CGFontRef> cgFont = CGFontCreateWithPlatformFont(&atsfont); |
|
645 |
CGContextSetFont(ctx, cgFont); |
|
646 |
||
647 |
qreal pos_x = -br.x.toReal()+1, pos_y = im.height()+br.y.toReal(); |
|
648 |
CGContextSetTextPosition(ctx, pos_x, pos_y); |
|
649 |
||
650 |
CGSize advance; |
|
651 |
advance.width = 0; |
|
652 |
advance.height = 0; |
|
653 |
CGGlyph cgGlyph = glyph; |
|
654 |
CGContextShowGlyphsWithAdvances(ctx, &cgGlyph, &advance, 1); |
|
655 |
||
656 |
if (synthesisFlags & QFontEngine::SynthesizedBold) { |
|
657 |
CGContextSetTextPosition(ctx, pos_x + 0.5 * lineThickness().toReal(), pos_y); |
|
658 |
CGContextShowGlyphsWithAdvances(ctx, &cgGlyph, &advance, 1); |
|
659 |
} |
|
660 |
||
661 |
CGContextRelease(ctx); |
|
662 |
||
663 |
return im; |
|
664 |
} |
|
665 |
||
666 |
QImage QCoreTextFontEngine::alphaMapForGlyph(glyph_t glyph) |
|
667 |
{ |
|
668 |
QImage im = imageForGlyph(glyph, 0, false); |
|
669 |
||
670 |
QImage indexed(im.width(), im.height(), QImage::Format_Indexed8); |
|
671 |
QVector<QRgb> colors(256); |
|
672 |
for (int i=0; i<256; ++i) |
|
673 |
colors[i] = qRgba(0, 0, 0, i); |
|
674 |
indexed.setColorTable(colors); |
|
675 |
||
676 |
for (int y=0; y<im.height(); ++y) { |
|
677 |
uint *src = (uint*) im.scanLine(y); |
|
678 |
uchar *dst = indexed.scanLine(y); |
|
679 |
for (int x=0; x<im.width(); ++x) { |
|
680 |
*dst = qGray(*src); |
|
681 |
++dst; |
|
682 |
++src; |
|
683 |
} |
|
684 |
} |
|
685 |
||
686 |
return indexed; |
|
687 |
} |
|
688 |
||
689 |
QImage QCoreTextFontEngine::alphaRGBMapForGlyph(glyph_t glyph, int margin, const QTransform &x) |
|
690 |
{ |
|
691 |
if (x.type() >= QTransform::TxScale) |
|
692 |
return QFontEngine::alphaRGBMapForGlyph(glyph, margin, x); |
|
693 |
||
694 |
QImage im = imageForGlyph(glyph, margin, true); |
|
695 |
qmacfontengine_gamma_correct(&im); |
|
696 |
return im; |
|
697 |
} |
|
698 |
||
699 |
void QCoreTextFontEngine::recalcAdvances(int numGlyphs, QGlyphLayout *glyphs, QTextEngine::ShaperFlags flags) const |
|
700 |
{ |
|
701 |
Q_ASSERT(false); |
|
702 |
Q_UNUSED(numGlyphs); |
|
703 |
Q_UNUSED(glyphs); |
|
704 |
Q_UNUSED(flags); |
|
705 |
} |
|
706 |
||
707 |
QFontEngine::FaceId QCoreTextFontEngine::faceId() const |
|
708 |
{ |
|
709 |
return QFontEngine::FaceId(); |
|
710 |
} |
|
711 |
||
712 |
bool QCoreTextFontEngine::canRender(const QChar *string, int len) |
|
713 |
{ |
|
714 |
QCFType<CTFontRef> retFont = CTFontCreateForString(ctfont, |
|
715 |
QCFType<CFStringRef>(CFStringCreateWithCharactersNoCopy(0, |
|
716 |
reinterpret_cast<const UniChar *>(string), |
|
717 |
len, kCFAllocatorNull)), |
|
718 |
CFRangeMake(0, len)); |
|
719 |
return retFont != 0; |
|
720 |
return false; |
|
721 |
} |
|
722 |
||
723 |
bool QCoreTextFontEngine::getSfntTableData(uint tag, uchar *buffer, uint *length) const |
|
724 |
{ |
|
725 |
QCFType<CFDataRef> table = CTFontCopyTable(ctfont, tag, 0); |
|
726 |
if (!table || !length) |
|
727 |
return false; |
|
728 |
CFIndex tableLength = CFDataGetLength(table); |
|
729 |
int availableLength = *length; |
|
730 |
*length = tableLength; |
|
731 |
if (buffer) { |
|
732 |
if (tableLength > availableLength) |
|
733 |
return false; |
|
734 |
CFDataGetBytes(table, CFRangeMake(0, tableLength), buffer); |
|
735 |
} |
|
736 |
return true; |
|
737 |
} |
|
738 |
||
739 |
void QCoreTextFontEngine::getUnscaledGlyph(glyph_t, QPainterPath *, glyph_metrics_t *) |
|
740 |
{ |
|
741 |
// ### |
|
742 |
} |
|
743 |
||
744 |
#endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 |
|
745 |
||
746 |
#ifndef QT_MAC_USE_COCOA |
|
747 |
QFontEngineMacMulti::QFontEngineMacMulti(const ATSFontFamilyRef &atsFamily, const ATSFontRef &atsFontRef, const QFontDef &fontDef, bool kerning) |
|
748 |
: QFontEngineMulti(0) |
|
749 |
{ |
|
750 |
this->fontDef = fontDef; |
|
751 |
this->kerning = kerning; |
|
752 |
||
753 |
// hopefully (CTFontCreateWithName or CTFontCreateWithFontDescriptor) + CTFontCreateCopyWithSymbolicTraits |
|
754 |
// (or CTFontCreateWithQuickdrawInstance) |
|
755 |
FMFontFamily fmFamily; |
|
756 |
FMFontStyle fntStyle = 0; |
|
757 |
fmFamily = FMGetFontFamilyFromATSFontFamilyRef(atsFamily); |
|
758 |
if (fmFamily == kInvalidFontFamily) { |
|
759 |
// Use the ATSFont then... |
|
760 |
fontID = FMGetFontFromATSFontRef(atsFontRef); |
|
761 |
} else { |
|
762 |
if (fontDef.weight >= QFont::Bold) |
|
763 |
fntStyle |= ::bold; |
|
764 |
if (fontDef.style != QFont::StyleNormal) |
|
765 |
fntStyle |= ::italic; |
|
766 |
||
767 |
FMFontStyle intrinsicStyle; |
|
768 |
FMFont fnt = 0; |
|
769 |
if (FMGetFontFromFontFamilyInstance(fmFamily, fntStyle, &fnt, &intrinsicStyle) == noErr) |
|
770 |
fontID = FMGetATSFontRefFromFont(fnt); |
|
771 |
} |
|
772 |
||
773 |
// CFDictionaryRef, <CTStringAttributes.h> |
|
774 |
OSStatus status; |
|
775 |
||
776 |
status = ATSUCreateTextLayout(&textLayout); |
|
777 |
Q_ASSERT(status == noErr); |
|
778 |
||
779 |
const int maxAttributeCount = 5; |
|
780 |
ATSUAttributeTag tags[maxAttributeCount + 1]; |
|
781 |
ByteCount sizes[maxAttributeCount + 1]; |
|
782 |
ATSUAttributeValuePtr values[maxAttributeCount + 1]; |
|
783 |
int attributeCount = 0; |
|
784 |
||
785 |
Fixed size = FixRatio(fontDef.pixelSize, 1); |
|
786 |
tags[attributeCount] = kATSUSizeTag; |
|
787 |
sizes[attributeCount] = sizeof(size); |
|
788 |
values[attributeCount] = &size; |
|
789 |
++attributeCount; |
|
790 |
||
791 |
tags[attributeCount] = kATSUFontTag; |
|
792 |
sizes[attributeCount] = sizeof(fontID); |
|
793 |
values[attributeCount] = &this->fontID; |
|
794 |
++attributeCount; |
|
795 |
||
796 |
transform = CGAffineTransformIdentity; |
|
797 |
if (fontDef.stretch != 100) { |
|
798 |
transform = CGAffineTransformMakeScale(float(fontDef.stretch) / float(100), 1); |
|
799 |
tags[attributeCount] = kATSUFontMatrixTag; |
|
800 |
sizes[attributeCount] = sizeof(transform); |
|
801 |
values[attributeCount] = &transform; |
|
802 |
++attributeCount; |
|
803 |
} |
|
804 |
||
805 |
status = ATSUCreateStyle(&style); |
|
806 |
Q_ASSERT(status == noErr); |
|
807 |
||
808 |
Q_ASSERT(attributeCount < maxAttributeCount + 1); |
|
809 |
status = ATSUSetAttributes(style, attributeCount, tags, sizes, values); |
|
810 |
Q_ASSERT(status == noErr); |
|
811 |
||
812 |
QFontEngineMac *fe = new QFontEngineMac(style, fontID, fontDef, this); |
|
813 |
fe->ref.ref(); |
|
814 |
engines.append(fe); |
|
815 |
} |
|
816 |
||
817 |
QFontEngineMacMulti::~QFontEngineMacMulti() |
|
818 |
{ |
|
819 |
ATSUDisposeTextLayout(textLayout); |
|
820 |
ATSUDisposeStyle(style); |
|
821 |
||
822 |
for (int i = 0; i < engines.count(); ++i) { |
|
823 |
QFontEngineMac *fe = const_cast<QFontEngineMac *>(static_cast<const QFontEngineMac *>(engines.at(i))); |
|
824 |
fe->multiEngine = 0; |
|
825 |
if (!fe->ref.deref()) |
|
826 |
delete fe; |
|
827 |
} |
|
828 |
engines.clear(); |
|
829 |
} |
|
830 |
||
831 |
struct QGlyphLayoutInfo |
|
832 |
{ |
|
833 |
QGlyphLayout *glyphs; |
|
834 |
int *numGlyphs; |
|
835 |
bool callbackCalled; |
|
836 |
int *mappedFonts; |
|
837 |
QTextEngine::ShaperFlags flags; |
|
838 |
QFontEngineMacMulti::ShaperItem *shaperItem; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
839 |
unsigned int styleStrategy; |
0 | 840 |
}; |
841 |
||
842 |
static OSStatus atsuPostLayoutCallback(ATSULayoutOperationSelector selector, ATSULineRef lineRef, URefCon refCon, |
|
843 |
void *operationExtraParameter, ATSULayoutOperationCallbackStatus *callbackStatus) |
|
844 |
{ |
|
845 |
Q_UNUSED(selector); |
|
846 |
Q_UNUSED(operationExtraParameter); |
|
847 |
||
848 |
QGlyphLayoutInfo *nfo = reinterpret_cast<QGlyphLayoutInfo *>(refCon); |
|
849 |
nfo->callbackCalled = true; |
|
850 |
||
851 |
ATSLayoutRecord *layoutData = 0; |
|
852 |
ItemCount itemCount = 0; |
|
853 |
||
854 |
OSStatus e = noErr; |
|
855 |
e = ATSUDirectGetLayoutDataArrayPtrFromLineRef(lineRef, kATSUDirectDataLayoutRecordATSLayoutRecordCurrent, |
|
856 |
/*iCreate =*/ false, |
|
857 |
(void **) &layoutData, |
|
858 |
&itemCount); |
|
859 |
if (e != noErr) |
|
860 |
return e; |
|
861 |
||
862 |
*nfo->numGlyphs = itemCount - 1; |
|
863 |
||
864 |
Fixed *baselineDeltas = 0; |
|
865 |
||
866 |
e = ATSUDirectGetLayoutDataArrayPtrFromLineRef(lineRef, kATSUDirectDataBaselineDeltaFixedArray, |
|
867 |
/*iCreate =*/ true, |
|
868 |
(void **) &baselineDeltas, |
|
869 |
&itemCount); |
|
870 |
if (e != noErr) |
|
871 |
return e; |
|
872 |
||
873 |
int nextCharStop = -1; |
|
874 |
int currentClusterGlyph = -1; // first glyph in log cluster |
|
875 |
QFontEngineMacMulti::ShaperItem *item = nfo->shaperItem; |
|
876 |
if (item->charAttributes) { |
|
877 |
item = nfo->shaperItem; |
|
878 |
#if !defined(QT_NO_DEBUG) |
|
879 |
int surrogates = 0; |
|
880 |
const QChar *str = item->string; |
|
881 |
for (int i = item->from; i < item->from + item->length - 1; ++i) { |
|
882 |
surrogates += (str[i].unicode() >= 0xd800 && str[i].unicode() < 0xdc00 |
|
883 |
&& str[i+1].unicode() >= 0xdc00 && str[i+1].unicode() < 0xe000); |
|
884 |
} |
|
885 |
#endif |
|
886 |
for (nextCharStop = item->from; nextCharStop < item->from + item->length; ++nextCharStop) |
|
887 |
if (item->charAttributes[nextCharStop].charStop) |
|
888 |
break; |
|
889 |
nextCharStop -= item->from; |
|
890 |
} |
|
891 |
||
892 |
nfo->glyphs->attributes[0].clusterStart = true; |
|
893 |
int glyphIdx = 0; |
|
894 |
int glyphIncrement = 1; |
|
895 |
if (nfo->flags & QTextEngine::RightToLeft) { |
|
896 |
glyphIdx = itemCount - 2; |
|
897 |
glyphIncrement = -1; |
|
898 |
} |
|
899 |
for (int i = 0; i < *nfo->numGlyphs; ++i, glyphIdx += glyphIncrement) { |
|
900 |
||
901 |
int charOffset = layoutData[glyphIdx].originalOffset / sizeof(UniChar); |
|
902 |
const int fontIdx = nfo->mappedFonts[charOffset]; |
|
903 |
||
904 |
ATSGlyphRef glyphId = layoutData[glyphIdx].glyphID; |
|
905 |
||
906 |
QFixed yAdvance = FixedToQFixed(baselineDeltas[glyphIdx]); |
|
907 |
QFixed xAdvance = FixedToQFixed(layoutData[glyphIdx + 1].realPos - layoutData[glyphIdx].realPos); |
|
908 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
909 |
if (nfo->styleStrategy & QFont::ForceIntegerMetrics) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
910 |
yAdvance = yAdvance.round(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
911 |
xAdvance = xAdvance.round(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
912 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
913 |
|
0 | 914 |
if (glyphId != 0xffff || i == 0) { |
915 |
if (i < nfo->glyphs->numGlyphs) |
|
916 |
{ |
|
917 |
nfo->glyphs->glyphs[i] = (glyphId & 0x00ffffff) | (fontIdx << 24); |
|
918 |
||
919 |
nfo->glyphs->advances_y[i] = yAdvance; |
|
920 |
nfo->glyphs->advances_x[i] = xAdvance; |
|
921 |
} |
|
922 |
} else { |
|
923 |
// ATSUI gives us 0xffff as glyph id at the index in the glyph array for |
|
924 |
// a character position that maps to a ligtature. Such a glyph id does not |
|
925 |
// result in any visual glyph, but it may have an advance, which is why we |
|
926 |
// sum up the glyph advances. |
|
927 |
--i; |
|
928 |
nfo->glyphs->advances_y[i] += yAdvance; |
|
929 |
nfo->glyphs->advances_x[i] += xAdvance; |
|
930 |
*nfo->numGlyphs -= 1; |
|
931 |
} |
|
932 |
||
933 |
if (item->log_clusters) { |
|
934 |
if (charOffset >= nextCharStop) { |
|
935 |
nfo->glyphs->attributes[i].clusterStart = true; |
|
936 |
currentClusterGlyph = i; |
|
937 |
||
938 |
++nextCharStop; |
|
939 |
for (; nextCharStop < item->length; ++nextCharStop) |
|
940 |
if (item->charAttributes[item->from + nextCharStop].charStop) |
|
941 |
break; |
|
942 |
} else { |
|
943 |
if (currentClusterGlyph == -1) |
|
944 |
currentClusterGlyph = i; |
|
945 |
} |
|
946 |
item->log_clusters[charOffset] = currentClusterGlyph; |
|
947 |
||
948 |
// surrogate handling |
|
949 |
if (charOffset < item->length - 1) { |
|
950 |
QChar current = item->string[item->from + charOffset]; |
|
951 |
QChar next = item->string[item->from + charOffset + 1]; |
|
952 |
if (current.unicode() >= 0xd800 && current.unicode() < 0xdc00 |
|
953 |
&& next.unicode() >= 0xdc00 && next.unicode() < 0xe000) { |
|
954 |
item->log_clusters[charOffset + 1] = currentClusterGlyph; |
|
955 |
} |
|
956 |
} |
|
957 |
} |
|
958 |
} |
|
959 |
||
960 |
/* |
|
961 |
if (item) { |
|
962 |
qDebug() << "resulting logclusters:"; |
|
963 |
for (int i = 0; i < item->length; ++i) |
|
964 |
qDebug() << "logClusters[" << i << "] =" << item->log_clusters[i]; |
|
965 |
qDebug() << "clusterstarts:"; |
|
966 |
for (int i = 0; i < *nfo->numGlyphs; ++i) |
|
967 |
qDebug() << "clusterStart[" << i << "] =" << nfo->glyphs[i].attributes.clusterStart; |
|
968 |
} |
|
969 |
*/ |
|
970 |
||
971 |
ATSUDirectReleaseLayoutDataArrayPtr(lineRef, kATSUDirectDataBaselineDeltaFixedArray, |
|
972 |
(void **) &baselineDeltas); |
|
973 |
||
974 |
ATSUDirectReleaseLayoutDataArrayPtr(lineRef, kATSUDirectDataLayoutRecordATSLayoutRecordCurrent, |
|
975 |
(void **) &layoutData); |
|
976 |
||
977 |
*callbackStatus = kATSULayoutOperationCallbackStatusHandled; |
|
978 |
return noErr; |
|
979 |
} |
|
980 |
||
981 |
int QFontEngineMacMulti::fontIndexForFontID(ATSUFontID id) const |
|
982 |
{ |
|
983 |
for (int i = 0; i < engines.count(); ++i) { |
|
984 |
if (engineAt(i)->fontID == id) |
|
985 |
return i; |
|
986 |
} |
|
987 |
||
988 |
QFontEngineMacMulti *that = const_cast<QFontEngineMacMulti *>(this); |
|
989 |
QFontEngineMac *fe = new QFontEngineMac(style, id, fontDef, that); |
|
990 |
fe->ref.ref(); |
|
991 |
that->engines.append(fe); |
|
992 |
return engines.count() - 1; |
|
993 |
} |
|
994 |
||
995 |
bool QFontEngineMacMulti::stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const |
|
996 |
{ |
|
997 |
return stringToCMap(str, len, glyphs, nglyphs, flags, /*logClusters=*/0, /*charAttributes=*/0); |
|
998 |
} |
|
999 |
||
1000 |
bool QFontEngineMacMulti::stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags, |
|
1001 |
unsigned short *logClusters, const HB_CharAttributes *charAttributes) const |
|
1002 |
{ |
|
1003 |
if (*nglyphs < len) { |
|
1004 |
*nglyphs = len; |
|
1005 |
return false; |
|
1006 |
} |
|
1007 |
||
1008 |
ShaperItem shaperItem; |
|
1009 |
shaperItem.string = str; |
|
1010 |
shaperItem.from = 0; |
|
1011 |
shaperItem.length = len; |
|
1012 |
shaperItem.glyphs = *glyphs; |
|
1013 |
shaperItem.glyphs.numGlyphs = *nglyphs; |
|
1014 |
shaperItem.flags = flags; |
|
1015 |
shaperItem.log_clusters = logClusters; |
|
1016 |
shaperItem.charAttributes = charAttributes; |
|
1017 |
||
1018 |
const int maxChars = qMax(1, |
|
1019 |
int(SHRT_MAX / maxCharWidth()) |
|
1020 |
- 10 // subtract a few to be on the safe side |
|
1021 |
); |
|
1022 |
if (len < maxChars || !charAttributes) |
|
1023 |
return stringToCMapInternal(str, len, glyphs, nglyphs, flags, &shaperItem); |
|
1024 |
||
1025 |
int charIdx = 0; |
|
1026 |
int glyphIdx = 0; |
|
1027 |
ShaperItem tmpItem = shaperItem; |
|
1028 |
||
1029 |
do { |
|
1030 |
tmpItem.from = shaperItem.from + charIdx; |
|
1031 |
||
1032 |
int charCount = qMin(maxChars, len - charIdx); |
|
1033 |
||
1034 |
int lastWhitespace = tmpItem.from + charCount - 1; |
|
1035 |
int lastSoftBreak = lastWhitespace; |
|
1036 |
int lastCharStop = lastSoftBreak; |
|
1037 |
for (int i = lastCharStop; i >= tmpItem.from; --i) { |
|
1038 |
if (tmpItem.charAttributes[i].whiteSpace) { |
|
1039 |
lastWhitespace = i; |
|
1040 |
break; |
|
1041 |
} if (tmpItem.charAttributes[i].lineBreakType != HB_NoBreak) { |
|
1042 |
lastSoftBreak = i; |
|
1043 |
} if (tmpItem.charAttributes[i].charStop) { |
|
1044 |
lastCharStop = i; |
|
1045 |
} |
|
1046 |
} |
|
1047 |
charCount = qMin(lastWhitespace, qMin(lastSoftBreak, lastCharStop)) - tmpItem.from + 1; |
|
1048 |
||
1049 |
int glyphCount = shaperItem.glyphs.numGlyphs - glyphIdx; |
|
1050 |
if (glyphCount <= 0) |
|
1051 |
return false; |
|
1052 |
tmpItem.length = charCount; |
|
1053 |
tmpItem.glyphs = shaperItem.glyphs.mid(glyphIdx, glyphCount); |
|
1054 |
tmpItem.log_clusters = shaperItem.log_clusters + charIdx; |
|
1055 |
if (!stringToCMapInternal(tmpItem.string + tmpItem.from, tmpItem.length, |
|
1056 |
&tmpItem.glyphs, &glyphCount, flags, |
|
1057 |
&tmpItem)) { |
|
1058 |
*nglyphs = glyphIdx + glyphCount; |
|
1059 |
return false; |
|
1060 |
} |
|
1061 |
for (int i = 0; i < charCount; ++i) |
|
1062 |
tmpItem.log_clusters[i] += glyphIdx; |
|
1063 |
glyphIdx += glyphCount; |
|
1064 |
charIdx += charCount; |
|
1065 |
} while (charIdx < len); |
|
1066 |
*nglyphs = glyphIdx; |
|
1067 |
glyphs->numGlyphs = glyphIdx; |
|
1068 |
||
1069 |
return true; |
|
1070 |
} |
|
1071 |
||
1072 |
bool QFontEngineMacMulti::stringToCMapInternal(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags,ShaperItem *shaperItem) const |
|
1073 |
{ |
|
1074 |
//qDebug() << "stringToCMap" << QString(str, len); |
|
1075 |
||
1076 |
OSStatus e = noErr; |
|
1077 |
||
1078 |
e = ATSUSetTextPointerLocation(textLayout, (UniChar *)(str), 0, len, len); |
|
1079 |
if (e != noErr) { |
|
1080 |
qWarning("Qt: internal: %ld: Error ATSUSetTextPointerLocation %s: %d", long(e), __FILE__, __LINE__); |
|
1081 |
return false; |
|
1082 |
} |
|
1083 |
||
1084 |
QGlyphLayoutInfo nfo; |
|
1085 |
nfo.glyphs = glyphs; |
|
1086 |
nfo.numGlyphs = nglyphs; |
|
1087 |
nfo.callbackCalled = false; |
|
1088 |
nfo.flags = flags; |
|
1089 |
nfo.shaperItem = shaperItem; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1090 |
nfo.styleStrategy = fontDef.styleStrategy; |
0 | 1091 |
|
1092 |
int prevNumGlyphs = *nglyphs; |
|
1093 |
||
1094 |
QVarLengthArray<int> mappedFonts(len); |
|
1095 |
for (int i = 0; i < len; ++i) |
|
1096 |
mappedFonts[i] = 0; |
|
1097 |
nfo.mappedFonts = mappedFonts.data(); |
|
1098 |
||
1099 |
Q_ASSERT(sizeof(void *) <= sizeof(URefCon)); |
|
1100 |
e = ATSUSetTextLayoutRefCon(textLayout, (URefCon)&nfo); |
|
1101 |
if (e != noErr) { |
|
1102 |
qWarning("Qt: internal: %ld: Error ATSUSetTextLayoutRefCon %s: %d", long(e), __FILE__, __LINE__); |
|
1103 |
return false; |
|
1104 |
} |
|
1105 |
||
1106 |
{ |
|
1107 |
const int maxAttributeCount = 3; |
|
1108 |
ATSUAttributeTag tags[maxAttributeCount + 1]; |
|
1109 |
ByteCount sizes[maxAttributeCount + 1]; |
|
1110 |
ATSUAttributeValuePtr values[maxAttributeCount + 1]; |
|
1111 |
int attributeCount = 0; |
|
1112 |
||
1113 |
tags[attributeCount] = kATSULineLayoutOptionsTag; |
|
1114 |
ATSLineLayoutOptions layopts = kATSLineHasNoOpticalAlignment |
|
1115 |
| kATSLineIgnoreFontLeading |
|
1116 |
| kATSLineNoSpecialJustification // we do kashidas ourselves |
|
1117 |
| kATSLineDisableAllJustification |
|
1118 |
; |
|
1119 |
||
1120 |
if (fontDef.styleStrategy & QFont::NoAntialias) |
|
1121 |
layopts |= kATSLineNoAntiAliasing; |
|
1122 |
||
1123 |
if (!kerning) |
|
1124 |
layopts |= kATSLineDisableAllKerningAdjustments; |
|
1125 |
||
1126 |
values[attributeCount] = &layopts; |
|
1127 |
sizes[attributeCount] = sizeof(layopts); |
|
1128 |
++attributeCount; |
|
1129 |
||
1130 |
tags[attributeCount] = kATSULayoutOperationOverrideTag; |
|
1131 |
ATSULayoutOperationOverrideSpecifier spec; |
|
1132 |
spec.operationSelector = kATSULayoutOperationPostLayoutAdjustment; |
|
1133 |
spec.overrideUPP = atsuPostLayoutCallback; |
|
1134 |
values[attributeCount] = &spec; |
|
1135 |
sizes[attributeCount] = sizeof(spec); |
|
1136 |
++attributeCount; |
|
1137 |
||
1138 |
// CTWritingDirection |
|
1139 |
Boolean direction; |
|
1140 |
if (flags & QTextEngine::RightToLeft) |
|
1141 |
direction = kATSURightToLeftBaseDirection; |
|
1142 |
else |
|
1143 |
direction = kATSULeftToRightBaseDirection; |
|
1144 |
tags[attributeCount] = kATSULineDirectionTag; |
|
1145 |
values[attributeCount] = &direction; |
|
1146 |
sizes[attributeCount] = sizeof(direction); |
|
1147 |
++attributeCount; |
|
1148 |
||
1149 |
Q_ASSERT(attributeCount < maxAttributeCount + 1); |
|
1150 |
e = ATSUSetLayoutControls(textLayout, attributeCount, tags, sizes, values); |
|
1151 |
if (e != noErr) { |
|
1152 |
qWarning("Qt: internal: %ld: Error ATSUSetLayoutControls %s: %d", long(e), __FILE__, __LINE__); |
|
1153 |
return false; |
|
1154 |
} |
|
1155 |
||
1156 |
} |
|
1157 |
||
1158 |
e = ATSUSetRunStyle(textLayout, style, 0, len); |
|
1159 |
if (e != noErr) { |
|
1160 |
qWarning("Qt: internal: %ld: Error ATSUSetRunStyle %s: %d", long(e), __FILE__, __LINE__); |
|
1161 |
return false; |
|
1162 |
} |
|
1163 |
||
1164 |
if (!(fontDef.styleStrategy & QFont::NoFontMerging)) { |
|
1165 |
int pos = 0; |
|
1166 |
do { |
|
1167 |
ATSUFontID substFont = 0; |
|
1168 |
UniCharArrayOffset changedOffset = 0; |
|
1169 |
UniCharCount changeCount = 0; |
|
1170 |
||
1171 |
e = ATSUMatchFontsToText(textLayout, pos, len - pos, |
|
1172 |
&substFont, &changedOffset, |
|
1173 |
&changeCount); |
|
1174 |
if (e == kATSUFontsMatched) { |
|
1175 |
int fontIdx = fontIndexForFontID(substFont); |
|
1176 |
for (uint i = 0; i < changeCount; ++i) |
|
1177 |
mappedFonts[changedOffset + i] = fontIdx; |
|
1178 |
pos = changedOffset + changeCount; |
|
1179 |
ATSUSetRunStyle(textLayout, engineAt(fontIdx)->style, changedOffset, changeCount); |
|
1180 |
} else if (e == kATSUFontsNotMatched) { |
|
1181 |
pos = changedOffset + changeCount; |
|
1182 |
} |
|
1183 |
} while (pos < len && e != noErr); |
|
1184 |
} |
|
1185 |
{ // trigger the a layout |
|
1186 |
// CFAttributedStringCreate, CTFramesetterCreateWithAttributedString (or perhaps Typesetter) |
|
1187 |
Rect rect; |
|
1188 |
e = ATSUMeasureTextImage(textLayout, kATSUFromTextBeginning, kATSUToTextEnd, |
|
1189 |
/*iLocationX =*/ 0, /*iLocationY =*/ 0, |
|
1190 |
&rect); |
|
1191 |
if (e != noErr) { |
|
1192 |
qWarning("Qt: internal: %ld: Error ATSUMeasureTextImage %s: %d", long(e), __FILE__, __LINE__); |
|
1193 |
return false; |
|
1194 |
} |
|
1195 |
} |
|
1196 |
||
1197 |
if (!nfo.callbackCalled) { |
|
1198 |
qWarning("Qt: internal: %ld: Error ATSUMeasureTextImage did not trigger callback %s: %d", long(e), __FILE__, __LINE__); |
|
1199 |
return false; |
|
1200 |
} |
|
1201 |
||
1202 |
ATSUClearLayoutCache(textLayout, kATSUFromTextBeginning); |
|
1203 |
if (prevNumGlyphs < *nfo.numGlyphs) |
|
1204 |
return false; |
|
1205 |
return true; |
|
1206 |
} |
|
1207 |
||
1208 |
void QFontEngineMacMulti::recalcAdvances(QGlyphLayout *glyphs, QTextEngine::ShaperFlags flags) const |
|
1209 |
{ |
|
1210 |
Q_ASSERT(false); |
|
1211 |
Q_UNUSED(glyphs); |
|
1212 |
Q_UNUSED(flags); |
|
1213 |
} |
|
1214 |
||
1215 |
void QFontEngineMacMulti::doKerning(QGlyphLayout *, QTextEngine::ShaperFlags) const |
|
1216 |
{ |
|
1217 |
//Q_ASSERT(false); |
|
1218 |
} |
|
1219 |
||
1220 |
void QFontEngineMacMulti::loadEngine(int /*at*/) |
|
1221 |
{ |
|
1222 |
// should never be called! |
|
1223 |
Q_ASSERT(false); |
|
1224 |
} |
|
1225 |
||
1226 |
bool QFontEngineMacMulti::canRender(const QChar *string, int len) |
|
1227 |
{ |
|
1228 |
ATSUSetTextPointerLocation(textLayout, reinterpret_cast<const UniChar *>(string), 0, len, len); |
|
1229 |
ATSUSetRunStyle(textLayout, style, 0, len); |
|
1230 |
||
1231 |
OSStatus e = noErr; |
|
1232 |
int pos = 0; |
|
1233 |
do { |
|
1234 |
FMFont substFont = 0; |
|
1235 |
UniCharArrayOffset changedOffset = 0; |
|
1236 |
UniCharCount changeCount = 0; |
|
1237 |
||
1238 |
// CTFontCreateForString |
|
1239 |
e = ATSUMatchFontsToText(textLayout, pos, len - pos, |
|
1240 |
&substFont, &changedOffset, |
|
1241 |
&changeCount); |
|
1242 |
if (e == kATSUFontsMatched) { |
|
1243 |
pos = changedOffset + changeCount; |
|
1244 |
} else if (e == kATSUFontsNotMatched) { |
|
1245 |
break; |
|
1246 |
} |
|
1247 |
} while (pos < len && e != noErr); |
|
1248 |
||
1249 |
return e == noErr || e == kATSUFontsMatched; |
|
1250 |
} |
|
1251 |
||
1252 |
QFontEngineMac::QFontEngineMac(ATSUStyle baseStyle, ATSUFontID fontID, const QFontDef &def, QFontEngineMacMulti *multiEngine) |
|
1253 |
: fontID(fontID), multiEngine(multiEngine), cmap(0), symbolCMap(false) |
|
1254 |
{ |
|
1255 |
fontDef = def; |
|
1256 |
ATSUCreateAndCopyStyle(baseStyle, &style); |
|
1257 |
ATSFontRef atsFont = FMGetATSFontRefFromFont(fontID); |
|
1258 |
cgFont = CGFontCreateWithPlatformFont(&atsFont); |
|
1259 |
||
1260 |
const int maxAttributeCount = 4; |
|
1261 |
ATSUAttributeTag tags[maxAttributeCount + 1]; |
|
1262 |
ByteCount sizes[maxAttributeCount + 1]; |
|
1263 |
ATSUAttributeValuePtr values[maxAttributeCount + 1]; |
|
1264 |
int attributeCount = 0; |
|
1265 |
||
1266 |
synthesisFlags = 0; |
|
1267 |
||
1268 |
// synthesizing using CG is not recommended |
|
1269 |
quint16 macStyle = 0; |
|
1270 |
{ |
|
1271 |
uchar data[4]; |
|
1272 |
ByteCount len = 4; |
|
1273 |
if (ATSFontGetTable(atsFont, MAKE_TAG('h', 'e', 'a', 'd'), 44, 4, &data, &len) == noErr) |
|
1274 |
macStyle = qFromBigEndian<quint16>(data); |
|
1275 |
} |
|
1276 |
||
1277 |
Boolean atsuBold = false; |
|
1278 |
Boolean atsuItalic = false; |
|
1279 |
if (fontDef.weight >= QFont::Bold) { |
|
1280 |
if (!(macStyle & 1)) { |
|
1281 |
synthesisFlags |= SynthesizedBold; |
|
1282 |
atsuBold = true; |
|
1283 |
tags[attributeCount] = kATSUQDBoldfaceTag; |
|
1284 |
sizes[attributeCount] = sizeof(atsuBold); |
|
1285 |
values[attributeCount] = &atsuBold; |
|
1286 |
++attributeCount; |
|
1287 |
} |
|
1288 |
} |
|
1289 |
if (fontDef.style != QFont::StyleNormal) { |
|
1290 |
if (!(macStyle & 2)) { |
|
1291 |
synthesisFlags |= SynthesizedItalic; |
|
1292 |
atsuItalic = true; |
|
1293 |
tags[attributeCount] = kATSUQDItalicTag; |
|
1294 |
sizes[attributeCount] = sizeof(atsuItalic); |
|
1295 |
values[attributeCount] = &atsuItalic; |
|
1296 |
++attributeCount; |
|
1297 |
} |
|
1298 |
} |
|
1299 |
||
1300 |
tags[attributeCount] = kATSUFontTag; |
|
1301 |
values[attributeCount] = &fontID; |
|
1302 |
sizes[attributeCount] = sizeof(fontID); |
|
1303 |
++attributeCount; |
|
1304 |
||
1305 |
Q_ASSERT(attributeCount < maxAttributeCount + 1); |
|
1306 |
OSStatus err = ATSUSetAttributes(style, attributeCount, tags, sizes, values); |
|
1307 |
Q_ASSERT(err == noErr); |
|
1308 |
Q_UNUSED(err); |
|
1309 |
||
1310 |
// CTFontCopyTable |
|
1311 |
quint16 tmpFsType; |
|
1312 |
if (ATSFontGetTable(atsFont, MAKE_TAG('O', 'S', '/', '2'), 8, 2, &tmpFsType, 0) == noErr) |
|
1313 |
fsType = qFromBigEndian<quint16>(tmpFsType); |
|
1314 |
else |
|
1315 |
fsType = 0; |
|
1316 |
||
1317 |
if (multiEngine) |
|
1318 |
transform = multiEngine->transform; |
|
1319 |
else |
|
1320 |
transform = CGAffineTransformIdentity; |
|
1321 |
||
1322 |
ATSUTextMeasurement metric; |
|
1323 |
||
1324 |
ATSUGetAttribute(style, kATSUAscentTag, sizeof(metric), &metric, 0); |
|
1325 |
m_ascent = FixRound(metric); |
|
1326 |
||
1327 |
ATSUGetAttribute(style, kATSUDescentTag, sizeof(metric), &metric, 0); |
|
1328 |
m_descent = FixRound(metric); |
|
1329 |
||
1330 |
ATSUGetAttribute(style, kATSULeadingTag, sizeof(metric), &metric, 0); |
|
1331 |
m_leading = FixRound(metric); |
|
1332 |
||
1333 |
ATSFontMetrics metrics; |
|
1334 |
||
1335 |
ATSFontGetHorizontalMetrics(FMGetATSFontRefFromFont(fontID), kATSOptionFlagsDefault, &metrics); |
|
1336 |
m_maxCharWidth = metrics.maxAdvanceWidth * fontDef.pointSize; |
|
1337 |
||
1338 |
ATSFontGetHorizontalMetrics(FMGetATSFontRefFromFont(fontID), kATSOptionFlagsDefault, &metrics); |
|
1339 |
m_xHeight = QFixed::fromReal(metrics.xHeight * fontDef.pointSize); |
|
1340 |
||
1341 |
ATSFontGetHorizontalMetrics(FMGetATSFontRefFromFont(fontID), kATSOptionFlagsDefault, &metrics); |
|
1342 |
m_averageCharWidth = QFixed::fromReal(metrics.avgAdvanceWidth * fontDef.pointSize); |
|
1343 |
||
1344 |
// Use width of 'X' if ATSFontGetHorizontalMetrics returns 0 for avgAdvanceWidth. |
|
1345 |
if (m_averageCharWidth == QFixed(0)) { |
|
1346 |
QChar c('X'); |
|
1347 |
QGlyphLayoutArray<1> glyphs; |
|
1348 |
int nglyphs = 1; |
|
1349 |
stringToCMap(&c, 1, &glyphs, &nglyphs, 0); |
|
1350 |
glyph_metrics_t metrics = boundingBox(glyphs); |
|
1351 |
m_averageCharWidth = metrics.width; |
|
1352 |
} |
|
1353 |
} |
|
1354 |
||
1355 |
QFontEngineMac::~QFontEngineMac() |
|
1356 |
{ |
|
1357 |
ATSUDisposeStyle(style); |
|
1358 |
} |
|
1359 |
||
1360 |
static inline unsigned int getChar(const QChar *str, int &i, const int len) |
|
1361 |
{ |
|
1362 |
unsigned int uc = str[i].unicode(); |
|
1363 |
if (uc >= 0xd800 && uc < 0xdc00 && i < len-1) { |
|
1364 |
uint low = str[i+1].unicode(); |
|
1365 |
if (low >= 0xdc00 && low < 0xe000) { |
|
1366 |
uc = (uc - 0xd800)*0x400 + (low - 0xdc00) + 0x10000; |
|
1367 |
++i; |
|
1368 |
} |
|
1369 |
} |
|
1370 |
return uc; |
|
1371 |
} |
|
1372 |
||
1373 |
bool QFontEngineMac::stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const |
|
1374 |
{ |
|
1375 |
if (!cmap) { |
|
1376 |
cmapTable = getSfntTable(MAKE_TAG('c', 'm', 'a', 'p')); |
|
1377 |
int size = 0; |
|
1378 |
cmap = getCMap(reinterpret_cast<const uchar *>(cmapTable.constData()), cmapTable.size(), &symbolCMap, &size); |
|
1379 |
if (!cmap) |
|
1380 |
return false; |
|
1381 |
} |
|
1382 |
if (symbolCMap) { |
|
1383 |
for (int i = 0; i < len; ++i) { |
|
1384 |
unsigned int uc = getChar(str, i, len); |
|
1385 |
glyphs->glyphs[i] = getTrueTypeGlyphIndex(cmap, uc); |
|
1386 |
if(!glyphs->glyphs[i] && uc < 0x100) |
|
1387 |
glyphs->glyphs[i] = getTrueTypeGlyphIndex(cmap, uc + 0xf000); |
|
1388 |
} |
|
1389 |
} else { |
|
1390 |
for (int i = 0; i < len; ++i) { |
|
1391 |
unsigned int uc = getChar(str, i, len); |
|
1392 |
glyphs->glyphs[i] = getTrueTypeGlyphIndex(cmap, uc); |
|
1393 |
} |
|
1394 |
} |
|
1395 |
||
1396 |
*nglyphs = len; |
|
1397 |
glyphs->numGlyphs = *nglyphs; |
|
1398 |
||
1399 |
if (!(flags & QTextEngine::GlyphIndicesOnly)) |
|
1400 |
recalcAdvances(glyphs, flags); |
|
1401 |
||
1402 |
return true; |
|
1403 |
} |
|
1404 |
||
1405 |
void QFontEngineMac::recalcAdvances(QGlyphLayout *glyphs, QTextEngine::ShaperFlags flags) const |
|
1406 |
{ |
|
1407 |
Q_UNUSED(flags) |
|
1408 |
||
1409 |
QVarLengthArray<GlyphID> atsuGlyphs(glyphs->numGlyphs); |
|
1410 |
for (int i = 0; i < glyphs->numGlyphs; ++i) |
|
1411 |
atsuGlyphs[i] = glyphs->glyphs[i]; |
|
1412 |
||
1413 |
QVarLengthArray<ATSGlyphScreenMetrics> metrics(glyphs->numGlyphs); |
|
1414 |
||
1415 |
ATSUGlyphGetScreenMetrics(style, glyphs->numGlyphs, atsuGlyphs.data(), sizeof(GlyphID), |
|
1416 |
/* iForcingAntiAlias =*/ false, |
|
1417 |
/* iAntiAliasSwitch =*/true, |
|
1418 |
metrics.data()); |
|
1419 |
||
1420 |
for (int i = 0; i < glyphs->numGlyphs; ++i) { |
|
1421 |
glyphs->advances_x[i] = QFixed::fromReal(metrics[i].deviceAdvance.x); |
|
1422 |
glyphs->advances_y[i] = QFixed::fromReal(metrics[i].deviceAdvance.y); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1423 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1424 |
if (fontDef.styleStrategy & QFont::ForceIntegerMetrics) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1425 |
glyphs->advances_x[i] = glyphs->advances_x[i].round(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1426 |
glyphs->advances_y[i] = glyphs->advances_y[i].round(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1427 |
} |
0 | 1428 |
} |
1429 |
} |
|
1430 |
||
1431 |
glyph_metrics_t QFontEngineMac::boundingBox(const QGlyphLayout &glyphs) |
|
1432 |
{ |
|
1433 |
QFixed w; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1434 |
for (int i = 0; i < glyphs.numGlyphs; ++i) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1435 |
w += (fontDef.styleStrategy & QFont::ForceIntegerMetrics) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1436 |
? glyphs.effectiveAdvance(i).round() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1437 |
: glyphs.effectiveAdvance(i); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1438 |
} |
0 | 1439 |
return glyph_metrics_t(0, -(ascent()), w, ascent()+descent(), w, 0); |
1440 |
} |
|
1441 |
||
1442 |
glyph_metrics_t QFontEngineMac::boundingBox(glyph_t glyph) |
|
1443 |
{ |
|
1444 |
GlyphID atsuGlyph = glyph; |
|
1445 |
||
1446 |
ATSGlyphScreenMetrics metrics; |
|
1447 |
||
1448 |
ATSUGlyphGetScreenMetrics(style, 1, &atsuGlyph, 0, |
|
1449 |
/* iForcingAntiAlias =*/ false, |
|
1450 |
/* iAntiAliasSwitch =*/true, |
|
1451 |
&metrics); |
|
1452 |
||
1453 |
// ### check again |
|
1454 |
||
1455 |
glyph_metrics_t gm; |
|
1456 |
gm.width = int(metrics.width); |
|
1457 |
gm.height = int(metrics.height); |
|
1458 |
gm.x = QFixed::fromReal(metrics.topLeft.x); |
|
1459 |
gm.y = -QFixed::fromReal(metrics.topLeft.y); |
|
1460 |
gm.xoff = QFixed::fromReal(metrics.deviceAdvance.x); |
|
1461 |
gm.yoff = QFixed::fromReal(metrics.deviceAdvance.y); |
|
1462 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1463 |
if (fontDef.styleStrategy & QFont::ForceIntegerMetrics) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1464 |
gm.x = gm.x.floor(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1465 |
gm.y = gm.y.floor(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1466 |
gm.xoff = gm.xoff.round(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1467 |
gm.yoff = gm.yoff.round(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1468 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1469 |
|
0 | 1470 |
return gm; |
1471 |
} |
|
1472 |
||
1473 |
QFixed QFontEngineMac::ascent() const |
|
1474 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1475 |
return (fontDef.styleStrategy & QFont::ForceIntegerMetrics) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1476 |
? m_ascent.round() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1477 |
: m_ascent; |
0 | 1478 |
} |
1479 |
||
1480 |
QFixed QFontEngineMac::descent() const |
|
1481 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1482 |
// subtract a pixel to even out the historical +1 in QFontMetrics::height(). |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1483 |
// Fix in Qt 5. |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1484 |
return (fontDef.styleStrategy & QFont::ForceIntegerMetrics) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1485 |
? m_descent.round() - 1 |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1486 |
: m_descent; |
0 | 1487 |
} |
1488 |
||
1489 |
QFixed QFontEngineMac::leading() const |
|
1490 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1491 |
return (fontDef.styleStrategy & QFont::ForceIntegerMetrics) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1492 |
? m_leading.round() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1493 |
: m_leading; |
0 | 1494 |
} |
1495 |
||
1496 |
qreal QFontEngineMac::maxCharWidth() const |
|
1497 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1498 |
return (fontDef.styleStrategy & QFont::ForceIntegerMetrics) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1499 |
? qRound(m_maxCharWidth) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1500 |
: m_maxCharWidth; |
0 | 1501 |
} |
1502 |
||
1503 |
QFixed QFontEngineMac::xHeight() const |
|
1504 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1505 |
return (fontDef.styleStrategy & QFont::ForceIntegerMetrics) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1506 |
? m_xHeight.round() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1507 |
: m_xHeight; |
0 | 1508 |
} |
1509 |
||
1510 |
QFixed QFontEngineMac::averageCharWidth() const |
|
1511 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1512 |
return (fontDef.styleStrategy & QFont::ForceIntegerMetrics) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1513 |
? m_averageCharWidth.round() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1514 |
: m_averageCharWidth; |
0 | 1515 |
} |
1516 |
||
1517 |
static void addGlyphsToPathHelper(ATSUStyle style, glyph_t *glyphs, QFixedPoint *positions, int numGlyphs, QPainterPath *path) |
|
1518 |
{ |
|
1519 |
if (!numGlyphs) |
|
1520 |
return; |
|
1521 |
||
1522 |
OSStatus e; |
|
1523 |
||
1524 |
QMacFontPath fontpath(0, 0, path); |
|
1525 |
ATSCubicMoveToUPP moveTo = NewATSCubicMoveToUPP(QMacFontPath::moveTo); |
|
1526 |
ATSCubicLineToUPP lineTo = NewATSCubicLineToUPP(QMacFontPath::lineTo); |
|
1527 |
ATSCubicCurveToUPP cubicTo = NewATSCubicCurveToUPP(QMacFontPath::cubicTo); |
|
1528 |
ATSCubicClosePathUPP closePath = NewATSCubicClosePathUPP(QMacFontPath::closePath); |
|
1529 |
||
1530 |
// CTFontCreatePathForGlyph |
|
1531 |
for (int i = 0; i < numGlyphs; ++i) { |
|
1532 |
GlyphID glyph = glyphs[i]; |
|
1533 |
||
1534 |
fontpath.setPosition(positions[i].x.toReal(), positions[i].y.toReal()); |
|
1535 |
ATSUGlyphGetCubicPaths(style, glyph, moveTo, lineTo, |
|
1536 |
cubicTo, closePath, &fontpath, &e); |
|
1537 |
} |
|
1538 |
||
1539 |
DisposeATSCubicMoveToUPP(moveTo); |
|
1540 |
DisposeATSCubicLineToUPP(lineTo); |
|
1541 |
DisposeATSCubicCurveToUPP(cubicTo); |
|
1542 |
DisposeATSCubicClosePathUPP(closePath); |
|
1543 |
} |
|
1544 |
||
1545 |
void QFontEngineMac::addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions, int numGlyphs, QPainterPath *path, |
|
1546 |
QTextItem::RenderFlags) |
|
1547 |
{ |
|
1548 |
addGlyphsToPathHelper(style, glyphs, positions, numGlyphs, path); |
|
1549 |
} |
|
1550 |
||
1551 |
||
1552 |
/*! |
|
1553 |
Helper function for alphaMapForGlyph and alphaRGBMapForGlyph. The two are identical, except for |
|
1554 |
the subpixel antialiasing... |
|
1555 |
*/ |
|
1556 |
QImage QFontEngineMac::imageForGlyph(glyph_t glyph, int margin, bool colorful) |
|
1557 |
{ |
|
1558 |
const glyph_metrics_t br = boundingBox(glyph); |
|
1559 |
QImage im(qRound(br.width)+2, qRound(br.height)+4, QImage::Format_RGB32); |
|
1560 |
im.fill(0xff000000); |
|
1561 |
||
1562 |
CGColorSpaceRef colorspace = QCoreGraphicsPaintEngine::macGenericColorSpace(); |
|
1563 |
uint cgflags = kCGImageAlphaNoneSkipFirst; |
|
1564 |
#ifdef kCGBitmapByteOrder32Host //only needed because CGImage.h added symbols in the minor version |
|
1565 |
cgflags |= kCGBitmapByteOrder32Host; |
|
1566 |
#endif |
|
1567 |
CGContextRef ctx = CGBitmapContextCreate(im.bits(), im.width(), im.height(), |
|
1568 |
8, im.bytesPerLine(), colorspace, |
|
1569 |
cgflags); |
|
1570 |
CGContextSetFontSize(ctx, fontDef.pixelSize); |
|
1571 |
CGContextSetShouldAntialias(ctx, fontDef.pointSize > qt_antialiasing_threshold && !(fontDef.styleStrategy & QFont::NoAntialias)); |
|
1572 |
// turn off sub-pixel hinting - no support for that in OpenGL |
|
1573 |
CGContextSetShouldSmoothFonts(ctx, colorful); |
|
1574 |
CGAffineTransform oldTextMatrix = CGContextGetTextMatrix(ctx); |
|
1575 |
CGAffineTransform cgMatrix = CGAffineTransformMake(1, 0, 0, 1, 0, 0); |
|
1576 |
CGAffineTransformConcat(cgMatrix, oldTextMatrix); |
|
1577 |
||
1578 |
if (synthesisFlags & QFontEngine::SynthesizedItalic) |
|
1579 |
cgMatrix = CGAffineTransformConcat(cgMatrix, CGAffineTransformMake(1, 0, tanf(14 * acosf(0) / 90), 1, 0, 0)); |
|
1580 |
||
1581 |
cgMatrix = CGAffineTransformConcat(cgMatrix, transform); |
|
1582 |
||
1583 |
CGContextSetTextMatrix(ctx, cgMatrix); |
|
1584 |
CGContextSetRGBFillColor(ctx, 1, 1, 1, 1); |
|
1585 |
CGContextSetTextDrawingMode(ctx, kCGTextFill); |
|
1586 |
CGContextSetFont(ctx, cgFont); |
|
1587 |
||
1588 |
qreal pos_x = -br.x.toReal() + 1; |
|
1589 |
qreal pos_y = im.height() + br.y.toReal() - 2; |
|
1590 |
CGContextSetTextPosition(ctx, pos_x, pos_y); |
|
1591 |
||
1592 |
CGSize advance; |
|
1593 |
advance.width = 0; |
|
1594 |
advance.height = 0; |
|
1595 |
CGGlyph cgGlyph = glyph; |
|
1596 |
CGContextShowGlyphsWithAdvances(ctx, &cgGlyph, &advance, 1); |
|
1597 |
||
1598 |
if (synthesisFlags & QFontEngine::SynthesizedBold) { |
|
1599 |
CGContextSetTextPosition(ctx, pos_x + 0.5 * lineThickness().toReal(), pos_y); |
|
1600 |
CGContextShowGlyphsWithAdvances(ctx, &cgGlyph, &advance, 1); |
|
1601 |
} |
|
1602 |
||
1603 |
CGContextRelease(ctx); |
|
1604 |
||
1605 |
return im; |
|
1606 |
} |
|
1607 |
||
1608 |
QImage QFontEngineMac::alphaMapForGlyph(glyph_t glyph) |
|
1609 |
{ |
|
1610 |
QImage im = imageForGlyph(glyph, 2, false); |
|
1611 |
||
1612 |
QImage indexed(im.width(), im.height(), QImage::Format_Indexed8); |
|
1613 |
QVector<QRgb> colors(256); |
|
1614 |
for (int i=0; i<256; ++i) |
|
1615 |
colors[i] = qRgba(0, 0, 0, i); |
|
1616 |
indexed.setColorTable(colors); |
|
1617 |
||
1618 |
for (int y=0; y<im.height(); ++y) { |
|
1619 |
uint *src = (uint*) im.scanLine(y); |
|
1620 |
uchar *dst = indexed.scanLine(y); |
|
1621 |
for (int x=0; x<im.width(); ++x) { |
|
1622 |
*dst = qGray(*src); |
|
1623 |
++dst; |
|
1624 |
++src; |
|
1625 |
} |
|
1626 |
} |
|
1627 |
||
1628 |
return indexed; |
|
1629 |
} |
|
1630 |
||
1631 |
QImage QFontEngineMac::alphaRGBMapForGlyph(glyph_t glyph, int margin, const QTransform &t) |
|
1632 |
{ |
|
1633 |
QImage im = imageForGlyph(glyph, margin, true); |
|
1634 |
||
1635 |
if (t.type() >= QTransform::TxScale) { |
|
1636 |
im = im.transformed(t); |
|
1637 |
} |
|
1638 |
||
1639 |
qmacfontengine_gamma_correct(&im); |
|
1640 |
||
1641 |
return im; |
|
1642 |
} |
|
1643 |
||
1644 |
||
1645 |
bool QFontEngineMac::canRender(const QChar *string, int len) |
|
1646 |
{ |
|
1647 |
Q_ASSERT(false); |
|
1648 |
Q_UNUSED(string); |
|
1649 |
Q_UNUSED(len); |
|
1650 |
return false; |
|
1651 |
} |
|
1652 |
||
1653 |
void QFontEngineMac::draw(CGContextRef ctx, qreal x, qreal y, const QTextItemInt &ti, int paintDeviceHeight) |
|
1654 |
{ |
|
1655 |
QVarLengthArray<QFixedPoint> positions; |
|
1656 |
QVarLengthArray<glyph_t> glyphs; |
|
1657 |
QTransform matrix; |
|
1658 |
matrix.translate(x, y); |
|
1659 |
getGlyphPositions(ti.glyphs, matrix, ti.flags, glyphs, positions); |
|
1660 |
if (glyphs.size() == 0) |
|
1661 |
return; |
|
1662 |
||
1663 |
CGContextSetFontSize(ctx, fontDef.pixelSize); |
|
1664 |
||
1665 |
CGAffineTransform oldTextMatrix = CGContextGetTextMatrix(ctx); |
|
1666 |
||
1667 |
CGAffineTransform cgMatrix = CGAffineTransformMake(1, 0, 0, -1, 0, -paintDeviceHeight); |
|
1668 |
||
1669 |
CGAffineTransformConcat(cgMatrix, oldTextMatrix); |
|
1670 |
||
1671 |
if (synthesisFlags & QFontEngine::SynthesizedItalic) |
|
1672 |
cgMatrix = CGAffineTransformConcat(cgMatrix, CGAffineTransformMake(1, 0, -tanf(14 * acosf(0) / 90), 1, 0, 0)); |
|
1673 |
||
1674 |
cgMatrix = CGAffineTransformConcat(cgMatrix, transform); |
|
1675 |
||
1676 |
CGContextSetTextMatrix(ctx, cgMatrix); |
|
1677 |
||
1678 |
CGContextSetTextDrawingMode(ctx, kCGTextFill); |
|
1679 |
||
1680 |
||
1681 |
QVarLengthArray<CGSize> advances(glyphs.size()); |
|
1682 |
QVarLengthArray<CGGlyph> cgGlyphs(glyphs.size()); |
|
1683 |
||
1684 |
for (int i = 0; i < glyphs.size() - 1; ++i) { |
|
1685 |
advances[i].width = (positions[i + 1].x - positions[i].x).toReal(); |
|
1686 |
advances[i].height = (positions[i + 1].y - positions[i].y).toReal(); |
|
1687 |
cgGlyphs[i] = glyphs[i]; |
|
1688 |
} |
|
1689 |
advances[glyphs.size() - 1].width = 0; |
|
1690 |
advances[glyphs.size() - 1].height = 0; |
|
1691 |
cgGlyphs[glyphs.size() - 1] = glyphs[glyphs.size() - 1]; |
|
1692 |
||
1693 |
CGContextSetFont(ctx, cgFont); |
|
1694 |
||
1695 |
CGContextSetTextPosition(ctx, positions[0].x.toReal(), positions[0].y.toReal()); |
|
1696 |
||
1697 |
CGContextShowGlyphsWithAdvances(ctx, cgGlyphs.data(), advances.data(), glyphs.size()); |
|
1698 |
||
1699 |
if (synthesisFlags & QFontEngine::SynthesizedBold) { |
|
1700 |
CGContextSetTextPosition(ctx, positions[0].x.toReal() + 0.5 * lineThickness().toReal(), |
|
1701 |
positions[0].y.toReal()); |
|
1702 |
||
1703 |
CGContextShowGlyphsWithAdvances(ctx, cgGlyphs.data(), advances.data(), glyphs.size()); |
|
1704 |
} |
|
1705 |
||
1706 |
CGContextSetTextMatrix(ctx, oldTextMatrix); |
|
1707 |
} |
|
1708 |
||
1709 |
QFontEngine::FaceId QFontEngineMac::faceId() const |
|
1710 |
{ |
|
1711 |
FaceId ret; |
|
1712 |
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5) |
|
1713 |
if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) { |
|
1714 |
// CTFontGetPlatformFont |
|
1715 |
FSRef ref; |
|
1716 |
if (ATSFontGetFileReference(FMGetATSFontRefFromFont(fontID), &ref) != noErr) |
|
1717 |
return ret; |
|
1718 |
ret.filename = QByteArray(128, 0); |
|
1719 |
ret.index = fontID; |
|
1720 |
FSRefMakePath(&ref, (UInt8 *)ret.filename.data(), ret.filename.size()); |
|
1721 |
}else |
|
1722 |
#endif |
|
1723 |
{ |
|
1724 |
FSSpec spec; |
|
1725 |
if (ATSFontGetFileSpecification(FMGetATSFontRefFromFont(fontID), &spec) != noErr) |
|
1726 |
return ret; |
|
1727 |
||
1728 |
FSRef ref; |
|
1729 |
FSpMakeFSRef(&spec, &ref); |
|
1730 |
ret.filename = QByteArray(128, 0); |
|
1731 |
ret.index = fontID; |
|
1732 |
FSRefMakePath(&ref, (UInt8 *)ret.filename.data(), ret.filename.size()); |
|
1733 |
} |
|
1734 |
return ret; |
|
1735 |
} |
|
1736 |
||
1737 |
QByteArray QFontEngineMac::getSfntTable(uint tag) const |
|
1738 |
{ |
|
1739 |
ATSFontRef atsFont = FMGetATSFontRefFromFont(fontID); |
|
1740 |
||
1741 |
ByteCount length; |
|
1742 |
OSStatus status = ATSFontGetTable(atsFont, tag, 0, 0, 0, &length); |
|
1743 |
if (status != noErr) |
|
1744 |
return QByteArray(); |
|
1745 |
QByteArray table(length, 0); |
|
1746 |
// CTFontCopyTable |
|
1747 |
status = ATSFontGetTable(atsFont, tag, 0, table.length(), table.data(), &length); |
|
1748 |
if (status != noErr) |
|
1749 |
return QByteArray(); |
|
1750 |
return table; |
|
1751 |
} |
|
1752 |
||
1753 |
QFontEngine::Properties QFontEngineMac::properties() const |
|
1754 |
{ |
|
1755 |
QFontEngine::Properties props; |
|
1756 |
ATSFontRef atsFont = FMGetATSFontRefFromFont(fontID); |
|
1757 |
quint16 tmp; |
|
1758 |
// CTFontGetUnitsPerEm |
|
1759 |
if (ATSFontGetTable(atsFont, MAKE_TAG('h', 'e', 'a', 'd'), 18, 2, &tmp, 0) == noErr) |
|
1760 |
props.emSquare = qFromBigEndian<quint16>(tmp); |
|
1761 |
struct { |
|
1762 |
qint16 xMin; |
|
1763 |
qint16 yMin; |
|
1764 |
qint16 xMax; |
|
1765 |
qint16 yMax; |
|
1766 |
} bbox; |
|
1767 |
bbox.xMin = bbox.xMax = bbox.yMin = bbox.yMax = 0; |
|
1768 |
// CTFontGetBoundingBox |
|
1769 |
if (ATSFontGetTable(atsFont, MAKE_TAG('h', 'e', 'a', 'd'), 36, 8, &bbox, 0) == noErr) { |
|
1770 |
bbox.xMin = qFromBigEndian<quint16>(bbox.xMin); |
|
1771 |
bbox.yMin = qFromBigEndian<quint16>(bbox.yMin); |
|
1772 |
bbox.xMax = qFromBigEndian<quint16>(bbox.xMax); |
|
1773 |
bbox.yMax = qFromBigEndian<quint16>(bbox.yMax); |
|
1774 |
} |
|
1775 |
struct { |
|
1776 |
qint16 ascender; |
|
1777 |
qint16 descender; |
|
1778 |
qint16 linegap; |
|
1779 |
} metrics; |
|
1780 |
metrics.ascender = metrics.descender = metrics.linegap = 0; |
|
1781 |
// CTFontGetAscent, etc. |
|
1782 |
if (ATSFontGetTable(atsFont, MAKE_TAG('h', 'h', 'e', 'a'), 4, 6, &metrics, 0) == noErr) { |
|
1783 |
metrics.ascender = qFromBigEndian<quint16>(metrics.ascender); |
|
1784 |
metrics.descender = qFromBigEndian<quint16>(metrics.descender); |
|
1785 |
metrics.linegap = qFromBigEndian<quint16>(metrics.linegap); |
|
1786 |
} |
|
1787 |
props.ascent = metrics.ascender; |
|
1788 |
props.descent = -metrics.descender; |
|
1789 |
props.leading = metrics.linegap; |
|
1790 |
props.boundingBox = QRectF(bbox.xMin, -bbox.yMax, |
|
1791 |
bbox.xMax - bbox.xMin, |
|
1792 |
bbox.yMax - bbox.yMin); |
|
1793 |
props.italicAngle = 0; |
|
1794 |
props.capHeight = props.ascent; |
|
1795 |
||
1796 |
qint16 lw = 0; |
|
1797 |
// fonts lie |
|
1798 |
if (ATSFontGetTable(atsFont, MAKE_TAG('p', 'o', 's', 't'), 10, 2, &lw, 0) == noErr) |
|
1799 |
lw = qFromBigEndian<quint16>(lw); |
|
1800 |
props.lineWidth = lw; |
|
1801 |
||
1802 |
// CTFontCopyPostScriptName |
|
1803 |
QCFString psName; |
|
1804 |
if (ATSFontGetPostScriptName(FMGetATSFontRefFromFont(fontID), kATSOptionFlagsDefault, &psName) == noErr) |
|
1805 |
props.postscriptName = QString(psName).toUtf8(); |
|
1806 |
props.postscriptName = QPdf::stripSpecialCharacters(props.postscriptName); |
|
1807 |
return props; |
|
1808 |
} |
|
1809 |
||
1810 |
void QFontEngineMac::getUnscaledGlyph(glyph_t glyph, QPainterPath *path, glyph_metrics_t *metrics) |
|
1811 |
{ |
|
1812 |
ATSUStyle unscaledStyle; |
|
1813 |
ATSUCreateAndCopyStyle(style, &unscaledStyle); |
|
1814 |
||
1815 |
int emSquare = properties().emSquare.toInt(); |
|
1816 |
||
1817 |
const int maxAttributeCount = 4; |
|
1818 |
ATSUAttributeTag tags[maxAttributeCount + 1]; |
|
1819 |
ByteCount sizes[maxAttributeCount + 1]; |
|
1820 |
ATSUAttributeValuePtr values[maxAttributeCount + 1]; |
|
1821 |
int attributeCount = 0; |
|
1822 |
||
1823 |
Fixed size = FixRatio(emSquare, 1); |
|
1824 |
tags[attributeCount] = kATSUSizeTag; |
|
1825 |
sizes[attributeCount] = sizeof(size); |
|
1826 |
values[attributeCount] = &size; |
|
1827 |
++attributeCount; |
|
1828 |
||
1829 |
Q_ASSERT(attributeCount < maxAttributeCount + 1); |
|
1830 |
OSStatus err = ATSUSetAttributes(unscaledStyle, attributeCount, tags, sizes, values); |
|
1831 |
Q_ASSERT(err == noErr); |
|
1832 |
Q_UNUSED(err); |
|
1833 |
||
1834 |
// various CTFont metrics functions: CTFontGetBoundingRectsForGlyphs, CTFontGetAdvancesForGlyphs |
|
1835 |
GlyphID atsuGlyph = glyph; |
|
1836 |
ATSGlyphScreenMetrics atsuMetrics; |
|
1837 |
ATSUGlyphGetScreenMetrics(unscaledStyle, 1, &atsuGlyph, 0, |
|
1838 |
/* iForcingAntiAlias =*/ false, |
|
1839 |
/* iAntiAliasSwitch =*/true, |
|
1840 |
&atsuMetrics); |
|
1841 |
||
1842 |
metrics->width = int(atsuMetrics.width); |
|
1843 |
metrics->height = int(atsuMetrics.height); |
|
1844 |
metrics->x = QFixed::fromReal(atsuMetrics.topLeft.x); |
|
1845 |
metrics->y = -QFixed::fromReal(atsuMetrics.topLeft.y); |
|
1846 |
metrics->xoff = QFixed::fromReal(atsuMetrics.deviceAdvance.x); |
|
1847 |
metrics->yoff = QFixed::fromReal(atsuMetrics.deviceAdvance.y); |
|
1848 |
||
1849 |
QFixedPoint p; |
|
1850 |
addGlyphsToPathHelper(unscaledStyle, &glyph, &p, 1, path); |
|
1851 |
||
1852 |
ATSUDisposeStyle(unscaledStyle); |
|
1853 |
} |
|
1854 |
#endif // !QT_MAC_USE_COCOA |
|
1855 |
||
1856 |
QT_END_NAMESPACE |