Merge pull request #2552 from sidewayss/#105436-#105471-saveSVG-cleanup

Fix #105436 Fix #105471 save svg cleanup
This commit is contained in:
Nicolas Froment 2016-04-16 10:32:02 +02:00
commit d68ac1e9b1
2 changed files with 98 additions and 72 deletions

View file

@ -2506,7 +2506,7 @@ bool MuseScore::saveSvg(Score* score, const QString& saveName)
QString title(score->title());
printer.setTitle(title);
printer.setFileName(saveName);
const PageFormat* pf = cs->pageFormat();
const PageFormat* pf = score->pageFormat();
QRectF r;
if (trimMargin >= 0 && score->npages() == 1) {
@ -2531,9 +2531,9 @@ bool MuseScore::saveSvg(Score* score, const QString& saveName)
if (trimMargin >= 0 && score->npages() == 1)
p.translate(-r.topLeft());
foreach (Page* page, score->pages()) {
for (Page* page : score->pages()) {
// 1st pass: StaffLines
foreach (System* s, page->systems()) {
for (System* s : page->systems()) {
for (int i = 0, n = s->staves()->size(); i < n; i++) {
if (score->staff(i)->invisible())
continue; // ignore invisible staves
@ -2542,24 +2542,29 @@ bool MuseScore::saveSvg(Score* score, const QString& saveName)
// MuseScore draws staff lines by measure, but for SVG they can
// generally be drawn once for each system. This makes a big
// difference for scores that scroll horizontally on a single
// page. But there is an exception to this rule:
// page. But there are exceptions to this rule:
//
// ~ One (or more) invisible measure(s) in a system/staff ~
// In this case the SVG staff lines for the system/staff
// ~ One (or more) elements of type HBOX or VBOX ~
//
// In these cases the SVG staff lines for the system/staff
// are drawn by measure.
//
bool byMeasure = false;
for (MeasureBase* mb = s->firstMeasure(); mb != 0; mb = s->nextMeasure(mb)) {
if (!static_cast<Measure*>(mb)->visible(i)) {
if (mb->type() == Element::Type::HBOX
|| mb->type() == Element::Type::VBOX
|| !static_cast<Measure*>(mb)->visible(i)) {
byMeasure = true;
break;
}
}
if (byMeasure) { // Draw visible staff lines by measure
for (MeasureBase* mb = s->firstMeasure(); mb != 0; mb = s->nextMeasure(mb)) {
Measure* m = static_cast<Measure*>(mb);
if (m->visible(i)) {
StaffLines* sl = m->staffLines(i);
if (mb->type() != Element::Type::HBOX
&& mb->type() != Element::Type::VBOX
&& static_cast<Measure*>(mb)->visible(i)) {
StaffLines* sl = static_cast<Measure*>(mb)->staffLines(i);
printer.setElement(sl);
paintElement(p, sl);
}
@ -2581,7 +2586,7 @@ bool MuseScore::saveSvg(Score* score, const QString& saveName)
qStableSort(pel.begin(), pel.end(), elementLessThan);
Element::Type eType;
foreach (const Element* e, pel) {
for (const Element* e : pel) {
// Always exclude invisible elements
if (!e->visible())
continue;

View file

@ -232,7 +232,7 @@ private:
QString stateString;
QTextStream stateStream;
// To eliminate transform attribute on polylines
// Qt translates everything. These help avoid SVG transform="translate()".
qreal _dx;
qreal _dy;
@ -275,6 +275,7 @@ protected:
#define SVG_CLASS " class=\""
#define SVG_ELEMENT_END "/>"
#define SVG_RPAREN_QUOTE ")\""
#define SVG_TITLE_BEGIN "<title>"
#define SVG_TITLE_END "</title>"
@ -306,6 +307,8 @@ protected:
#define SVG_FILL_RULE " fill-rule=\"evenodd\""
#define SVG_VECTOR_EFFECT " vector-effect=\"non-scaling-stroke\""
#define SVG_MATRIX " transform=\"matrix("
public:
SvgPaintEngine()
: QPaintEngine(*new SvgPaintEnginePrivate,
@ -1126,10 +1129,28 @@ void SvgPaintEngine::updateState(const QPaintEngineState &state)
if (!qFuzzyIsNull(state.opacity() - 1))
stateStream << SVG_OPACITY << state.opacity() << SVG_QUOTE;
// Set these class variables for later use in the drawXXX() functions
QMatrix mx = state.matrix();
_dx = mx.dx();
_dy = mx.dy();
// Translations, SVG transform="translate()", are handled separately from
// other transformations such as rotation. Qt translates everything, but
// other transformations do occur, and must be handled here.
QTransform t = state.transform();
if (t.m11() == t.m22() // No scaling
&& t.m12() == t.m21()) { // No rotation, etc.
// No transformation except translation
_dx = t.m31();
_dy = t.m32();
}
else {
// Other transformations are more straightforward with a full matrix
_dx = 0;
_dy = 0;
stateStream << SVG_MATRIX << t.m11() << SVG_COMMA
<< t.m12() << SVG_COMMA
<< t.m21() << SVG_COMMA
<< t.m22() << SVG_COMMA
<< t.m31() << SVG_COMMA
<< t.m32() << SVG_RPAREN_QUOTE;
}
}
void SvgPaintEngine::drawPath(const QPainterPath &p)