Skip to main content

TtiBlock

Struct TtiBlock 

Source
pub struct TtiBlock { /* private fields */ }
Expand description

Text and Timing Information (TTI) block, 128 bytes with the text and timing of a subtitle.

Implementations§

Source§

impl TtiBlock

Source

pub fn subtitle_group_number(&self) -> u8

Subtitle Group Number (SGN).

Source

pub fn subtitle_number(&self) -> u16

Subtitle Number (SN).

Source

pub fn extension_block_number(&self) -> u8

Extension Block Number (EBN), see also TtiBlock::is_last_block and TtiBlock::is_user_data.

Source

pub fn cumulative_status(&self) -> &CumulativeStatus

Cumulative Status (CS).

Source

pub fn time_code_in( &self, dfc: &DiskFormatCode, ) -> Result<Time, InvalidFieldValue<Time>>

Time Code In (TCI), validated against the ranges in the spec: hours 0-23, minutes and seconds 0-59 and frames according to the Disk Format Code.

On error, InvalidFieldValue::value gives the value as stored in the file.

§Example
use ebustl_parser::Time;

let stl = ebustl_parser::parse_stl_from_file("stls/test.stl").unwrap();
let dfc = stl.gsi.disk_format_code();
let time = Time { hours: 10, minutes: 0, seconds: 0, frames: 0 };
assert_eq!(Ok(time), stl.ttis[0].time_code_in(dfc));
Source

pub fn time_code_out( &self, dfc: &DiskFormatCode, ) -> Result<Time, InvalidFieldValue<Time>>

Time Code Out (TCO), validated against the ranges in the spec: hours 0-23, minutes and seconds 0-59 and frames according to the Disk Format Code.

On error, InvalidFieldValue::value gives the value as stored in the file.

§Example
use ebustl_parser::Time;

let stl = ebustl_parser::parse_stl_from_file("stls/test.stl").unwrap();
let dfc = stl.gsi.disk_format_code();
let time = Time { hours: 10, minutes: 0, seconds: 0, frames: 5 };
assert_eq!(Ok(time), stl.ttis[0].time_code_out(dfc));
Source

pub fn vertical_position(&self) -> u8

Vertical Position (VP), the row of the first subtitle row: 1-23 for teletext and 0 up to MNR for open subtitles.

Source

pub fn justification(&self) -> Result<Justification, InvalidFieldValue<u8>>

Justification Code (JC), validated as 00h-03h.

On error, InvalidFieldValue::value gives the value as stored in the file.

§Example
use ebustl_parser::Justification;

let stl = ebustl_parser::parse_stl_from_file("stls/test.stl").unwrap();
assert_eq!(Ok(Justification::Centered), stl.ttis[0].justification());
Source

pub fn comment_flag(&self) -> Result<bool, InvalidFieldValue<u8>>

Comment Flag (CF), validated as 00h or 01h. true if the Text Field contains comments not intended for transmission.

On error, InvalidFieldValue::value gives the value as stored in the file.

§Example
let stl = ebustl_parser::parse_stl_from_file("stls/test.stl").unwrap();
assert_eq!(Ok(false), stl.ttis[0].comment_flag());
Source§

impl TtiBlock

Source

pub fn new( idx: u16, tci: Time, tco: Time, txt: &str, opt: TtiFormat, cct: CharacterCodeTable, ) -> TtiBlock

Creates a teletext subtitle in a single TTI block (EBN FFh), with idx as Subtitle Number.

Rows are separated by \n or \r\n. Text that does not fit in one block is truncated, use Stl::add_sub to continue it in extension blocks.

§Example
use ebustl_parser::{CharacterCodeTable, Time, TtiBlock, TtiFormat};

let time = |seconds| Time { hours: 10, minutes: 0, seconds, frames: 0 };
let format = TtiFormat { jc: 2, vp: 20, dh: false };

let tti = TtiBlock::new(1, time(1), time(3), "One\nTwo", format, CharacterCodeTable::Latin);
assert_eq!("One\r\nTwo", tti.text());
assert!(tti.is_last_block());
Source

pub fn text(&self) -> String

Decodes the Text Field of this single block into a string.

Control codes are dropped, except CR/LF which becomes \r\n. Use TtiBlock::text_elements to get the control codes too.

A subtitle may span several blocks (extension blocks), use Stl::subtitles and Subtitle::text to get the complete text of a subtitle.

Source

pub fn text_elements(&self) -> Vec<TextElement>

Decodes the Text Field of this single block into characters and control codes, e.g. teletext colors, double height and boxing, or italics for open subtitles.

A subtitle may span several blocks (extension blocks), use Subtitle::text_elements to get the elements of the complete subtitle.

§Example
use ebustl_parser::{TeletextControl, TextElement};

let stl = ebustl_parser::parse_stl_from_file("stls/test.stl").unwrap();
let elements = stl.ttis[2].text_elements();
assert_eq!(TextElement::Teletext(TeletextControl::DoubleHeight), elements[0]);
Source

pub fn is_user_data(&self) -> bool

Returns true for a block carrying user data (EBN FEh). Its Text Field is not subtitle text and must not affect the rest of the subtitle.

§Example
let stl = ebustl_parser::parse_stl_from_file("stls/test.stl").unwrap();
assert!(!stl.ttis[0].is_user_data());
Source

pub fn is_text_block(&self) -> bool

Returns true if the Text Field of this block is part of the subtitle text, i.e. the block is an extension block (EBN 00h-EFh) or the last block of a subtitle (EBN FFh). User data (FEh) and blocks reserved for future use (F0h-FDh) are not.

§Example
let stl = ebustl_parser::parse_stl_from_file("stls/test.stl").unwrap();
assert!(stl.ttis.iter().all(|tti| tti.is_text_block()));
Source

pub fn is_last_block(&self) -> bool

Returns true for the last block of a subtitle (EBN FFh).

§Example
let stl = ebustl_parser::parse_stl_from_file("stls/test.stl").unwrap();
assert!(stl.ttis[0].is_last_block());
Source

pub fn is_comment(&self) -> bool

Returns true if the Comment Flag (CF 01h) marks the Text Field as comments, which are not intended for transmission.

§Example
let stl = ebustl_parser::parse_stl_from_file("stls/test.stl").unwrap();
assert!(!stl.ttis[0].is_comment());

Trait Implementations§

Source§

impl Debug for TtiBlock

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for TtiBlock

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for TtiBlock

Source§

impl PartialEq for TtiBlock

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for TtiBlock

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.