"KARASIK via RT" <bug-Prima@rt.cpan.org> writes:
Show quoted text>
>> In some of my own code I've still got the .
>
> Do you have a good algorithm with this combination that can be used
> generally here?
Oh, the FillArc+DrawArc I only arrived at the same as you presumably
did.
Show quoted text> Does that also include the half-width GC line, you
> mentioned above?
Concept code below for the half-width idea. Apologies for it being gtk
based. Gtk is bloat on top of xlib, draw_arc() is XDrawArc.
To do a 20x10 ellipse it draws line width 5 with the ellipse line at
y=2. This means the line extends up by 2.5 from the centre of the y=2
pixel, thus taking in the whole of the y=0 pixel.
Not certain if I've got the rounding right for all different odd/even
sizes (or modulo 4 or what :-).
Slightly ironically I don't think this works for 5x3, because the 3 ends
up drawing h=0, and the same missing end pixel as the other 5x1 ticket!
At any rate, this may be an idea for bigger ones. height==3 or width==3
could be made a special case with three lines or a little polygon or
something. The middle of the 3 rows is full width, and not too hard to
take a sqrt() for how many pixels desired on the two top and bottom
rows.
use 5.008;
use strict;
use warnings;
use Gtk2 '-init';
use List::Util 'min';
my $width = 20;
my $height = 10;
my $rootwin = Gtk2::Gdk->get_default_root_window;
my $pixmap = Gtk2::Gdk::Pixmap->new ($rootwin, $width, $height, -1);
my $black = Gtk2::Gdk::Color->new(0,0,0,0);
my $gc = Gtk2::Gdk::GC->new ($rootwin,
{ line_width => 1,
foreground => $black,
});
$pixmap->draw_rectangle ($gc,
1, # fill
0, 0,
$width,$height);
my $line_width = min ($height/2, $width/2);
$line_width = int($line_width + .5); # up to integer
$line_width += !($line_width&1); # up to next odd integer
print "line_width=$line_width\n";
my $white = Gtk2::Gdk::Color->new(0xFFFF,0xFFFF,0xFFFF,0xFFFFFF);
$gc = Gtk2::Gdk::GC->new ($rootwin,
{ line_width => $line_width,
function => 'xor',
foreground => $white,
});
my $shrink = int($line_width/2); # round down
print "shrink=$shrink\n";
my $x = 0 + $shrink;
my $y = 0 + $shrink;
my $w = $width-1 - 2*$shrink;
my $h = $height-1 - 2*$shrink;
print "x=$x, y=$y, w=$w, h=$h\n";
$pixmap->draw_arc ($gc,
0, # unfilled
$x,$y, $w,$h,
0, 360*64);
print "\n";
my $pixbuf = Gtk2::Gdk::Pixbuf->get_from_drawable
($pixmap, undef, 0,0, 0,0, $width,$height);
$pixbuf->save ('/tmp/x.png', 'png');
system ("convert -monochrome /tmp/x.png /tmp/x.xpm && cat /tmp/x.xpm");
exit 0;