/* 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 */ #include "uitoolkit/UITypeface.h" #include #define stemobject_implementation UITypeface v_begin(); v_func(dispose); v_func(getLineHeight); v_func(measureString); v_func(positionXAtIndex); v_func(indexAtPositionX); v_func(writeGlyphsWithCallback); v_func(characterIndexToCodepoint); v_func(codepointToCharacterIndex); v_func(encodeCharacterIndexString); v_func(canStringFitWidth); v_end(); UITypeface * UITypeface_create(void) { stemobject_create_implementation(init) } bool UITypeface_init(UITypeface * self) { call_super(init, self); return true; } void UITypeface_dispose(UITypeface * self) { call_super_virtual(dispose, self); } float UITypeface_getLineHeight(UITypeface * self) { return 1.0f; } float UITypeface_measureString(UITypeface * self, String string) { return 0.0f; } float UITypeface_positionXAtIndex(UITypeface * self, String string, size_t index) { return 0.0f; } size_t UITypeface_indexAtPositionX(UITypeface * self, String string, float positionX, bool * outLeadingEdge) { return 0; } 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) { return 0; } unsigned int UITypeface_codepointToCharacterIndex(UITypeface * self, uint32_t codepoint) { return UINT_MAX; } String UITypeface_encodeCharacterIndexString(UITypeface * self, String string) { return STR_NULL; } String UITypeface_decodeCharacterIndexString(UITypeface * self, String string, TextEncoding encoding) { return STR_NULL; } bool UITypeface_canStringFitWidth(UITypeface * self, String string, float widthMax, String truncationSuffix, size_t * outTruncatedLength) { float measuredWidth = call_virtual(measureString, self, string); if (measuredWidth > widthMax) { if (outTruncatedLength != NULL) { float truncationSuffixWidth = call_virtual(measureString, self, truncationSuffix); *outTruncatedLength = call_virtual(indexAtPositionX, self, string, widthMax - truncationSuffixWidth, NULL); } return false; } return true; }