GithubHelp home page GithubHelp logo

freetype-rs's Introduction

freetype-rs Build Status

Rust bindings for FreeType library

Requirements

  • Cargo: We use Cargo to compile the project.
  • FreeType2 development libraries: For installation instructions see freetype-sys.

Build

Clone this repo then run

cd freetype-rs
cargo build

Examples

To build examples, use cargo test. They are all built in ./target/debug/examples/*.

To run examples, use cargo run --example name, for example:

cargo run --example single_glyph examples/assets/FiraSans-Regular.ttf A

How to contribute

freetype-rs's People

Contributors

abonander avatar andrewrk avatar ankit3005 avatar bgdncz avatar bvssvni avatar chrisduerr avatar coeuvre avatar dominaezzz avatar hannobraun avatar indiv0 avatar jneem avatar jyc avatar kagami avatar kchibisov avatar leaexplores avatar m4rw3r avatar mgsloan avatar michaelzoech avatar mprobinson avatar ms2ger avatar nox avatar nyurik avatar petevine avatar potpourri avatar rockyzhengwu avatar seemk avatar thendiscard avatar tomaka avatar tyoverby avatar zummenix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

freetype-rs's Issues

Avoid `FT_MemoryRec`

See #91 (comment)

Alternately, we could avoid dealing with FT_MemoryRec altogether and init FT_Library with FT_Init_Freetype. We don't have to worry about establishing our allocators because rustc links malloc to the proper platform implementation automatically.

error: unresolved name `ffi::FT_Get_Sfnt_Table`

I get this error when attempting to compile freetype-rs on Windows 8.1 x64

   Compiling freetype-rs v0.1.1
C:\Users\admin\.cargo\registry\src\github.com-1ecc6299db9ec823\freetype-rs-0.1.1\src\tt_os2.rs:12:23: 12:45 error: unres
olved name `ffi::FT_Get_Sfnt_Table`
C:\Users\admin\.cargo\registry\src\github.com-1ecc6299db9ec823\freetype-rs-0.1.1\src\tt_os2.rs:12             let os2 =
ffi::FT_Get_Sfnt_Table(face.raw_mut() as *mut ffi::FT_FaceRec, ffi::ft_sfnt_os2) as ffi::TT_OS2_Internal;

^~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error
Build failed, waiting for other jobs to finish...
Could not compile `freetype-rs`.

To learn more, run the command again with --verbose.

Failed to Open Resource at Runtime

Problem

Compiling, then running my program, rust-ssb, results in the following error message:

task '<main>' failed at 'called `Result::unwrap()` on an `Err` value: CannotOpenResource', /home/indiv0/projects/lib/rust/src/libcore/result.rs:548

Steps to Reproduce

I'm trying to compile my project, rust-ssb with rustc version:

$ rustc -v
rustc 0.12.0-pre (793b1424ac52b7d1cb20e508e313ce516530cea7 2014-07-19 16:01:43 +0000)

As well as the latest versions of all Piston libraries (using luqmana's updated rust-sdl2).

The build itself runs fine:

$ cargo build -u
    Updating git repository `https://github.com/PistonDevelopers/freetype-rs`
    Updating git repository `https://github.com/PistonDevelopers/opengl_graphics`
    Updating git repository `https://github.com/PistonDevelopers/rust-graphics`
    Updating git repository `https://github.com/PistonDevelopers/piston`
    Updating git repository `https://github.com/bjz/gl-rs`
    Updating git repository `https://github.com/bjz/sax-rs`
    Updating git repository `https://github.com/PistonDevelopers/vecmath`
    Updating git repository `https://github.com/PistonDevelopers/rust-image`
       Fresh piston v0.0.0 (https://github.com/PistonDevelopers/piston)
       Fresh image v0.0.0 (https://github.com/PistonDevelopers/rust-image)
   Compiling vecmath v0.0.0 (https://github.com/PistonDevelopers/vecmath)
       Fresh sdl2 v0.0.1 (file:/media/projects/rust-ssb)
       Fresh freetype-rs v0.0.0 (https://github.com/PistonDevelopers/freetype-rs)
       Fresh sax-rs v0.0.1 (https://github.com/bjz/sax-rs)
       Fresh gl_generator v0.0.1 (https://github.com/bjz/gl-rs)
       Fresh gl v0.0.1 (https://github.com/bjz/gl-rs)
       Fresh sdl2_game_window v0.0.0 (file:/media/projects/rust-ssb)
   Compiling graphics v0.0.0 (https://github.com/PistonDevelopers/rust-graphics)
   Compiling opengl_graphics v0.0.0 (https://github.com/PistonDevelopers/opengl_graphics)
   Compiling rust-ssb v0.0.0 (file:/media/projects/rust-ssb)
src/ssbapp.rs:23:5: 23:26 warning: code is never used: `freetype`, #[warn(dead_code)] on by default
src/ssbapp.rs:23     freetype: ft::Library,
                     ^~~~~~~~~~~~~~~~~~~~~

I then copy my assets/ folder into the target directory:

$ cp -R assets target/
$ tree target
target
├── assets
│   ├── FantasqueSansMono-Regular.ttf
│   └── OFL.txt
├── deps
│   ├── libfreetype-57a1db24984c25a3.rlib
│   ├── libgl-5061fee3d996e95b.rlib
│   ├── libgl_generator-0b27c215b798fc73.so
│   ├── libgraphics-f42b6273953a8552.rlib
│   ├── libimage-e644bec1e1073740.rlib
│   ├── libopengl_graphics-b6dbc47643b7cd36.rlib
│   ├── libpiston-73bde3540db379e8.rlib
│   ├── libsax-a002b9f722ac6474.rlib
│   ├── libsdl2-18405cbac1f07626.rlib
│   ├── libsdl2_game_window-19bf9a5dd8d3850c.rlib
│   └── libvecmath-e3b4fd24d667f0d5.rlib
├── native
│   ├── gl-5061fee3d996e95b
│   └── sdl2-18405cbac1f07626
└── rust-ssb

5 directories, 14 files

Running the program gives the following error:

$ target/rust-ssb
Constructing window
task '<main>' failed at 'called `Result::unwrap()` on an `Err` value: CannotOpenResource', /home/indiv0/projects/lib/rust/src/libcore/result.rs:548

The error itself occurs on this line (i.e., when trying to load the fontface).

I don't believe this is an issue with my code because my travis builds only started failing after a rename of my main app file.

Any ideas?

Incorrect calculation of bitmap buffer length

The length of the bitmap buffer is calculated using self.width() * self.rows(), this however assumes that one pixel equals one byte, which might not be the case (for example if pixel_mode == Mono. The correct way to calculate the buffer length would be self.pitch().abs() * self.rows(), if I understand the freetype documentation correctly.

Also, if I interpret the documentation correctly, when pitch is negative, the buffer pointer points at the last row in memory (i.e. buffer points at the row with index zero, but the row at index one is located at a lower address than that row in memory).

Example outdated?

error[E0432]: unresolved import `unicode_normalization::UnicodeNormalization`
error[E0412]: type name `ft::Bitmap` is undefined or not in scope
error[E0433]: failed to resolve. Could not find `Library` in `fonttest::ft`
error[E0433]: failed to resolve. Could not find `face` in `fonttest::ft`
error: no method named `nfc` found for type `std::string::String` in the current scope

Crate not usable on arm/android any more

The reason being this.

Compiling freetype-rs v0.4.0
/home/odroid/.cargo/registry/src/github.com-48ad6e4054423464/freetype-rs-0.4.0/src/face.rs:81:43: 81:77 error: mismatched types:
 expected `*const u8`,
    found `*const i8`
(expected u8,
    found i8) [E0308]
/home/odroid/.cargo/registry/src/github.com-48ad6e4054423464/freetype-rs-0.4.0/src/face.rs:81             ffi::FT_Attach_File(self.raw, filepathname.as_ptr() as *const i8)
                                                                                                                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/odroid/.cargo/registry/src/github.com-48ad6e4054423464/freetype-rs-0.4.0/src/face.rs:81:43: 81:77 help: run `rustc --explain E0308` to see a detailed explanation
error: aborting due to previous error

`ffi::FT_New_Face` fails when built in Release mode, however is fine in Debug?

For some reason the FT_New_Face method in src/ffi.rs returns the error CannotOpenResource ONLY when I compile and run in Release mode (I built release mode like this cargo build --release). It runs fine if built with regular cargo build.

This is the line where the error is returned.

I've also tried two different fonts (one .otf, one .ttf) and the strange behaviour is the same regardless.

I'm unsure how to approach this further, I'm keen to test release mode on a personal project however I have to fix this to get it going. Anyone have any ideas what might be going on?

`Sync` not implemented for some types

   Compiling freetype-rs v0.0.1 (file:///Users/sven/rust/freetype-rs)
src/library.rs:38:36: 43:2 error: the trait `core::kinds::Sync` is not implemented for the type `*mut libc::types::common::c95::c_void`
src/library.rs:38 static MEMORY: ffi::FT_MemoryRec = ffi::FT_MemoryRec {
src/library.rs:39     user: 0 as *mut c_void,
src/library.rs:40     alloc: alloc_library,
src/library.rs:41     free: free_library,
src/library.rs:42     realloc: realloc_library,
src/library.rs:43 };
src/library.rs:38:36: 43:2 note: the type `*mut libc::types::common::c95::c_void` must implement `core::kinds::Sync` because it appears within the type `freetype-sys::FT_MemoryRec`
src/library.rs:38 static MEMORY: ffi::FT_MemoryRec = ffi::FT_MemoryRec {
src/library.rs:39     user: 0 as *mut c_void,
src/library.rs:40     alloc: alloc_library,
src/library.rs:41     free: free_library,
src/library.rs:42     realloc: realloc_library,
src/library.rs:43 };
src/library.rs:38:36: 43:2 note: shared static variables must have a type that implements `Sync`
src/library.rs:38 static MEMORY: ffi::FT_MemoryRec = ffi::FT_MemoryRec {
src/library.rs:39     user: 0 as *mut c_void,
src/library.rs:40     alloc: alloc_library,
src/library.rs:41     free: free_library,
src/library.rs:42     realloc: realloc_library,
src/library.rs:43 };
error: aborting due to previous error
Could not compile `freetype-rs`.

Compilation Error: Expected `i32` but found `i64`

freetype-rs fails to compile under cygwin in Windows 7 x64 with the following error:

$ cargo build --verbose
   Compiling graphics v0.0.0 (https://github.com/PistonDevelopers/rust-graphics)
   Compiling freetype-rs v0.0.0 (https://github.com/PistonDevelopers/freetype-rs)
   Compiling piston v0.0.0 (https://github.com/PistonDevelopers/piston)
   Compiling sdl2 v0.0.1 (https://github.com/AngryLawyer/rust-sdl2)
   Compiling image v0.0.0 (https://github.com/PistonDevelopers/rust-image)
   Compiling sax-rs v0.0.1 (https://github.com/bjz/sax-rs)
Could not execute process `rustc src\lib.rs --crate-type lib --out-dir C:\Users\npekin\Desktop\progs\cygwin\home\npekin\code\rust-ssb\target\deps -L C:\Users\npekin\Desktop\progs\cygwin\home\npekin\code\rust-ssb\target\deps -L C:\Users\npekin\Desktop\progs\cygwin\home\npekin\code\rust-ssb\target\deps` (status=101)
--- stderr
src\lib.rs:3:1: 4:2 warning: the #[crate_id] attribute is deprecated for the #[crate_name] attribute
src\lib.rs:3 #![crate_id="freetype#0.0.1"]
src\lib.rs:4 #![desc = "Rust bindings for FreeType, based on version 2.5.2"]
src\library.rs:44:69: 44:88 error: mismatched types: expected `i32` but found `i64` (expected i32 but found i64)
src\library.rs:44             let err = FT_New_Memory_Face(self.raw, buffer.as_ptr(), buffer.len() as i64, face_index, &mut face);
                                                                                      ^~~~~~~~~~~~~~~~~~~
error: aborting due to previous error


Caused by:
  Could not execute process `rustc src\lib.rs --crate-type lib --out-dir C:\Users\npekin\Desktop\progs\cygwin\home\npekin\code\rust-ssb\target\deps -L C:\Users\npekin\Desktop\progs\cygwin\home\npekin\code\rust-ssb\target\deps -L C:\Users\npekin\Desktop\progs\cygwin\home\npekin\code\rust-ssb\target\deps` (status=101)
--- stderr
src\lib.rs:3:1: 4:2 warning: the #[crate_id] attribute is deprecated for the #[crate_name] attribute
src\lib.rs:3 #![crate_id="freetype#0.0.1"]
src\lib.rs:4 #![desc = "Rust bindings for FreeType, based on version 2.5.2"]
src\library.rs:44:69: 44:88 error: mismatched types: expected `i32` but found `i64` (expected i32 but found i64)
src\library.rs:44             let err = FT_New_Memory_Face(self.raw, buffer.as_ptr(), buffer.len() as i64, face_index, &mut face);
                                                                                      ^~~~~~~~~~~~~~~~~~~
error: aborting due to previous error

task '<unnamed>' failed at 'sending on a closed channel', C:\bot\slave\nightly-win\build\src\libsync\comm\mod.rs:563
task '<unnamed>' failed at 'sending on a closed channel', C:\bot\slave\nightly-win\build\src\libsync\comm\mod.rs:563
task '<unnamed>' failed at 'sending on a closed channel', C:\bot\slave\nightly-win\build\src\libsync\comm\mod.rs:563
task '<unnamed>' failed at 'sending on a closed channel', C:\bot\slave\nightly-win\build\src\libsync\comm\mod.rs:563
task '<unnamed>' failed at 'sending on a closed channel', C:\bot\slave\nightly-win\build\src\libsync\comm\mod.rs:563

Font rendering only shows black blocks

This is what I see when running the font_with_piston example on Fedora 20 with KDE:

freetype-screenshot

I can't work out how to change the black blocks to actual text. Trying this with a different font resulted in the same issue.
There is no console output while running the application.

FFI error compiling freetype-rs as dependency

C:\Users\roboj_000\Documents\GitHub\spy-rs>cargo build
   Compiling pkg-config v0.3.5
   Compiling bitflags v0.1.1
   Compiling libc v0.1.8
   Compiling libz-sys v0.1.6
   Compiling freetype-sys v0.1.2
   Compiling freetype-rs v0.1.1
C:\Users\roboj_000\.cargo\registry\src\github.com-1ecc6299db9ec823\freetype-rs-0
.1.1\src\tt_os2.rs:12:23: 12:45 error: unresolved name `ffi::FT_Get_Sfnt_Table`
C:\Users\roboj_000\.cargo\registry\src\github.com-1ecc6299db9ec823\freetype-rs-0
.1.1\src\tt_os2.rs:12             let os2 = ffi::FT_Get_Sfnt_Table(face.raw_mut(
) as *mut ffi::FT_FaceRec, ffi::ft_sfnt_os2) as ffi::TT_OS2_Internal;

                                            ^~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error
Could not compile `freetype-rs`.

To learn more, run the command again with --verbose.

When listed as a cargo dependency freetype-rs build fails.
This build was attempted on Windows 8.

Implement `Clone` for `Face`

The same FT_Face instance can be used in multiple locations as long as it's not used across threads. Since Face does not implement Send or Sync, we should be safe simply incrementing the refcount of FT_Face and FT_Library and copying the pointers.

Needed by PistonDevelopers/opengl_graphics#115

Bindings between Rust and C

Here we can collect some general approaches of binding C to Rust.

Macro used as inline function in C and be converted to inline function in Rust. Fox example:

// C
#define FT_HAS_COLOR( face ) \
          ( face->face_flags & FT_FACE_FLAG_COLOR )
// Rust
#[inline(always)]
pub fn FT_HAS_COLOR(face: FT_Face) -> bool {
    unsafe {
        (*face).face_flags & FT_FACE_FLAG_COLOR != 0
    }
}

Here are somethings I can't bind to rust now:

  1. How to convert macro like:
#ifndef FT_IMAGE_TAG
#define FT_IMAGE_TAG( value, _x1, _x2, _x3, _x4 )  \
          value = ( ( (unsigned long)_x1 << 24 ) | \
                    ( (unsigned long)_x2 << 16 ) | \
                    ( (unsigned long)_x3 << 8  ) | \
                      (unsigned long)_x4         )
#endif /* FT_IMAGE_TAG */

// How to use them
typedef enum  FT_Glyph_Format_
{
    FT_IMAGE_TAG( FT_GLYPH_FORMAT_NONE, 0, 0, 0, 0 ),

    FT_IMAGE_TAG( FT_GLYPH_FORMAT_COMPOSITE, 'c', 'o', 'm', 'p' ),
    FT_IMAGE_TAG( FT_GLYPH_FORMAT_BITMAP,    'b', 'i', 't', 's' ),
    FT_IMAGE_TAG( FT_GLYPH_FORMAT_OUTLINE,   'o', 'u', 't', 'l' ),
    FT_IMAGE_TAG( FT_GLYPH_FORMAT_PLOTTER,   'p', 'l', 'o', 't' )

} FT_Glyph_Format;

font_with_piston example crashes on close

/bin/bash: line 1:  3917 Segmentation fault: 11  ./target/font_with_piston

shell returned 139                                                    

I'm not sure if this is a known issue already? Will let you know if I can refine down the source of the problem.

OSX 10.9.4
rustc 0.12.0-pre (cf1381c1d 2014-07-26 00:46:16 +0000)

CurveIterator is wrong with curves starting with OFF point

According to freetype docs, the contour may start with conic off point. This case is not handled by CurveIterator, which assumes that first point is always on curve.

I encountered the problem with FreeSans.ttf, glyph "0". The inner contour has these tags: 00101001. The first point is conic off, so the last point should be used instead as the curve's starting point.

This is my render of the wrong outline:
screen shot 2017-02-14 at 10 59 01

Another example is the glyph for "8", the tags are 00010010010, ie. both ends of the contour are off-curve.

Segfaulting in FFI

#0  0x00007ffff102d000 in ?? ()
#1  0x00007ffff7845aa0 in ft_mem_qalloc ()
   from /usr/lib/x86_64-linux-gnu/libfreetype.so.6
#2  0x00007ffff7845ae8 in ft_mem_alloc ()
   from /usr/lib/x86_64-linux-gnu/libfreetype.so.6
#3  0x00007ffff7845f2d in FT_Stream_New ()
   from /usr/lib/x86_64-linux-gnu/libfreetype.so.6
#4  0x00007ffff7848f50 in FT_Open_Face ()
   from /usr/lib/x86_64-linux-gnu/libfreetype.so.6
#5  0x00007ffff78496cb in FT_New_Face ()
   from /usr/lib/x86_64-linux-gnu/libfreetype.so.6
#6  0x0000555555681299 in freetype::library::Library::new_face (
    self=0x7fffffffd6c8, filepathname=..., face_index=0) at src/library.rs:70
#7  0x00005555555f2521 in opengl_graphics::glyph_cache::GlyphCache::new (
    font=0x7fffffffd730) at src/glyph_cache.rs:39
#8  0x000055555556b4a4 in file_chooser::font () at examples/file_chooser.rs:28
#9  0x0000555555567af7 in file_chooser::main () at examples/file_chooser.rs:11
#10 0x00005555556aef49 in rust_try_inner ()
#11 0x00005555556aef36 in rust_try ()
#12 0x00005555556ac1ff in rt::lang_start::hf694818d7a643d8eflz ()
#13 0x000055555556813f in main ()

I downloaded Freetype's source to get the body of the relevant function (since there doesn't seem to be a debug symbols package available in the Ubuntu/Mint repos ¯_(ツ)_/¯ ):

  FT_BASE_DEF( FT_Pointer )
  ft_mem_qalloc( FT_Memory  memory,
                 FT_Long    size,
                 FT_Error  *p_error )
  {
    FT_Error    error = FT_Err_Ok;
    FT_Pointer  block = NULL;

    if ( size > 0 )
    {
      block = memory->alloc( memory, size );
      if ( block == NULL )
        error = FT_THROW( Out_Of_Memory );
    }
    else if ( size < 0 )
    {
      /* may help catch/prevent security issues */
      error = FT_THROW( Invalid_Argument );
    }

    *p_error = error;
    return block;
  }

The only place a segfault looks possible is the virtual call memory->alloc() which I think would segfault if memory was null, correct?

I can't figure out how to configure a debug build for Freetype or else I'd have tried to debug this further. I mean, I can configure it, but the ./configure script is giving me weird errors.

Is this possibly related to #90?

Use array constructor in single glyph examples

https://github.com/jneem/freetype-rs/blob/master/examples/single_glyph/single_glyph.rs

[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,],

This can be written as

[[0, ..WIDTH], ..HEIGHT]

Update README

The current information in the README is outdated.

Write a unicode text editor controller using Piston and freetype-rs

This probably requires adding unicode text input support to Piston.

The idea is to have a controller that handles text editing, which other widgets could use. You implement a trait TextEdit that contains methods for manipulating the text source and queries a view of the text. The controller does the rendering, handles selected text, clipboard and scrolling behavior.

  • Single-line mode and a multi-line mode?
  • Password mode?
  • Settings for margin, line space and other stuff?

Might be necessary to do this in a separate library.

Failing to compile tests

note: "cc" "-m64" "-L" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib" "-o" "/Users/sven/rust/freetype-rs/target/debug/freetype-35d8ea5e8adfe59e" "/Users/sven/rust/freetype-rs/target/debug/freetype-35d8ea5e8adfe59e.o" "-Wl,-force_load,/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libmorestack.a" "-Wl,-dead_strip" "-nodefaultlibs" "/Users/sven/rust/freetype-rs/target/debug/deps/libfreetype_sys-d78ceca407e3bfcf.rlib" "/Users/sven/rust/freetype-rs/target/debug/deps/libbitflags-518ea12e21428edd.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libtest-4e7c5e5c.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libgetopts-4e7c5e5c.rlib" "/Users/sven/rust/freetype-rs/target/debug/deps/liblibc-fe9268dcf892ee7b.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libterm-4e7c5e5c.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libserialize-4e7c5e5c.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/liblog-4e7c5e5c.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libstd-4e7c5e5c.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libcollections-4e7c5e5c.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libunicode-4e7c5e5c.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/librand-4e7c5e5c.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/liballoc-4e7c5e5c.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/liblibc-4e7c5e5c.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libcore-4e7c5e5c.rlib" "-L" "/Users/sven/rust/freetype-rs/target/debug" "-L" "/Users/sven/rust/freetype-rs/target/debug/deps" "-L" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib" "-L" "/Users/sven/rust/freetype-rs/.rust/lib/x86_64-apple-darwin" "-L" "/Users/sven/rust/freetype-rs/lib/x86_64-apple-darwin" "-lfreetype:dylib" "-lc" "-lm" "-lSystem" "-lpthread" "-lc" "-lm" "-lcompiler-rt"
note: ld: warning: directory not found for option '-L/Users/sven/rust/freetype-rs/.rust/lib/x86_64-apple-darwin'
ld: warning: directory not found for option '-L/Users/sven/rust/freetype-rs/lib/x86_64-apple-darwin'
ld: library not found for -lfreetype:dylib
clang: error: linker command failed with exit code 1 (use -v to see invocation)

error: aborting due to previous error
Could not compile `freetype-rs`.

Link error when building 'examples/font_with_piston'

error: linking with `cc` failed: exit code: 1
note: cc '-m64' '-L' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib' '-o' 'examples/font_with_piston' 'examples/font_with_piston.o' '-Wl,-force_load,/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libmorestack.a' '-nodefaultlibs' '-Wl,-dead_strip' '/Users/sven/Desktop/opengl_graphics/target/libopengl_graphics.rlib' '/Users/sven/Desktop/rust-image/target/libimage.rlib' '/Users/sven/Desktop/freetype-rs/target/libfreetype.rlib' '/Users/sven/Desktop/rust-graphics/target/libgraphics.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libnative-4e7c5e5c.rlib' '/Users/sven/Desktop/sdl2_game_window/target/libsdl2_game_window.rlib' '/Users/sven/Desktop/opensource/rust-sdl2/target/libsdl2.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libdebug-4e7c5e5c.rlib' '/Users/sven/Desktop/piston/target/libpiston.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libtime-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libserialize-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/liblog-4e7c5e5c.rlib' '/Users/sven/Desktop/opensource/gl-rs/target/libgl.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libflate-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libstd-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libsync-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/librustrt-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libcollections-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libunicode-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/liballoc-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/liblibc-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/librand-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libcore-4e7c5e5c.rlib' '-L' 'target/deps' '-L' 'target' '-L' '/Users/sven/Desktop/freetype-rs/.rust' '-L' '/Users/sven/Desktop/freetype-rs' '-lfreetype' '-lSDL2' '-lSystem' '-lpthread' '-lc' '-lm' '-lcompiler-rt'
note: ld: warning: directory not found for option '-L/Users/sven/Desktop/freetype-rs/.rust'
Undefined symbols for architecture x86_64:
  "_FT_New_Face", referenced from:
      library::Library::new_face::hf0dd684f56d0ebafW5c in libfreetype.rlib(freetype.o)
  "_FT_Init_FreeType", referenced from:
      library::Library::init::hb27045d1c63c4b11j5c in libfreetype.rlib(freetype.o)
  "_FT_Done_Face", referenced from:
      face::Face.Drop::drop::h4625357dce44ccc977b in libfreetype.rlib(freetype.o)
  "_FT_Load_Char", referenced from:
      face::Face::load_char::hbcc4ef60e3d9833cb4b in libfreetype.rlib(freetype.o)
  "_FT_Set_Pixel_Sizes", referenced from:
      face::Face::set_pixel_sizes::h0421b0ec9efc079aK2b in libfreetype.rlib(freetype.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

error: aborting due to previous error

Relicense under dual MIT/Apache-2.0

This issue was automatically generated. Feel free to close without ceremony if
you do not agree with re-licensing or if it is not possible for other reasons.
Respond to @cmr with any questions or concerns, or pop over to
#rust-offtopic on IRC to discuss.

You're receiving this because someone (perhaps the project maintainer)
published a crates.io package with the license as "MIT" xor "Apache-2.0" and
the repository field pointing here.

TL;DR the Rust ecosystem is largely Apache-2.0. Being available under that
license is good for interoperation. The MIT license as an add-on can be nice
for GPLv2 projects to use your code.

Why?

The MIT license requires reproducing countless copies of the same copyright
header with different names in the copyright field, for every MIT library in
use. The Apache license does not have this drawback. However, this is not the
primary motivation for me creating these issues. The Apache license also has
protections from patent trolls and an explicit contribution licensing clause.
However, the Apache license is incompatible with GPLv2. This is why Rust is
dual-licensed as MIT/Apache (the "primary" license being Apache, MIT only for
GPLv2 compat), and doing so would be wise for this project. This also makes
this crate suitable for inclusion and unrestricted sharing in the Rust
standard distribution and other projects using dual MIT/Apache, such as my
personal ulterior motive, the Robigalia project.

Some ask, "Does this really apply to binary redistributions? Does MIT really
require reproducing the whole thing?" I'm not a lawyer, and I can't give legal
advice, but some Google Android apps include open source attributions using
this interpretation. Others also agree with
it
.
But, again, the copyright notice redistribution is not the primary motivation
for the dual-licensing. It's stronger protections to licensees and better
interoperation with the wider Rust ecosystem.

How?

To do this, get explicit approval from each contributor of copyrightable work
(as not all contributions qualify for copyright) and then add the following to
your README:

## License

Licensed under either of
 * Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
 * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
at your option.

### Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any
additional terms or conditions.

and in your license headers, use the following boilerplate (based on that used in Rust):

// Copyright (c) 2016 freetype-rs developers
//
// Licensed under the Apache License, Version 2.0
// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT
// license <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. All files in the project carrying such notice may not be copied,
// modified, or distributed except according to those terms.

Be sure to add the relevant LICENSE-{MIT,APACHE} files. You can copy these
from the Rust repo for a plain-text
version.

And don't forget to update the license metadata in your Cargo.toml to:

license = "MIT/Apache-2.0"

I'll be going through projects which agree to be relicensed and have approval
by the necessary contributors and doing this changes, so feel free to leave
the heavy lifting to me!

Contributor checkoff

To agree to relicensing, comment with :

I license past and future contributions under the dual MIT/Apache-2.0 license, allowing licensees to chose either at their option

Or, if you're a contributor, you can check the box in this repo next to your
name. My scripts will pick this exact phrase up and check your checkbox, but
I'll come through and manually review this issue later as well.

Take u64 instead of FT_ULong

Currently it breaks compilation on platforms where long is 32 bit.

pub fn load_char(&self, char_code: ffi::FT_ULong, load_flags: LoadFlag) -> FtResult<()> {

It should cast to FT_ULong internally, while keeping a platform agnostic interface.

Build error on Windows MinGW32

src\library.rs:17:22: 17:33 error: mismatched types: expected `u32` but found `u64` (expected u32 but found u64)
src\library.rs:17         libc::malloc(size as u64)
                       ^~~~~~~~~~~
src\library.rs:32:30: 32:45 error: mismatched types: expected `u32` but found `u64` (expected u32 but found u64)
src\library.rs:32         libc::realloc(block, new_size as u64)

I assume because this is a 32-bit build environment, those functions take 32-bit integers, but I could be wrong.

Support Stroker

FT_Stroker is required to render outline text, which probably will be added in text libraries then.

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.