eLeontev / SABRE.js

Substation Alpha suBtitles REnderer -- A Gpu Accelerated Javascript Advanced SubStation (ASS) Alpha Subtitles Renderer. Renders .ass and .ssa files.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SABRE.js

SABRE.js: Substation Alpha suBtitles REnderer

A Gpu Accelerated Javascript Advanced Substation Alpha Subtitles Renderer.

code style: prettier CodeFactor

What is the SABRE.js?

SABRE.js is a full renderer for Substation Alpha Subtitles and Advanced Substation Alpha Subtitles.

Other Similar software.

  • Subtitles-Octopus
  • Libass
  • XY-VSFilter

Documentation

You can retrieve a instance of the library by calling sabre.SABRERenderer(fontLoadingFunction) and passing it a function that loads fonts using the CSS Font loading API:

function loadFont(name) {
    // check if font is already loaded
    if (document.fonts.check("12px '" + name + "'")) return;

    // if the name has an extension, load from local fonts
    if (name.indexOf(".") !== -1) {
        const newFont = new FontFace(name, `url(./fonts/${name})`);
        newFont.load().then((font) => document.fonts.add(font));
        return;
    }

    // otherwise, load from google fonts and add stylesheet to document
    let link = document.createElement("link");
    link.setAttribute("rel", "stylesheet");
    link.setAttribute("media", "print");
    link.setAttribute("type", "text/css");
    link.setAttribute("onload", "this.media='all';");
    link.setAttribute(
        "href",
        `https://fonts.googleapis.com/css?family=${name}:100,100i,300,300i,400,400i,500,500i,700,700i,900,900i`
    );
    document.head.appendChild(link);
    //Force the font to load.
    let force_load = document.createElement("span");
    force_load.setAttribute(
        "style",
        `font-family: '${name}';position:absolute;top:-999999px;left:0px;`
    );
    force_load.appendChild(document.createTextNode("Force Load"));
    document.body.appendChild(force_load);
}

// pass the function to the renderer
let renderer = sabre.SABRERenderer(loadFont);

Functions

loadSubtitles(subsText)

Begins the process of parsing the passed subtitles in SSA/ASS format into subtitle events.

setViewport(width, height)

Updates the resolution/scale at which the subtitles are rendered (if the player is resized, for example).

getFrame(time)string

Fetches a rendered frame of subtitles as an object url.

loadSubtitles(subsText)

Begins the process of parsing the passed subtitles in SSA/ASS format into subtitle events.

Kind: global function

Param Type
subsText string

setViewport(width, height)

Updates the resolution/scale at which the subtitles are rendered (if the player is resized, for example).

Kind: global function

Param Type
width number
height number

getFrame(time) ⇒ string

Fetches a rendered frame of subtitles as an object url.

Kind: global function

Param Type
time number

© 2012-2021 Patrick "ILOVEPIE" Rhodes Martin.

About

Substation Alpha suBtitles REnderer -- A Gpu Accelerated Javascript Advanced SubStation (ASS) Alpha Subtitles Renderer. Renders .ass and .ssa files.

License:Other


Languages

Language:JavaScript 93.5%Language:HTML 3.2%Language:Shell 3.1%Language:Makefile 0.3%