Beispiel #1
0
Sym::Sym(int c, int fid, qreal ax, qreal ay)
   : _code(c), fontId(fid), _attach(ax * MScore::DPI/PPI, ay * MScore::DPI/PPI)
      {
      QFont _font(fontId2font(fontId));
      QFontMetricsF fm(_font);
      if (!fm.inFont(_code)) {
            qDebug("Sym: character 0x%x(%d) are not in font <%s>\n", c, c, qPrintable(_font.family()));
            return;
            }
      w     = fm.width(_code);
      _bbox = fm.boundingRect(_code);
#ifdef USE_GLYPHS
      genGlyphs(fontId2font(fontId));
#endif
      }
Beispiel #2
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  = _spatium;
            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));

            QFont font(fontId2font(0));
            painter->setFont(font);
            QFontMetricsF fm(font);
            y  = -_spatium * .5 - fm.ascent();
            painter->drawText(QRectF(center(x1, x2), y, .0, .0),
               Qt::AlignHCenter|Qt::TextDontClip,
               QString("%1").arg(n));
            }
      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));
                        }
                  }
            }
      }
Beispiel #3
0
Sym::Sym(int c, int fid, const QPointF& a, const QRectF& b)
   : _code(c), fontId(fid)
      {
      qreal ds = MScore::DPI/PPI;
      _bbox.setRect(b.x() * ds, b.y() * ds, b.width() * ds, b.height() * ds);
      _attach = a * ds;
      w = _bbox.width();
#ifdef USE_GLYPHS
      genGlyphs(fontId2font(fontId));
#endif
      }
Beispiel #4
0
static void addSymbolToText(const SymCode& s, QTextCursor* cur)
      {
      QTextCharFormat oFormat = cur->charFormat();
      if (s.fontId >= 0) {
            QTextCharFormat oFormat = cur->charFormat();
            QTextCharFormat nFormat(oFormat);
            nFormat.setFontFamily(fontId2font(s.fontId).family());
            cur->setCharFormat(nFormat);
            cur->insertText(QChar(s.code));
            cur->setCharFormat(oFormat);
            }
      else
            cur->insertText(QChar(s.code));
      }
Beispiel #5
0
void Text::addSymbol(const SymCode& s, QTextCursor* cur)
      {
      if (cur == 0)
            cur = _cursor;
      if (s.fontId >= 0) {
            QTextCharFormat nFormat(cur->charFormat());
            nFormat.setFontFamily(fontId2font(s.fontId).family());
            QString ss;
            if (s.code >= 0x10000) {
                  ss = QChar(QChar::highSurrogate(s.code));
                  ss += QChar(QChar::lowSurrogate(s.code));
                  }
            else
                  ss = QChar(s.code);
            cur->insertText(ss, nFormat);
            }
      else
            cur->insertText(QChar(s.code));
      score()->setLayoutAll(true);
      score()->end();
      }
Beispiel #6
0
void Text::addSymbol(const SymCode& s)
      {
      if (styled()) {
            SimpleText::addSymbol(s);
            return;
            }

      if (s.fontId >= 0) {
            QTextCharFormat nFormat(_cursor->charFormat());
            nFormat.setFontFamily(fontId2font(s.fontId).family());
            QString ss;
            if (s.code >= 0x10000) {
                  ss = QChar(QChar::highSurrogate(s.code));
                  ss += QChar(QChar::lowSurrogate(s.code));
                  }
            else
                  ss = QChar(s.code);
            _cursor->insertText(ss, nFormat);
            }
      else
            _cursor->insertText(QChar(s.code));
      score()->setLayoutAll(true);
      score()->end();
      }
Beispiel #7
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));
                        }
                  }
            }
      }
Beispiel #8
0
void Bracket::layout()
      {
      qreal _spatium = spatium();
      path = QPainterPath();
      if (h2 == 0.0)
            return;

      qreal h = h2 + yoff * .5;
//      qreal d = 0.0;

      if (subtype() == BRACKET_AKKOLADE) {
            qreal w = point(score()->styleS(ST_akkoladeWidth));
#if 0
            const qreal X1 =  2.0 * w;
            const qreal X2 = -0.7096 * w;
            const qreal X3 = -1.234 * w;
            const qreal X4 =  1.734 * w;
            const qreal Y1 =  .3359 * h;
            const qreal Y2 =  .5089 * h;
            const qreal Y3 =  .5025 * h;
            const qreal Y4 =  .2413 * h;

            path.moveTo(0, h);
            path.cubicTo(X1, h + Y1,   X2, h + Y2,    w, 2 * h);
            path.cubicTo(X3, h + Y3,   X4, h + Y4,    0, h);

            path.cubicTo(X1, h - Y1,   X2, h - Y2,    w, 0);
            path.cubicTo(X3, h - Y3,   X4, h - Y4,    0, h);
#endif

#define XM(a) (a+700)*w/700
#define YM(a) (a+7100)*h2/7100

path.moveTo( XM(   -8), YM(-2048));
path.cubicTo(XM(   -8), YM(-3192), XM(-360), YM(-4304), XM( -360), YM(-5400)); // c 0
path.cubicTo(XM( -360), YM(-5952), XM(-264), YM(-6488), XM(   32), YM(-6968)); // c 1
path.cubicTo(XM(   40), YM(-6976), XM(  40), YM(-6976), XM(   40), YM(-6984)); // c 0
path.cubicTo(XM(   40), YM(-7000), XM(  16), YM(-7024), XM(    0), YM(-7024)); // c 0
path.cubicTo(XM(   -8), YM(-7024), XM( -24), YM(-7024), XM(  -32), YM(-7008)); // c 1
path.cubicTo(XM( -416), YM(-6392), XM(-544), YM(-5680), XM( -544), YM(-4960)); // c 0
path.cubicTo(XM( -544), YM(-3800), XM(-168), YM(-2680), XM( -168), YM(-1568)); // c 0
path.cubicTo(XM( -168), YM(-1016), XM(-264), YM( -496), XM( -560), YM(  -16)); // c 1
path.lineTo( XM( -560), YM(    0));  //  l 1
path.lineTo( XM( -560), YM(   16));  //  l 1
path.cubicTo(XM( -264), YM(  496), XM(-168), YM( 1016), XM( -168), YM( 1568)); // c 0
path.cubicTo(XM( -168), YM( 2680), XM(-544), YM( 3800), XM( -544), YM( 4960)); // c 0
path.cubicTo(XM( -544), YM( 5680), XM(-416), YM( 6392), XM(  -32), YM( 7008)); // c 1
path.cubicTo(XM(  -24), YM( 7024), XM(  -8), YM( 7024), XM(    0), YM( 7024)); // c 0
path.cubicTo(XM(   16), YM( 7024), XM(  40), YM( 7000), XM(   40), YM( 6984)); // c 0
path.cubicTo(XM(   40), YM( 6976), XM(  40), YM( 6976), XM(   32), YM( 6968)); // c 1
path.cubicTo(XM( -264), YM( 6488), XM(-360), YM( 5952), XM( -360), YM( 5400)); // c 0
path.cubicTo(XM( -360), YM( 4304), XM(  -8), YM( 3192), XM(   -8), YM( 2048)); // c 0
path.cubicTo(XM( -  8), YM( 1320), XM(-136), YM(  624), XM( -512), YM(    0)); // c 1
path.cubicTo(XM( -136), YM( -624), XM(  -8), YM(-1320), XM(   -8), YM(-2048)); // c 0

            }
      else if (subtype() == BRACKET_NORMAL) {
            qreal w = point(score()->styleS(ST_bracketWidth));

            QChar up   = symbols[score()->symIdx()][brackettipsRightUp].code();
            QChar down = symbols[score()->symIdx()][brackettipsRightDown].code();

            QFont f(fontId2font(0));
            f.setPointSizeF(2.0 * _spatium);

            qreal o   = _spatium * .17;
            qreal slw = point(score()->styleS(ST_staffLineWidth));

            path.setFillRule(Qt::WindingFill);

            path.addText(QPointF(0.0, -o), f,          QString(up));
            path.addText(QPointF(0.0, h * 2.0 + o), f, QString(down));
            path.addRect(0.0, -slw * .5, w, h * 2.0 + slw);
            }
      QRectF r(path.boundingRect());
      setbbox(path.boundingRect());
      }