makeText method
Stream the text operations required to draw the barcode texts. This is automatically called by make
Implementation
@override
Iterable<BarcodeElement> makeText(
String data,
double width,
double height,
double fontHeight,
double textPadding,
double lineWidth,
) sync* {
if (data.length <= 8) {
// Try to convert UPC-E to UPC-A
data = upceToUpca(data);
}
data = checkLength(data, maxLength);
final first = data.substring(0, 1);
final last = data.substring(11, 12);
try {
data = upcaToUpce(data);
} on BarcodeException {
if (fallback) {
yield* const BarcodeUpcA().makeText(
data,
width,
height,
fontHeight,
textPadding,
lineWidth,
);
return;
}
rethrow;
}
final w = lineWidth * 7;
final left = marginLeft(true, width, height, fontHeight, textPadding);
final right = marginRight(true, width, height, fontHeight, textPadding);
yield BarcodeText(
left: 0,
top: height - fontHeight,
width: left - lineWidth,
height: fontHeight,
text: first,
align: BarcodeTextAlign.right,
);
var offset = left + lineWidth * 3;
for (var i = 0; i < data.length; i++) {
yield BarcodeText(
left: offset,
top: height - fontHeight,
width: w,
height: fontHeight,
text: data[i],
align: BarcodeTextAlign.center,
);
offset += w;
}
yield BarcodeText(
left: width - right + lineWidth,
top: height - fontHeight,
width: right - lineWidth,
height: fontHeight,
text: last,
align: BarcodeTextAlign.left,
);
}