-
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
Changes from 9 commits
5c6f8e4
9aac019
847e5af
1c54cfb
d4accaf
9309552
6b6b00b
37171b9
1b73948
f760a2e
d8ecb73
5403236
60ed833
c2f4cc1
18dc53e
6b45c14
9b68061
e88252d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4850,14 +4850,50 @@ 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. | ||
* @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 | ||
) { | ||
let encodingOptions = [ | ||
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. Can't use 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. Done. |
||
"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 weired combination of fontweight and font style throw error | ||
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. typo ;) 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. Done. |
||
if ( | ||
(fontStyle == "normal" && fontWeight == "bold") || | ||
vbinithyanandamv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(fontStyle == "bold" && fontWeight == "normal") || | ||
(fontStyle == "bold" && fontWeight == 400) || | ||
(fontStyle == "normal" && fontWeight == 700) | ||
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. normal+700 as well 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. Done. |
||
) { | ||
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 | ||
? "normal" | ||
: fontWeight == 700 | ||
? "bold" | ||
: fontStyle + "" + fontWeight; | ||
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. What about "italic" fontStyle? E.g. "italic" + "400" should result in "italic". 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. Done. |
||
} | ||
} | ||
encoding = encoding || "Identity-H"; | ||
return addFont.call(this, postScriptName, fontName, fontStyle, encoding); | ||
}; | ||
|
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.
number|string