From dd978494da1ee06c8c2ce88651b35aec5378e85e Mon Sep 17 00:00:00 2001 From: kimikage Date: Fri, 28 Aug 2020 05:09:44 +0900 Subject: [PATCH] Remove depwarn for X11 color names with spaces This also removes `color(::AbstractString)` and depreates `parse(::Type, ::Colorant)`. --- docs/namedcolorcharts.jl | 2 +- docs/src/constructionandconversion.md | 9 --------- src/names_data.jl | 2 +- src/parse.jl | 18 +++++++++--------- test/parse.jl | 10 ++++------ 5 files changed, 15 insertions(+), 26 deletions(-) diff --git a/docs/namedcolorcharts.jl b/docs/namedcolorcharts.jl index b28e3bcf..01024c8b 100644 --- a/docs/namedcolorcharts.jl +++ b/docs/namedcolorcharts.jl @@ -78,7 +78,7 @@ function ColorChartSVG(colorcategory) write(io, """$name""") else m = match(r"^(dark|pale|light|lemon|medium|blanched|(?:.+(?=white|blue|purple|blush)))(.+)$", name) - if m != nothing + if m !== nothing write(io, """$(m.captures[1])""") write(io, """$(m.captures[2])""") else diff --git a/docs/src/constructionandconversion.md b/docs/src/constructionandconversion.md index 039e3f27..b903cc12 100644 --- a/docs/src/constructionandconversion.md +++ b/docs/src/constructionandconversion.md @@ -111,15 +111,6 @@ julia> parse(RGB{N0f16}, "indianred") RGB{N0f16}(0.80392,0.36078,0.36078) ``` -You can also pass a color (`Colorant` value) to the second argument of the -[`parse`](@ref) function, but in this case, `parse` does not apply any -conversion on the color. - -```jldoctest example -julia> parse(RGB{N0f8}, HSL{Float64}(120, 1, 0.5)) # use `convert` instead -HSL{Float64}(120.0,1.0,0.5) -``` - You can convert colors to hexadecimal strings using the [`hex`](@ref) function. Note that the conversion result does not have the prefix `"#"`. diff --git a/src/names_data.jl b/src/names_data.jl index 2f486938..0a503ad6 100644 --- a/src/names_data.jl +++ b/src/names_data.jl @@ -142,8 +142,8 @@ const color_names = Dict( "firebrick3" => (205, 38, 38), "firebrick4" => (139, 26, 26), "floralwhite" => (255, 250, 240), - "fuchsia" => (255, 0, 255), "forestgreen" => ( 34, 139, 34), + "fuchsia" => (255, 0, 255), "gainsboro" => (220, 220, 220), "ghostwhite" => (248, 248, 255), "gold" => (255, 215, 0), diff --git a/src/parse.jl b/src/parse.jl index a45b6df1..2789ddc4 100644 --- a/src/parse.jl +++ b/src/parse.jl @@ -136,15 +136,9 @@ function _parse_colorant(desc::String) ldesc == "transparent" && return RGBA{N0f8}(0,0,0,0) - wo_spaces = replace(ldesc, r"(?<=[^ ]{3}) (?=[^ ]{3})" => "") + wo_spaces = replace(ldesc, r"(?<=[^bfptuv ][^p ][adeghk-rtwy]) (?=[^efinq ][aeh-mo-rtuy][^kw \d][a-y]{0,7}\b)" => "") c = get(color_names, wo_spaces, nothing) - if c !== nothing - camel = replace(titlecase(ldesc), " " => "") - Base.depwarn( - """ - The X11 color names with spaces are not recommended because they are not allowed in the SVG/CSS. - Use "$camel" or "$wo_spaces" instead. - """, :parse) + if c !== nothing && sizeof(wo_spaces) > 6 return RGB{N0f8}(n0f8(c[1]), n0f8(c[2]), n0f8(c[3])) end @@ -211,7 +205,13 @@ function Base.parse(::Type{C}, desc::AbstractString) where {C<:Colorant} end Base.parse(::Type{C}, desc::Symbol) where {C<:Colorant} = parse(C, string(desc)) -Base.parse(::Type{C}, c::Colorant) where {C<:Colorant} = c + +@noinline function Base.parse(::Type{C}, c::Colorant) where {C<:Colorant} + Base.depwarn(""" + `parse(::Type, ::Coloarant)` is deprecated. + Do not call `parse` if the object does not need to be parsed.""", :parse) + c +end """ @colorant_str(ex) diff --git a/test/parse.jl b/test/parse.jl index d379ec50..6cbf4610 100644 --- a/test/parse.jl +++ b/test/parse.jl @@ -6,16 +6,14 @@ using FixedPointNumbers # Color parsing # named-color redN0f8 = parse(Colorant, "red") - @test colorant"red" == redN0f8 - @test isa(redN0f8, RGB{N0f8}) - @test redN0f8 == RGB(1,0,0) + @test colorant"red" === redN0f8 + @test redN0f8 === RGB{N0f8}(1,0,0) @test parse(RGB{Float64}, "red") === RGB{Float64}(1,0,0) @test isa(parse(HSV, "blue"), HSV) @test_throws ErrorException parse(Colorant, "p ink") @test parse(Colorant, "transparent") === RGBA{N0f8}(0,0,0,0) @test parse(Colorant, "\nSeaGreen ") === RGB{N0f8}(r8(0x2E),r8(0x8B),r8(0x57)) - seagreen = @test_logs (:warn, r"Use \"SeaGreen\" or \"seagreen\"") parse(Colorant, "sea GREEN") - @test seagreen == colorant"seagreen" + @test parse(Colorant, "sea GREEN") === colorant"seagreen" # hex-color @test parse(Colorant, "#D0FF58") === RGB(r8(0xD0),r8(0xFF),r8(0x58)) @@ -50,6 +48,6 @@ using FixedPointNumbers @test parse(Colorant, "hsl( 120 50% 7% / 1)") === HSLA{Float32}(120,.5,.07, 1) # CSS Color Module Level 4 @test parse(Colorant, :red) === colorant"red" - @test parse(Colorant, colorant"red") === colorant"red" + @test_deprecated parse(Colorant, colorant"red") === colorant"red" end