From da69588d09c7b443cc56a18b0b5c990b8b603c64 Mon Sep 17 00:00:00 2001 From: Mathan Mathialagan Date: Sat, 22 Feb 2025 23:58:06 +0530 Subject: [PATCH] Minor changes --- pdf/lib/src/pdf/font/indic-shaper.dart | 46 ++++++++++++++++---------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/pdf/lib/src/pdf/font/indic-shaper.dart b/pdf/lib/src/pdf/font/indic-shaper.dart index a19ef2ec..029f3bd3 100644 --- a/pdf/lib/src/pdf/font/indic-shaper.dart +++ b/pdf/lib/src/pdf/font/indic-shaper.dart @@ -66,21 +66,25 @@ doGlobalSubstitution(List charIndexes, TtfParser font) { } initialReorder(List glyphIndexes, String lang) { - for (int i = 0; i < glyphIndexes.length; i++) { - var glyphIndex = glyphIndexes[i]; - if (lang == 'tamil') { - if (glyphIndex == 47 || glyphIndex == 46 || glyphIndex == 48) { - // ெ ை ே - glyphIndexes[i] = glyphIndexes[i - 1]; - glyphIndexes[i - 1] = glyphIndex; - } - } else if (lang == 'hindi') { - if (glyphIndex == 67) { - glyphIndexes[i] = glyphIndexes[i - 1]; - glyphIndexes[i - 1] = glyphIndex; + try { + for (int i = 0; i < glyphIndexes.length; i++) { + var glyphIndex = glyphIndexes[i]; + if (i != 0) { + if (lang == 'tamil') { + if (glyphIndex == 47 || glyphIndex == 46 || glyphIndex == 48) { + // ெ ை ே + glyphIndexes[i] = glyphIndexes[i - 1]; + glyphIndexes[i - 1] = glyphIndex; + } + } else if (lang == 'hindi') { + if (glyphIndex == 67) { + glyphIndexes[i] = glyphIndexes[i - 1]; + glyphIndexes[i - 1] = glyphIndex; + } + } } } - } + } catch (e) {} return glyphIndexes; } @@ -105,14 +109,22 @@ getLang(String fontName) { return 'tamil'; } else if (fontName.toLowerCase().contains('devanagari')) { return 'hindi'; + } else if (fontName.toLowerCase().contains('telugu')) { + return 'telugu'; } return ''; } +isIndicShaperSupported(String lang) { + return ['tamil', 'hindi', 'telugu'].contains(lang); +} + indicShaper(List glyphIndexes, TtfParser font) { var lang = getLang(font.fontName); - glyphIndexes = doGlobalSubstitution(glyphIndexes, font); - glyphIndexes = initialReorder(glyphIndexes, lang); - glyphIndexes = finalReorder(glyphIndexes, lang); + if (isIndicShaperSupported(lang)) { + glyphIndexes = doGlobalSubstitution(glyphIndexes, font); + glyphIndexes = initialReorder(glyphIndexes, lang); + glyphIndexes = finalReorder(glyphIndexes, lang); + } return glyphIndexes; -} +} \ No newline at end of file