I solved it with this expression:
// Kashida (Tatweel) Removal Expression
var originalText = “text here”;
var kashidaChar = String.fromCharCode(0x0640); // Arabic Tatweel ـ
// Get removal percentage from control layer
var removePercent = 0;
try {
removePercent = thisComp.layer(“Kashida Control Layer”).effect(“Remove Kashida %”)(“Slider”);
} catch (e) {
removePercent = 0;
}
// Find all Kashida positions
var kashidaPositions = [];
for (var i = 0; i < originalText.length; i++) {
if (originalText.charAt(i) === kashidaChar) {
kashidaPositions.push(i);
}
}
// Calculate how many Kashidas to remove
var totalKashidas = kashidaPositions.length;
var kashidasToRemove = Math.floor((removePercent / 100) * totalKashidas);
// Build new text by removing Kashidas proportionally
if (kashidasToRemove === 0) {
originalText;
} else if (kashidasToRemove >= totalKashidas) {
originalText.split(kashidaChar).join(“”);
} else {
var newText = originalText;
var removedCount = 0;
for (var i = kashidaPositions.length – 1; i >= 0 && removedCount < kashidasToRemove; i–) {
kashidaPositions[i] = -1;
removedCount++;
}
var result = “”;
var kashidaIndex = 0;
for (var i = 0; i < originalText.length; i++) {
if (originalText.charAt(i) === kashidaChar) {
if (kashidaPositions[kashidaIndex] !== -1) {
result += kashidaChar;
}
kashidaIndex++;
} else {
result += originalText.charAt(i);
}
}
result;
}
It’s working good, But I’m wondering if there is a better simpler mechanism?!