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

📄 notefont.cpp

📁 LINUX下的混音软件
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* -*- 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 "NoteFont.h"#include "misc/Debug.h"#include "misc/Strings.h"#include "base/Exception.h"#include "gui/general/PixmapFunctions.h"#include "NoteCharacter.h"#include "NoteFontMap.h"#include "SystemFont.h"#include <qbitmap.h>#include <qgarray.h>#include <qimage.h>#include <qpainter.h>#include <qpixmap.h>#include <qpoint.h>#include <qstring.h>#include <qstringlist.h>namespace Rosegarden{NoteFont::FontPixmapMap *NoteFont::m_fontPixmapMap = 0;NoteFont::DrawRepMap *NoteFont::m_drawRepMap = 0;QPixmap *NoteFont::m_blankPixmap = 0;NoteFont::NoteFont(std::string fontName, int size) :        m_fontMap(fontName){    // Do the size checks first, to avoid doing the extra work if they fail    std::set<int> sizes = m_fontMap.getSizes();    if (sizes.size() > 0) {        m_size = *sizes.begin();    } else {        throw BadNoteFont(std::string("No sizes listed for font ") + fontName);    }    if (size > 0) {        if (sizes.find(size) == sizes.end()) {            throw BadNoteFont(qstrtostr(QString("Font \"%1\" not available in size %2").arg(strtoqstr(fontName)).arg(size)));        } else {            m_size = size;        }    }    // Create the global font map and blank pixmap if necessary    if (m_fontPixmapMap == 0) {        m_fontPixmapMap = new FontPixmapMap();    }    if (m_blankPixmap == 0) {        m_blankPixmap = new QPixmap(10, 10);        m_blankPixmap->setMask(QBitmap(10, 10, TRUE));    }    // Locate our font's pixmap map in the font map, create if necessary    std::string fontKey = qstrtostr(QString("__%1__%2__")                                    .arg(strtoqstr(m_fontMap.getName()))                                    .arg(m_size));    FontPixmapMap::iterator i = m_fontPixmapMap->find(fontKey);    if (i == m_fontPixmapMap->end()) {        (*m_fontPixmapMap)[fontKey] = new PixmapMap();    }    m_map = (*m_fontPixmapMap)[fontKey];}NoteFont::~NoteFont(){    // empty}boolNoteFont::getStemThickness(unsigned int &thickness) const{    thickness = m_size / 9 + 1;    return m_fontMap.getStemThickness(m_size, thickness);}boolNoteFont::getBeamThickness(unsigned int &thickness) const{    thickness = m_size / 2;    return m_fontMap.getBeamThickness(m_size, thickness);}boolNoteFont::getStemLength(unsigned int &length) const{    getStaffLineThickness(length);    length = (m_size + length) * 7 / 2;    return m_fontMap.getStemLength(m_size, length);}boolNoteFont::getFlagSpacing(unsigned int &spacing) const{    spacing = m_size;    return m_fontMap.getFlagSpacing(m_size, spacing);}boolNoteFont::getStaffLineThickness(unsigned int &thickness) const{    thickness = (m_size < 7 ? 1 : m_size / 7);    return m_fontMap.getStaffLineThickness(m_size, thickness);}boolNoteFont::getLegerLineThickness(unsigned int &thickness) const{    thickness = (m_size < 6 ? 1 : m_size / 6);    return m_fontMap.getLegerLineThickness(m_size, thickness);}boolNoteFont::lookup(CharName charName, bool inverted, QPixmap *&pixmap) const{    PixmapMap::iterator i = m_map->find(charName);    if (i != m_map->end()) {        if (inverted) {            pixmap = i->second.second;            if (!pixmap && i->second.first)                return false;        } else {            pixmap = i->second.first;            if (!pixmap && i->second.second)                return false;        }        return true;    }    pixmap = 0;    return false;}voidNoteFont::add(CharName charName, bool inverted, QPixmap *pixmap) const{    PixmapMap::iterator i = m_map->find(charName);    if (i != m_map->end()) {        if (inverted) {            delete i->second.second;            i->second.second = pixmap;        } else {            delete i->second.first;            i->second.first = pixmap;        }    } else {        if (inverted) {            (*m_map)[charName] = PixmapPair(0, pixmap);        } else {            (*m_map)[charName] = PixmapPair(pixmap, 0);        }    }}    NoteCharacterDrawRep *NoteFont::lookupDrawRep(QPixmap *pixmap) const{    if (!m_drawRepMap)        m_drawRepMap = new DrawRepMap();    if (m_drawRepMap->find(pixmap) != m_drawRepMap->end()) {        return (*m_drawRepMap)[pixmap];    } else {        QImage image = pixmap->convertToImage();        if (image.isNull())            return 0;        if (image.depth() > 1) {            image = image.convertDepth(1, Qt::MonoOnly | Qt::ThresholdDither);        }        NoteCharacterDrawRep *a = new NoteCharacterDrawRep();        for (int yi = 0; yi < image.height(); ++yi) {            unsigned char *line = image.scanLine(yi);            int startx = 0;            for (int xi = 0; xi <= image.width(); ++xi) {                bool pixel = false;                if (xi < image.width()) {                    if (image.bitOrder() == QImage::LittleEndian) {                        if (*(line + (xi >> 3)) & 1 << (xi & 7))                            pixel = true;                    } else {                        if (*(line + (xi >> 3)) & 1 << (7 - (xi & 7)))                            pixel = true;                    }                }                if (!pixel) {                    if (startx < xi) {                        a->resize(a->size() + 2, QGArray::SpeedOptim);                        a->setPoint(a->size() - 2, startx, yi);                        a->setPoint(a->size() - 1, xi - 1, yi);                    }                    startx = xi + 1;                }            }        }        (*m_drawRepMap)[pixmap] = a;        return a;    }}boolNoteFont::getPixmap(CharName charName, QPixmap &pixmap, bool inverted) const{    QPixmap *found = 0;    bool ok = lookup(charName, inverted, found);    if (ok) {        if (found) {            pixmap = *found;            return true;        } else {            pixmap = *m_blankPixmap;            return false;        }    }    if (inverted && !m_fontMap.hasInversion(m_size, charName)) {        if (!getPixmap(charName, pixmap, !inverted))            return false;        found = new QPixmap(PixmapFunctions::flipVertical(pixmap));        add(charName, inverted, found);        pixmap = *found;        return true;    }    std::string src;    ok = false;    if (!inverted)        ok = m_fontMap.getSrc(m_size, charName, src);    else        ok = m_fontMap.getInversionSrc(m_size, charName, src);    if (ok) {        NOTATION_DEBUG        << "NoteFont::getPixmap: Loading \"" << src << "\"" << endl;        found = new QPixmap(strtoqstr(src));        if (!found->isNull()) {            if (found->mask() == 0) {                std::cerr << "NoteFont::getPixmap: Warning: No automatic mask "                << "for character \"" << charName << "\""                << (inverted ? " (inverted)" : "") << " in font \""                << m_fontMap.getName() << "-" << m_size                << "\"; consider making xpm background transparent"                << std::endl;                found->setMask(PixmapFunctions::generateMask(*found));            }            add(charName, inverted, found);            pixmap = *found;            return true;        }        std::cerr << "NoteFont::getPixmap: Warning: Unable to read pixmap file " << src << std::endl;    } else {        int code = -1;        if (!inverted)            ok = m_fontMap.getCode(m_size, charName, code);        else            ok = m_fontMap.getInversionCode(m_size, charName, code);        int glyph = -1;        if (!inverted)            ok = m_fontMap.getGlyph(m_size, charName, glyph);        else            ok = m_fontMap.getInversionGlyph(m_size, charName, glyph);        if (code < 0 && glyph < 0) {            std::cerr << "NoteFont::getPixmap: Warning: No pixmap, code, or glyph for character \""            << charName << "\"" << (inverted ? " (inverted)" : "")            << " in font \"" << m_fontMap.getName() << "\"" << std::endl;            add(charName, inverted, 0);            pixmap = *m_blankPixmap;            return false;        }

⌨️ 快捷键说明

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