@@ -19,52 +19,50 @@ enum FontStyle {
1919struct Fonts {
2020 Fonts ()
2121 {
22- Typeface::setTypefaceCacheSize (7 );
23-
24- // Our unicode font is too big, the compiler will run out of memory
25- // To prevent this, we split the BinaryData into multiple files, and add them back together here
26- HeapArray<uint8_t > interUnicodeXz;
27- interUnicodeXz.reserve (7 * 1024 * 1024 );
22+ HeapArray<uint8_t > interUnicodeZip;
23+ interUnicodeZip.reserve (7 * 1024 * 1024 );
2824 int i = 0 ;
29- while (true ) {
30- int size;
31- auto * resource = BinaryData::getNamedResource (( String ( " InterUnicode_ " ) + String (i)). toRawUTF8 (), size) ;
32-
33- if (!resource) {
25+ while (true )
26+ {
27+ int size = 0 ;
28+ auto * resource = BinaryData::getNamedResource (( " InterUnicode_ " + String (i)). toRawUTF8 (), size);
29+ if (!resource)
3430 break ;
35- }
36-
37- interUnicodeXz.insert (interUnicodeXz.end (), resource, resource + size);
38- i++;
31+ interUnicodeZip.insert (interUnicodeZip.end (), resource, resource + size);
32+ ++i;
3933 }
40- HeapArray<uint8_t > interUnicode;
41- interUnicode.reserve (17 * 1024 * 1024 ); // Reserve 17mb to prevent more allocations
42- {
43- lzma_stream strm = LZMA_STREAM_INIT;
44- if (lzma_stream_decoder (&strm, UINT64_MAX, 0 ) != LZMA_OK)
45- return ; // TODO: handle failure!!
4634
47- strm. next_in = reinterpret_cast < const uint8_t *>(interUnicodeXz. data ());
48- strm. avail_in = interUnicodeXz .size ();
35+ // Create a MemoryInputStream from the combined ZIP data buffer
36+ MemoryInputStream zipInputStream (interUnicodeZip. data (), interUnicodeZip .size (), false );
4937
50- uint8_t buffer[ 8192 ];
51- lzma_ret ret ;
38+ // Open the ZIP archive from memory
39+ ZipFile zipFile (zipInputStream) ;
5240
53- do {
54- strm.next_out = buffer;
55- strm.avail_out = sizeof (buffer);
41+ HeapArray<uint8_t > interUnicode;
42+ interUnicode.reserve (17 * 1024 * 1024 ); // reserve enough memory for decompressed font
5643
57- ret = lzma_code (&strm, LZMA_FINISH);
58- size_t written = sizeof (buffer) - strm.avail_out ;
59- interUnicode.insert (interUnicode.end (), buffer, buffer + written);
44+ auto numEntries = zipFile.getNumEntries ();
45+ if (numEntries == 0 )
46+ {
47+ // TODO: handle error
48+ return ;
49+ }
6050
61- if (ret != LZMA_OK && ret != LZMA_STREAM_END) {
62- lzma_end (&strm);
63- return ;
64- }
65- } while (ret != LZMA_STREAM_END);
51+ auto fileEntry = zipFile.getEntry (numEntries - 1 ); // or use 0 if you want first entry
52+
53+ // Create a InputStream for the file entry
54+ std::unique_ptr<InputStream> fileStream (zipFile.createStreamForEntry (*fileEntry));
6655
67- lzma_end (&strm);
56+ // Read the decompressed font data into interUnicode array
57+ const int bufferSize = 8192 ;
58+ char buffer[bufferSize];
59+
60+ while (!fileStream->isExhausted ())
61+ {
62+ auto bytesRead = fileStream->read (buffer, bufferSize);
63+ if (bytesRead <= 0 )
64+ break ;
65+ interUnicode.insert (interUnicode.end (), (const uint8_t *)buffer, (const uint8_t *)buffer + bytesRead);
6866 }
6967
7068 // Initialise typefaces
0 commit comments