decodeStreamData function
Applies the filters of dict over raw.
Handles /FlateDecode (with and without a zlib header) and
/ASCIIHexDecode, including the /DecodeParms predictor that follows a
Flate stream. Returns null when the filter is not supported — LZW, DCT,
JPX and RunLength do not show up in content streams or in /ToUnicode in
practice.
Implementation
Uint8List? decodeStreamData(
PdfDocumentParser parser, PdfDictToken dict, Uint8List raw) {
var data = raw;
final predictor =
PdfParserXref.readPredictorParams(parser.resolve(dict.values['/DecodeParms']));
for (final filter in _filterNames(parser, dict.values['/Filter'])) {
switch (filter) {
case '/FlateDecode':
case '/Fl':
final inflated = _inflate(data);
if (inflated == null) return null;
// A predictor left in place would decode to garbage, silently.
data = PdfParserPredictor.apply(inflated, predictor);
break;
case '/ASCIIHexDecode':
case '/AHx':
data = _asciiHexDecode(data);
break;
default:
return null;
}
}
return data;
}