Skip to content

Commit

Permalink
Add getDeviceData and getBlock methods to Typeface
Browse files Browse the repository at this point in the history
  • Loading branch information
mikee47 committed Dec 27, 2024
1 parent 9446ca7 commit 13c0d22
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Asset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,14 @@ class ResourceGlyph : public GlyphObject

/* ResourceTypeface */

GlyphBlock ResourceTypeface::getBlock(unsigned index) const
{
if(index < FSTR::readValue(&typeface.numBlocks)) {
return FSTR::readValue(&typeface.blocks[index]);
}
return GlyphBlock{};
}

bool ResourceTypeface::findGlyph(uint16_t codePoint, Resource::GlyphResource& glyph) const
{
auto glyphPtr = typeface.glyphs;
Expand Down
20 changes: 20 additions & 0 deletions src/include/Graphics/Asset.h
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ class TextOptions : public Meta
}
};

using GlyphBlock = Resource::GlyphBlock;
using GlyphOptions = TextOptions;

/**
Expand All @@ -522,6 +523,23 @@ class TypeFace : public AssetTemplate<AssetType::Typeface>
public:
using AssetTemplate::AssetTemplate;

/**
* @brief Return any device-specific information
*
* Controllers with internal fonts return private structures here to support rendering.
*/
virtual const void* getDeviceData() const
{
return nullptr;
}

/**
* @brief Support enumeration of codepoint ranges
* @param index Zero-based index of glyph block to return
* @retval GlyphBlock
*/
virtual GlyphBlock getBlock(unsigned index) const = 0;

/**
* @brief Style of this typeface (bold, italic, etc.)
*/
Expand Down Expand Up @@ -613,6 +631,8 @@ class ResourceTypeface : public Graphics::TypeFace
{
}

GlyphBlock getBlock(unsigned index) const override;

FontStyles getStyle() const override
{
Resource::TypefaceResource::Format format{
Expand Down
8 changes: 8 additions & 0 deletions src/include/Graphics/LcdFont.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ class LcdGlyph : public GlyphObject
class LcdTypeFace : public TypeFace
{
public:
GlyphBlock getBlock(unsigned index) const override
{
if(index == 0) {
return GlyphBlock{0, 255};
}
return GlyphBlock{};
}

FontStyles getStyle() const override
{
return 0;
Expand Down

0 comments on commit 13c0d22

Please sign in to comment.