<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl

use strict;
use warnings;
use Cairo;

use constant
{
	WIDTH =&gt; 450,
	HEIGHT =&gt; 900,
	NUM_STRINGS =&gt; 3,
	M_PI =&gt; 4 * atan2(1, 1),
};

{
	my $surface = Cairo::ImageSurface-&gt;create ('argb32', WIDTH, HEIGHT);
	my $cr = Cairo::Context-&gt;create ($surface);

	$cr-&gt;set_source_rgb (0.0, 0.0, 0.0);

	$cr-&gt;translate (40, 40);

	$cr-&gt;select_font_face ('mono', 'normal', 'normal');
	$cr-&gt;set_font_size (12);
	$cr-&gt;show_text ('+CTM rotation');

	$cr-&gt;save;
	$cr-&gt;select_font_face ('serif', 'normal', 'normal');
	$cr-&gt;set_font_size (40);
	for (my $i = 0; $i &lt; NUM_STRINGS; $i++) {
		my $angle = $i * 0.5 * M_PI / (NUM_STRINGS - 1);
		$cr-&gt;save;
		$cr-&gt;rotate ($angle);
		$cr-&gt;move_to (100, 0);
		$cr-&gt;show_text ("Text");
		$cr-&gt;restore;
	}
	$cr-&gt;restore;

	$cr-&gt;translate (0, HEIGHT / 3);

	$cr-&gt;move_to (0, 0);
	$cr-&gt;show_text ('+CTM rotation');
	$cr-&gt;rel_move_to (0, 12);
	$cr-&gt;show_text ('-font rotation');

	$cr-&gt;save;
	$cr-&gt;select_font_face ('serif', 'normal', 'normal');
	$cr-&gt;set_font_size (40);
	for (my $i = 0; $i &lt; NUM_STRINGS; $i++) {
		my $angle = $i * 0.5 * M_PI / (NUM_STRINGS - 1);
		$cr-&gt;save;
		$cr-&gt;rotate ($angle);
		my $matrix = Cairo::Matrix-&gt;init_identity;
		$matrix-&gt;scale (40, 40);
		$matrix-&gt;rotate (-$angle);
		$cr-&gt;set_font_matrix ($matrix);
		$cr-&gt;move_to (100, 0);
		$cr-&gt;show_text ('Text');
		$cr-&gt;restore;
	}
	$cr-&gt;restore;

	$cr-&gt;translate (0, HEIGHT / 3);

	$cr-&gt;move_to (0, 0);
	$cr-&gt;show_text ('+CTM rotation');
	$cr-&gt;rel_move_to (0, 12);
	$cr-&gt;show_text ('-CTM rotation');

	$cr-&gt;save;
	$cr-&gt;select_font_face ('serif', 'normal', 'normal');
	$cr-&gt;set_font_size (40);
	for (my $i = 0; $i &lt; NUM_STRINGS; $i++) {
		my $angle = $i * 0.5 * M_PI / (NUM_STRINGS - 1);
		$cr-&gt;save;
		$cr-&gt;rotate ($angle);
		$cr-&gt;move_to (100, 0);
		$cr-&gt;rotate (-$angle);
		$cr-&gt;show_text ('Text');
		$cr-&gt;restore;
	}
	$cr-&gt;restore;

	$surface-&gt;write_to_png ('text-rotate.png');
}
</pre></body></html>