Пример #1
0
QString symToHtml(const Sym& s1, const Sym& s2, int leftMargin)
      {
      QFont f        = s1.font();
#ifdef USE_GLYPHS
      qreal size = s1.font().pointSizeF();
#else
      qreal size = s1.font().pixelSize();
#endif
      QString family = f.family();

      return QString(
      "<data>"
        "<html>"
          "<head>"
            "<meta name=\"qrichtext\" content=\"1\" >"
            "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf8\" />"
            "<style type=\"text/css\">"
              "p, li { white-space: pre-wrap; }"
              "</style>"
            "</head>"
          "<body style=\" font-family:'%1'; font-size:%2pt;\">"
            "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:%3px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">"
                "&#%4;&#%5;"
              "</p>"
            "</body>"
          "</html>"
      "</data>").arg(family).arg(size).arg(leftMargin).arg(s1.code()).arg(s2.code());
      }
Пример #2
0
QString symToHtml(const Sym& s, int leftMargin, const TextStyle* ts, qreal _spatium)
      {
      qreal size;
      if (ts) {
            size = ts->font(_spatium).pointSizeF();
            }
      else {
#ifdef USE_GLYPHS
            size = s.font().pointSizeF();
#else
            size = s.font().pixelSize();
#endif
            }

      QString family = s.font().family();
      return QString(
      "<data>"
        "<html>"
          "<head>"
            "<meta name=\"qrichtext\" content=\"1\" >"
            "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf8\" />"
            "<style type=\"text/css\">"
              "p, li { white-space: pre-wrap; }"
              "</style>"
            "</head>"
          "<body style=\" font-family:'%1'; font-size:%2pt;\">"
            "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:%3px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">"
                "&#%4;"
              "</p>"
            "</body>"
          "</html>"
      "</data>").arg(family).arg(size).arg(leftMargin).arg(s.code());
      }
Пример #3
0
void initSymbols(int idx)
      {
      if (symbolsInitialized[idx])
            return;
      symbolsInitialized[idx] = true;
      symbols[idx] = QVector<Sym>(lastSym);

      symbols[idx][clefEightSym] = Sym(0x38, 2);
      symbols[idx][clefOneSym]   = Sym(0x31, 2);
      symbols[idx][clefFiveSym]  = Sym(0x35, 2);
      symbols[idx][letterTSym]   = Sym('T',  2);
      symbols[idx][letterSSym]   = Sym('S',  2);
      symbols[idx][letterPSym]   = Sym('P',  2);

      QString path;
#ifdef Q_OS_IOS
      {
      extern QString resourcePath();
      QString rpath = resourcePath();
      path = rpath + QString(idx == 0 ? "/mscore20.xml" : "/mscore/gonville.xml");
      }
#else
      path = idx == 0 ? ":/fonts/mscore20.xml" : ":/fonts/gonville.xml";
#endif
      QFile f(path);
      if (!f.open(QFile::ReadOnly)) {
            qDebug("cannot open symbols file %s", qPrintable(path));
            if (!MScore::debugMode)
                  exit(-1);
            }
      XmlReader e(&f);
      int fid = idx == 0 ? 0 : 3;

      while (e.readNextStartElement()) {
            if (e.name() == "museScore") {
                  while (e.readNextStartElement()) {
                        if (e.name() == "Glyph") {
                              QString name;
                              int code = -1;
                              QPointF p;
                              QRectF b;
                              while (e.readNextStartElement()) {
                                    const QStringRef& tag(e.name());
                                    if (tag == "name")
                                          name = e.readElementText();
                                    else if (tag == "code") {
                                          QString val(e.readElementText());
                                          bool ok;
                                          code = val.mid(2).toInt(&ok, 16);
                                          if (!ok)
                                                qDebug("cannot read code");
                                          }
                                    else if (tag == "attach")
                                          p = e.readPoint();
                                    else if (tag == "bbox")
                                          b = e.readRect();
                                    else
                                          e.unknown();
                                    }
                              if (code == -1)
                                    qDebug("no code for glyph <%s>", qPrintable(name));
                              SymId idx1 = Sym::name2id(name);
                              if (idx1 != noSym)
                                    symbols[idx][idx1] = Sym(code, fid, p, b);
                              else {
                                    qDebug("symbol <%s> declared in %s for symbol set %d not used",
                                       qPrintable(name), qPrintable(path), idx);
                                    }
                              }
                        else
                              e.unknown();
                        }
                  }
            else
                  e.unknown();
            }
      for (int i = 0; i < lastSym; ++i) {
            Sym* sym = &symbols[idx][i];
            if (sym->code() == -1) {
                  qDebug("no code for symbol %s", Sym::id2name(SymId(i)));
                  if (idx > 0) {
                        //fallback to default font
                        symbols[idx][i] = symbols[0][i];
                        }
                  }
            }
      }