⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 notefontmap.cpp

📁 LINUX下的混音软件
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: *//*    Rosegarden    A MIDI and audio sequencer and musical notation editor.     This program is Copyright 2000-2007        Guillaume Laurent   <glaurent@telegraph-road.org>,        Chris Cannam        <cannam@all-day-breakfast.com>,        Richard Bown        <richard.bown@ferventsoftware.com>     The moral rights of Guillaume Laurent, Chris Cannam, and Richard    Bown to claim authorship of this work have been asserted.     Other copyrights also apply to some parts of this work.  Please    see the AUTHORS file and individual file headers for details.     This program is free software; you can redistribute it and/or    modify it under the terms of the GNU General Public License as    published by the Free Software Foundation; either version 2 of the    License, or (at your option) any later version.  See the file    COPYING included with this distribution for more information.*/#include "NoteFontMap.h"#include "misc/Debug.h"#include <klocale.h>#include <kstddirs.h>#include "misc/Strings.h"#include "base/Exception.h"#include "SystemFont.h"#include <kglobal.h>#include <qfile.h>#include <qfileinfo.h>#include <qpixmap.h>#include <qregexp.h>#include <qstring.h>#include <qstringlist.h>namespace Rosegarden{NoteFontMap::NoteFontMap(std::string name) :        m_name(name),        m_smooth(false),        m_srcDirectory(name),        m_characterDestination(0),        m_hotspotCharName(""),        m_errorString(i18n("unknown error")),        m_ok(true){    m_fontDirectory = KGlobal::dirs()->findResource("appdata", "fonts/");    QString mapFileName;    QString mapFileMixedName = QString("%1/mappings/%2.xml")                               .arg(m_fontDirectory)                               .arg(strtoqstr(name));    QFileInfo mapFileMixedInfo(mapFileMixedName);    if (!mapFileMixedInfo.isReadable()) {        QString lowerName = strtoqstr(name).lower();        lowerName.replace(QRegExp(" "), "_");        QString mapFileLowerName = QString("%1/mappings/%2.xml")                                   .arg(m_fontDirectory)                                   .arg(lowerName);        QFileInfo mapFileLowerInfo(mapFileLowerName);        if (!mapFileLowerInfo.isReadable()) {            if (mapFileLowerName != mapFileMixedName) {                throw MappingFileReadFailed                (qstrtostr(i18n("Can't open font mapping file %1 or %2").                           arg(mapFileMixedName).arg(mapFileLowerName)));            } else {                throw MappingFileReadFailed                (qstrtostr(i18n("Can't open font mapping file %1").                           arg(mapFileMixedName)));            }        } else {            mapFileName = mapFileLowerName;        }    } else {        mapFileName = mapFileMixedName;    }    QFile mapFile(mapFileName);    QXmlInputSource source(mapFile);    QXmlSimpleReader reader;    reader.setContentHandler(this);    reader.setErrorHandler(this);    bool ok = reader.parse(source);    mapFile.close();    if (!ok) {        throw MappingFileReadFailed(qstrtostr(m_errorString));    }}NoteFontMap::~NoteFontMap(){    for (SystemFontMap::iterator i = m_systemFontCache.begin();            i != m_systemFontCache.end(); ++i) {        delete i->second;    }}boolNoteFontMap::characters(QString &chars){    if (!m_characterDestination)        return true;    *m_characterDestination += qstrtostr(chars);    return true;}intNoteFontMap::toSize(int baseSize, double factor, bool limitAtOne){    double dsize = factor * baseSize;    dsize += 0.5;    if (limitAtOne && dsize < 1.0)        dsize = 1.0;    return int(dsize);}boolNoteFontMap::startElement(const QString &, const QString &,                          const QString &qName,                          const QXmlAttributes &attributes){    QString lcName = qName.lower();    m_characterDestination = 0;    // The element names are actually unique within the whole file;    // we don't bother checking we're in the right context.  Leave that    // to the DTD, when we have one.    if (lcName == "rosegarden-font-encoding") {        QString s;        s = attributes.value("name");        if (s) {            m_name = qstrtostr(s);            m_srcDirectory = m_name;        }    } else if (lcName == "font-information") {        QString s;        s = attributes.value("origin");        if (s)            m_origin = qstrtostr(s);        s = attributes.value("copyright");        if (s)            m_copyright = qstrtostr(s);        s = attributes.value("mapped-by");        if (s)            m_mappedBy = qstrtostr(s);        s = attributes.value("type");        if (s)            m_type = qstrtostr(s);        s = attributes.value("autocrop");        if (s) {            std::cerr << "Warning: autocrop attribute in note font mapping file is no longer supported\n(all fonts are now always autocropped)" << std::endl;        }        s = attributes.value("smooth");        if (s)            m_smooth = (s.lower() == "true");    } else if (lcName == "font-sizes") {    }    else if (lcName == "font-size") {        QString s = attributes.value("note-height");        if (!s) {            m_errorString = "note-height is a required attribute of font-size";            return false;        }        int noteHeight = s.toInt();        SizeData &sizeData = m_sizes[noteHeight];        s = attributes.value("staff-line-thickness");        if (s)            sizeData.setStaffLineThickness(s.toInt());        s = attributes.value("leger-line-thickness");        if (s)            sizeData.setLegerLineThickness(s.toInt());        s = attributes.value("stem-thickness");        if (s)            sizeData.setStemThickness(s.toInt());        s = attributes.value("beam-thickness");        if (s)            sizeData.setBeamThickness(s.toInt());        s = attributes.value("stem-length");        if (s)            sizeData.setStemLength(s.toInt());        s = attributes.value("flag-spacing");        if (s)            sizeData.setFlagSpacing(s.toInt());        s = attributes.value("border-x");        if (s) {            std::cerr << "Warning: border-x attribute in note font mapping file is no longer supported\n(use hotspot-x for note head or flag)" << std::endl;        }        s = attributes.value("border-y");        if (s) {            std::cerr << "Warning: border-y attribute in note font mapping file is no longer supported" << std::endl;        }        int fontId = 0;        s = attributes.value("font-id");        if (s)            fontId = s.toInt();        s = attributes.value("font-height");        if (s)            sizeData.setFontHeight(fontId, s.toInt());    } else if (lcName == "font-scale") {        double fontHeight = -1.0;        double beamThickness = -1.0;        double stemLength = -1.0;        double flagSpacing = -1.0;        double staffLineThickness = -1.0;        double legerLineThickness = -1.0;        double stemThickness = -1.0;        QString s;        s = attributes.value("font-height");        if (s)            fontHeight = qstrtodouble(s);        else {            m_errorString = "font-height is a required attribute of font-scale";            return false;        }        s = attributes.value("staff-line-thickness");        if (s)            staffLineThickness = qstrtodouble(s);        s = attributes.value("leger-line-thickness");        if (s)            legerLineThickness = qstrtodouble(s);        s = attributes.value("stem-thickness");        if (s)            stemThickness = qstrtodouble(s);        s = attributes.value("beam-thickness");        if (s)            beamThickness = qstrtodouble(s);        s = attributes.value("stem-length");        if (s)            stemLength = qstrtodouble(s);        s = attributes.value("flag-spacing");        if (s)            flagSpacing = qstrtodouble(s);        int fontId = 0;        s = attributes.value("font-id");        if (s)            fontId = s.toInt();        //!!! need to be able to calculate max size -- checkFont needs        //to take a size argument; unfortunately Qt doesn't seem to be        //able to report to us when a scalable font was loaded in the        //wrong size, so large sizes might be significantly inaccurate        //as it just stops scaling up any further at somewhere around        //120px.  We could test whether the metric for the black        //notehead is noticeably smaller than the notehead should be,        //and reject if so?  [update -- no, that doesn't work either,        //Qt just returns the correct metric even if drawing the        //incorrect size]        for (int sz = 1; sz <= 30; sz += (sz == 1 ? 1 : 2)) {            SizeData & sizeData = m_sizes[sz];            unsigned int temp;            if (sizeData.getStaffLineThickness(temp) == false &&                    staffLineThickness >= 0.0)                sizeData.setStaffLineThickness(toSize(sz, staffLineThickness, true));            if (sizeData.getLegerLineThickness(temp) == false &&                    legerLineThickness >= 0.0)                sizeData.setLegerLineThickness(toSize(sz, legerLineThickness, true));            if (sizeData.getStemThickness(temp) == false &&                    stemThickness >= 0.0)                sizeData.setStemThickness(toSize(sz, stemThickness, true));            if (sizeData.getBeamThickness(temp) == false &&                    beamThickness >= 0.0)                sizeData.setBeamThickness(toSize(sz, beamThickness, true));            if (sizeData.getStemLength(temp) == false &&                    stemLength >= 0.0)                sizeData.setStemLength(toSize(sz, stemLength, true));            if (sizeData.getFlagSpacing(temp) == false &&                    flagSpacing >= 0.0)                sizeData.setFlagSpacing(toSize(sz, flagSpacing, true));            if (sizeData.getFontHeight(fontId, temp) == false)                sizeData.setFontHeight(fontId, toSize(sz, fontHeight, true));        }    } else if (lcName == "font-symbol-map") {    }    else if (lcName == "src-directory") {        QString d = attributes.value("name");        if (!d) {            m_errorString = "name is a required attribute of src-directory";            return false;        }        m_srcDirectory = qstrtostr(d);    } else if (lcName == "codebase") {        int bn = 0, fn = 0;        bool ok;        QString base = attributes.value("base");        if (!base) {            m_errorString = "base is a required attribute of codebase";            return false;        }        bn = base.toInt(&ok);        if (!ok || bn < 0) {            m_errorString =                QString("invalid base attribute \"%1\" (must be integer >= 0)").                arg(base);            return false;        }        QString fontId = attributes.value("font-id");        if (!fontId) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -