Added Font class (+ FreeType loader)
Former-commit-id: 1811304cd0efe9a86cbae83faaf4c39d9fae248f
This commit is contained in:
@@ -218,6 +218,27 @@ enum nzPrimitiveMode
|
||||
nzPrimitiveMode_Max = nzPrimitiveMode_TriangleFan
|
||||
};
|
||||
|
||||
enum nzTextAlign
|
||||
{
|
||||
nzTextAlign_Left,
|
||||
nzTextAlign_Middle,
|
||||
nzTextAlign_Right,
|
||||
|
||||
nzTextAlign_Max = nzTextAlign_Right
|
||||
};
|
||||
|
||||
enum nzTextStyleFlags
|
||||
{
|
||||
nzTextStyle_None = 0x0,
|
||||
|
||||
nzTextStyle_Bold = 0x1,
|
||||
nzTextStyle_Italic = 0x2,
|
||||
nzTextStyle_StrikeThrough = 0x4,
|
||||
nzTextStyle_Underlined = 0x8,
|
||||
|
||||
nzTextStyle_Max = nzTextStyle_Underlined*2-1
|
||||
};
|
||||
|
||||
enum nzVertexComponent
|
||||
{
|
||||
nzVertexComponent_Unused = -1,
|
||||
|
||||
133
include/Nazara/Utility/Font.hpp
Normal file
133
include/Nazara/Utility/Font.hpp
Normal file
@@ -0,0 +1,133 @@
|
||||
// Copyright (C) 2014 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Utility module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_FONT_HPP
|
||||
#define NAZARA_FONT_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/GuillotineBinPack.hpp>
|
||||
#include <Nazara/Core/NonCopyable.hpp>
|
||||
#include <Nazara/Core/ResourceRef.hpp>
|
||||
#include <Nazara/Core/ResourceLoader.hpp>
|
||||
#include <Nazara/Utility/Image.hpp>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
|
||||
struct NAZARA_API NzFontParams
|
||||
{
|
||||
bool IsValid() const;
|
||||
};
|
||||
|
||||
class NzFont;
|
||||
class NzFontData;
|
||||
|
||||
struct NzFontGlyph; // TEMP
|
||||
|
||||
using NzFontConstRef = NzResourceRef<const NzFont>;
|
||||
using NzFontLoader = NzResourceLoader<NzFont, NzFontParams>;
|
||||
using NzFontRef = NzResourceRef<NzFont>;
|
||||
|
||||
class NAZARA_API NzFont : public NzResource, NzNonCopyable
|
||||
{
|
||||
friend NzFontLoader;
|
||||
|
||||
public:
|
||||
struct Atlas
|
||||
{
|
||||
NzGuillotineBinPack binPack;
|
||||
NzImage image;
|
||||
};
|
||||
|
||||
struct Glyph
|
||||
{
|
||||
NzRecti aabb;
|
||||
NzRectui atlasRect;
|
||||
bool flipped;
|
||||
bool valid;
|
||||
int advance;
|
||||
unsigned int atlasIndex;
|
||||
};
|
||||
|
||||
struct SizeInfo
|
||||
{
|
||||
unsigned int lineHeight;
|
||||
float underlinePosition;
|
||||
float underlineThickness;
|
||||
};
|
||||
|
||||
NzFont();
|
||||
NzFont(NzFont&& font) = default;
|
||||
~NzFont();
|
||||
|
||||
void ClearGlyphCache();
|
||||
void ClearKerningCache();
|
||||
void ClearSizeInfoCache();
|
||||
|
||||
bool Create(NzFontData* data);
|
||||
void Destroy();
|
||||
|
||||
bool ExtractGlyph(unsigned int characterSize, char32_t character, nzUInt32 style, NzFontGlyph* glyph) const;
|
||||
|
||||
const Atlas& GetAtlas(unsigned int atlasIndex) const;
|
||||
unsigned int GetAtlasCount() const;
|
||||
unsigned int GetCachedGlyphCount(unsigned int characterSize, nzUInt32 style) const;
|
||||
unsigned int GetCachedGlyphCount() const;
|
||||
NzString GetFamilyName() const;
|
||||
int GetKerning(unsigned int characterSize, char32_t first, char32_t second) const;
|
||||
const Glyph& GetGlyph(unsigned int characterSize, nzUInt32 style, char32_t character) const;
|
||||
unsigned int GetMaxAtlasSize() const;
|
||||
unsigned int GetMinimumStepSize() const;
|
||||
const SizeInfo& GetSizeInfo(unsigned int characterSize) const;
|
||||
NzString GetStyleName() const;
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
bool Precache(unsigned int characterSize, nzUInt32 style, char32_t character) const;
|
||||
bool Precache(unsigned int characterSize, nzUInt32 style, const NzString& characterSet) const;
|
||||
|
||||
// Open
|
||||
bool OpenFromFile(const NzString& filePath, const NzFontParams& params = NzFontParams());
|
||||
bool OpenFromMemory(const void* data, std::size_t size, const NzFontParams& params = NzFontParams());
|
||||
bool OpenFromStream(NzInputStream& stream, const NzFontParams& params = NzFontParams());
|
||||
|
||||
void SetMaxAtlasSize(unsigned int maxAtlasSize);
|
||||
void SetMinimumStepSize(unsigned int minimumSizeStep);
|
||||
|
||||
NzFont& operator=(NzFont&& font) = default;
|
||||
|
||||
static unsigned int GetDefaultMaxAtlasSize();
|
||||
static void SetDefaultMaxAtlasSize(unsigned int maxAtlasSize);
|
||||
|
||||
private:
|
||||
using GlyphMap = std::unordered_map<char32_t, Glyph>;
|
||||
|
||||
struct QueuedGlyph
|
||||
{
|
||||
char32_t codepoint;
|
||||
NzImage image;
|
||||
GlyphMap* map;
|
||||
};
|
||||
|
||||
nzUInt64 ComputeKey(unsigned int characterSize, nzUInt32 style) const;
|
||||
unsigned int GetRealMaxAtlasSize() const;
|
||||
unsigned int InsertRect(NzRectui* rect, bool* flipped) const;
|
||||
const Glyph& PrecacheGlyph(GlyphMap& glyphMap, unsigned int characterSize, bool bold, char32_t character) const;
|
||||
void ProcessGlyphQueue() const;
|
||||
|
||||
std::unique_ptr<NzFontData> m_data;
|
||||
mutable std::unordered_map<nzUInt64, std::unordered_map<nzUInt64, int>> m_kerningCache;
|
||||
mutable std::unordered_map<nzUInt64, GlyphMap> m_glyphes;
|
||||
mutable std::unordered_map<nzUInt64, SizeInfo> m_sizeInfoCache;
|
||||
mutable std::vector<Atlas> m_atlases;
|
||||
mutable std::vector<QueuedGlyph> m_glyphQueue;
|
||||
unsigned int m_maxAtlasSize;
|
||||
unsigned int m_minimumSizeStep;
|
||||
|
||||
static NzFontLoader::LoaderList s_loaders;
|
||||
static unsigned int s_maxAtlasSize;
|
||||
};
|
||||
|
||||
#endif // NAZARA_FONT_HPP
|
||||
36
include/Nazara/Utility/FontData.hpp
Normal file
36
include/Nazara/Utility/FontData.hpp
Normal file
@@ -0,0 +1,36 @@
|
||||
// Copyright (C) 2014 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Utility module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_FONTDATA_HPP
|
||||
#define NAZARA_FONTDATA_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
|
||||
struct NzFontGlyph;
|
||||
|
||||
class NAZARA_API NzFontData
|
||||
{
|
||||
public:
|
||||
NzFontData() = default;
|
||||
virtual ~NzFontData();
|
||||
|
||||
virtual bool ExtractGlyph(unsigned int characterSize, char32_t character, bool bold, NzFontGlyph* dst) = 0;
|
||||
|
||||
virtual NzString GetFamilyName() const = 0;
|
||||
virtual NzString GetStyleName() const = 0;
|
||||
|
||||
virtual bool HasKerning() const = 0;
|
||||
|
||||
virtual bool IsScalable() const = 0;
|
||||
|
||||
virtual int QueryKerning(unsigned int characterSize, char32_t first, char32_t second) const = 0;
|
||||
virtual unsigned int QueryLineHeight(unsigned int characterSize) const = 0;
|
||||
virtual float QueryUnderlinePosition(unsigned int characterSize) const = 0;
|
||||
virtual float QueryUnderlineThickness(unsigned int characterSize) const = 0;
|
||||
};
|
||||
|
||||
#endif // NAZARA_FONTDATA_HPP
|
||||
19
include/Nazara/Utility/FontGlyph.hpp
Normal file
19
include/Nazara/Utility/FontGlyph.hpp
Normal file
@@ -0,0 +1,19 @@
|
||||
// Copyright (C) 2014 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Utility module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_FONTGLYPH_HPP
|
||||
#define NAZARA_FONTGLYPH_HPP
|
||||
|
||||
#include <Nazara/Utility/Image.hpp>
|
||||
|
||||
struct NzFontGlyph
|
||||
{
|
||||
NzImage image;
|
||||
NzRecti aabb;
|
||||
int advance;
|
||||
};
|
||||
|
||||
#endif // NAZARA_FONTGLYPH_HPP
|
||||
Reference in New Issue
Block a user