Skip to content

Commit

Permalink
add glyph-image() method
Browse files Browse the repository at this point in the history
  • Loading branch information
dwarring committed Dec 25, 2023
1 parent 37cae76 commit 6cfb480
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{{$NEXT}}
- Add glyph-image() method

0.5.4 2023-12-17T06:55:36+13:00
- Fix face height and advance-width. Thanks Tom Browder
Expand Down
4 changes: 4 additions & 0 deletions docs/Font/FreeType/Face.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ Similar to `forall-glyphs`, except that detachable [Font::FreeType::GlyphImage](

If there was an error loading the glyph, then the glyph-images's, `stat` method will return non-zero and the `error` method will return an exception object.

### glyph-image()

Returns a single [Font::FreeType::GlyphImage](https://pdf-raku.github.io/Font-FreeType-raku/Font/FreeType/GlyphImage) object for a code-point.

### has-glyph-names()

True if individual glyphs have names. If so, the names can be retrieved with the `name()` method on [Font::FreeType::Glyph](https://pdf-raku.github.io/Font-FreeType-raku/Font/FreeType/Glyph) objects.
Expand Down
26 changes: 15 additions & 11 deletions lib/Font/FreeType/Face.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,18 @@ class Font::FreeType::Face {
self.forall-chars(&code, $text.ords, |c);
}

multi method forall-char-images(::?CLASS:D $face: &code, @ords, :$flags = $!load-flags --> Seq) {
method glyph-image(::?CLASS:D $face: UInt:D $char-code, :$flags = $!load-flags --> Font::FreeType::GlyphImage) {
my FT_GlyphSlot:D $glyph = $!raw.glyph;

$!lock.protect: {
my $stat = $!raw.FT_Load_Char($char-code, $flags);
Font::FreeType::GlyphImage.new: :$face, :$glyph, :$char-code, :$stat;
}
}

multi method forall-char-images(::?CLASS:D: &code, @ords, :$flags = $!load-flags --> Seq) {
@ords.map: -> UInt:D $char-code {
my Font::FreeType::GlyphImage $glyph-image = $!lock.protect: {
my $stat = $!raw.FT_Load_Char($char-code, $flags);
Font::FreeType::GlyphImage.new: :$face, :$glyph, :$char-code, :$stat;
}
my $glyph-image = self.glyph-image($char-code, :$flags);
&code($glyph-image);
}
}
Expand All @@ -189,16 +193,12 @@ class Font::FreeType::Face {
}
}

multi method forall-char-images(::?CLASS:D $face: &code, :$flags = $!load-flags) {
my FT_GlyphSlot:D $glyph = $!raw.glyph;
multi method forall-char-images(::?CLASS:D: &code, :$flags = $!load-flags) {
my FT_UInt $glyph-index;
my FT_ULong $char-code = $!raw.FT_Get_First_Char( $glyph-index);

while $glyph-index {
my Font::FreeType::GlyphImage $glyph-image = $!lock.protect: {
my $stat = $!raw.FT_Load_Char($char-code, $flags);
Font::FreeType::GlyphImage.new: :$face, :$glyph, :$char-code, :$glyph-index, :$stat;
}
my $glyph-image := self.glyph-image($char-code, :$flags);
&code($glyph-image);
$char-code = $!raw.FT_Get_Next_Char( $char-code, $glyph-index);
}
Expand Down Expand Up @@ -599,6 +599,10 @@ Similar to `forall-glyphs`, except that detachable L<Font::FreeType::GlyphImage>
If there was an error loading the glyph, then the glyph-images's, `stat` method will return non-zero and the `error`
method will return an exception object.
=head3 glyph-image()
Returns a single L<Font::FreeType::GlyphImage> object for a code-point.
=head3 has-glyph-names()
True if individual glyphs have names. If so, the names can be
Expand Down

0 comments on commit 6cfb480

Please sign in to comment.