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

Add fonts with different font-weights #3036

Merged
merged 18 commits into from Dec 22, 2020
Merged
Changes from 4 commits
Commits
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
11 changes: 9 additions & 2 deletions src/jspdf.js
Expand Up @@ -4850,15 +4850,22 @@ 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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

number|string

* @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) {
encoding = encoding || "Identity-H";
API.addFont = function(postScriptName, fontName, fontStyle, fontWeight, encoding) {
encoding = encoding || "Identity-H"
if ((fontStyle == 'normal' && fontWeight === 'bold') || (fontStyle == 'bold' && fontWeight == 'normal')) {
throw new Error("Invalid Combination of fontweight and fontstyle");
}
if (fontWeight && fontStyle !== fontWeight) {
fontStyle = fontWeight == 400 ? 'normal' : fontWeight == 700 ? 'bold' : fontStyle + ' ' + fontWeight;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • make sure to also compare with 'normal' and 'bold' strings as fontWeight values.
  • Maybe add a comment that the == vs === is intentional

}
return addFont.call(this, postScriptName, fontName, fontStyle, encoding);
};

Expand Down