Skip to content

Commit f75812b

Browse files
authored
Merge pull request #20346 from ryzokuken/binary-fontpath
Encode FontPath data into an ArrayBuffer
2 parents 2bb30fb + 3a85770 commit f75812b

File tree

5 files changed

+487
-411
lines changed

5 files changed

+487
-411
lines changed

src/core/evaluator.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ import {
4040
lookupMatrix,
4141
lookupNormalRect,
4242
} from "./core_utils.js";
43-
import { FontInfo, PatternInfo } from "../shared/obj-bin-transform.js";
43+
import {
44+
FontInfo,
45+
FontPathInfo,
46+
PatternInfo,
47+
} from "../shared/obj-bin-transform.js";
4448
import {
4549
getEncoding,
4650
MacRomanEncoding,
@@ -4663,11 +4667,8 @@ class PartialEvaluator {
46634667
if (font.renderer.hasBuiltPath(fontChar)) {
46644668
return;
46654669
}
4666-
handler.send("commonobj", [
4667-
glyphName,
4668-
"FontPath",
4669-
font.renderer.getPathJs(fontChar),
4670-
]);
4670+
const buffer = FontPathInfo.write(font.renderer.getPathJs(fontChar));
4671+
handler.send("commonobj", [glyphName, "FontPath", buffer], [buffer]);
46714672
} catch (reason) {
46724673
if (evaluatorOptions.ignoreErrors) {
46734674
warn(`buildFontPaths - ignoring ${glyphName} glyph: "${reason}".`);

src/display/api.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ import {
4545
StatTimer,
4646
} from "./display_utils.js";
4747
import { FontFaceObject, FontLoader } from "./font_loader.js";
48-
import { FontInfo, PatternInfo } from "../shared/obj-bin-transform.js";
48+
import {
49+
FontInfo,
50+
FontPathInfo,
51+
PatternInfo,
52+
} from "../shared/obj-bin-transform.js";
4953
import {
5054
getDataProp,
5155
getFactoryUrlProp,
@@ -2821,6 +2825,8 @@ class WorkerTransport {
28212825
}
28222826
break;
28232827
case "FontPath":
2828+
this.commonObjs.resolve(id, new FontPathInfo(exportedData));
2829+
break;
28242830
case "Image":
28252831
this.commonObjs.resolve(id, exportedData);
28262832
break;

src/display/font_loader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ class FontFaceObject {
436436
} catch (ex) {
437437
warn(`getPathGenerator - ignoring character: "${ex}".`);
438438
}
439-
const path = makePathFromDrawOPS(cmds);
439+
const path = makePathFromDrawOPS(cmds.path);
440440

441441
if (!this.fontExtraProperties) {
442442
// Remove the raw path-string, since we don't need it anymore.

src/shared/obj-bin-transform.js

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* limitations under the License.
1414
*/
1515

16-
import { assert, MeshFigureType } from "./util.js";
16+
import { assert, FeatureTest, MeshFigureType } from "./util.js";
1717

1818
class CssFontInfo {
1919
#buffer;
@@ -881,4 +881,40 @@ class PatternInfo {
881881
throw new Error(`Unsupported pattern kind: ${kind}`);
882882
}
883883
}
884-
export { CssFontInfo, FontInfo, PatternInfo, SystemFontInfo };
884+
885+
class FontPathInfo {
886+
static write(path) {
887+
let data;
888+
let buffer;
889+
if (
890+
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) ||
891+
FeatureTest.isFloat16ArraySupported
892+
) {
893+
buffer = new ArrayBuffer(path.length * 2);
894+
data = new Float16Array(buffer);
895+
} else {
896+
buffer = new ArrayBuffer(path.length * 4);
897+
data = new Float32Array(buffer);
898+
}
899+
data.set(path);
900+
return buffer;
901+
}
902+
903+
#buffer;
904+
905+
constructor(buffer) {
906+
this.#buffer = buffer;
907+
}
908+
909+
get path() {
910+
if (
911+
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) ||
912+
FeatureTest.isFloat16ArraySupported
913+
) {
914+
return new Float16Array(this.#buffer);
915+
}
916+
return new Float32Array(this.#buffer);
917+
}
918+
}
919+
920+
export { CssFontInfo, FontInfo, FontPathInfo, PatternInfo, SystemFontInfo };

0 commit comments

Comments
 (0)