Record Class PrinterProfile

java.lang.Object
java.lang.Record
io.github.chkrishnatej.rp3200.PrinterProfile
Record Components:
charsPerLine - number of Font A columns on one line (at least 8)
codePage - ESC t code page number sent at the start of each receipt (0 = PC437 on Epson-compatible printers), 0..255
charset - Java charset matching codePage, used to turn text into bytes
replacements - text substitutions applied before encoding, for characters the printer's code page does not have; copied, never null afterwards

public record PrinterProfile(int charsPerLine, int codePage, Charset charset, Map<String,String> replacements) extends Record
Describes the physical printer: how many characters fit on a line and how text is encoded.

The TVS RP 3200 Lite prints 72 mm at 203 DPI = 576 dots. With the default Font A (12 dots wide) that is 48 characters on 80 mm paper and 32 characters on 58 mm paper. Use the constants for those two cases:


 PrinterProfile.RP3200_80MM                       // 48 chars, PC437, Rupee sign -> "Rs."
 PrinterProfile.RP3200_58MM                       // 32 chars
 PrinterProfile.RP3200_80MM.withReplacement("₹", "INR ")   // customise
 

Profiles are immutable and thread-safe; the with... methods return new profiles. Any other ESC/POS printer works too - create a profile with its line width.

Character set

Text is sent in the printer's code page (PC437 by default, which covers ASCII plus Western European accents and box-drawing characters). Before encoding, the replacements() are applied - by default the Rupee sign becomes "Rs.", curly quotes become straight quotes, dashes become - and the ellipsis becomes .... Anything still unprintable becomes ?. Indian scripts (Tamil, Devanagari, ...) cannot be printed as text by this printer.

  • Field Details

    • RP3200_80MM

      public static final PrinterProfile RP3200_80MM
      TVS RP 3200 Lite with 80 mm paper: 48 characters per line, code page PC437, default replacements. This is the default used by ReceiptTemplate.render(Object).
    • RP3200_58MM

      public static final PrinterProfile RP3200_58MM
      TVS RP 3200 Lite with 58 mm paper: 32 characters per line, code page PC437, default replacements.
  • Constructor Details

    • PrinterProfile

      public PrinterProfile(int charsPerLine, int codePage, Charset charset, Map<String,String> replacements)
      Creates a profile. Prefer the constants and with... methods for normal use.
      Parameters:
      charsPerLine - number of Font A columns on one line
      codePage - ESC t code page number, 0..255
      charset - Java charset matching codePage
      replacements - substitutions applied before encoding; may be null (none)
      Throws:
      IllegalArgumentException - if charsPerLine < 8 or codePage is out of range
      NullPointerException - if charset is null
  • Method Details

    • withCharsPerLine

      public PrinterProfile withCharsPerLine(int chars)
      Returns a copy with a different line width, e.g. 64 when the printer is set to the smaller Font B.
      Parameters:
      chars - characters per line, at least 8
      Returns:
      the new profile
    • withCodePage

      public PrinterProfile withCodePage(int page, Charset cs)
      Returns a copy that uses another code page. The printer's code page number and the Java charset must describe the same table, e.g. withCodePage(19, Charset.forName("IBM858")) for PC858 (PC437 plus the Euro sign) on Epson-compatible printers. Check the printer's self-test page for the numbers it supports.
      Parameters:
      page - the ESC t code page number, 0..255
      cs - the matching Java charset
      Returns:
      the new profile
    • withReplacement

      public PrinterProfile withReplacement(String from, String to)
      Returns a copy with one extra (or overridden) text replacement, e.g. withReplacement("₹", "INR ") to print the Rupee sign as "INR ".
      Parameters:
      from - the text to replace
      to - what to print instead
      Returns:
      the new profile
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • charsPerLine

      public int charsPerLine()
      Returns the value of the charsPerLine record component.
      Returns:
      the value of the charsPerLine record component
    • codePage

      public int codePage()
      Returns the value of the codePage record component.
      Returns:
      the value of the codePage record component
    • charset

      public Charset charset()
      Returns the value of the charset record component.
      Returns:
      the value of the charset record component
    • replacements

      public Map<String,String> replacements()
      Returns the value of the replacements record component.
      Returns:
      the value of the replacements record component