star-micronics / StarXpand-SDK-Android

StarXpand SDK for Android is a software development kit for supporting application development for Star Micronics devices.
https://star-m.jp/starxpandsdk-oml.html
Other
14 stars 2 forks source link

How can we print Khmer font? #6

Closed sornbarang closed 6 months ago

sornbarang commented 1 year ago

Description

I can't print in Khmer font. example: វិក័យប័ត្រ

Your printer

Tatsuki-Yamamoto2731 commented 1 year ago

Unfortunately, SM-L200 does not support Khmer font. However, you can print Khmer font by converting it to image data.

Here is a sample code for converting text to image data.

val settings = StarConnectionSettings(interfaceType, identifier)
val printer = StarPrinter(settings, applicationContext)

val textSize = 22
val printWidth = 576
val printText = "វិក័យប័ត្រ"
val typeface = Typeface.create(Typeface.MONOSPACE, Typeface.NORMAL)

val paint = Paint()
paint.textSize = textSize.toFloat()
paint.typeface = typeface

val textPaint = TextPaint(paint)

val staticLayoutBuilder = StaticLayout.Builder.obtain(printText, 0, printText.length, textPaint, printWidth)
     .setAlignment(Layout.Alignment.ALIGN_NORMAL)
     .setLineSpacing(0f, 1f)
     .setIncludePad(false)

val staticLayout = staticLayoutBuilder.build()

val bitmap: Bitmap = Bitmap.createBitmap(staticLayout.width, staticLayout.height, Bitmap.Config.ARGB_8888)

val canvas = Canvas(bitmap)
canvas.drawColor(Color.WHITE)
canvas.translate(0F, 0F)
staticLayout.draw(canvas)

val builder = StarXpandCommandBuilder()
builder.addDocument(
      DocumentBuilder()
              .addPrinter(
                        PrinterBuilder()
                                .actionPrintImage(ImageParameter(bitmap, 576))
                                .actionFeedLine(1)
                                .actionCut(CutType.Partial)
               )
)
val commands = builder.getCommands()

printer.openAsync().await()
printer.printAsync(commands).await()

Printing result: Khmer font

Tatsuki-Yamamoto2731 commented 6 months ago

I am closing this Issue. If you still have this issue, please reopen it.