Skip to content

Commit

Permalink
Adjusting 0.7 fixes for 0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
sambitdash committed Jul 22, 2018
1 parent a8bc2e4 commit 8d92089
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 21 deletions.
9 changes: 5 additions & 4 deletions src/CosDoc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,10 @@ function find_page_label(doc::CosDoc, values::Vector{Tuple{Int,CosObject}},
ln = notnothing(lno)
ln < start && throw(ErrorException(E_INVALID_PAGE_NUMBER))
found_page = prev_pageno + 1 + ln - start
found_page <= pageno && return range(found_page, length=1)
found_page <= pageno && return Compat.range(found_page, length=1)
else
return range(prev_pageno + 1, length=(pageno - prev_pageno))
return Compat.range(prev_pageno + 1,
length=(pageno - prev_pageno))
end
found = false
prev_pageno = pageno
Expand Down Expand Up @@ -480,12 +481,12 @@ function find_page_label(doc::CosDoc, values::Vector{Tuple{Int,CosObject}},
end
end
found && lno === nothing &&
return range(prev_pageno + 1, length=(pageno - prev_pageno))
return Compat.range(prev_pageno + 1, length=(pageno - prev_pageno))
if found && lno !== nothing
ln = notnothing(lno)
ln < start && throw(ErrorException(E_INVALID_PAGE_NUMBER))
found_page = prev_pageno + 1 + ln - start
return range(found_page, length=1)
return Compat.range(found_page, length=1)
end
throw(ErrorException(E_INVALID_PAGE_NUMBER))
end
Expand Down
8 changes: 7 additions & 1 deletion src/CosReader.jl
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,13 @@ end
Parse a float from the given bytes vector, starting at `from` and ending at the
byte before `to`. Bytes enclosed should all be ASCII characters.
"""
float_from_bytes(bytes::Vector{UInt8}) = tryparse(Float64, String(bytes))
function float_from_bytes(bytes::Vector{UInt8})
res = tryparse(Float64, String(bytes))
res === nothing && return res
res isa Float64 && return res
isnull(res) && return nothing
return get(res)
end

"""
Parse an integer from the given bytes vector, starting at `from` and ending at
Expand Down
2 changes: 1 addition & 1 deletion src/Inflate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const Z_MEM_ERROR = -4
const Z_BUF_ERROR = -5
const Z_VERSION_ERROR = -6

@static if Sys.iswindows()
@static if Compat.Sys.iswindows()
const libz = "zlib1"
else
const libz = "libz"
Expand Down
15 changes: 9 additions & 6 deletions src/PDFontMetrics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mutable struct AdobeFontMetrics
name_to_b::Dict{CosName, Vector{Int}}
kern_pairs::Dict{Tuple{CosName, CosName}, Tuple{Int, Int}}
has_kerning::Bool
italicAngle::Int
italicAngle::Float32
isFixedPitch::Bool
weight::Symbol

Expand All @@ -30,12 +30,15 @@ isBold(afm::AdobeFontMetrics) = afm.weight === :Bold
isItalic(afm::AdobeFontMetrics) = afm.italicAngle != 0
isFixedW(afm::AdobeFontMetrics) = afm.isFixedPitch

get_font_flags(afm::AdobeFontMetrics) =
isItalic(afm) ? 0x00000040 : 0x00000000 +
isFixedW(afm) ? 0x00000001 : 0x00000000
function get_font_flags(afm::AdobeFontMetrics)
res = 0x00000000
isItalic(afm) && (res += 0x00000040)
isFixedW(afm) && (res += 0x00000001)
return res
end

function interpret_metric_line(line::AbstractString)
tokens = split(line, ';'; keepempty=false)
tokens = Compat.split(line, ';'; keepempty=false)
cid = -1; wx = 1000; n = "null"; bb = [0,0,0,0]
for token in tokens
v = split(strip(token), ' '; limit = 2)
Expand Down Expand Up @@ -108,7 +111,7 @@ function read_afm(fontname::AbstractString)
(line, state) = next(lines, state)
if startswith(line, "ItalicAngle")
v = split(line)
afm.italicAngle = parse(Int, v[2])
afm.italicAngle = parse(Float32, v[2])
elseif startswith(line, "IsFixedPitch")
v = split(line)
afm.isFixedPitch = parse(Bool, v[2])
Expand Down
10 changes: 5 additions & 5 deletions src/PDFonts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,11 @@ SPACE_CODE(w::CIDWidth) = get_character_code(cn"space", w)
INIT_CODE(x) = 0x00
SPACE_CODE(x) = get_character_code(cn"space", x)

isBold(pdfont::PDFont) = (pdfonts.flags & 0x80000000) > 0
isItalic(pdfont::PDFont) = (pdfonts.flags & 0x00000040) > 0
isFixedW(pdfont::PDFont) = (pdfonts.flags & 0x00000001) > 0
isAllCap(pdfont::PDFont) = (pdfonts.flags & 0x00010000) > 0
isSmallCap(pdfont::PDFont) = (pdfonts.flags & 0x00020000) > 0
isBold(pdfont::PDFont) = (pdfont.flags & 0x80000000) > 0
isItalic(pdfont::PDFont) = (pdfont.flags & 0x00000040) > 0
isFixedW(pdfont::PDFont) = (pdfont.flags & 0x00000001) > 0
isAllCap(pdfont::PDFont) = (pdfont.flags & 0x00010000) > 0
isSmallCap(pdfont::PDFont) = (pdfont.flags & 0x00020000) > 0

# Not supported FD attribute in CIDFonts
@inline function get_font_flags(doc::PDDoc, cosfont::CosObject, widths)
Expand Down
8 changes: 4 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using Compat
using Compat.Test
using PDFIO
using PDFIO.PD
using PDFIO.Cos
using PDFIO.Common
using Test

# Internal methods for testing only
using PDFIO.Cos: parse_indirect_ref, decode_ascii85, CosXString
Expand Down Expand Up @@ -220,11 +220,11 @@ include("debugIO.jl")
doc = pdDocOpen(filename)
@assert pdDocGetPageCount(doc) == 54
@assert PDFIO.Cos.cosDocGetPageNumbers(doc.cosDoc, doc.catalog, "title") ==
range(1, length=1)
Compat.range(1, length=1)
@assert PDFIO.Cos.cosDocGetPageNumbers(doc.cosDoc, doc.catalog, "ii") ==
range(3, length=1)
Compat.range(3, length=1)
@assert PDFIO.Cos.cosDocGetPageNumbers(doc.cosDoc, doc.catalog, "42") ==
range(46, length=1)
Compat.range(46, length=1)
pdDocGetPageRange(doc, "iii")
pdDocClose(doc)
length(utilPrintOpenFiles()) == 0
Expand Down

0 comments on commit 8d92089

Please sign in to comment.