How to ajust Arabic 'aarab' characters? Please see my code

筅森魡賤 提交于 2020-01-23 03:41:06

问题


I am trying to display arabic text with custom font. my code is as following:

package com.androidbook.test;

import java.io.BufferedInputStream;
import java.io.InputStream;

import org.apache.http.util.ByteArrayBuffer;

import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;
import android.widget.TextView;

public class ArabicTextActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.arabic_display);

        TextView arabicTextView;
          Typeface arabicFont;

          arabicTextView = (TextView)findViewById(R.id.arabicTextDisplayTextView);
          arabicFont =Typeface.createFromAsset(getAssets(),"me_quran.ttf");
          arabicTextView.setTypeface(arabicFont);     
          arabicTextView.setTextSize(40);

            InputStream is = getResources().openRawResource(R.raw.arabic_text); 
            BufferedInputStream bis = new BufferedInputStream(is);
            int myInt=0;

            try{
                ByteArrayBuffer myByteArray = new ByteArrayBuffer(100); 
                while((myInt = bis.read())!=-1)
                {
                    if(myInt == 10) break;
                    myByteArray.append((byte)myInt);
                }

                String arabicLine = new String(myByteArray.toByteArray(), 0, myByteArray.length(), "UTF-8");
                arabicTextView.setText(arabicLine);
            }catch(Exception ex)
            {
                ex.printStackTrace();
            }
    }

}

and arabic_display.xml is:

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/quranDisplayItemLinearLayout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        android:orientation="vertical">

        <TextView
            android:id="@+id/arabicTextDisplayTextView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="Arabic" />

    </LinearLayout> 

where res/raw/as arabic_text.txt is displayed in notepad as (font name: me_quran.ttf and font size 40)

but in simulator it is shown as:

you can notice that small characters (called aaraab characters in arabic) are not adjusted at all.. how should i fix this? /////////////////////////////////////////////////////////////////// ///////////

//// /////

RESULT AFTER USING DroidSansArabic.ttf


回答1:


Judging by the charmap of the "me_quran.ttf" , it looks like what the simulator is showing is what it ought to show. This font looks way too different from other arabic fonts that I've seen, you might want to get a hold on another font.




回答2:


This is my font. It is a valid opentype font, and has some advance features that most other arabic font does not have.

The problem here is with Android. It's arabic support is too basic, it does not understand advance typography features that this font has. You won't be able to get a good arabic display with. The best you can get is probably with something like tahoma, which uses same position for it's diacritics.

To solve this problem, i've updated the font to make it work with Android and Iphone. Unfortunately, due to the nature of these platform, one could never be able to use standard arabic text to get a good arabic support. What I did was use a modified text so that I get the result I wanted. The result is a basic font, but much better looking than those system font. Sorry I can't post an image (new user here)

Just a reminder, me_quran is not a free font. It's only free for free projects. If you would like to get my solution, you can contact me directly.



来源:https://stackoverflow.com/questions/9256149/how-to-ajust-arabic-aarab-characters-please-see-my-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!