Files
pdf.js/test/unit/to_unicode_map_spec.js
calixteman b4aa2afa17 Use CharCodeMap for font character mappings (bug 2077176)
Store CMap, ToUnicode and CIDToGIDMap entries in an Array for integer
codes in [0, 0xFFFF] and a Map for other codes. Track keys separately
to preserve insertion order without scanning array holes.

Cache reverse lookups after eight linear searches, preserving the
first matching code. This avoids repeated scans during CFF glyph
mapping and string encoding.
2026-10-06 21:56:07 +02:00

36 lines
1.2 KiB
JavaScript

/* Copyright 2025 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { CharCodeMap } from "../../src/core/char_code_map.js";
import { ToUnicodeMap } from "../../src/core/to_unicode_map.js";
describe("ToUnicodeMap", () => {
it("should correctly map Extension B characters using codePointAt", () => {
const cmap = new CharCodeMap();
cmap.set(0x20, "\uD840\uDC00"); // U+20000.
const toUnicodeMap = new ToUnicodeMap(cmap);
const expected = 0x20000; // Unicode code point for the character
let actual;
toUnicodeMap.forEach((charCode, unicode) => {
if (charCode === 0x20) {
actual = unicode;
}
});
expect(actual).toBe(expected);
});
});