Struct pango::Language

source ·
pub struct Language(_);
Expand description

The Language structure is used to represent a language.

Language pointers can be efficiently copied and compared with each other.

Implementations§

source§

impl Language

source

pub fn from_string(language: &str) -> Self

Convert a language tag to a Language.

The language tag must be in a RFC-3066 format. Language pointers can be efficiently copied (copy the pointer) and compared with other language tags (compare the pointer.)

This function first canonicalizes the string by converting it to lowercase, mapping ‘_’ to ‘-’, and stripping all characters other than letters and ‘-’.

Use default() if you want to get the Language for the current locale of the process.

language

a string representing a language tag

Returns

a Language

source

pub fn to_string(&self) -> GString

source

pub fn matches(&self, range_list: &str) -> bool

Checks if a language tag matches one of the elements in a list of language ranges.

A language tag is considered to match a range in the list if the range is ‘*’, the range is exactly the tag, or the range is a prefix of the tag, and the character after it in the tag is ‘-’.

range_list

a list of language ranges, separated by ‘;’, ‘:’, ‘,’, or space characters. Each element must either be ‘*’, or a RFC 3066 language range canonicalized as by from_string()

Returns

true if a match was found

source

pub fn includes_script(&self, script: Script) -> bool

Determines if @script is one of the scripts used to write @self.

The returned value is conservative; if nothing is known about the language tag @self, true will be returned, since, as far as Pango knows, @script might be used to write @self.

This routine is used in Pango’s itemization process when determining if a supplied language tag is relevant to a particular section of text. It probably is not useful for applications in most circumstances.

This function uses scripts() internally.

script

a Script

Returns

true if @script is one of the scripts used to write @self or if nothing is known about @self (including the case that @self is None), false otherwise.

source

pub fn scripts(&self) -> Vec<Script>

Determines the scripts used to to write @self.

If nothing is known about the language tag @self, or if @self is None, then None is returned. The list of scripts returned starts with the script that the language uses most and continues to the one it uses least.

The value @num_script points at will be set to the number of scripts in the returned array (or zero if None is returned).

Most languages use only one script for writing, but there are some that use two (Latin and Cyrillic for example), and a few use three (Japanese for example). Applications should not make any assumptions on the maximum number of scripts returned though, except that it is positive if the return value is not None, and it is a small number.

The includes_script() function uses this function internally.

Note: while the return value is declared as Script, the returned values are from the GUnicodeScript enumeration, which may have more values. Callers need to handle unknown values.

Returns

An array of Script values, with the number of entries in the array stored in @num_scripts, or None if Pango does not have any information about this particular language tag (also the case if @self is None).

source

pub fn sample_string(&self) -> GString

Get a string that is representative of the characters needed to render a particular language.

The sample text may be a pangram, but is not necessarily. It is chosen to be demonstrative of normal text in the language, as well as exposing font feature requirements unique to the language. It is suitable for use as sample text in a font selection dialog.

If @self is None, the default language as found by default() is used.

If Pango does not have a sample string for @self, the classic “The quick brown fox…” is returned. This can be detected by comparing the returned pointer value to that returned for (non-existent) language code “xx”. That is, compare to:

pango_language_get_sample_string (pango_language_from_string ("xx"))
Returns

the sample string

source

pub fn preferred(&self) -> Vec<Language>

Available on crate feature v1_48 only.

Returns the list of languages that the user prefers.

The list is specified by the PANGO_LANGUAGE or LANGUAGE environment variables, in order of preference. Note that this list does not necessarily include the language returned by default().

When choosing language-specific resources, such as the sample text returned by sample_string(), you should first try the default language, followed by the languages returned by this function.

Returns

a None-terminated array of Language*

Trait Implementations§

source§

impl Default for Language

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Send for Language

source§

impl Sync for Language

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.