Skip to content

Commit

Permalink
use qfont for print, not freetype rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
wschweer committed May 11, 2015
1 parent dcdf697 commit 9e84592
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions libmscore/mscore.cpp
Expand Up @@ -95,6 +95,7 @@ int MScore::mtcType;

bool MScore::noExcerpts = false;
bool MScore::noImages = false;
bool MScore::pdfPrinting = false;

#ifdef SCRIPT_INTERFACE
QQmlEngine* MScore::_qml = 0;
Expand Down
2 changes: 2 additions & 0 deletions libmscore/mscore.h
Expand Up @@ -407,6 +407,8 @@ class MScore : public QObject {
static bool noExcerpts;
static bool noImages;

static bool pdfPrinting;

#ifdef SCRIPT_INTERFACE
static QQmlEngine* qml();
#endif
Expand Down
25 changes: 25 additions & 0 deletions libmscore/sym.cpp
Expand Up @@ -5209,6 +5209,31 @@ void ScoreFont::draw(SymId id, QPainter* painter, qreal mag, const QPointF& pos,
return;
}

if (MScore::pdfPrinting) {
if (font == 0) {
QString s(_fontPath+_filename);
if (-1 == QFontDatabase::addApplicationFont(s)) {
qDebug("Mscore: fatal error: cannot load internal font <%s>", qPrintable(s));
return;
}
printf("load <%s> <%s>\n", qPrintable(s), qPrintable(_family));
font = new QFont;
font->setWeight(QFont::Normal);
font->setItalic(false);
font->setFamily(_family);
font->setStyleStrategy(QFont::NoFontMerging);
font->setHintingPreference(QFont::PreferVerticalHinting);
qreal size = 20.0 * MScore::DPI / PPI;
font->setPixelSize(lrint(size));
}
qreal imag = 1.0 / mag;
painter->scale(mag, mag);
painter->setFont(*font);
painter->drawText(pos * imag, toString(id));
painter->scale(imag, imag);
return;
}

QColor color(painter->pen().color());

int pr = painter->device()->devicePixelRatio();
Expand Down
1 change: 1 addition & 0 deletions libmscore/sym.h
Expand Up @@ -2566,6 +2566,7 @@ class ScoreFont {
QString _filename;
QByteArray fontImage;
QCache<GlyphKey, GlyphPixmap>* cache { 0 };
mutable QFont* font { 0 };

static QVector<ScoreFont> _scoreFonts;
const Sym& sym(SymId id) const { return _symbols[int(id)]; }
Expand Down
8 changes: 7 additions & 1 deletion mscore/file.cpp
Expand Up @@ -1848,7 +1848,7 @@ bool MuseScore::savePdf(const QString& saveName)
bool MuseScore::savePdf(Score* cs, const QString& saveName)
{
cs->setPrinting(true);

MScore::pdfPrinting = true;
QPdfWriter printerDev(saveName);
printerDev.setResolution(preferences.exportPdfDpi);
const PageFormat* pf = cs->pageFormat();
Expand Down Expand Up @@ -1878,6 +1878,7 @@ bool MuseScore::savePdf(Score* cs, const QString& saveName)
}
p.end();
cs->setPrinting(false);
MScore::pdfPrinting = false;
return true;
}

Expand Down Expand Up @@ -1926,6 +1927,7 @@ bool MuseScore::savePdf(QList<Score*> cs, const QString& saveName)
s->doLayout();
}
s->setPrinting(true);
MScore::pdfPrinting = true;

// we ignore the configured page offset
// we display page footer on all pages
Expand Down Expand Up @@ -1986,6 +1988,8 @@ bool MuseScore::savePdf(QList<Score*> cs, const QString& saveName)

//reset score
s->setPrinting(false);
MScore::pdfPrinting = false;

s->setPageNumberOffset(oldPageOffset);
s->style()->set(StyleIdx::footerFirstPage, footerFirstPage);
s->style()->set(StyleIdx::evenFooterL, evenFooterL);
Expand Down Expand Up @@ -2565,6 +2569,7 @@ bool MuseScore::saveSvg(Score* score, const QString& saveName)
printer.setViewBox(QRectF(0.0, 0.0, w * mag, h * mag));

score->setPrinting(true);
MScore::pdfPrinting = true;

QPainter p(&printer);
p.setRenderHint(QPainter::Antialiasing, true);
Expand All @@ -2581,6 +2586,7 @@ bool MuseScore::saveSvg(Score* score, const QString& saveName)
}

score->setPrinting(false);
MScore::pdfPrinting = false;
p.end();
return true;
}
Expand Down

0 comments on commit 9e84592

Please sign in to comment.