Documentation
¶
Overview ¶
Package ass reads, writes, and styles Advanced SubStation Alpha subtitles.
Index ¶
- Variables
- type Alignment
- type Alpha
- type BoldWeight
- type BorderStyle
- type CaptionSpec
- type Clip
- type Color
- type Contents
- type Dialogue
- type Document
- type Edit
- type Effect
- type Encoding
- type Event
- type EventEdit
- type Fade
- type Movement
- type Override
- type Position
- type Preset
- type Script
- type Style
- type StyleEdit
- type Transform
- type WrapStyle
Constants ¶
This section is empty.
Variables ¶
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 )
type Alpha ¶
type Alpha string
Alpha holds an ASS transparency value from 00 for opaque to FF for transparent.
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 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" 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" )
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 ¶
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 (*Document) Apply ¶
Apply returns a new document. The original remains available if an edit fails.
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 )
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 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.
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 ¶
LookupPreset returns the requested look.
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 (Script) MarshalText ¶
MarshalText writes a new v4+ ASS script from typed values.
func (Script) WriteToFile ¶
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 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 )