aboutsummaryrefslogtreecommitdiff
path: root/fonts
ModeNameSize
-rw-r--r--DroidSansFallbackFull.ttf4529044logplain
-rw-r--r--liberationmono.ttf333636logplain
-rw-r--r--liberationsans.ttf133828logplain
-rwxr-xr-xlucida_sans_10.xml156248logplain
-rwxr-xr-xlucida_sans_100.png12012logplain
-rwxr-xr-xlucida_sans_11.xml157272logplain
-rwxr-xr-xlucida_sans_110.png14739logplain
-rwxr-xr-xlucida_sans_12.xml157058logplain
-rwxr-xr-xlucida_sans_120.png16295logplain
-rwxr-xr-xlucida_sans_14.xml159272logplain
-rwxr-xr-xlucida_sans_140.png42429logplain
-rwxr-xr-xlucida_sans_16.xml160744logplain
-rwxr-xr-xlucida_sans_160.png48106logplain
-rwxr-xr-xlucida_sans_18.xml162284logplain
-rwxr-xr-xlucida_sans_180.png56766logplain
-rwxr-xr-xlucida_sans_20.xml162438logplain
-rwxr-xr-xlucida_sans_200.png69059logplain
-rwxr-xr-xlucida_sans_22.xml162936logplain
-rwxr-xr-xlucida_sans_220.png74427logplain
-rwxr-xr-xlucida_sans_24.xml166358logplain
-rwxr-xr-xlucida_sans_240.png83532logplain
-rwxr-xr-xlucida_sans_26.xml167054logplain
-rwxr-xr-xlucida_sans_260.png93958logplain
-rwxr-xr-xlucida_sans_28.xml167156logplain
-rwxr-xr-xlucida_sans_280.png101952logplain
-rwxr-xr-xlucida_sans_36.xml169606logplain
-rwxr-xr-xlucida_sans_360.png143453logplain
-rwxr-xr-xlucida_sans_4.xml136910logplain
-rwxr-xr-xlucida_sans_40.png7642logplain
-rwxr-xr-xlucida_sans_48.xml171972logplain
-rwxr-xr-xlucida_sans_480.png205578logplain
-rwxr-xr-xlucida_sans_56.xml174174logplain
-rwxr-xr-xlucida_sans_560.png246505logplain
-rwxr-xr-xlucida_sans_6.xml140552logplain
-rwxr-xr-xlucida_sans_60.png13992logplain
-rwxr-xr-xlucida_sans_8.xml154564logplain
-rwxr-xr-xlucida_sans_80.png9740logplain
-rwxr-xr-xlucida_sans_9.xml154830logplain
-rwxr-xr-xlucida_sans_90.png10704logplain
-rwxr-xr-xmono_dejavu_sans_10.xml257014logplain
-rwxr-xr-xmono_dejavu_sans_100.png56121logplain
-rwxr-xr-xmono_dejavu_sans_11.xml263644logplain
-rwxr-xr-xmono_dejavu_sans_110.png67613logplain
-rwxr-xr-xmono_dejavu_sans_12.xml268932logplain
-rwxr-xr-xmono_dejavu_sans_120.png73938logplain
-rwxr-xr-xmono_dejavu_sans_14.xml269188logplain
-rwxr-xr-xmono_dejavu_sans_140.png89073logplain
-rwxr-xr-xmono_dejavu_sans_16.xml275642logplain
-rwxr-xr-xmono_dejavu_sans_160.png101939logplain
-rwxr-xr-xmono_dejavu_sans_18.xml279962logplain
-rwxr-xr-xmono_dejavu_sans_180.png122274logplain
-rwxr-xr-xmono_dejavu_sans_20.xml282588logplain
-rwxr-xr-xmono_dejavu_sans_200.png138662logplain
-rwxr-xr-xmono_dejavu_sans_22.xml283950logplain
-rwxr-xr-xmono_dejavu_sans_220.png152844logplain
-rwxr-xr-xmono_dejavu_sans_24.xml286626logplain
-rwxr-xr-xmono_dejavu_sans_240.png170247logplain
-rwxr-xr-xmono_dejavu_sans_26.xml289710logplain
-rwxr-xr-xmono_dejavu_sans_260.png190156logplain
-rwxr-xr-xmono_dejavu_sans_28.xml292596logplain
-rwxr-xr-xmono_dejavu_sans_280.png200848logplain
-rwxr-xr-xmono_dejavu_sans_4.xml237740logplain
-rwxr-xr-xmono_dejavu_sans_40.png15668logplain
-rwxr-xr-xmono_dejavu_sans_6.xml245472logplain
-rwxr-xr-xmono_dejavu_sans_60.png29291logplain
-rwxr-xr-xmono_dejavu_sans_8.xml251876logplain
-rwxr-xr-xmono_dejavu_sans_80.png45552logplain
-rwxr-xr-xmono_dejavu_sans_9.xml254016logplain
-rwxr-xr-xmono_dejavu_sans_90.png50995logplain
lude <algorithm> static Settings main_settings; Settings *g_settings = &main_settings; std::string g_settings_path; Settings::~Settings() { clear(); } Settings & Settings::operator += (const Settings &other) { update(other); return *this; } Settings & Settings::operator = (const Settings &other) { if (&other == this) return *this; MutexAutoLock lock(m_mutex); MutexAutoLock lock2(other.m_mutex); clearNoLock(); updateNoLock(other); return *this; } bool Settings::checkNameValid(const std::string &name) { bool valid = name.find_first_of("=\"{}#") == std::string::npos; if (valid) valid = trim(name) == name; if (!valid) { errorstream << "Invalid setting name \"" << name << "\"" << std::endl; return false; } return true; } bool Settings::checkValueValid(const std::string &value) { if (value.substr(0, 3) == "\"\"\"" || value.find("\n\"\"\"") != std::string::npos) { errorstream << "Invalid character sequence '\"\"\"' found in" " setting value!" << std::endl; return false; } return true; } std::string Settings::sanitizeName(const std::string &name) { std::string n = trim(name); for (const char *s = "=\"{}#"; *s; s++) n.erase(std::remove(n.begin(), n.end(), *s), n.end()); return n; } std::string Settings::sanitizeValue(const std::string &value) { std::string v(value); size_t p = 0; if (v.substr(0, 3) == "\"\"\"") v.erase(0, 3); while ((p = v.find("\n\"\"\"")) != std::string::npos) v.erase(p, 4); return v; } std::string Settings::getMultiline(std::istream &is, size_t *num_lines) { size_t lines = 1; std::string value; std::string line; while (is.good()) { lines++; std::getline(is, line); if (line == "\"\"\"") break; value += line; value.push_back('\n'); } size_t len = value.size(); if (len) value.erase(len - 1); if (num_lines) *num_lines = lines; return value; } bool Settings::readConfigFile(const char *filename) { std::ifstream is(filename); if (!is.good()) return false; return parseConfigLines(is, ""); } bool Settings::parseConfigLines(std::istream &is, const std::string &end) { MutexAutoLock lock(m_mutex); std::string line, name, value; while (is.good()) { std::getline(is, line); SettingsParseEvent event = parseConfigObject(line, end, name, value); switch (event) { case SPE_NONE: case SPE_INVALID: case SPE_COMMENT: break; case SPE_KVPAIR: m_settings[name] = SettingsEntry(value); break; case SPE_END: return true; case SPE_GROUP: { Settings *group = new Settings; if (!group->parseConfigLines(is, "}")) { delete group; return false; } m_settings[name] = SettingsEntry(group); break; } case SPE_MULTILINE: m_settings[name] = SettingsEntry(getMultiline(is)); break; } } return end.empty(); } void Settings::writeLines(std::ostream &os, u32 tab_depth) const { MutexAutoLock lock(m_mutex); for (std::map<std::string, SettingsEntry>::const_iterator it = m_settings.begin(); it != m_settings.end(); ++it) printEntry(os, it->first, it->second, tab_depth); } void Settings::printEntry(std::ostream &os, const std::string &name, const SettingsEntry &entry, u32 tab_depth) { for (u32 i = 0; i != tab_depth; i++) os << "\t"; if (entry.is_group) { os << name << " = {\n"; entry.group->writeLines(os, tab_depth + 1); for (u32 i = 0; i != tab_depth; i++) os << "\t"; os << "}\n"; } else { os << name << " = "; if (entry.value.find('\n') != std::string::npos) os << "\"\"\"\n" << entry.value << "\n\"\"\"\n"; else os << entry.value << "\n"; } } bool Settings::updateConfigObject(std::istream &is, std::ostream &os, const std::string &end, u32 tab_depth) { std::map<std::string, SettingsEntry>::const_iterator it; std::set<std::string> present_entries; std::string line, name, value; bool was_modified = false; bool end_found = false; // Add any settings that exist in the config file with the current value // in the object if existing while (is.good() && !end_found) { std::getline(is, line); SettingsParseEvent event = parseConfigObject(line, end, name, value); switch (event) { case SPE_END: os << line << (is.eof() ? "" : "\n"); end_found = true; break; case SPE_MULTILINE: value = getMultiline(is); /* FALLTHROUGH */ case SPE_KVPAIR: it = m_settings.find(name); if (it != m_settings.end() && (it->second.is_group || it->second.value != value)) { printEntry(os, name, it->second, tab_depth); was_modified = true; } else { os << line << "\n"; if (event == SPE_MULTILINE) os << value << "\n\"\"\"\n"; } present_entries.insert(name); break; case SPE_GROUP: it = m_settings.find(name); if (it != m_settings.end() && it->second.is_group) { os << line << "\n"; sanity_check(it->second.group != NULL); was_modified |= it->second.group->updateConfigObject(is, os, "}", tab_depth + 1); } else { printEntry(os, name, it->second, tab_depth); was_modified = true; } present_entries.insert(name); break; default: os << line << (is.eof() ? "" : "\n"); break; } } // Add any settings in the object that don't exist in the config file yet for (it = m_settings.begin(); it != m_settings.end(); ++it) { if (present_entries.find(it->first) != present_entries.end()) continue; printEntry(os, it->first, it->second, tab_depth); was_modified = true; } return was_modified; } bool Settings::updateConfigFile(const char *filename) { MutexAutoLock lock(m_mutex); std::ifstream is(filename); std::ostringstream os(std::ios_base::binary); bool was_modified = updateConfigObject(is, os, ""); is.close(); if (!was_modified) return true; if (!fs::safeWriteToFile(filename, os.str())) { errorstream << "Error writing configuration file: \"" << filename << "\"" << std::endl; return false; } return true; } bool Settings::parseCommandLine(int argc, char *argv[], std::map<std::string, ValueSpec> &allowed_options) { int nonopt_index = 0; for (int i = 1; i < argc; i++) { std::string arg_name = argv[i]; if (arg_name.substr(0, 2) != "--") { // If option doesn't start with -, read it in as nonoptX if (arg_name[0] != '-'){ std::string name = "nonopt"; name += itos(nonopt_index); set(name, arg_name); nonopt_index++; continue; } errorstream << "Invalid command-line parameter \"" << arg_name << "\": --<option> expected." << std::endl; return false; } std::string name = arg_name.substr(2); std::map<std::string, ValueSpec>::iterator n; n = allowed_options.find(name); if (n == allowed_options.end()) { errorstream << "Unknown command-line parameter \"" << arg_name << "\"" << std::endl; return false; } ValueType type = n->second.type; std::string value = ""; if (type == VALUETYPE_FLAG) { value = "true"; } else { if ((i + 1) >= argc) { errorstream << "Invalid command-line parameter \"" << name << "\": missing value" << std::endl; return false; } value = argv[++i]; } set(name, value); } return true; } /*********** * Getters * ***********/ const SettingsEntry &Settings::getEntry(const std::string &name) const { MutexAutoLock lock(m_mutex); std::map<std::string, SettingsEntry>::const_iterator n; if ((n = m_settings.find(name)) == m_settings.end()) { if ((n = m_defaults.find(name)) == m_defaults.end()) throw SettingNotFoundException("Setting [" + name + "] not found."); } return n->second; } Settings *Settings::getGroup(const std::string &name) const { const SettingsEntry &entry = getEntry(name); if (!entry.is_group) throw SettingNotFoundException("Setting [" + name + "] is not a group."); return entry.group; } std::string Settings::get(const std::string &name) const { const SettingsEntry &entry = getEntry(name); if (entry.is_group) throw SettingNotFoundException("Setting [" + name + "] is a group."); return entry.value; } bool Settings::getBool(const std::string &name) const { return is_yes(get(name)); } u16 Settings::getU16(const std::string &name) const { return stoi(get(name), 0, 65535); } s16 Settings::getS16(const std::string &name) const { return stoi(get(name), -32768, 32767); } s32 Settings::getS32(const std::string &name) const { return stoi(get(name)); } float Settings::getFloat(const std::string &name) const { return stof(get(name)); } u64 Settings::getU64(const std::string &name) const { u64 value = 0; std::string s = get(name); std::istringstream ss(s); ss >> value; return value; } v2f Settings::getV2F(const std::string &name) const { v2f value; Strfnd f(get(name)); f.next("("); value.X = stof(f.next(",")); value.Y = stof(f.next(")")); return value; } v3f Settings::getV3F(const std::string &name) const { v3f value; Strfnd f(get(name)); f.next("("); value.X = stof(f.next(",")); value.Y = stof(f.next(",")); value.Z = stof(f.next(")")); return value; } u32 Settings::getFlagStr(const std::string &name, const FlagDesc *flagdesc, u32 *flagmask) const { std::string val = get(name); return std::isdigit(val[0]) ? stoi(val) : readFlagString(val, flagdesc, flagmask); } // N.B. if getStruct() is used to read a non-POD aggregate type, // the behavior is undefined. bool Settings::getStruct(const std::string &name, const std::string &format, void *out, size_t olen) const { std::string valstr; try { valstr = get(name); } catch (SettingNotFoundException &e) { return false; } if (!deSerializeStringToStruct(valstr, format, out, olen)) return false; return true; } bool Settings::getNoiseParams(const std::string &name, NoiseParams &np) const { return getNoiseParamsFromGroup(name, np) || getNoiseParamsFromValue(name, np); } bool Settings::getNoiseParamsFromValue(const std::string &name, NoiseParams &np) const { std::string value; if (!getNoEx(name, value)) return false; Strfnd f(value); np.offset = stof(f.next(",")); np.scale = stof(f.next(",")); f.next("("); np.spread.X = stof(f.next(",")); np.spread.Y = stof(f.next(",")); np.spread.Z = stof(f.next(")")); f.next(","); np.seed = stoi(f.next(",")); np.octaves = stoi(f.next(",")); np.persist = stof(f.next(",")); std::string optional_params = f.next(""); if (optional_params != "") np.lacunarity = stof(optional_params); return true; } bool Settings::getNoiseParamsFromGroup(const std::string &name, NoiseParams &np) const { Settings *group = NULL; if (!getGroupNoEx(name, group)) return false; group->getFloatNoEx("offset", np.offset); group->getFloatNoEx("scale", np.scale); group->getV3FNoEx("spread", np.spread); group->getS32NoEx("seed", np.seed); group->getU16NoEx("octaves", np.octaves); group->getFloatNoEx("persistence", np.persist); group->getFloatNoEx("lacunarity", np.lacunarity); np.flags = 0; if (!group->getFlagStrNoEx("flags", np.flags, flagdesc_noiseparams)) np.flags = NOISE_FLAG_DEFAULTS; return true; } bool Settings::exists(const std::string &name) const { MutexAutoLock lock(m_mutex); return (m_settings.find(name) != m_settings.end() || m_defaults.find(name) != m_defaults.end()); } std::vector<std::string> Settings::getNames() const { std::vector<std::string> names; for (std::map<std::string, SettingsEntry>::const_iterator i = m_settings.begin(); i != m_settings.end(); ++i) { names.push_back(i->first); } return names; } /*************************************** * Getters that don't throw exceptions * ***************************************/ bool Settings::getEntryNoEx(const std::string &name, SettingsEntry &val) const { try { val = getEntry(name); return true; } catch (SettingNotFoundException &e) { return false; } } bool Settings::getGroupNoEx(const std::string &name, Settings *&val) const { try { val = getGroup(name); return true; } catch (SettingNotFoundException &e) { return false; } } bool Settings::getNoEx(const std::string &name, std::string &val) const { try { val = get(name); return true; } catch (SettingNotFoundException &e) { return false; } } bool Settings::getFlag(const std::string &name) const { try { return getBool(name); } catch(SettingNotFoundException &e) { return false; } } bool Settings::getFloatNoEx(const std::string &name, float &val) const { try { val = getFloat(name); return true; } catch (SettingNotFoundException &e) { return false; } } bool Settings::getU16NoEx(const std::string &name, u16 &val) const { try { val = getU16(name); return true; } catch (SettingNotFoundException &e) { return false; } } bool Settings::getS16NoEx(const std::string &name, s16 &val) const { try { val = getS16(name); return true; } catch (SettingNotFoundException &e) { return false; } } bool Settings::getS32NoEx(const std::string &name, s32 &val) const { try { val = getS32(name); return true; } catch (SettingNotFoundException &e) { return false; } } bool Settings::getU64NoEx(const std::string &name, u64 &val) const { try { val = getU64(name); return true; } catch (SettingNotFoundException &e) { return false; } } bool Settings::getV2FNoEx(const std::string &name, v2f &val) const { try { val = getV2F(name); return true; } catch (SettingNotFoundException &e) { return false; } } bool Settings::getV3FNoEx(const std::string &name, v3f &val) const { try { val = getV3F(name); return true; } catch (SettingNotFoundException &e) { return false; } } // N.B. getFlagStrNoEx() does not set val, but merely modifies it. Thus, // val must be initialized before using getFlagStrNoEx(). The intention of // this is to simplify modifying a flags field from a default value. bool Settings::getFlagStrNoEx(const std::string &name, u32 &val, FlagDesc *flagdesc) const { try { u32 flags, flagmask; flags = getFlagStr(name, flagdesc, &flagmask); val &= ~flagmask; val |= flags; return true; } catch (SettingNotFoundException &e) { return false; } } /*********** * Setters * ***********/ bool Settings::setEntry(const std::string &name, const void *data, bool set_group, bool set_default) { Settings *old_group = NULL; if (!checkNameValid(name)) return false; if (!set_group && !checkValueValid(*(const std::string *)data)) return false; { MutexAutoLock lock(m_mutex); SettingsEntry &entry = set_default ? m_defaults[name] : m_settings[name]; old_group = entry.group; entry.value = set_group ? "" : *(const std::string *)data; entry.group = set_group ? *(Settings **)data : NULL; entry.is_group = set_group; } delete old_group; return true; } bool Settings::set(const std::string &name, const std::string &value) { if (!setEntry(name, &value, false, false)) return false; doCallbacks(name); return true; } bool Settings::setDefault(const std::string &name, const std::string &value) { return setEntry(name, &value, false, true); } bool Settings::setGroup(const std::string &name, Settings *group) { return setEntry(name, &group, true, false); } bool Settings::setGroupDefault(const std::string &name, Settings *group) { return setEntry(name, &group, true, true); } bool Settings::setBool(const std::string &name, bool value) { return set(name, value ? "true" : "false"); } bool Settings::setS16(const std::string &name, s16 value) { return set(name, itos(value)); } bool Settings::setU16(const std::string &name, u16 value) { return set(name, itos(value)); } bool Settings::setS32(const std::string &name, s32 value) { return set(name, itos(value)); } bool Settings::setU64(const std::string &name, u64 value) { std::ostringstream os; os << value; return set(name, os.str()); } bool Settings::setFloat(const std::string &name, float value) { return set(name, ftos(value)); } bool Settings::setV2F(const std::string &name, v2f value) { std::ostringstream os; os << "(" << value.X << "," << value.Y << ")"; return set(name, os.str()); } bool Settings::setV3F(const std::string &name, v3f value) { std::ostringstream os; os << "(" << value.X << "," << value.Y << "," << value.Z << ")"; return set(name, os.str()); } bool Settings::setFlagStr(const std::string &name, u32 flags, const FlagDesc *flagdesc, u32 flagmask) { return set(name, writeFlagString(flags, flagdesc, flagmask)); } bool Settings::setStruct(const std::string &name, const std::string &format, void *value) { std::string structstr; if (!serializeStructToString(&structstr, format, value)) return false; return set(name, structstr); } bool Settings::setNoiseParams(const std::string &name, const NoiseParams &np, bool set_default) { Settings *group = new Settings; group->setFloat("offset", np.offset); group->setFloat("scale", np.scale);