Pure MoonBit PDF417 encoder: Text / Byte / Numeric compaction, the annex P mode selector, GF(929) Reed-Solomon parity with error repair, symbol layout, the annex A module patterns and SVG or ASCII rendering.
let codes : Array[Int] = []
for character in "HELLO WORLD 1234567890123".iter() {
codes.push(character.to_int())
}
let high = @pdf417.encode_high_level(codes) // data codewords
let symbol = @pdf417.finalize(high.codewords, 2, 4) // + descriptor, pad, parity
@pdf417.verify_symbol(symbol) // true| Area | API |
|---|---|
| Text Compaction | encode_text, encode_text_segment, decode_text, text_automaton |
| Numeric Compaction | encode_numeric, decimal_chunk_to_base900, base900_to_decimal, decode_numeric |
| Byte Compaction | encode_byte, bytes_to_base900, base900_to_bytes, decode_byte |
| Automatic mode selection | encode_high_level, consecutive_digits, consecutive_text, consecutive_binary |
| Error correction | error_correction, generator_polynomial, syndromes, correct_errors |
| Layout | finalize, rows_for, pad_codewords, plan_columns |
| Planning queries | data_capacity, recommended_level, smallest_symbol, geometry_of, symbol_modules |
| Structure | start_pattern, stop_pattern, left_row_indicator, right_row_indicator, symbol_rows |
| Low level | cluster_pattern, symbol_row_modules, symbol_matrix, verify_matrix, column_box, module_is_bar |
| Rendering | matrix_to_ascii, matrix_to_svg |
| Verification | verify_symbol, verify_matrix, is_error_free, round_trip_matches, decode_high_level |
moon add fan-ere/moon-pdf417-coreimport {
"fan-ere/moon-pdf417-core" @pdf417,
}moon check --deny-warn --target all
moon build --target all
moon test --deny-warn --target wasm
moon test --deny-warn --target wasm-gc
moon test --deny-warn --target js
moon run examples/quickstart --target wasmmoon run cmd/main --target native -- encode --data "HELLO WORLD 1234567890123" --level 2 --columns 4
moon run cmd/main --target native -- inspect --data "HELLO WORLD"
moon run cmd/main --target native -- capacity --level 2
moon run cmd/main --target native -- structure --columns 4 --rows 6 --level 2
moon run cmd/main --target native -- render --data "HELLO 1234" --format svg > symbol.svg
moon run cmd/main --target native -- render --data "HELLO 1234" --format ascii --scale 1| Job | What it covers |
|---|---|
| lint | moon fmt and moon info leave no diff |
| test (matrix) | moon check --deny-warn, moon build, moon test --deny-warn on wasm, wasm-gc, js and native |
| cli | runs examples/quickstart, the five cmd/main commands and checks the rendered SVG and ASCII output |
| tables | the generated tables match their generators, and the symbol character table matches the reference table |
pub suberror EncodeError {
EmptyInput
UnrepresentableChar(Int)
TooManyCodewords(Int)
InvalidErrorCorrectionLevel(Int)
InvalidColumnCount(Int)
LayoutImpossible(Int, Int)
TooManyErasures(Int, Int)
} derive(Debug)pub(all) enum Compaction {
Text
Numeric
Byte
Auto
}impl Eq for Compactionpub(all) struct Geometry {
width_modules : Int
height_rows : Int
data_columns : Int
data_rows : Int
ec_level : Int
}pub(all) struct Symbol {
codewords : Array[Int]
columns : Int
rows : Int
ec_level : Int
data_count : Int
pad_count : Int
}pub(all) enum TextSubmode {
Alpha
Lower
Mixed
Punctuation
}impl Eq for TextSubmodefn byte_capacity(count : Int) -> Intfn byte_count_codewords(count : Int) -> Intlet byte_group_codewords : Intlet byte_group_size : Intfn cluster_pattern(cluster : Int, codeword : Int) -> Int?fn column_box(column : Int, columns : Int, rows : Int, scale : Int, quiet : Int) -> (Int, Int, Int, Int)fn correct_errors(words : Array[Int], parity_count : Int, erasures : Array[Int]) -> (Array[Int], Array[Int]) raise EncodeErrorfn data_capacity(columns : Int, level : Int) -> Intfn encode_byte_segment(input : Array[Int], start : Int, count : Int) -> Array[Int] raise EncodeErrorfn encode_numeric_segment(input : Array[Int], start : Int, count : Int) -> Array[Int] raise EncodeErrorfn encode_text_segment(input : Array[Int], start : Int, count : Int, initial : TextSubmode) -> (Array[Int], TextSubmode) raise EncodeErrorfn error_correction_codeword_count(level : Int) -> Intfn error_locator_of(position : Int, length : Int) -> Intfn inverse929(value : Int) -> Intfn is_alpha_lower(code : Int) -> Boolfn is_alpha_upper(code : Int) -> Boolfn is_byte_group_multiple(count : Int) -> Boolfn is_punctuation(code : Int) -> Boolfn is_text_byte(code : Int) -> Boolfn is_text_code(code : Int) -> Boolfn is_valid_layout(columns : Int, rows : Int) -> Boolfn is_valid_pattern(pattern : Int, modules : Int) -> Boollet latch_byte_padded : Intfn left_row_indicator(row : Int, rows : Int, columns : Int, ec_level : Int) -> Intfn module_is_bar(pattern : Int, modules : Int, index : Int) -> Boollet numeric_chunk_size : Intfn pad_codewords(source_codewords : Int, ec_codewords : Int, columns : Int, rows : Int) -> Int?fn plan_columns(source_codewords : Int, ec_codewords : Int, min_cols : Int, max_cols : Int, min_r : Int, max_r : Int) -> (Int, Int)?fn plan_rows(source_codewords : Int, ec_codewords : Int, columns : Int, min_rows : Int) -> Intfn recommended_level(n : Int) -> Int?fn right_row_indicator(row : Int, rows : Int, columns : Int, ec_level : Int) -> Intfn row_codeword_count(columns : Int) -> Intfn rows_for(source_codewords : Int, ec_codewords : Int, columns : Int) -> Intfn smallest_symbol(codewords : Int, ec_level : Int) -> (Int, Int)?let start_pattern : Intfn symbol_codeword_capacity(columns : Int, rows : Int) -> Intfn symbol_modules(columns : Int) -> Int 17 + 17 * (columns + 2) + 18 = 69 + 17 * columnsfn symbol_row_modules(codewords : Array[Int], row : Int, columns : Int, rows : Int, ec_level : Int) -> Array[Int] raise EncodeErrorfn text_automaton(input : Array[Int], start : Int, count : Int, initial : TextSubmode) -> (Array[Int], TextSubmode) raise EncodeErrorInstall
Download zipPure MoonBit PDF417 encoder: Text / Byte / Numeric compaction, the annex P mode selector, GF(929) Reed-Solomon parity with error repair, symbol layout, the annex A module patterns and SVG or ASCII rendering.