简体   繁体   中英

Why does this piece of code make text center align?

I am doing some Android programming for a receipt printer from Star Micronics. In the sample code it provides, there is a line I do not quite understand. I am puzzled by the fact that it is somewhat linking to assembly language or some sort of machine specific instructions.

ArrayList<Byte> list = new ArrayList<Byte>();
Byte[] tempList;

// Alignment (center)                   
list.addAll(Arrays.asList(new Byte[]{0x1b, 0x1d, 0x61, 0x01}));

Can someone tell me how that line achieves the center alignment?

This is almost surely a command sequence that is sent to the printer. The exact meaning depends on the printer model, but the byte values correspond to the following character sequence:

<ESC><GS>a<01>

If this were, say, a TSP200 series printer, then according to the programmer's manual (page 58) it corresponds to the function "Enable/disable automatic status transmission". Since you say that the effect is center alignment, I'm guessing it's simply a different printer model. Just check the escape sequences in the appropriate programmers manual.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM