1
0
Fork 0

Compare commits

...

4 Commits

Author SHA1 Message Date
Peter Nelson d3d10fb0bc
Merge d5e0fa7a73 into 7c8759552a 2025-07-28 04:50:33 +00:00
translators 7c8759552a Update: Translations from eints
japanese: 40 changes by akaregi
hungarian: 6 changes by nemesbala
2025-07-28 04:48:20 +00:00
Peter Nelson d5e0fa7a73
Codechange: Move fallback font detection to FontCacheFactory.
Provides a standard interface instead of relying on defines.
2025-07-20 23:04:05 +01:00
Peter Nelson b32f46f36e
Codechange: Use ProviderManager interface to register FontCache factories.
This removes use of #ifdefs to select the appropriate loader, and also replaces FontCache self-registration.
2025-07-20 23:04:05 +01:00
20 changed files with 625 additions and 520 deletions

View File

@ -187,7 +187,6 @@ add_files(
fios_gui.cpp
fontcache.cpp
fontcache.h
fontdetection.h
framerate_gui.cpp
framerate_type.h
gamelog.cpp

View File

@ -2369,7 +2369,7 @@ static bool ConFont(std::span<std::string_view> argv)
FontCacheSubSetting *setting = GetFontCacheSubSetting(fs);
/* Make sure all non sprite fonts are loaded. */
if (!setting->font.empty() && !fc->HasParent()) {
InitFontCache(fs);
FontCache::LoadFontCaches(fs);
fc = FontCache::Get(fs);
}
IConsolePrint(CC_DEFAULT, "{} font:", FontSizeToName(fs));

View File

@ -9,10 +9,8 @@
#include "stdafx.h"
#include "fontcache.h"
#include "fontdetection.h"
#include "blitter/factory.hpp"
#include "gfx_layout.h"
#include "fontcache/spritefontcache.h"
#include "openttd.h"
#include "settings_func.h"
#include "strings_func.h"
@ -30,22 +28,38 @@
FontCacheSettings _fcsettings;
/**
* Create a new font cache.
* @param fs The size of the font.
* Try loading a font with any fontcache factory.
* @param fs Font size to load.
* @param fonttype Font type requested.
* @return FontCache of the font if loaded, or nullptr.
*/
FontCache::FontCache(FontSize fs) : parent(FontCache::Get(fs)), fs(fs)
/* static */ std::unique_ptr<FontCache> FontProviderManager::LoadFont(FontSize fs, FontType fonttype)
{
assert(this->parent == nullptr || this->fs == this->parent->fs);
FontCache::caches[this->fs] = this;
Layouter::ResetFontCache(this->fs);
for (auto &provider : FontProviderManager::GetProviders()) {
auto fc = provider->LoadFont(fs, fonttype);
if (fc != nullptr) return fc;
}
/** Clean everything up. */
FontCache::~FontCache()
return nullptr;
}
/**
* We would like to have a fallback font as the current one
* doesn't contain all characters we need.
* This function must set all fonts of settings.
* @param settings the settings to overwrite the fontname of.
* @param language_isocode the language, e.g. en_GB.
* @param callback The function to call to check for missing glyphs.
* @return true if a font has been set, false otherwise.
*/
/* static */ bool FontProviderManager::FindFallbackFont(FontCacheSettings *settings, const std::string &language_isocode, MissingGlyphSearcher *callback)
{
assert(this->parent == nullptr || this->fs == this->parent->fs);
FontCache::caches[this->fs] = this->parent;
Layouter::ResetFontCache(this->fs);
for (auto &provider : FontProviderManager::GetProviders()) {
if (provider->FindFallbackFont(settings, language_isocode, callback)) {
return true;
}
}
return false;
}
int FontCache::GetDefaultFontHeight(FontSize fs)
@ -80,12 +94,16 @@ int GetCharacterHeight(FontSize size)
}
/* static */ FontCache *FontCache::caches[FS_END];
/* static */ std::array<std::unique_ptr<FontCache>, FS_END> FontCache::caches{};
/**
* Initialise font caches with the base sprite font cache for all sizes.
*/
/* static */ void FontCache::InitializeFontCaches()
{
for (FontSize fs = FS_BEGIN; fs != FS_END; fs++) {
if (FontCache::caches[fs] == nullptr) new SpriteFontCache(fs); /* FontCache inserts itself into to the cache. */
if (FontCache::Get(fs) != nullptr) continue;
FontCache::Register(FontProviderManager::LoadFont(fs, FontType::Sprite));
}
}
@ -126,7 +144,7 @@ void SetFont(FontSize fontsize, const std::string &font, uint size)
CheckForMissingGlyphs();
_fcsettings = std::move(backup);
} else {
InitFontCache(fontsize);
FontCache::LoadFontCaches(fontsize);
}
LoadStringWidthTable(fontsize);
@ -136,15 +154,6 @@ void SetFont(FontSize fontsize, const std::string &font, uint size)
if (_save_config) SaveToConfig();
}
#ifdef WITH_FREETYPE
extern void LoadFreeTypeFont(FontSize fs);
extern void UninitFreeType();
#elif defined(_WIN32)
extern void LoadWin32Font(FontSize fs);
#elif defined(WITH_COCOA)
extern void LoadCoreTextFont(FontSize fs);
#endif
/**
* Test if a font setting uses the default font.
* @return true iff the font is not configured and no fallback font data is present.
@ -211,43 +220,55 @@ std::string GetFontCacheFontName(FontSize fs)
return GetDefaultTruetypeFontFile(fs);
}
/**
* Register a FontCache for its font size.
* @param fc FontCache to register.
*/
/* static */ void FontCache::Register(std::unique_ptr<FontCache> &&fc)
{
if (fc == nullptr) return;
FontSize fs = fc->fs;
fc->parent = std::move(FontCache::caches[fs]);
FontCache::caches[fs] = std::move(fc);
}
/**
* (Re)initialize the font cache related things, i.e. load the non-sprite fonts.
* @param fontsizes Font sizes to be initialised.
*/
void InitFontCache(FontSizes fontsizes)
/* static */ void FontCache::LoadFontCaches(FontSizes fontsizes)
{
FontCache::InitializeFontCaches();
for (FontSize fs : fontsizes) {
FontCache *fc = FontCache::Get(fs);
if (fc->HasParent()) delete fc;
Layouter::ResetFontCache(fs);
#ifdef WITH_FREETYPE
LoadFreeTypeFont(fs);
#elif defined(_WIN32)
LoadWin32Font(fs);
#elif defined(WITH_COCOA)
LoadCoreTextFont(fs);
#endif
/* Unload everything except the sprite font cache. */
while (FontCache::Get(fs)->HasParent()) {
FontCache::caches[fs] = std::move(FontCache::caches[fs]->parent);
}
FontCache::Register(FontProviderManager::LoadFont(fs, FontType::TrueType));
}
}
/**
* Clear cached information for the specified font caches.
* @param fontsizes Font sizes to clear.
*/
/* static */ void FontCache::ClearFontCaches(FontSizes fontsizes)
{
for (FontSize fs : fontsizes) {
FontCache::Get(fs)->ClearFontCache();
}
}
/**
* Free everything allocated w.r.t. fonts.
*/
void UninitFontCache()
/* static */ void FontCache::UninitializeFontCaches()
{
for (FontSize fs = FS_BEGIN; fs < FS_END; fs++) {
while (FontCache::Get(fs) != nullptr) delete FontCache::Get(fs);
std::ranges::generate(FontCache::caches, []() { return nullptr; });
}
#ifdef WITH_FREETYPE
UninitFreeType();
#endif /* WITH_FREETYPE */
}
#if !defined(_WIN32) && !defined(__APPLE__) && !defined(WITH_FONTCONFIG) && !defined(WITH_COCOA)
bool SetFallbackFont(FontCacheSettings *, const std::string &, MissingGlyphSearcher *) { return false; }
#endif /* !defined(_WIN32) && !defined(__APPLE__) && !defined(WITH_FONTCONFIG) && !defined(WITH_COCOA) */

View File

@ -10,6 +10,7 @@
#ifndef FONTCACHE_H
#define FONTCACHE_H
#include "provider_manager.h"
#include "string_type.h"
#include "spritecache.h"
@ -20,18 +21,23 @@ static const GlyphID SPRITE_GLYPH = 1U << 30;
/** Font cache for basic fonts. */
class FontCache {
protected:
static FontCache *caches[FS_END]; ///< All the font caches.
FontCache *parent; ///< The parent of this font cache.
static std::array<std::unique_ptr<FontCache>, FS_END> caches; ///< All the font caches.
std::unique_ptr<FontCache>parent; ///< The parent of this font cache.
const FontSize fs; ///< The size of the font.
int height = 0; ///< The height of the font.
int ascender = 0; ///< The ascender value of the font.
int descender = 0; ///< The descender value of the font.
FontCache(FontSize fs) : fs(fs) {}
static void Register(std::unique_ptr<FontCache> &&fc);
public:
FontCache(FontSize fs);
virtual ~FontCache();
virtual ~FontCache() {}
static void InitializeFontCaches();
static void UninitializeFontCaches();
static void LoadFontCaches(FontSizes fontsizes);
static void ClearFontCaches(FontSizes fontsizes);
/** Default unscaled font heights. */
static const int DEFAULT_FONT_HEIGHT[FS_END];
@ -124,7 +130,7 @@ public:
static inline FontCache *Get(FontSize fs)
{
assert(fs < FS_END);
return FontCache::caches[fs];
return FontCache::caches[fs].get();
}
static std::string GetName(FontSize fs);
@ -143,13 +149,6 @@ public:
virtual bool IsBuiltInFont() = 0;
};
inline void ClearFontCache(FontSizes fontsizes)
{
for (FontSize fs : fontsizes) {
FontCache::Get(fs)->ClearFontCache();
}
}
/** Get the Sprite for a glyph */
inline const Sprite *GetGlyph(FontSize size, char32_t key)
{
@ -207,12 +206,39 @@ inline FontCacheSubSetting *GetFontCacheSubSetting(FontSize fs)
uint GetFontCacheFontSize(FontSize fs);
std::string GetFontCacheFontName(FontSize fs);
void InitFontCache(FontSizes fontsizes);
void UninitFontCache();
bool GetFontAAState();
void SetFont(FontSize fontsize, const std::string &font, uint size);
/** Different types of font that can be loaded. */
enum class FontType : uint8_t {
Sprite, ///< Bitmap sprites from GRF files.
TrueType, ///< Scalable TrueType fonts.
};
/** Factory for FontCaches. */
class FontCacheFactory : public BaseProvider<FontCacheFactory> {
public:
FontCacheFactory(std::string_view name, std::string_view description) : BaseProvider<FontCacheFactory>(name, description)
{
ProviderManager<FontCacheFactory>::Register(*this);
}
virtual ~FontCacheFactory()
{
ProviderManager<FontCacheFactory>::Unregister(*this);
}
virtual std::unique_ptr<FontCache> LoadFont(FontSize fs, FontType fonttype) = 0;
virtual bool FindFallbackFont(struct FontCacheSettings *settings, const std::string &language_isocode, class MissingGlyphSearcher *callback) = 0;
};
class FontProviderManager : ProviderManager<FontCacheFactory> {
public:
static std::unique_ptr<FontCache> LoadFont(FontSize fs, FontType fonttype);
static bool FindFallbackFont(FontCacheSettings *settings, const std::string &language_isocode, MissingGlyphSearcher *callback);
};
/* Implemented in spritefontcache.cpp */
void InitializeUnicodeGlyphMap();
void SetUnicodeGlyph(FontSize size, char32_t key, SpriteID sprite);

View File

@ -8,14 +8,14 @@
/** @file freetypefontcache.cpp FreeType font cache implementation. */
#include "../stdafx.h"
#include "../debug.h"
#include "../fontcache.h"
#include "../fontdetection.h"
#include "../blitter/factory.hpp"
#include "../core/math_func.hpp"
#include "../zoom_func.h"
#include "../fileio_func.h"
#include "../error_func.h"
#include "../../os/unix/font_unix.h"
#include "truetypefontcache.h"
#include "../table/control_codes.h"
@ -46,9 +46,6 @@ public:
const void *GetOSHandle() override { return &face; }
};
FT_Library _ft_library = nullptr;
/**
* Create a new FreeTypeFontCache.
* @param fs The font size that is going to be cached.
@ -113,93 +110,6 @@ void FreeTypeFontCache::SetFontSize(int pixels)
}
}
static FT_Error LoadFont(FontSize fs, FT_Face face, std::string_view font_name, uint size)
{
Debug(fontcache, 2, "Requested '{}', using '{} {}'", font_name, face->family_name, face->style_name);
/* Attempt to select the unicode character map */
FT_Error error = FT_Select_Charmap(face, ft_encoding_unicode);
if (error == FT_Err_Ok) goto found_face; // Success
if (error == FT_Err_Invalid_CharMap_Handle) {
/* Try to pick a different character map instead. We default to
* the first map, but platform_id 0 encoding_id 0 should also
* be unicode (strange system...) */
FT_CharMap found = face->charmaps[0];
int i;
for (i = 0; i < face->num_charmaps; i++) {
FT_CharMap charmap = face->charmaps[i];
if (charmap->platform_id == 0 && charmap->encoding_id == 0) {
found = charmap;
}
}
if (found != nullptr) {
error = FT_Set_Charmap(face, found);
if (error == FT_Err_Ok) goto found_face;
}
}
FT_Done_Face(face);
return error;
found_face:
new FreeTypeFontCache(fs, face, size);
return FT_Err_Ok;
}
/**
* Loads the freetype font.
* First type to load the fontname as if it were a path. If that fails,
* try to resolve the filename of the font using fontconfig, where the
* format is 'font family name' or 'font family name, font style'.
* @param fs The font size to load.
*/
void LoadFreeTypeFont(FontSize fs)
{
FontCacheSubSetting *settings = GetFontCacheSubSetting(fs);
std::string font = GetFontCacheFontName(fs);
if (font.empty()) return;
if (_ft_library == nullptr) {
if (FT_Init_FreeType(&_ft_library) != FT_Err_Ok) {
ShowInfo("Unable to initialize FreeType, using sprite fonts instead");
return;
}
Debug(fontcache, 2, "Initialized");
}
FT_Face face = nullptr;
/* If font is an absolute path to a ttf, try loading that first. */
int32_t index = 0;
if (settings->os_handle != nullptr) index = *static_cast<const int32_t *>(settings->os_handle);
FT_Error error = FT_New_Face(_ft_library, font.c_str(), index, &face);
if (error != FT_Err_Ok) {
/* Check if font is a relative filename in one of our search-paths. */
std::string full_font = FioFindFullPath(BASE_DIR, font);
if (!full_font.empty()) {
error = FT_New_Face(_ft_library, full_font.c_str(), 0, &face);
}
}
/* Try loading based on font face name (OS-wide fonts). */
if (error != FT_Err_Ok) error = GetFontByFaceName(font, &face);
if (error == FT_Err_Ok) {
error = LoadFont(fs, face, font, GetFontCacheFontSize(fs));
if (error != FT_Err_Ok) {
ShowInfo("Unable to use '{}' for {} font, FreeType reported error 0x{:X}, using sprite font instead", font, FontSizeToName(fs), error);
}
} else {
FT_Done_Face(face);
}
}
/**
* Free everything that was allocated for this font cache.
*/
@ -296,19 +206,116 @@ GlyphID FreeTypeFontCache::MapCharToGlyph(char32_t key, bool allow_fallback)
return glyph;
}
/**
* Free everything allocated w.r.t. freetype.
*/
void UninitFreeType()
FT_Library _ft_library = nullptr;
class FreeTypeFontCacheFactory : public FontCacheFactory {
public:
FreeTypeFontCacheFactory() : FontCacheFactory("freetype", "FreeType font provider") {}
virtual ~FreeTypeFontCacheFactory()
{
FT_Done_FreeType(_ft_library);
_ft_library = nullptr;
}
#if !defined(WITH_FONTCONFIG)
/**
* Loads the freetype font.
* First type to load the fontname as if it were a path. If that fails,
* try to resolve the filename of the font using fontconfig, where the
* format is 'font family name' or 'font family name, font style'.
* @param fs The font size to load.
*/
std::unique_ptr<FontCache> LoadFont(FontSize fs, FontType fonttype) override
{
if (fonttype != FontType::TrueType) return nullptr;
FT_Error GetFontByFaceName(std::string_view font_name, FT_Face *face) { return FT_Err_Cannot_Open_Resource; }
FontCacheSubSetting *settings = GetFontCacheSubSetting(fs);
#endif /* !defined(WITH_FONTCONFIG) */
std::string font = GetFontCacheFontName(fs);
if (font.empty()) return nullptr;
if (_ft_library == nullptr) {
if (FT_Init_FreeType(&_ft_library) != FT_Err_Ok) {
ShowInfo("Unable to initialize FreeType, using sprite fonts instead");
return nullptr;
}
Debug(fontcache, 2, "Initialized");
}
FT_Face face = nullptr;
/* If font is an absolute path to a ttf, try loading that first. */
int32_t index = 0;
if (settings->os_handle != nullptr) index = *static_cast<const int32_t *>(settings->os_handle);
FT_Error error = FT_New_Face(_ft_library, font.c_str(), index, &face);
if (error != FT_Err_Ok) {
/* Check if font is a relative filename in one of our search-paths. */
std::string full_font = FioFindFullPath(BASE_DIR, font);
if (!full_font.empty()) {
error = FT_New_Face(_ft_library, full_font.c_str(), 0, &face);
}
}
#ifdef WITH_FONTCONFIG
/* Try loading based on font face name (OS-wide fonts). */
if (error != FT_Err_Ok) error = GetFontByFaceName(font, &face);
#endif /* WITH_FONTCONFIG */
if (error != FT_Err_Ok) {
FT_Done_Face(face);
return nullptr;
}
return LoadFont(fs, face, font, GetFontCacheFontSize(fs));
}
bool FindFallbackFont(struct FontCacheSettings *settings, const std::string &language_isocode, class MissingGlyphSearcher *callback) override
{
#ifdef WITH_FONTCONFIG
if (FontConfigFindFallbackFont(settings, language_isocode, callback)) return true;
#endif /* WITH_FONTCONFIG */
return false;
}
private:
static std::unique_ptr<FontCache> LoadFont(FontSize fs, FT_Face face, std::string_view font_name, uint size)
{
Debug(fontcache, 2, "Requested '{}', using '{} {}'", font_name, face->family_name, face->style_name);
/* Attempt to select the unicode character map */
FT_Error error = FT_Select_Charmap(face, ft_encoding_unicode);
if (error == FT_Err_Invalid_CharMap_Handle) {
/* Try to pick a different character map instead. We default to
* the first map, but platform_id 0 encoding_id 0 should also
* be unicode (strange system...) */
FT_CharMap found = face->charmaps[0];
for (int i = 0; i < face->num_charmaps; ++i) {
FT_CharMap charmap = face->charmaps[i];
if (charmap->platform_id == 0 && charmap->encoding_id == 0) {
found = charmap;
}
}
if (found != nullptr) {
error = FT_Set_Charmap(face, found);
}
}
if (error != FT_Err_Ok) {
FT_Done_Face(face);
ShowInfo("Unable to use '{}' for {} font, FreeType reported error 0x{:X}, using sprite font instead", font_name, FontSizeToName(fs), error);
return nullptr;
}
return std::make_unique<FreeTypeFontCache>(fs, face, size);
}
};
static FreeTypeFontCacheFactory s_freetype_fontcache_factory;
#endif /* WITH_FREETYPE */

View File

@ -151,3 +151,22 @@ bool SpriteFontCache::GetDrawGlyphShadow()
{
return false;
}
class SpriteFontCacheFactory : public FontCacheFactory {
public:
SpriteFontCacheFactory() : FontCacheFactory("sprite", "Sprite font provider") {}
std::unique_ptr<FontCache> LoadFont(FontSize fs, FontType fonttype) override
{
if (fonttype != FontType::Sprite) return nullptr;
return std::make_unique<SpriteFontCache>(fs);
}
bool FindFallbackFont(struct FontCacheSettings *, const std::string &, class MissingGlyphSearcher *) override
{
return false;
}
};
static SpriteFontCacheFactory s_sprite_fontcache_factory;

View File

@ -1,41 +0,0 @@
/*
* This file is part of OpenTTD.
* OpenTTD 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, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file fontdetection.h Functions related to detecting/finding the right font. */
#ifndef FONTDETECTION_H
#define FONTDETECTION_H
#include "fontcache.h"
#ifdef WITH_FREETYPE
#include <ft2build.h>
#include FT_FREETYPE_H
/**
* Load a freetype font face with the given font name.
* @param font_name The name of the font to load.
* @param face The face that has been found.
* @return The error we encountered.
*/
FT_Error GetFontByFaceName(std::string_view font_name, FT_Face *face);
#endif /* WITH_FREETYPE */
/**
* We would like to have a fallback font as the current one
* doesn't contain all characters we need.
* This function must set all fonts of settings.
* @param settings the settings to overwrite the fontname of.
* @param language_isocode the language, e.g. en_GB.
* @param callback The function to call to check for missing glyphs.
* @return true if a font has been set, false otherwise.
*/
bool SetFallbackFont(struct FontCacheSettings *settings, const std::string &language_isocode, class MissingGlyphSearcher *callback);
#endif

View File

@ -1253,7 +1253,7 @@ static void GfxMainBlitter(const Sprite *sprite, int x, int y, BlitterMode mode,
*/
void LoadStringWidthTable(FontSizes fontsizes)
{
ClearFontCache(fontsizes);
FontCache::ClearFontCaches(fontsizes);
for (FontSize fs : fontsizes) {
for (uint i = 0; i != 224; i++) {
@ -1820,7 +1820,7 @@ bool AdjustGUIZoom(bool automatic)
if (old_font_zoom != _font_zoom) {
GfxClearFontSpriteCache();
}
ClearFontCache(FONTSIZES_ALL);
FontCache::ClearFontCaches(FONTSIZES_ALL);
LoadStringWidthTable();
SetupWidgetDimensions();

View File

@ -245,7 +245,7 @@ static void RealChangeBlitter(std::string_view repl_blitter)
/* Clear caches that might have sprites for another blitter. */
VideoDriver::GetInstance()->ClearSystemSprites();
ClearFontCache(FONTSIZES_ALL);
FontCache::ClearFontCaches(FONTSIZES_ALL);
GfxClearSpriteCache();
ReInitAllWindows(false);
}
@ -326,7 +326,7 @@ void CheckBlitter()
{
if (!SwitchNewGRFBlitter()) return;
ClearFontCache(FONTSIZES_ALL);
FontCache::ClearFontCaches(FONTSIZES_ALL);
GfxClearSpriteCache();
ReInitAllWindows(false);
}
@ -338,7 +338,7 @@ void GfxLoadSprites()
SwitchNewGRFBlitter();
VideoDriver::GetInstance()->ClearSystemSprites();
ClearFontCache(FONTSIZES_ALL);
FontCache::ClearFontCaches(FONTSIZES_ALL);
GfxInitSpriteMem();
LoadSpriteTables();
GfxInitPalettes();

View File

@ -697,8 +697,11 @@ STR_GRAPH_CARGO_TOOLTIP_DISABLE_ALL :{BLACK}Ne mutas
STR_GRAPH_CARGO_PAYMENT_TOGGLE_CARGO :{BLACK}Adott rakomány grafikonjának mutatása be/ki
STR_GRAPH_CARGO_PAYMENT_CARGO :{TINY_FONT}{BLACK}{STRING}
STR_GRAPH_INDUSTRY_CAPTION :{WHITE}{INDUSTRY} - Rakománytörténet
STR_GRAPH_INDUSTRY_RANGE_PRODUCED :Előállított
STR_GRAPH_INDUSTRY_RANGE_TRANSPORTED :Szállítva
STR_GRAPH_INDUSTRY_RANGE_DELIVERED :Leszállítva
STR_GRAPH_INDUSTRY_RANGE_WAITING :Várakozik
STR_GRAPH_PERFORMANCE_DETAIL_TOOLTIP :{BLACK}Részletes teljesítményértékelés mutatása
@ -4087,6 +4090,8 @@ STR_INDUSTRY_VIEW_PRODUCTION_LAST_MONTH_TITLE :{BLACK}Múlt ha
STR_INDUSTRY_VIEW_PRODUCTION_LAST_MINUTE_TITLE :{BLACK}Termelés az elmúlt percben:
STR_INDUSTRY_VIEW_TRANSPORTED :{YELLOW}{CARGO_LONG}{STRING}{BLACK} ({COMMA}% elszállítva)
STR_INDUSTRY_VIEW_LOCATION_TOOLTIP :{BLACK}A fő nézetet a gazdasági épületre állítja. Ctrl+kattintással új nézet nyílik a gazdasági épület helyzeténél
STR_INDUSTRY_VIEW_CARGO_GRAPH :{BLACK}Rakomány grafikon
STR_INDUSTRY_VIEW_CARGO_GRAPH_TOOLTIP :{BLACK}Megmutatja az iparág rakománytörténetének grafikonját
STR_INDUSTRY_VIEW_PRODUCTION_LEVEL :{BLACK}Termelési szint: {YELLOW}{COMMA}%
STR_INDUSTRY_VIEW_INDUSTRY_ANNOUNCED_CLOSURE :{YELLOW}A gyár bejelentette a közelgő bezárását!
@ -5062,6 +5067,7 @@ STR_ERROR_FLAT_LAND_REQUIRED :{WHITE}Sima tal
STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION :{WHITE}Rossz irányba lejt a föld
STR_ERROR_CAN_T_DO_THIS :{WHITE}Nem teheted ezt...
STR_ERROR_BUILDING_MUST_BE_DEMOLISHED :{WHITE}Előbb le kell rombolnod az épületet
STR_ERROR_BUILDING_IS_PROTECTED :{WHITE}... a(z) épület védett
STR_ERROR_CAN_T_CLEAR_THIS_AREA :{WHITE}Nem tisztíthatod meg ezt a területet...
STR_ERROR_SITE_UNSUITABLE :{WHITE}... nem alkalmas rá a hely
STR_ERROR_ALREADY_BUILT :{WHITE}... már van itt

View File

@ -437,6 +437,7 @@ STR_SETTINGS_MENU_NEWGRF_SETTINGS :NewGRFの設定
STR_SETTINGS_MENU_TRANSPARENCY_OPTIONS :透過表示設定
STR_SETTINGS_MENU_TOWN_NAMES_DISPLAYED :街名を表示
STR_SETTINGS_MENU_STATION_NAMES_DISPLAYED :駅名を表示
STR_SETTINGS_MENU_STATION_NAMES_BUS :バス停
STR_SETTINGS_MENU_WAYPOINTS_DISPLAYED :中継駅名を表示
STR_SETTINGS_MENU_SIGNS_DISPLAYED :標識を表示
STR_SETTINGS_MENU_SHOW_COMPETITOR_SIGNS :競争者の標識と名前を表示
@ -522,6 +523,7 @@ STR_ABOUT_MENU_ABOUT_OPENTTD :OpenTTDにつ
STR_ABOUT_MENU_SPRITE_ALIGNER :スプライトを整列
STR_ABOUT_MENU_TOGGLE_BOUNDING_BOXES :バウンディングボックスの表示切替
STR_ABOUT_MENU_TOGGLE_DIRTY_BLOCKS :ダーティーブロックの色付け切替
STR_ABOUT_MENU_TOGGLE_WIDGET_OUTLINES :ウィジェットの枠線の表示切替
###length 31
STR_DAY_NUMBER_1ST :1
@ -1203,12 +1205,14 @@ STR_CONFIG_SETTING_HORIZONTAL_POS_CENTER :中央
STR_CONFIG_SETTING_HORIZONTAL_POS_RIGHT :右
STR_CONFIG_SETTING_INFINITE_MONEY :無限の資金: {STRING}
STR_CONFIG_SETTING_INFINITE_MONEY_HELPTEXT :無制限の支出を許容し、会社の破産も無効にします
STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN :初期の借入最大額: {STRING}
STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN_HELPTEXT :初期の借入限度額を設定します (インフレは考慮されません)
STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN_HELPTEXT :初期の借入限度額を設定します (インフレは考慮されません)。「借入金なし」に設定した場合、ゲームスクリプトか「無限の資金」オプションによる提供がない限り、資金は利用できなくなります。
STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN_VALUE :{CURRENCY_LONG}
###setting-zero-is-special
STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN_DISABLED :借入金なし {RED}ゲームスクリプトで資金を受給する必要があります
STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN_DISABLED :借入金なし
STR_CONFIG_SETTING_INTEREST_RATE :金利: {STRING}
STR_CONFIG_SETTING_INTEREST_RATE_HELPTEXT :借入利率を設定します (インフレ設定を有効にしたときのインフレ率にも影響します)
@ -1247,7 +1251,7 @@ STR_CONFIG_SETTING_TRAIN_REVERSING_HELPTEXT :設定を有効
STR_CONFIG_SETTING_DISASTERS :災害: {STRING}
STR_CONFIG_SETTING_DISASTERS_HELPTEXT :設定を有効にすると時折、乗り物や交通インフラを遮断・破壊する災害が起きるようになります
STR_CONFIG_SETTING_CITY_APPROVAL :議会の姿勢: {STRING}
STR_CONFIG_SETTING_CITY_APPROVAL :地方自治体の姿勢: {STRING}
STR_CONFIG_SETTING_CITY_APPROVAL_HELPTEXT :会社が街で引き起こした騒音(主に空港)や環境破壊がどの程度、街での評価や更なる建設行為に影響するかを設定します
STR_CONFIG_SETTING_MAP_HEIGHT_LIMIT :マップ高さ限界: {STRING}
@ -1351,10 +1355,10 @@ STR_CONFIG_SETTING_AUTOSCROLL_MAIN_VIEWPORT_FULLSCREEN :する (フル
STR_CONFIG_SETTING_AUTOSCROLL_MAIN_VIEWPORT :する
STR_CONFIG_SETTING_AUTOSCROLL_EVERY_VIEWPORT :する (ビューポートでも有効)
STR_CONFIG_SETTING_BRIBE :議会の買収: {STRING}
STR_CONFIG_SETTING_BRIBE :地方自治体の贈賄: {STRING}
###length 2
STR_CONFIG_SETTING_BRIBE_HELPTEXT :街で議会買収を企てられるようになります。成功すれば街での評判が良くなりますが、地元当局に事が発覚した場合罰金を受けた上評判が悪くなり、その上その街では半年間何もできなくなります
STR_CONFIG_SETTING_BRIBE_HELPTEXT_MINUTES :会社が議会買収を企てられるようにします。もし当局に事が発覚した場合、買収した会社は当該自治体では半年間何もできなくなります
STR_CONFIG_SETTING_BRIBE_HELPTEXT :地方自治体への贈賄を企てられるようにします。もし当局に事が発覚した場合、贈賄を試みた会社は当該自治体では半年間何もできなくなります
STR_CONFIG_SETTING_BRIBE_HELPTEXT_MINUTES :地方自治体への贈賄を企てられるようにします。もし当局に事が発覚した場合、贈賄を試みた会社は当該自治体では半年間何もできなくなります
STR_CONFIG_SETTING_ALLOW_EXCLUSIVE :独占運送契約の締結: {STRING}
###length 2
@ -1424,6 +1428,7 @@ STR_CONFIG_SETTING_NEVER_EXPIRE_VEHICLES_HELPTEXT :有効にする
###setting-zero-is-special
STR_CONFIG_SETTING_CARGO_SCALE_VALUE :{NUM}%
STR_CONFIG_SETTING_AUTORENEW_VEHICLE :老朽車両の自動交換: {STRING}
STR_CONFIG_SETTING_AUTORENEW_VEHICLE_HELPTEXT :有効にすると、耐用年数を越えた輸送機器は自動で更新されるようになります(交換には一度格納施設に戻る必要があります)。具体的な交換時期は下の設定で変更できます。
@ -1858,7 +1863,7 @@ STR_CONFIG_SETTING_ALLOW_TOWN_ROADS_HELPTEXT :街の自治体
STR_CONFIG_SETTING_ALLOW_TOWN_LEVEL_CROSSINGS :街路との平面交差を許可: {STRING}
STR_CONFIG_SETTING_ALLOW_TOWN_LEVEL_CROSSINGS_HELPTEXT :有効にすると、会社が作る道路と街路とが交差できるようになります
STR_CONFIG_SETTING_NOISE_LEVEL :空港建設に対する街の騒音レベル規制: {STRING}
STR_CONFIG_SETTING_NOISE_LEVEL :騒音レベルに基づいた空港建設の制限: {STRING}
STR_CONFIG_SETTING_NOISE_LEVEL_HELPTEXT :この設定を無効にすると、街に作れる空港は最大2つまでになります。有効にした場合は、各空港の騒音レベルの総和が街の騒音許容レベル以下になるようにしか建てられません。騒音レベルは空港の大きさ・街からの距離により、騒音許容レベルは街の人口により左右されます
STR_CONFIG_SETTING_TOWN_FOUNDING :ゲーム中での街新設: {STRING}
@ -1936,9 +1941,9 @@ STR_CONFIG_SETTING_CITY_SIZE_MULTIPLIER :初期の都市
STR_CONFIG_SETTING_CITY_SIZE_MULTIPLIER_HELPTEXT :ゲーム開始時に都市が普通の街に比べて平均して何倍の人口規模になるかを設定します
STR_CONFIG_SETTING_LINKGRAPH_RECALC_INTERVAL :行先分配グラフを{STRING}秒毎に更新
STR_CONFIG_SETTING_LINKGRAPH_RECALC_INTERVAL_HELPTEXT :行先分配グラフの更新の間の待ち時間。各更新はグラフの一部だけのルートを再計算します。即ち、この設定を〇〇秒に指定する場合、全グラフが〇〇秒毎に更新されるのではありません。間隔が短ければ短いほどCPU時間を消費します。長ければ長いほど貨物流通の新規ルートの行先分配に時間がかかります。
STR_CONFIG_SETTING_LINKGRAPH_RECALC_INTERVAL_HELPTEXT :行先分配グラフの再計算間隔。各計算タイミングでは一部のグラフのみが再計算されます。よって、ここ設定した X 秒ごとにグラフ全体が更新されるというわけではありません。再計算の間隔が短ければ短いほどCPU時間を消費します。長ければ長いほど貨物流通の新規ルートの行先分配に時間がかかります。
STR_CONFIG_SETTING_LINKGRAPH_RECALC_TIME :行先分配の更新に{STRING}秒を割り当て
STR_CONFIG_SETTING_LINKGRAPH_RECALC_TIME_HELPTEXT :行先分配グラフの更新に割り当てられる時間。更新が始まると、スレッドが生成されて、指定の時間に実行させられます。短ければ短いほど間に合わない可能性が高まります。その場合、ゲームは停止して計算完了を待ちます。長ければ長いほどルート変更の際に行先分配の更新に時間がかかります。
STR_CONFIG_SETTING_LINKGRAPH_RECALC_TIME_HELPTEXT :行先分配グラフの再計算に割り当てられる時間。再計算が始まると、グラフの処理のために指定した生存秒数だけ実行可能なスレッドが作られます。生存秒数が短ければ短いほど再計算が間に合わない可能性が高まります。その際、ゲームは一時停止して計算完了を待ちます。生存秒数が長ければ長いほど、ルート変更の際に行先分配の更新に時間がかかります。
STR_CONFIG_SETTING_DISTRIBUTION_PAX :旅客の行先分配法: {STRING}
STR_CONFIG_SETTING_DISTRIBUTION_PAX_HELPTEXT :旅客がどのように行き先別に分配されるかを設定します。「対称」ではAからBへ向かう乗客とほぼ同数が、BからAに向かうようになります。 「非対称」ではそれぞれの方向に向かう旅客数は独立に決められます。「無効」では行き先別分配をしなくなります。
@ -1954,7 +1959,7 @@ STR_CONFIG_SETTING_DISTRIBUTION_ASYMMETRIC :非対称
STR_CONFIG_SETTING_DISTRIBUTION_SYMMETRIC :対称
STR_CONFIG_SETTING_LINKGRAPH_ACCURACY :分配精度: {STRING}
STR_CONFIG_SETTING_LINKGRAPH_ACCURACY_HELPTEXT :この値を高くすると、リンクグラフ演算の為CPUへの負荷が大きくなります。演算に時間がかかりすぎると、目に見えてタイムラグが起こる場合があります。しかし低い値に設定すると、分配が不正確になり、望まれる場所に貨物が送られなくなる場合があります
STR_CONFIG_SETTING_LINKGRAPH_ACCURACY_HELPTEXT :この設定値を高く設定すればするほど、行先分配グラフの計算に要するCPU時間が長くなります。計算に時間がかかりすぎると遅延が発生する可能性があります。一方、設定値を低く設定すると分配が不正確になり、荷物が意図された場所に送られない場合があります。
STR_CONFIG_SETTING_DEMAND_DISTANCE :距離効果: {STRING}
STR_CONFIG_SETTING_DEMAND_DISTANCE_HELPTEXT :0より大きい値に設定すると、ある貨物の生産先Aと受取可能先Bとの距離がAからBへ送られる貨物量に影響を及ぼすようになります。高い値を設定すればするほど、遠い施設に送られる貨物量は少なくなり、近場の施設に送られる量が大きくなります
@ -2058,8 +2063,10 @@ STR_CONFIG_ERROR_INVALID_BASE_MUSIC_NOT_FOUND :{WHITE}ファ
# Video initalization errors
STR_VIDEO_DRIVER_ERROR :{WHITE}ビデオ設定にエラーがあります...
STR_VIDEO_DRIVER_ERROR_NO_HARDWARE_ACCELERATION :{WHITE}... 対応する GPU が見つかりません。ハードウェアアクセラレーションは無効になります。
STR_VIDEO_DRIVER_ERROR_HARDWARE_ACCELERATION_CRASH :{WHITE}... GPUドライバーがゲームをクラッシュさせました。ハードウェアアクセラレーションは無効になりました
# Intro window
STR_INTRO_CAPTION :{WHITE}OpenTTD
STR_INTRO_NEW_GAME :{BLACK}新しいゲーム
STR_INTRO_LOAD_GAME :{BLACK}ロード
@ -2070,6 +2077,7 @@ STR_INTRO_MULTIPLAYER :{BLACK}マル
STR_INTRO_GAME_OPTIONS :{BLACK}基本設定
STR_INTRO_HIGHSCORE :{BLACK}ハイスコア
STR_INTRO_HELP :{BLACK}ヘルプとマニュアル
STR_INTRO_ONLINE_CONTENT :{BLACK}オンラインコンテンツの確認
STR_INTRO_QUIT :{BLACK}終了
@ -2121,14 +2129,14 @@ STR_HELP_WINDOW_COMMUNITY :{BLACK}コミ
STR_CHEATS :{WHITE}サンドボックスのオプション
STR_CHEAT_MONEY :{LTBLUE}預金残高を{CURRENCY_LONG}増やす
STR_CHEAT_CHANGE_COMPANY :{LTBLUE}会社: {ORANGE}{COMMA}を乗っ取ってプレイする
STR_CHEAT_EXTRA_DYNAMITE :{LTBLUE}魔法のブルドーザー(産業拠点等、何でも撤去できる): {ORANGE}{STRING}
STR_CHEAT_EXTRA_DYNAMITE :{LTBLUE}魔法のブルドーザー(産業拠点など何でも撤去可能): {ORANGE}{STRING}
STR_CHEAT_CROSSINGTUNNELS :{LTBLUE}トンネルの平面交差を許容: {ORANGE}{STRING}
STR_CHEAT_NO_JETCRASH :{LTBLUE}ジェット機の小型空港での墜落率を減少: {ORANGE}{STRING}
STR_CHEAT_EDIT_MAX_HL :{LTBLUE}マップの最高高度を変更: {ORANGE}{NUM}
STR_CHEAT_EDIT_MAX_HL_QUERY_CAPT :{WHITE}マップの最大高度
STR_CHEAT_CHANGE_DATE :{LTBLUE}日付を変更: {ORANGE}{DATE_SHORT}
STR_CHEAT_CHANGE_DATE_QUERY_CAPT :{WHITE}現在日時を変更
STR_CHEAT_SETUP_PROD :{LTBLUE}生産量変更: {ORANGE}{STRING}
STR_CHEAT_SETUP_PROD :{LTBLUE}産業の生産量変更を有効化: {ORANGE}{STRING}
# Livery window
STR_LIVERY_CAPTION :{WHITE}{COMPANY} - 配色
@ -2457,6 +2465,7 @@ STR_NETWORK_SERVER_MESSAGE_GAME_REASON_LINK_GRAPH :リンクグラ
STR_NETWORK_MESSAGE_CLIENT_LEAVING :退出
STR_NETWORK_MESSAGE_CLIENT_JOINED :*** {STRING} が参加してきました
STR_NETWORK_MESSAGE_CLIENT_JOINED_ID :*** {STRING} がゲームに参加してきました (クライアント #{NUM})
STR_NETWORK_MESSAGE_CLIENT_COMPANY_JOIN :*** {0:STRING} が{STRING}の経営に参画してきました
STR_NETWORK_MESSAGE_CLIENT_COMPANY_SPECTATE :*** {STRING} がゲームを観覧し始めました
STR_NETWORK_MESSAGE_CLIENT_COMPANY_NEW :*** {STRING} が新会社 (#{NUM}) を設立しました
STR_NETWORK_MESSAGE_CLIENT_LEFT :*** {STRING} が退出しました({STRING})
@ -2672,6 +2681,7 @@ STR_SELECT_ROAD_BRIDGE_CAPTION :{WHITE}道路
STR_SELECT_BRIDGE_SELECTION_TOOLTIP :{BLACK}建設したい橋の種類をクリックしてください
STR_SELECT_BRIDGE_INFO_NAME :{GOLD}{STRING}
STR_SELECT_BRIDGE_INFO_NAME_MAX_SPEED :{GOLD}{STRING}{} {VELOCITY}
STR_SELECT_BRIDGE_INFO_NAME_COST :{GOLD}{STRING}{} {WHITE}{CURRENCY_LONG}
STR_SELECT_BRIDGE_INFO_NAME_MAX_SPEED_COST :{GOLD}{STRING}{} {VELOCITY} {WHITE}{CURRENCY_LONG}
STR_BRIDGE_NAME_SUSPENSION_STEEL :吊橋(S造)
STR_BRIDGE_NAME_GIRDER_STEEL :桁橋(S造)
@ -3458,7 +3468,7 @@ STR_LOCAL_AUTHORITY_ACTION_ROAD_RECONSTRUCTION :道路補修に
STR_LOCAL_AUTHORITY_ACTION_STATUE_OF_COMPANY :社長の彫像を建設
STR_LOCAL_AUTHORITY_ACTION_NEW_BUILDINGS :市街地開発に出資
STR_LOCAL_AUTHORITY_ACTION_EXCLUSIVE_TRANSPORT :独占運送契約を締結
STR_LOCAL_AUTHORITY_ACTION_BRIBE :議会を買収
STR_LOCAL_AUTHORITY_ACTION_BRIBE :地方自治体への贈賄
###next-name-looks-similar
STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_SMALL_ADVERTISING :{PUSH_COLOUR}{YELLOW}旅客と貨物を確保する為に、街で新聞広告を実施します。{}より多くの旅客と貨物が自社の交通網を利用するようになります。{}{POP_COLOUR}費用: {CURRENCY_LONG}
@ -3466,7 +3476,7 @@ STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_MEDIUM_ADVERTISING :{PUSH_COLOUR}{Y
STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_LARGE_ADVERTISING :{PUSH_COLOUR}{YELLOW}旅客と貨物を確保する為に、街でTV-CMを開始します{}街の中心部の大範囲にある駅の評価が一時的に高まります。{}{POP_COLOUR}費用: {CURRENCY_LONG}
STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_STATUE_OF_COMPANY :{PUSH_COLOUR}{YELLOW}社を称える彫像を建設します{}この街の駅の評価を恒久的に高めます。{}{POP_COLOUR}費用: {CURRENCY_LONG}
STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_NEW_BUILDINGS :{PUSH_COLOUR}{YELLOW}市街地の開発に出資します{}街の成長速度が一時的に早まります。{}{POP_COLOUR}費用: {CURRENCY_LONG}
STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_BRIBE :{PUSH_COLOUR}{YELLOW}買収を行い、議会内の評判を高めます。注意: 露見した場合は処罰されます{}{POP_COLOUR}費用: {CURRENCY_LONG}
STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_BRIBE :{PUSH_COLOUR}{YELLOW}贈賄を通じて地方自治体内の評判を高めます。注意: 露見した場合は処罰されます{}{POP_COLOUR}費用: {CURRENCY_LONG}
# Goal window
STR_GOALS_CAPTION :{WHITE}{COMPANY} 目標
@ -4374,6 +4384,7 @@ STR_ORDER_REFIT_STOP_ORDER :({STRING}に改
STR_ORDER_STOP_ORDER :(運用停止)
STR_ORDER_GO_TO_STATION :{STRING} {STATION}
STR_ORDER_GO_TO_STATION_CAN_T_USE_STATION :{PUSH_COLOUR}{RED}(駅を使用できません){POP_COLOUR} {STRING} {STATION}
STR_ORDER_IMPLICIT :(自動)
@ -4432,6 +4443,7 @@ STR_TIMETABLE_TOOLTIP :{BLACK}ダイ
STR_TIMETABLE_NO_TRAVEL :運行計画無
STR_TIMETABLE_NOT_TIMETABLEABLE :該当区間を運行 (次の手動指令により自動設定)
STR_TIMETABLE_TRAVEL_NOT_TIMETABLED :該当区間を運行 (ダイヤ設定無)
STR_TIMETABLE_TRAVEL_NOT_TIMETABLED_SPEED :最高速度{VELOCITY}で該当区間を運行 (ダイヤ設定無)
STR_TIMETABLE_TRAVEL_FOR :{STRING}で該当区間を運行
STR_TIMETABLE_TRAVEL_FOR_SPEED :{STRING}で該当区間を運行(最高速度{VELOCITY})
STR_TIMETABLE_TRAVEL_FOR_ESTIMATED :運行({0:STRING}・ダイヤ設定無)
@ -4525,14 +4537,14 @@ STR_AI_CONFIG_MOVE_DOWN :{BLACK}下に
STR_AI_CONFIG_MOVE_DOWN_TOOLTIP :{BLACK}選択したAIの順位を下げる
STR_AI_CONFIG_GAMESCRIPT :{SILVER}ゲームスクリプト
STR_AI_CONFIG_GAMESCRIPT_PARAM :{SILVER}パラメータ
STR_AI_CONFIG_GAMESCRIPT_PARAM :{SILVER}パラメータ
STR_AI_CONFIG_AI :{SILVER}AI
STR_AI_CONFIG_CHANGE_AI :{BLACK}AIを選択
STR_AI_CONFIG_CHANGE_GAMESCRIPT :{BLACK}ゲームスクリプトを選択
STR_AI_CONFIG_CHANGE_TOOLTIP :{BLACK}他のスクリプトをロードします。Ctrl+クリックで全ての利用可能バージョンを表示します
STR_AI_CONFIG_CONFIGURE :{BLACK}設定
STR_AI_CONFIG_CONFIGURE_TOOLTIP :{BLACK}スクリプトのパラメータを設定します
STR_AI_CONFIG_CONFIGURE_TOOLTIP :{BLACK}スクリプトのパラメータを設定します
# Available AIs window
STR_AI_LIST_CAPTION :{WHITE}使用可能な{STRING}
@ -4556,8 +4568,8 @@ STR_SCREENSHOT_HEIGHTMAP_SCREENSHOT :{BLACK}ハイ
STR_SCREENSHOT_MINIMAP_SCREENSHOT :{BLACK}ミニマップのスクリーンショット
# Script Parameters
STR_AI_SETTINGS_CAPTION_AI :AI
STR_AI_SETTINGS_CAPTION_GAMESCRIPT :ゲームスクリプト
STR_AI_SETTINGS_CAPTION_AI :{WHITE}AIのパラメーター
STR_AI_SETTINGS_CAPTION_GAMESCRIPT :{WHITE}ゲームスクリプトのパラメーター
STR_AI_SETTINGS_RESET :{BLACK}リセット
STR_AI_SETTINGS_SETTING :{STRING}: {ORANGE}{STRING}
@ -4638,6 +4650,7 @@ STR_ERROR_SCREENSHOT_FAILED :{WHITE}スク
# Error message titles
STR_ERROR_MESSAGE_CAPTION :{YELLOW}メッセージ
STR_ERROR_MESSAGE_CAPTION_OTHER_COMPANY :{YELLOW}{COMPANY}からのメッセージ
# Generic construction errors
STR_ERROR_OFF_EDGE_OF_MAP :{WHITE}マップからはみ出します
@ -4656,12 +4669,13 @@ STR_ERROR_TERRAFORM_LIMIT_REACHED :{WHITE}一度
STR_ERROR_CLEARING_LIMIT_REACHED :{WHITE}一度にできる撤去量を越えています
STR_ERROR_TREE_PLANT_LIMIT_REACHED :{WHITE}木の本数が多すぎます
STR_ERROR_NAME_MUST_BE_UNIQUE :{WHITE}名前は重複してはいけません
STR_ERROR_GENERIC_OBJECT_IN_THE_WAY :{WHITE}{STRING}があります
STR_ERROR_NOT_ALLOWED_WHILE_PAUSED :{WHITE}ポーズ中にはできない行動です
# Local authority errors
STR_ERROR_LOCAL_AUTHORITY_REFUSES_TO_ALLOW_THIS :{WHITE}{TOWN}議会が反対しています
STR_ERROR_LOCAL_AUTHORITY_REFUSES_AIRPORT :{WHITE}{TOWN}議会はこれ以上の空港建設を認可しない方針です
STR_ERROR_LOCAL_AUTHORITY_REFUSES_NOISE :{WHITE}{TOWN}の地元民が騒音公害を理由に空港建設に反対しています
STR_ERROR_LOCAL_AUTHORITY_REFUSES_TO_ALLOW_THIS :{WHITE}{TOWN}の地方自治体が反対しています
STR_ERROR_LOCAL_AUTHORITY_REFUSES_AIRPORT :{WHITE}{TOWN}の地方自治体はこれ以上の空港建設を許可しません
STR_ERROR_LOCAL_AUTHORITY_REFUSES_NOISE :{WHITE}{TOWN}の地方自治体は騒音公害の懸念から空港建設を許可しません
STR_ERROR_BRIBE_FAILED :{WHITE}あなたの行った贈収賄が地元当局に露見しました!
# Levelling errors
@ -5535,3 +5549,8 @@ STR_SHIP :{BLACK}{SHIP}
STR_TOOLBAR_RAILTYPE_VELOCITY :{STRING} ({VELOCITY})
STR_BADGE_CONFIG_MENU_TOOLTIP :バッジ設定を開く
STR_BADGE_CONFIG_RESET :リセット
STR_BADGE_CONFIG_ICONS :{WHITE}バッジのアイコン
STR_BADGE_CONFIG_FILTERS :{WHITE}バッジのフィルター
STR_BADGE_CONFIG_NAME :名前

View File

@ -315,7 +315,7 @@ static void ShutdownGame()
/* No NewGRFs were loaded when it was still bootstrapping. */
if (_game_mode != GM_BOOTSTRAP) ResetNewGRFData();
UninitFontCache();
FontCache::UninitializeFontCaches();
}
/**
@ -700,7 +700,7 @@ int openttd_main(std::span<std::string_view> arguments)
InitializeLanguagePacks();
/* Initialize the font cache */
InitFontCache(FONTSIZES_REQUIRED);
FontCache::LoadFontCaches(FONTSIZES_REQUIRED);
/* This must be done early, since functions use the SetWindowDirty* calls */
InitWindowSystem();

View File

@ -14,7 +14,6 @@
#include "../../blitter/factory.hpp"
#include "../../error_func.h"
#include "../../fileio_func.h"
#include "../../fontdetection.h"
#include "../../string_func.h"
#include "../../strings_func.h"
#include "../../zoom_func.h"
@ -24,91 +23,6 @@
#include "../../safeguards.h"
bool SetFallbackFont(FontCacheSettings *settings, const std::string &language_isocode, MissingGlyphSearcher *callback)
{
/* Determine fallback font using CoreText. This uses the language isocode
* to find a suitable font. CoreText is available from 10.5 onwards. */
std::string lang;
if (language_isocode == "zh_TW") {
/* Traditional Chinese */
lang = "zh-Hant";
} else if (language_isocode == "zh_CN") {
/* Simplified Chinese */
lang = "zh-Hans";
} else {
/* Just copy the first part of the isocode. */
lang = language_isocode.substr(0, language_isocode.find('_'));
}
/* Create a font descriptor matching the wanted language and latin (english) glyphs.
* Can't use CFAutoRelease here for everything due to the way the dictionary has to be created. */
CFStringRef lang_codes[2];
lang_codes[0] = CFStringCreateWithCString(kCFAllocatorDefault, lang.c_str(), kCFStringEncodingUTF8);
lang_codes[1] = CFSTR("en");
CFArrayRef lang_arr = CFArrayCreate(kCFAllocatorDefault, (const void **)lang_codes, lengthof(lang_codes), &kCFTypeArrayCallBacks);
CFAutoRelease<CFDictionaryRef> lang_attribs(CFDictionaryCreate(kCFAllocatorDefault, const_cast<const void **>(reinterpret_cast<const void *const *>(&kCTFontLanguagesAttribute)), (const void **)&lang_arr, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
CFAutoRelease<CTFontDescriptorRef> lang_desc(CTFontDescriptorCreateWithAttributes(lang_attribs.get()));
CFRelease(lang_arr);
CFRelease(lang_codes[0]);
/* Get array of all font descriptors for the wanted language. */
CFAutoRelease<CFSetRef> mandatory_attribs(CFSetCreate(kCFAllocatorDefault, const_cast<const void **>(reinterpret_cast<const void *const *>(&kCTFontLanguagesAttribute)), 1, &kCFTypeSetCallBacks));
CFAutoRelease<CFArrayRef> descs(CTFontDescriptorCreateMatchingFontDescriptors(lang_desc.get(), mandatory_attribs.get()));
bool result = false;
for (int tries = 0; tries < 2; tries++) {
for (CFIndex i = 0; descs.get() != nullptr && i < CFArrayGetCount(descs.get()); i++) {
CTFontDescriptorRef font = (CTFontDescriptorRef)CFArrayGetValueAtIndex(descs.get(), i);
/* Get font traits. */
CFAutoRelease<CFDictionaryRef> traits((CFDictionaryRef)CTFontDescriptorCopyAttribute(font, kCTFontTraitsAttribute));
CTFontSymbolicTraits symbolic_traits;
CFNumberGetValue((CFNumberRef)CFDictionaryGetValue(traits.get(), kCTFontSymbolicTrait), kCFNumberIntType, &symbolic_traits);
/* Skip symbol fonts and vertical fonts. */
if ((symbolic_traits & kCTFontClassMaskTrait) == (CTFontStylisticClass)kCTFontSymbolicClass || (symbolic_traits & kCTFontVerticalTrait)) continue;
/* Skip bold fonts (especially Arial Bold, which looks worse than regular Arial). */
if (symbolic_traits & kCTFontBoldTrait) continue;
/* Select monospaced fonts if asked for. */
if (((symbolic_traits & kCTFontMonoSpaceTrait) == kCTFontMonoSpaceTrait) != callback->Monospace()) continue;
/* Get font name. */
char buffer[128];
CFAutoRelease<CFStringRef> font_name((CFStringRef)CTFontDescriptorCopyAttribute(font, kCTFontDisplayNameAttribute));
CFStringGetCString(font_name.get(), buffer, std::size(buffer), kCFStringEncodingUTF8);
/* Serif fonts usually look worse on-screen with only small
* font sizes. As such, we try for a sans-serif font first.
* If we can't find one in the first try, try all fonts. */
if (tries == 0 && (symbolic_traits & kCTFontClassMaskTrait) != (CTFontStylisticClass)kCTFontSansSerifClass) continue;
/* There are some special fonts starting with an '.' and the last
* resort font that aren't usable. Skip them. */
std::string_view name{buffer};
if (name.starts_with(".") || name.starts_with("LastResort")) continue;
/* Save result. */
callback->SetFontNames(settings, name);
if (!callback->FindMissingGlyphs()) {
Debug(fontcache, 2, "CT-Font for {}: {}", language_isocode, name);
result = true;
break;
}
}
}
if (!result) {
/* For some OS versions, the font 'Arial Unicode MS' does not report all languages it
* supports. If we didn't find any other font, just try it, maybe we get lucky. */
callback->SetFontNames(settings, "Arial Unicode MS");
result = !callback->FindMissingGlyphs();
}
callback->FindMissingGlyphs();
return result;
}
CoreTextFontCache::CoreTextFontCache(FontSize fs, CFAutoRelease<CTFontDescriptorRef> &&font, int pixels) : TrueTypeFontCache(fs, pixels), font_desc(std::move(font))
{
this->SetFontSize(pixels);
@ -287,39 +201,9 @@ const Sprite *CoreTextFontCache::InternalGetGlyph(GlyphID key, bool use_aa)
return this->SetGlyphPtr(key, std::move(new_glyph)).GetSprite();
}
static CTFontDescriptorRef LoadFontFromFile(const std::string &font_name)
{
if (!MacOSVersionIsAtLeast(10, 6, 0)) return nullptr;
/* Might be a font file name, try load it. Direct font loading is
* only supported starting on OSX 10.6. */
CFAutoRelease<CFStringRef> path;
/* See if this is an absolute path. */
if (FileExists(font_name)) {
path.reset(CFStringCreateWithCString(kCFAllocatorDefault, font_name.c_str(), kCFStringEncodingUTF8));
} else {
/* Scan the search-paths to see if it can be found. */
std::string full_font = FioFindFullPath(BASE_DIR, font_name);
if (!full_font.empty()) {
path.reset(CFStringCreateWithCString(kCFAllocatorDefault, full_font.c_str(), kCFStringEncodingUTF8));
}
}
if (path) {
/* Try getting a font descriptor to see if the system can use it. */
CFAutoRelease<CFURLRef> url(CFURLCreateWithFileSystemPath(kCFAllocatorDefault, path.get(), kCFURLPOSIXPathStyle, false));
CFAutoRelease<CFArrayRef> descs(CTFontManagerCreateFontDescriptorsFromURL(url.get()));
if (descs && CFArrayGetCount(descs.get()) > 0) {
CTFontDescriptorRef font_ref = (CTFontDescriptorRef)CFArrayGetValueAtIndex(descs.get(), 0);
CFRetain(font_ref);
return font_ref;
}
}
return nullptr;
}
class CoreTextFontCacheFactory : public FontCacheFactory {
public:
CoreTextFontCacheFactory() : FontCacheFactory("coretext", "CoreText font loader") {}
/**
* Loads the TrueType font.
@ -327,12 +211,14 @@ static CTFontDescriptorRef LoadFontFromFile(const std::string &font_name)
* fallback search, use it. Otherwise, try to resolve it by font name.
* @param fs The font size to load.
*/
void LoadCoreTextFont(FontSize fs)
std::unique_ptr<FontCache> LoadFont(FontSize fs, FontType fonttype) override
{
if (fonttype != FontType::TrueType) return nullptr;
FontCacheSubSetting *settings = GetFontCacheSubSetting(fs);
std::string font = GetFontCacheFontName(fs);
if (font.empty()) return;
if (font.empty()) return nullptr;
CFAutoRelease<CTFontDescriptorRef> font_ref;
@ -367,8 +253,130 @@ void LoadCoreTextFont(FontSize fs)
if (!font_ref) {
ShowInfo("Unable to use '{}' for {} font, using sprite font instead", font, FontSizeToName(fs));
return;
return nullptr;
}
new CoreTextFontCache(fs, std::move(font_ref), GetFontCacheFontSize(fs));
return std::make_unique<CoreTextFontCache>(fs, std::move(font_ref), GetFontCacheFontSize(fs));
}
bool FindFallbackFont(FontCacheSettings *settings, const std::string &language_isocode, MissingGlyphSearcher *callback) override
{
/* Determine fallback font using CoreText. This uses the language isocode
* to find a suitable font. CoreText is available from 10.5 onwards. */
std::string lang;
if (language_isocode == "zh_TW") {
/* Traditional Chinese */
lang = "zh-Hant";
} else if (language_isocode == "zh_CN") {
/* Simplified Chinese */
lang = "zh-Hans";
} else {
/* Just copy the first part of the isocode. */
lang = language_isocode.substr(0, language_isocode.find('_'));
}
/* Create a font descriptor matching the wanted language and latin (english) glyphs.
* Can't use CFAutoRelease here for everything due to the way the dictionary has to be created. */
CFStringRef lang_codes[2];
lang_codes[0] = CFStringCreateWithCString(kCFAllocatorDefault, lang.c_str(), kCFStringEncodingUTF8);
lang_codes[1] = CFSTR("en");
CFArrayRef lang_arr = CFArrayCreate(kCFAllocatorDefault, (const void **)lang_codes, lengthof(lang_codes), &kCFTypeArrayCallBacks);
CFAutoRelease<CFDictionaryRef> lang_attribs(CFDictionaryCreate(kCFAllocatorDefault, const_cast<const void **>(reinterpret_cast<const void *const *>(&kCTFontLanguagesAttribute)), (const void **)&lang_arr, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
CFAutoRelease<CTFontDescriptorRef> lang_desc(CTFontDescriptorCreateWithAttributes(lang_attribs.get()));
CFRelease(lang_arr);
CFRelease(lang_codes[0]);
/* Get array of all font descriptors for the wanted language. */
CFAutoRelease<CFSetRef> mandatory_attribs(CFSetCreate(kCFAllocatorDefault, const_cast<const void **>(reinterpret_cast<const void *const *>(&kCTFontLanguagesAttribute)), 1, &kCFTypeSetCallBacks));
CFAutoRelease<CFArrayRef> descs(CTFontDescriptorCreateMatchingFontDescriptors(lang_desc.get(), mandatory_attribs.get()));
bool result = false;
for (int tries = 0; tries < 2; tries++) {
for (CFIndex i = 0; descs.get() != nullptr && i < CFArrayGetCount(descs.get()); i++) {
CTFontDescriptorRef font = (CTFontDescriptorRef)CFArrayGetValueAtIndex(descs.get(), i);
/* Get font traits. */
CFAutoRelease<CFDictionaryRef> traits((CFDictionaryRef)CTFontDescriptorCopyAttribute(font, kCTFontTraitsAttribute));
CTFontSymbolicTraits symbolic_traits;
CFNumberGetValue((CFNumberRef)CFDictionaryGetValue(traits.get(), kCTFontSymbolicTrait), kCFNumberIntType, &symbolic_traits);
/* Skip symbol fonts and vertical fonts. */
if ((symbolic_traits & kCTFontClassMaskTrait) == (CTFontStylisticClass)kCTFontSymbolicClass || (symbolic_traits & kCTFontVerticalTrait)) continue;
/* Skip bold fonts (especially Arial Bold, which looks worse than regular Arial). */
if (symbolic_traits & kCTFontBoldTrait) continue;
/* Select monospaced fonts if asked for. */
if (((symbolic_traits & kCTFontMonoSpaceTrait) == kCTFontMonoSpaceTrait) != callback->Monospace()) continue;
/* Get font name. */
char buffer[128];
CFAutoRelease<CFStringRef> font_name((CFStringRef)CTFontDescriptorCopyAttribute(font, kCTFontDisplayNameAttribute));
CFStringGetCString(font_name.get(), buffer, std::size(buffer), kCFStringEncodingUTF8);
/* Serif fonts usually look worse on-screen with only small
* font sizes. As such, we try for a sans-serif font first.
* If we can't find one in the first try, try all fonts. */
if (tries == 0 && (symbolic_traits & kCTFontClassMaskTrait) != (CTFontStylisticClass)kCTFontSansSerifClass) continue;
/* There are some special fonts starting with an '.' and the last
* resort font that aren't usable. Skip them. */
std::string_view name{buffer};
if (name.starts_with(".") || name.starts_with("LastResort")) continue;
/* Save result. */
callback->SetFontNames(settings, name);
if (!callback->FindMissingGlyphs()) {
Debug(fontcache, 2, "CT-Font for {}: {}", language_isocode, name);
result = true;
break;
}
}
}
if (!result) {
/* For some OS versions, the font 'Arial Unicode MS' does not report all languages it
* supports. If we didn't find any other font, just try it, maybe we get lucky. */
callback->SetFontNames(settings, "Arial Unicode MS");
result = !callback->FindMissingGlyphs();
}
callback->FindMissingGlyphs();
return result;
}
private:
static CTFontDescriptorRef LoadFontFromFile(const std::string &font_name)
{
if (!MacOSVersionIsAtLeast(10, 6, 0)) return nullptr;
/* Might be a font file name, try load it. Direct font loading is
* only supported starting on OSX 10.6. */
CFAutoRelease<CFStringRef> path;
/* See if this is an absolute path. */
if (FileExists(font_name)) {
path.reset(CFStringCreateWithCString(kCFAllocatorDefault, font_name.c_str(), kCFStringEncodingUTF8));
} else {
/* Scan the search-paths to see if it can be found. */
std::string full_font = FioFindFullPath(BASE_DIR, font_name);
if (!full_font.empty()) {
path.reset(CFStringCreateWithCString(kCFAllocatorDefault, full_font.c_str(), kCFStringEncodingUTF8));
}
}
if (path) {
/* Try getting a font descriptor to see if the system can use it. */
CFAutoRelease<CFURLRef> url(CFURLCreateWithFileSystemPath(kCFAllocatorDefault, path.get(), kCFURLPOSIXPathStyle, false));
CFAutoRelease<CFArrayRef> descs(CTFontManagerCreateFontDescriptorsFromURL(url.get()));
if (descs && CFArrayGetCount(descs.get()) > 0) {
CTFontDescriptorRef font_ref = (CTFontDescriptorRef)CFArrayGetValueAtIndex(descs.get(), 0);
CFRetain(font_ref);
return font_ref;
}
}
return nullptr;
}
};
static CoreTextFontCacheFactory s_coretext_fontcache_Factory;

View File

@ -12,6 +12,7 @@ add_files(
add_files(
font_unix.cpp
font_unix.h
CONDITION Fontconfig_FOUND
)

View File

@ -11,17 +11,17 @@
#include "../../misc/autorelease.hpp"
#include "../../debug.h"
#include "../../fontdetection.h"
#include "../../fontcache.h"
#include "../../string_func.h"
#include "../../strings_func.h"
#include "font_unix.h"
#include <fontconfig/fontconfig.h>
#include "../../safeguards.h"
#include <ft2build.h>
#include FT_FREETYPE_H
#include "../../safeguards.h"
extern FT_Library _ft_library;
/**
@ -61,6 +61,12 @@ static std::tuple<std::string, std::string> SplitFontFamilyAndStyle(std::string_
return { std::string(font_name.substr(0, separator)), std::string(font_name.substr(begin)) };
}
/**
* Load a freetype font face with the given font name.
* @param font_name The name of the font to load.
* @param face The face that has been found.
* @return The error we encountered.
*/
FT_Error GetFontByFaceName(std::string_view font_name, FT_Face *face)
{
FT_Error err = FT_Err_Cannot_Open_Resource;
@ -117,7 +123,7 @@ FT_Error GetFontByFaceName(std::string_view font_name, FT_Face *face)
return err;
}
bool SetFallbackFont(FontCacheSettings *settings, const std::string &language_isocode, MissingGlyphSearcher *callback)
bool FontConfigFindFallbackFont(FontCacheSettings *settings, const std::string &language_isocode, MissingGlyphSearcher *callback)
{
bool ret = false;
@ -182,6 +188,6 @@ bool SetFallbackFont(FontCacheSettings *settings, const std::string &language_is
if (best_font == nullptr) return false;
callback->SetFontNames(settings, best_font, &best_index);
InitFontCache(callback->Monospace() ? FontSizes{FS_MONO} : FONTSIZES_REQUIRED);
FontCache::LoadFontCaches(callback->Monospace() ? FontSizes{FS_MONO} : FONTSIZES_REQUIRED);
return true;
}

View File

@ -0,0 +1,26 @@
/*
* This file is part of OpenTTD.
* OpenTTD 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, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file font_unix.h Functions related to detecting/finding the right font. */
#ifndef FONT_UNIX_H
#define FONT_UNIX_H
#ifdef WITH_FONTCONFIG
#include "../../fontcache.h"
#include <ft2build.h>
#include FT_FREETYPE_H
FT_Error GetFontByFaceName(std::string_view font_name, FT_Face *face);
bool FontConfigFindFallbackFont(FontCacheSettings *settings, const std::string &language_isocode, MissingGlyphSearcher *callback);
#endif /* WITH_FONTCONFIG */
#endif /* FONT_UNIX_H */

View File

@ -15,7 +15,6 @@
#include "../../fileio_func.h"
#include "../../fontcache.h"
#include "../../fontcache/truetypefontcache.h"
#include "../../fontdetection.h"
#include "../../library_loader.h"
#include "../../string_func.h"
#include "../../strings_func.h"
@ -85,32 +84,6 @@ static int CALLBACK EnumFontCallback(const ENUMLOGFONTEX *logfont, const NEWTEXT
return 0; // stop enumerating
}
bool SetFallbackFont(FontCacheSettings *settings, const std::string &language_isocode, MissingGlyphSearcher *callback)
{
Debug(fontcache, 1, "Trying fallback fonts");
EFCParam langInfo;
std::wstring lang = OTTD2FS(language_isocode.substr(0, language_isocode.find('_')));
if (GetLocaleInfoEx(lang.c_str(), LOCALE_FONTSIGNATURE, reinterpret_cast<LPWSTR>(&langInfo.locale), sizeof(langInfo.locale) / sizeof(wchar_t)) == 0) {
/* Invalid isocode or some other mysterious error, can't determine fallback font. */
Debug(fontcache, 1, "Can't get locale info for fallback font (isocode={})", language_isocode);
return false;
}
langInfo.settings = settings;
langInfo.callback = callback;
LOGFONT font;
/* Enumerate all fonts. */
font.lfCharSet = DEFAULT_CHARSET;
font.lfFaceName[0] = '\0';
font.lfPitchAndFamily = 0;
HDC dc = GetDC(nullptr);
int ret = EnumFontFamiliesEx(dc, &font, (FONTENUMPROC)&EnumFontCallback, (LPARAM)&langInfo, 0);
ReleaseDC(nullptr, dc);
return ret == 0;
}
/**
* Create a new Win32FontCache.
* @param fs The font size that is going to be cached.
@ -293,6 +266,85 @@ void Win32FontCache::ClearFontCache()
return allow_fallback && key >= SCC_SPRITE_START && key <= SCC_SPRITE_END ? this->parent->MapCharToGlyph(key) : 0;
}
class Win32FontCacheFactory : FontCacheFactory {
public:
Win32FontCacheFactory() : FontCacheFactory("win32", "Win32 font loader") {}
/**
* Loads the GDI font.
* If a GDI font description is present, e.g. from the automatic font
* fallback search, use it. Otherwise, try to resolve it by font name.
* @param fs The font size to load.
*/
std::unique_ptr<FontCache> LoadFont(FontSize fs, FontType fonttype) override
{
if (fonttype != FontType::TrueType) return nullptr;
FontCacheSubSetting *settings = GetFontCacheSubSetting(fs);
std::string font = GetFontCacheFontName(fs);
if (font.empty()) return nullptr;
LOGFONT logfont{};
logfont.lfPitchAndFamily = fs == FS_MONO ? FIXED_PITCH : VARIABLE_PITCH;
logfont.lfCharSet = DEFAULT_CHARSET;
logfont.lfOutPrecision = OUT_OUTLINE_PRECIS;
logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
if (settings->os_handle != nullptr) {
logfont = *(const LOGFONT *)settings->os_handle;
} else if (font.find('.') != std::string::npos) {
/* Might be a font file name, try load it. */
if (!TryLoadFontFromFile(font, logfont)) {
ShowInfo("Unable to load file '{}' for {} font, using default windows font selection instead", font, FontSizeToName(fs));
}
}
if (logfont.lfFaceName[0] == 0) {
logfont.lfWeight = StrContainsIgnoreCase(font, " bold") ? FW_BOLD : FW_NORMAL; // Poor man's way to allow selecting bold fonts.
convert_to_fs(font, logfont.lfFaceName);
}
return LoadWin32Font(fs, logfont, GetFontCacheFontSize(fs), font);
}
bool FindFallbackFont(FontCacheSettings *settings, const std::string &language_isocode, MissingGlyphSearcher *callback) override
{
Debug(fontcache, 1, "Trying fallback fonts");
EFCParam langInfo;
std::wstring lang = OTTD2FS(language_isocode.substr(0, language_isocode.find('_')));
if (GetLocaleInfoEx(lang.c_str(), LOCALE_FONTSIGNATURE, reinterpret_cast<LPWSTR>(&langInfo.locale), sizeof(langInfo.locale) / sizeof(wchar_t)) == 0) {
/* Invalid isocode or some other mysterious error, can't determine fallback font. */
Debug(fontcache, 1, "Can't get locale info for fallback font (isocode={})", language_isocode);
return false;
}
langInfo.settings = settings;
langInfo.callback = callback;
LOGFONT font;
/* Enumerate all fonts. */
font.lfCharSet = DEFAULT_CHARSET;
font.lfFaceName[0] = '\0';
font.lfPitchAndFamily = 0;
HDC dc = GetDC(nullptr);
int ret = EnumFontFamiliesEx(dc, &font, (FONTENUMPROC)&EnumFontCallback, (LPARAM)&langInfo, 0);
ReleaseDC(nullptr, dc);
return ret == 0;
}
private:
static std::unique_ptr<FontCache> LoadWin32Font(FontSize fs, const LOGFONT &logfont, uint size, std::string_view font_name)
{
HFONT font = CreateFontIndirect(&logfont);
if (font == nullptr) {
ShowInfo("Unable to use '{}' for {} font, Win32 reported error 0x{:X}, using sprite font instead", font_name, FontSizeToName(fs), GetLastError());
return nullptr;
}
DeleteObject(font);
return std::make_unique<Win32FontCache>(fs, logfont, size);
}
static bool TryLoadFontFromFile(const std::string &font_name, LOGFONT &logfont)
{
@ -342,50 +394,6 @@ static bool TryLoadFontFromFile(const std::string &font_name, LOGFONT &logfont)
return logfont.lfFaceName[0] != 0;
}
};
static void LoadWin32Font(FontSize fs, const LOGFONT &logfont, uint size, std::string_view font_name)
{
HFONT font = CreateFontIndirect(&logfont);
if (font == nullptr) {
ShowInfo("Unable to use '{}' for {} font, Win32 reported error 0x{:X}, using sprite font instead", font_name, FontSizeToName(fs), GetLastError());
return;
}
DeleteObject(font);
new Win32FontCache(fs, logfont, size);
}
/**
* Loads the GDI font.
* If a GDI font description is present, e.g. from the automatic font
* fallback search, use it. Otherwise, try to resolve it by font name.
* @param fs The font size to load.
*/
void LoadWin32Font(FontSize fs)
{
FontCacheSubSetting *settings = GetFontCacheSubSetting(fs);
std::string font = GetFontCacheFontName(fs);
if (font.empty()) return;
LOGFONT logfont{};
logfont.lfPitchAndFamily = fs == FS_MONO ? FIXED_PITCH : VARIABLE_PITCH;
logfont.lfCharSet = DEFAULT_CHARSET;
logfont.lfOutPrecision = OUT_OUTLINE_PRECIS;
logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
if (settings->os_handle != nullptr) {
logfont = *(const LOGFONT *)settings->os_handle;
} else if (font.find('.') != std::string::npos) {
/* Might be a font file name, try load it. */
if (!TryLoadFontFromFile(font, logfont)) {
ShowInfo("Unable to load file '{}' for {} font, using default windows font selection instead", font, FontSizeToName(fs));
}
}
if (logfont.lfFaceName[0] == 0) {
logfont.lfWeight = StrContainsIgnoreCase(font, " bold") ? FW_BOLD : FW_NORMAL; // Poor man's way to allow selecting bold fonts.
convert_to_fs(font, logfont.lfFaceName);
}
LoadWin32Font(fs, logfont, GetFontCacheFontSize(fs), font);
}
static Win32FontCacheFactory s_win32_fontcache_factory;

View File

@ -1036,8 +1036,8 @@ struct GameOptionsWindow : Window {
this->SetWidgetDisabledState(WID_GO_GUI_FONT_AA, _fcsettings.prefer_sprite);
this->SetDirty();
InitFontCache(FONTSIZES_ALL);
ClearFontCache(FONTSIZES_ALL);
FontCache::LoadFontCaches(FONTSIZES_ALL);
FontCache::ClearFontCaches(FONTSIZES_ALL);
CheckForMissingGlyphs();
SetupWidgetDimensions();
UpdateAllVirtCoords();
@ -1050,7 +1050,7 @@ struct GameOptionsWindow : Window {
this->SetWidgetLoweredState(WID_GO_GUI_FONT_AA, _fcsettings.global_aa);
MarkWholeScreenDirty();
ClearFontCache(FONTSIZES_ALL);
FontCache::ClearFontCaches(FONTSIZES_ALL);
break;
#endif /* HAS_TRUETYPE_FONT */

View File

@ -17,7 +17,6 @@
#include "newgrf_text.h"
#include "fileio_func.h"
#include "signs_base.h"
#include "fontdetection.h"
#include "error.h"
#include "error_func.h"
#include "strings_func.h"
@ -2278,7 +2277,7 @@ std::string_view GetCurrentLanguageIsoCode()
*/
bool MissingGlyphSearcher::FindMissingGlyphs()
{
InitFontCache(this->Monospace() ? FontSizes{FS_MONO} : FONTSIZES_REQUIRED);
FontCache::LoadFontCaches(this->Monospace() ? FontSizes{FS_MONO} : FONTSIZES_REQUIRED);
this->Reset();
for (auto text = this->NextString(); text.has_value(); text = this->NextString()) {
@ -2376,7 +2375,7 @@ void CheckForMissingGlyphs(bool base_font, MissingGlyphSearcher *searcher)
_fcsettings.mono.os_handle = nullptr;
_fcsettings.medium.os_handle = nullptr;
bad_font = !SetFallbackFont(&_fcsettings, _langpack.langpack->isocode, searcher);
bad_font = !FontProviderManager::FindFallbackFont(&_fcsettings, _langpack.langpack->isocode, searcher);
_fcsettings = std::move(backup);
@ -2395,7 +2394,7 @@ void CheckForMissingGlyphs(bool base_font, MissingGlyphSearcher *searcher)
/* Our fallback font does miss characters too, so keep the
* user chosen font as that is more likely to be any good than
* the wild guess we made */
InitFontCache(searcher->Monospace() ? FontSizes{FS_MONO} : FONTSIZES_REQUIRED);
FontCache::LoadFontCaches(searcher->Monospace() ? FontSizes{FS_MONO} : FONTSIZES_REQUIRED);
}
}
#endif

View File

@ -32,7 +32,8 @@ public:
static void InitializeFontCaches()
{
for (FontSize fs = FS_BEGIN; fs != FS_END; fs++) {
if (FontCache::caches[fs] == nullptr) new MockFontCache(fs); /* FontCache inserts itself into to the cache. */
if (FontCache::Get(fs) != nullptr) continue;
FontCache::Register(std::make_unique<MockFontCache>(fs));
}
}
};