Skip to content

Commit

Permalink
refactor outline() is-outline()
Browse files Browse the repository at this point in the history
  • Loading branch information
dwarring committed Dec 14, 2023
1 parent d14c27f commit 48276b9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 23 deletions.
11 changes: 11 additions & 0 deletions lib/Font/FreeType/BBox.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,22 @@ class Font::FreeType::BBox
my Font::FreeType $freetype .= new;
my Font::Freetype::Face $vera = $freetype.face('Vera.ttf');
# get the font bounding box
my Font::FreeType::BBox $bbox = $vera.bbox;
say $bbox.x-min;
say $bbox.x-max;
say $bbox.width;
say $bbox.height;
# get the bounding box for an individual glyph
$vera.for-glyphs: "X", -> $gslot {
}
=end code
=head2 Description
=head2 Methods
=end pod
7 changes: 1 addition & 6 deletions lib/Font/FreeType/Glyph.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ class Font::FreeType::Glyph {
use Font::FreeType::Error;

use Font::FreeType::BitMap;
use Font::FreeType::Outline;
constant Dot6 = Font::FreeType::Raw::Defs::Dot6;

has FT_GlyphSlot $!raw handles <metrics>;
has FT_GlyphSlot $.raw is built handles <metrics>;
has UInt:D $.flags = FT_LOAD_DEFAULT;
has Numeric $!x-scale;
has Numeric $!y-scale;
Expand All @@ -41,10 +40,6 @@ class Font::FreeType::Glyph {
method height returns Rat:D { $.metrics.height / $!y-scale }
method format returns UInt:D { FT_GLYPH_FORMAT($!raw.format) }

method is-outline {
$.format == FT_GLYPH_FORMAT_OUTLINE;
}

method glyph-image handles<bitmap outline decompose> returns Font::FreeType::GlyphImage:D {
my $top = $!raw.bitmap-top;
my $left = $!raw.bitmap-left;
Expand Down
17 changes: 2 additions & 15 deletions lib/Font/FreeType/GlyphImage.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@ class Font::FreeType::GlyphImage {
use Font::FreeType::Raw::Defs;

use Font::FreeType::BitMap;
use Font::FreeType::Outline;

has FT_Glyph $!raw handles <top left>;
has FT_Glyph $.raw is built handles <top left>;

method !library(--> FT_Library:D) {
$.face.ft-lib.raw;
}
method !library(--> FT_Library:D) { $.face.ft-lib.raw; }

submethod TWEAK(FT_GlyphSlot :$glyph!, :$top = $glyph.bitmap-top, :$left = $glyph.bitmap-left,) {
my $glyph-p = Pointer[FT_Glyph].new;
Expand All @@ -40,16 +37,6 @@ class Font::FreeType::GlyphImage {
}
method format returns UInt:D { FT_GLYPH_FORMAT($!raw.format) }

method is-outline {
.format == FT_GLYPH_FORMAT_OUTLINE with $!raw;
}
method outline handles<decompose> returns Font::FreeType::Outline:D {
die "not an outline glyph"
unless self.is-outline;
my FT_Outline:D $outline = $!raw.outline;
my FT_Outline $raw = $outline.clone(self!library);
Font::FreeType::Outline.new: :$raw, :$.face;
}
method bold(Int $s) is DEPRECATED<set-bold> { self.set-bold($s) }
method set-bold(Int $strength) {
if self.is-outline {
Expand Down
19 changes: 17 additions & 2 deletions lib/Font/FreeType/_Glyph.rakumod
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
unit class Font::FreeType::_Glyph is rw;

use Font::FreeType::Error;
use Font::FreeType::Outline;
use Font::FreeType::Raw;
use Font::FreeType::Raw::Defs;

has $.face is required; # parent object
has FT_ULong $.char-code;
has FT_UInt $.glyph-index;
has FT_Error $.stat;
method error { Font::FreeType::Error.new: :error($!stat) }

method !library(--> FT_Library:D) { $.face.ft-lib.raw; }

method error { Font::FreeType::Error.new: :error($!stat) }
method Str { $!char-code.chr }
method name returns Str { $!face.glyph-name-from-index: $.index }
method index returns UInt:D {
$!glyph-index ||= $!face.raw.FT_Get_Char_Index: $!char-code;
}
method Str { $!char-code.chr }
method is-outline {
.format == FT_GLYPH_FORMAT_OUTLINE with $.raw;
}

method outline handles<decompose> returns Font::FreeType::Outline:D {
die "not an outline glyph"
unless self.is-outline;
my FT_Outline:D $outline = $.raw.outline;
my FT_Outline $raw = $outline.clone(self!library);
Font::FreeType::Outline.new: :$raw, :$.face;
}

0 comments on commit 48276b9

Please sign in to comment.