/* Copyright (c) 2023 Alex Diener This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. Alex Diener alex@ludobloom.com */ #ifndef __UITypeface_H__ #define __UITypeface_H__ typedef struct UITypeface UITypeface; #define UITypeface_superclass StemObject #include "font/String.h" #include "font/TextShared.h" #include "gamemath/Rect4f.h" #include "stemobject/StemObject.h" typedef void (* UITypeface_glyphCallback)(Rect4f vertexBounds, Rect4f textureBounds, bool fixedColor, void * context); #define UITypeface_ivars \ StemObject_ivars #define UITypeface_vtable(self_type) \ StemObject_vtable(self_type) \ \ float (* getLineHeight)(self_type * self); \ float (* measureString)(self_type * self, String string); \ float (* positionXAtIndex)(self_type * self, String string, size_t index); \ size_t (* indexAtPositionX)(self_type * self, String string, float positionX, bool * outLeadingEdge); \ void (* writeGlyphsWithCallback)(self_type * self, String string, Vector2f offset, float scale, UITypeface_glyphCallback callback, void * callbackContext); \ uint32_t (* characterIndexToCodepoint)(self_type * self, unsigned int characterIndex); \ unsigned int (* codepointToCharacterIndex)(self_type * self, uint32_t codepoint); \ String (* encodeCharacterIndexString)(self_type * self, String string); \ String (* decodeCharacterIndexString)(self_type * self, String string, TextEncoding encoding); \ bool (* canStringFitWidth)(self_type * self, String string, float widthMax, String truncationSuffix, size_t * outTruncatedLength); stemobject_declare(UITypeface) bool UITypeface_init(UITypeface * self); void UITypeface_dispose(UITypeface * self); float UITypeface_getLineHeight(UITypeface * self); float UITypeface_measureString(UITypeface * self, String string); float UITypeface_positionXAtIndex(UITypeface * self, String string, size_t index); size_t UITypeface_indexAtPositionX(UITypeface * self, String string, float positionX, bool * outLeadingEdge); void UITypeface_writeGlyphsWithCallback(UITypeface * self, String string, Vector2f offset, float scale, UITypeface_glyphCallback callback, void * callbackContext); uint32_t UITypeface_characterIndexToCodepoint(UITypeface * self, unsigned int characterIndex); unsigned int UITypeface_codepointToCharacterIndex(UITypeface * self, uint32_t codepoint); String UITypeface_encodeCharacterIndexString(UITypeface * self, String string); String UITypeface_decodeCharacterIndexString(UITypeface * self, String string, TextEncoding encoding); bool UITypeface_canStringFitWidth(UITypeface * self, String string, float widthMax, String truncationSuffix, size_t * outTruncatedLength); #endif