Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Feature/custom fonts #1433

Merged
merged 143 commits into from Feb 20, 2018
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
143 commits
Select commit Hold shift + click to select a range
fe0abfb
add custom fonts support
sphilee Sep 2, 2017
98e8d79
fix getVfs error
sphilee Sep 3, 2017
97f8bc6
Merge remote-tracking branch 'upstream/master'
sphilee Sep 3, 2017
f8a91e4
reduce vfs_fonts.js file size
sphilee Sep 4, 2017
64a84a0
modify the addfonts
sphilee Sep 5, 2017
18fb16c
change to camelcase
sphilee Sep 5, 2017
887fc05
Merge pull request #1398 from sphilee/master
MrRio Sep 11, 2017
59d14ab
Update jspdf.js
Uzlopak Sep 20, 2017
2f8c1af
Update jspdf.js
Uzlopak Sep 20, 2017
948648d
Add files via upload
Uzlopak Sep 20, 2017
dd574e7
Add files via upload
Uzlopak Sep 20, 2017
3b70504
Update stroke.pdf
Uzlopak Sep 20, 2017
11fee20
Update jspdf.js
Uzlopak Sep 20, 2017
5ff181c
Update jspdf.js
Uzlopak Sep 20, 2017
73abdaf
Add files via upload
Uzlopak Sep 20, 2017
10561c6
polyfill.js updated
Uzlopak Sep 20, 2017
554fd73
Add files via upload
Uzlopak Sep 20, 2017
757291a
Update jspdf.js
Uzlopak Sep 20, 2017
39a5d8c
Refactor jspdf.js
sphilee Oct 10, 2017
cc5df20
fix alignment
sphilee Oct 12, 2017
f8dbf94
change file saver link
sphilee Oct 12, 2017
e092d5b
encapsulate customfonts
sphilee Oct 22, 2017
c94de44
change reduce, fill method
sphilee Oct 22, 2017
216ddf3
Refactor putFonts function
sphilee Oct 26, 2017
476d13f
Move makeFontTable jspdf.js to plugins/customfonts.js
sphilee Oct 26, 2017
5c626e2
Apply customfonts.js to the eslint syntax.
sphilee Oct 26, 2017
e51d085
Refactor customfonts.js
sphilee Oct 27, 2017
8423f98
Separate vfs.js
sphilee Oct 27, 2017
424875c
Refactor multiline text
sphilee Oct 28, 2017
ecaa308
update build.js
sphilee Oct 30, 2017
decfebc
add customfonts test
sphilee Oct 30, 2017
477a206
test customfonts
sphilee Oct 30, 2017
af60ca4
update build.js
sphilee Oct 30, 2017
eb7daa5
change customfonts test
sphilee Oct 30, 2017
bd08c9a
fix align text
sphilee Oct 31, 2017
e8b83fc
Update split_text_to_size.js
sphilee Oct 31, 2017
f27581b
Merge pull request #1484 from sphilee/feature/custom-fonts
MrRio Nov 2, 2017
054af65
Merge branch 'master' into feature/custom-fonts
MrRio Nov 2, 2017
03204f6
Update split_text_to_size.js
Uzlopak Nov 3, 2017
31f963e
Merge pull request #1501 from arasabbasi/patch-1
MrRio Nov 3, 2017
4ebcd15
Update and rename plugins/ttffont.js to libs/ttffont.js
Uzlopak Jan 11, 2018
1eec5e1
Update main.js
Uzlopak Jan 11, 2018
ae2f26c
Merge branch 'feature/custom-fonts' into refactor_text
Uzlopak Jan 12, 2018
db6cf47
Merge branch 'feature/custom-fonts' into refactor_text
Uzlopak Jan 26, 2018
81c0c5b
Delete customfonts.js
Uzlopak Feb 12, 2018
4476a0e
Update saucelabs.karma.conf.js
Uzlopak Feb 12, 2018
1c25307
Update context2d.js
Uzlopak Feb 12, 2018
e22e6a9
Update arabic.js
Uzlopak Feb 13, 2018
546348f
Update saucelabs.karma.conf.js
Uzlopak Feb 13, 2018
2884dfa
Update arabic.js
Uzlopak Feb 13, 2018
24e1588
Update jspdf.js
Uzlopak Feb 13, 2018
7a582b9
Create arabic.spec.js
Uzlopak Feb 13, 2018
e64562b
Add files via upload
Uzlopak Feb 13, 2018
61ce968
Delete arabic.pdf
Uzlopak Feb 13, 2018
11b74ca
Add files via upload
Uzlopak Feb 13, 2018
4d9ac7b
Update jspdf.js
Uzlopak Feb 13, 2018
cafe33e
Delete standard.spec.js
Uzlopak Feb 13, 2018
243c82f
Delete custom_fonts.pdf
Uzlopak Feb 13, 2018
62378d8
Update utf8.js
Uzlopak Feb 13, 2018
83dec25
Update utf8.js
Uzlopak Feb 13, 2018
aa1b249
Update jspdf.js
Uzlopak Feb 13, 2018
ca2a5a4
Add files via upload
Uzlopak Feb 13, 2018
2e75275
Update jspdf.js
Uzlopak Feb 13, 2018
1910426
Add files via upload
Uzlopak Feb 13, 2018
fa02180
Add files via upload
Uzlopak Feb 13, 2018
eb419aa
Update karma.conf.js
Uzlopak Feb 13, 2018
d58033d
Update jspdf.js
Uzlopak Feb 13, 2018
744b39c
add japanese test
Uzlopak Feb 14, 2018
fdf706d
Delete custom_fonts.html
Uzlopak Feb 14, 2018
94228d2
Delete defaultVFS.js
Uzlopak Feb 14, 2018
bb80796
Update basic.html
Uzlopak Feb 14, 2018
106f7c1
Update basic.js
Uzlopak Feb 14, 2018
da2da23
Update ttfsupport.js
Uzlopak Feb 14, 2018
d18cae0
Update jspdf.js
Uzlopak Feb 14, 2018
6c75dc5
Update ttffont.js
Uzlopak Feb 14, 2018
0949af6
Update utf8.js
Uzlopak Feb 14, 2018
39219de
Merge pull request #1448 from arasabbasi/refactor_text
MrRio Feb 14, 2018
e4f2f3e
Merge branch 'master' into feature/custom-fonts
Uzlopak Feb 15, 2018
eb9055f
fix acroform so that it passes the tests
Uzlopak Feb 15, 2018
0c7740a
Update jspdf.js
Uzlopak Feb 15, 2018
c235adc
Update saucelabs.karma.conf.js
Uzlopak Feb 15, 2018
8a89712
Update saucelabs.karma.conf.js
Uzlopak Feb 15, 2018
49f768e
Update saucelabs.karma.conf.js
Uzlopak Feb 15, 2018
fdc4b43
Update saucelabs.karma.conf.js
Uzlopak Feb 15, 2018
959cddd
Update jspdf.js
Uzlopak Feb 15, 2018
fe4d986
Update compare.js
Uzlopak Feb 15, 2018
cba6044
Update jspdf.js
Uzlopak Feb 15, 2018
e929838
Update acroform.js
Uzlopak Feb 15, 2018
d1b9b4e
Update acroform.js
Uzlopak Feb 15, 2018
4e11950
Update acroform.js
Uzlopak Feb 15, 2018
6ad6497
Update acroform.js
Uzlopak Feb 15, 2018
8423d3a
Update compare.js
Uzlopak Feb 15, 2018
9d3e057
Update compare.js
Uzlopak Feb 15, 2018
1b130e8
Update compare.js
Uzlopak Feb 15, 2018
d17f73e
Update compare.js
Uzlopak Feb 15, 2018
bdc2e7d
Update acroform.js
Uzlopak Feb 15, 2018
b834fe6
Update acroform.js
Uzlopak Feb 15, 2018
53c3225
Update saucelabs.karma.conf.js
Uzlopak Feb 15, 2018
4ea0ba6
Update saucelabs.karma.conf.js
Uzlopak Feb 15, 2018
9a1c00f
Update saucelabs.karma.conf.js
Uzlopak Feb 15, 2018
aebc2be
Update saucelabs.karma.conf.js
Uzlopak Feb 15, 2018
69482b4
Update saucelabs.karma.conf.js
Uzlopak Feb 15, 2018
6cacbec
Update saucelabs.karma.conf.js
Uzlopak Feb 15, 2018
d8fe093
Update saucelabs.karma.conf.js
Uzlopak Feb 15, 2018
ddca806
Update saucelabs.karma.conf.js
Uzlopak Feb 15, 2018
a75e1f7
Update saucelabs.karma.conf.js
Uzlopak Feb 15, 2018
1474bf0
Update ttffont.js
Uzlopak Feb 15, 2018
b851e9c
Update saucelabs.karma.conf.js
Uzlopak Feb 15, 2018
2832722
Add files via upload
Uzlopak Feb 15, 2018
399512a
Update saucelabs.karma.conf.js
Uzlopak Feb 15, 2018
a357900
Update saucelabs.karma.conf.js
Uzlopak Feb 15, 2018
2b90cc8
Update saucelabs.karma.conf.js
Uzlopak Feb 15, 2018
d3dbb53
Update standard.spec.js
Uzlopak Feb 15, 2018
aecbe5f
Update saucelabs.karma.conf.js
Uzlopak Feb 15, 2018
d2ce772
Update standard.spec.js
Uzlopak Feb 15, 2018
79670c0
Update standard.spec.js
Uzlopak Feb 15, 2018
949bae8
Update standard.spec.js
Uzlopak Feb 15, 2018
84d241a
Update standard.spec.js
Uzlopak Feb 15, 2018
7baac7f
Update standard.spec.js
Uzlopak Feb 15, 2018
7f453f5
Update standard.spec.js
Uzlopak Feb 15, 2018
348cbe2
Update standard.spec.js
Uzlopak Feb 15, 2018
f0c74a6
Update standard.spec.js
Uzlopak Feb 15, 2018
1c09ae6
Update standard.spec.js
Uzlopak Feb 15, 2018
cc4ea1f
Update standard.spec.js
Uzlopak Feb 15, 2018
381f079
revert
Uzlopak Feb 15, 2018
526f1a2
Update acroform.js
Uzlopak Feb 15, 2018
850d401
Update standard.spec.js
Uzlopak Feb 15, 2018
9c32303
Update standard.spec.js
Uzlopak Feb 16, 2018
20b0e80
Update saucelabs.karma.conf.js
Uzlopak Feb 16, 2018
ff6e93b
Merge branch 'master' into feature/custom-fonts
Uzlopak Feb 19, 2018
4308dfb
Update standard.spec.js
Uzlopak Feb 19, 2018
0c14369
Update standard.spec.js
Uzlopak Feb 19, 2018
d9a5795
Update package.json
Uzlopak Feb 20, 2018
81634b8
Update .travis.yml
Uzlopak Feb 20, 2018
6e11d4b
Merge branch 'master' into feature/custom-fonts
Uzlopak Feb 20, 2018
d082b45
Update saucelabs.karma.conf.js
Uzlopak Feb 20, 2018
3c0dfd1
Update package.json
Uzlopak Feb 20, 2018
7e97f2d
Update standard.spec.js
Uzlopak Feb 20, 2018
42dc206
Update acroform.js
Uzlopak Feb 20, 2018
1fcdd15
Update standard.spec.js
Uzlopak Feb 20, 2018
b229223
Update jspdf.js
Uzlopak Feb 20, 2018
dd56b51
Update package.json
Uzlopak Feb 20, 2018
45dd407
Update saucelabs.karma.conf.js
Uzlopak Feb 20, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 26 additions & 7 deletions build.js
Expand Up @@ -12,14 +12,32 @@ bundle({
})

// Monkey patching adler32 and filesaver
function monkeyPatch () {
function monkeyPatch() {
return {
transform: (code, id) => {
var file = id.split('/').pop()

if (file === 'adler32cs.js') {
// Make library assign itself to the jsPDF instance instead
// of window to avoid polluting global scope
code = code.replace(/this, function/g, 'jsPDF, function')

// Remove call to require('buffer') since it is not used and
// might import a large arbitrary buffer library if a user is
// using a commonjs module bundler
code = code.replace(/require\('buffer'\)/g, '{}')
}

// Only one define call per module is allowed by requirejs so
// we have to remove calls that other libraries make
if (file === 'adler32cs.js') {
code = code.replace(/typeof define/g, '0')
} else if (file === 'FileSaver.js') {
code = code.replace(/define !== null\) && \(define.amd != null/g, '0')
} else if (file === 'html2canvas.js') {
code = code.replace(/&&\s+define.amd/g, '&& define.amd && false')
}

return code
}
}
Expand All @@ -29,7 +47,7 @@ function monkeyPatch () {
// This plugin makes sure specified local variables are preserved
// and kept local. This plugin wouldn't be necessary if es2015
// modules would be used.
function rawjs (opts) {
function rawjs(opts) {
opts = opts || {}
return {
transform: (code, id) => {
Expand All @@ -51,9 +69,10 @@ function rawjs (opts) {
}
}

function bundle (paths) {
function bundle(paths) {
rollup.rollup({
entry: './main.js',
input: './main.js',
context: 'window',
plugins: [
monkeyPatch(),
rawjs({
Expand All @@ -72,7 +91,7 @@ function bundle (paths) {
}).then((bundle) => {
return bundle.generate({
format: 'umd',
moduleName: 'jspdf'
name: 'jsPDF'
})
}).then(output => {
let code = output.code
Expand All @@ -97,7 +116,7 @@ function bundle (paths) {
})
}

function renew (code) {
function renew(code) {
var date = new Date().toISOString()
var version = require('./package.json').version
var whoami = execSync('whoami').toString().trim()
Expand All @@ -107,4 +126,4 @@ function renew (code) {
code = code.replace(/1\.0\.0-trunk/, version + ' ' + date + ':' + whoami)

return code
}
}
53 changes: 53 additions & 0 deletions examples/custom_fonts/custom_fonts.html
@@ -0,0 +1,53 @@
<!DOCTYPE html>
<!--
/**
* OpenSans.ttf
* Copyright "Digitized data copyright © 2010-2011, Google Corporation."
*
* "Licensed under the Apache License, Version 2.0"
* "http://www.apache.org/licenses/LICENSE-2.0"
*/
-->
<html>

<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>jsPDF custom fonts example</title>
<script src="../../dist/jspdf.debug.js"></script>
<script src="../../examples/js/defaultVFS.js"></script>
</head>

<body>
<script>
var doc = new jsPDF();


doc.addFont('OpenSans-Regular.ttf', 'OpenSans', 'normal');
doc.addFont('OpenSans-Bold.ttf', 'OpenSans', 'bold');
doc.addFont('OpenSans-Italic.ttf', 'OpenSans', 'italic');
doc.addFont('OpenSans-BoldItalic.ttf', 'OpenSans', 'boldItalic');


doc.text(20, 20, 'This is the default font.')

doc.setFont('OpenSans')
doc.setFontType('normal')
doc.text(20, 30, 'This is courier normal.')

doc.setFont('OpenSans')
doc.setFontType('italic')
doc.text(20, 40, 'This is times italic.')

doc.setFont('OpenSans')
doc.setFontType('bold')
doc.text(20, 50, 'This is helvetica bold.')

doc.setFont('OpenSans')
doc.setFontType('bolditalic')
doc.text(20, 60, 'This is courier bolditalic.')

doc.save('custom_fonts.pdf');
</script>
</body>

</html>
16 changes: 16 additions & 0 deletions examples/js/defaultVFS.js

Large diffs are not rendered by default.