128 } |
127 } |
129 } |
128 } |
130 return uc; |
129 return uc; |
131 } |
130 } |
132 |
131 |
|
132 CFont *QFontEngineS60::fontWithSize(qreal size) const |
|
133 { |
|
134 CFont *result = 0; |
|
135 TFontSpec fontSpec(qt_QString2TPtrC(QFontEngine::fontDef.family), TInt(size)); |
|
136 fontSpec.iFontStyle.SetBitmapType(EAntiAliasedGlyphBitmap); |
|
137 fontSpec.iFontStyle.SetPosture(QFontEngine::fontDef.style == QFont::StyleNormal?EPostureUpright:EPostureItalic); |
|
138 fontSpec.iFontStyle.SetStrokeWeight(QFontEngine::fontDef.weight > QFont::Normal?EStrokeWeightBold:EStrokeWeightNormal); |
|
139 const TInt errorCode = S60->screenDevice()->GetNearestFontToDesignHeightInPixels(result, fontSpec); |
|
140 Q_ASSERT(result && (errorCode == 0)); |
|
141 return result; |
|
142 } |
|
143 |
|
144 void QFontEngineS60::setFontScale(qreal scale) |
|
145 { |
|
146 if (qFuzzyCompare(scale, qreal(1))) { |
|
147 if (!m_originalFont) |
|
148 m_originalFont = fontWithSize(m_originalFontSizeInPixels); |
|
149 m_activeFont = m_originalFont; |
|
150 } else { |
|
151 const qreal scaledFontSizeInPixels = m_originalFontSizeInPixels * scale; |
|
152 if (!m_scaledFont || |
|
153 (TInt(scaledFontSizeInPixels) != TInt(m_scaledFontSizeInPixels))) { |
|
154 releaseFont(m_scaledFont); |
|
155 m_scaledFontSizeInPixels = scaledFontSizeInPixels; |
|
156 m_scaledFont = fontWithSize(m_scaledFontSizeInPixels); |
|
157 } |
|
158 m_activeFont = m_scaledFont; |
|
159 } |
|
160 } |
|
161 |
|
162 void QFontEngineS60::releaseFont(CFont *&font) |
|
163 { |
|
164 if (font) { |
|
165 S60->screenDevice()->ReleaseFont(font); |
|
166 font = 0; |
|
167 } |
|
168 } |
|
169 |
133 QFontEngineS60::QFontEngineS60(const QFontDef &request, const QFontEngineS60Extensions *extensions) |
170 QFontEngineS60::QFontEngineS60(const QFontDef &request, const QFontEngineS60Extensions *extensions) |
134 : m_extensions(extensions) |
171 : m_extensions(extensions) |
|
172 , m_originalFont(0) |
|
173 , m_originalFontSizeInPixels((request.pixelSize >= 0)? |
|
174 request.pixelSize:pointsToPixels(request.pointSize)) |
|
175 , m_scaledFont(0) |
|
176 , m_scaledFontSizeInPixels(0) |
|
177 , m_activeFont(0) |
135 { |
178 { |
136 QFontEngine::fontDef = request; |
179 QFontEngine::fontDef = request; |
137 m_fontSizeInPixels = (request.pixelSize >= 0)? |
180 setFontScale(1.0); |
138 request.pixelSize:pointsToPixels(request.pointSize); |
181 cache_cost = sizeof(QFontEngineS60); |
139 |
|
140 QSymbianFbsHeapLock lock(QSymbianFbsHeapLock::Unlock); |
|
141 |
|
142 m_textRenderBitmap = q_check_ptr(new CFbsBitmap()); // CBase derived object needs check on new |
|
143 const TSize bitmapSize(1, 1); // It is just a dummy bitmap that I need to keep the font alive (or maybe not) |
|
144 qt_symbian_throwIfError(m_textRenderBitmap->Create(bitmapSize, EGray256)); |
|
145 QT_TRAP_THROWING(m_textRenderBitmapDevice = CFbsBitmapDevice::NewL(m_textRenderBitmap)); |
|
146 qt_symbian_throwIfError(m_textRenderBitmapDevice->CreateContext(m_textRenderBitmapGc)); |
|
147 cache_cost = sizeof(QFontEngineS60) + bitmapSize.iHeight * bitmapSize.iWidth * 4; |
|
148 |
|
149 TFontSpec fontSpec(qt_QString2TPtrC(request.family), m_fontSizeInPixels); |
|
150 fontSpec.iFontStyle.SetBitmapType(EAntiAliasedGlyphBitmap); |
|
151 fontSpec.iFontStyle.SetPosture(request.style == QFont::StyleNormal?EPostureUpright:EPostureItalic); |
|
152 fontSpec.iFontStyle.SetStrokeWeight(request.weight > QFont::Normal?EStrokeWeightBold:EStrokeWeightNormal); |
|
153 const TInt errorCode = m_textRenderBitmapDevice->GetNearestFontInPixels(m_font, fontSpec); |
|
154 Q_ASSERT(errorCode == 0); |
|
155 m_textRenderBitmapGc->UseFont(m_font); |
|
156 |
|
157 lock.relock(); |
|
158 } |
182 } |
159 |
183 |
160 QFontEngineS60::~QFontEngineS60() |
184 QFontEngineS60::~QFontEngineS60() |
161 { |
185 { |
162 QSymbianFbsHeapLock lock(QSymbianFbsHeapLock::Unlock); |
186 releaseFont(m_originalFont); |
163 |
187 releaseFont(m_scaledFont); |
164 m_textRenderBitmapGc->DiscardFont(); |
|
165 delete m_textRenderBitmapGc; |
|
166 m_textRenderBitmapGc = NULL; |
|
167 m_textRenderBitmapDevice->ReleaseFont(m_font); |
|
168 delete m_textRenderBitmapDevice; |
|
169 m_textRenderBitmapDevice = NULL; |
|
170 delete m_textRenderBitmap; |
|
171 m_textRenderBitmap = NULL; |
|
172 |
|
173 lock.relock(); |
|
174 } |
188 } |
175 |
189 |
176 bool QFontEngineS60::stringToCMap(const QChar *characters, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const |
190 bool QFontEngineS60::stringToCMap(const QChar *characters, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const |
177 { |
191 { |
178 if (*nglyphs < len) { |
192 if (*nglyphs < len) { |
271 return boundingBox_const(glyph); |
285 return boundingBox_const(glyph); |
272 } |
286 } |
273 |
287 |
274 QFixed QFontEngineS60::ascent() const |
288 QFixed QFontEngineS60::ascent() const |
275 { |
289 { |
276 return m_font->FontMaxAscent(); |
290 return m_originalFont->FontMaxAscent(); |
277 } |
291 } |
278 |
292 |
279 QFixed QFontEngineS60::descent() const |
293 QFixed QFontEngineS60::descent() const |
280 { |
294 { |
281 return m_font->FontMaxDescent(); |
295 return m_originalFont->FontMaxDescent(); |
282 } |
296 } |
283 |
297 |
284 QFixed QFontEngineS60::leading() const |
298 QFixed QFontEngineS60::leading() const |
285 { |
299 { |
286 return 0; |
300 return 0; |
287 } |
301 } |
288 |
302 |
289 qreal QFontEngineS60::maxCharWidth() const |
303 qreal QFontEngineS60::maxCharWidth() const |
290 { |
304 { |
291 return m_font->MaxCharWidthInPixels(); |
305 return m_originalFont->MaxCharWidthInPixels(); |
292 } |
306 } |
293 |
307 |
294 const char *QFontEngineS60::name() const |
308 const char *QFontEngineS60::name() const |
295 { |
309 { |
296 return "QFontEngineS60"; |
310 return "QFontEngineS60"; |
322 // Setting the most significant bit tells GetCharacterData |
336 // Setting the most significant bit tells GetCharacterData |
323 // that 'code' is a Glyph ID, rather than a UTF-16 value |
337 // that 'code' is a Glyph ID, rather than a UTF-16 value |
324 const TUint specialCode = (TUint)glyph | 0x80000000; |
338 const TUint specialCode = (TUint)glyph | 0x80000000; |
325 |
339 |
326 const CFont::TCharacterDataAvailability availability = |
340 const CFont::TCharacterDataAvailability availability = |
327 m_font->GetCharacterData(specialCode, metrics, bitmap, bitmapSize); |
341 m_activeFont->GetCharacterData(specialCode, metrics, bitmap, bitmapSize); |
328 const glyph_t fallbackGlyph = '?'; |
342 const glyph_t fallbackGlyph = '?'; |
329 if (availability != CFont::EAllCharacterData) { |
343 if (availability != CFont::EAllCharacterData) { |
330 const CFont::TCharacterDataAvailability fallbackAvailability = |
344 const CFont::TCharacterDataAvailability fallbackAvailability = |
331 m_font->GetCharacterData(fallbackGlyph, metrics, bitmap, bitmapSize); |
345 m_activeFont->GetCharacterData(fallbackGlyph, metrics, bitmap, bitmapSize); |
332 Q_ASSERT(fallbackAvailability == CFont::EAllCharacterData); |
346 Q_ASSERT(fallbackAvailability == CFont::EAllCharacterData); |
333 } |
347 } |
334 } |
348 } |
335 |
349 |
336 QT_END_NAMESPACE |
350 QT_END_NAMESPACE |