Add text outlines!
This commit is contained in:
@@ -44,6 +44,7 @@ namespace Nz
|
||||
Vector2f corners[4];
|
||||
AbstractImage* atlas;
|
||||
bool flipped;
|
||||
int renderOrder;
|
||||
};
|
||||
|
||||
struct Line
|
||||
|
||||
@@ -59,14 +59,14 @@ namespace Nz
|
||||
bool Create(FontData* data);
|
||||
void Destroy();
|
||||
|
||||
bool ExtractGlyph(unsigned int characterSize, char32_t character, TextStyleFlags style, FontGlyph* glyph) const;
|
||||
bool ExtractGlyph(unsigned int characterSize, char32_t character, TextStyleFlags style, float outlineThickness, FontGlyph* glyph) const;
|
||||
|
||||
const std::shared_ptr<AbstractAtlas>& GetAtlas() const;
|
||||
std::size_t GetCachedGlyphCount(unsigned int characterSize, TextStyleFlags style) const;
|
||||
std::size_t GetCachedGlyphCount(unsigned int characterSize, TextStyleFlags style, float outlineThickness) const;
|
||||
std::size_t GetCachedGlyphCount() const;
|
||||
String GetFamilyName() const;
|
||||
int GetKerning(unsigned int characterSize, char32_t first, char32_t second) const;
|
||||
const Glyph& GetGlyph(unsigned int characterSize, TextStyleFlags style, char32_t character) const;
|
||||
const Glyph& GetGlyph(unsigned int characterSize, TextStyleFlags style, float outlineThickness, char32_t character) const;
|
||||
unsigned int GetGlyphBorder() const;
|
||||
unsigned int GetMinimumStepSize() const;
|
||||
const SizeInfo& GetSizeInfo(unsigned int characterSize) const;
|
||||
@@ -74,8 +74,8 @@ namespace Nz
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
bool Precache(unsigned int characterSize, TextStyleFlags style, char32_t character) const;
|
||||
bool Precache(unsigned int characterSize, TextStyleFlags style, const String& characterSet) const;
|
||||
bool Precache(unsigned int characterSize, TextStyleFlags style, float outlineThickness, char32_t character) const;
|
||||
bool Precache(unsigned int characterSize, TextStyleFlags style, float outlineThickness, const String& characterSet) const;
|
||||
|
||||
void SetAtlas(const std::shared_ptr<AbstractAtlas>& atlas);
|
||||
void SetGlyphBorder(unsigned int borderSize);
|
||||
@@ -107,6 +107,7 @@ namespace Nz
|
||||
bool requireFauxItalic;
|
||||
bool flipped;
|
||||
bool valid;
|
||||
float fauxOutlineThickness;
|
||||
int advance;
|
||||
unsigned int layerIndex;
|
||||
};
|
||||
@@ -131,11 +132,11 @@ namespace Nz
|
||||
private:
|
||||
using GlyphMap = std::unordered_map<char32_t, Glyph>;
|
||||
|
||||
UInt64 ComputeKey(unsigned int characterSize, TextStyleFlags style) const;
|
||||
UInt64 ComputeKey(unsigned int characterSize, TextStyleFlags style, float outlineThickness) const;
|
||||
void OnAtlasCleared(const AbstractAtlas* atlas);
|
||||
void OnAtlasLayerChange(const AbstractAtlas* atlas, AbstractImage* oldLayer, AbstractImage* newLayer);
|
||||
void OnAtlasRelease(const AbstractAtlas* atlas);
|
||||
const Glyph& PrecacheGlyph(GlyphMap& glyphMap, unsigned int characterSize, TextStyleFlags style, char32_t character) const;
|
||||
const Glyph& PrecacheGlyph(GlyphMap& glyphMap, unsigned int characterSize, TextStyleFlags style, float outlineThickness, char32_t character) const;
|
||||
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Nz
|
||||
FontData() = default;
|
||||
virtual ~FontData();
|
||||
|
||||
virtual bool ExtractGlyph(unsigned int characterSize, char32_t character, TextStyleFlags style, FontGlyph* dst) = 0;
|
||||
virtual bool ExtractGlyph(unsigned int characterSize, char32_t character, TextStyleFlags style, float outlineThickness, FontGlyph* dst) = 0;
|
||||
|
||||
virtual String GetFamilyName() const = 0;
|
||||
virtual String GetStyleName() const = 0;
|
||||
@@ -36,6 +36,7 @@ namespace Nz
|
||||
virtual float QueryUnderlinePosition(unsigned int characterSize) const = 0;
|
||||
virtual float QueryUnderlineThickness(unsigned int characterSize) const = 0;
|
||||
|
||||
virtual bool SupportsOutline(float outlineThickness) const = 0;
|
||||
virtual bool SupportsStyle(TextStyleFlags style) const = 0;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -38,12 +38,16 @@ namespace Nz
|
||||
std::size_t GetGlyphCount() const override;
|
||||
const Line& GetLine(std::size_t index) const override;
|
||||
std::size_t GetLineCount() const override;
|
||||
const Color& GetOutlineColor() const;
|
||||
float GetOutlineThickness() const;
|
||||
TextStyleFlags GetStyle() const;
|
||||
const String& GetText() const;
|
||||
|
||||
void SetCharacterSize(unsigned int characterSize);
|
||||
void SetColor(const Color& color);
|
||||
void SetFont(Font* font);
|
||||
void SetOutlineColor(const Color& color);
|
||||
void SetOutlineThickness(float thickness);
|
||||
void SetStyle(TextStyleFlags style);
|
||||
void SetText(const String& str);
|
||||
|
||||
@@ -51,7 +55,9 @@ namespace Nz
|
||||
SimpleTextDrawer& operator=(SimpleTextDrawer&& drawer);
|
||||
|
||||
static SimpleTextDrawer Draw(const String& str, unsigned int characterSize, TextStyleFlags style = TextStyle_Regular, const Color& color = Color::White);
|
||||
static SimpleTextDrawer Draw(const String& str, unsigned int characterSize, TextStyleFlags style, const Color& color, float outlineThickness, const Color& outlineColor);
|
||||
static SimpleTextDrawer Draw(Font* font, const String& str, unsigned int characterSize, TextStyleFlags style = TextStyle_Regular, const Color& color = Color::White);
|
||||
static SimpleTextDrawer Draw(Font* font, const String& str, unsigned int characterSize, TextStyleFlags style, const Color& color, float outlineThickness, const Color& outlineColor);
|
||||
|
||||
private:
|
||||
void ClearGlyphs() const;
|
||||
@@ -72,6 +78,7 @@ namespace Nz
|
||||
mutable std::vector<Glyph> m_glyphs;
|
||||
mutable std::vector<Line> m_lines;
|
||||
Color m_color;
|
||||
Color m_outlineColor;
|
||||
FontRef m_font;
|
||||
mutable Rectf m_workingBounds;
|
||||
mutable Recti m_bounds;
|
||||
@@ -81,6 +88,7 @@ namespace Nz
|
||||
mutable Vector2ui m_drawPos;
|
||||
mutable bool m_colorUpdated;
|
||||
mutable bool m_glyphUpdated;
|
||||
float m_outlineThickness;
|
||||
unsigned int m_characterSize;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user