🖨️ esc/pos implementation in gleam

chore: remove accidental public function and add docs

okk.moe 3c8218e1 8e935c81

verified
+31 -15
+1 -5
src/escpos.gleam
··· 104 104 } 105 105 106 106 /// Sets text size multiplier (1-8 for width and height). 107 - pub fn text_size( 108 - cb: CommandBuffer, 109 - width: Int, 110 - height: Int, 111 - ) -> CommandBuffer { 107 + pub fn text_size(cb: CommandBuffer, width: Int, height: Int) -> CommandBuffer { 112 108 append(cb, protocol.character_size(width, height)) 113 109 } 114 110
+1 -5
src/escpos/document.gleam
··· 352 352 ) 353 353 } 354 354 Raw(b) -> 355 - do_build_ast( 356 - rest, 357 - [DoRaw(b), ..acc], 358 - State(..state, new_line: False), 359 - ) 355 + do_build_ast(rest, [DoRaw(b), ..acc], State(..state, new_line: False)) 360 356 } 361 357 } 362 358 }
+29 -5
src/escpos/image.gleam
··· 3 3 //// There are printers that can print grayscale or even color, if 4 4 //// you want to do that, you'll need to implement that yourself 5 5 //// and/or leverage the `protocol` module directly. 6 - //// 7 - //// 80mm printers usually have a maximum of 640 dots width. 8 - //// There is no validation so please check your image beforehand. 6 + //// 7 + //// 80mm printers usually have a maximum around 600 dots width. 8 + //// There is no validation so please check your image width beforehand. 9 + //// 10 + //// Images need to be supplied in PBM or PGM format. You can use tools like 11 + //// Imagemagick to convert your image. `magick img.png img.pgm` 12 + //// 13 + //// ## Example 14 + //// 15 + //// ```gleam 16 + //// import escpos/document 17 + //// import escpos/image 18 + //// import simplifile 19 + //// 20 + //// // PBM images are already monochrome — just parse and print 21 + //// let assert Ok(pbm) = simplifile.read_bits(from: "./logo.pbm") 22 + //// let assert Ok(img) = image.from_pbm(pbm) 23 + //// 24 + //// document.render([document.image(img), document.cut()]) 25 + //// 26 + //// // PGM images are grayscale and need dithering first 27 + //// let assert Ok(pgm) = simplifile.read_bits(from: "./photo.pgm") 28 + //// let assert Ok(img) = image.from_pgm(pgm) 29 + //// let img = image.dither_ign(img) 30 + //// 31 + //// document.render([document.image(img), document.cut()]) 32 + //// ``` 9 33 //// 10 34 //// Thank you jak for the pgm reading and bayer dithering 💕 11 35 ··· 126 150 dither_bayer(image, bias, bayer_4x4_matrix) 127 151 } 128 152 129 - pub fn bayer_2x2_matrix(row: Int, column: Int) -> Int { 153 + fn bayer_2x2_matrix(row: Int, column: Int) -> Int { 130 154 case row % 2 + 1, column % 2 + 1 { 131 155 1, 1 -> 0 132 156 1, 2 -> 127 ··· 137 161 } 138 162 } 139 163 140 - pub fn bayer_4x4_matrix(row: Int, column: Int) -> Int { 164 + fn bayer_4x4_matrix(row: Int, column: Int) -> Int { 141 165 case row % 4 + 1, column % 4 + 1 { 142 166 1, 1 -> 0 143 167 1, 2 -> 127