-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add face unicode-set() and unicode-to-gid-map()
Along with new HarfBUzz::Set and HafrBuzz::Map classes
- Loading branch information
Showing
6 changed files
with
128 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
unit class HarfBuzz::Map; | ||
|
||
use HarfBuzz::Set; | ||
use HarfBuzz::Raw; | ||
use HarfBuzz::Raw::Defs :types; | ||
|
||
has hb_map:D $!raw handles<elems> = hb_map::create(); | ||
method raw { $!raw } | ||
|
||
method keys { | ||
given HarfBuzz::Set.new { | ||
$!raw.keys(.raw); | ||
$_; | ||
} | ||
} | ||
|
||
method values { | ||
given HarfBuzz::Set.new { | ||
$!raw.values(.raw); | ||
$_; | ||
} | ||
} | ||
|
||
method exists(UInt:D $i --> Int) { | ||
$!raw.exists($i).so; | ||
} | ||
|
||
method AT-POS(UInt:D $i --> Int) { | ||
$i < $.elems ?? $!raw.get($i) !! Int | ||
} | ||
|
||
submethod DESTROY { .destroy with $!raw } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
unit class HarfBuzz::Set; | ||
|
||
use HarfBuzz::Raw; | ||
use HarfBuzz::Raw::Defs :types, :hb-set-value; | ||
use NativeCall; | ||
|
||
has hb_set:D $!raw handles<elems> = hb_set::create(); | ||
method raw { $!raw } | ||
|
||
method exists(UInt:D $i --> Int) { | ||
$!raw.exists($i).so; | ||
} | ||
|
||
method AT-POS(UInt:D $i --> Int) { | ||
$i < $.elems ?? $!raw.get($i) !! Int | ||
} | ||
|
||
method array handles<Array List> { | ||
my hb_codepoint @to-unicode; | ||
@to-unicode[$!raw.elems - 1 ] = 0 if $!raw.elems; | ||
my $buf = nativecast(CArray, @to-unicode); | ||
$!raw.next-many(HB_SET_VALUE_INVALID, $buf, $!raw.elems); | ||
@to-unicode; | ||
} | ||
|
||
submethod DESTROY { .destroy with $!raw } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use Test; | ||
plan 4; | ||
use HarfBuzz::Face; | ||
|
||
my $file = 't/fonts/NimbusRoman-Regular.otf'; | ||
my HarfBuzz::Face:D() $face = %( :$file ); | ||
|
||
is $face.get-glyph-count, 855; | ||
is $face.units-per-EM, 1000; | ||
|
||
subtest 'unicode-set', { | ||
my HarfBuzz::Set $unicode-set = $face.unicode-set; | ||
ok $unicode-set.defined; | ||
is $unicode-set.elems, 854, 'set elems'; | ||
ok $unicode-set.exists(42), 'exists'; | ||
my @unicodes := $unicode-set.array; | ||
is @unicodes.elems, 854, 'array elems'; | ||
is @unicodes[10], 42; | ||
} | ||
|
||
subtest 'unicode-to-gid-map', { | ||
my HarfBuzz::Map $unicode-map = $face.unicode-to-gid-map; | ||
ok $unicode-map.exists(42), 'exists'; | ||
my HarfBuzz::Set $keys = $unicode-map.keys; | ||
my HarfBuzz::Set $values = $unicode-map.values; | ||
is $values.array[10], 11, 'values'; | ||
is $unicode-map.elems, 854, 'elems'; | ||
is $unicode-map[42], 11; | ||
} | ||
|