Skip to content

Commit

Permalink
Merge pull request #315 from tlnagy/tn/batch-limit-fix
Browse files Browse the repository at this point in the history
updated #267 and fixed printing error
  • Loading branch information
tlnagy authored Oct 21, 2018
2 parents 9e8f3ef + ac5f62d commit afb9b07
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/cairo_backends.jl
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,11 @@ function push_property_frame(img::Image, properties::Vector{Property})
isp = isscalar.(properties)
scalar_properties = Dict{Type, Property}(typeof(x)=>x for x in properties[isp])
vector_properties = Dict{Type, Property}(typeof(x)=>x for x in properties[.!isp])

kt = [Property{FillOpacityPrimitive}, Property{FillPrimitive}]
if haskey(scalar_properties, kt[1]) && haskey(vector_properties, kt[2])
alpha = scalar_properties[kt[1]].primitives[1].value
vector_properties[kt[1]] = fillopacity(fill(alpha, length(vector_properties[kt[2]].primitives)))
vector_properties[kt[1]] = fillopacity(fill(alpha, length(vector_properties[kt[2]].primitives)))
pop!(scalar_properties, kt[1])
end

Expand All @@ -297,7 +297,7 @@ function push_property_frame(img::Image, properties::Vector{Property})
frame.vector_properties = vector_properties
push!(img.property_stack, frame)
isempty(scalar_properties) && return

save_property_state(img)
for (_, property) in scalar_properties
apply_property(img, property.primitives[1])
Expand Down
1 change: 1 addition & 0 deletions src/pgf_backend.jl
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ function push_property_frame(img::PGF, properties::Vector{Property})
push!(scalar_properties, property)
push!(applied_properties, typeof(property))
frame.has_scalar_properties = true
img.vector_properties[typeof(property)] = nothing
else
frame.vector_properties[typeof(property)] = property
img.vector_properties[typeof(property)] = property
Expand Down
11 changes: 6 additions & 5 deletions src/svg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ function SVG(out::IO,
has_current_id = false,
id_count = 0,
jsheader = Set{AbstractString}(),
jsmodules = Set{Tuple{AbstractString, AbstractString}}((("Snap.svg", "Snap"),)),
jsmodules = Set{Tuple{AbstractString, AbstractString}}((("Snap.svg", "Snap"),)),
scripts = AbstractString[],
withjs = jsmode != :none,
panelcoords = ())
Expand Down Expand Up @@ -684,7 +684,7 @@ function print_property(img::SVG, property::JSCallPrimitive)
end

# Print the property at the given index in each vector property
function print_vector_properties(img::SVG, idx::Int, supress_fill::Bool=false)
function print_vector_properties(img::SVG, idx::Int, suppress_fill::Bool=false)
if haskey(img.vector_properties, JSCall)
if haskey(img.vector_properties, SVGID)
img.current_id = img.vector_properties[SVGID].primitives[idx].value
Expand All @@ -699,7 +699,7 @@ function print_vector_properties(img::SVG, idx::Int, supress_fill::Bool=false)

for (propertytype, property) in img.vector_properties
if property === nothing ||
(propertytype == Fill && supress_fill)
(propertytype == Fill && suppress_fill)
continue
end

Expand Down Expand Up @@ -1110,6 +1110,7 @@ function push_property_frame(img::SVG, properties::Vector{Property})
push!(scalar_properties, property)
push!(applied_properties, typeof(property))
frame.has_scalar_properties = true
img.vector_properties[typeof(property)] = nothing
else
frame.vector_properties[typeof(property)] = property
img.vector_properties[typeof(property)] = property
Expand Down Expand Up @@ -1200,7 +1201,7 @@ function Compose.draw(img::SVG, prim::ArcPrimitive, idx::Int)
y2 = ry*sin(prim.angle2)
= prim.angle2 - prim.angle1
+= 2π*(dθ<0)

indent(img)
img.indentation += 1
print(img.out, "<g transform=\"translate(")
Expand All @@ -1213,7 +1214,7 @@ function Compose.draw(img::SVG, prim::ArcPrimitive, idx::Int)
indent(img)

print(img.out, "<path d=\"M")
prim.sector && print(img.out,"0,0 L")
prim.sector && print(img.out,"0,0 L")
svg_print_float(img.out, x1)
print(img.out, ",")
svg_print_float(img.out, y1)
Expand Down
1 change: 1 addition & 0 deletions test/REQUIRE
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Cairo
EzXML
4 changes: 2 additions & 2 deletions test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ end
Random.seed!(23)
withoutcompose = rand()
Random.seed!(23)
draw(SVG(), compose(context()))
draw(SVG(10cm, 8cm, false), compose(context()))
withcompose = rand()
@test withoutcompose == withcompose
end
Expand All @@ -161,4 +161,4 @@ end
@test getfield.(img1.vector_properties[Compose.Property{Compose.FillOpacityPrimitive}].primitives, :value) == [0.3, 0.3]
@test occursin("fill-opacity=\"0.3\"", a)
@test all(occursin.(["fill=\"rgba(255,0,0,1)\"","fill=\"rgba(0,0,255,1)\""], a))
end
end
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
using Compose
using Test

include("misc.jl")
@testset "SVG Correctness Tests" begin
include("svg.jl")
end
include("immerse.jl")

# Run the examples
Expand Down
19 changes: 19 additions & 0 deletions test/svg.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Test
using EzXML
using Colors
using Measures

@testset "Issue 267" begin
c = compose(context(), fill(["red", "blue"]),
[context(), fill("green"), circle([0.25, 0.75], [0.5], [0.25])])
img = SVG(8cm, 6cm, false)
draw(img, c)
svgxml = root(parsexml(String(img.out.data)))
# get all grouped values that have the fill attribute
fillcolors = nodecontent.(findall("//ns:g[@fill]/@fill", svgxml, ["ns"=>namespace(svgxml)]))
# there should only be a single color (because green should clobber the red
# and blue colors)
@test length(fillcolors) == 1
# make sure it's green
@test fillcolors[1] == "rgba(0,128,0,1)"
end

0 comments on commit afb9b07

Please sign in to comment.