loadFont method

Future<void> loadFont(
  1. int pageIndex, {
  2. bool isFontsLocal = false,
})

Loads the font for the specified page index.

This method asynchronously loads the font for 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> loadFont(int pageIndex, {bool isFontsLocal = false}) async {
  if (isFontsLocal) {
    return;
  } else {
    try {
      final appDir = await getApplicationDocumentsDirectory();
      // تعديل المسار ليشمل المجلد الإضافي
      final fontFile = File(
          '${appDir.path}/quran_fonts/quran_fonts/p${(pageIndex + 2001)}.ttf');
      if (!await fontFile.exists()) {
        throw Exception("Font file not found for page: ${pageIndex + 2001}");
      }
      final fontLoader = FontLoader('p${(pageIndex + 2001)}');
      fontLoader.addFont(_getFontLoaderBytes(fontFile));
      await fontLoader.load();
    } catch (e) {
      throw Exception("Failed to load font: $e");
    }
  }
}