mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-07-06 23:25:48 +02:00
Merge pull request #21538 from greymoth-jp/fix/font-encodeString-fffe-fffff
Do not drop the character after U+FFFE or U+FFFF in Font.prototype.encodeString
This commit is contained in:
commit
e148b154cd
@ -3710,7 +3710,7 @@ class Font {
|
|||||||
|
|
||||||
for (let i = 0, ii = str.length; i < ii; i++) {
|
for (let i = 0, ii = str.length; i < ii; i++) {
|
||||||
const unicode = str.codePointAt(i);
|
const unicode = str.codePointAt(i);
|
||||||
if (unicode > 0xd7ff && (unicode < 0xe000 || unicode > 0xfffd)) {
|
if (unicode > 0xffff) {
|
||||||
// unicode is represented by two uint16
|
// unicode is represented by two uint16
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,6 +26,7 @@
|
|||||||
"event_utils_spec.js",
|
"event_utils_spec.js",
|
||||||
"fetch_stream_spec.js",
|
"fetch_stream_spec.js",
|
||||||
"font_substitutions_spec.js",
|
"font_substitutions_spec.js",
|
||||||
|
"fonts_spec.js",
|
||||||
"image_utils_spec.js",
|
"image_utils_spec.js",
|
||||||
"message_handler_spec.js",
|
"message_handler_spec.js",
|
||||||
"metadata_spec.js",
|
"metadata_spec.js",
|
||||||
|
|||||||
44
test/unit/fonts_spec.js
Normal file
44
test/unit/fonts_spec.js
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
/* Copyright 2026 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 { Font } from "../../src/core/fonts.js";
|
||||||
|
import { IdentityToUnicodeMap } from "../../src/core/to_unicode_map.js";
|
||||||
|
|
||||||
|
describe("Font", () => {
|
||||||
|
describe("encodeString", () => {
|
||||||
|
// `encodeString` only reads `this.toUnicode` and `this.cMap`, so a
|
||||||
|
// full `Font` (which needs a complete properties/font-file setup) isn't
|
||||||
|
// necessary to exercise it in isolation.
|
||||||
|
function encodeString(str, { cMap = null } = {}) {
|
||||||
|
const fakeFont = {
|
||||||
|
toUnicode: new IdentityToUnicodeMap(0, 0x10ffff),
|
||||||
|
cMap,
|
||||||
|
};
|
||||||
|
return Font.prototype.encodeString.call(fakeFont, str);
|
||||||
|
}
|
||||||
|
|
||||||
|
it("should keep the character after U+FFFE or U+FFFF", () => {
|
||||||
|
expect(encodeString("A")).toEqual(["\xffA"]);
|
||||||
|
expect(encodeString("B")).toEqual(["\xfeB"]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should still treat a real surrogate pair as one code point", () => {
|
||||||
|
// U+1F602 ("😂") is genuinely represented by a surrogate pair; the
|
||||||
|
// character after it must still be kept, and the pair itself must
|
||||||
|
// not be split into its two unpaired halves.
|
||||||
|
expect(encodeString("😂C")).toEqual(["\x02C"]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -72,6 +72,7 @@ async function initializePDFJS(callback) {
|
|||||||
"pdfjs-test/unit/event_utils_spec.js",
|
"pdfjs-test/unit/event_utils_spec.js",
|
||||||
"pdfjs-test/unit/fetch_stream_spec.js",
|
"pdfjs-test/unit/fetch_stream_spec.js",
|
||||||
"pdfjs-test/unit/font_substitutions_spec.js",
|
"pdfjs-test/unit/font_substitutions_spec.js",
|
||||||
|
"pdfjs-test/unit/fonts_spec.js",
|
||||||
"pdfjs-test/unit/image_utils_spec.js",
|
"pdfjs-test/unit/image_utils_spec.js",
|
||||||
"pdfjs-test/unit/message_handler_spec.js",
|
"pdfjs-test/unit/message_handler_spec.js",
|
||||||
"pdfjs-test/unit/metadata_spec.js",
|
"pdfjs-test/unit/metadata_spec.js",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user