| 172 | } |
| 173 | |
| 174 | static HTextLayout GetOrCreateTextLayout(LabelComponent* component) |
| 175 | { |
| 176 | FontResource* font_resource = GetFontResource(component, component->m_Resource); |
| 177 | uint32_t font_version = font_resource ? ResFontGetVersion(font_resource) : 0; |
| 178 | |
| 179 | if (!component->m_TextLayoutDirty && component->m_TextLayout && font_resource && |
| 180 | component->m_TextLayoutFontVersion == font_version) |
| 181 | { |
| 182 | return component->m_TextLayout; |
| 183 | } |
| 184 | |
| 185 | InvalidateTextLayout(component); |
| 186 | |
| 187 | dmRender::HFontMap font_map = font_resource ? ResFontGetHandle(font_resource) : 0; |
| 188 | if (!font_map || !component->m_Text) |
| 189 | return 0; |
| 190 | |
| 191 | TextLayoutSettings settings = {0}; |
| 192 | settings.m_Width = component->m_Size.getX(); |
| 193 | settings.m_LineBreak = component->m_LineBreak; |
| 194 | settings.m_Leading = component->m_Leading; |
| 195 | settings.m_Tracking = component->m_Tracking; |
| 196 | settings.m_Size = dmRender::GetFontMapSize(font_map); |
| 197 | settings.m_Monospace = dmRender::GetFontMapMonospaced(font_map); |
| 198 | settings.m_Padding = dmRender::GetFontMapPadding(font_map); |
| 199 | |
| 200 | dmArray<uint32_t> codepoints; |
| 201 | TextToCodePoints(component->m_Text, codepoints); |
| 202 | |
| 203 | HTextLayout layout = 0; |
| 204 | TextResult r = TextLayoutCreate(dmRender::GetFontCollection(font_map), codepoints.Begin(), codepoints.Size(), &settings, &layout); |
| 205 | if (r != TEXT_RESULT_OK) |
| 206 | { |
| 207 | if (layout) |
| 208 | TextLayoutRelease(layout); |
| 209 | return 0; |
| 210 | } |
| 211 | |
| 212 | component->m_TextLayout = layout; |
| 213 | component->m_TextLayoutFontVersion = font_version; |
| 214 | component->m_TextLayoutDirty = 0; |
| 215 | return component->m_TextLayout; |
| 216 | } |
| 217 | |
| 218 | void ReHash(LabelComponent* component) |
| 219 | { |
no test coverage detected