Giter Site home page Giter Site logo

font-freetype-raku's Introduction

[Raku PDF Project] / [Font-FreeType Module] Actions Status

Font-FreeType-raku - Raku binding to the FreeType font library (version 2)

Classes in this Distribution

Synopsis

use Font::FreeType;

my Font::FreeType $freetype .= new;
my $face = $freetype.face('t/fonts/Vera.ttf');

$face.set-font-size(12, 12, 72, 72);
for $face.glyph-images('ABC') {
    my $outline = .outline;
    my $bitmap = .bitmap;
    # ...
}

Description

This module allows Raku programs to conveniently read information from font files. All the font access is done through the FreeType2 library, which supports many formats. It can render images of characters with high-quality hinting and anti-aliasing, extract metrics information, and extract the outlines of characters in scalable formats like TrueType.

Please see Font::FreeType.

Scripts

font-say

font-say [--resolution=<Int>] [--pixels=<Int] [--kern] [--hint] [--ascend=<Int>] [--descend=<Int>] [--char-spacing=<Int>] [--word-spacing=<Int>] [--bold=<Int>] [--mode=<Mode> (lcd lcd-v light mono normal)] [--verbose] <font-file> <text>

This script displays text as bitmapped characters, using a given font. For example:

% bin/font-say --hint --pixels=14 t/fonts/Vera.ttf 'FreeType!'
#######                            ##########                              ##
##                                     ##                                  ##
##      #####   ######    ######       ##    ###   ##  #######    ######   ##
##      ####    #######   #######      ##    ###  ###  #######    #######  ##
######  ##     ###   ##  ###   ##      ##     ##  ###  ##   ##   ###   ##  ##
##      ##     ########  ########      ##     ### ##   ##   ###  ########  ##
##      ##     ###       ###           ##      #####   ##   ###  ###
##      ##     ###       ###           ##      ####    ##   ##   ###
##      ##      #######   #######      ##      ####    #######    #######  ##
##      ##       ######    ######      ##       ###    #######     ######  ##
                                                ##     ##
                                               ###     ##
                                              ###      ##

Install

Font::FreeType depends on the freetype native library, so you must install that prior to using this module.

Debian/Ubuntu Linux

sudo apt-get install freetype6-dev

Alpine Linux

doas apk add freetype-dev

Max OS X

brew update
brew install freetype

Windows

This module uses prebuilt DLLs on Windows. No additional configuration is needed.

Testing

To checkout and test this module from the Git repository:

$ git checkout https://github.com/pdf-raku/Font-FreeType-raku.git
$ zef build .  # -OR- raku Build.rakumod
$ prove -e'raku -I .' -v t

Authors

Geoff Richards [email protected]

Ivan Baidakou [email protected]

David Warring [email protected] (Raku Port)

Copyright

Copyright 2004, Geoff Richards.

Ported from Perl to Raku by David Warring [email protected] Copyright 2017.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

font-freetype-raku's People

Contributors

dwarring avatar niner avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

font-freetype-raku's Issues

OpenType fonts are reported as format type "CFF"

I expected the format type to be "OpenType" but "CFF" was reported. I see that the font has a CFF table, but I don't understand why that would define its format when TrueType fonts are reported as TrueType.

Tests fail on Linux Mint 19.2

Tests fail with the following message:

Must specify something as a path: did you mean '.' for the current directory?
  in sub guess_library_name at /home/vrurg/raku/share/perl6/core/sources/947BDAB9F96E0E5FCCB383124F923A6BF6F8D76B (NativeCall) line 225
  in method setup at /home/vrurg/raku/share/perl6/core/sources/947BDAB9F96E0E5FCCB383124F923A6BF6F8D76B (NativeCall) line 285
  in block  at /home/vrurg/raku/share/perl6/core/sources/947BDAB9F96E0E5FCCB383124F923A6BF6F8D76B (NativeCall) line 594
  in method outline at /home/vrurg/src/Raku/Font-FreeType-p6/lib/Font/FreeType/Native.pm (Font::FreeType::Native) line 246
  in method outline at /home/vrurg/src/Raku/Font-FreeType-p6/lib/Font/FreeType/GlyphImage.pm (Font::FreeType::GlyphImage) line 49
  in block <unit> at t/00-basic.t line 41

libfreetype6 and libfreetype6-dev packages are installed:

Package: libfreetype6
Version: 2.8.1-2ubuntu2
Package: libfreetype6-dev
Version: 2.8.1-2ubuntu2
> ll /usr/lib/x86_64-linux-gnu/libfreetype.*                                                       
-rw-r--r-- 1 root root 1037428 Apr 12  2018 /usr/lib/x86_64-linux-gnu/libfreetype.a
-rw-r--r-- 1 root root     906 Apr 12  2018 /usr/lib/x86_64-linux-gnu/libfreetype.la
lrwxrwxrwx 1 root root      21 Apr 12  2018 /usr/lib/x86_64-linux-gnu/libfreetype.so -> libfreetype.so.6.15.0
lrwxrwxrwx 1 root root      21 Apr 12  2018 /usr/lib/x86_64-linux-gnu/libfreetype.so.6 -> libfreetype.so.6.15.0
-rw-r--r-- 1 root root  735704 Apr 12  2018 /usr/lib/x86_64-linux-gnu/libfreetype.so.6.15.0

Can't install on debian testing/unstable

zef install Font::FreeType
===> Searching for: Font::FreeType
===> Updating cpan mirror: https://raw.githubusercontent.com/ugexe/Perl6-ecosystems/master/cpan1.json
===> Updating p6c mirror: http://ecosystem-api.p6c.org/projects1.json
===> Updated p6c mirror: http://ecosystem-api.p6c.org/projects1.json
===> Updated cpan mirror: https://raw.githubusercontent.com/ugexe/Perl6-ecosystems/master/cpan1.json
===> Building: Font::FreeType:ver<0.1.5>:auth<github:p6-pdf>
/bin/sh: 1: freetype-config: not found
/bin/sh: 1: freetype-config: not found
In file included from src/ft6_outline.c:6:
src/ft6_outline.h:10:10: fatal error: ft2build.h: No such file or directory
 #include <ft2build.h>
          ^~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:11: src/ft6_outline.o] Error 1
The spawned command 'make' exited unsuccessfully (exit code: 2)
  in method build at /home/alex/.zef/store/Font-FreeType-0.1.5.tar.gz/Font-FreeType-0.1.5/Build.pm line 26
  in sub MAIN at /home/alex/.zef/store/Font-FreeType-0.1.5.tar.gz/Font-FreeType-0.1.5/Build.pm line 33
  in block <unit> at /home/alex/.zef/store/Font-FreeType-0.1.5.tar.gz/Font-FreeType-0.1.5/Build.pm line 5
  in block <unit> at -e line 1

===> Building [FAIL]: Font::FreeType:ver<0.1.5>:auth<github:p6-pdf>
Aborting due to build failure: Font::FreeType:ver<0.1.5>:auth<github:p6-pdf> (use --force-build to override)

i have both libfreetype6 and libfreetype6-dev packages installed. I believe that these packages used to have freetype-config and ft2build.h files, but they no longer do.

Clearly define attribute 'height' as used herein

Does the 'height' attribute apply to the individual glyph or to the entire set of glyphs?

If it is line height, then it should not be an individual glyph attribute. The glyph height could be called 'char-' or 'glyph-height', but I would just eliminate it as a glyph attribute.

As a face attribute, 'height' would be as FreeType defines 'external leading' or 'line gap': the difference between baselines. It might be useful to alias 'height' to 'line-height'.

FreeType documention is somewhat loose with some of its definitions, but its C code is better. A table comparing the various attributes in code versus its documentation would be very helpful.

`t/10metrics_5x7bdf.t` inexplicitly dying in `available-fixed-sizes` invocation.

Tryed back as far as Rakudo-2013-12. Segfaulting on raw invocation of `get-available-sizes':

david@pc:~/git/Font-FreeType-raku$ rakudo-gdb-m -I . t/10metrics_5x7bdf.t 
================================================================================================
This is Rakudo running in the  debugger, which often allows the user to generate useful back-
traces to debug or report issues in Rakudo, the MoarVM backend or the currently running code.

This Rakudo version is 2024.04.100.g.5.d.6.a.7.dfca built on MoarVM version 2024.04.5.gdbdfb.3999,
running on debian (12.bookworm) / linux

Type `bt full` to generate a backtrace if applicable, type `q` to quit or `help` for help.
------------------------------------------------------------------------------------------------
Reading symbols from /home/david/git/rakudo/install/bin/rakudo-m...
Starting program: /home/david/git/rakudo/install/bin/rakudo-m -I . t/10metrics_5x7bdf.t
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff72836c0 (LWP 53550)]
1..1899
ok 1 - FreeType.face returns an object
ok 2 - FreeType.face returns face object
ok 3 - $face.num-faces
ok 4 - $face.face-index
ok 5 - there is no postscript name
ok 6 - $face->family-name() is right
ok 7 - no style name, defaults to "Regular"
ok 8 - $face.has-glyph-names
ok 9 - $face.has-horizontal-metrics
ok 10 - $face.has-kerning
ok 11 - $face.has-reliable-glyph-names
ok 12 - $face.has-vertical-metrics
ok 13 - $face.is-bold
ok 14 - $face.is-fixed-width
ok 15 - $face.is-italic
ok 16 - $face.is-scalable
ok 17 - $face.is-sfnt
ok 18 - $face.num-glyphs
ok 19 - units-per-em() undef
ok 20 - underline position undef
ok 21 - underline thickness undef
ok 22 - ascender undef
ok 23 - descender undef
ok 24 - BDF files have a single fixed size

Thread 1 "rakudo-m" received signal SIGSEGV, Segmentation fault.
MVMP6int_get_int (tc=0x4a172020180, st=0x4a1727774d0, root=0x4a179250f90, 
    data=0x50009) at src/6model/reprs/P6int.c:94
94	        case 16: return ((MVMP6intBody *)data)->value.i16;
(gdb) bt
#0  MVMP6int_get_int (tc=0x4a172020180, st=0x4a1727774d0, root=0x4a179250f90, 
    data=0x50009) at src/6model/reprs/P6int.c:94
#1  0x00007ffff789cfab in get_attribute (tc=0x4a172020180, st=<optimized out>, 
    root=<optimized out>, data=0x4a179250fa8, class_handle=<optimized out>, 
    name=<optimized out>, hint=-1, result_reg=0x4a172482d30, kind=4)
    at src/6model/reprs/CStruct.c:551
#2  0x00007ffff782100d in MVM_interp_run (tc=0x4a172020180, 
    initial_invoke=0x4a1727774d0, 
    initial_invoke@entry=0x7ffff794cb90 <toplevel_initial_invoke>, 
    invoke_data=0x4a1727774d0, 
    invoke_data@entry=0x7ffff794cb90 <toplevel_initial_invoke>, 
    outer_runloop=0x50009, outer_runloop@entry=0x0) at src/core/interp.c:1923
#3  0x00007ffff794dc05 in MVM_vm_run_file (
    instance=instance@entry=0x4a172010000, 
    filename=filename@entry=0x555555559520 "/home/david/git/rakudo/install/share/perl6/runtime/perl6.moarvm") at src/moar.c:505
#4  0x0000555555555608 in main (argc=<optimized out>, argv=<optimized out>)
    at src/vm/moar/runner/main.c:480
(gdb) 

Using a list of glyph objects doesn't work as I would expect

I'm trying to do this (pseudo code):

load a font file in a face object
set the size for the font
get a hash of Glyph objects keyed by the char
set string width to zero
for each char in a string of text
    get the glyph object from the hash
    get its attributes of interest
        width, height, bbox, etc.
        kern if there is a following char
    add the char width to the stringwidth

While watching the program run, I see no change in the attributes for any character. I see no difference in kerning between kern pairs.

Note it does appear the attributes have been scaled to the font size rather than the raw em size.

The program appears as https://github.com/tbrowder/FontFactory/blob/master/dev/iterate-text.raku.

t/10metrics_*.t failures on freetype 2.9.1 + bleed

 LD_LIBRARY_PATH=/home/david/git/freetype2/objs/.libs/ prove -e'perl6 -I .' t/10metrics_postscript.t
t/10metrics_postscript.t .. 25/53 # Failed test 'right bearing of glyph 'A''
# at t/10metrics_postscript.t line 111
# expected: '50'
#      got: '20'
# Failed test 'width of glyph 'A''
# at t/10metrics_postscript.t line 113
# expected: '1409'
#      got: '1439'
# Failed test 'right bearing of glyph '_''
# at t/10metrics_postscript.t line 111
# expected: '4'
#      got: '-17'
# Failed test 'width of glyph '_''
# at t/10metrics_postscript.t line 113
# expected: '1037'
#      got: '1058'
# Failed test 'left bearing of glyph '`''
# at t/10metrics_postscript.t line 109
# expected: '116'
#      got: '118'
# Failed test 'right bearing of glyph '`''
# at t/10metrics_postscript.t line 111
# expected: '245'
#      got: '235'
# Failed test 'width of glyph '`''
# at t/10metrics_postscript.t line 113
# expected: '321'
#      got: '329'
# Failed test 'left bearing of glyph 'g''
# at t/10metrics_postscript.t line 109
# expected: '56'
#      got: '57'
# Failed test 'right bearing of glyph 'g''
# at t/10metrics_postscript.t line 111
# expected: '56'
#      got: '36'
# Failed test 'width of glyph 'g''
# at t/10metrics_postscript.t line 113
# expected: '912'
#      got: '931'
# Failed test 'left bearing of glyph '|''
# at t/10metrics_postscript.t line 109
# expected: '160'
#      got: '163'
# Failed test 'right bearing of glyph '|''
# at t/10metrics_postscript.t line 111
# expected: '169'
#      got: '164'
# Failed test 'width of glyph '|''
# at t/10metrics_postscript.t line 113
# expected: '81'
#      got: '83'
# Looks like you failed 13 tests of 53
t/10metrics_postscript.t .. Dubious, test returned 13 (wstat 3328, 0xd00)
Failed 13/53 subtests 

Test Summary Report
-------------------
t/10metrics_postscript.t (Wstat: 3328 Tests: 53 Failed: 13)
  Failed tests:  31-32, 36-37, 40-42, 45-47, 50-52
  Non-zero exit status: 13
``

Example 'glyph-to-eps' doesn't work with latest version

FYI: In my modules with executable Raku progams I usually add a ./t or ./xt test for each. For example:

$ cat ./t/test-examples.t
use Test;
use MyModule;

lives-ok {
    raku -Ilib ./examples/eg1.raku
}

That's very useful to me during development.

Attempt Windows port

Similar to recent work on the Raku LibXML module? I.e. build and include freetype6 and ft6 DLLs with the distribution.

Two problems during module testing

I'm trying to install Font::FreeType, but it fails during testing.
Here's the error message:

===> Testing: Font::FreeType:ver<0.0.6>:auth<github:p6-pdf>
Potential difficulties:
    Duplicate 'is export' trait
    at .zef/store/Font-FreeType-0.0.6.tar.gz/Font-FreeType-0.0.6/lib/Font/FreeType/Native.pm (Font::FreeType::Native):122
    ------> FT_CharMap is export is repr('CStruct') ⏏is export {
FreeType2 version is 2.8.1
FreeType Error: invalid file format
  in sub ft-try at .zef/store/Font-FreeType-0.0.6.tar.gz/Font-FreeType-0.0.6/lib/Font/FreeType/Error.pm (Font::FreeType::Error) line 142
  in method for-glyphs at .zef/store/Font-FreeType-0.0.6.tar.gz/Font-FreeType-0.0.6/lib/Font/FreeType/Face.pm (Font::FreeType::Face) line 124
  in block  at t/20bitmap.t line 43
  in block <unit> at t/20bitmap.t line 22

“zef install Font::FreeType” fails on Debian 11

During installation, zef reports “Building [OK]” then starts testing and reports:

# Failed test: ‘wrapper lib access’
# at t/00-basic.t line 22
# Type check failed in binding to parameter ‘$library’; expected IO::Path but got Slip (Empty) unable to access FreeType wrapper library; has it been built? (e.g. ‘zef build .) in block <unit> at t/00-basic.t line 22
…
===> Testing [FAIL]…

Note I have the “libfreetype-dev” package installed on the host.

Also note, this occurs on one host but not another on which it installs fine.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.