Skip to content

Commit e855efc

Browse files
committed
Removed unnecessary usage of Compat.
1 parent 9c8f210 commit e855efc

File tree

8 files changed

+108
-46
lines changed

8 files changed

+108
-46
lines changed

src/CDObject.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ using TimeZones
88
PDF files support the string format: (D:YYYYMMDDHHmmSSOHH'mm)
99
1010
"""
11-
@compat struct CDDate
11+
struct CDDate
1212
d::ZonedDateTime
1313
CDDate(d::ZonedDateTime) = new(d)
1414
end
@@ -30,7 +30,7 @@ end
3030

3131
Base.show(io::IO, dt::CDDate) = show(io, dt.d)
3232

33-
@compat struct CDRect{T <: Number}
33+
struct CDRect{T <: Number}
3434
llx::T
3535
lly::T
3636
urx::T

src/CosDoc.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ export CosDoc,
88
cosDocGetRoot,
99
cosDocGetObject
1010

11-
@compat abstract type CosDoc end
11+
abstract type CosDoc end
1212

13-
@compat mutable struct CosDocImpl <: CosDoc
13+
mutable struct CosDocImpl <: CosDoc
1414
filepath::String
1515
size::Int
1616
io::IOStream

src/CosObject.jl

Lines changed: 75 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,29 @@ export CosDict, CosString, CosNumeric, CosBoolean, CosTrue, CosFalse,
44
CosObject, CosNull, CosNullType,CosFloat, CosInt, CosArray, CosName,
55
CosDict, CosIndirectObjectRef, CosStream, get, set!
66

7-
@compat abstract type CosObject end
7+
abstract type CosObject end
88

99
@inline get{T<:CosObject}(o::T)=o.val
1010

11-
@compat abstract type CosString <: CosObject end
12-
@compat abstract type CosNumeric <: CosObject end
11+
abstract type CosString <: CosObject end
12+
abstract type CosNumeric <: CosObject end
1313

14-
@compat struct CosBoolean <: CosObject
14+
struct CosBoolean <: CosObject
1515
val::Bool
1616
end
1717

1818
const CosTrue=CosBoolean(true)
1919
const CosFalse=CosBoolean(false)
2020

21-
@compat struct CosNullType <: CosObject end
21+
struct CosNullType <: CosObject end
2222

2323
const CosNull=CosNullType()
2424

25-
@compat struct CosFloat <: CosNumeric
25+
struct CosFloat <: CosNumeric
2626
val::Float64
2727
end
2828

29-
@compat struct CosInt <: CosNumeric
29+
struct CosInt <: CosNumeric
3030
val::Int
3131
end
3232

@@ -35,40 +35,37 @@ A parsed data structure to ensure the object information is stored as an object.
3535
This has no meaning without a associated CosDoc. When a reference object is hit
3636
the object should be searched from the CosDoc and returned.
3737
"""
38-
@compat struct CosIndirectObjectRef <: CosObject
38+
struct CosIndirectObjectRef <: CosObject
3939
val::Tuple{Int,Int}
4040
CosIndirectObjectRef(num::Int, gen::Int)=new((num,gen))
4141
end
4242

43-
#hash(o::CosIndirectObjectRef, h::UInt=zero(UInt)) = hash(o.val, h)
44-
#isequal(r1::CosIndirectObjectRef, r2::CosIndirectObjectRef) = isequal(r1.val, r2.val)
45-
46-
@compat mutable struct CosIndirectObject{T <: CosObject} <: CosObject
43+
mutable struct CosIndirectObject{T <: CosObject} <: CosObject
4744
num::Int
4845
gen::Int
4946
obj::T
5047
end
5148

5249
get(o::CosIndirectObject) = get(o.obj)
5350

54-
@compat struct CosName <: CosObject
51+
struct CosName <: CosObject
5552
val::Symbol
5653
CosName(str::String)=new(Symbol("CosName_",str))
5754
end
5855

59-
@compat struct CosXString <: CosString
56+
struct CosXString <: CosString
6057
val::Vector{UInt8}
6158
CosXString(arr::Vector{UInt8})=new(arr)
6259
end
6360

64-
@compat struct CosLiteralString <: CosString
61+
struct CosLiteralString <: CosString
6562
val::Vector{UInt8}
6663
CosLiteralString(arr::Vector{UInt8})=new(arr)
6764
end
6865

6966
CosLiteralString(str::AbstractString)=CosLiteralString(transcode(UInt8,str))
7067

71-
@compat mutable struct CosArray <: CosObject
68+
mutable struct CosArray <: CosObject
7269
val::Array{CosObject,1}
7370
function CosArray(arr::Array{T,1} where {T<:CosObject})
7471
val = Array{CosObject,1}()
@@ -83,7 +80,7 @@ end
8380
get(o::CosArray, isNative=false)=isNative ? map((x)->get(x),o.val) : o.val
8481
length(o::CosArray)=length(o.val)
8582

86-
@compat mutable struct CosDict <: CosObject
83+
mutable struct CosDict <: CosObject
8784
val::Dict{CosName,CosObject}
8885
CosDict()=new(Dict{CosName,CosObject}())
8986
end
@@ -107,7 +104,7 @@ end
107104
set!(o::CosIndirectObject{CosDict}, name::CosName, obj::CosObject) =
108105
set!(o.obj, name, obj)
109106

110-
@compat mutable struct CosStream <: CosObject
107+
mutable struct CosStream <: CosObject
111108
extent::CosDict
112109
isInternal::Bool
113110
CosStream(d::CosDict,isInternal::Bool=true)=new(d,isInternal)
@@ -128,7 +125,7 @@ Decodes the stream and provides output as an BufferedInputStream.
128125
"""
129126
get(stm::CosStream) = decode(stm)
130127

131-
@compat mutable struct CosObjectStream <: CosObject
128+
mutable struct CosObjectStream <: CosObject
132129
stm::CosStream
133130
n::Int
134131
first::Int
@@ -161,7 +158,7 @@ set!(os::CosIndirectObject{CosObjectStream}, name::CosName, obj::CosObject)=
161158

162159
get(os::CosObjectStream) = get(os.stm)
163160

164-
@compat mutable struct CosXRefStream<: CosObject
161+
mutable struct CosXRefStream<: CosObject
165162
stm::CosStream
166163
isDecoded::Bool
167164
function CosXRefStream(s::CosStream,isDecoded::Bool=false)
@@ -181,6 +178,64 @@ set!(os::CosIndirectObject{CosXRefStream}, name::CosName, obj::CosObject)=
181178

182179
get(os::CosXRefStream) = get(os.stm)
183180

181+
"""
182+
Can be a Number Tree or a Name Tree.
183+
184+
`kids`: is `null` in case of a leaf node
185+
`range`: is `null` in case of a root node
186+
`values`: is `null` in case of an intermediate node
187+
188+
Intent: faster loookup without needing to load the complete tree structure. Hence, the tree
189+
will not be loaded on full scan.
190+
"""
191+
mutable struct CosTreeNode{K}
192+
values::Nullable{Vector{Pair{K,CosObject}}}
193+
kids::Nullable{Vector{CosIndirectObjectRef}}
194+
range::Nullable{Pair{K,K}}
195+
end
196+
197+
function createTreeNode(dict::CosObject)
198+
range = get(dict, CosName("Limits"))
199+
kids = get(dict, CosName("Kids"))
200+
names = get(dict, CosName("Names"))
201+
nums = get(dict, CosName("Nums"))
202+
203+
204+
end
205+
206+
#=
207+
function find_tree{S}(search_fn::Function, doc::CosDoc, root::CosObject, term::S)
208+
end
209+
210+
function find{K}(fn::Function, doc::CosDoc, node::CosTreeNode{K}, key::K)
211+
inrange = 0
212+
if (!isnull(node.range))
213+
inrange = (key < node.range[1]) ? -1 :
214+
(key > node.range[2]) ? 1 : 0
215+
end
216+
if inrange == 0
217+
if isnull(node.kids) # This is the leaf
218+
# TBD: look into the values.
219+
return (found, fn(key, node.values))
220+
end
221+
for kid in kids
222+
kidobj = cosDocGetObject(doc, kid)
223+
kidnode = CosTreeNode(kidobj)
224+
inrange, val = find(fn, doc, kidnode, key)
225+
if inrange == -1
226+
break
227+
elseif inrange == 0
228+
return (inrange,val)
229+
end
230+
end
231+
else
232+
return (inrange, nothing)
233+
end
234+
return (inrange, nothing)
235+
end
236+
237+
=#
238+
184239
# All show methods
185240

186241
show(io::IO, o::CosObject) = print(io, o.val)

src/CosReader.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ function read_internal_stream_data(ps::BufferedInputStream, extent::CosDict, len
285285
end
286286

287287

288-
@compat mutable struct CosObjectLoc
288+
mutable struct CosObjectLoc
289289
loc::Int
290290
stm::CosObject
291291
obj::CosObject

src/CosStream.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ function decode_filter(io, filters::CosArray, parms::CosObject)
114114
return bufstm
115115
end
116116

117-
@compat mutable struct PNGPredictorSource{T<:BufferedInputStream}
117+
mutable struct PNGPredictorSource{T<:BufferedInputStream}
118118
input::T
119119
predictor::UInt8
120120
columns::Int
@@ -265,7 +265,7 @@ function load_png_row!(source::PNGPredictorSource)
265265
return source
266266
end
267267

268-
@compat mutable struct RLEDecodeSource{T<:BufferedInputStream}
268+
mutable struct RLEDecodeSource{T<:BufferedInputStream}
269269
input::T
270270
run::Vector{UInt8}
271271
s::UInt8
@@ -354,7 +354,7 @@ function decode_rle(input::BufferedInputStream)
354354
return BufferedInputStream(RLEDecodeSource(input))
355355
end
356356

357-
@compat mutable struct ASCIIHexDecodeSource{T<:BufferedInputStream}
357+
mutable struct ASCIIHexDecodeSource{T<:BufferedInputStream}
358358
input::T
359359
isClosed::Bool
360360
end
@@ -389,7 +389,7 @@ function BufferedStreams.readbytes!{T<:BufferedInputStream}(
389389
nbreturn = ndata / 2
390390

391391
i = j = 0
392-
c = n = UInt(0) # Ensuring computation at the word boundary.
392+
c = n = UInt(0) # Ensuring computation at the word boundary.
393393
while i < nbreturn
394394
n = 0
395395
c = data[i+=1]
@@ -413,7 +413,7 @@ end
413413

414414
#This is still buggy. Needs to be worked upon.
415415

416-
@compat mutable struct ASCII85DecodeSource{T<:BufferedInputStream}
416+
mutable struct ASCII85DecodeSource{T<:BufferedInputStream}
417417
input::T
418418
residue::Vector{UInt8}
419419
isEOF::Bool

src/PDDoc.jl

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ export PDDoc,
22
pdDocOpen,
33
pdDocClose,
44
pdDocGetCatalog,
5+
pdDocGetNamesDict,
56
pdDocGetInfo,
67
pdDocGetCosDoc,
78
pdDocGetPageCount,
89
pdDocGetPage
910

1011
using ..Common
1112

12-
@compat abstract type PDDoc end
13+
abstract type PDDoc end
1314

1415
function pdDocOpen(fp::String)
1516
doc = PDDocImpl(fp)
@@ -44,15 +45,21 @@ function pdDocGetInfo(doc::PDDoc)
4445
ref = get(doc.cosDoc.trailer[1], CosName("Info"))
4546
obj = cosDocGetObject(doc.cosDoc, ref)
4647
dInfo = Dict{CDTextString, Union{CDTextString, CDDate}}()
47-
for (index, data) in enumerate(get(obj))
48-
skey = CDTextString(data[1])
48+
for (key, val) in get(obj)
49+
skey = CDTextString(key)
4950
dInfo[skey] = (skey == "CreationDate") || (skey == "ModDate") ?
50-
CDDate(data[2]) : CDTextString(data[2])
51+
CDDate(val) : CDTextString(val)
5152
end
5253
return dInfo
5354
end
5455

55-
@compat mutable struct PDDocImpl <: PDDoc
56+
function pdDocGetNamesDict(doc::PDDoc)
57+
catalog = pdDocGetCatalog(doc)
58+
ref = get(catalog, CosName("Names"))
59+
obj = cosDocGetObject(doc.cosDoc, ref)
60+
end
61+
62+
mutable struct PDDocImpl <: PDDoc
5663
cosDoc::CosDoc
5764
catalog::CosObject
5865
pages::CosObject

src/PDPage.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ export PDPage,
44
pdPageGetCosObject,
55
pdPageGetContentObjects
66

7-
@compat abstract type PDPage end
7+
abstract type PDPage end
88

9-
@compat mutable struct PDPageImpl <: PDPage
9+
mutable struct PDPageImpl <: PDPage
1010
doc::PDDocImpl
1111
cospage::CosObject
1212
contents::CosObject

src/PDPageElement.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
using BufferedStreams
22
import Base: show
33

4-
@compat abstract type PDPageObject end
4+
abstract type PDPageObject end
55

66
"""
77
*PDPageElement* type is a representation of organization of content and content
88
operators.
99
1010
The operands are like attributes of the element to be used for any operations.
1111
"""
12-
@compat mutable struct PDPageElement <: PDPageObject
12+
mutable struct PDPageElement <: PDPageObject
1313
t::Symbol
1414
version::Tuple{Int,Int}
1515
noperand::Int
@@ -29,7 +29,7 @@ function show(io::IO, e::PDPageElement)
2929
print(io, String(e.t))
3030
end
3131

32-
@compat mutable struct PDPageObjectGroup <: PDPageObject
32+
mutable struct PDPageObjectGroup <: PDPageObject
3333
isEOG::Bool
3434
objs::Vector{Union{PDPageObject,CosObject}}
3535
PDPageObjectGroup(isEOG::Bool=false)=
@@ -76,24 +76,24 @@ function collect_object(grp::PDPageObjectGroup,
7676
return elem
7777
end
7878

79-
@compat mutable struct PDPageTextObject <: PDPageObject
79+
mutable struct PDPageTextObject <: PDPageObject
8080
group::PDPageObjectGroup
8181
PDPageTextObject()=new(PDPageObjectGroup())
8282
end
8383

84-
@compat mutable struct PDPageMarkedContent <: PDPageObject
84+
mutable struct PDPageMarkedContent <: PDPageObject
8585
group::PDPageObjectGroup
8686
PDPageMarkedContent()=new(PDPageObjectGroup())
8787
end
8888

89-
@compat mutable struct PDPageInlineImage <: PDPageObject
89+
mutable struct PDPageInlineImage <: PDPageObject
9090
params::CosDict
9191
data::Vector{UInt8}
9292
isRead::Bool
9393
PDPageInlineImage()=new(CosDict(),Vector{UInt8}(),false)
9494
end
9595

96-
@compat mutable struct PDPage_BeginInlineImage <: PDPageObject
96+
mutable struct PDPage_BeginInlineImage <: PDPageObject
9797
elem::PDPageElement
9898
PDPage_BeginInlineImage(ts::AbstractString,ver::Tuple{Int,Int},nop)=
9999
new(PDPageElement(ts,ver,nop))
@@ -149,14 +149,14 @@ function collect_inline_image(img::PDPageInlineImage, elem::PDPageElement,
149149
end
150150

151151

152-
@compat mutable struct PDPage_BeginGroup <: PDPageObject
152+
mutable struct PDPage_BeginGroup <: PDPageObject
153153
elem::PDPageElement
154154
objT::Type
155155
PDPage_BeginGroup(ts::AbstractString,ver::Tuple{Int,Int},nop,t::Type)=
156156
new(PDPageElement(ts,ver,nop),t)
157157
end
158158

159-
@compat mutable struct PDPage_EndGroup
159+
mutable struct PDPage_EndGroup
160160
elem::PDPageElement
161161
PDPage_EndGroup(ts::AbstractString,ver::Tuple{Int,Int},nop)=
162162
new(PDPageElement(ts,ver,nop))

0 commit comments

Comments
 (0)