Documentation
¶
Overview ¶
Package ass reads, writes, and styles Advanced SubStation Alpha subtitles.
Index ¶
- Constants
- Variables
- type Alignment
- type Alpha
- type BoldWeight
- type BorderStyle
- type CaptionSpec
- type Clip
- type Color
- type Contents
- type Dialogue
- type Document
- func (d *Document) Apply(edit Edit) (*Document, error)
- func (d *Document) Contents() Contents
- func (d *Document) String() string
- func (d *Document) Theme(preset Preset, name string) (*Document, error)
- func (d *Document) Validate() error
- func (d *Document) WithTextPosition(position TextPosition, name string) (*Document, error)
- type Edit
- type Effect
- type Encoding
- type Event
- type EventEdit
- type Fade
- type Karaoke
- type KaraokeMode
- type Movement
- type Override
- type Position
- type Preset
- type Script
- type SimpleFade
- type Style
- type StyleEdit
- type TextPosition
- type Transform
- type VectorClip
- type WrapStyle
Constants ¶
const ( FontDejaVuSans = "DejaVu Sans" FontDejaVuSerif = "DejaVu Serif" FontDejaVuSansMono = "DejaVu Sans Mono" FontTikTokSans = "TikTok Sans" FontBarlowCondensedExtraBold = "Barlow Condensed ExtraBold" FontAnton = "Anton" FontTheBold = "THE BOLD FONT (FREE VERSION)" )
Built-in preset fonts. Custom presets may name any installed font family.
const ( PresetBlackGold = "black-gold" // DefaultPreset is the look used when a caller does not choose one. DefaultPreset = PresetBlackGold )
Preset names referenced outside the preset table.
Variables ¶
var ( ErrInvalidDocument = errors.New("invalid ASS document") ErrInputTooLarge = errors.New("ASS input exceeds 64 MiB") )
Errors specific to ASS documents. Missing entries wrap commerr.ErrNotFound and rejected values wrap commerr.ErrInvalidValue from github.com/psyb0t/ctxerrors/commerr.
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.
Alpha values for opaque, fully transparent and half 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
Ptr returns a pointer to a copy of b, for optional fields.
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
Ptr returns a pointer to a copy of b, for optional fields.
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 ( ColorWhite Color = "&H00FFFFFF" ColorBlack Color = "&H00000000" ColorRed Color = "&H000000FF" ColorGreen Color = "&H0000FF00" ColorBlue Color = "&H00FF0000" ColorYellow Color = "&H0000FFFF" ColorMagenta Color = "&H00FF00FF" ColorCyan Color = "&H00FFFF00" ColorGray Color = "&H00808080" ColorDarkGray Color = "&H00404040" ColorLightGray Color = "&H00C0C0C0" 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" 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.
func (*Document) String ¶
String returns the document text, including every untouched byte of the original.
func (*Document) Theme ¶
Theme replaces the selected style fields. A blank name applies the preset to every style.
func (*Document) WithTextPosition ¶ added in v0.1.0
func (d *Document) WithTextPosition(position TextPosition, name string) (*Document, error)
WithTextPosition changes style defaults, preserving all event fields and inline tags. An empty style name selects every style.
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 {
Comment bool // Emit a Comment event instead of Dialogue.
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 Fade ¶
type Fade struct {
A1 int
A2 int
A3 int
T1 time.Duration
T2 time.Duration
T3 time.Duration
T4 time.Duration
}
Fade is the complex \fade tag: alphas A1, A2 and A3 from 0 to 255 change at times T1 to T4.
type Karaoke ¶ added in v0.1.0
type Karaoke struct {
Mode KaraokeMode
Duration time.Duration
}
Karaoke highlights the following syllable for Duration. An empty Mode selects KaraokeInstant.
type KaraokeMode ¶ added in v0.1.0
type KaraokeMode string
KaraokeMode selects the karaoke highlight effect.
const ( KaraokeInstant KaraokeMode = "k" KaraokeSweep KaraokeMode = "kf" KaraokeOutline KaraokeMode = "ko" )
type Movement ¶
type Movement struct {
X1 float64
Y1 float64
X2 float64
Y2 float64
T1 *time.Duration
T2 *time.Duration
}
Movement moves text from (X1, Y1) to (X2, Y2). T1 and T2 bound the movement in event time and must be set together.
type Override ¶
type Override struct {
ResetStyle *string // Reset overrides, optionally to another named style.
Spacing *float64
Encoding *Encoding
BorderX *float64
BorderY *float64
ShadowX *float64
ShadowY *float64
BlurEdges *int
DrawingMode *int
DrawingBaseline *float64
Karaoke *Karaoke
KaraokeStart *time.Duration
SimpleFade *SimpleFade
VectorClip *VectorClip
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
SideMarginRatio 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, or an error wrapping commerr.ErrNotFound.
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
Info map[string]string // Additional script headers; title, type and resolution use their typed fields.
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. Custom Info headers replace the generated defaults of the same name and follow them in sorted order.
func (Script) WithTextPosition ¶ added in v0.1.0
func (s Script) WithTextPosition(position TextPosition) (Script, error)
WithTextPosition returns a script with position geometry applied to every style.
func (Script) WriteToFile ¶
WriteToFile writes an ASS script to the requested path.
type SimpleFade ¶ added in v0.1.0
SimpleFade fades in over In and out over Out.
type Style ¶
type Style struct {
Name string // Unique identifier for the style
FontName string // Name of the font to use
FontSize float64 // Font size in ASS script coordinates.
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 TextPosition ¶ added in v0.1.0
type TextPosition struct {
Name string
Alignment Alignment
MarginRatio float64
LeftMarginRatio float64
RightMarginRatio float64
}
TextPosition sets style alignment and margins as fractions of the script canvas. Existing event margins and inline positioning retain precedence.
func LookupTextPosition ¶ added in v0.1.0
func LookupTextPosition(name string) (TextPosition, error)
LookupTextPosition returns a named placement, or an error wrapping commerr.ErrNotFound.
func TextPositions ¶ added in v0.1.0
func TextPositions() []TextPosition
TextPositions returns independent values in display order. Portrait names describe intended use.
type VectorClip ¶ added in v0.1.0
VectorClip uses ASS drawing commands. Scale zero selects the default scale of one.
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 with a wider bottom line. WrapStyleSmartBottom WrapStyle = 3 // Forced wrapping, only wrap at \n or \N WrapStyleForced WrapStyle = 2 WrapStyleNoWrap WrapStyle = WrapStyleForced )