Merge 4fed542e3f808350cc4fdb37013b368b12778071 into a96553648551b94652f4b1139c440d53c806836f
This commit is contained in:
commit
94e48bc23b
@ -40,7 +40,11 @@ import {
|
|||||||
lookupMatrix,
|
lookupMatrix,
|
||||||
lookupNormalRect,
|
lookupNormalRect,
|
||||||
} from "./core_utils.js";
|
} from "./core_utils.js";
|
||||||
import { FontInfo, PatternInfo } from "../shared/obj-bin-transform.js";
|
import {
|
||||||
|
FontInfo,
|
||||||
|
FontPathInfo,
|
||||||
|
PatternInfo,
|
||||||
|
} from "../shared/obj-bin-transform.js";
|
||||||
import {
|
import {
|
||||||
getEncoding,
|
getEncoding,
|
||||||
MacRomanEncoding,
|
MacRomanEncoding,
|
||||||
@ -4663,11 +4667,8 @@ class PartialEvaluator {
|
|||||||
if (font.renderer.hasBuiltPath(fontChar)) {
|
if (font.renderer.hasBuiltPath(fontChar)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
handler.send("commonobj", [
|
const buffer = FontPathInfo.write(font.renderer.getPathJs(fontChar));
|
||||||
glyphName,
|
handler.send("commonobj", [glyphName, "FontPath", buffer], [buffer]);
|
||||||
"FontPath",
|
|
||||||
font.renderer.getPathJs(fontChar),
|
|
||||||
]);
|
|
||||||
} catch (reason) {
|
} catch (reason) {
|
||||||
if (evaluatorOptions.ignoreErrors) {
|
if (evaluatorOptions.ignoreErrors) {
|
||||||
warn(`buildFontPaths - ignoring ${glyphName} glyph: "${reason}".`);
|
warn(`buildFontPaths - ignoring ${glyphName} glyph: "${reason}".`);
|
||||||
|
|||||||
@ -45,7 +45,11 @@ import {
|
|||||||
StatTimer,
|
StatTimer,
|
||||||
} from "./display_utils.js";
|
} from "./display_utils.js";
|
||||||
import { FontFaceObject, FontLoader } from "./font_loader.js";
|
import { FontFaceObject, FontLoader } from "./font_loader.js";
|
||||||
import { FontInfo, PatternInfo } from "../shared/obj-bin-transform.js";
|
import {
|
||||||
|
FontInfo,
|
||||||
|
FontPathInfo,
|
||||||
|
PatternInfo,
|
||||||
|
} from "../shared/obj-bin-transform.js";
|
||||||
import {
|
import {
|
||||||
getDataProp,
|
getDataProp,
|
||||||
getFactoryUrlProp,
|
getFactoryUrlProp,
|
||||||
@ -2821,6 +2825,8 @@ class WorkerTransport {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "FontPath":
|
case "FontPath":
|
||||||
|
this.commonObjs.resolve(id, new FontPathInfo(exportedData));
|
||||||
|
break;
|
||||||
case "Image":
|
case "Image":
|
||||||
this.commonObjs.resolve(id, exportedData);
|
this.commonObjs.resolve(id, exportedData);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -436,7 +436,7 @@ class FontFaceObject {
|
|||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
warn(`getPathGenerator - ignoring character: "${ex}".`);
|
warn(`getPathGenerator - ignoring character: "${ex}".`);
|
||||||
}
|
}
|
||||||
const path = makePathFromDrawOPS(cmds);
|
const path = makePathFromDrawOPS(cmds.path);
|
||||||
|
|
||||||
if (!this.fontExtraProperties) {
|
if (!this.fontExtraProperties) {
|
||||||
// Remove the raw path-string, since we don't need it anymore.
|
// Remove the raw path-string, since we don't need it anymore.
|
||||||
|
|||||||
@ -13,7 +13,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { assert, MeshFigureType } from "./util.js";
|
import { assert, FeatureTest, MeshFigureType } from "./util.js";
|
||||||
|
|
||||||
class CssFontInfo {
|
class CssFontInfo {
|
||||||
#buffer;
|
#buffer;
|
||||||
@ -881,4 +881,40 @@ class PatternInfo {
|
|||||||
throw new Error(`Unsupported pattern kind: ${kind}`);
|
throw new Error(`Unsupported pattern kind: ${kind}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export { CssFontInfo, FontInfo, PatternInfo, SystemFontInfo };
|
|
||||||
|
class FontPathInfo {
|
||||||
|
static write(path) {
|
||||||
|
let data;
|
||||||
|
let buffer;
|
||||||
|
if (
|
||||||
|
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) ||
|
||||||
|
FeatureTest.isFloat16ArraySupported
|
||||||
|
) {
|
||||||
|
buffer = new ArrayBuffer(path.length * 2);
|
||||||
|
data = new Float16Array(buffer);
|
||||||
|
} else {
|
||||||
|
buffer = new ArrayBuffer(path.length * 4);
|
||||||
|
data = new Float32Array(buffer);
|
||||||
|
}
|
||||||
|
data.set(path);
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
#buffer;
|
||||||
|
|
||||||
|
constructor(buffer) {
|
||||||
|
this.#buffer = buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
get path() {
|
||||||
|
if (
|
||||||
|
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) ||
|
||||||
|
FeatureTest.isFloat16ArraySupported
|
||||||
|
) {
|
||||||
|
return new Float16Array(this.#buffer);
|
||||||
|
}
|
||||||
|
return new Float32Array(this.#buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { CssFontInfo, FontInfo, FontPathInfo, PatternInfo, SystemFontInfo };
|
||||||
|
|||||||
@ -16,11 +16,14 @@
|
|||||||
import {
|
import {
|
||||||
CssFontInfo,
|
CssFontInfo,
|
||||||
FontInfo,
|
FontInfo,
|
||||||
|
FontPathInfo,
|
||||||
PatternInfo,
|
PatternInfo,
|
||||||
SystemFontInfo,
|
SystemFontInfo,
|
||||||
} from "../../src/shared/obj-bin-transform.js";
|
} from "../../src/shared/obj-bin-transform.js";
|
||||||
import { MeshFigureType } from "../../src/shared/util.js";
|
import { FeatureTest, MeshFigureType } from "../../src/shared/util.js";
|
||||||
|
|
||||||
|
describe("obj-bin-transform", function () {
|
||||||
|
describe("Font data", function () {
|
||||||
const cssFontInfo = {
|
const cssFontInfo = {
|
||||||
fontFamily: "Sample Family",
|
fontFamily: "Sample Family",
|
||||||
fontWeight: "not a number",
|
fontWeight: "not a number",
|
||||||
@ -164,7 +167,9 @@ describe("font data serialization and deserialization", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Pattern data", function () {
|
||||||
const axialPatternIR = [
|
const axialPatternIR = [
|
||||||
"RadialAxial",
|
"RadialAxial",
|
||||||
"axial",
|
"axial",
|
||||||
@ -203,8 +208,8 @@ const meshPatternIR = [
|
|||||||
0, 0, 50, 0, 100, 0, 0, 50, 50, 50, 100, 50, 0, 100, 50, 100, 100, 100,
|
0, 0, 50, 0, 100, 0, 0, 50, 50, 50, 100, 50, 0, 100, 50, 100, 100, 100,
|
||||||
]),
|
]),
|
||||||
new Uint8Array([
|
new Uint8Array([
|
||||||
255, 0, 0, 0, 255, 0, 0, 0, 255, 255, 255, 0, 128, 128, 128, 255, 0, 255, 0,
|
255, 0, 0, 0, 255, 0, 0, 0, 255, 255, 255, 0, 128, 128, 128, 255, 0,
|
||||||
255, 255, 255, 128, 0, 128, 0, 128,
|
255, 0, 255, 255, 255, 128, 0, 128, 0, 128,
|
||||||
]),
|
]),
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
@ -295,9 +300,13 @@ describe("Pattern serialization and deserialization", function () {
|
|||||||
const fig1 = reconstructedIR[4][0];
|
const fig1 = reconstructedIR[4][0];
|
||||||
expect(fig1.type).toEqual(MeshFigureType.TRIANGLES);
|
expect(fig1.type).toEqual(MeshFigureType.TRIANGLES);
|
||||||
expect(fig1.coords).toBeInstanceOf(Int32Array);
|
expect(fig1.coords).toBeInstanceOf(Int32Array);
|
||||||
expect(Array.from(fig1.coords)).toEqual([0, 2, 4, 6, 8, 10, 12, 14, 16]);
|
expect(Array.from(fig1.coords)).toEqual([
|
||||||
|
0, 2, 4, 6, 8, 10, 12, 14, 16,
|
||||||
|
]);
|
||||||
expect(fig1.colors).toBeInstanceOf(Int32Array);
|
expect(fig1.colors).toBeInstanceOf(Int32Array);
|
||||||
expect(Array.from(fig1.colors)).toEqual([0, 2, 4, 6, 8, 10, 12, 14, 16]);
|
expect(Array.from(fig1.colors)).toEqual([
|
||||||
|
0, 2, 4, 6, 8, 10, 12, 14, 16,
|
||||||
|
]);
|
||||||
expect(fig1.verticesPerRow).toBeUndefined();
|
expect(fig1.verticesPerRow).toBeUndefined();
|
||||||
|
|
||||||
const fig2 = reconstructedIR[4][1];
|
const fig2 = reconstructedIR[4][1];
|
||||||
@ -450,3 +459,27 @@ describe("Pattern serialization and deserialization", function () {
|
|||||||
expect(reconstructedIR[7]).toBeNull();
|
expect(reconstructedIR[7]).toBeNull();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("FontPath data", function () {
|
||||||
|
const path = FeatureTest.isFloat16ArraySupported
|
||||||
|
? new Float16Array([
|
||||||
|
0.214, 0.27, 0.23, 0.33, 0.248, 0.395, 0.265, 0.471, 0.281, 0.54,
|
||||||
|
0.285, 0.54, 0.302, 0.472, 0.32, 0.395, 0.338, 0.33, 0.353, 0.27,
|
||||||
|
0.214, 0.27, 0.423, 0, 0.579, 0, 0.375, 0.652, 0.198, 0.652, -0.006,
|
||||||
|
0, 0.144, 0, 0.184, 0.155, 0.383, 0.155,
|
||||||
|
])
|
||||||
|
: new Float32Array([
|
||||||
|
0.214, 0.27, 0.23, 0.33, 0.248, 0.395, 0.265, 0.471, 0.281, 0.54,
|
||||||
|
0.285, 0.54, 0.302, 0.472, 0.32, 0.395, 0.338, 0.33, 0.353, 0.27,
|
||||||
|
0.214, 0.27, 0.423, 0, 0.579, 0, 0.375, 0.652, 0.198, 0.652, -0.006,
|
||||||
|
0, 0.144, 0, 0.184, 0.155, 0.383, 0.155,
|
||||||
|
]);
|
||||||
|
|
||||||
|
it("should create a FontPathInfo instance from an array of path commands", function () {
|
||||||
|
const buffer = FontPathInfo.write(path);
|
||||||
|
const fontPathInfo = new FontPathInfo(buffer);
|
||||||
|
expect(fontPathInfo.path).toEqual(path);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user