encode method
BitMatrix
encode(
- String contents,
- BarcodeFormat format,
- int width,
- int height, [
- EncodeHint? hints,
override
@param contents The contents to encode in the barcode @param format The barcode format to generate @param width The preferred width in pixels @param height The preferred height in pixels @param hints Additional parameters to supply to the encoder @return BitMatrix representing encoded barcode image @throws WriterException if contents cannot be encoded legally in a format
Implementation
@override
BitMatrix encode(
String contents,
BarcodeFormat format,
int width,
int height, [
EncodeHint? hints,
]) {
if (format != BarcodeFormat.pdf417) {
throw ArgumentError('Can only encode PDF_417, but got $format');
}
final encoder = PDF417();
int margin = _whiteSpace;
int errorCorrectionLevel = _defaultErrorCorrectionLevel;
bool autoECI = false;
if (hints != null) {
if (hints.pdf417Compact == true) {
encoder.setCompact(hints.pdf417Compact);
}
if (hints.pdf417Compaction != null) {
encoder.setCompaction(hints.pdf417Compaction!);
}
if (hints.pdf417Dimensions != null) {
final dimensions = hints.pdf417Dimensions!;
encoder.setDimensions(
dimensions.maxCols,
dimensions.minCols,
dimensions.maxRows,
dimensions.minRows,
);
}
if (hints.margin != null) {
margin = hints.margin!;
}
if (hints.errorCorrection != null) {
errorCorrectionLevel = hints.errorCorrection!;
}
if (hints.characterSet != null) {
final encoding = CharacterSetECI.getCharacterSetECIByName(
hints.characterSet!,
)?.charset;
if (encoding != null) encoder.setEncoding(encoding);
}
autoECI = hints.pdf417AutoEci;
}
return _bitMatrixFromEncoder(
encoder,
contents,
errorCorrectionLevel,
width,
height,
margin,
autoECI,
);
}