W3C home > Mailing lists > Public > www-svg@w3.org > January 2014

Re: Float values in rgb() colour values

From: Dirk Schulze <dschulze@adobe.com>
Date: Mon, 27 Jan 2014 13:25:46 +0000
To: Paul LeBeau <paul.lebeau@gmail.com>
CC: www-svg <www-svg@w3.org>
Message-ID: <B2AAFEB2-6099-4646-8C62-0DA9E0012499@adobe.com>

On Jan 26, 2014, at 9:03 PM, Paul LeBeau <paul.lebeau@gmail.com> wrote:

> So it turns out that Adobe InDesign - before SVG export was removed post-CS3 - generated files with rgb() component values that are floats rather than integers.  I discovered this after a user of my rendering library reported a rendering "bug".
> 
> After experimenting, I see that all three of Chrome, FF and IE allow float values in percentage components, but not normal components.  In the following test file, the first rect is displayed, but not the second.
> 
> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
> <svg xmlns="http://www.w3.org/2000/svg" version="1.1"
>    width="100%" height="100%"
>    viewBox="0 0 200 200">
> 
>   <!-- Test float values in rgb() colour declarations.
>        The Adobe InDesign SVG export filter (present in CS3 and earlier) generated
>        these erroneous type of values. -->
>   <rect x="50" y="50" width="50" height="80" fill="rgb(100.5%,-4%, 33.3%)" />
>   <rect x="100" y="50" width="50" height="80" fill="rgb(255, 0, 85.3)" />
>   
>   <text x="100" y="160" text-anchor="middle" font-size="8">Accept bad Adobe InDesign colour declarations</text>
> </svg>
> 
> How did it come about that the browsers all support floats in percentages?  All versions of the spec, including SVG2, specify that they should be integers.  Is it just a case of choosing to be permissive?  If so, why do non-percent components not get the same treatment?

The relevant spec is CSS3 Colors [1] now have been for most browsers all along. CSS Colors says:

“The format of an RGB value in the functional notation is ‘rgb(’ followed by a comma-separated list of three numerical values (either three integer values or three percentage values) followed by ‘)’. The integer value 255 corresponds to 100%, and to F or FF in the hexadecimal notation: rgb(255,255,255) = rgb(100%,100%,100%) = #FFF. White space characters are allowed around the numerical values.”

A percentage value according to CSS Units and Values [2]...

“... consists of a <number> immediately followed by a percent sign ‘%’”.

A three <number> version is under consideration for CSS Color 4[3] but in the range of [0,255].

Greetings,
Dirk

[1] http://www.w3.org/TR/css3-color/#colorunits
[2] http://www.w3.org/TR/2013/CR-css3-values-20130730/#percentages
[3] http://dev.w3.org/csswg/css-color/#typedef-component
> 
> Cheers
> 
> Paul
> 
> 
Received on Monday, 27 January 2014 13:26:26 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 22:54:50 UTC