/* 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 __UITextLayout_H__ #define __UITextLayout_H__ typedef struct UITextLayout UITextLayout; #define UITextLayout_superclass StemObject #include "font/String.h" #include "font/TextShared.h" #include "font/WordWrap.h" #include "stemobject/StemObject.h" #include "uitoolkit/UITypeface.h" struct UITextLayout_wrapPoint { size_t wrapPoint; size_t ignoredWhitespaceCount; }; struct UITextLayout_wrapInfo { struct UITextLayout_wrapPoint * wrapPoints; size_t wrapPointCount; size_t wrapPointAllocatedCount; float lineWidthMax; }; #define UITextLayout_ivars \ StemObject_ivars \ \ UITypeface * typeface; \ String string; \ TextAlignMode alignMode; \ WordWrapBehavior wrapBehavior; \ float wrapWidth; \ bool dirty; \ struct UITextLayout_wrapInfo private_ivar(wrapInfo); #define UITextLayout_vtable(self_type) \ StemObject_vtable(self_type) \ \ void (* setString)(self_type * self, String string); \ void (* setTypeface)(self_type * self, compat_type(UITypeface *) typeface); \ void (* setAlignMode)(self_type * self, TextAlignMode alignMode); \ void (* setWrapBehavior)(self_type * self, WordWrapBehavior wrapBehavior); \ void (* setWrapWidth)(self_type * self, float wrapWidth); \ unsigned int (* getLineCount)(self_type * self); \ unsigned int (* getLineIndex)(self_type * self, size_t charIndex); \ size_t (* getLineStartCharIndex)(self_type * self, unsigned int lineIndex); \ size_t (* getLineEndCharIndex)(self_type * self, unsigned int lineIndex); \ Vector2f (* measureString)(self_type * self); \ size_t (* indexAtPosition)(self_type * self, Vector2f position, bool * outLeadingEdge); \ Vector2f (* positionAtIndex)(self_type * self, size_t charIndex); \ void (* writeGlyphsWithCallback)(self_type * self, Vector2f offset, float scale, UITypeface_glyphCallback callback, void * callbackContext); stemobject_declare(UITextLayout) // Takes ownership of string UITextLayout * UITextLayout_create(compat_type(UITypeface *) typeface, String string, TextAlignMode alignMode, WordWrapBehavior wrapBehavior, float wrapWidth); bool UITextLayout_init(UITextLayout * self, compat_type(UITypeface *) typeface, String string, TextAlignMode alignMode, WordWrapBehavior wrapBehavior, float wrapWidth); void UITextLayout_dispose(UITextLayout * self); void UITextLayout_setString(UITextLayout * self, String string); void UITextLayout_setTypeface(UITextLayout * self, compat_type(UITypeface *) typeface); void UITextLayout_setAlignMode(UITextLayout * self, TextAlignMode alignMode); void UITextLayout_setWrapBehavior(UITextLayout * self, WordWrapBehavior wrapBehavior); void UITextLayout_setWrapWidth(UITextLayout * self, float wrapWidth); unsigned int UITextLayout_getLineCount(UITextLayout * self); unsigned int UITextLayout_getLineIndex(UITextLayout * self, size_t charIndex); size_t UITextLayout_getLineStartCharIndex(UITextLayout * self, unsigned int lineIndex); size_t UITextLayout_getLineEndCharIndex(UITextLayout * self, unsigned int lineIndex); Vector2f UITextLayout_measureString(UITextLayout * self); size_t UITextLayout_indexAtPosition(UITextLayout * self, Vector2f position, bool * outLeadingEdge); Vector2f UITextLayout_positionAtIndex(UITextLayout * self, size_t charIndex); void UITextLayout_writeGlyphsWithCallback(UITextLayout * self, Vector2f offset, float scale, UITypeface_glyphCallback callback, void * callbackContext); #endif