| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | #include <iostream> |
| |
|
| | #include <QFileInfo> |
| | #include <QLocale> |
| | #include <QString> |
| | #include <QStringList> |
| |
|
| | #include "rs_debug.h" |
| | #include "rs_font.h" |
| | #include "rs_fontlist.h" |
| | #include "rs_system.h" |
| |
|
| | RS_FontList* RS_FontList::uniqueInstance = nullptr; |
| |
|
| | RS_FontList* RS_FontList::instance() { |
| | if (!uniqueInstance) { |
| | uniqueInstance = new RS_FontList(); |
| | } |
| | return uniqueInstance; |
| | } |
| |
|
| |
|
| | |
| | |
| | |
| | |
| | void RS_FontList::init() { |
| | RS_DEBUG->print("RS_FontList::initFonts"); |
| |
|
| | QStringList list = RS_SYSTEM->getNewFontList(); |
| | list.append(RS_SYSTEM->getFontList()); |
| | QHash<QString, int> added; |
| |
|
| | for (int i = 0; i < list.size(); ++i) { |
| | RS_DEBUG->print(RS_Debug::D_ERROR, "font: %s:", list.at(i).toLatin1().data()); |
| |
|
| | QFileInfo fi( list.at(i) ); |
| | if ( !added.contains(fi.baseName()) ) { |
| | m_fonts.emplace_back(new RS_Font(fi.baseName())); |
| | added.insert(fi.baseName(), 1); |
| | } |
| |
|
| | RS_DEBUG->print(RS_Debug::D_ERROR, "base: %s", fi.baseName().toLatin1().data()); |
| | } |
| | } |
| |
|
| | size_t RS_FontList::countFonts() const{ |
| | return m_fonts.size(); |
| | } |
| |
|
| | std::vector<std::unique_ptr<RS_Font> >::const_iterator RS_FontList::begin() const |
| | { |
| | return m_fonts.begin(); |
| | } |
| |
|
| | std::vector<std::unique_ptr<RS_Font> >::const_iterator RS_FontList::end() const |
| | { |
| | return m_fonts.end(); |
| | } |
| |
|
| | |
| | |
| | |
| | void RS_FontList::clearFonts() { |
| | m_fonts.clear(); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | RS_Font* RS_FontList::requestFont(const QString& name) { |
| | RS_DEBUG->print("RS_FontList::requestFont %s", name.toLatin1().data()); |
| |
|
| | QString name2 = name.toLower(); |
| | RS_Font* foundFont = nullptr; |
| | if (name.isEmpty()) |
| | return foundFont; |
| |
|
| | |
| | if (name2.contains('#') && name2.contains('_')) { |
| | name2 = name2.left(name2.indexOf('_')); |
| | } else if (name2.contains('#')) { |
| | name2 = name2.left(name2.indexOf('#')); |
| | } |
| |
|
| | RS_DEBUG->print("name2: %s", name2.toLatin1().data()); |
| |
|
| | |
| | for( auto const& f: m_fonts){ |
| |
|
| | if (f->getFileName().toLower() == name2) { |
| | |
| | f->loadFont(); |
| | foundFont = f.get(); |
| | break; |
| | } |
| | } |
| |
|
| | if (!foundFont && name!="standard") { |
| | foundFont = requestFont("standard"); |
| | } |
| |
|
| | return foundFont; |
| | } |
| |
|
| |
|
| | QString RS_FontList::getDefaultFont() { |
| | QLocale loc = QLocale::system(); |
| | QLocale::Script script = loc.script(); |
| |
|
| | switch (script) { |
| | case QLocale::ArabicScript: |
| | return "amiri-regular"; |
| | case QLocale::CyrillicScript: |
| | return "OpenGostTypeA-Regular"; |
| | case QLocale::GreekScript: |
| | return "greeks"; |
| | case QLocale::JapaneseScript: |
| | return "kochigothic"; |
| | case QLocale::HangulScript: |
| | return "kst32b"; |
| | case QLocale::SimplifiedHanScript: |
| | case QLocale::TraditionalHanScript: |
| | return "unicode"; |
| | default: |
| | return "unicode"; |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | std::ostream& operator << (std::ostream& os, RS_FontList& l) { |
| |
|
| | os << "Fontlist: \n"; |
| | for(auto const& f: l.m_fonts){ |
| | os << *f << "\n"; |
| | } |
| |
|
| | return os; |
| | } |
| |
|