cohtml::System

A System owns multiple Views. These Views share resources among them. It is usually enough to have just one System per application run. All System APIs, unless explicitly stated otherwise, can be called on any thread, but should not be used on multiple threads simultaneously.

#include <System.h>

Public Functions

Name
virtual unsignedGetId() =0
virtual voidSetId(unsigned id) =0
virtual~System()
virtual View *CreateView(const ViewSettings & settings) =0
Creates a new View with the specified options.
virtual SystemCacheStats *GetSystemCacheStats() const =0
Returns an objects that holds the current statistics of the system-wide caches. Remember to Release when done.
virtual voidClearCachedUnusedImages() =0
Removes all unused images (raster and svg) from internal caches.
virtual SystemRenderer *CreateSystemRenderer(const SystemRendererSettings & settings) =0
Creates a new SystemRenderer. The SystemRenderer will hold rendering resources shared by all view renderers. Can be used on any thread.
virtual SystemRenderer *CreateSystemRendererWithExternalRenderingLibrary(const SystemRendererSettingsWithExternalRenderingLibrary & settings) =0
Creates a new SystemRenderer. The SystemRenderer will hold rendering resources shared by all view renderers. Can be used on any thread.
virtual voidAddFontsFromFolder_DEPRECATED(const char * path) =0
Loads all fonts from the specified folder. The fonts can later be used in the Views Prefer using the RegisterFont API for better control over the loaded fonts.
virtual voidRegisterFont(const char * url, const FontDescription & desc =FontDescription(), Fonts::FontSDF useSDF =Fonts::SDF_Auto) =0
Registers a font that can be later used in the Views. This API is similar to a font-face rule and allows you to prepare font stream readers in advance, so that text can render without delays. Unlike the font-face rule, this API also allows you to load the font with its original description (using ‘Auto’ for weight or/and style with or without specifying specific family name for it). This API will load all available fonts from font collections (ttc, otc) when a specific font description isn’t provided (use ‘Auto’ without family name). If any description is specified for a font collection, only the first font will be loaded under that description (same behavior as a font-face rule with font collection).
virtual boolUnregisterFont(const char * url) =0
Unregisters all registered fonts by the RegisterFont API for a specific font resource identified by the URL. Font resources are shared between the system and the views, so the font resource may not be freed if there are active at font-face rules using the same URL. Since the font resource is required for rendering, fonts will be freed after all pending frames are painted.
virtual voidAddUserFont(const char ** imagesData, unsigned * imagesDataSize, unsigned imagesCount, const UserFontDescription & description) =0
Load the user font using image files.
virtual voidAddUserFont(const IAsyncResourceResponse::UserImageData * userImages, unsigned imagesCount, const UserFontDescription & description) =0
Load the user font using preloaded images.
virtual boolRemoveUserFont(const UserFontDescription & description) =0
Unregisters the bitmap font which has been registered by the user.
virtual voidSetDefaultFallbackFontName_DEPRECATED(const char * name) =0
Loads font with given name from folders specified by AddFontsFromFolder. This font will be used when the another font cannot be loaded or found as a default one. This font is a fallback if the font name used in a Style property is not found. If you want to change the default font that will be applied to all elements, you should change the value in LibraryParams::DefaultStyleFontFamily.
virtual voidDestroy() =0
Destroys the System.
virtual voidAdvance(TimePoint timeMilliseconds) =0
Advances the internal timers and inspector when available.
virtual voidRegisterGamepad(unsigned id, const char * info, unsigned axesCount, unsigned buttonsCount, void * reserved =nullptr) =0
Registers a new gamepad. All views will receive the gamepadconnected event. You can provide any number of axes and buttons though the standard mapping according to the HTML spec has 4 axes and 17 buttons which can be found here https://w3c.github.io/gamepad/#remapping.
virtual voidUnregisterGamepad(unsigned id) =0
Unregisters a gamepad. All views will receive the gamepaddisconnected event.
virtual voidUpdateGamepadState(const cohtml::GamepadState & state) =0
Updates the state of a single gamepad.
virtual voidUpdateGamepadStateExtended(const cohtml::GamepadStateExtended & state) =0
Updates the state of a single gamepad with motion tracking information.
virtual voidUserImagesChanged(const unsigned * images, unsigned count) =0
Trigger repaint of a user provided texture. Call this whenever the image is changed by logic external to the library. Make sure to have ImageHandle set for such images.
virtual voidPreloadAndCacheStylesheet(const char * url) =0
Schedules a preload task for a given stylesheet and caches it upon successful parsing.
virtual boolRemoveStylesheetCacheEntry(const char * url) =0
Clears data for a given stylesheet from the cache.
virtual voidClearStylesheetCache() =0
Clears all preloaded stylesheet data from the cache.
virtual voidPreloadAndCacheHTML(const char * url) =0
Schedules a preload task for a given HTML, parses it, and caches it.
virtual boolRemoveHTMLCacheEntry(const char * url) =0
Clears data for a given HTML from the cache.
virtual voidClearHTMLCache() =0
Clears all preloaded HTML data from the cache.

Public Functions Documentation

function GetId

virtual unsigned GetId() =0

function SetId

virtual void SetId(
    unsigned id
) =0

function ~System

virtual ~System()

function CreateView

virtual View * CreateView(
    const ViewSettings & settings
) =0

Creates a new View with the specified options.

function GetSystemCacheStats

virtual SystemCacheStats * GetSystemCacheStats() const =0

Returns an objects that holds the current statistics of the system-wide caches. Remember to Release when done.

function ClearCachedUnusedImages

virtual void ClearCachedUnusedImages() =0

Removes all unused images (raster and svg) from internal caches.

Note: Images must be unused (orphaned) for them to be cleared. If you want to force ALL images to be unloaded you need for first call View::UnloadDocument to remove any references the DOM might still hold to the images.

function CreateSystemRenderer

virtual SystemRenderer * CreateSystemRenderer(
    const SystemRendererSettings & settings
) =0

Creates a new SystemRenderer. The SystemRenderer will hold rendering resources shared by all view renderers. Can be used on any thread.

function CreateSystemRendererWithExternalRenderingLibrary

virtual SystemRenderer * CreateSystemRendererWithExternalRenderingLibrary(
    const SystemRendererSettingsWithExternalRenderingLibrary & settings
) =0

Creates a new SystemRenderer. The SystemRenderer will hold rendering resources shared by all view renderers. Can be used on any thread.

See: cohtml::Library::InitializeWithRenderingLibrary

Note: Use this version when the Library is initialized with an external rendering library.

function AddFontsFromFolder_DEPRECATED

virtual void AddFontsFromFolder_DEPRECATED(
    const char * path
) =0

Loads all fonts from the specified folder. The fonts can later be used in the Views Prefer using the RegisterFont API for better control over the loaded fonts.

Parameters:

  • path the name of the folder

Note: Requires a valid IFileSystemReader for enumerating the folder.

Warning: This API is deprecated. Use font-face rules or RegisterFont API to load/preload fonts

function RegisterFont

virtual void RegisterFont(
    const char * url,
    const FontDescription & desc =FontDescription(),
    Fonts::FontSDF useSDF =Fonts::SDF_Auto
) =0

Registers a font that can be later used in the Views. This API is similar to a font-face rule and allows you to prepare font stream readers in advance, so that text can render without delays. Unlike the font-face rule, this API also allows you to load the font with its original description (using ‘Auto’ for weight or/and style with or without specifying specific family name for it). This API will load all available fonts from font collections (ttc, otc) when a specific font description isn’t provided (use ‘Auto’ without family name). If any description is specified for a font collection, only the first font will be loaded under that description (same behavior as a font-face rule with font collection).

Parameters:

  • url URL for the font to be loaded. Must be a valid URL. Spaces aren’t allowed.
  • desc The description of the font to be loaded
  • useSDF Controls the method used when rendering fonts, same as the coh-font-sdf font-face property SDF reduces memory consumption but finer font details are lost. If you experience a loss of detail in font rendering, try turning SDF off.

function UnregisterFont

virtual bool UnregisterFont(
    const char * url
) =0

Unregisters all registered fonts by the RegisterFont API for a specific font resource identified by the URL. Font resources are shared between the system and the views, so the font resource may not be freed if there are active at font-face rules using the same URL. Since the font resource is required for rendering, fonts will be freed after all pending frames are painted.

Parameters:

  • url URL identifying the font resource. Must be a valid URL. Spaces aren’t allowed.

Return: true, if the font was unregistered successfully and false otherwise.

function AddUserFont

virtual void AddUserFont(
    const char ** imagesData,
    unsigned * imagesDataSize,
    unsigned imagesCount,
    const UserFontDescription & description
) =0

Load the user font using image files.

Parameters:

  • imagesData pointer to image files data.
  • imagesDataSize pointer to size of the image files.
  • imagesCount number of images
  • description Description of the bitmap font.

Note:

  • The memory can be freed immediately after the call
  • Images must have the appropriate number of channels Bitmap: 1-channel(A) texture MSDF: 3-channel(RGB) texture

function AddUserFont

virtual void AddUserFont(
    const IAsyncResourceResponse::UserImageData * userImages,
    unsigned imagesCount,
    const UserFontDescription & description
) =0

Load the user font using preloaded images.

Parameters:

  • userImages pointer to UserImageData structs describing the images.
  • imagesCount number of images
  • description Description of the bitmap font.

Note:

  • After freeing the rendering resources you can call this method again in order to provide new images for the same bitmap font description.
  • The memory can be freed immediately after the call
  • Images must have the appropriate number of channels Bitmap: 1-channel(A) texture MSDF: 3-channel(RGB) texture

function RemoveUserFont

virtual bool RemoveUserFont(
    const UserFontDescription & description
) =0

Unregisters the bitmap font which has been registered by the user.

Parameters:

  • description Description of the bitmap font.

Return: true, if the font was unregistered successfully and false otherwise.

function SetDefaultFallbackFontName_DEPRECATED

virtual void SetDefaultFallbackFontName_DEPRECATED(
    const char * name
) =0

Loads font with given name from folders specified by AddFontsFromFolder. This font will be used when the another font cannot be loaded or found as a default one. This font is a fallback if the font name used in a Style property is not found. If you want to change the default font that will be applied to all elements, you should change the value in LibraryParams::DefaultStyleFontFamily.

Parameters:

  • name name of the font to load as default fallback

Note: This should be called after AddFontsFromFolder

Warning: This function is deprecated and about to be removed. Cohtml now uses an embedded fallback font.

function Destroy

virtual void Destroy() =0

Destroys the System.

function Advance

virtual void Advance(
    TimePoint timeMilliseconds
) =0

Advances the internal timers and inspector when available.

function RegisterGamepad

virtual void RegisterGamepad(
    unsigned id,
    const char * info,
    unsigned axesCount,
    unsigned buttonsCount,
    void * reserved =nullptr
) =0

Registers a new gamepad. All views will receive the gamepadconnected event. You can provide any number of axes and buttons though the standard mapping according to the HTML spec has 4 axes and 17 buttons which can be found here https://w3c.github.io/gamepad/#remapping.

Parameters:

  • id the unique identifier for the gamepad
  • info general information for the gamepad such as producer and model
  • axesCount the number of analog axes the gamepad has
  • buttonsCount the number of buttons the gamepad has
  • reserved reserved parameter. Set to nullptr

function UnregisterGamepad

virtual void UnregisterGamepad(
    unsigned id
) =0

Unregisters a gamepad. All views will receive the gamepaddisconnected event.

Parameters:

  • id the id of the gamepad to unregister

function UpdateGamepadState

virtual void UpdateGamepadState(
    const cohtml::GamepadState & state
) =0

Updates the state of a single gamepad.

Parameters:

  • state new state of the gamepad

Note: All gamepad-related methods are system-wise. All views will get the new state.

function UpdateGamepadStateExtended

virtual void UpdateGamepadStateExtended(
    const cohtml::GamepadStateExtended & state
) =0

Updates the state of a single gamepad with motion tracking information.

Parameters:

  • state new state of the gamepad

Note:

  • All gamepad-related methods are system-wise. All views will get the new state.
  • If you do not require motion tracking, use System::UpdateGamepadState

function UserImagesChanged

virtual void UserImagesChanged(
    const unsigned * images,
    unsigned count
) =0

Trigger repaint of a user provided texture. Call this whenever the image is changed by logic external to the library. Make sure to have ImageHandle set for such images.

Parameters:

  • images array of image handles - id-s of the user provided images that are changed
  • count the number of changed images

function PreloadAndCacheStylesheet

virtual void PreloadAndCacheStylesheet(
    const char * url
) =0

Schedules a preload task for a given stylesheet and caches it upon successful parsing.

Parameters:

  • url A URL for the stylesheet to be preloaded and cached. Must be a valid URL. Spaces aren’t allowed.

Note: The stylesheet cache is shared among all views

function RemoveStylesheetCacheEntry

virtual bool RemoveStylesheetCacheEntry(
    const char * url
) =0

Clears data for a given stylesheet from the cache.

Parameters:

  • url The URL for the stylesheet to be cleared from cache. Must be the same URL used for its preloading.

Return: true, if the cache entry corresponding to the given URL was found and cleared successfully

Note:

  • If a stylesheet that is currently in use by a view is cleared, it won’t affect the view
  • but a resource request will be fired the next time it is needed

function ClearStylesheetCache

virtual void ClearStylesheetCache() =0

Clears all preloaded stylesheet data from the cache.

Note:

  • If a stylesheet that is currently in use by a view is cleared, it won’t affect the view
  • but a resource request will be fired the next time it is needed

function PreloadAndCacheHTML

virtual void PreloadAndCacheHTML(
    const char * url
) =0

Schedules a preload task for a given HTML, parses it, and caches it.

Parameters:

  • url A URL for the HTML to be preloaded and cached. Must be a valid absolute URL. Spaces aren’t allowed.

Note: The HTML cache is shared among all views

function RemoveHTMLCacheEntry

virtual bool RemoveHTMLCacheEntry(
    const char * url
) =0

Clears data for a given HTML from the cache.

Parameters:

  • url The URL for the HTML to be cleared from the cache. Must be the same URL used for its preloading.

Return: true, if the cache entry corresponding to the given URL was found and cleared successfully

Note:

  • Removing HTML from cache that is currently in use by a view won’t free HTML data immediately,
  • data will be freed after the View finishes DOM building, even if the HTML is not loaded yet.

function ClearHTMLCache

virtual void ClearHTMLCache() =0

Clears all preloaded HTML data from the cache.

Note:

  • Removing HTML from cache that is currently in use by a view won’t free HTML data immediately,
  • data will be freed after the View finishes DOM building, even if the HTML is not loaded yet.