Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indian language tamil font is not printing #517

Closed
sjnaveenkumar opened this issue Apr 30, 2024 · 5 comments
Closed

Indian language tamil font is not printing #517

sjnaveenkumar opened this issue Apr 30, 2024 · 5 comments

Comments

@sjnaveenkumar
Copy link

I'm trying to print "தமிழ்" Font in HOP-E801 thermal printer but it is printing random characters instead of tamil.

I get to know that Tamil is supported at page 68 from epson-biz. Also i tried with charsets like "UTF-8", "ISO-8859-1", "CP864".

No luck so far. It would be great if someone can help me with this issue. Thanks in advance.

@nrs1022
Copy link

nrs1022 commented May 1, 2024

Hi, printing non-english characters depends mainly of your printer support.

Advice: Try to convert your text as image, then print the image. It makes your print more device independant.

@sjnaveenkumar
Copy link
Author

@nrs1022 I can able to print the font in this App.

@nrs1022
Copy link

nrs1022 commented May 4, 2024

@nrs1022 I can able to print the font in this App.

It's because app probably does text-to-image convert before printing. Most chinese printers has fonts supporting english and (of course) chinese characters. To print any another character you'll have to pass text in canvas to a Bitmap, then print the Bitmap.

@nrs1022
Copy link

nrs1022 commented May 4, 2024

You can try with this code. It puts text on a StaticLayout and put it on a canvas to return a Bitmap.

 Bitmap getMultiLangTextAsImage(String text, float textSize, Typeface typeface)  {
        TextPaint mPaint = new TextPaint();
        mPaint.setColor(Color.BLACK);
        if (typeface != null) mPaint.setTypeface(typeface);
        mPaint.setTextSize(textSize);
        Layout.Alignment alignment = Layout.Alignment.ALIGN_NORMAL;
        StaticLayout mStaticLayout = new StaticLayout(text, mPaint, 385, alignment, 1.0f, 0, false);

        int width = mStaticLayout.getWidth();
        int height = mStaticLayout.getHeight();

        Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

        Canvas canvas = new Canvas(bitmap);

        canvas.drawColor(Color.WHITE);

        mStaticLayout.draw(canvas);

        return bitmap;
    }

StaticLayout was my choice because we could print with HTML tags too, in that case replace
StaticLayout(text...
with
StaticLayout(Html.fromHtml(text, Html.FROM_HTML_MODE_LEGACY)...

The Bitmap has max width of 385px but you can put more text, in this case text will be multilined.

In my app:

EscPosPrinter printer = new EscPosPrinter(BluetoothPrintersConnections.selectFirstPaired(), 203, 48f, 32);
Bitmap xb = getMultiLangTextAsImage("á é í ó ú ñ Ñ தமிழ்", 24, Typeface.DEFAULT_BOLD);
printer.printFormattedText("[C]<img>"+PrinterTextParserImg.bitmapToHexadecimalString(printer,xb) + "</img>\n");

It will print your text with size 24 and bold typeface. Feel free to test it and improve it to your needs.

EDIT: Code was extracted from a working app of mine, removed unnecesary code.

@sjnaveenkumar
Copy link
Author

@nrs1022 Thank you very much for the help. It worked as i expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants