summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qfontengine_s60.cpp
diff options
context:
space:
mode:
authorOlivier Goffart <olivier.goffart@nokia.com>2010-10-15 11:05:43 +0200
committerOlivier Goffart <olivier.goffart@nokia.com>2010-10-15 11:11:31 +0200
commit3ef69b12f6d6905594ef3976b3e16787378dfe6a (patch)
tree1105fb45cddf0afca5929041e679e743e36a1772 /src/gui/text/qfontengine_s60.cpp
parent1745a0e7799774373ad6252a73d6e8af841db2a1 (diff)
parent9358d77fc1de64d2a8a06bfa4095dcde9f9b009b (diff)
Merge remote branch 'origin/4.7' into qt-master-from-4.7
Conflicts: src/gui/painting/qpaintengine_raster.cpp tests/auto/declarative/qdeclarativetext/data/alignments_cb.png tests/auto/declarative/qdeclarativetext/data/alignments_cc.png tests/auto/declarative/qdeclarativetext/data/alignments_ct.png
Diffstat (limited to 'src/gui/text/qfontengine_s60.cpp')
-rw-r--r--src/gui/text/qfontengine_s60.cpp68
1 files changed, 42 insertions, 26 deletions
diff --git a/src/gui/text/qfontengine_s60.cpp b/src/gui/text/qfontengine_s60.cpp
index e9dcfa077c..134c1edfcb 100644
--- a/src/gui/text/qfontengine_s60.cpp
+++ b/src/gui/text/qfontengine_s60.cpp
@@ -41,6 +41,7 @@
#include "qfontengine_s60_p.h"
#include "qtextengine_p.h"
+#include "qendian.h"
#include "qglobal.h"
#include <private/qapplication_p.h>
#include "qimage.h"
@@ -177,6 +178,24 @@ CFont *QSymbianTypeFaceExtras::fontOwner() const
return m_cFont;
}
+QFixed QSymbianTypeFaceExtras::unitsPerEm() const
+{
+ if (m_unitsPerEm.value() != 0)
+ return m_unitsPerEm;
+ const QByteArray head = getSfntTable(MAKE_TAG('h', 'e', 'a', 'd'));
+ const int unitsPerEmOffset = 18;
+ if (head.size() > unitsPerEmOffset + sizeof(quint16)) {
+ const uchar* tableData = reinterpret_cast<const uchar*>(head.constData());
+ const uchar* unitsPerEm = tableData + unitsPerEmOffset;
+ m_unitsPerEm = qFromBigEndian<quint16>(unitsPerEm);
+ } else {
+ // Bitmap font? Corrupt font?
+ // We return -1 and let the QFontEngineS60 return the pixel size.
+ m_unitsPerEm = -1;
+ }
+ return m_unitsPerEm;
+}
+
// duplicated from qfontengine_xyz.cpp
static inline unsigned int getChar(const QChar *str, int &i, const int len)
{
@@ -249,6 +268,13 @@ QFontEngineS60::~QFontEngineS60()
releaseFont(m_scaledFont);
}
+QFixed QFontEngineS60::emSquareSize() const
+{
+ const QFixed unitsPerEm = m_extras->unitsPerEm();
+ return unitsPerEm.toInt() == -1 ?
+ QFixed::fromReal(m_originalFontSizeInPixels) : unitsPerEm;
+}
+
bool QFontEngineS60::stringToCMap(const QChar *characters, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const
{
if (*nglyphs < len) {
@@ -278,10 +304,13 @@ bool QFontEngineS60::stringToCMap(const QChar *characters, int len, QGlyphLayout
void QFontEngineS60::recalcAdvances(QGlyphLayout *glyphs, QTextEngine::ShaperFlags flags) const
{
Q_UNUSED(flags);
+ TOpenFontCharMetrics metrics;
+ const TUint8 *glyphBitmapBytes;
+ TSize glyphBitmapSize;
for (int i = 0; i < glyphs->numGlyphs; i++) {
- const glyph_metrics_t bbox = boundingBox_const(glyphs->glyphs[i]);
- glyphs->advances_x[i] = bbox.xoff;
- glyphs->advances_y[i] = bbox.yoff;
+ getCharacterData(glyphs->glyphs[i], metrics, glyphBitmapBytes, glyphBitmapSize);
+ glyphs->advances_x[i] = metrics.HorizAdvance();
+ glyphs->advances_y[i] = 0;
}
}
@@ -309,6 +338,7 @@ void QFontEngineS60::addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions,
parseGlyphPathData(outlineChar, outlineEnd, *path, fontSizeInPixels,
positions[count++].toPointF(), false);
} while(KErrNone == iterator.Next() && count <= nglyphs);
+ iterator.Close();
#else // Q_SYMBIAN_HAS_GLYPHOUTLINE_API
QFontEngine::addGlyphsToPath(glyphs, positions, nglyphs, path, flags);
#endif //Q_SYMBIAN_HAS_GLYPHOUTLINE_API
@@ -316,29 +346,17 @@ void QFontEngineS60::addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions,
QImage QFontEngineS60::alphaMapForGlyph(glyph_t glyph)
{
+ // Note: On some Symbian versions (apparently <= Symbian^1), this
+ // function will return gray values 0x00, 0x10 ... 0xe0, 0xf0 due
+ // to a bug. The glyphs are nowhere perfectly opaque.
+ // This has been fixed for Symbian^3.
+
TOpenFontCharMetrics metrics;
const TUint8 *glyphBitmapBytes;
TSize glyphBitmapSize;
getCharacterData(glyph, metrics, glyphBitmapBytes, glyphBitmapSize);
QImage result(glyphBitmapBytes, glyphBitmapSize.iWidth, glyphBitmapSize.iHeight, glyphBitmapSize.iWidth, QImage::Format_Indexed8);
result.setColorTable(grayPalette());
-
- // The above setColorTable() call detached the image data anyway, so why not shape tha data a bit, while we can.
- // CFont::GetCharacterData() returns 8-bit data that obviously was 4-bit data before, and converted to 8-bit incorrectly.
- // The data values are 0x00, 0x10 ... 0xe0, 0xf0. So, a real opaque 0xff is never reached, which we get punished
- // for every time we want to blit this glyph in the raster paint engine.
- // "Fix" is to convert all 0xf0 to 0xff. Is fine, quality wise, and I assume faster than correcting all values.
- // Blitting is however, evidentially faster now.
- const int bpl = result.bytesPerLine();
- for (int row = 0; row < result.height(); ++row) {
- uchar *scanLine = result.scanLine(row);
- for (int column = 0; column < bpl; ++column) {
- if (*scanLine == 0xf0)
- *scanLine = 0xff;
- scanLine++;
- }
- }
-
return result;
}
@@ -360,13 +378,11 @@ glyph_metrics_t QFontEngineS60::boundingBox_const(glyph_t glyph) const
const TUint8 *glyphBitmapBytes;
TSize glyphBitmapSize;
getCharacterData(glyph, metrics, glyphBitmapBytes, glyphBitmapSize);
- TRect glyphBounds;
- metrics.GetHorizBounds(glyphBounds);
const glyph_metrics_t result(
- glyphBounds.iTl.iX,
- glyphBounds.iTl.iY,
- glyphBounds.Width(),
- glyphBounds.Height(),
+ metrics.HorizBearingX(),
+ -metrics.HorizBearingY(),
+ metrics.Width(),
+ metrics.Height(),
metrics.HorizAdvance(),
0
);