-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Add fonts with different font-weights #3036
Merged
Merged
Changes from 10 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
5c6f8e4
Add fonts with different font-weights #2920
vbinithyanandamv 9aac019
Handled Optional
vbinithyanandamv 847e5af
Undefined cases handled
vbinithyanandamv 1c54cfb
Test Fixed
vbinithyanandamv d4accaf
handled custom fontweight and added test cases
vbinithyanandamv 9309552
removed console
vbinithyanandamv 6b6b00b
ie fix
vbinithyanandamv 37171b9
Preetier added
vbinithyanandamv 1b73948
Merge branch 'master' of https://github.com/MrRio/jsPDF into font-weight
vbinithyanandamv f760a2e
Review changes added
vbinithyanandamv d8ecb73
Fontweight logic added in setfont
vbinithyanandamv 5403236
review Feedback updated
vbinithyanandamv 60ed833
prettier done.
vbinithyanandamv c2f4cc1
test case added for setfont
vbinithyanandamv 18dc53e
review feedback updated
vbinithyanandamv 6b45c14
Run preetier
vbinithyanandamv 9b68061
Re-run build
vbinithyanandamv e88252d
Merge branch 'master' into font-weight
HackbrettXXX File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4795,7 +4795,8 @@ function jsPDF(options) { | |
* @memberof jsPDF# | ||
* @name setFont | ||
*/ | ||
API.setFont = function(fontName, fontStyle) { | ||
API.setFont = function(fontName, fontStyle, fontWeight) { | ||
fontStyle = !fontWeight ? fontStyle : fontStyle + "" + fontWeight; | ||
activeFontKey = getFont(fontName, fontStyle, { | ||
disableWarning: false | ||
}); | ||
|
@@ -4850,14 +4851,52 @@ function jsPDF(options) { | |
* @param {string} postScriptName PDF specification full name for the font. | ||
* @param {string} id PDF-document-instance-specific label assinged to the font. | ||
* @param {string} fontStyle Style of the Font. | ||
* @param {number || string} fontWeight Weight of the Font. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
* @param {Object} encoding Encoding_name-to-Font_metrics_object mapping. | ||
* @function | ||
* @instance | ||
* @memberof jsPDF# | ||
* @name addFont | ||
* @returns {string} fontId | ||
*/ | ||
API.addFont = function(postScriptName, fontName, fontStyle, encoding) { | ||
API.addFont = function( | ||
postScriptName, | ||
fontName, | ||
fontStyle, | ||
fontWeight, | ||
encoding | ||
) { | ||
var encodingOptions = [ | ||
"StandardEncoding", | ||
"MacRomanEncoding", | ||
"Identity-H", | ||
"WinAnsiEncoding" | ||
]; | ||
if (arguments[3] && encodingOptions.indexOf(arguments[3]) !== -1) { | ||
//IE 11 fix | ||
encoding = arguments[3]; | ||
} else if (arguments[3] && encodingOptions.indexOf(arguments[3]) == -1) { | ||
//if weird combination of fontweight and font style throw error | ||
if ( | ||
(fontStyle == "bold" && fontWeight == "normal") || | ||
(fontStyle == "bold" && fontWeight == 400) || | ||
(fontStyle == "normal" && fontWeight == "italic") || | ||
(fontStyle == "bold" && fontWeight == "italic") | ||
) { | ||
throw new Error("Invalid Combination of fontweight and fontstyle"); | ||
} | ||
if (fontWeight && fontStyle !== fontWeight) { | ||
//if fontstyle is normal and fontweight is normal too no need to append the font-weight | ||
fontStyle = | ||
fontWeight == 400 | ||
? fontStyle == "italic" | ||
? "italic" | ||
: "normal" | ||
: fontWeight == 700 && fontStyle !== "italic" | ||
? "bold" | ||
: fontStyle + "" + fontWeight; | ||
} | ||
} | ||
encoding = encoding || "Identity-H"; | ||
return addFont.call(this, postScriptName, fontName, fontStyle, encoding); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need the same logic as in
addFont
here.