[][src]Struct harfbuzz::Buffer

pub struct Buffer { /* fields omitted */ }

A series of Unicode characters.

Adding Text

Since in Rust, a value of type &str must contain valid UTF-8 text, adding text to a Buffer is simple:

let mut b = Buffer::new();
b.add_str("Hello World");
assert_eq!(b.is_empty(), false);

or, more simply:

let b = Buffer::with("Hello World");
assert_eq!(b.is_empty(), false);

Segment Properties

In addition to the text itself, there are three important properties that influence how a piece of text is shaped:

  • Direction: The direction in which the output glyphs flow. This is typically left to right or right to left. This is controlled via the set_direction method on Buffer.
  • Script: Script is crucial for choosing the proper shaping behaviour for scripts that require it (e.g. Arabic) and the which OpenType features defined in the font to be applied. This is controlled via the set_script method on Buffer.
  • Language: Languages are crucial for selecting which OpenType feature to apply to the buffer which can result in applying language-specific behaviour. Languages are orthogonal to the scripts, and though they are related, they are different concepts and should not be confused with each other. This is controlled via the set_language method on Buffer.

Additionally, Harfbuzz can attempt to infer the values for these properties using the guess_segment_properties method on Buffer:

let mut b = Buffer::with("مساء الخير");
b.guess_segment_properties();
assert_eq!(b.get_direction(), Direction::RTL);
assert_eq!(b.get_script(), sys::HB_SCRIPT_ARABIC);

Methods

impl Buffer[src]

pub fn new() -> Self[src]

Create a new, empty buffer.

let b = Buffer::new();
assert!(b.is_empty());

pub unsafe fn from_raw(raw: *mut hb_buffer_t) -> Self[src]

Construct a Buffer from a raw pointer. Takes ownership of the buffer.

pub fn as_ptr(&self) -> *mut hb_buffer_t[src]

Borrows a raw pointer to the buffer.

pub fn into_raw(self) -> *mut hb_buffer_t[src]

Gives up ownership and returns a raw pointer to the buffer.

pub fn with(text: &str) -> Self[src]

Create a new buffer with the given text.

pub fn with_capacity(capacity: usize) -> Self[src]

Create a new, empty buffer with the specified capacity.

pub fn add_str(&mut self, text: &str)[src]

Add UTF-8 encoded text to the buffer.

pub fn append(&mut self, other: &Buffer, start: usize, end: usize)[src]

Append part of the contents of another buffer to this one.

let mut b1 = Buffer::with("butter");
let b2 = Buffer::with("fly");
b1.append(&b2, 0, 3);
assert_eq!(b1.len(), "butterfly".len());

pub fn clear_contents(&mut self)[src]

Throw away text stored in the buffer, but maintain the currently configured Unicode functions and flags.

Text, glyph info, and segment properties will be discarded.

pub fn reset(&mut self)[src]

Throw away all data stored in the buffer as well as configuration parameters like Unicode functions, flags, and segment properties.

pub fn reserve(&mut self, size: usize)[src]

Preallocate space to fit at least size number of items.

FIXME: Does this correctly match the expected semantics?

pub fn len(&self) -> usize[src]

Returns the number of elements in the buffer, also referred to as its 'length'.

pub fn is_empty(&self) -> bool[src]

Returns true if the buffer contains no data.

pub fn guess_segment_properties(&mut self)[src]

Sets unset buffer segment properties based on buffer Unicode contents.

If buffer is not empty, it must have content type HB_BUFFER_CONTENT_TYPE_UNICODE.

If buffer script is not set (ie. is HB_SCRIPT_INVALID), it will be set to the Unicode script of the first character in the buffer that has a script other than HB_SCRIPT_COMMON, HB_SCRIPT_INHERITED, and HB_SCRIPT_UNKNOWN.

Next, if buffer direction is not set (ie. is Direction::Invalid), it will be set to the natural horizontal direction of the buffer script as returned by hb_script_get_horizontal_direction().

Finally, if buffer language is not set (ie. is HB_LANGUAGE_INVALID), it will be set to the process's default language as returned by hb_language_get_default(). This may change in the future by taking buffer script into consideration when choosing a language.

let mut b = Buffer::with("Hello, world!");
b.guess_segment_properties();
assert_eq!(b.get_direction(), Direction::LTR);
assert_eq!(b.get_script(), sys::HB_SCRIPT_LATIN);

See also:

pub fn set_direction(&mut self, direction: Direction)[src]

Set the text flow direction of the buffer.

No shaping can happen without setting buffer direction, and it controls the visual direction for the output glyphs; for RTL direction the glyphs will be reversed. Many layout features depend on the proper setting of the direction, for example, reversing RTL text before shaping, then shaping with LTR direction is not the same as keeping the text in logical order and shaping with RTL direction.

See also:

pub fn get_direction(&self) -> Direction[src]

Get the text flow direction for the buffer.

See also:

pub fn set_script(&mut self, script: hb_script_t)[src]

Sets the script of buffer to script.

Script is crucial for choosing the proper shaping behaviour for scripts that require it (e.g. Arabic) and the which OpenType features defined in the font to be applied.

See also:

pub fn get_script(&self) -> hb_script_t[src]

Get the script for the buffer.

See also:

pub fn set_language(&mut self, language: Language)[src]

Sets the language of buffer to language.

Languages are crucial for selecting which OpenType feature to apply to the buffer which can result in applying language-specific behaviour. Languages are orthogonal to the scripts, and though they are related, they are different concepts and should not be confused with each other.

See also:

pub fn get_language(&self) -> Language[src]

Get the language for the buffer.

See also:

Trait Implementations

impl Drop for Buffer[src]

impl Default for Buffer[src]

fn default() -> Self[src]

Create a new, empty buffer.

impl Debug for Buffer[src]

Auto Trait Implementations

impl !Send for Buffer

impl !Sync for Buffer

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]