ass

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ass reads, writes, and styles Advanced SubStation Alpha subtitles.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidDocument = errors.New("invalid ASS document")
	ErrInvalidValue    = errors.New("invalid ASS value")
	ErrNotFound        = errors.New("ASS entry not found")
	ErrInputTooLarge   = errors.New("ASS input exceeds 64 MiB")
)

Errors reported by the reader and editor.

Functions

This section is empty.

Types

type Alignment

type Alignment int

Alignment represents text positioning using numpad-style layout

const (
	AlignmentBottomLeft   Alignment = 1
	AlignmentBottomCenter Alignment = 2
	AlignmentBottomRight  Alignment = 3
	AlignmentMiddleLeft   Alignment = 4
	AlignmentMiddleCenter Alignment = 5
	AlignmentMiddleRight  Alignment = 6
	AlignmentTopLeft      Alignment = 7
	AlignmentTopCenter    Alignment = 8
	AlignmentTopRight     Alignment = 9
)

func (Alignment) Ptr

func (a Alignment) Ptr() *Alignment

type Alpha

type Alpha string

Alpha holds an ASS transparency value from 00 for opaque to FF for transparent.

const (
	AlphaOpaque      Alpha = "&H00&"
	AlphaTransparent Alpha = "&HFF&"
	AlphaHalf        Alpha = "&H80&"
)

Common alpha values

type BoldWeight

type BoldWeight int

BoldWeight represents predefined weights for bold text

const (
	BoldWeightNone   BoldWeight = 0
	BoldWeightNormal BoldWeight = 1
	BoldWeightBold   BoldWeight = 700
	BoldWeightBolder BoldWeight = 900
)

func (BoldWeight) Ptr

func (b BoldWeight) Ptr() *BoldWeight

type BorderStyle

type BorderStyle int

BorderStyle represents the type of border to draw around text

const (
	BorderStyleOutlineDropShadow BorderStyle = 1
	BorderStyleOpaqueBox         BorderStyle = 3
)

func (BorderStyle) Ptr

func (b BorderStyle) Ptr() *BorderStyle

type CaptionSpec

type CaptionSpec struct {
	Title        string
	Width        int
	Height       int
	Dialogues    []Dialogue
	Uppercase    bool
	WordsPerLine int
}

CaptionSpec supplies timed lines and the visual settings for a new caption script.

type Clip

type Clip struct {
	X1      float64
	Y1      float64
	X2      float64
	Y2      float64
	Inverse bool
}

type Color

type Color string

Color holds an ASS color in BGR or ABGR format.

const (
	// Basic Colors
	ColorWhite   Color = "&H00FFFFFF"
	ColorBlack   Color = "&H00000000"
	ColorRed     Color = "&H000000FF"
	ColorGreen   Color = "&H0000FF00"
	ColorBlue    Color = "&H00FF0000"
	ColorYellow  Color = "&H0000FFFF"
	ColorMagenta Color = "&H00FF00FF"
	ColorCyan    Color = "&H00FFFF00"

	// Gray Shades
	ColorGray      Color = "&H00808080"
	ColorDarkGray  Color = "&H00404040"
	ColorLightGray Color = "&H00C0C0C0"

	// Common Colors
	ColorPurple Color = "&H00800080"
	ColorViolet Color = "&H00EE82EE"
	ColorIndigo Color = "&H004B0082"
	ColorPink   Color = "&H00CBC0FF"
	ColorOrange Color = "&H000080FF"
	ColorBrown  Color = "&H002A2AA5"
	ColorMaroon Color = "&H00000080"
	ColorNavy   Color = "&H00800000"
	ColorOlive  Color = "&H00008080"
	ColorTeal   Color = "&H00808000"

	// Web Colors
	ColorDeepPink       Color = "&H009314FF"
	ColorSkyBlue        Color = "&H00EBCE87"
	ColorLimeGreen      Color = "&H0032CD32"
	ColorGoldenRod      Color = "&H0020A5DA"
	ColorCornflowerBlue Color = "&H00ED9564"
	ColorBlueViolet     Color = "&H00E22B8A"
	ColorTurquoise      Color = "&H00D0E040"
	ColorSeaGreen       Color = "&H00578B2E"
	ColorHotPink        Color = "&H00B469FF"
	ColorDodgerBlue     Color = "&H00FF901E"
)

func ParseRGB

func ParseRGB(value string) (Color, error)

ParseRGB accepts three or six hexadecimal RGB digits, with an optional #.

func (Color) Ptr

func (c Color) Ptr() *string

type Contents

type Contents struct {
	Info   map[string]string
	Styles []map[string]string
	Events []map[string]string
}

Contents contains the parsed fields. All returned maps are independent of the document.

type Dialogue

type Dialogue struct {
	Start time.Duration
	End   time.Duration
	Text  string
}

Dialogue represents a single subtitle event (dialogue line) in the ASS file. This is a helper struct that is used when constructing an event.

type Document

type Document struct {
	// contains filtered or unexported fields
}

Document keeps the original ASS text and locates the fields that can be edited.

func Parse

func Parse(reader io.Reader) (*Document, error)

Parse reads a UTF-8 ASS v4+ file, preserving its original bytes.

func (*Document) Apply

func (d *Document) Apply(edit Edit) (*Document, error)

Apply returns a new document. The original remains available if an edit fails.

func (*Document) Contents

func (d *Document) Contents() Contents

Contents returns the script settings, styles, and events in file order.

func (*Document) String

func (d *Document) String() string

func (*Document) Theme

func (d *Document) Theme(preset Preset, name string) (*Document, error)

Theme replaces the selected style fields. A blank name applies the preset to every style.

func (*Document) Validate

func (d *Document) Validate() error

Validate checks style names, references, and ASS dialogue timestamps.

type Edit

type Edit struct {
	Info   map[string]string
	Styles []StyleEdit
	Events []EventEdit
}

Edit contains changes to script settings, named styles, and numbered events.

type Effect

type Effect string

Effect represents predefined special effects

const (
	EffectKaraoke     Effect = "Karaoke"
	EffectScroll      Effect = "Scroll"
	EffectBanner      Effect = "Banner"
	EffectScrollUp    Effect = "Scroll up"
	EffectScrollDown  Effect = "Scroll down"
	EffectScrollLeft  Effect = "Scroll left"
	EffectScrollRight Effect = "Scroll right"
)

func (Effect) Ptr

func (e Effect) Ptr() *Effect

type Encoding

type Encoding int

Encoding represents character encoding options

const (
	EncodingANSI       Encoding = 0
	EncodingDefault    Encoding = 1
	EncodingSymbol     Encoding = 2
	EncodingShiftJIS   Encoding = 128
	EncodingHangeul    Encoding = 129
	EncodingGB2312     Encoding = 134
	EncodingChineseBig Encoding = 136
	EncodingMac        Encoding = 77
	EncodingKorean     Encoding = 129
	EncodingJohab      Encoding = 130
	EncodingOEM        Encoding = 255
)

func (Encoding) Ptr

func (e Encoding) Ptr() *Encoding

type Event

type Event struct {
	Layer    int           // Layer number (higher layers are drawn on top)
	Start    time.Duration // Start time of the subtitle
	End      time.Duration // End time of the subtitle
	Style    string        // Name of the style to use
	Name     string        // Name of the event (actor/character name)
	MarginL  int           // Left margin override in pixels
	MarginR  int           // Right margin override in pixels
	MarginV  int           // Vertical margin override in pixels
	Effect   Effect        // Special effect name
	Text     string        // The actual subtitle text
	Override *Override     // Optional override tags for custom formatting
}

Event represents a single subtitle event (dialogue line) in the ASS file.

type EventEdit

type EventEdit struct {
	Index    int
	Fields   map[string]string
	Override *Override
}

EventEdit updates an event by its one-based index, including comment events.

type Fade

type Fade struct {
	A1 int
	A2 int
	A3 int
	T1 time.Duration
	T2 time.Duration
	T3 time.Duration
	T4 time.Duration
}

type Movement

type Movement struct {
	X1 float64
	Y1 float64
	X2 float64
	Y2 float64
	T1 *time.Duration
	T2 *time.Duration
}

type Override

type Override struct {
	Position     *Position   // Absolute positioning
	Movement     *Movement   // Movement animation
	Origin       *Position   // Origin point for rotations
	Alignment    *Alignment  // Text alignment override
	Bold         *bool       // Bold override
	BoldWeight   *BoldWeight // Custom bold weight
	Italic       *bool       // Italic override
	Underline    *bool       // Underline override
	StrikeOut    *bool       // Strikeout override
	FontSize     *float64    // Font size override
	FontName     *string     // Font name override
	PrimaryColor *Color      // Primary color override
	SecondColor  *Color      // Secondary color override
	OutlineColor *Color      // Outline color override
	ShadowColor  *Color      // Shadow color override
	GlobalAlpha  *Alpha      // Global alpha override
	PrimaryAlpha *Alpha      // Primary color alpha
	SecondAlpha  *Alpha      // Secondary color alpha
	OutlineAlpha *Alpha      // Outline alpha
	ShadowAlpha  *Alpha      // Shadow alpha
	Border       *float64    // Border width override
	Shadow       *float64    // Shadow depth override
	Blur         *float64    // Blur effect
	ScaleX       *float64    // Horizontal scaling override
	ScaleY       *float64    // Vertical scaling override
	RotationZ    *float64    // Z-axis rotation
	RotationX    *float64    // X-axis rotation
	RotationY    *float64    // Y-axis rotation
	ShearX       *float64    // X-axis shearing
	ShearY       *float64    // Y-axis shearing
	Fade         *Fade       // Fade effect
	Transform    []Transform // Transform animations
	Clip         *Clip       // Clipping rectangle
	WrapStyle    *WrapStyle  // Wrap style override
}

Override represents text override tags that can be applied to a subtitle event.

func (*Override) Tags

func (o *Override) Tags() (string, error)

Tags encodes the override as a leading ASS tag block.

type Position

type Position struct {
	X float64
	Y float64
}

type Preset

type Preset struct {
	Name            string
	Font            string
	Text            Color
	Highlight       Color
	Background      Color
	OutlineColor    Color
	BackgroundAlpha Alpha
	FontRatio       float64
	MarginRatio     float64
	Outline         float64
	Shadow          float64
	Padding         float64
	Bold            bool
	Alignment       Alignment
}

Preset sets the complete look of a subtitle style. Ratios are relative to script height.

func LookupPreset

func LookupPreset(name string) (Preset, error)

LookupPreset returns the requested look.

func Presets

func Presets() []Preset

Presets returns the built-in looks in display order.

func (Preset) Captions

func (p Preset) Captions(spec CaptionSpec) Script

Captions builds timed captions with separate text and background layers when the preset has a box.

type Script

type Script struct {
	Title      string
	Resolution struct {
		Width  int
		Height int
	}
	Styles []Style
	Events []Event
}

Script represents a complete ASS subtitle script including styles and events.

func NewScript

func NewScript(title string, width, height int) *Script

NewScript starts an empty script at the given coordinate resolution.

func (*Script) AddEvent

func (s *Script) AddEvent(event Event)

AddEvent appends a dialogue event.

func (*Script) AddStyle

func (s *Script) AddStyle(style Style)

AddStyle appends a style definition.

func (Script) Encode

func (s Script) Encode(w io.Writer) error

Encode writes an ASS script to w.

func (Script) MarshalText

func (s Script) MarshalText() ([]byte, error)

MarshalText writes a new v4+ ASS script from typed values.

func (Script) WriteToFile

func (s Script) WriteToFile(path string) error

WriteToFile writes an ASS script to the requested path.

type Style

type Style struct {
	Name         string      // Unique identifier for the style
	FontName     string      // Name of the font to use
	FontSize     float64     // Size of the font in points
	PrimaryColor Color       // Primary color in ASS format: &HBBGGRR&
	SecondColor  Color       // Secondary color (for karaoke) in ASS format: &HBBGGRR&
	OutlineColor Color       // Outline color in ASS format: &HBBGGRR&
	ShadowColor  Color       // Shadow color in ASS format: &HBBGGRR&
	PrimaryAlpha Alpha       // Primary color alpha
	SecondAlpha  Alpha       // Secondary color alpha
	OutlineAlpha Alpha       // Outline alpha
	ShadowAlpha  Alpha       // Shadow alpha
	Bold         bool        // Whether text should be bold
	Italic       bool        // Whether text should be italic
	Underline    bool        // Whether text should be underlined
	StrikeOut    bool        // Whether text should be struck through
	ScaleX       float64     // Horizontal scaling as percentage (100 = normal)
	ScaleY       float64     // Vertical scaling as percentage (100 = normal)
	Spacing      float64     // Additional space between letters in pixels
	Angle        float64     // Rotation angle in degrees
	BorderStyle  BorderStyle // Style of border around text
	Outline      float64     // Width of the outline in pixels
	Shadow       float64     // Depth of the shadow in pixels
	Alignment    Alignment   // Text alignment using numpad layout
	MarginL      int         // Left margin in pixels
	MarginR      int         // Right margin in pixels
	MarginV      int         // Vertical margin in pixels
	Encoding     Encoding    // Character encoding number
	WrapStyle    WrapStyle   // Text wrapping style
}

Style represents an ASS style definition that can be applied to multiple subtitle events.

type StyleEdit

type StyleEdit struct {
	Name   string
	Fields map[string]string
}

StyleEdit replaces selected Format columns in a named style.

type Transform

type Transform struct {
	Start    time.Duration
	End      time.Duration
	Accel    float64
	Override *Override
}

type WrapStyle

type WrapStyle int

WrapStyle represents text wrapping behavior

const (
	// Smart wrapping, top line is wider
	WrapStyleSmartTop WrapStyle = 0
	// End-of-line wrapping, right margin is strictly enforced
	WrapStyleEndOfLine WrapStyle = 1
	// Smart wrapping, bottom line is wider (usually best looking)
	WrapStyleSmartBottom WrapStyle = 2
	// Forced wrapping, only wrap at \n or \N
	WrapStyleForced WrapStyle = 3
)

func (WrapStyle) Ptr

func (w WrapStyle) Ptr() *WrapStyle

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL