forked from mirrors/0ad
Fixes CC for fonts.
This commit is contained in:
@@ -369,7 +369,7 @@ const CFont::GlyphData* CFont::ExtractAndGenerateGlyph(u16 codepoint)
|
||||
}
|
||||
|
||||
m_IsDirty = true;
|
||||
CVector2D offset{0,0};
|
||||
CVector2D offset{0.0f, 0.0f};
|
||||
|
||||
const FT_Render_Mode renderMode{FT_RENDER_MODE_NORMAL};
|
||||
|
||||
@@ -536,7 +536,7 @@ void CFont::BlendGlyphBitmapToTextureRGBA(const FT_Bitmap& bitmap, int targetX,
|
||||
u8* tempDstRow{dstRow + x * m_TextureFormatStride};
|
||||
u8 alpha{srcRow[x]};
|
||||
|
||||
const float srcAlpha{m_StrokeWidth > 0 ? (*m_GammaCorrectionLUT)[alpha] : alpha/255.0f};
|
||||
const float srcAlpha{m_StrokeWidth > 0 ? m_GammaCorrectionLUT[alpha] : alpha/255.0f};
|
||||
const float dstAlpha{tempDstRow[3] / 255.0f};
|
||||
const float outAlpha{srcAlpha + dstAlpha * (1.0f - srcAlpha)};
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace Renderer::Backend::Sampler { struct Desc; }
|
||||
class CFont
|
||||
{
|
||||
public:
|
||||
CFont(FT_Library library, std::shared_ptr<std::array<float, 256>> gammaCorrection) : m_FreeType{library}, m_GammaCorrectionLUT{gammaCorrection} {};
|
||||
CFont(FT_Library library, const std::array<float, 256>& gammaCorrection) : m_FreeType{library}, m_GammaCorrectionLUT{gammaCorrection} {}
|
||||
~CFont() = default;
|
||||
NONCOPYABLE(CFont);
|
||||
|
||||
@@ -112,11 +112,15 @@ public:
|
||||
CTexturePtr GetTexture() const { return m_Texture; }
|
||||
void UploadTextureAtlasToGPU();
|
||||
const GlyphData* GetGlyph(u16 i);
|
||||
|
||||
private:
|
||||
static void ftFaceDeleter(FT_Face face) {
|
||||
static void ftFaceDeleter(FT_Face face)
|
||||
{
|
||||
FT_Done_Face(face);
|
||||
}
|
||||
static void ftStrokerDeleter(FT_Stroker stroker) {
|
||||
|
||||
static void ftStrokerDeleter(FT_Stroker stroker)
|
||||
{
|
||||
FT_Stroker_Done(stroker);
|
||||
}
|
||||
|
||||
@@ -173,7 +177,7 @@ private:
|
||||
|
||||
float m_FontSize{0.0f};
|
||||
std::string m_FontName;
|
||||
std::shared_ptr<std::array<float, 256>> m_GammaCorrectionLUT{nullptr};
|
||||
const std::array<float, 256>& m_GammaCorrectionLUT;
|
||||
|
||||
FT_Library m_FreeType;
|
||||
std::vector<std::shared_ptr<u8>> m_FontsData;
|
||||
|
||||
@@ -43,8 +43,11 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
struct FontSpec {
|
||||
namespace
|
||||
{
|
||||
|
||||
struct FontSpec
|
||||
{
|
||||
std::string type;
|
||||
bool bold{false};
|
||||
bool italic{false};
|
||||
@@ -103,7 +106,7 @@ CFontManager::CFontManager()
|
||||
throw std::runtime_error{"Failed to initialize FreeType " + std::to_string(error)};
|
||||
m_FreeType.reset(lib);
|
||||
|
||||
m_GammaCorrectionLUT = std::make_shared<std::array<float, 256>>();
|
||||
m_GammaCorrectionLUT = std::make_unique<std::array<float, 256>>();
|
||||
|
||||
std::generate(m_GammaCorrectionLUT->begin(), m_GammaCorrectionLUT->end(), [i = 0]() mutable {
|
||||
return std::pow((i++) / 255.0f, 1.0f / GAMMA_CORRECTION);
|
||||
@@ -189,7 +192,7 @@ std::shared_ptr<CFont> CFontManager::LoadFont(CStrIntern fontName, CStrIntern lo
|
||||
}()
|
||||
};
|
||||
|
||||
std::shared_ptr<CFont> font{std::make_shared<CFont>(this->m_FreeType.get(), m_GammaCorrectionLUT)};
|
||||
std::shared_ptr<CFont> font{std::make_shared<CFont>(this->m_FreeType.get(), *m_GammaCorrectionLUT)};
|
||||
|
||||
if (!font->SetFontParams(localeFontName.string(), fontSpec.size, fontSpec.stroke ? 1.0f : 0.0f, guiScale))
|
||||
{
|
||||
|
||||
@@ -44,12 +44,14 @@ public:
|
||||
void UploadTexturesAtlasToGPU();
|
||||
|
||||
private:
|
||||
static void ftLibraryDeleter(FT_Library library) {
|
||||
static void ftLibraryDeleter(FT_Library library)
|
||||
{
|
||||
FT_Done_FreeType(library);
|
||||
}
|
||||
|
||||
std::unique_ptr<FT_LibraryRec_, decltype(&ftLibraryDeleter)> m_FreeType{nullptr, &ftLibraryDeleter};
|
||||
|
||||
std::shared_ptr<std::array<float,256>> m_GammaCorrectionLUT;
|
||||
std::unique_ptr<std::array<float, 256>> m_GammaCorrectionLUT;
|
||||
|
||||
using FontsMap = std::unordered_map<CStrIntern, std::shared_ptr<CFont>>;
|
||||
FontsMap m_Fonts;
|
||||
|
||||
Reference in New Issue
Block a user