void Sym::genGlyphs(const QRawFont& rfont) { QVector<quint32> idx = rfont.glyphIndexesForString(toString()); QVector<QPointF> adv; adv << QPointF(); glyphs.setGlyphIndexes(idx); glyphs.setPositions(adv); glyphs.setRawFont(rfont); }
void tst_QRawFont::invalidRawFont() { QRawFont font; QVERIFY(!font.isValid()); QCOMPARE(font.pixelSize(), 0.0); QVERIFY(font.familyName().isEmpty()); QCOMPARE(font.style(), QFont::StyleNormal); QCOMPARE(font.weight(), -1); QCOMPARE(font.ascent(), 0.0); QCOMPARE(font.descent(), 0.0); QVERIFY(font.glyphIndexesForString(QLatin1String("Test")).isEmpty()); }
bool GlyphPage::fill(unsigned offset, unsigned length, UChar* buffer, unsigned bufferLength, const SimpleFontData* fontData) { QRawFont rawFont = fontData->platformData().rawFont(); QString qstring = QString::fromRawData(reinterpret_cast<const QChar*>(buffer), static_cast<int>(bufferLength)); QVector<quint32> indexes = rawFont.glyphIndexesForString(qstring); bool haveGlyphs = false; for (unsigned i = 0; i < length; ++i) { Glyph glyph = (i < indexes.size()) ? indexes.at(i) : 0; if (!glyph) setGlyphDataForIndex(offset + i, 0, 0); else { haveGlyphs = true; setGlyphDataForIndex(offset + i, glyph, fontData); } } return haveGlyphs; }
void Rest::draw(QPainter* painter) const { if ( (staff() && staff()->isTabStaff() // in tab staff, do not draw rests is rests are off OR if dur. symbols are on && ( !((StaffTypeTablature*)staff()->staffType())->showRests() || ((StaffTypeTablature*)staff()->staffType())->genDurations()) ) || generated()) return; qreal _spatium = spatium(); painter->setPen(curColor()); if (parent() && measure() && measure()->multiMeasure()) { Measure* m = measure(); int n = m->multiMeasure(); qreal pw = _spatium * .7; QPen pen(painter->pen()); pen.setWidthF(pw); painter->setPen(pen); qreal w = _mmWidth; qreal y = 0.0; qreal x1 = 0.0; qreal x2 = w; pw *= .5; painter->drawLine(QLineF(x1 + pw, y, x2 - pw, y)); // draw vertical lines: pen.setWidthF(_spatium * .2); painter->setPen(pen); painter->drawLine(QLineF(x1, y-_spatium, x1, y+_spatium)); painter->drawLine(QLineF(x2, y-_spatium, x2, y+_spatium)); #ifdef USE_GLYPHS QRawFont rfont = fontId2RawFont(0); rfont.setPixelSize(20.0 * spatium()/(PPI * SPATIUM20)); QGlyphRun glyphs; QVector<quint32> idx = rfont.glyphIndexesForString(QString("%1").arg(n)); glyphs.setGlyphIndexes(idx); QVector<QPointF> adv = rfont.advancesForGlyphIndexes(idx); adv.insert(0, QPointF()); glyphs.setPositions(adv); glyphs.setRawFont(rfont); QRectF r = glyphs.boundingRect(); y = -_spatium * .5; painter->drawGlyphRun(QPointF((x2 - x1) * .5 + x1 - r.width() * .5, y), glyphs); #else QFont font = fontId2font(0); font.setPixelSize(lrint(20.0 * spatium()/(PPI * SPATIUM20))); painter->setFont(font); QFontMetricsF fm(font); // y = -_spatium * .5 - (staff()->height()*.5) - fm.ascent(); y = -_spatium * .5 - fm.ascent(); painter->drawText(QRectF(center(x1, x2), y, .0, .0), Qt::AlignHCenter|Qt::TextDontClip, QString("%1").arg(n)); #endif } else { qreal mag = magS(); symbols[score()->symIdx()][_sym].draw(painter, mag); int dots = durationType().dots(); if (dots) { qreal y = dotline * _spatium * .5; for (int i = 1; i <= dots; ++i) { qreal x = symbols[score()->symIdx()][_sym].width(mag) + point(score()->styleS(ST_dotNoteDistance)) * i; symbols[score()->symIdx()][dotSym].draw(painter, mag, QPointF(x, y)); } } } }