Skip to content

Commit 42bafe5

Browse files
committed
Support for multiple content streams per page
1 parent 78e5736 commit 42bafe5

File tree

3 files changed

+44
-25
lines changed

3 files changed

+44
-25
lines changed

src/CosStream.jl

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import Libz:BufferedStreams.readbytes!
44

55
import BufferedStreams:readbytes!
66

7-
export cosStreamRemoveFilters,
8-
decode
7+
export cosStreamRemoveFilters,
8+
merge_streams,
9+
decode
910

1011
function _not_implemented(input)
1112
error(E_NOT_IMPLEMENTED)
@@ -83,6 +84,27 @@ function cosStreamRemoveFilters(stm::CosObject)
8384
return stm
8485
end
8586

87+
function merge_streams(stms::CosArray)
88+
(path,io) = get_tempfilepath()
89+
try
90+
dict = CosDict()
91+
println(path)
92+
set!(dict, cn"F", CosLiteralString(path))
93+
ret = CosStream(dict, false)
94+
v = get(stms)
95+
for stm in v
96+
bufstm = decode(stm)
97+
data = read(bufstm)
98+
close(bufstm)
99+
write(io, data)
100+
end
101+
return ret
102+
finally
103+
util_close(io)
104+
end
105+
return CosNull
106+
end
107+
86108
"""
87109
Reads the filter data and decodes the stream.
88110
"""

src/PDPage.jl

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -101,31 +101,29 @@ converted to an actual stream object
101101
get_page_content_ref(page::PDPageImpl) = get(page.cospage, cn"Contents")
102102

103103
function get_page_contents(page::PDPageImpl, contents::CosArray)
104-
len = length(contents)
105-
for i = 1:len
106-
ref = splice!(get(contents), 1)
107-
cosstm = get_page_contents(page,ref)
108-
if (cosstm != CosNull)
109-
push!(get(contents),cosstm)
104+
len = length(contents)
105+
arr = get(contents)
106+
for i = 1:len
107+
ref = splice!(arr, 1)
108+
cosstm = get_page_contents(page, ref)
109+
if (cosstm !== CosNull)
110+
push!(arr, cosstm)
111+
end
110112
end
111-
end
112-
return contents
113+
return merge_streams(contents)
113114
end
114115

115-
function get_page_contents(page::PDPageImpl, contents::CosIndirectObjectRef)
116-
return cosDocGetObject(page.doc.cosDoc, contents)
117-
end
116+
get_page_contents(page::PDPageImpl, contents::CosIndirectObjectRef) =
117+
cosDocGetObject(page.doc.cosDoc, contents)
118118

119-
function get_page_contents(page::PDPage, contents::CosObject)
120-
return CosNull
121-
end
119+
get_page_contents(page::PDPage, obj::CosObject) = obj
122120

123121
function load_page_objects(page::PDPageImpl)
124122
contents = pdPageGetContents(page)
125123
if (isnull(page.content_objects))
126-
page.content_objects=Nullable(PDPageObjectGroup())
124+
page.content_objects = Nullable(PDPageObjectGroup())
127125
end
128-
load_page_objects(page, contents)
126+
return load_page_objects(page, contents)
129127
end
130128

131129
load_page_objects(page::PDPageImpl, stm::CosNullType) = nothing
@@ -137,12 +135,13 @@ function load_page_objects(page::PDPageImpl, stm::CosObject)
137135
finally
138136
close(bufstm)
139137
end
138+
return nothing
140139
end
141140

142-
function load_page_objects(page::PDPageImpl, stm::CosArray)
143-
for s in get(stm)
144-
load_page_objects(page,s)
145-
end
141+
function load_page_objects(page::PDPageImpl, stms::CosArray)
142+
stm = merge_streams(stms)
143+
page.contents = stm
144+
return load_page_objects(page, stm)
146145
end
147146

148147

src/PDPageElement.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,9 @@ function populate_element(grp::PDPageObjectGroup, elem::PDPageElement)
101101
unshift!(elem.operands,operand)
102102
end
103103
else
104-
len=endof(grp.objs)
105-
while(isa(grp.objs[len],CosObject))
104+
while(isa(grp.objs[end],CosObject))
106105
operand=pop!(grp.objs)
107106
unshift!(elem.operands,operand)
108-
len = endof(grp.objs)
109107
end
110108
end
111109
end

0 commit comments

Comments
 (0)