Skip to content

Commit

Permalink
feat: support bold-italic standard fonts (#1841)
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomura authored May 31, 2022
1 parent 434df31 commit 25a80eb
Show file tree
Hide file tree
Showing 24 changed files with 129 additions and 2,471 deletions.
7 changes: 7 additions & 0 deletions .changeset/wild-deers-kiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@react-pdf/font': minor
'@react-pdf/layout': minor
'@react-pdf/pdfkit': minor
---

feat: support bold-italic standard fonts
3 changes: 3 additions & 0 deletions packages/font/src/standard.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ export default [
'Courier',
'Courier-Bold',
'Courier-Oblique',
'Courier-BoldOblique',
'Helvetica',
'Helvetica-Bold',
'Helvetica-Oblique',
'Helvetica-BoldOblique',
'Times-Roman',
'Times-Bold',
'Times-Italic',
'Times-BoldItalic',
];
6 changes: 6 additions & 0 deletions packages/layout/src/text/standardFont.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ class StandardFont {
case 'Times-Roman':
case 'Times-Bold':
case 'Times-Italic':
case 'Times-BoldItalic':
return 650;
case 'Courier':
case 'Courier-Bold':
case 'Courier-Oblique':
case 'Courier-BoldOblique':
return 550;
default:
return 690;
Expand All @@ -73,10 +75,12 @@ class StandardFont {
case 'Times-Roman':
case 'Times-Bold':
case 'Times-Italic':
case 'Times-BoldItalic':
return 440;
case 'Courier':
case 'Courier-Bold':
case 'Courier-Oblique':
case 'Courier-BoldOblique':
return 390;
default:
return 490;
Expand All @@ -89,10 +93,12 @@ class StandardFont {
case 'Times-Roman':
case 'Times-Bold':
case 'Times-Italic':
case 'Times-BoldItalic':
return -220;
case 'Courier':
case 'Courier-Bold':
case 'Courier-Oblique':
case 'Courier-BoldOblique':
return -230;
default:
return -200;
Expand Down
4 changes: 2 additions & 2 deletions packages/pdfkit/src/font/afm.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function parse(contents) {
case 'KernPairs':
match = line.match(/^KPX\s+(\.?\w+)\s+(\.?\w+)\s+(-?\d+)/);
if (match) {
obj.kernPairs[match[1] + '\0' + match[2]] = parseInt(match[3]);
obj.kernPairs[match[1] + match[2]] = parseInt(match[3]);
}
break;
}
Expand Down Expand Up @@ -241,7 +241,7 @@ class AFMFont {
}

getKernPair(left, right) {
return this.kernPairs[left + '\0' + right] || 0;
return this.kernPairs[left + right] || 0;
}

advancesForGlyphs(glyphs) {
Expand Down
1 change: 0 additions & 1 deletion packages/pdfkit/src/font/data/Courier-Bold.b64.afm

This file was deleted.

2 changes: 1 addition & 1 deletion packages/pdfkit/src/font/data/Courier-BoldOblique.afm
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Weight Bold
ItalicAngle -12
IsFixedPitch true
CharacterSet ExtendedRoman
FontBBox -57 -250 869 801
FontBBox -57 -250 869 801
UnderlinePosition -100
UnderlineThickness 50
Version 003.000
Expand Down
1 change: 0 additions & 1 deletion packages/pdfkit/src/font/data/Courier-BoldOblique.b64.afm

This file was deleted.

Loading

0 comments on commit 25a80eb

Please sign in to comment.