Skip to content

Commit 7d4e2eb

Browse files
authored
Increase Code Coverage (#2396)
* Make standard_fonts_metrics. 100% tested Write compress-method ;) * Increase code coverage
1 parent b720de5 commit 7d4e2eb

24 files changed

+240
-241
lines changed

spec/acroform.spec.js

+6
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,12 @@ describe('Module: Acroform Unit Test', function () {
616616
expect(new PushButton().pushButton).toEqual(true);
617617
expect(new PushButton() instanceof Button).toEqual(true);
618618
});
619+
it('ComboBox TopIndex', function () {
620+
var comboBox = new ComboBox();
621+
expect(comboBox.topIndex).toEqual(0);
622+
comboBox.topIndex = 1;
623+
expect(comboBox.topIndex).toEqual(1);
624+
});
619625
});
620626

621627
describe('Module: Acroform Integration Test', function () {

spec/filters.spec.js

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict'
2-
/* global describe, xit, it, jsPDF, comparePdf, jasmine, expect */
2+
/* global describe, it, jsPDF, expect */
33
/**
44
* Standard spec tests
55
*
@@ -13,26 +13,31 @@ describe('Module: Filters', () => {
1313
expect(jsPDF.API.processDataByFilters('61 62 2e6364 65', 'ASCIIHexDecode').data).toEqual("ab.cde");
1414
expect(jsPDF.API.processDataByFilters('61 62 2e6364 657>', 'ASCIIHexDecode').data).toEqual("ab.cdep");
1515
expect(jsPDF.API.processDataByFilters('7>', 'ASCIIHexDecode').data).toEqual("p");
16+
expect(jsPDF.API.processDataByFilters('eRROR', 'ASCIIHexDecode').data).toEqual("");
17+
1618
})
17-
19+
1820
it('ASCIIHexEncode', () => {
19-
21+
2022
expect(jsPDF.API.processDataByFilters("ab.cde", 'ASCIIHexEncode').data).toEqual('61622e636465>');
2123
expect(jsPDF.API.processDataByFilters('ab.cdep', 'ASCIIHexEncode').data).toEqual("61622e63646570>");
2224
expect(jsPDF.API.processDataByFilters("p", 'ASCIIHexEncode').data).toEqual("70>");
2325
})
24-
26+
2527
it('ASCII85Encode', () => {
2628
expect(jsPDF.API.processDataByFilters('Man is distinguished', 'ASCII85Encode').data).toEqual("9jqo^BlbD-BleB1DJ+*+F(f,q~>");
2729
})
28-
30+
2931
it('ASCII85Decode', () => {
3032
expect(jsPDF.API.processDataByFilters('E,9)oF*2M7/c~>', 'ASCII85Decode').data).toEqual("pleasure.");
3133
expect(jsPDF.API.processDataByFilters('E,9 )oF*2M 7/c~>', 'ASCII85Decode').data).toEqual("pleasure.");
3234
})
33-
35+
36+
it('Invalid', () => {
37+
expect(function () {jsPDF.API.processDataByFilters('Man is distinguished', ['invalid']); } ).toThrow(new Error("The filter: \"invalid\" is not implemented"));
38+
})
39+
3440
it('FlateEncode', () => {
3541
expect(jsPDF.API.processDataByFilters('Man is distinguished', ['FlateEncode', 'ASCIIHexEncode']).data).toEqual("789cf34dcc53c82c5648c92c2ec9cc4b2fcd2cce484d0100ad079c4c>");
3642
})
37-
3843
})

spec/processArabic.spec.js

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* global describe, it, expect, jsPDF */
12
describe('Module: ArabicParser', function() {
23

34
it('isArabicLetter', function() {
@@ -145,4 +146,8 @@ describe('Module: ArabicParser', function() {
145146
it('ligatures', function() {
146147
expect(jsPDF.API.processArabic("الله").charCodeAt(0)).toEqual(65010);
147148
});
149+
150+
it('position array passthrough', function() {
151+
expect(jsPDF.API.processArabic({text: [["الله", 0, 0]]}).text[0][0].charCodeAt(0)).toEqual(65010);
152+
});
148153
});
1.18 KB
Binary file not shown.

spec/xmpmetadata.spec.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
/* global describe, it, jsPDF, comparePdf */
22

33
describe('Module: xmp_metadata', () => {
4-
it('make some metadata', () => {
4+
it('make some metadata var. 1', () => {
55
var doc = new jsPDF({ putOnlyUsedFonts: true });
66
doc.addMetadata("My metadata as a string.", "http://my.namespace.uri/");
77
comparePdf(doc.output(), 'xmpmetadata.pdf')
88
});
9+
it('make some metadata var. 2', () => {
10+
var doc = new jsPDF({ putOnlyUsedFonts: true });
11+
doc.addMetadata("My metadata as a string.");
12+
comparePdf(doc.output(), 'xmpmetadata-defaultNS.pdf')
13+
});
914
});

src/jspdf.js

+28-27
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ var jsPDF = (function (global) {
359359
API.setCreationDate = function (date) {
360360
setCreationDate(date);
361361
return this;
362-
}
362+
};
363363

364364
/**
365365
* @name getCreationDate
@@ -371,7 +371,7 @@ var jsPDF = (function (global) {
371371
*/
372372
API.getCreationDate = function (type) {
373373
return getCreationDate(type);
374-
}
374+
};
375375

376376
var padd2 = API.__private__.padd2 = function (number) {
377377
return ('0' + parseInt(number)).slice(-2);
@@ -380,7 +380,13 @@ var jsPDF = (function (global) {
380380
var padd2Hex = API.__private__.padd2Hex = function (hexString) {
381381
hexString = hexString.toString();
382382
return ("00" + hexString).substr(hexString.length);
383-
}
383+
};
384+
385+
var objectNumber = 0; // 'n' Current object number
386+
var offsets = []; // List of offsets. Activated and reset by buildDocument(). Pupulated by various calls buildDocument makes.
387+
var content = [];
388+
var contentLength = 0;
389+
var additionalObjects = [];
384390

385391
var pages = [];
386392
var currentPage;
@@ -639,12 +645,6 @@ var jsPDF = (function (global) {
639645
return documentProperties[key] = value;
640646
};
641647

642-
var objectNumber = 0; // 'n' Current object number
643-
var offsets = []; // List of offsets. Activated and reset by buildDocument(). Pupulated by various calls buildDocument makes.
644-
var content = [];
645-
var contentLength = 0;
646-
var additionalObjects = [];
647-
648648
var fonts = {}; // collection of font objects, where key is fontKey - a dynamically created label for a given font.
649649
var fontmap = {}; // mapping structure fontName > fontStyle > font key - performance layer. See addFont()
650650
var activeFontKey; // will be string representing the KEY of the font as combination of fontName + fontStyle
@@ -893,7 +893,7 @@ var jsPDF = (function (global) {
893893
this.ty = !isNaN(ty) ? ty : 0;
894894

895895
return this;
896-
}
896+
};
897897

898898
/**
899899
* Join the Matrix Values to a String
@@ -1132,7 +1132,8 @@ var jsPDF = (function (global) {
11321132
colorAsRGB += ('0' + Math.floor(parseFloat(colorEncoded[i]) * 255).toString(16)).slice(-2);
11331133
}
11341134
return colorAsRGB;
1135-
}
1135+
};
1136+
11361137
var encodeColorString = API.__private__.encodeColorString = function (options) {
11371138
var color;
11381139

@@ -1242,7 +1243,7 @@ var jsPDF = (function (global) {
12421243
if (typeof jsPDF.API.processDataByFilters !== 'undefined') {
12431244
processedData = jsPDF.API.processDataByFilters(data, filters);
12441245
} else {
1245-
processedData = { data: data, reverseChain: [] }
1246+
processedData = { data: data, reverseChain: [] };
12461247
}
12471248
var filterAsString = processedData.reverseChain + ((Array.isArray(alreadyAppliedFilters)) ? alreadyAppliedFilters.join(' ') : alreadyAppliedFilters.toString());
12481249

@@ -1347,7 +1348,8 @@ var jsPDF = (function (global) {
13471348
});
13481349
out('endobj');
13491350
return pageObjectNumber;
1350-
}
1351+
};
1352+
13511353
var putPages = API.__private__.putPages = function () {
13521354
var n, i, pageObjectNumbers = [];
13531355

@@ -1389,14 +1391,16 @@ var jsPDF = (function (global) {
13891391
var pdfEscapeWithNeededParanthesis = function (text, flags) {
13901392
var addParanthesis = text.indexOf(' ') !== -1;
13911393
return (addParanthesis) ? '(' + pdfEscape(text, flags) + ')' : pdfEscape(text, flags);
1392-
}
1394+
};
1395+
13931396
events.publish('putFont', {
13941397
font: font,
13951398
out: out,
13961399
newObject: newObject,
13971400
putStream: putStream,
13981401
pdfEscapeWithNeededParanthesis: pdfEscapeWithNeededParanthesis
13991402
});
1403+
14001404
if (font.isAlreadyPutted !== true) {
14011405
font.objectNumber = newObject();
14021406
out('<<');
@@ -2055,7 +2059,8 @@ var jsPDF = (function (global) {
20552059

20562060
var getNumberOfPages = API.__private__.getNumberOfPages = API.getNumberOfPages = function () {
20572061
return pages.length - 1;
2058-
}
2062+
};
2063+
20592064
/**
20602065
* Returns a document-specific font key - a label assigned to a
20612066
* font name + font type combination at the time the font was added
@@ -2190,13 +2195,12 @@ var jsPDF = (function (global) {
21902195
};
21912196

21922197
var putXRef = API.__private__.putXRef = function () {
2193-
var i = 1;
21942198
var p = "0000000000";
21952199

21962200
out('xref');
21972201
out('0 ' + (objectNumber + 1));
21982202
out('0000000000 65535 f ');
2199-
for (i = 1; i <= objectNumber; i++) {
2203+
for (var i = 1; i <= objectNumber; i++) {
22002204
var offset = offsets[i];
22012205
if (typeof offset === 'function') {
22022206
out((p + offsets[i]()).slice(-10) + ' 00000 n ');
@@ -2718,7 +2722,7 @@ var jsPDF = (function (global) {
27182722
tmpTextIsOfTypeString = false;
27192723
}
27202724
}
2721-
textIsOfTypeString = tmpTextIsOfTypeString
2725+
textIsOfTypeString = tmpTextIsOfTypeString;
27222726
}
27232727
if (textIsOfTypeString === false) {
27242728
throw new Error('Type of text must be string or Array. "' + text + '" is not recognized.');
@@ -2873,7 +2877,7 @@ var jsPDF = (function (global) {
28732877
//if the coder wrote it explicitly to use a specific
28742878
//renderingMode, then use it
28752879
if (renderingMode !== -1) {
2876-
xtra += renderingMode + " Tr\n"
2880+
xtra += renderingMode + " Tr\n";
28772881
//otherwise check if we used the rendering Mode already
28782882
//if so then set the rendering Mode...
28792883
} else if (usedRenderingMode !== -1) {
@@ -2888,7 +2892,6 @@ var jsPDF = (function (global) {
28882892
align = options.align || 'left';
28892893
var leading = activeFontSize * lineHeight;
28902894
var pageWidth = scope.internal.pageSize.getWidth();
2891-
var lineWidth = lineWidth;
28922895
var activeFont = fonts[activeFontKey];
28932896
charSpace = options.charSpace || activeCharSpace;
28942897
maxWidth = options.maxWidth || 0;
@@ -2953,8 +2956,6 @@ var jsPDF = (function (global) {
29532956
text = [];
29542957
len = da.length;
29552958
for (var h = 0; h < len; h++) {
2956-
newY = (h === 0) ? getVerticalCoordinate(y) : -leading;
2957-
newX = (h === 0) ? getHorizontalCoordinate(x) : 0;
29582959
text.push(da[h]);
29592960
}
29602961
} else if (align === "justify") {
@@ -3033,7 +3034,7 @@ var jsPDF = (function (global) {
30333034
position = f2(parmPosX) + " " + f2(parmPosY) + " Td\n";
30343035
}
30353036
return position;
3036-
}
3037+
};
30373038

30383039
for (var lineIndex = 0; lineIndex < da.length; lineIndex++) {
30393040

@@ -3052,7 +3053,7 @@ var jsPDF = (function (global) {
30523053
break;
30533054
}
30543055

3055-
if (wordSpacingPerLine !== undefined && wordSpacingPerLine[lineIndex] !== undefined) {
3056+
if (typeof wordSpacingPerLine !== 'undefined' && typeof wordSpacingPerLine[lineIndex] !== 'undefined') {
30563057
wordSpacing = wordSpacingPerLine[lineIndex] + " Tw\n";
30573058
}
30583059

@@ -3183,7 +3184,7 @@ var jsPDF = (function (global) {
31833184
result = true;
31843185
}
31853186
return (result);
3186-
}
3187+
};
31873188

31883189
var getStyle = API.__private__.getStyle = API.getStyle = function (style) {
31893190

@@ -3990,7 +3991,7 @@ var jsPDF = (function (global) {
39903991
*/
39913992
API.__private__.getStrokeColor = API.getDrawColor = function () {
39923993
return decodeColorString(strokeColor);
3993-
}
3994+
};
39943995

39953996
/**
39963997
* Sets the stroke color for upcoming elements.
@@ -4125,7 +4126,7 @@ var jsPDF = (function (global) {
41254126
*/
41264127
var getTextColor = API.__private__.getTextColor = API.getTextColor = function () {
41274128
return decodeColorString(textColor);
4128-
}
4129+
};
41294130
/**
41304131
* Sets the text color for upcoming elements.
41314132
*

src/libs/JPEGEncoder.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ function JPEGEncoder(quality) {
528528
//Encode ACs
529529
var end0pos = 63; // was const... which is crazy
530530
while ((end0pos > 0) && (DU[end0pos] == 0)) {
531-
end0pos--
531+
end0pos--;
532532
}
533533
//end0pos = first element in reverse order !=0
534534
if (end0pos == 0) {
@@ -609,7 +609,6 @@ function JPEGEncoder(quality) {
609609
x = 0;
610610
while (x < quadWidth) {
611611
start = quadWidth * y + x;
612-
p = start;
613612
col = -1;
614613
row = 0;
615614

@@ -623,7 +622,7 @@ function JPEGEncoder(quality) {
623622
}
624623

625624
if (x + col >= quadWidth) { // padding right
626-
p -= ((x + col) - quadWidth + 4)
625+
p -= ((x + col) - quadWidth + 4);
627626
}
628627

629628
r = imageData[p++];
@@ -666,7 +665,7 @@ function JPEGEncoder(quality) {
666665
writeWord(0xFFD9); //EOI
667666

668667
return new Uint8Array(byteout);
669-
}
668+
};
670669

671670
function setQuality(quality) {
672671
if (quality <= 0) {

src/libs/ttffont.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* eslint-disable no-control-regex */
2+
/* global jsPDF */
23
/************************************************
34
* Title : custom font *
45
* Start Data : 2017. 01. 22. *
@@ -102,7 +103,7 @@
102103
} else {
103104
contents = b64ToByteArray(vfs);
104105
}
105-
return new TTFFont(contents, name, encoding);
106+
return new TTFFont(contents);
106107
};
107108
/***************************************************************/
108109
/* function : TTFFont gernerator */
@@ -168,7 +169,7 @@
168169
raw = this.post.italic_angle;
169170
hi = raw >> 16;
170171
low = raw & 0xFF;
171-
if (hi & 0x8000 !== 0) {
172+
if ((hi & 0x8000) !== 0) {
172173
hi = -((hi ^ 0xFFFF) + 1);
173174
}
174175
this.italicAngle = +("" + hi + "." + low);
@@ -980,7 +981,7 @@
980981
}
981982
PostTable.prototype.tag = 'post';
982983
PostTable.prototype.parse = function (data) {
983-
var length, numberOfGlyphs, _i, _results;
984+
var length, numberOfGlyphs, _results;
984985
data.pos = this.offset;
985986
this.format = data.readInt();
986987
this.italicAngle = data.readInt();
@@ -1112,9 +1113,9 @@
11121113
}
11131114
NameTable.prototype.tag = 'name';
11141115
NameTable.prototype.parse = function (data) {
1115-
var count, entries, entry, format, i, name, stringOffset, strings, text, _j, _len, _name;
1116+
var count, entries, entry, i, name, stringOffset, strings, text, _j, _len, _name;
11161117
data.pos = this.offset;
1117-
format = data.readShort();
1118+
data.readShort(); //format
11181119
count = data.readShort();
11191120
stringOffset = data.readShort();
11201121
entries = [];
@@ -1694,7 +1695,7 @@
16941695
/* comment : Encode various tables for the characters you use. */
16951696
/***************************************************************/
16961697
Subset.prototype.encode = function (glyID, indexToLocFormat) {
1697-
var cmap, code, glyf, glyphs, id, ids, loca, name, new2old, newIDs, nextGlyphID, old2new, oldID, oldIDs, tables, _ref, _ref1;
1698+
var cmap, code, glyf, glyphs, id, ids, loca, new2old, newIDs, nextGlyphID, old2new, oldID, oldIDs, tables, _ref;
16981699
cmap = CmapTable.encode(this.generateCmap(), 'unicode');
16991700
glyphs = this.glyphsFor(glyID);
17001701
old2new = {
@@ -1746,7 +1747,7 @@
17461747
})();
17471748

17481749
jsPDF.API.PDFObject = (function () {
1749-
var pad, swapBytes;
1750+
var pad;
17501751

17511752
function PDFObject() {}
17521753
pad = function (str, length) {

0 commit comments

Comments
 (0)