QRawFont::fromFont not working correctly on Mac OS X
-
I found something wrong on Qt on Mac OS X 10.6.3:
@QFont font = QFont("Wingdings"); //font.family() == "Wingdings"
QRawFont rawFont = QRawFont::fromFont(font); //rawFont.familyName() == "Lucida Grande"@I think rawFont.familyName() should be "Wingdings". On Windows this code works correctly.
I tried this method:
@QRawFont ( const QString & fileName, qreal pixelSize, QFont::HintingPreference hintingPreference = QFont::PreferDefaultHinting )@
on a font file and it works correctly.
I really don't know how to correct this. Any help is appreciated.
-
I have also run into this issue on Mac OS X 10.7.5 using Qt 4.8.1 and 4.8.3.
QGraphicsTextItem won't display (some?) symbol type fonts on this OS, even using the setHtml() method and specifying like Wingdings as the font to draw with.
Even the provided example application "fontsampler" won't properly display webdings, wingdings, wingdings 2, or wingdings 3.
I didn't know about the QRawFont class and did some research on it. The below sample code uses it with the QGlyphRun class to allow printing of some text on the screen using the Wingdings font, but it is definitely not the way I would like to go with symbol font support.
@
#include <QApplication>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QRawFont>
#include <QGlyphRun>int main(int argc, char *argv[])
{
QApplication a(argc, argv);QGlyphRun glyphs;
QVector<quint32> glyphIndexes;
QVector<QPointF> positions;glyphIndexes.append(43); //H
glyphIndexes.append(72); //e
glyphIndexes.append(79); //l
glyphIndexes.append(79); //l
glyphIndexes.append(82); //opositions.append(QPointF(100, 200));
positions.append(QPointF(150, 200));
positions.append(QPointF(230, 200));
positions.append(QPointF(300, 200));
positions.append(QPointF(375, 200));glyphs.setRawFont(QRawFont(QString("/Library/Fonts/Wingdings.ttf"), 72));
glyphs.setGlyphIndexes(glyphIndexes);
glyphs.setPositions(positions);QPixmap drawGlyphs(800, 800);
drawGlyphs.fill(Qt::white);QPainter p(&drawGlyphs);
p.setPen(Qt::black);
p.drawGlyphRun(QPointF(10, 10), glyphs);QGraphicsScene *pScene = new QGraphicsScene(0, 0, 1000, 1000);
QGraphicsView *pView = new QGraphicsView(pScene);pScene->addPixmap(drawGlyphs);
pView->show();return a.exec();
}
@ -
see "here":http://stackoverflow.com/questions/15613466/qt-font-os-x-and-fontbookfor for a solution for drawing symbol fonts on mac: Use QChar(0xf0 | c) instead of QChar( c )