Sparkle 0.0.1
Loading...
Searching...
No Matches
spk::Font::Bitmap Class Reference

Font atlas texture and glyph metadata for a specific size. More...

#include <spk_font.hpp>

Inheritance diagram for spk::Font::Bitmap:
Inheritance graph
Collaboration diagram for spk::Font::Bitmap:
Collaboration graph

Classes

struct  Glyph
 Glyph quad data and layout metrics. More...

Public Types

using Format = spk::OpenGL::TextureObject::Format
 Texture format type for the bitmap.
using Filtering = spk::OpenGL::TextureObject::Filtering
 Texture filtering type for the bitmap.
using Filter = spk::OpenGL::TextureObject::Filter
 Texture filter type for the bitmap.
using Wrap = spk::OpenGL::TextureObject::Wrap
 Texture wrap type for the bitmap.
using Wrapper = spk::OpenGL::TextureObject::Wrapper
 Texture wrapper type for the bitmap.
using Mipmap = spk::OpenGL::TextureObject::Mipmap
 Texture mipmap type for the bitmap.
using EditionContract = spk::ContractProvider::Contract
 Contract type returned by edition subscriptions.
using EditionJob = spk::ContractProvider::Job
 Job type invoked on bitmap edits.
Public Types inherited from spk::OpenGL::TextureObject
enum class  Format : GLenum {
  RGB = GL_RGB , RGBA = GL_RGBA , BGR = GL_BGR , BGRA = GL_BGRA ,
  GreyLevel = GL_RED , DualChannel = GL_RG , DepthComponent = GL_DEPTH_COMPONENT , DepthStencil = GL_DEPTH_STENCIL ,
  Error = GL_NONE
}
 Supported GPU pixel formats.
enum class  Filtering : GLenum { Nearest = GL_NEAREST , Linear = GL_LINEAR }
 Texture sampling algorithms for minification/magnification.
enum class  Wrap : GLenum { Repeat = GL_REPEAT , ClampToEdge = GL_CLAMP_TO_EDGE , ClampToBorder = GL_CLAMP_TO_BORDER }
 Texture coordinate wrapping strategies.
using Mipmap = spk::ActivationStatus
 Indicates whether mipmaps are active.
Public Types inherited from spk::ActivableObject
using Contract = StatefulObject<ActivationStatus>::Contract
 Subscription handle controlling callback lifetime.
using Job = StatefulObject<ActivationStatus>::Job
 Callback signature executed on activation state changes.
Public Types inherited from spk::StatefulObject< ActivationStatus >
using Contract
 Handle allowing subscribers to manage callback lifetimes.
using Job
 Callable invoked when the object transitions to a state.

Public Member Functions

 Bitmap (const stbtt_fontinfo *p_fontInfo, const Size &p_fontSize)
 Builds a bitmap atlas for a font size.
EditionContract subscribeToEdition (const EditionJob &p_job)
 Subscribes to bitmap edition notifications.
const Glyphoperator[] (const wchar_t &p_glyphChar)
 Returns glyph data for the requested codepoint.
int lineHeight () const
 Returns the line height for this font size.
int kerning (const wchar_t p_previous, const wchar_t p_current) const
 Returns kerning adjustment between two glyphs.
void preloadGlyphs (const std::wstring &p_glyphs)
 Preloads glyphs into the bitmap atlas.
Public Member Functions inherited from spk::OpenGL::TextureObject
 TextureObject (Format p_format=Format::RGBA, Filter p_filter={Filtering::Linear, Filtering::Linear}, Wrapper p_wrapper={Wrap::Repeat, Wrap::Repeat}, Mipmap p_mipmap=Mipmap::Activated)
 Constructs a texture with format, filtering, and wrapping options.
 TextureObject (const TextureObject &p_other)
 Copy-constructs a texture object including CPU-side data.
TextureObjectoperator= (const TextureObject &p_other)
 Copy-assigns a texture object including CPU-side data.
 TextureObject (TextureObject &&p_other) noexcept
 Move-constructs a texture object transferring ownership.
TextureObjectoperator= (TextureObject &&p_other) noexcept
 Move-assigns a texture object transferring ownership.
void activate () const
 Activates this texture for rendering.
void deactivate () const
 Deactivates this texture after rendering.
Format format () const
 Gets the current texture format.
Filter filter () const
 Gets filtering parameters.
Wrapper wrapper () const
 Gets wrapping parameters.
Mipmap mipmap () const
 Gets mipmap activation state.
void setFormat (Format p_format)
 Sets the texture format (affects upload interpretation).
void setFiltering (Filter p_filter)
 Sets min/mag filtering together.
void setFiltering (Filtering p_minFilter, Filtering p_magFilter)
 Sets minification and magnification filters independently.
void setWrap (Wrapper p_wrapper)
 Sets wrapping for both axes.
void setWrap (Wrap p_wrapS, Wrap p_wrapT)
 Sets wrapping for each axis independently.
void setMipmap (Mipmap p_mipmap)
 Sets mipmap activation state.
spk::Vector2UInt size () const
 Returns texture dimensions.
size_t sizeAsBytes () const
 Returns CPU data size in bytes.
GLuint id () const
 Returns GL texture id, creating if needed.
void setData (const uint8_t *p_data, const spk::Vector2UInt &p_size, Format p_format=Format::RGBA)
 Uploads pixel data from raw pointer.
void setData (std::vector< uint8_t > p_data, const spk::Vector2UInt &p_size, Format p_format=Format::RGBA)
 Uploads pixel data by move.
void clearData ()
 Clears CPU data and marks for sync.
void resize (const spk::Vector2UInt &p_size)
 Resizes CPU data and marks for sync.
std::vector< uint8_t > & data ()
 Gets CPU-side pixel data.
const std::vector< uint8_t > & data () const
 Gets CPU-side pixel data.
void flip (const spk::Orientation &p_orientation)
 Flips stored pixel data along the given orientation.
void activate ()
 Sets the state to Activated.
void deactivate ()
 Sets the state to Deactivated.
Public Member Functions inherited from spk::ActivableObject
 ActivableObject ()
 Builds a deactivated object.
 ActivableObject (ActivationStatus p_initial)
 Builds with a custom initial activation state.
void activate ()
 Sets the state to Activated.
void deactivate ()
 Sets the state to Deactivated.
void toggle ()
 Toggles between activated and deactivated states.
bool isActive () const
 Checks whether the object is currently activated.
Contract addActivationCallback (const Job &p_callback)
 Registers a callback executed when the object activates.
Contract addDeactivationCallback (const Job &p_callback)
 Registers a callback executed when the object deactivates.
Public Member Functions inherited from spk::StatefulObject< ActivationStatus >
 StatefulObject (const ActivationStatus &p_initialState)
 Builds with an initial state.
StatefulObjectoperator= (const StatefulObject &p_other)=delete
void setState (const ActivationStatus &p_newState)
 Sets a new state and triggers callbacks registered for it.
ActivationStatus state () const
 Returns the current state.
Contract addCallback (const ActivationStatus &p_state, const Job &p_callback)
 Subscribes a callback for a specific state.
Public Member Functions inherited from spk::SynchronizableObject
void requestSynchronization () noexcept
 Marks the object as needing synchronization.
bool needsSynchronization () const noexcept
 Checks if synchronization is pending.
void synchronize ()
 Performs synchronization if requested.
void forceSynchronization ()
 Forces synchronization regardless of current flag.

Additional Inherited Members

Protected Member Functions inherited from spk::OpenGL::TextureObject
void _onSynchronize () override
 Synchronizes CPU-side data with the GPU texture.

Detailed Description

Font atlas texture and glyph metadata for a specific size.

Constructor & Destructor Documentation

◆ Bitmap()

spk::Font::Bitmap::Bitmap ( const stbtt_fontinfo * p_fontInfo,
const Size & p_fontSize )

Builds a bitmap atlas for a font size.

Parameters
p_fontInfoFont info pointer.
p_fontSizeSize of glyphs and outline.
Here is the call graph for this function:

Member Function Documentation

◆ kerning()

int spk::Font::Bitmap::kerning ( const wchar_t p_previous,
const wchar_t p_current ) const

Returns kerning adjustment between two glyphs.

Parameters
p_previousPrevious glyph codepoint.
p_currentCurrent glyph codepoint.
Returns
Kerning adjustment in pixels.

◆ lineHeight()

int spk::Font::Bitmap::lineHeight ( ) const

Returns the line height for this font size.

Returns
Line height in pixels.

◆ operator[]()

const Font::Bitmap::Glyph & spk::Font::Bitmap::operator[] ( const wchar_t & p_glyphChar)

Returns glyph data for the requested codepoint.

Parameters
p_glyphCharCharacter to fetch.
Returns
Glyph data.
Here is the caller graph for this function:

◆ preloadGlyphs()

void spk::Font::Bitmap::preloadGlyphs ( const std::wstring & p_glyphs)

Preloads glyphs into the bitmap atlas.

Parameters
p_glyphsGlyph characters to load.

◆ subscribeToEdition()

Font::Bitmap::EditionContract spk::Font::Bitmap::subscribeToEdition ( const EditionJob & p_job)

Subscribes to bitmap edition notifications.

Parameters
p_jobCallback executed on edits.
Returns
Contract handle for the subscription.

The documentation for this class was generated from the following files:
  • includes/structure/graphics/spk_font.hpp
  • srcs/structure/graphics/spk_font.cpp