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

Method prewarmStyle

lib/EpdFont/SdCardFont.cpp:764–985  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

762}
763
764int SdCardFont::prewarmStyle(uint8_t styleIdx, const uint32_t* codepoints, uint32_t cpCount, bool metadataOnly) {
765 auto& s = styles_[styleIdx];
766
767 // Map codepoints to global glyph indices for this style
768 struct CpGlyphMapping {
769 uint32_t codepoint;
770 int32_t globalIndex;
771 };
772 CpGlyphMapping* mappings = new (std::nothrow) CpGlyphMapping[cpCount];
773 if (!mappings) {
774 LOG_ERR("SDCF", "Failed to allocate mapping array for style %u", styleIdx);
775 return static_cast<int>(cpCount);
776 }
777
778 uint32_t validCount = 0;
779 for (uint32_t i = 0; i < cpCount; i++) {
780 int32_t idx = findGlobalGlyphIndex(s, codepoints[i]);
781 if (idx >= 0) {
782 mappings[validCount].codepoint = codepoints[i];
783 mappings[validCount].globalIndex = idx;
784 validCount++;
785 }
786 }
787 int missed = static_cast<int>(cpCount - validCount);
788
789 if (validCount == 0) {
790 freeStyleMiniData(s);
791 delete[] mappings;
792 s.epdFont.data = &s.stubData;
793 return missed;
794 }
795
796 // Build mini intervals from sorted codepoints
797 freeStyleMiniData(s);
798
799 uint32_t intervalCapacity = validCount;
800 s.miniIntervals = new (std::nothrow) EpdUnicodeInterval[intervalCapacity];
801 if (!s.miniIntervals) {
802 LOG_ERR("SDCF", "Failed to allocate mini intervals for style %u", styleIdx);
803 delete[] mappings;
804 return static_cast<int>(cpCount);
805 }
806
807 s.miniIntervalCount = 0;
808 uint32_t rangeStart = 0;
809 for (uint32_t i = 1; i <= validCount; i++) {
810 if (i == validCount || mappings[i].codepoint != mappings[i - 1].codepoint + 1) {
811 s.miniIntervals[s.miniIntervalCount].first = mappings[rangeStart].codepoint;
812 s.miniIntervals[s.miniIntervalCount].last = mappings[i - 1].codepoint;
813 s.miniIntervals[s.miniIntervalCount].offset = rangeStart;
814 s.miniIntervalCount++;
815 rangeStart = i;
816 }
817 }
818
819 // Allocate mini glyph array
820 s.miniGlyphCount = validCount;
821 s.miniGlyphs = new (std::nothrow) EpdGlyph[s.miniGlyphCount];

Callers

nothing calls this directly

Calls 4

openFileForReadMethod · 0.80
seekSetMethod · 0.80
closeMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected