loadFontFromZip method
Loads a font from a ZIP file for the specified page index.
This method asynchronously loads a font from a ZIP file based on the given
pageIndex
. The font is then available for use within the application.
pageIndex
- The index of the page for which the font should be loaded.
Returns a Future that completes when the font has been successfully loaded.
Implementation
Future<void> loadFontFromZip(int pageIndex) async {
try {
final fontsDir = Directory('${_dir.path}/quran_fonts');
// تحقق من الملفات داخل المجلد
final files = await fontsDir.list().toList();
log('Files in fontsDir: ${files.map((file) => file.path).join(', ')}');
final fontFile =
File('${fontsDir.path}/quran_fonts/p${(pageIndex + 2001)}.ttf');
if (!await fontFile.exists()) {
throw Exception("Font file not found for page: ${pageIndex + 1}");
}
final fontLoader = FontLoader('p${(pageIndex + 2001)}');
fontLoader.addFont(_getFontLoaderBytes(fontFile));
await fontLoader.load();
} catch (e) {
throw Exception("Failed to load font: $e");
}
}