Beispiel #1
0
QRawFont fontId2RawFont(int fontId)
      {
      static QRawFont* fonts[4];       // cached values
      Q_ASSERT(fontId >= 0 && fontId < 4);

      QRawFont* f = fonts[fontId];
      if (f == 0) {
            qreal size = 20.0 * MScore::DPI / PPI;
            QString name;

            if (fontId == 0)
                  name = ":/fonts/mscore-20.ttf";
            else if (fontId == 2) {
                  name = ":/fonts/FreeSerifMscore.ttf";
                  size = 8 * MScore::DPI / PPI;
                  }
            else if (fontId == 3)
                  name = ":/fonts/gonville-20.ttf";
            else
                  qFatal("illegal font id %d", fontId);

            // horizontal hinting is bad as note hooks do not attach to stems
            // properly at some magnifications
            f = fonts[fontId] = new QRawFont(name, size, QFont::PreferVerticalHinting);
            f->setPixelSize(size);
            }
      return *f;
      }
Beispiel #2
0
void tst_QRawFont::rawFontSetPixelSize()
{
    QFETCH(QFont::HintingPreference, hintingPreference);

    QTextLayout layout("Foobar");

    QFont font = layout.font();
    font.setHintingPreference(hintingPreference);
    font.setPixelSize(12);
    layout.setFont(font);

    layout.beginLayout();
    layout.createLine();
    layout.endLayout();

    QGlyphRun glyphs = layout.glyphRuns().at(0);
    QRawFont rawFont = glyphs.rawFont();
    QCOMPARE(rawFont.pixelSize(), 12.0);

    rawFont.setPixelSize(24);
    QCOMPARE(rawFont.pixelSize(), 24.0);
}
Beispiel #3
0
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));
                        }
                  }
            }
      }