MCPcopy Create free account
hub / github.com/crosspoint-reader/crosspoint-reader / prewarmCache

Method prewarmCache

lib/EpdFont/FontDecompressor.cpp:245–500  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

243}
244
245int FontDecompressor::prewarmCache(const EpdFontData* fontData, const char* utf8Text) {
246 if (!fontData || !fontData->groups || !utf8Text) return 0;
247
248 // Allocate the next available slot (caller must call freePageBuffer/clearCache to reset)
249 if (pageSlotCount >= MAX_PAGE_SLOTS) {
250 LOG_ERR("FDC", "All %u page buffer slots full, cannot prewarm fontData=%p", MAX_PAGE_SLOTS, (void*)fontData);
251 return -1;
252 }
253 PageSlot& slot = pageSlots[pageSlotCount];
254
255 // Step 1: Collect unique glyph indices needed for this page
256 uint32_t neededGlyphs[MAX_PAGE_GLYPHS];
257 uint16_t glyphCount = 0;
258 bool glyphCapWarned = false;
259
260 const unsigned char* p = reinterpret_cast<const unsigned char*>(utf8Text);
261 while (*p) {
262 uint32_t cp = utf8NextCodepoint(&p);
263 if (cp == 0) break;
264
265 int32_t glyphIdx = findGlyphIndex(fontData, cp);
266 if (glyphIdx < 0) continue;
267
268 // Deduplicate
269 bool found = false;
270 for (uint16_t i = 0; i < glyphCount; i++) {
271 if (neededGlyphs[i] == static_cast<uint32_t>(glyphIdx)) {
272 found = true;
273 break;
274 }
275 }
276 if (!found) {
277 if (glyphCount < MAX_PAGE_GLYPHS) {
278 neededGlyphs[glyphCount++] = static_cast<uint32_t>(glyphIdx);
279 } else if (!glyphCapWarned) {
280 LOG_DBG("FDC", "Glyph cap (%u) reached during prewarm; excess glyphs will use hot-group fallback",
281 MAX_PAGE_GLYPHS);
282 glyphCapWarned = true;
283 }
284 }
285 }
286
287 // Add ligature output glyphs: if both input codepoints of a ligature pair are
288 // in the needed set, the output glyph will be queried during rendering.
289 if (fontData->ligaturePairs && fontData->ligaturePairCount > 0) {
290 for (uint32_t li = 0; li < fontData->ligaturePairCount && glyphCount < MAX_PAGE_GLYPHS; li++) {
291 uint32_t leftCp = fontData->ligaturePairs[li].pair >> 16;
292 uint32_t rightCp = fontData->ligaturePairs[li].pair & 0xFFFF;
293
294 int32_t leftIdx = findGlyphIndex(fontData, leftCp);
295 int32_t rightIdx = findGlyphIndex(fontData, rightCp);
296 if (leftIdx < 0 || rightIdx < 0) continue;
297
298 // Check if both inputs are in neededGlyphs
299 bool hasLeft = false, hasRight = false;
300 for (uint16_t i = 0; i < glyphCount; i++) {
301 if (neededGlyphs[i] == static_cast<uint32_t>(leftIdx)) hasLeft = true;
302 if (neededGlyphs[i] == static_cast<uint32_t>(rightIdx)) hasRight = true;

Callers 1

renderPreviewPaneMethod · 0.45

Calls 1

utf8NextCodepointFunction · 0.85

Tested by

no test coverage detected