calculateDynamicLineHeight method

double calculateDynamicLineHeight({
  1. required double availableHeight,
  2. required int pageIndex,
  3. required bool hasHeader,
  4. required bool hasBasmala,
})

حساب ارتفاع السطر الديناميكي للصفحة Calculate dynamic line height for page

Implementation

double calculateDynamicLineHeight({
  required double availableHeight,
  required int pageIndex,
  required bool hasHeader,
  required bool hasBasmala,
}) {
  // شرح: حساب المساحة المستخدمة للعناصر الإضافية
  // Explanation: Calculate space used by additional elements
  double usedSpace = 0;

  if (hasHeader) {
    usedSpace += 80; // مساحة البنر
  }

  if (hasBasmala) {
    usedSpace += 50; // مساحة البسملة
  }

  // شرح: المساحة المتبقية للأسطر
  // Explanation: Remaining space for lines
  final remainingHeight = (availableHeight - usedSpace) * 0.95;

  // شرح: الحصول على عدد الأسطر المتوقع
  // Explanation: Get expected lines count
  final expectedLines = getExpectedLinesCount(pageIndex);

  // شرح: حساب ارتفاع السطر
  // Explanation: Calculate line height
  if (expectedLines > 0) {
    return pageIndex == 0 && shouldShowBasmala()
        ? remainingHeight / expectedLines + 9.3
        : pageIndex == 0 && surahNumber == 9
            ? remainingHeight / expectedLines + 5
            : remainingHeight / expectedLines;
  }

  // شرح: ارتفاع افتراضي
  // Explanation: Default height
  return 40.0;
}