Skip to content

Commit

Permalink
Take bbox() from scaled font delegate
Browse files Browse the repository at this point in the history
  • Loading branch information
dwarring committed Dec 12, 2023
1 parent f7e4adb commit 3f6ba1e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
11 changes: 1 addition & 10 deletions lib/Font/FreeType/Face.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,12 @@ class Font::FreeType::Face {
size> is required;
has UInt $.load-flags = FT_LOAD_DEFAULT;
has Lock $!lock handles<protect> .= new;
has $!metrics-delegate handles<units-per-EM underline-position underline-thickness ascender descender height bounding-box max-advance max-advance-height> = $!raw;
has $!metrics-delegate handles<units-per-EM underline-position underline-thickness ascender descender height bounding-box bbox max-advance max-advance-height> = $!raw;

method attach-file(Str:D() $filepath) {
ft-try { self.raw.FT_Attach_File($filepath); }
}

method bbox returns Font::FreeType::BBox {
if self.is-scalable {
my FT_BBox $bbox = $!raw.bbox;
Font::FreeType::BBox.new: :$bbox;
}
else {
Font::FreeType::BBox;
}
}
class UnscaledMetrics {
method bbox is also<bounding-box> { Array }
method FALLBACK(|) { Int }
Expand Down
12 changes: 11 additions & 1 deletion t/00-basic.t
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,17 @@ lives-ok { $face = $freetype.face('t/fonts/DejaVuSerif.ttf'.IO.slurp(:bin)) }, '
is $face.num-faces, 1, 'num-faces';
is $face.family-name, 'DejaVu Serif', 'face family name';

$face.set-char-size(2048, 2048, 72, 72);
$face.set-font-size(1024, 1024, 72, 72);

$bbox = $face.bounding-box;
ok $bbox.defined, 'got bounding-box';
is $bbox.x-min, -788, 'bbox.x-min';
is $bbox.x-max, 2156, 'bbox.x-max';
is $bbox.y-min, -355, 'bbox.y-min';
is $bbox.y-max, 1136, 'bbox.y-max';
is $bbox.width, 2944, 'bbox.width';
is $bbox.height, 1491, 'bbox.height';

$face.for-glyphs: 'AI', -> $gslot {
ok $gslot, '.for-glyphs';

Expand Down

0 comments on commit 3f6ba1e

Please sign in to comment.