LibGfx/JBIG2: Implement support for transposed text regions

Only the coordinates get transposed -- the bitmaps apparently don't.
And all the prose amounts to "if the transposed bit is set, swap
instance s and t coordinates before painting", as far as I can tell.

Makes pages 3/4 and 7/8 in 0001346.pdf render. (But here the feature
isn't used to render transposed text -- it just has stripes that keep s
roughy constant, which would normally produce vertical runs but here
produces regular horizontal runs. It's not clear to me why this feature
is used for these pages!)
This commit is contained in:
Nico Weber 2024-03-30 19:36:09 -07:00 committed by Andreas Kling
parent ca6ebedf58
commit b04569c1da
Notes: sideshowbarker 2024-07-17 06:45:52 +09:00

View File

@ -1211,9 +1211,6 @@ static ErrorOr<NonnullOwnPtr<BitBuffer>> text_region_decoding_procedure(TextRegi
if (inputs.uses_huffman_encoding)
return Error::from_string_literal("JBIG2ImageDecoderPlugin: Cannot decode huffman text regions yet");
if (inputs.is_transposed)
return Error::from_string_literal("JBIG2ImageDecoderPlugin: Cannot decode transposed text regions yet");
auto decoder = TRY(JBIG2::ArithmeticDecoder::initialize(data));
// 6.4.6 Strip delta T
@ -1440,15 +1437,12 @@ static ErrorOr<NonnullOwnPtr<BitBuffer>> text_region_decoding_procedure(TextRegi
// If any part of IBI, when placed at this location, lies outside the bounds of SBREG, then ignore
// this part of IBI in step 3 c) ix)."
// Implementor's note: The spec means "ignore this part of IBI in step 3 c) x)" in 3c viii)'s last sentence.
// FIXME: Support all reference corners and transpose values.
if (!inputs.is_transposed) {
if (inputs.reference_corner == TopRight || inputs.reference_corner == BottomRight)
s_instance -= symbol.width() - 1;
if (inputs.reference_corner == BottomLeft || inputs.reference_corner == BottomRight)
t_instance -= symbol.height() - 1;
} else {
TODO();
}
if (inputs.reference_corner == TopRight || inputs.reference_corner == BottomRight)
s_instance -= symbol.width() - 1;
if (inputs.reference_corner == BottomLeft || inputs.reference_corner == BottomRight)
t_instance -= symbol.height() - 1;
if (inputs.is_transposed)
swap(s_instance, t_instance);
// "ix) If COLEXTFLAG is 1, set the colour specified by SBCOLS[SBFGCOLID[NINSTANCES]]
// to the foreground colour of the symbol instance bitmap IBI."