mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
Merge pull request #9340 from brendandahl/private-use
Map all glyphs to the private use area and duplicate the first glyph.
This commit is contained in:
commit
66422eb83e
14 changed files with 16188 additions and 304 deletions
3
test/pdfs/.gitignore
vendored
3
test/pdfs/.gitignore
vendored
|
@ -114,6 +114,7 @@
|
|||
!issue5686.pdf
|
||||
!issue3928.pdf
|
||||
!clippath.pdf
|
||||
!issue8795_reduced.pdf
|
||||
!close-path-bug.pdf
|
||||
!issue6019.pdf
|
||||
!issue6621.pdf
|
||||
|
@ -281,6 +282,7 @@
|
|||
!issue5475.pdf
|
||||
!annotation-border-styles.pdf
|
||||
!IdentityToUnicodeMap_charCodeOf.pdf
|
||||
!PDFJS-9279-reduced.pdf
|
||||
!issue5481.pdf
|
||||
!issue5567.pdf
|
||||
!issue5701.pdf
|
||||
|
@ -303,6 +305,7 @@
|
|||
!issue7014.pdf
|
||||
!issue8187.pdf
|
||||
!annotation-link-text-popup.pdf
|
||||
!issue9278.pdf
|
||||
!annotation-text-without-popup.pdf
|
||||
!annotation-underline.pdf
|
||||
!annotation-strikeout.pdf
|
||||
|
|
BIN
test/pdfs/PDFJS-9279-reduced.pdf
Normal file
BIN
test/pdfs/PDFJS-9279-reduced.pdf
Normal file
Binary file not shown.
1
test/pdfs/bug1425312.pdf.link
Normal file
1
test/pdfs/bug1425312.pdf.link
Normal file
|
@ -0,0 +1 @@
|
|||
https://web.archive.org/web/20171116124714/https://www.unicode.org/charts/PDF/U11A50.pdf
|
15887
test/pdfs/issue8795_reduced.pdf
Normal file
15887
test/pdfs/issue8795_reduced.pdf
Normal file
File diff suppressed because one or more lines are too long
BIN
test/pdfs/issue9278.pdf
Normal file
BIN
test/pdfs/issue9278.pdf
Normal file
Binary file not shown.
|
@ -122,6 +122,12 @@
|
|||
"lastPage": 1,
|
||||
"type": "eq"
|
||||
},
|
||||
{ "id": "issue8795_reduced",
|
||||
"file": "pdfs/issue8795_reduced.pdf",
|
||||
"md5": "3ce58fa4aff351d46c42e0677d582099",
|
||||
"rounds": 1,
|
||||
"type": "eq"
|
||||
},
|
||||
{ "id": "issue2391-1",
|
||||
"file": "pdfs/issue2391-1.pdf",
|
||||
"md5": "25ae9cb959612e7b343b55da63af2716",
|
||||
|
@ -2443,6 +2449,12 @@
|
|||
"link": false,
|
||||
"type": "text"
|
||||
},
|
||||
{ "id": "issue9278",
|
||||
"file": "pdfs/issue9278.pdf",
|
||||
"md5": "9819c3a5715c1a46ea5a6740f9ead3da",
|
||||
"rounds": 1,
|
||||
"type": "eq"
|
||||
},
|
||||
{ "id": "bug894572",
|
||||
"file": "pdfs/bug894572.pdf",
|
||||
"md5": "e54a6b0451939f685ed37e3d46e16158",
|
||||
|
@ -3467,6 +3479,15 @@
|
|||
"rounds": 1,
|
||||
"type": "eq"
|
||||
},
|
||||
{ "id": "bug1425312",
|
||||
"file": "pdfs/bug1425312.pdf",
|
||||
"md5": "5b1e7d3e4ba7792fab2b69d1836df5a9",
|
||||
"link": true,
|
||||
"rounds": 1,
|
||||
"firstPage": 2,
|
||||
"lastPage": 2,
|
||||
"type": "eq"
|
||||
},
|
||||
{ "id": "issue3438",
|
||||
"file": "pdfs/issue3438.pdf",
|
||||
"md5": "5aa3340b0920b65a377f697587668f89",
|
||||
|
@ -3706,6 +3727,12 @@
|
|||
"type": "eq",
|
||||
"about": "Image mask in higher resolution than the image itself"
|
||||
},
|
||||
{ "id": "PDFJS-9279-reduced",
|
||||
"file": "pdfs/PDFJS-9279-reduced.pdf",
|
||||
"md5": "a562a25596e9fe571ac6fb5b9f561974",
|
||||
"rounds": 1,
|
||||
"type": "eq"
|
||||
},
|
||||
{ "id": "issue4436",
|
||||
"file": "pdfs/issue4436r.pdf",
|
||||
"md5": "4e43d692d213f56674fcac92110c7364",
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
*/
|
||||
|
||||
import {
|
||||
CFFCompiler, CFFParser, CFFStrings
|
||||
CFFCompiler, CFFFDSelect, CFFParser, CFFStrings
|
||||
} from '../../src/core/cff_parser';
|
||||
import { SEAC_ANALYSIS_ENABLED } from '../../src/core/fonts';
|
||||
import { Stream } from '../../src/core/stream';
|
||||
|
@ -311,7 +311,7 @@ describe('CFFParser', function() {
|
|||
var fdSelect = parser.parseFDSelect(0, 2);
|
||||
|
||||
expect(fdSelect.fdSelect).toEqual([0, 1]);
|
||||
expect(fdSelect.raw).toEqual(bytes);
|
||||
expect(fdSelect.format).toEqual(0);
|
||||
});
|
||||
|
||||
it('parses fdselect format 3', function() {
|
||||
|
@ -327,7 +327,7 @@ describe('CFFParser', function() {
|
|||
var fdSelect = parser.parseFDSelect(0, 4);
|
||||
|
||||
expect(fdSelect.fdSelect).toEqual([9, 9, 0xa, 0xa]);
|
||||
expect(fdSelect.raw).toEqual(bytes);
|
||||
expect(fdSelect.format).toEqual(3);
|
||||
});
|
||||
|
||||
it('parses invalid fdselect format 3 (bug 1146106)', function() {
|
||||
|
@ -343,8 +343,7 @@ describe('CFFParser', function() {
|
|||
var fdSelect = parser.parseFDSelect(0, 4);
|
||||
|
||||
expect(fdSelect.fdSelect).toEqual([9, 9, 0xa, 0xa]);
|
||||
bytes[3] = bytes[4] = 0x00; // The adjusted first range, first gid.
|
||||
expect(fdSelect.raw).toEqual(bytes);
|
||||
expect(fdSelect.format).toEqual(3);
|
||||
});
|
||||
|
||||
// TODO fdArray
|
||||
|
@ -400,5 +399,52 @@ describe('CFFCompiler', function() {
|
|||
expect(names[0].length).toEqual(127);
|
||||
});
|
||||
|
||||
it('compiles fdselect format 0', function() {
|
||||
var fdSelect = new CFFFDSelect(0, [3, 2, 1]);
|
||||
var c = new CFFCompiler();
|
||||
var out = c.compileFDSelect(fdSelect);
|
||||
expect(out).toEqual([
|
||||
0, // format
|
||||
3, // gid: 0 fd 3
|
||||
2, // gid: 1 fd 3
|
||||
1, // gid: 2 fd 3
|
||||
]);
|
||||
});
|
||||
|
||||
it('compiles fdselect format 3', function() {
|
||||
var fdSelect = new CFFFDSelect(3, [0, 0, 1, 1]);
|
||||
var c = new CFFCompiler();
|
||||
var out = c.compileFDSelect(fdSelect);
|
||||
expect(out).toEqual([
|
||||
3, // format
|
||||
0, // nRanges (high)
|
||||
2, // nRanges (low)
|
||||
0, // range struct 0 - first (high)
|
||||
0, // range struct 0 - first (low)
|
||||
0, // range struct 0 - fd
|
||||
0, // range struct 0 - first (high)
|
||||
2, // range struct 0 - first (low)
|
||||
1, // range struct 0 - fd
|
||||
0, // sentinel (high)
|
||||
4, // sentinel (low)
|
||||
]);
|
||||
});
|
||||
|
||||
it('compiles fdselect format 3, single range', function() {
|
||||
var fdSelect = new CFFFDSelect(3, [0, 0]);
|
||||
var c = new CFFCompiler();
|
||||
var out = c.compileFDSelect(fdSelect);
|
||||
expect(out).toEqual([
|
||||
3, // format
|
||||
0, // nRanges (high)
|
||||
1, // nRanges (low)
|
||||
0, // range struct 0 - first (high)
|
||||
0, // range struct 0 - first (low)
|
||||
0, // range struct 0 - fd
|
||||
0, // sentinel (high)
|
||||
2, // sentinel (low)
|
||||
]);
|
||||
});
|
||||
|
||||
// TODO a lot more compiler tests
|
||||
});
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
"dom_utils_spec.js",
|
||||
"encodings_spec.js",
|
||||
"evaluator_spec.js",
|
||||
"fonts_spec.js",
|
||||
"function_spec.js",
|
||||
"message_handler_spec.js",
|
||||
"metadata_spec.js",
|
||||
|
|
|
@ -1,91 +0,0 @@
|
|||
/* Copyright 2017 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 {
|
||||
PRIVATE_USE_OFFSET_END, PRIVATE_USE_OFFSET_START, ProblematicCharRanges
|
||||
} from '../../src/core/fonts';
|
||||
|
||||
/**
|
||||
* Used to validate the entries in `ProblematicCharRanges`, and to ensure that
|
||||
* its total number of characters does not exceed the PUA (Private Use Area)
|
||||
* length.
|
||||
* @returns {Object} An object with {number} `numChars`, {number} `puaLength`,
|
||||
* and {number} `percentage` parameters.
|
||||
*/
|
||||
var checkProblematicCharRanges = function checkProblematicCharRanges() {
|
||||
function printRange(limits) {
|
||||
return '[' + limits.lower.toString('16').toUpperCase() + ', ' +
|
||||
limits.upper.toString('16').toUpperCase() + ')';
|
||||
}
|
||||
|
||||
var numRanges = ProblematicCharRanges.length;
|
||||
if (numRanges % 2 !== 0) {
|
||||
throw new Error('Char ranges must contain an even number of elements.');
|
||||
}
|
||||
var prevLimits, numChars = 0;
|
||||
for (var i = 0; i < numRanges; i += 2) {
|
||||
var limits = {
|
||||
lower: ProblematicCharRanges[i],
|
||||
upper: ProblematicCharRanges[i + 1],
|
||||
};
|
||||
if (!Number.isInteger(limits.lower) || !Number.isInteger(limits.upper)) {
|
||||
throw new Error('Range endpoints must be integers: ' +
|
||||
printRange(limits));
|
||||
}
|
||||
if (limits.lower < 0 || limits.upper < 0) {
|
||||
throw new Error('Range endpoints must be non-negative: ' +
|
||||
printRange(limits));
|
||||
}
|
||||
var range = limits.upper - limits.lower;
|
||||
if (range < 1) {
|
||||
throw new Error('Range must contain at least one element: ' +
|
||||
printRange(limits));
|
||||
}
|
||||
if (prevLimits) {
|
||||
if (limits.lower < prevLimits.lower) {
|
||||
throw new Error('Ranges must be sorted in ascending order: ' +
|
||||
printRange(limits) + ', ' + printRange(prevLimits));
|
||||
}
|
||||
if (limits.lower < prevLimits.upper) {
|
||||
throw new Error('Ranges must not overlap: ' +
|
||||
printRange(limits) + ', ' + printRange(prevLimits));
|
||||
}
|
||||
}
|
||||
prevLimits = {
|
||||
lower: limits.lower,
|
||||
upper: limits.upper,
|
||||
};
|
||||
// The current range is OK.
|
||||
numChars += range;
|
||||
}
|
||||
var puaLength = (PRIVATE_USE_OFFSET_END + 1) - PRIVATE_USE_OFFSET_START;
|
||||
if (numChars > puaLength) {
|
||||
throw new Error('Total number of chars must not exceed the PUA length.');
|
||||
}
|
||||
return {
|
||||
numChars,
|
||||
puaLength,
|
||||
percentage: 100 * (numChars / puaLength),
|
||||
};
|
||||
};
|
||||
|
||||
describe('Fonts', function() {
|
||||
it('checkProblematicCharRanges', function() {
|
||||
var EXPECTED_PERCENTAGE = 100;
|
||||
var result = checkProblematicCharRanges();
|
||||
|
||||
expect(result.percentage).toBeLessThan(EXPECTED_PERCENTAGE);
|
||||
});
|
||||
});
|
|
@ -60,7 +60,6 @@ function initializePDFJS(callback) {
|
|||
'pdfjs-test/unit/dom_utils_spec',
|
||||
'pdfjs-test/unit/encodings_spec',
|
||||
'pdfjs-test/unit/evaluator_spec',
|
||||
'pdfjs-test/unit/fonts_spec',
|
||||
'pdfjs-test/unit/function_spec',
|
||||
'pdfjs-test/unit/message_handler_spec',
|
||||
'pdfjs-test/unit/metadata_spec',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue