Skip to content

Commit

Permalink
Coerce to IO::Path objects on face creation #31
Browse files Browse the repository at this point in the history
  • Loading branch information
dwarring committed Oct 31, 2024
1 parent ed111cd commit 1344eae
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/Font/FreeType.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Create a new 'instance' of the freetype library and return the object. This is a
my Font::FreeType $freetype .= new;
my Font::FreeType::Face $face = $freetype.face('Vera.ttf');

Return a [Font::FreeType::Face](https://pdf-raku.github.io/Font-FreeType-raku/Font/FreeType/Face) object representing a font face from the specified file or Blob.
Return a [Font::FreeType::Face](https://pdf-raku.github.io/Font-FreeType-raku/Font/FreeType/Face) object representing a font face from the specified file (`Str` or `IO::Path`) or a Blob.

If your font is scalable (i.e., not a bit-mapped font) then set the size and resolution you want to see it at, for example 24pt at 100dpi:

Expand Down
10 changes: 9 additions & 1 deletion docs/Font/FreeType/Raw.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,18 @@ method clone(

make a copy of the bitmap

### method clone

```raku
method clone() returns Mu
```

shallow clone. Works best on leaf structs

class Font::FreeType::Raw::FT_Bitmap_Size
-----------------------------------------

This structure models the metrics of a bitmap strike (i.e., a set of glyphs for a given point size and resolution) in a bitmap font. It is used for the ‘available_sizes’ field of FT_Face.
This structure models the metrics of a bitmap strike (i.e., a set of glyphs for a given point size and resolution) in a bitmap font. It is used for the ‘available-sizes’ field of FT_Face.

class Font::FreeType::Raw::FT_CharMap
-------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions lib/Font/FreeType.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ class Font::FreeType:ver<0.5.9> {
}

multi method face(::?CLASS:D $ft-lib:
Str:D $file-path-name,
IO:D() $file-io,
Int :$index = 0,
|c --> Font::FreeType::Face:D
) is hidden-from-backtrace {
my $p = Pointer[FT_Face].new;
$lock.protect: sub () is hidden-from-backtrace {
CATCH {
when Font::FreeType::Error {
.details = "loading file '$file-path-name'";
.details = "loading file '{$file-io.path}'";
.rethrow;
}
}
ft-try { $!raw.FT_New_Face($file-path-name, $index, $p); };
ft-try { $!raw.FT_New_Face($file-io.path, $index, $p); };
}
my FT_Face:D $raw = $p.deref;
Font::FreeType::Face.new: :$raw, :$ft-lib, |c;
Expand Down Expand Up @@ -134,7 +134,7 @@ object to a variable:
my Font::FreeType::Face $face = $freetype.face('Vera.ttf');
Return a L<Font::FreeType::Face> object representing
a font face from the specified file or Blob.
a font face from the specified file (`Str` or `IO::Path`) or a Blob.
If your font is scalable (i.e., not a bit-mapped font) then set the size
and resolution you want to see it at, for example 24pt at 100dpi:
Expand Down
5 changes: 4 additions & 1 deletion t/00-basic.t
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ bail-out "FreeType2 version $version is too old"
lives-ok({ cglobal($FT-WRAPPER-LIB, "ft6_glyph_outline", Pointer) }, 'wrapper symbol lib access');

my Font::FreeType::Face $face;
lives-ok {$face = $freetype.face('t/fonts/DejaVuSans.ttf') }, 'face creation from file';
lives-ok {$face = $freetype.face('t/fonts/DejaVuSans.ttf') }, 'face creation from filename';
is $face.font-format, 'TrueType', 'font format';
is $face.num-faces, 1, 'num-faces';
is $face.family-name, 'DejaVu Sans', 'face family name';
Expand All @@ -42,6 +42,9 @@ is $face.units-per-EM, 2048, '.units-per-EM';
is $face.ascender, 1901, '.ascender';
is $face.descender, -483, '.ascender';

lives-ok {$face = $freetype.face('t/fonts/DejaVuSans.ttf'.IO) }, 'face creation from IO path';
is $face.font-format, 'TrueType', 'font format';

lives-ok { $face = $freetype.face('t/fonts/DejaVuSerif.ttf'.IO.slurp(:bin)) }, 'face creation from buffer';
is $face.num-faces, 1, 'num-faces';
is $face.family-name, 'DejaVu Serif', 'face family name';
Expand Down

0 comments on commit 1344eae

Please sign in to comment.