Last active
August 26, 2023 22:43
-
-
Save alierdogan7/11f9cfb24f5551c34191485fc764d4c0 to your computer and use it in GitHub Desktop.
Arabic tex view utilities
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ae.ftech.quraan.Utility.arabicfont; | |
import android.graphics.Color; | |
import android.text.SpannableString; | |
import android.text.Spanned; | |
import android.text.style.ForegroundColorSpan; | |
/** | |
* Created by arshadbinhamza on 11/27/16. | |
*/ | |
public class ABHArabicDiacritics { | |
String contentText; | |
String serchText; | |
int searchTextStartPosition=-1; | |
int searchTextEndPosition=-1; | |
SpannableString searchHighlightedSpan; | |
public ABHArabicDiacritics(String contentText, String searchtext) { | |
this.contentText =contentText; | |
this.serchText =searchtext; | |
String adVersa = contentText; | |
String temp=""; | |
for(int i=0;i<adVersa.length();i++) | |
{ | |
temp = adVersa.substring(0,i); | |
if(getDiacriticinsensitive(temp).contains(searchtext)) | |
{ | |
searchTextEndPosition=i; | |
break; | |
} | |
} | |
if(searchTextEndPosition>-1) | |
{ | |
temp=""; | |
for(int j=searchTextEndPosition;j>=0;j--) | |
{ | |
temp = adVersa.substring(j,searchTextEndPosition); | |
if(temp.length()>0) | |
if(getDiacriticinsensitive(temp).contains(searchtext)) | |
{ | |
searchTextStartPosition=j; | |
break; | |
} | |
} | |
} | |
searchHighlightedSpan = new SpannableString(contentText); | |
searchHighlightedSpan.setSpan(new ForegroundColorSpan(Color.RED), searchTextStartPosition>0?searchTextStartPosition-1:searchTextStartPosition, searchTextEndPosition, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); | |
} | |
public ABHArabicDiacritics() { | |
} | |
public boolean isContain() | |
{ | |
if(getSearchTextEndPosition()>-1) | |
return true; | |
else return false; | |
} | |
public String getDiacriticinsensitive(String s) { | |
/* String normalized = Normalizer.normalize(s, Normalizer.Form.NFD); | |
return normalized.replaceAll("\\p{M}", "");*/ | |
String input =s; | |
//Remove honorific sign | |
input=input.replaceAll("\u0610", "");//ARABIC SIGN SALLALLAHOU ALAYHE WA SALLAM | |
input=input.replaceAll("\u0611", "");//ARABIC SIGN ALAYHE ASSALLAM | |
input=input.replaceAll("\u0612", "");//ARABIC SIGN RAHMATULLAH ALAYHE | |
input=input.replaceAll("\u0613", "");//ARABIC SIGN RADI ALLAHOU ANHU | |
input=input.replaceAll("\u0614", "");//ARABIC SIGN TAKHALLUS | |
//Remove koranic anotation | |
input=input.replaceAll("\u0615", "");//ARABIC SMALL HIGH TAH | |
input=input.replaceAll("\u0616", "");//ARABIC SMALL HIGH LIGATURE ALEF WITH LAM WITH YEH | |
input=input.replaceAll("\u0617", "");//ARABIC SMALL HIGH ZAIN | |
input=input.replaceAll("\u0618", "");//ARABIC SMALL FATHA | |
input=input.replaceAll("\u0619", "");//ARABIC SMALL DAMMA | |
input=input.replaceAll("\u061A", "");//ARABIC SMALL KASRA | |
input=input.replaceAll("\u06D6", "");//ARABIC SMALL HIGH LIGATURE SAD WITH LAM WITH ALEF MAKSURA | |
input=input.replaceAll("\u06D7", "");//ARABIC SMALL HIGH LIGATURE QAF WITH LAM WITH ALEF MAKSURA | |
input=input.replaceAll("\u06D8", "");//ARABIC SMALL HIGH MEEM INITIAL FORM | |
input=input.replaceAll("\u06D9", "");//ARABIC SMALL HIGH LAM ALEF | |
input=input.replaceAll("\u06DA", "");//ARABIC SMALL HIGH JEEM | |
input=input.replaceAll("\u06DB", "");//ARABIC SMALL HIGH THREE DOTS | |
input=input.replaceAll("\u06DC", "");//ARABIC SMALL HIGH SEEN | |
input=input.replaceAll("\u06DD", "");//ARABIC END OF AYAH | |
input=input.replaceAll("\u06DE", "");//ARABIC START OF RUB EL HIZB | |
input=input.replaceAll("\u06DF", "");//ARABIC SMALL HIGH ROUNDED ZERO | |
input=input.replaceAll("\u06E0", "");//ARABIC SMALL HIGH UPRIGHT RECTANGULAR ZERO | |
input=input.replaceAll("\u06E1", "");//ARABIC SMALL HIGH DOTLESS HEAD OF KHAH | |
input=input.replaceAll("\u06E2", "");//ARABIC SMALL HIGH MEEM ISOLATED FORM | |
input=input.replaceAll("\u06E3", "");//ARABIC SMALL LOW SEEN | |
input=input.replaceAll("\u06E4", "");//ARABIC SMALL HIGH MADDA | |
input=input.replaceAll("\u06E5", "");//ARABIC SMALL WAW | |
input=input.replaceAll("\u06E6", "");//ARABIC SMALL YEH | |
input=input.replaceAll("\u06E7", "");//ARABIC SMALL HIGH YEH | |
input=input.replaceAll("\u06E8", "");//ARABIC SMALL HIGH NOON | |
input=input.replaceAll("\u06E9", "");//ARABIC PLACE OF SAJDAH | |
input=input.replaceAll("\u06EA", "");//ARABIC EMPTY CENTRE LOW STOP | |
input=input.replaceAll("\u06EB", "");//ARABIC EMPTY CENTRE HIGH STOP | |
input=input.replaceAll("\u06EC", "");//ARABIC ROUNDED HIGH STOP WITH FILLED CENTRE | |
input=input.replaceAll("\u06ED", "");//ARABIC SMALL LOW MEEM | |
//Remove tatweel | |
input=input.replaceAll("\u0640", ""); | |
//Remove tashkeel | |
input=input.replaceAll("\u064B", "");//ARABIC FATHATAN | |
input=input.replaceAll("\u064C", "");//ARABIC DAMMATAN | |
input=input.replaceAll("\u064D", "");//ARABIC KASRATAN | |
input=input.replaceAll("\u064E", "");//ARABIC FATHA | |
input=input.replaceAll("\u064F", "");//ARABIC DAMMA | |
input=input.replaceAll("\u0650", "");//ARABIC KASRA | |
input=input.replaceAll("\u0651", "");//ARABIC SHADDA | |
input=input.replaceAll("\u0652", "");//ARABIC SUKUN | |
input=input.replaceAll("\u0653", "");//ARABIC MADDAH ABOVE | |
input=input.replaceAll("\u0654", "");//ARABIC HAMZA ABOVE | |
input=input.replaceAll("\u0655", "");//ARABIC HAMZA BELOW | |
input=input.replaceAll("\u0656", "");//ARABIC SUBSCRIPT ALEF | |
input=input.replaceAll("\u0657", "");//ARABIC INVERTED DAMMA | |
input=input.replaceAll("\u0658", "");//ARABIC MARK NOON GHUNNA | |
input=input.replaceAll("\u0659", "");//ARABIC ZWARAKAY | |
input=input.replaceAll("\u065A", "");//ARABIC VOWEL SIGN SMALL V ABOVE | |
input=input.replaceAll("\u065B", "");//ARABIC VOWEL SIGN INVERTED SMALL V ABOVE | |
input=input.replaceAll("\u065C", "");//ARABIC VOWEL SIGN DOT BELOW | |
input=input.replaceAll("\u065D", "");//ARABIC REVERSED DAMMA | |
input=input.replaceAll("\u065E", "");//ARABIC FATHA WITH TWO DOTS | |
input=input.replaceAll("\u065F", "");//ARABIC WAVY HAMZA BELOW | |
input=input.replaceAll("\u0670", "");//ARABIC LETTER SUPERSCRIPT ALEF | |
//Replace Waw Hamza Above by Waw | |
input=input.replaceAll("\u0624", "\u0648"); | |
//Replace Ta Marbuta by Ha | |
input=input.replaceAll("\u0629", "\u0647"); | |
//Replace Ya | |
// and Ya Hamza Above by Alif Maksura | |
input=input.replaceAll("\u064A", "\u0649"); | |
input=input.replaceAll("\u0626", "\u0649"); | |
// Replace Alifs with Hamza Above/Below | |
// and with Madda Above by Alif | |
input=input.replaceAll("\u0622", "\u0627"); | |
input=input.replaceAll("\u0623", "\u0627"); | |
input=input.replaceAll("\u0625", "\u0627"); | |
return input; | |
} | |
public String getContentText() { | |
return contentText; | |
} | |
public void setContentText(String contentText) { | |
this.contentText = contentText; | |
} | |
public String getSerchText() { | |
return serchText; | |
} | |
public void setSerchText(String serchText) { | |
this.serchText = serchText; | |
} | |
public int getSearchTextStartPosition() { | |
return searchTextStartPosition; | |
} | |
public void setSearchTextStartPosition(int searchTextStartPosition) { | |
this.searchTextStartPosition = searchTextStartPosition; | |
} | |
public int getSearchTextEndPosition() { | |
return searchTextEndPosition; | |
} | |
public void setSearchTextEndPosition(int searchTextEndPosition) { | |
this.searchTextEndPosition = searchTextEndPosition; | |
} | |
public SpannableString getSearchHighlightedSpan() { | |
return searchHighlightedSpan; | |
} | |
public void setSearchHighlightedSpan(SpannableString searchHighlightedSpan) { | |
this.searchHighlightedSpan = searchHighlightedSpan; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* ArabicNormalizer class | |
* @author Ibrabel | |
*/ | |
public final class ArabicNormalizer { | |
private String input; | |
private final String output; | |
/** | |
* ArabicNormalizer constructor | |
* @param input String | |
*/ | |
public ArabicNormalizer(String input){ | |
this.input=input; | |
this.output=normalize(); | |
} | |
/** | |
* normalize Method | |
* @return String | |
*/ | |
private String normalize(){ | |
//Remove honorific sign | |
input=input.replaceAll("\u0610", "");//ARABIC SIGN SALLALLAHOU ALAYHE WA SALLAM | |
input=input.replaceAll("\u0611", "");//ARABIC SIGN ALAYHE ASSALLAM | |
input=input.replaceAll("\u0612", "");//ARABIC SIGN RAHMATULLAH ALAYHE | |
input=input.replaceAll("\u0613", "");//ARABIC SIGN RADI ALLAHOU ANHU | |
input=input.replaceAll("\u0614", "");//ARABIC SIGN TAKHALLUS | |
//Remove koranic anotation | |
input=input.replaceAll("\u0615", "");//ARABIC SMALL HIGH TAH | |
input=input.replaceAll("\u0616", "");//ARABIC SMALL HIGH LIGATURE ALEF WITH LAM WITH YEH | |
input=input.replaceAll("\u0617", "");//ARABIC SMALL HIGH ZAIN | |
input=input.replaceAll("\u0618", "");//ARABIC SMALL FATHA | |
input=input.replaceAll("\u0619", "");//ARABIC SMALL DAMMA | |
input=input.replaceAll("\u061A", "");//ARABIC SMALL KASRA | |
input=input.replaceAll("\u06D6", "");//ARABIC SMALL HIGH LIGATURE SAD WITH LAM WITH ALEF MAKSURA | |
input=input.replaceAll("\u06D7", "");//ARABIC SMALL HIGH LIGATURE QAF WITH LAM WITH ALEF MAKSURA | |
input=input.replaceAll("\u06D8", "");//ARABIC SMALL HIGH MEEM INITIAL FORM | |
input=input.replaceAll("\u06D9", "");//ARABIC SMALL HIGH LAM ALEF | |
input=input.replaceAll("\u06DA", "");//ARABIC SMALL HIGH JEEM | |
input=input.replaceAll("\u06DB", "");//ARABIC SMALL HIGH THREE DOTS | |
input=input.replaceAll("\u06DC", "");//ARABIC SMALL HIGH SEEN | |
input=input.replaceAll("\u06DD", "");//ARABIC END OF AYAH | |
input=input.replaceAll("\u06DE", "");//ARABIC START OF RUB EL HIZB | |
input=input.replaceAll("\u06DF", "");//ARABIC SMALL HIGH ROUNDED ZERO | |
input=input.replaceAll("\u06E0", "");//ARABIC SMALL HIGH UPRIGHT RECTANGULAR ZERO | |
input=input.replaceAll("\u06E1", "");//ARABIC SMALL HIGH DOTLESS HEAD OF KHAH | |
input=input.replaceAll("\u06E2", "");//ARABIC SMALL HIGH MEEM ISOLATED FORM | |
input=input.replaceAll("\u06E3", "");//ARABIC SMALL LOW SEEN | |
input=input.replaceAll("\u06E4", "");//ARABIC SMALL HIGH MADDA | |
input=input.replaceAll("\u06E5", "");//ARABIC SMALL WAW | |
input=input.replaceAll("\u06E6", "");//ARABIC SMALL YEH | |
input=input.replaceAll("\u06E7", "");//ARABIC SMALL HIGH YEH | |
input=input.replaceAll("\u06E8", "");//ARABIC SMALL HIGH NOON | |
input=input.replaceAll("\u06E9", "");//ARABIC PLACE OF SAJDAH | |
input=input.replaceAll("\u06EA", "");//ARABIC EMPTY CENTRE LOW STOP | |
input=input.replaceAll("\u06EB", "");//ARABIC EMPTY CENTRE HIGH STOP | |
input=input.replaceAll("\u06EC", "");//ARABIC ROUNDED HIGH STOP WITH FILLED CENTRE | |
input=input.replaceAll("\u06ED", "");//ARABIC SMALL LOW MEEM | |
//Remove tatweel | |
input=input.replaceAll("\u0640", ""); | |
//Remove tashkeel | |
input=input.replaceAll("\u064B", "");//ARABIC FATHATAN | |
input=input.replaceAll("\u064C", "");//ARABIC DAMMATAN | |
input=input.replaceAll("\u064D", "");//ARABIC KASRATAN | |
input=input.replaceAll("\u064E", "");//ARABIC FATHA | |
input=input.replaceAll("\u064F", "");//ARABIC DAMMA | |
input=input.replaceAll("\u0650", "");//ARABIC KASRA | |
input=input.replaceAll("\u0651", "");//ARABIC SHADDA | |
input=input.replaceAll("\u0652", "");//ARABIC SUKUN | |
input=input.replaceAll("\u0653", "");//ARABIC MADDAH ABOVE | |
input=input.replaceAll("\u0654", "");//ARABIC HAMZA ABOVE | |
input=input.replaceAll("\u0655", "");//ARABIC HAMZA BELOW | |
input=input.replaceAll("\u0656", "");//ARABIC SUBSCRIPT ALEF | |
input=input.replaceAll("\u0657", "");//ARABIC INVERTED DAMMA | |
input=input.replaceAll("\u0658", "");//ARABIC MARK NOON GHUNNA | |
input=input.replaceAll("\u0659", "");//ARABIC ZWARAKAY | |
input=input.replaceAll("\u065A", "");//ARABIC VOWEL SIGN SMALL V ABOVE | |
input=input.replaceAll("\u065B", "");//ARABIC VOWEL SIGN INVERTED SMALL V ABOVE | |
input=input.replaceAll("\u065C", "");//ARABIC VOWEL SIGN DOT BELOW | |
input=input.replaceAll("\u065D", "");//ARABIC REVERSED DAMMA | |
input=input.replaceAll("\u065E", "");//ARABIC FATHA WITH TWO DOTS | |
input=input.replaceAll("\u065F", "");//ARABIC WAVY HAMZA BELOW | |
input=input.replaceAll("\u0670", "");//ARABIC LETTER SUPERSCRIPT ALEF | |
//Replace Waw Hamza Above by Waw | |
input=input.replaceAll("\u0624", "\u0648"); | |
//Replace Ta Marbuta by Ha | |
input=input.replaceAll("\u0629", "\u0647"); | |
//Replace Ya | |
// and Ya Hamza Above by Alif Maksura | |
input=input.replaceAll("\u064A", "\u0649"); | |
input=input.replaceAll("\u0626", "\u0649"); | |
// Replace Alifs with Hamza Above/Below | |
// and with Madda Above by Alif | |
input=input.replaceAll("\u0622", "\u0627"); | |
input=input.replaceAll("\u0623", "\u0627"); | |
input=input.replaceAll("\u0625", "\u0627"); | |
return input; | |
} | |
/** | |
* @return the output | |
*/ | |
public String getOutput() { | |
return output; | |
} | |
public static void main(String[] args) { | |
String test = "كَلَّا لَا تُطِعْهُ وَاسْجُدْ وَاقْتَرِبْ ۩"; | |
System.out.println("Before: "+test); | |
test=new ArabicNormalizer(test).getOutput(); | |
System.out.println("After: "+test); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SpannedString result = new SpannedString(""); | |
for (int j=0;j<myString.length();j++){ | |
Spannable wordtoSpan = new SpannableString(myString.substring(j,j+1)); | |
if (arabicV.contains(myString.substring(j,j+1))) { | |
wordtoSpan.setSpan(new ForegroundColorSpan(Color.parseColor("#FF0000")), | |
0, 1, 0); | |
} | |
else | |
{ | |
wordtoSpan.setSpan(new ForegroundColorSpan(Color.parseColor( "#000000")), | |
0, 1, 0); | |
} | |
result = (SpannedString) TextUtils.concat(result,"",wordtoSpan); | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ABHArabicDiacritics objSearchd = new ABHArabicDiacritics(); | |
objSearchdobjSearch.getDiacriticinsensitive("وَ اَشْهَدُ اَنْ لا اِلهَ اِلاَّ اللَّهُ").contains("اشهد"); | |
ABHArabicDiacritics objSearch = new ABHArabicDiacritics( وَ اَشْهَدُ اَنْ لا اِلهَ اِلاَّ اللَّهُ, اشهد); | |
SpannableString spoutput=objSearch.getSearchHighlightedSpan(); | |
textView.setText(spoutput); | |
objSearch.isContain();// | |
objSearch.getSearchHighlightedSpan(); | |
objSearch.getSearchTextStartPosition(); | |
objSearch.getSearchTextEndPosition(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment