File: 20_shaper.t

package info (click to toggle)
libharfbuzz-shaper-perl 0.031%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 204 kB
  • sloc: perl: 1,282; makefile: 3
file content (93 lines) | stat: -rw-r--r-- 1,803 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#! perl

use strict;
use warnings;
use utf8;
use charnames ':full';

-d 't' && chdir 't';

use Test::More tests => 2;
BEGIN { use_ok('HarfBuzz::Shaper') };

my $hb = HarfBuzz::Shaper->new;

$hb->set_font('/usr/share/fonts/truetype/lohit-devanagari/Lohit-Devanagari.ttf');
$hb->set_size(36);
$hb->set_text(
  "\N{DEVANAGARI LETTER TA}".
  "\N{DEVANAGARI LETTER MA}".
  "\N{DEVANAGARI VOWEL SIGN AA}".
  "\N{DEVANAGARI LETTER NGA}".
  "\N{DEVANAGARI SIGN VIRAMA}".
  "\N{DEVANAGARI LETTER GA}"
);
my $info = $hb->shaper;
#use DDumper; DDumper($info);
my $result = [
  {
#    ax => '21.384',		# harfbuzz 1.8.7
    ax => '21.348',		# harfbuzz 2.6.4
    ay => 0,
    dx => 0,
    dy => 0,
    g => 341,
    name => 'tadeva',
  },
  {
    ax => '20.34',
    ay => 0,
    dx => 0,
    dy => 0,
    g => 351,
    name => 'madeva',
  },
  {
#    ax => '9.36',		# harfbuzz 1.8.7
    ax => '9.324',		# harfbuzz 2.6.4
    ay => 0,
    dx => 0,
    dy => 0,
    g => 367,
    name => 'aasigndeva',
  },
  {
    ax => '23.904',
    ay => 0,
    dx => 0,
    dy => 0,
    g => 611,
    name => 'ngadeva_viramadeva_gadeva',
  },
];

ok(compare( $info, $result ), "content" );

sub compare {
    my ( $soll, $ist ) = @_;
    unless ( @$ist == @$soll ) {
	diag( scalar(@$ist) . " elements, must be " . scalar(@$soll) );
	return;
    }

    for ( 0 .. @$ist-1 ) {
	my $i = $ist->[$_];
	my $j = $soll->[$_];
	unless ( $i->{g} == $j->{g} ) {
	    diag( "CId $i->{g} must be $j->{g}" );
	    return;
	}
	unless ( $i->{name} eq $j->{name} ) {
	    diag( "Name $i->{name} must be $j->{name}" );
	    return;
	}
	for ( qw( ax ay dx dy ) ) {
	    next if $i->{$_} == $j->{$_};
	    unless ( abs( $i->{$_} - $j->{$_} ) <= abs($j->{$_} / 100) ) {
		diag( "$_ $i->{$_} must be $j->{$_}" );
		return;
	    }
	}
    }
    return 1;
}