示例#1
0
QPointF Pedal::linePos(GripLine grip, System** sys) const
      {
      qreal x;
      qreal nhw = score()->noteHeadWidth();
      System* s = nullptr;
      if (grip == GripLine::START) {
            ChordRest* c = static_cast<ChordRest*>(startElement());
            s = c->segment()->system();
            x = c->pos().x() + c->segment()->pos().x() + c->segment()->measure()->pos().x();
            if (beginHook() && beginHookType() == HookType::HOOK_45)
                  x += nhw * .5;
            }
      else {
            ChordRest* c = nullptr;
            Element* e = endElement();
            if (!e || e == startElement()) {
                  // pedal marking on single note - extend to next note or end of measure
                  Segment* seg = startSegment();
                  if (seg) {
                        seg = seg->next();
                        for ( ; seg; seg = seg->next()) {
                              if (seg->segmentType() == Segment::Type::ChordRest) {
                                    if (seg->element(track()))
                                          break;
                                    }
                              else if (seg->segmentType() == Segment::Type::EndBarLine) {
                                    break;
                                    }
                              }
                        }
                  if (seg) {
                        s = seg->system();
                        x = seg->pos().x() + seg->measure()->pos().x() - nhw * 2;
                        }
                  }
            else {
                  c = static_cast<ChordRest*>(endElement());
                  if (c) {
                        s = c->segment()->system();
                        x = c->pos().x() + c->segment()->pos().x() + c->segment()->measure()->pos().x();
                        }
                  }
            if (!s) {
                  int t = tick2();
                  Measure* m = score()->tick2measure(t);
                  s = m->system();
                  x = m->tick2pos(t);
                  }
            if (endHook() && endHookType() == HookType::HOOK_45)
                  x += nhw * .5;
            else
                  x += nhw;
            }
      *sys = s;
      return QPointF(x, 0);
      }
示例#2
0
QPointF SLine::linePos(int grip, System** sys)
      {
      qreal _spatium = spatium();

      qreal x = 0.0;

      if (anchor() == ANCHOR_SEGMENT) {
            Segment* seg = static_cast<Segment*>(grip == 0 ? startElement() : endElement());
            Measure* m   = seg->measure();
            *sys         = m->system();
            if (*sys == 0)
                  return QPointF(x, 0.0);
            x            = seg->pos().x() + m->pos().x();
            if (grip == GRIP_LINE_END) {
                  if (((*sys)->firstMeasure() == m) && (seg->tick() == m->tick())) {
                        m = m->prevMeasure();
                        if (m) {
                              *sys = m->system();
                              x = m->pos().x() + m->width();
                              }
                        }
                  }
            }
      else {
            // anchor() == ANCHOR_MEASURE
            Measure* m;
            if (grip == GRIP_LINE_START) {
                  m = static_cast<Measure*>(startElement());
                  x = m->pos().x();
                  }
            else {
                  m = static_cast<Measure*>(endElement());
                  x = m->pos().x() + m->bbox().right();
                  if (type() == VOLTA) {
                        Segment* seg = m->last();
                        if (seg->subtype() == SegEndBarLine) {
                              Element* e = seg->element(0);
                              if (e && e->type() == BAR_LINE) {
                                    if (static_cast<BarLine*>(e)->subtype() == START_REPEAT)
                                          x -= e->width() - _spatium * .5;
                                    else
                                          x -= _spatium * .5;
                                    }
                              }
                        }
                  }
            *sys = m->system();
            }
      //DEBUG:
      if ((*sys)->staves()->isEmpty())
            return QPointF(x, 0.0);

      qreal y = (*sys)->staff(staffIdx())->y();
      return QPointF(x, y);
      }
示例#3
0
void KoXmlWriter::addManifestEntry( const QString& fullPath, const QString& mediaType )
{
    startElement( "manifest:file-entry" );
    addAttribute( "manifest:media-type", mediaType );
    addAttribute( "manifest:full-path", fullPath );
    endElement();
}
示例#4
0
void byteSwap(void* buffer,
              size_t elemSize,
              size_t numElements,
              size_t numThreads)
{
    if (numThreads <= 1)
    {
        sys::byteSwap(buffer,
                      static_cast<unsigned short>(elemSize),
                      numElements);
    }
    else
    {
        mt::ThreadGroup threads;
        const mt::ThreadPlanner planner(numElements, numThreads);

        size_t threadNum(0);
        size_t startElement(0);
        size_t numElementsThisThread(0);
        while (planner.getThreadInfo(threadNum++,
                                     startElement,
                                     numElementsThisThread))
        {
            std::auto_ptr<sys::Runnable> thread(new ByteSwapRunnable(
                    buffer,
                    elemSize,
                    startElement,
                    numElementsThisThread));

            threads.createThread(thread);
        }
        threads.joinAll();
    }
}
示例#5
0
QPointF Pedal::linePos(GripLine grip, System** sys) const
      {
      qreal x;
      qreal nhw = score()->noteHeadWidth();
      System* s;
      if (grip == GripLine::START) {
            ChordRest* c = static_cast<ChordRest*>(startElement());
            s = c->segment()->system();
            x = c->pos().x() + c->segment()->pos().x() + c->segment()->measure()->pos().x();
            if (beginHook() && beginHookType() == HookType::HOOK_45)
                  x += nhw * .5;
            }
      else {
            ChordRest* c = static_cast<ChordRest*>(endElement());
            if (c) {
                  s = c->segment()->system();
                  x = c->pos().x() + c->segment()->pos().x() + c->segment()->measure()->pos().x();
                  }
            else {
                  int t = tick2();
                  Measure* m = score()->tick2measure(t);
                  s = m->system();
                  x = m->tick2pos(t);
                  }
            if (endHook() && endHookType() == HookType::HOOK_45)
                  x += nhw * .5;
            else
                  x += nhw;
            }
      *sys = s;
      return QPointF(x, 0);
      }
示例#6
0
bool CCRapidXMLParser::initWithFile(const char *xmlFileName)
{
    std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(xmlFileName);
    CCLog("XMLPath====>%s",fullPath.c_str());
    ssize_t size = 0;
    char* pBuffer = (char*)CCFileUtils::sharedFileUtils()->getFileData(fullPath.c_str(), "r", &size);
    if (pBuffer != NULL && size > 0)
    {
        xml_document<> doc;
        std::string content(pBuffer, size);
        CC_SAFE_DELETE_ARRAY(pBuffer);
        doc.parse<0>(&content[0]);
        xml_node<>* node = doc.first_node()->first_node();
        while (node)
        {
            std::string nodeName = node->name();
            if (nodeName == "Group")
            {
                startElement(node);
                node = node->next_sibling();
            }
        }
    }
    return true;
}
示例#7
0
void KoXmlWriter::addConfigItem( const QString & configName, const QString& value )
{
    startElement( "config:config-item" );
    addAttribute( "config:name", configName );
    addAttribute( "config:type",  "string" );
    addTextNode( value );
    endElement();
}
示例#8
0
void KoXmlWriter::addConfigItem( const QString & configName, bool value )
{
    startElement( "config:config-item" );
    addAttribute( "config:name", configName );
    addAttribute( "config:type",  "boolean" );
    addTextNode( value ? "true" : "false" );
    endElement();
}
示例#9
0
void KoXmlWriter::addConfigItem( const QString & configName, short value )
{
    startElement( "config:config-item" );
    addAttribute( "config:name", configName );
    addAttribute( "config:type", "short" );
    addTextNode( QString::number( value ) );
    endElement();
}
 void start_include(const string_type& namespaceURI,
                    const string_type& localName,
                    const string_type& qName,
                    const SAX::Attributes<string_type, string_adaptor>& atts)
 {
   context_->parser().setContentHandler(*this);
   startElement(namespaceURI, localName, qName, atts);
 } // start_include
bool  QXmlDefaultHandler_QtDShell::__override_startElement(const QString&  namespaceURI0, const QString&  localName1, const QString&  qName2, const QXmlAttributes&  atts3, bool static_call)
{
    if (static_call) {
        return QXmlDefaultHandler::startElement((const QString& )namespaceURI0, (const QString& )localName1, (const QString& )qName2, (const QXmlAttributes& )atts3);
    } else {
        return startElement((const QString& )namespaceURI0, (const QString& )localName1, (const QString& )qName2, (const QXmlAttributes& )atts3);
    }
}
/*!
  \internal

   Treats \a outputItem as a node and calls the appropriate function,
   e.g., attribute() or comment(), depending on its
   QXmlNodeModelIndex::NodeKind.

   This is a helper function that subclasses can use to multiplex
   Nodes received via item().
 */
void QAbstractXmlReceiver::sendAsNode(const QPatternist::Item &outputItem)
{
    Q_ASSERT(outputItem);
    Q_ASSERT(outputItem.isNode());
    const QXmlNodeModelIndex asNode = outputItem.asNode();

    switch(asNode.kind())
    {
        case QXmlNodeModelIndex::Attribute:
        {
            const QString &v = outputItem.stringValue();
            attribute(asNode.name(), QStringRef(&v));
            return;
        }
        case QXmlNodeModelIndex::Element:
        {
            startElement(asNode.name());

            /* First the namespaces, then attributes, then the children. */
            asNode.sendNamespaces(this);
            sendFromAxis<QXmlNodeModelIndex::AxisAttribute>(asNode);
            sendFromAxis<QXmlNodeModelIndex::AxisChild>(asNode);

            endElement();

            return;
        }
        case QXmlNodeModelIndex::Text:
        {
            const QString &v = asNode.stringValue();
            characters(QStringRef(&v));
            return;
        }
        case QXmlNodeModelIndex::ProcessingInstruction:
        {
            processingInstruction(asNode.name(), outputItem.stringValue());
            return;
        }
        case QXmlNodeModelIndex::Comment:
        {
            comment(outputItem.stringValue());
            return;
        }
        case QXmlNodeModelIndex::Document:
        {
            startDocument();
            sendFromAxis<QXmlNodeModelIndex::AxisChild>(asNode);
            endDocument();
            return;
        }
        case QXmlNodeModelIndex::Namespace:
            Q_ASSERT_X(false, Q_FUNC_INFO, "Not implemented");
    }

    Q_ASSERT_X(false, Q_FUNC_INFO,
               QString::fromLatin1("Unknown node type: %1").arg(asNode.kind()).toUtf8().constData());
}
示例#13
0
void GeogebraTransformer::startElement( const QXmlName& name )
{
  if( name.localName( m_np ) == "Section" )
  {
    m_nsections++;
    m_sections.push_back( GeogebraSection() );

    // Clear stacks
    m_inputObjectLabels.clear();
    m_outputObjectLabels.clear();
    m_currentArgStack.clear();
    m_objectMap.clear();
    return;
  }

  switch( m_currentState )
  {
  case GeogebraTransformer::ReadingObject:
    if( m_currentObject )
    {
      // We are already building an object
      m_currentState = GeogebraTransformer::ReadingArguments;
      startElement( name );
      return;
    }

    {
      resetDrawerVars();
      const QByteArray nameData = name.localName( m_np ).toLatin1();
      m_currentObject = ObjectTypeFactory::instance()->find( nameData );

      if ( !m_currentObject )
      {
        qWarning() << name.localName( m_np ) << " object not found!";
      }
    }

    break;
  case GeogebraTransformer::ReadingArguments:
    if ( name.localName( m_np ) == QLatin1String( "Double" ) )
    {
      m_currentState = GeogebraTransformer::ReadingDouble;
    }

    break;
  default:
    break;
  }
}
示例#14
0
void MemcheckParser::parse()
{
    while (!atEnd()) {
        switch (readNext()) {

        case StartDocument:
            clear();
            break;

        case StartElement:
            startElement();
            break;

        case EndElement:
            endElement();
            break;

        case Characters:
            m_buffer += text().toString();
            break;

        default:
            break;
        }
    }

    if (hasError()) {
        switch (error()) {

        case CustomError:
        case UnexpectedElementError:
        case NotWellFormedError:
            KMessageBox::error(qApp->activeWindow(),
                               i18n("Valgrind XML Parsing: error at line %1, column %2: %3",
                                    lineNumber(),
                                    columnNumber(),
                                    errorString()),
                               i18n("Valgrind Error"));
            break;

        case NoError:
        case PrematureEndOfDocumentError:
            break;
        }
    }
}
示例#15
0
void CXMLDocument::startElementCallback(void *ctx,
										const xmlChar *fullname,
										const xmlChar **atts)
{
    extern Bool XML_ProcessNameSpaces;
    if (allowcallbacks)
		CB_startElement((const char *)fullname,(const char **)atts);
	if (buildtree)
        //HS-2010-10-11: [[ Bug 7586 ]] Reinstate libxml2 to create name spaces. Implement new liveCode commands to suppress name space creation.
        if (XML_ProcessNameSpaces)
        {
		    startElement(ctx,fullname,atts);
        }
        else
        {
            xmlSAX2StartElementNoNS(ctx,fullname,atts);
        }
}
示例#16
0
void XMLWriter::dataElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname,
                             const XMLString& data,
	                         const XMLString& attr1, const XMLString& value1,
							 const XMLString& attr2, const XMLString& value2,
							 const XMLString& attr3, const XMLString& value3)
{
	AttributesImpl attributes;
	if (!attr1.empty()) attributes.addAttribute(XMLString(), XMLString(), attr1, CDATA, value1);
	if (!attr2.empty()) attributes.addAttribute(XMLString(), XMLString(), attr2, CDATA, value2);
	if (!attr3.empty()) attributes.addAttribute(XMLString(), XMLString(), attr3, CDATA, value3);
	if (data.empty())
	{
		emptyElement(namespaceURI, localName, qname, attributes);
	}
	else
	{
		startElement(namespaceURI, localName, qname, attributes);
		characters(data);
		endElement(namespaceURI, localName, qname);
	}
}
示例#17
0
void Tie::slurPos(SlurPos* sp)
      {
      Note* note1 = static_cast<Note*>(startElement());
      qreal hw   = note1->headWidth();
      qreal __up = _up ? -1.0 : 1.0;
      qreal _spatium = spatium();

      Chord* sc   = note1->chord();
      sp->system1 = sc->measure()->system();

      qreal xo;
      qreal yo;

      //------p1
      if ((sc->notes().size() > 1) || (sc->stem() && (sc->up() == _up))) {
            xo = note1->x() + hw * 1.12;
            yo = note1->pos().y() + hw * .3 * __up;
            }
      else {
            xo = note1->x() + hw * 0.85;
            yo = note1->pos().y() + _spatium * .75 * __up;
            }
      sp->p1 = sc->pagePos() - sp->system1->pagePos() + QPointF(xo, yo);

      //------p2
      Note* note2 = static_cast<Note*>(endElement());
      if (note2 == 0) {
            sp->p2 = sp->p1 + QPointF(_spatium * 3, 0.0);
            sp->system2 = sp->system1;
            return;
            }
      Chord* ec   = note2->chord();
      sp->system2 = ec->measure()->system();
      if ((ec->notes().size() > 1) || (ec->stem() && !ec->up() && !_up))
            xo = note2->x() - hw * 0.12;
      else
            xo = note2->x() + hw * 0.15;
      sp->p2 = ec->pagePos() - sp->system2->pagePos() + QPointF(xo, yo);
      }
示例#18
0
void Trill::layout()
      {
      qreal _spatium = spatium();
      setPos(0.0, yoff() * _spatium);

      SLine::layout();

      //
      // special case:
      // if end segment is first chord/rest segment in measure,
      // shorten trill line so it ends at end of previous measure
      //
      Segment* seg1  = static_cast<Segment*>(startElement());
      Segment* seg2  = static_cast<Segment*>(endElement());
      if (seg2
         && (seg1->system() == seg2->system())
         && (spannerSegments().size() == 1)
         && (seg2->tick() == seg2->measure()->tick())
         ) {
            qreal x1   = seg2->pagePos().x();
            Measure* m = seg2->measure()->prevMeasure();
            if (m) {
                  Segment* s2      = m->last();
                  qreal x2         = s2->pagePos().x();
                  qreal dx         = x1 - x2 + _spatium * .3;
                  TrillSegment* ls = static_cast<TrillSegment*>(frontSegment());
                  ls->setPos2(ls->ipos2() + QPointF(-dx, 0.0));
                  ls->layout();
                  }
            }

      if (_accidental) {
            _accidental->setMag(.6);
            _accidental->layout();
            _accidental->setPos(_spatium*1.3, -2.2*_spatium);
            _accidental->adjustReadPos();
            }
      }
示例#19
0
    virtual Status startElement(const string& name,
                                const Attributes& attributes,
                                stream_offset position)
    {
        HandlerInfo& top = handlers_.top();
         
        // element start/end validation

        top.names.push(name);

        // call handler

        Handler::Status status = top.handler.startElement(name, attributes, position);
        if (status.flag != Handler::Status::Delegate)
            return status; 

        // Status::Delegate: let status.delegate handle this message 

        if (!status.delegate) throw runtime_error("[SAXParser] Null delegate.");
        top.names.pop();            
        handlers_.push(*status.delegate);
        return startElement(name, attributes, position);
    }
示例#20
0
void Slur::slurPos(SlurPos* sp)
      {
      qreal _spatium = spatium();
      Element* e1 = startElement();
      Element* e2 = endElement();

      if (e2 == 0) {
            sp->p1 = e1->pagePos();
            sp->p1.rx() += e1->width();
            sp->p2 = sp->p1;
            sp->p2.rx() += 5 * _spatium;
            sp->system1 = static_cast<ChordRest*>(e1)->measure()->system();
            sp->system2 = sp->system1;
            return;
            }

      if ((e1->type() != CHORD) || (e2->type() != CHORD)) {
            sp->p1 = e1->pagePos();
            sp->p2 = e2->pagePos();
            sp->p1.rx() += e1->width();
            sp->p2.rx() += e2->width();
            sp->system1 = static_cast<ChordRest*>(e1)->measure()->system();
            sp->system2 = static_cast<ChordRest*>(e2)->measure()->system();
            return;
            }
      Chord* sc   = static_cast<Chord*>(e1);
      Chord* ec   = static_cast<Chord*>(e2);
      Note* note1 = _up ? sc->upNote() : sc->downNote();
      Note* note2 = _up ? ec->upNote() : ec->downNote();

      sp->system1 = sc->measure()->system();
      sp->system2 = ec->measure()->system();
      sp->p1      = sc->pagePos() - sp->system1->pagePos();
      sp->p2      = ec->pagePos() - sp->system2->pagePos();

      qreal xo, yo;

      Stem* stem1 = sc->stem();
      Stem* stem2 = ec->stem();

      enum SlurAnchor {
            SA_NONE, SA_STEM
            };
      SlurAnchor sa1 = SA_NONE;
      SlurAnchor sa2 = SA_NONE;
      if ((sc->up() == ec->up()) && !sc->beam() && !ec->beam() && (_up == sc->up())) {
            if (stem1)
                  sa1 = SA_STEM;
            if (stem2)
                  sa2 = SA_STEM;
            }

      qreal __up = _up ? -1.0 : 1.0;
      qreal hw   = note1->headWidth();
      switch (sa1) {
            case SA_STEM:
                  sp->p1 += sc->stemPosBeam() - sc->pagePos() + sc->stem()->p2();
                  sp->p1 += QPointF(0.35 * _spatium, 0.25 * _spatium);
                  break;
            case SA_NONE:
                  break;
            }
      switch(sa2) {
            case SA_STEM:
                  sp->p2 += ec->stemPosBeam() - ec->pagePos() + ec->stem()->p2();
                  sp->p2 += QPointF(-0.35 * _spatium, 0.25 * _spatium);
                  break;
            case SA_NONE:
                  break;
            }

      //
      // default position:
      //    horizontal: middle of note head
      //    vertical:   _spatium * .4 above/below note head
      //
      //------p1
      bool stemPos = false;   // p1 starts at chord stem side
      yo = note1->pos().y() + _spatium * .9 * __up;
      xo = hw * .5;

      if (stem1) {
            Beam* beam1 = sc->beam();
            if (beam1 && (beam1->elements().back() != sc) && (sc->up() == _up)) {
                  qreal sh = stem1->height() + _spatium;
                  yo       = sc->downNote()->pos().y() + sh * __up;
                  xo       = stem1->pos().x();
                  stemPos  = true;
                  }
            else {
                  if (sc->up() && _up)
                        xo = hw + _spatium * .3;
                  //
                  // handle case: stem up   - stem down
                  //              stem down - stem up
                  //
                  if ((sc->up() != ec->up()) && (sc->up() == _up)) {
                        Note* n1  = sc->up() ? sc->downNote() : sc->upNote();
                        Note* n2  = ec->up() ? ec->downNote() : ec->upNote();
                        qreal yd  = n2->pos().y() - n1->pos().y();

                        yd *= .5;

                        qreal sh = stem1->height();    // limit y move
                        if (yd > 0.0) {
                              if (yd > sh)
                                    yd = sh;
                              }
                        else {
                              if (yd < - sh)
                                    yd = -sh;
                              }
                        stemPos = true;
                        if ((_up && (yd < -_spatium)) || (!_up && (yd > _spatium)))
                              yo += yd;
                        }
                  else if (sc->up() != _up)
                        yo = fixArticulations(yo, sc, __up);
                  }
            }

      if (sa1 == SA_NONE)
            sp->p1 += QPointF(xo, yo);

      //------p2
      xo = hw * .5;
      yo = note2->pos().y() + _spatium * .9 * __up;

      if (stem2) {
            Beam* beam2 = ec->beam();
            if ((stemPos && (sc->up() == ec->up()))
               || (beam2
                 && (!beam2->elements().isEmpty())
                 && (beam2->elements().front() != ec)
                 && (ec->up() == _up)
                 && (sc->noteType() == NOTE_NORMAL)
                 )
                  ) {
                  qreal sh = stem2->height() + _spatium;
                  if (_up)
                        yo = ec->downNote()->pos().y() - sh;
                  else
                        yo = ec->upNote()->pos().y() + sh;
                  xo = stem2->pos().x();
                  }
            else if (!ec->up() && !_up)
                  xo = -_spatium * .3 + note2->x();
            //
            // handle case: stem up   - stem down
            //              stem down - stem up
            //
            if ((sc->up() != ec->up()) && (ec->up() == _up)) {
                  Note* n1 = sc->up() ? sc->downNote() : sc->upNote();
                  Note* n2 = ec->up() ? ec->downNote() : ec->upNote();
                  qreal yd = n2->pos().y() - n1->pos().y();

                  yd *= .5;

                  qreal mh = stem2->height();    // limit y move
                  if (yd > 0.0) {
                        if (yd > mh)
                              yd = mh;
                        }
                  else {
                        if (yd < - mh)
                              yd = -mh;
                        }

                  if ((_up && (yd > _spatium)) || (!_up && (yd < -_spatium)))
                        yo -= yd;
                  }
            else if (ec->up() != _up)
                  yo = fixArticulations(yo, ec, __up);
            }

      if (sa2 == SA_NONE)
            sp->p2 += QPointF(xo, yo);
      }
示例#21
0
 ScopedElement scopedElement( std::string const& name ) {
     ScopedElement scoped( this );
     startElement( name );
     return scoped;
 }
示例#22
0
int SLine::tick() const
      {
      if (startElement()->type() != SEGMENT)
            return -1;
      return static_cast<Segment*>(startElement())->tick();
      }
示例#23
0
void SLine::layout()
      {
      if (parent() == 0) {
            //
            // when used in a palette, SLine has no parent and
            // tick and tick2 has no meaning so no layout is
            // possible and needed
            //
            if (!spannerSegments().isEmpty()) {
                  LineSegment* s = frontSegment();
                  s->layout();
                  setbbox(s->bbox());
                  }
            return;
            }
      if (startElement() == 0 || endElement() == 0) {
            qDebug("SLine::layout() failed: %s %s\n", parent()->name(), name());
            qDebug("   start %p   end %p\n", startElement(), endElement());
            return;
            }

      System* s1;
      System* s2;
      QPointF p1 = linePos(GRIP_LINE_START, &s1);
      QPointF p2 = linePos(GRIP_LINE_END,   &s2);

      QList<System*>* systems = score()->systems();
      int sysIdx1 = systems->indexOf(s1);
      int sysIdx2 = systems->indexOf(s2);
      int segmentsNeeded = 0;
      for (int i = sysIdx1; i < sysIdx2+1;  ++i) {
            if (systems->at(i)->isVbox())
                  continue;
            ++segmentsNeeded;
            }
      int segCount = spannerSegments().size();

      if (segmentsNeeded != segCount) {
            if (segmentsNeeded > segCount) {
                  int n = segmentsNeeded - segCount;
                  for (int i = 0; i < n; ++i) {
                        LineSegment* ls = createLineSegment();
                        add(ls);
                        // set user offset to previous segment's offset
                        if (segCount > 0)
                              ls->setUserOff(QPointF(0, segmentAt(segCount+i-1)->userOff().y()));
                        }
                  }
            else {
                  int n = segCount - segmentsNeeded;
                  qDebug("SLine: segments %d needed %d, remove %d\n", segCount, segmentsNeeded, n);
                  for (int i = 0; i < n; ++i) {
                        if (spannerSegments().isEmpty()) {
                              qDebug("SLine::layout(): no segment %d, %d expected\n", i, n);
                              break;
                              }
                        else {
                              // LineSegment* seg = takeLastSegment();
                              // TODO delete seg;
                              }
                        }
                  }
            }

      int segIdx = 0;
      int si  = staffIdx();
      for (int i = sysIdx1; i <= sysIdx2; ++i) {
            System* system = systems->at(i);
            if (system->isVbox())
                  continue;
            LineSegment* seg = segmentAt(segIdx++);
            seg->setSystem(system);

            Measure* m = system->firstMeasure();
            qreal x1 = m->first(SegChordRest)->pos().x() + m->pos().x();
            qreal x2 = system->bbox().right();
            qreal y  = system->staff(si)->y();

            if (sysIdx1 == sysIdx2) {
                  // single segment
                  seg->setSubtype(SEGMENT_SINGLE);
                  seg->setPos(p1);
                  seg->setPos2(QPointF(p2.x() - p1.x(), 0.0));
                  }
            else if (i == sysIdx1) {
                  // start segment
                  seg->setSubtype(SEGMENT_BEGIN);
                  seg->setPos(p1);
                  seg->setPos2(QPointF(x2 - p1.x(), 0.0));
                  }
            else if (i > 0 && i != sysIdx2) {
                  // middle segment
                  seg->setSubtype(SEGMENT_MIDDLE);
                  seg->setPos(QPointF(x1, y));
                  seg->setPos2(QPointF(x2 - x1, 0.0));
                  }
            else if (i == sysIdx2) {
                  // end segment
                  seg->setSubtype(SEGMENT_END);
                  seg->setPos(QPointF(x1, y));
                  seg->setPos2(QPointF(p2.x() - x1, 0.0));
                  }
            seg->layout();
            seg->rypos() += (_yoffset * spatium());
            seg->adjustReadPos();
            }
      }
示例#24
0
void KoXmlWriter::addTextSpan( const QString& text, const QMap<int, int>& tabCache )
{
    uint len = text.length();
    int nrSpaces = 0; // number of consecutive spaces
    bool leadingSpace = false;
    QString str;
    str.reserve( len );

    // Accumulate chars either in str or in nrSpaces (for spaces).
    // Flush str when writing a subelement (for spaces or for another reason)
    // Flush nrSpaces when encountering two or more consecutive spaces
    for ( uint i = 0; i < len ; ++i ) {
        QChar ch = text[i];
        if ( ch != ' ' ) {
            if ( nrSpaces > 0 ) {
                // For the first space we use ' '.
                // "it is good practice to use (text:s) for the second and all following SPACE 
                // characters in a sequence." (per the ODF spec)
                // however, per the HTML spec, "authors should not rely on user agents to render 
                // white space immediately after a start tag or immediately before an end tag"
                // (and both we and OO.o ignore leading spaces in <text:p> or <text:h> elements...)
                if (!leadingSpace)
                {
                    str += ' ';
                    --nrSpaces;
                }
                if ( nrSpaces > 0 ) { // there are more spaces
                    if ( !str.isEmpty() )
                        addTextNode( str );
                    str = QString::null;
                    startElement( "text:s" );
                    if ( nrSpaces > 1 ) // it's 1 by default
                        addAttribute( "text:c", nrSpaces );
                    endElement();
                }
            }
            nrSpaces = 0;
            leadingSpace = false;
        }
        switch ( ch.unicode() ) {
        case '\t':
            if ( !str.isEmpty() )
                addTextNode( str );
            str = QString::null;
            startElement( "text:tab" );
            if ( tabCache.contains( i ) )
                addAttribute( "text:tab-ref", tabCache[i] + 1 );
            endElement();
            break;
        case '\n':
            if ( !str.isEmpty() )
                addTextNode( str );
            str = QString::null;
            startElement( "text:line-break" );
            endElement();
            break;
        case ' ':
            if ( i == 0 )
                leadingSpace = true;
            ++nrSpaces;
            break;
        default:
            str += text[i];
            break;
        }
    }
    // either we still have text in str or we have spaces in nrSpaces
    if ( !str.isEmpty() ) {
        addTextNode( str );
    }
    if ( nrSpaces > 0 ) { // there are more spaces
        startElement( "text:s" );
        if ( nrSpaces > 1 ) // it's 1 by default
            addAttribute( "text:c", nrSpaces );
        endElement();
    }
}
示例#25
0
文件: line.cpp 项目: briff/MuseScore
QPointF SLine::linePos(int grip, System** sys)
      {
      qreal _spatium = spatium();
      qreal x = 0.0;

      switch(anchor()) {
            case Spanner::ANCHOR_SEGMENT:
                  {
                  Segment* seg = static_cast<Segment*>(grip == 0 ? startElement() : endElement());
                  Measure* m   = seg->measure();
                  *sys         = m->system();
                  if (*sys == 0)
                        return QPointF(x, 0.0);
                  x = seg->pos().x() + m->pos().x();
                  if (grip == GRIP_LINE_END) {
                        if (((*sys)->firstMeasure() == m) && (seg->tick() == m->tick())) {
                              m = m->prevMeasure();
                              if (m) {
                                    *sys = m->system();
                                    x = m->pos().x() + m->width();
                                    }
                              }
                        }
                  }
                  break;

            case Spanner::ANCHOR_MEASURE:
                  {
                  // anchor() == ANCHOR_MEASURE
                  Measure* m;
                  if (grip == GRIP_LINE_START) {
                        m = static_cast<Measure*>(startElement());
                        x = m->pos().x();
                        }
                  else {
                        m = static_cast<Measure*>(endElement());
                        x = m->pos().x() + m->bbox().right();
                        if (type() == VOLTA) {
                              Segment* seg = m->last();
                              if (seg->subtype() == Segment::SegEndBarLine) {
                                    Element* e = seg->element(0);
                                    if (e && e->type() == BAR_LINE) {
                                          if (static_cast<BarLine*>(e)->subtype() == START_REPEAT)
                                                x -= e->width() - _spatium * .5;
                                          else
                                                x -= _spatium * .5;
                                          }
                                    }
                              }
                        }
                  *sys = m->system();
                  }
                  break;

            case Spanner::ANCHOR_NOTE:
                  {
                  System* s = static_cast<Note*>(startElement())->chord()->segment()->system();
                  *sys = s;
                  if (grip == GRIP_LINE_START)
                        return startElement()->pagePos() - s->pagePos();
                  else
                        return endElement()->pagePos() - s->pagePos();
                  }

            case Spanner::ANCHOR_CHORD:
                  qDebug("Sline::linePos(): anchor not implemented\n");
                  break;
            }

      //DEBUG:
      if ((*sys)->staves()->isEmpty())
            return QPointF(x, 0.0);

      qreal y = (*sys)->staff(staffIdx())->y();
      return QPointF(x, y);
      }
示例#26
0
QPointF Pedal::linePos(Grip grip, System** sys) const
      {
      qreal x = 0.0;
      qreal nhw = score()->noteHeadWidth();
      System* s = nullptr;
      if (grip == Grip::START) {
            ChordRest* c = toChordRest(startElement());
            if (c) {
                  s = c->segment()->system();
                  x = c->pos().x() + c->segment()->pos().x() + c->segment()->measure()->pos().x();
                  if (c->type() == ElementType::REST && c->durationType() == TDuration::DurationType::V_MEASURE)
                        x -= c->x();
                  if (beginHookType() == HookType::HOOK_45)
                        x += nhw * .5;
                  }
            }
      else {
            Element* e = endElement();
            ChordRest* c = toChordRest(endElement());
            if (!e || e == startElement() || (endHookType() == HookType::HOOK_90)) {
                  // pedal marking on single note or ends with non-angled hook:
                  // extend to next note or end of measure
                  Segment* seg = nullptr;
                  if (!e)
                        seg = startSegment();
                  else
                        seg = c->segment();
                  if (seg) {
                        seg = seg->next();
                        for ( ; seg; seg = seg->next()) {
                              if (seg->segmentType() == SegmentType::ChordRest) {
                                    // look for a chord/rest in any voice on this staff
                                    bool crFound = false;
                                    int track = staffIdx() * VOICES;
                                    for (int i = 0; i < VOICES; ++i) {
                                          if (seg->element(track + i)) {
                                                crFound = true;
                                                break;
                                                }
                                          }
                                    if (crFound)
                                          break;
                                    }
                              else if (seg->segmentType() == SegmentType::EndBarLine) {
                                    break;
                                    }
                              }
                        }
                  if (seg) {
                        s = seg->system();
                        x = seg->pos().x() + seg->measure()->pos().x() - nhw * 2;
                        }
                  }
            else if (c) {
                  s = c->segment()->system();
                  x = c->pos().x() + c->segment()->pos().x() + c->segment()->measure()->pos().x();
                  if (c->type() == ElementType::REST && c->durationType() == TDuration::DurationType::V_MEASURE)
                        x -= c->x();
                  }
            if (!s) {
                  int t = tick2();
                  Measure* m = score()->tick2measure(t);
                  s = m->system();
                  x = m->tick2pos(t);
                  }
            if (endHookType() == HookType::HOOK_45)
                  x += nhw * .5;
            else
                  x += nhw;
            }

      *sys = s;
      return QPointF(x, 0);
      }
示例#27
0
void AccelTreeBuilder<FromDocument>::startElement(const QXmlName &name)
{
    startElement(name, 1, 1);
}
示例#28
0
void XMLWriter::startElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname)
{
	const AttributesImpl attributes;
	startElement(namespaceURI, localName, qname, attributes);
}
示例#29
0
bool 
CControlObject::parseXML( char *pData, unsigned int len )
{
	bool rv = true;
	unsigned int pos = 0;
	int xml_state = XML_STATE_NONE; 
	char *pTag = NULL;
	char *pChar = NULL;
	wxString strStatus;
	int loopcnt = 0;

	// Must be valid pointers
	if ( NULL == pData ) return false;

	// Must be something to parse
	if ( 0 == len )  return false;

	// Must be something in buffer
	if ( 0 == *pData ) return false;

	while( pos < len ) {
		
		loopcnt++;
	 
		if ( loopcnt > 500 ) {
			//m_objectInfoWnd.GetWindowText( strStatus );
			strStatus += _T(".");
			//m_objectInfoWnd.SetWindowText( strStatus );
			loopcnt = 0;
		}

		switch ( xml_state ) {
		
		case XML_STATE_START:		// Start tag

			if ( pData[ pos ] == _T('>') ) {
				
				// We have parsed a full start tag
				pData[ pos ] = 0;
				startElement( pTag, NULL );
				xml_state = XML_STATE_DATA;
				pChar = pData + pos + 1;

			}
			break;

		case XML_STATE_DATA:		// data

			if ( ( pos < ( len - 1 ) ) && 
						pData[ pos ] == _T('<') && 
						pData[ pos + 1] == _T('/')) {
				// We have parsed a full data object
				xml_state = XML_STATE_END;
				pData[ pos ] = 0;
				pData++; // Move past '/'
				characterHandler( pChar,  strlen( pChar ) );
			}
			else if ( ( pos < ( len - 1 ) ) && 
						pData[ pos ] == _T('<') && 
						pData[ pos + 1] != _T('?') &&
						pData[ pos + 1] != _T('&') ) {
				// Nested start tag
				xml_state = XML_STATE_START;
				pTag = pData + pos + 1;
			}
			break;

		case XML_STATE_END:			// end tag

			if ( pData[ pos ] == _T('>') ) {
				// We have parsed a full end tag
				pData[ pos ] = 0;
				endElement( pTag );
				xml_state = XML_STATE_NONE;
				pChar = pData + pos + 1;
			}
			break;

		default: // no state
			if ( pData[ pos ] == _T('<') ) {

				if ( pos < ( len - 1 ) ) {
				
					if ( pData[ pos + 1 ] == _T('/') ) {
						xml_state = XML_STATE_END;
						pTag = pData + pos + 2;
						pData++;
					}
					else if ( ( pData[ pos + 1 ] != _T('!') ) &&
						( pData[ pos + 1 ] != _T('?') ) ) {
						// Not a comment, new state "start tag"
						xml_state = XML_STATE_START;
						pTag = pData + pos + 1;
					}

				}
				
			}
			break;
		}

		// Next character
		pos++;
	}

	return rv;
}
示例#30
0
void Glissando::layout()
      {
      qreal       _spatium    = spatium();

      if (score() == gscore                                                   // for use in palettes
                  || startElement() == nullptr || endElement() == nullptr) {  // or while dragging
            if (spannerSegments().isEmpty())
                  add(createLineSegment());
            LineSegment* s = frontSegment();
            s->setPos(QPointF());
            s->setPos2(QPointF(_spatium * GLISS_PALETTE_WIDTH, -_spatium * GLISS_PALETTE_HEIGHT));
            s->layout();
            return;
            }

      SLine::layout();
      setPos(0.0, 0.0);
      adjustReadPos();

      Note*       anchor1     = static_cast<Note*>(startElement());
      Note*       anchor2     = static_cast<Note*>(endElement());
      Chord*      cr1         = anchor1->chord();
      Chord*      cr2         = anchor2->chord();
      GlissandoSegment*       segm1 = static_cast<GlissandoSegment*>(frontSegment());
      GlissandoSegment*       segm2 = static_cast<GlissandoSegment*>(backSegment());

      // Note: line segments are defined by
      // initial point: ipos() (relative to system origin)
      // ending point:  pos2() (relative to initial point)

      // LINE ENDING POINTS TO NOTE HEAD CENTRES

      // assume gliss. line goes from centre of initial note centre to centre of ending note:
      // move first segment origin and last segment ending point from note head origin to note head centre
      QPointF     offs1       = QPointF(anchor1->headWidth() * 0.5, 0.0);
      QPointF     offs2       = QPointF(anchor2->headWidth() * 0.5, 0.0);

      // AVOID HORIZONTAL LINES

      int         upDown      = (0 < (anchor2->pitch() - anchor1->pitch())) - ((anchor2->pitch() - anchor1->pitch()) < 0);
      // on TAB's, glissando are by necessity on the same string, this gives an horizontal glissando line;
      // make bottom end point lower and top ending point higher
      if (cr1->staff()->isTabStaff()) {
                  qreal yOff = cr1->staff()->lineDistance() * 0.3 * _spatium;
                  offs1.ry() += yOff * upDown;
                  offs2.ry() -= yOff * upDown;
            }
      // if not TAB, angle glissando between notes on the same line
      else {
            if (anchor1->line() == anchor2->line()) {
                  offs1.ry() += _spatium * 0.25 * upDown;
                  offs2.ry() -= _spatium * 0.25 * upDown;
                  }
            }

      // move initial point of first segment and adjust its length accordingly
      segm1->setPos (segm1->ipos()  + offs1);
      segm1->setPos2(segm1->ipos2() - offs1);
      // adjust ending point of last segment
      segm2->setPos2(segm2->ipos2() + offs2);

      // FINAL SYSTEM-INITIAL NOTE
      // if the last gliss. segment attaches to a system-initial note, some extra width has to be added
      if (cr2->segment()->measure() == cr2->segment()->system()->firstMeasure() && cr2->rtick() == 0)
      {
            segm2->rxpos() -= GLISS_STARTOFSYSTEM_WIDTH * _spatium;
            segm2->rxpos2()+= GLISS_STARTOFSYSTEM_WIDTH * _spatium;
      }

      // INTERPOLATION OF INTERMEDIATE POINTS
      // This probably belongs to SLine class itself; currently it does not seem
      // to be needed for anything else than Glissando, though

      // get total x-width and total y-height of all segments
      qreal xTot = 0.0;
      for (SpannerSegment* segm : spannerSegments())
            xTot += segm->ipos2().x();
      qreal y0   = segm1->ipos().y();
      qreal yTot = segm2->ipos().y() + segm2->ipos2().y() - y0;
      qreal ratio = yTot / xTot;
      // interpolate y-coord of intermediate points across total width and height
      qreal xCurr = 0.0;
      qreal yCurr;
      for (int i = 0; i < spannerSegments().count()-1; i++)
      {
           SpannerSegment* segm = segmentAt(i);
           xCurr += segm->ipos2().x();
           yCurr = y0 + ratio * xCurr;
           segm->rypos2() = yCurr - segm->ipos().y();       // position segm. end point at yCurr
           // next segment shall start where this segment stopped
           segm = segmentAt(i+1);
           segm->rypos2() += segm->ipos().y() - yCurr;      // adjust next segm. vertical length
           segm->rypos() = yCurr;                           // position next segm. start point at yCurr
      }

      // STAY CLEAR OF NOTE APPENDAGES

      // initial note dots / ledger line / note head
      offs1 *= -1.0;          // discount changes already applied
      int dots = cr1->dots();
      LedgerLine * ledLin = cr1->ledgerLines();
      // if dots, start at right of last dot
      // if no dots, from right of ledger line, if any; from right of note head, if no ledger line
      offs1.rx() += (dots && anchor1->dot(dots-1) ? anchor1->dot(dots-1)->pos().x() + anchor1->dot(dots-1)->width()
                  : (ledLin ? ledLin->pos().x() + ledLin->width() : anchor1->headWidth()) );

      // final note arpeggio / accidental / ledger line / accidental / arpeggio (i.e. from outermost to innermost)
      offs2 *= -1.0;          // discount changes already applied
      if (Arpeggio* a = cr2->arpeggio())
            offs2.rx() += a->pos().x() + a->userOff().x();
      else if (Accidental* a = anchor2->accidental())
            offs2.rx() += a->pos().x() + a->userOff().x();
      else if ( (ledLin = cr2->ledgerLines()) != nullptr)
            offs2.rx() += ledLin->pos().x();

      // add another a quarter spatium of 'air'
      offs1.rx() += _spatium * 0.25;
      offs2.rx() -= _spatium * 0.25;

      // apply offsets: shorten first segment by x1 (and proportionally y) and adjust its length accordingly
      offs1.ry() = segm1->ipos2().y() * offs1.x() / segm1->ipos2().x();
      segm1->setPos(segm1->ipos() + offs1);
      segm1->setPos2(segm1->ipos2() - offs1);
      // adjust last segment length by x2 (and proportionally y)
      offs2.ry() = segm2->ipos2().y() * offs2.x() / segm2->ipos2().x();
      segm2->setPos2(segm2->ipos2() + offs2);

      for (SpannerSegment* segm : spannerSegments())
            static_cast<GlissandoSegment*>(segm)->layout();

      // compute glissando bbox as the bbox of the last segment, relative to the end anchor note
      QPointF anchor2PagePos = anchor2->pagePos();
      QPointF system2PagePos = cr2->segment()->system()->pagePos();
      QPointF anchor2SystPos = anchor2PagePos - system2PagePos;
      QRectF r = QRectF(anchor2SystPos - segm2->pos(), anchor2SystPos - segm2->pos() - segm2->pos2()).normalized();
      qreal lw = _spatium * lineWidth().val() * .5;
      setbbox(r.adjusted(-lw, -lw, lw, lw));
      }