[mapserver-dev] mapscript styleObj and colorObj

Steve Lime sdlime at gmail.com
Mon Dec 23 09:40:09 PST 2019


I don't think we're missing anything. There are general set/get methods
already for a colorObj - just two flavors since you can specify colors in
two ways (tuple and hex). It seems like that should be sufficient and we
wouldn't want to pollute the interface adding colorObj get/set methods
everywhere. I whipped up a similar script in Perl MapScript and it behaves
as expected:

#!/usr/bin/perl

use mapscript74;

my $style = new mapscript74::styleObj();

$style->updateFromString("STYLE COLOR  1 2 3 END");
print "$style->{color}->{red} $style->{color}->{green}
$style->{color}->{blue} $style->{color}->{alpha}\n";

$style->{color}->setRGB(100, 150, 200);
print "$style->{color}->{red} $style->{color}->{green}
$style->{color}->{blue} $style->{color}->{alpha}\n";

$style->{color}->setHex('#FF00007F');
print "$style->{color}->{red} $style->{color}->{green}
$style->{color}->{blue} $style->{color}->{alpha}\n";

print $style->convertToString() ."\n";

Which outputs:

1 2 3 255
100 150 200 255
255 0 0 127
STYLE
  COLOR "#ff00007f"
END # STYLE

There must be something else going on. Are you referring to master? (I can
still do something like "$style->{color}->{red} = 128;" in 7.4)

--Steve

On Sun, Dec 22, 2019 at 8:41 AM Seth G <sethg at geographika.co.uk> wrote:

> Hi all,
>
> A general mapscript question I'm hoping someone can provide some
> information on.
> Should any attribute that is a C class be read-only in SWIG, and requires
> getters/setters to update?
>
> For example the styleObj attributes [1] includes a color property that is
> of type colorObj. This can be set in MapScript, but I believe this causes
> undefined behaviour, and any property that is not a basic int/str/float
> type will need a setter function added in the SWIG interface files.
>
> For example the following Python script runs without crashing, however
> when output back to a Mapfile contains strange results:
>
>     import mapscript
>
>     style = mapscript.styleObj()
>
>     style.updateFromString("""
>     STYLE
>         COLOR  1 2 3
>     END # STYLE
>     """)
>
>     success = style.color.setRGB(100, 150, 200)
>     # the following asserts all pass
>     assert success == mapscript.MS_SUCCESS
>
>     assert style.color.red == 100
>     assert style.color.green == 150
>     assert style.color.blue == 200
>     assert style.color.alpha == 255
>
>     print(style.convertToString())
>
>
> Outputs the following:
>
> STYLE
>   COLOR 200 255 3
> END # STYLE
>
> Note the blue value has become red, the alpha green, and I don't know
> where the 3 comes from.
>
> I'm guessing the setter function for the styleObj color needs to be added?
>
> Seth
>
> [1] https://mapserver.org/mapscript/mapscript.html#styleobj-attributes
>
> --
> web:http://geographika.co.uk
> twitter: @geographika
> _______________________________________________
> mapserver-dev mailing list
> mapserver-dev at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/mapserver-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-dev/attachments/20191223/321a0ca5/attachment.html>


More information about the mapserver-dev mailing list