Help language development. Donate to The Perl Foundation

Gnome::Cairo cpan:MARTIMM last updated on 2022-02-20

t/Surface.rakutest
use v6;
use NativeCall;
use Test;

use Gnome::Cairo::ImageSurface;
use Gnome::Cairo::Surface;
#use Gnome::Cairo;

use Gnome::Cairo::Types;
use Gnome::Cairo::Enums;

#use Gnome::N::X;
#Gnome::N::debug(:on);

#-------------------------------------------------------------------------------
#my Gnome::Cairo $c;
my Gnome::Cairo::Surface $s;
my Gnome::Cairo::ImageSurface $is;
#-------------------------------------------------------------------------------
subtest 'ISA test', {
#  $s .= new;
#  ok $s.is-valid, '.new()';

  $is .= new( :format(CAIRO_FORMAT_RGB24), :width(100), :height(100));

  $s .= new( :similar($is), :content(CAIRO_CONTENT_COLOR_ALPHA));
  ok $s.is-valid, '.new(:similar)';

  $s .= new( :image($is), :format(CAIRO_FORMAT_ARGB32));
  ok $s.is-valid, '.new(:image)';

  $s .= new( :target($is), :10x, :10y, :100width, :100height);
  ok $s.is-valid, '.new(:target)';
}

#-------------------------------------------------------------------------------
# set environment variable 'raku-test-all' if rest must be tested too.
unless %*ENV<raku_test_all>:exists {
  done-testing;
  exit;
}

#-------------------------------------------------------------------------------
subtest 'Manipulations', {
  $is .= new(:png<t/data/Add.png>);
  is $is.write-to-png('t/data/Add2.png'), CAIRO_STATUS_SUCCESS,
    '.write-to-png()';
  't/data/Add2.png'.IO.unlink;

  my cairo_rectangle_int_t $rectangle .= new( :8x, :0y, :8width, :16height);
  $s .= new( :map($is), :$rectangle);
  is $is.write-to-png('t/data/Add2.png'), CAIRO_STATUS_SUCCESS,
    '.new( :map, :rectangle)';
  't/data/Add2.png'.IO.unlink;

  is $is.get-content, CAIRO_CONTENT_COLOR_ALPHA, '.get-content()';
  nok $is.get-device.defined, '.get-device()';

  $is.set-fallback-resolution( 100, 100);
  my Num ( $xr, $yr ) = $is.get-fallback-resolution;
  is-deeply ( $xr, $yr ), ( 100e0, 100e0),
    '.get-fallback-resolution() / .set-fallback-resolution()';

  is $is.get-type, CAIRO_SURFACE_TYPE_IMAGE, '.get-type()';
  nok $is.has-show-text-glyphs, '.has-show-text-glyphs()';

  $s.unmap-image($is);
  $is.clear-object;
}

#-------------------------------------------------------------------------------
done-testing;

=finish