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); }
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); }
void KoXmlWriter::addManifestEntry( const QString& fullPath, const QString& mediaType ) { startElement( "manifest:file-entry" ); addAttribute( "manifest:media-type", mediaType ); addAttribute( "manifest:full-path", fullPath ); endElement(); }
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); }
void KoXmlWriter::addConfigItem( const QString & configName, const QString& value ) { startElement( "config:config-item" ); addAttribute( "config:name", configName ); addAttribute( "config:type", "string" ); addTextNode( value ); endElement(); }
void CXMLDocument::endElementCallback(void *ctx, const xmlChar *name) { if (allowcallbacks) CB_endElement((const char *)name); if (buildtree) endElement(ctx,name); }
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(); }
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(); }
bool QXmlDefaultHandler_QtDShell::__override_endElement(const QString& namespaceURI0, const QString& localName1, const QString& qName2, bool static_call) { if (static_call) { return QXmlDefaultHandler::endElement((const QString& )namespaceURI0, (const QString& )localName1, (const QString& )qName2); } else { return endElement((const QString& )namespaceURI0, (const QString& )localName1, (const QString& )qName2); } }
/*! \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()); }
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; } } }
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); } }
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); }
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(); } }
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); }
// --------------------------------------------------------------------------- // XSDDOMParser: Implementation of the XMLDocumentHandler interface // --------------------------------------------------------------------------- void XSDDOMParser::startElement( const XMLElementDecl& elemDecl , const unsigned int urlId , const XMLCh* const elemPrefix , const RefVectorOf<XMLAttr>& attrList , const unsigned int attrCount , const bool isEmpty , const bool isRoot) { fDepth++; // while it is true that non-whitespace character data // may only occur in appInfo or documentation // elements, it's certainly legal for comments and PI's to // occur as children of annotation; we need // to account for these here. if (fAnnotationDepth == -1) { if (XMLString::equals(elemDecl.getBaseName(), SchemaSymbols::fgELT_ANNOTATION) && XMLString::equals(getURIText(urlId), SchemaSymbols::fgURI_SCHEMAFORSCHEMA)) { fAnnotationDepth = fDepth; startAnnotation(elemDecl, attrList, attrCount); } } else if (fDepth == fAnnotationDepth+1) { fInnerAnnotationDepth = fDepth; startAnnotationElement(elemDecl, attrList, attrCount); } else { startAnnotationElement(elemDecl, attrList, attrCount); // avoid falling through; don't call startElement in this case return; } DOMElement *elem; if (urlId != fScanner->getEmptyNamespaceId()) //TagName has a prefix { if (elemPrefix && *elemPrefix) { XMLBufBid elemQName(&fBufMgr); elemQName.set(elemPrefix); elemQName.append(chColon); elemQName.append(elemDecl.getBaseName()); elem = createElementNSNode( fScanner->getURIText(urlId), elemQName.getRawBuffer()); } else { elem = createElementNSNode( fScanner->getURIText(urlId), elemDecl.getBaseName()); } } else { elem = createElementNSNode(0, elemDecl.getBaseName()); } DOMElementImpl *elemImpl = (DOMElementImpl *) elem; for (unsigned int index = 0; index < attrCount; ++index) { const XMLAttr* oneAttrib = attrList.elementAt(index); unsigned int attrURIId = oneAttrib->getURIId(); const XMLCh* namespaceURI = 0; //for xmlns=... if (XMLString::equals(oneAttrib->getName(), XMLUni::fgXMLNSString)) attrURIId = fScanner->getXMLNSNamespaceId(); //TagName has a prefix if (attrURIId != fScanner->getEmptyNamespaceId()) namespaceURI = fScanner->getURIText(attrURIId); //get namespaceURI // revisit. Optimize to init the named node map to the // right size up front. DOMAttrImpl *attr = (DOMAttrImpl *) fDocument->createAttributeNS(namespaceURI, oneAttrib->getQName()); attr->setValue(oneAttrib -> getValue()); DOMNode* remAttr = elemImpl->setAttributeNodeNS(attr); if (remAttr) remAttr->release(); // Attributes of type ID. If this is one, add it to the hashtable of IDs // that is constructed for use by GetElementByID(). if (oneAttrib->getType()==XMLAttDef::ID) { if (fDocument->fNodeIDMap == 0) fDocument->fNodeIDMap = new (fDocument) DOMNodeIDMap(500, fDocument); fDocument->fNodeIDMap->add(attr); attr->fNode.isIdAttr(true); } attr->setSpecified(oneAttrib->getSpecified()); } // set up the default attributes if (elemDecl.hasAttDefs()) { XMLAttDefList* defAttrs = &elemDecl.getAttDefList(); XMLAttDef* attr = 0; DOMAttrImpl * insertAttr = 0; while (defAttrs->hasMoreElements()) { attr = &defAttrs->nextElement(); const XMLAttDef::DefAttTypes defType = attr->getDefaultType(); if ((defType == XMLAttDef::Default) || (defType == XMLAttDef::Fixed)) { // DOM Level 2 wants all namespace declaration attributes // to be bound to "http://www.w3.org/2000/xmlns/" // So as long as the XML parser doesn't do it, it needs to // done here. const XMLCh* qualifiedName = attr->getFullName(); XMLBufBid bbPrefixQName(&fBufMgr); XMLBuffer& prefixBuf = bbPrefixQName.getBuffer(); int colonPos = -1; unsigned int uriId = fScanner->resolveQName(qualifiedName, prefixBuf, ElemStack::Mode_Attribute, colonPos); const XMLCh* namespaceURI = 0; if (XMLString::equals(qualifiedName, XMLUni::fgXMLNSString)) uriId = fScanner->getXMLNSNamespaceId(); //TagName has a prefix if (uriId != fScanner->getEmptyNamespaceId()) namespaceURI = fScanner->getURIText(uriId); insertAttr = (DOMAttrImpl *) fDocument->createAttributeNS( namespaceURI, qualifiedName); DOMAttr* remAttr = elemImpl->setDefaultAttributeNodeNS(insertAttr); if (remAttr) remAttr->release(); if (attr->getValue() != 0) { insertAttr->setValue(attr->getValue()); insertAttr->setSpecified(false); } } insertAttr = 0; attr->reset(); } } fCurrentParent->appendChild(elem); fNodeStack->push(fCurrentParent); fCurrentParent = elem; fCurrentNode = elem; fWithinElement = true; // If an empty element, do end right now (no endElement() will be called) if (isEmpty) endElement(elemDecl, urlId, isRoot, elemPrefix); }
int SLine::tick2() const { if (endElement()->type() != SEGMENT) return -1; return static_cast<Segment*>(endElement())->tick(); }
~XmlWriter() { while( !m_tags.empty() ) endElement(); }
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(); } }
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(); } }
void KoXmlWriter::addTextSpan(const QString& text, const QMap<int, int>& tabCache) { int 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 (int i = 0; i < len ; ++i) { QChar ch = text[i]; ushort unicode = ch.unicode(); if (unicode == ' ') { if (i == 0) leadingSpace = true; ++nrSpaces; } else { 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.clear(); startElement("text:s"); if (nrSpaces > 1) // it's 1 by default addAttribute("text:c", nrSpaces); endElement(); } } nrSpaces = 0; leadingSpace = false; switch (unicode) { case '\t': if (!str.isEmpty()) addTextNode(str); str.clear(); startElement("text:tab"); if (tabCache.contains(i)) addAttribute("text:tab-ref", tabCache[i] + 1); endElement(); break; // gracefully handle \f form feed in text input. // otherwise the xml will not be valid. // \f can be added e.g. in ascii import filter. case '\f': case '\n': case QChar::LineSeparator: if (!str.isEmpty()) addTextNode(str); str.clear(); startElement("text:line-break"); endElement(); break; default: // don't add stuff that is not allowed in xml. The stuff we need we have already handled above if (ch.unicode() >= 0x20) { 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(); } }
static int rcParse(LoadMibState *state, char *buf, size_t length) { char *elementName; char *atts[MAX_ATTRIBUTES * 2]; int attNameIdx = 0; int attValueIdx = 1; char *cursor; char *attStart; int bytesRemaining; char *delimiter; char *token; if (length < 2) { writeMemoNote("[?] No element name in rc line", buf); return -1; } cursor = buf + 1; findToken(&cursor, &token); if (token == NULL) { writeMemo("Element name omitted."); return -1; } elementName = token; memset(atts, 0, sizeof atts); bytesRemaining = length - (cursor - buf); while (bytesRemaining > 0) { if (bytesRemaining < 2) { writeMemoNote("[?] Incomplete rc line attribute", cursor); return -1; } attStart = cursor; delimiter = strchr(cursor, '='); if (delimiter == NULL) { writeMemoNote("[?] Attribute name not terminated", cursor); return -1; } if (attValueIdx > MAX_ATTRIBUTES) { writeMemoNote("[?] Too many attributes", cursor); return -1; } atts[attNameIdx] = cursor; *delimiter = 0; cursor = delimiter + 1; findToken(&cursor, &token); if (token == NULL) { writeMemoNote("[?] Attribute value omitted", atts[attNameIdx]); return -1; } atts[attValueIdx] = token; attNameIdx += 2; attValueIdx += 2; bytesRemaining -= (cursor - attStart); } switch (buf[0]) { case '+': startElement(state, elementName, (const char **) atts); break; case '-': endElement(state, elementName); break; case '*': startElement(state, elementName, (const char **) atts); endElement(state, elementName); break; default: writeMemoNote("[?] Invalid rc line control character", buf); return -1; } return 0; }
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); }
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); }
Note* Tie::endNote() const { Q_ASSERT(!endElement() || endElement()->type() == Element::Type::NOTE); return static_cast<Note*>(endElement()); }
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; }
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)); }