Skip to content

Commit 0d6ad13

Browse files
authored
update: 2.6.14
1 parent 9f46642 commit 0d6ad13

2 files changed

Lines changed: 11 additions & 99 deletions

File tree

app/index.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<link rel="alternate" hreflang="ar" href="https://subs.js.org/ass-subset/?lang=ar">
2222
<link rel="alternate" hreflang="x-default" href="https://subs.js.org/ass-subset/">
2323
<link rel="icon" type="image/jpeg" href="icons/icon-256.png">
24-
<meta name="version" content="2.6.13">
24+
<meta name="version" content="2.6.14">
2525
<meta property="og:type" content="website">
2626
<meta property="og:title" content="ASS Subsetter · Font Embedding for Subtitles">
2727
<meta property="og:description" content="Font embedding tool for ASS/SSA subtitles. Subset fonts to compress file size, or embed them fully. Perfect for complex subtitle typesetting with multiple font files.">
@@ -933,7 +933,6 @@
933933
-webkit-tap-highlight-color: transparent;
934934
}
935935
.fi-dismiss:hover { opacity: 1; color: var(--err); }
936-
.fi-system { opacity: 0.72; }
937936
.fi-status { display: none; }
938937

939938
.btn {
@@ -4779,7 +4778,7 @@ <h3 id="preview-title" data-i18n="preview.title">Font Preview / Download</h3>
47794778
: [{ slot: 'default', vk: key + '::default', label: null, active: true }];
47804779

47814780
const div = document.createElement('div');
4782-
div.className = 'font-item' + (info.isSystem ? ' fi-system' : '');
4781+
div.className = 'font-item';
47834782

47844783
const hdr = document.createElement('div');
47854784
hdr.className = 'fi-header';

app/worker.js

Lines changed: 9 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -838,97 +838,12 @@ function locateTableInBuffer(buffer, sfntOffset) {
838838
return result;
839839
}
840840

841-
function locateWoffTableInBuffer(buffer) {
842-
const view = new DataView(buffer);
843-
if (buffer.byteLength < 48) return {};
844-
const numTables = view.getUint16(12, false);
845-
const result = {};
846-
for (let i = 0; i < numTables; i++) {
847-
const pos = 44 + i * 20;
848-
if (pos + 20 > buffer.byteLength) break;
849-
const tag = String.fromCharCode(
850-
view.getUint8(pos), view.getUint8(pos + 1),
851-
view.getUint8(pos + 2), view.getUint8(pos + 3)
852-
);
853-
const offset = view.getUint32(pos + 4, false);
854-
const compLength = view.getUint32(pos + 8, false);
855-
const origLength = view.getUint32(pos + 12, false);
856-
result[tag] = { offset, compLength, origLength };
857-
}
858-
return result;
859-
}
860-
861-
function extractWoffTable(buffer, entry) {
862-
const { offset, compLength, origLength } = entry;
863-
const raw = new Uint8Array(buffer, offset, compLength);
864-
if (compLength === origLength) return raw.buffer.slice(offset, offset + origLength);
865-
const inflated = new Uint8Array(origLength);
866-
let si = 0, di = 0;
867-
while (si < raw.length) {
868-
const bfinal = raw[si] & 1;
869-
const btype = (raw[si] >> 1) & 3;
870-
si++;
871-
if (btype === 0) {
872-
si = (si + 3) & ~3;
873-
if (si + 4 > raw.length) break;
874-
const len = raw[si] | (raw[si + 1] << 8);
875-
si += 4;
876-
for (let k = 0; k < len && si < raw.length && di < origLength; k++) inflated[di++] = raw[si++];
877-
} else {
878-
break;
879-
}
880-
if (bfinal) break;
881-
}
882-
const tmp = new ArrayBuffer(origLength);
883-
new Uint8Array(tmp).set(inflated);
884-
return tmp;
885-
}
886-
887841
function parseFontMetaFromBuffer(buffer, sfntOffset) {
888842
const view = new DataView(buffer);
889843
const tables = locateTableInBuffer(buffer, sfntOffset);
890844
return extractMetaFromTables(buffer, tables, false);
891845
}
892846

893-
function parseFontMetaFromWoff(buffer) {
894-
const woffTables = locateWoffTableInBuffer(buffer);
895-
const nameEntry = woffTables['name'];
896-
const os2Entry = woffTables['OS/2'];
897-
898-
const syntheticBuffer = buffer;
899-
const allNames = new Set();
900-
const familyNames = new Set();
901-
let weight = 400, isItalic = false, version = '', subfamilyName = '', description = '';
902-
903-
if (nameEntry) {
904-
const nameBuf = extractWoffTable(buffer, nameEntry);
905-
const raw = readNameTableRaw(nameBuf, 0);
906-
if (raw) {
907-
extractNamesFromRaw(nameBuf, raw.records, raw.strOff, allNames, familyNames,
908-
(v) => { if (!version) version = v; },
909-
(v) => { if (!subfamilyName) subfamilyName = v; },
910-
(v) => { if (!description) description = v; }
911-
);
912-
}
913-
}
914-
915-
if (os2Entry) {
916-
const os2Buf = extractWoffTable(buffer, os2Entry);
917-
const os2View = new DataView(os2Buf);
918-
if (os2Buf.byteLength >= 64) {
919-
const wc = os2View.getUint16(4, false);
920-
if (wc) weight = wc;
921-
const fsSel = os2View.getUint16(62, false);
922-
isItalic = !!(fsSel & 1);
923-
}
924-
}
925-
926-
applySubfamilyFallbacks(subfamilyName, weight, isItalic,
927-
(w) => { weight = w; }, (it) => { isItalic = it; });
928-
929-
return { allNames, familyNames, weight, isItalic, version, subfamilyName, description };
930-
}
931-
932847
function extractNamesFromRaw(buffer, records, strOff, allNames, familyNames, onVersion, onSubfamily, onDescription) {
933848
const FAMILY_IDS = new Set([NAME_ID_FAMILY, NAME_ID_FULL, NAME_ID_PREF_FAMILY]);
934849
const INCLUDE_IDS = new Set([
@@ -1021,14 +936,14 @@ function readFontDescriptionRaw(buffer) {
1021936
if (buffer.byteLength < 4) return '';
1022937
const view = new DataView(buffer);
1023938
const magic = view.getUint32(0, false);
1024-
if (magic === MAGIC_WOFF2) return '';
1025-
if (magic === MAGIC_WOFF) {
1026-
const woffTables = locateWoffTableInBuffer(buffer);
1027-
if (!woffTables['name']) return '';
1028-
const nameBuf = extractWoffTable(buffer, woffTables['name']);
1029-
const raw = readNameTableRaw(nameBuf, 0);
1030-
if (!raw) return '';
1031-
return bestNameValue(raw.records, raw.strOff, nameBuf, NAME_ID_DESCRIPTION);
939+
if (magic === MAGIC_WOFF2 || magic === MAGIC_WOFF) {
940+
try {
941+
const fontObj = opentype.parse(buffer);
942+
const desc = fontObj.names?.description?.en || Object.values(fontObj.names?.description || {})[0];
943+
return typeof desc === 'string' ? desc : '';
944+
} catch (e) {
945+
return '';
946+
}
1032947
}
1033948
const isTTC = magic === MAGIC_TTC;
1034949
const sfntOffset = isTTC ? view.getUint32(12, false) : 0;
@@ -1073,7 +988,7 @@ function matchFontBuffer(buffer, requiredFonts, id) {
1073988
};
1074989

1075990
try {
1076-
if (magic === MAGIC_WOFF2) {
991+
if (magic === MAGIC_WOFF2 || magic === MAGIC_WOFF) {
1077992
const fontObj = opentype.parse(buffer);
1078993
const allNames = new Set();
1079994
const familyNames = new Set();
@@ -1101,8 +1016,6 @@ function matchFontBuffer(buffer, requiredFonts, id) {
11011016
const sub = (fontObj.names?.preferredSubfamily?.en || fontObj.names?.fontSubfamily?.en || '').trim();
11021017
const ver = (fontObj.names?.version?.en || '').trim();
11031018
commitResult({ allNames, familyNames, weight, isItalic, version: ver, subfamilyName: sub }, -1);
1104-
} else if (magic === MAGIC_WOFF) {
1105-
commitResult(parseFontMetaFromWoff(buffer), -1);
11061019
} else if (magic === MAGIC_TTC) {
11071020
const numFonts = view.getUint32(8, false);
11081021
for (let i = 0; i < numFonts; i++) {

0 commit comments

Comments
 (0)