Skip to content

Commit

Permalink
fix: height of multi line breaks
Browse files Browse the repository at this point in the history
  • Loading branch information
weizhenye committed Sep 2, 2024
1 parent cadc662 commit 2c105aa
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
10 changes: 1 addition & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
<a href="https://github.com/weizhenye/ass-compiler">ass-compiler</a>
<span>・</span>

ASS.js renders ASS subtitles on HTML5 video, with almost full ASS features.

(Karaoke tags `\k`, `\kf`, `\ko`, `\kt`, `\K` are still WIP.)
ASS.js renders ASS subtitles on HTML5 video, with [almost full ASS features](https://github.com/weizhenye/ASS/wiki/Differences-with-Specs).

It's lightweight and suitable for web, **60x** smaller than WebAssembly solutions:
| | Solution | Size |
Expand Down Expand Up @@ -152,9 +150,3 @@ ASS.js uses many Web APIs to render subtitles, some features will be disabled if
| `\q0` | [text-wrap: balance](https://caniuse.com/css-text-wrap-balance) | 114 | 121 | 17.5 |
| BorderStyle=3 with `\bord0` | [@container](https://caniuse.com/mdn-css_at-rules_container_style_queries_for_custom_properties) | 111 | - | 18.0 |
| `\blur` with `\bord0` | [sign()](https://caniuse.com/mdn-css_types_sign) | - | 118 | 15.4 |

## Known issues

* `\N` in Aegisub has less height than `<br>` in browsers, subbers should avoid to use multiple `\N` to position a dialogue, use `\pos` instead.
* `\be` is just treated as `\blur`.
* `\q3` is just treated as `\q0`.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "assjs",
"version": "0.1.2",
"type": "module",
"description": "A JavaScript ASS subtitle format renderer",
"description": "A lightweight JavaScript ASS subtitle renderer",
"main": "dist/ass.js",
"types": "dist/ass.d.ts",
"files": [
Expand Down
4 changes: 4 additions & 0 deletions src/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@
line-height: calc(var(--ass-scale) * var(--ass-tag-fs) * 1px);
letter-spacing: calc(var(--ass-scale) * var(--ass-tag-fsp) * 1px);
}
.ASS-dialogue [data-is="br"] + [data-is="br"] {
height: calc(var(--ass-scale) * var(--ass-tag-fs) * 1px / 2);
}
.ASS-dialogue[data-wrap-style="0"],
.ASS-dialogue[data-wrap-style="3"] {
/* \q3 is just treated the same as \q0 in libass */
text-wrap: balance;
white-space: pre-wrap;
}
Expand Down
7 changes: 5 additions & 2 deletions src/renderer/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function createDialogue(dialogue, store) {
const hasScale = scaleTags.some((x) => tags.some((t) => t[x] !== undefined && t[x] !== 100));
const hasSkew = skewTags.some((x) => tags.some((t) => t[x]));

encodeText(text, tag.q).split('\n').forEach((content, idx) => {
encodeText(text, dialogue.q).split('\n').forEach((content, idx) => {
const $span = document.createElement('span');
const $ssspan = document.createElement('span');
if (hasScale || hasSkew) {
Expand All @@ -76,7 +76,10 @@ export function createDialogue(dialogue, store) {
$span.append(obj.$svg);
} else {
if (idx) {
df.append(document.createElement('br'));
const br = document.createElement('div');
br.dataset.is = 'br';
br.style.setProperty('--ass-tag-fs', tag.fs);
df.append(br);
}
if (!content) return;
if (hasScale || hasSkew) {
Expand Down

0 comments on commit 2c105aa

Please sign in to comment.