Skip to content

Commit ab32889

Browse files
committed
FIX: handle text encoded stream data
1 parent 123702f commit ab32889

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/mezz/codec-pdf.reb

+14-7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ REBOL [
1515
The loading is not optimal. It tries to load all objects even these not referenced in cross-reference table.
1616
It can be changed in the future, but so far, purpose of the code is to learn some PDF implementation details.
1717
It is not designed for real life processing of large PDF documents.
18+
19+
Useful link for manual tests: https://www.pdf-online.com/osa/validate.aspx
1820
}
1921
]
2022

@@ -419,20 +421,25 @@ get-xref-count: function[xrefs n][
419421
to integer! n
420422
]
421423

422-
emit-stream: func[obj [object!]][
424+
emit-stream: func[obj [object!] /local data][
423425
unless find obj 'spec [
424426
extend obj 'spec #(Length: 0)
425427
]
426-
unless any [
427-
obj/spec/Filter
428-
300 > length? obj/data ; don't use compression on tiny strings
428+
data: any [obj/data #{}]
429+
unless any [ ; don't use compression
430+
obj/spec/Filter ; if there is already some filter
431+
300 > length? data ; if data are small enough
429432
][
430433
obj/spec/Filter: 'FlateDecode
431-
obj/data: compress/zlib obj/data
434+
data: compress/zlib obj/data
435+
]
436+
unless binary? data [
437+
; make sure that data are in binary, so the length is correct!
438+
data: to binary! data
432439
]
433-
obj/spec/Length: length? obj/data
440+
obj/spec/Length: length? data
434441
emit-obj obj/spec
435-
out: insert insert insert out "stream^M^/" obj/data "^M^/endstream"
442+
out: insert insert insert out "stream^M^/" data "^M^/endstream"
436443
]
437444

438445
rebol-version-str: rejoin ["Rebol/" system/product " Version " system/version]

0 commit comments

Comments
 (0)