修改使用热敏打印机打印的阿拉伯字母

问题描述 投票:0回答:1

我设法用热敏打印机打印阿拉伯字符串。但是,字符是相反的(从左到右而不是从右到左书写)。我通过反转字符串的字符来解决该问题,效果很好。现在,我遇到了一个新问题,因为阿拉伯语单词结尾的某些字符的形状与所附照片中的错误。

enter image description here

我该如何解决?

第一行中的单词应为“السلام”,如图所示。

第二行的正确单词应为“النوع”,如图所示。

这是我要打印的代码

 void sendData() throws IOException {
        try {
            byte[] ALLINEA_CT = {0x1B, 0x61, 0x01}; //text to center

            String title = new StringBuilder("السلام").reverse().toString()+ '\n';
            mmOutputStream.write(ALLINEA_CT);
            mmOutputStream.write(title.getBytes("ISO-8859-6"));


            String kind =new StringBuilder("النوع").reverse().toString();
            String number = new StringBuilder("العدد").reverse().toString();
            String cost = new StringBuilder("التكلفة").reverse().toString();
            String BILL = "";
            BILL = BILL+ "-----------------------------\n";
            BILL = BILL + String.format("%1$4s %2$4s %3$17s",cost,number,kind);
            mmOutputStream.write(BILL.getBytes("ISO-8859-6"));


        } catch (Exception e) {
            e.printStackTrace();
        }
    }

这是建立连接的方式

      OutputStream mmOutputStream;
      InputStream mmInputStream;
      BluetoothAdapter mBluetoothAdapter;
      BluetoothSocket mmSocket;
      BluetoothDevice mmDevice;


void findBT() {

        try {
            mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

            if(mBluetoothAdapter == null) {

            }

            if(!mBluetoothAdapter.isEnabled()) {
                Intent enableBluetooth = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
                startActivityForResult(enableBluetooth, 0);
            }

            Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();

            if(pairedDevices.size() > 0) {
                for (BluetoothDevice device : pairedDevices) {

                    if (device.getName().equals(printername)) {
                        mmDevice = device;
                        break;
                    }
                }
            }


        }catch(Exception e){
            e.printStackTrace();
        }
    }



    // tries to open a connection to the bluetooth printer device
    void openBT() throws IOException {
        try {

            // Standard SerialPortService ID
            UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb");
            mmSocket = mmDevice.createRfcommSocketToServiceRecord(uuid);
            mmSocket.connect();
            mmOutputStream = mmSocket.getOutputStream();
            mmInputStream = mmSocket.getInputStream();


        } catch (Exception e) {
            e.printStackTrace();
        }
    }
android printing arabic arabic-support
1个回答
0
投票
Bitmap bitmap = Bitmap.createBitmap(256+128, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); canvas.drawColor(Color.WHITE); Strint text = "السلام"; canvas.drawText(text, 20, 20, new Paint()); printImage(bitmap);

我正在使用此代码来打印图像https://github.com/MFori/Android-Bluetooth-Printer

© www.soinside.com 2019 - 2024. All rights reserved.