Skip to content

Commit 4870bd4

Browse files
* se arreglo fuente helvetica
*se agrego extension subWrite
1 parent a723345 commit 4870bd4

File tree

5 files changed

+92
-25
lines changed

5 files changed

+92
-25
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
### **Apoyar con brave tokens**
77
### ir a repositorio de [GitHub](https://github.com/gamalielmendez/node-fpdf) con el navegador brave
88

9+
### **Apoyar proyecto en Patreon**
10+
[![alt text](https://onlcontent.blob.core.windows.net/images/cimga7b6940b4f4c422180c268a12a6d39d2_ico.png)](https://www.patreon.com/user?u=70304264)
11+
912
# Para Instalar
1013
```javascript
1114
npm i node-fpdf
@@ -94,5 +97,6 @@ pdf.Output('F',`test.pdf`);
9497
- [x] *Ellipse - Dibuja un elipse*
9598
- [x] *Circle - Dibuja un circulo*
9699
- [x] *DashedRect - Dibuja un rectangulo con borde punteado*
100+
- [x] *subWrite - Escribe Texto De Diferentes tamaños*
97101
98102
**Puedes encontrar ejemplos de uso [aqui](https://github.com/gamalielmendez/node-fpdf/tree/master/test)**

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-fpdf",
3-
"version": "1.0.37",
3+
"version": "1.0.38",
44
"description": "port de la libreria de FPDF de PHP",
55
"main": "index.js",
66
"directories": {
@@ -26,7 +26,8 @@
2626
"test17": "node ./test/gridtest.js",
2727
"test18": "node ./test/RoundedRect.js",
2828
"test19": "node ./test/circle_ellipse.js",
29-
"test20": "node ./test/DashedRect.js"
29+
"test20": "node ./test/DashedRect.js",
30+
"test21": "node ./test/subWrite.js"
3031
},
3132
"repository": {
3233
"type": "git",

src/fonts/helveticab.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,26 @@ const Font = {
55
name: 'Helvetica-Bold',
66
up: -100,
77
ut: 50,
8-
cw: {
9-
' ': 278, '!': 278, '"': 355, '#': 556, '$': 556,
10-
'%': 889, '&': 667, '\'': 191, '(': 333, ')': 333,
8+
cw:{
9+
' ': 278, '!': 333, '"': 474, '#': 556, '$': 556,
10+
'%': 889, '&': 722, '\'': 238, '(': 333, ')': 333,
1111
'*': 389, '+': 584, ',': 278, '-': 333, '.': 278,
1212
'/': 278, '0': 556, '1': 556, '2': 556, '3': 556,
1313
'4': 556, '5': 556, '6': 556, '7': 556, '8': 556,
14-
'9': 556, ':': 278, ';': 278, '<': 584, '=': 584,
15-
'>': 584, '?': 556, '@': 1015, 'A': 667, 'B': 667,
16-
'C': 722, 'D': 722, 'E': 667, 'F': 611, 'G': 778,
17-
'H': 722, 'I': 278, 'J': 500, 'K': 667, 'L': 556,
18-
'M': 833, 'N': 722, 'O': 778, 'P': 667, 'Q': 778,
19-
'R': 722, 'S': 667, 'T': 611, 'U': 722, 'V': 667,
20-
'W': 944, 'X': 667, 'Y': 667, 'Z': 611, '[': 278,
21-
'\\': 278, ']': 278, '^': 469, '_': 556, '`': 333,
22-
'a': 556, 'b': 556, 'c': 500, 'd': 556, 'e': 556,
23-
'f': 278, 'g': 556, 'h': 556, 'i': 222, 'j': 222,
24-
'k': 500, 'l': 222, 'm': 833, 'n': 556, 'o': 556,
25-
'p': 556, 'q': 556, 'r': 333, 's': 500, 't': 278,
26-
'u': 556, 'v': 500, 'w': 722, 'x': 500, 'y': 500,
27-
'z': 500, '{': 334, '|': 260, '}': 334, '~': 584
14+
'9': 556, ':': 333, ';': 333, '<':584,'=':584,
15+
'>':584,'?':611,'@':975,'A':722,'B':722,
16+
'C':722,'D':722,'E':667,'F':611,'G':778,
17+
'H':722,'I':278,'J':556,'K':722,'L':611,
18+
'M':833,'N':722,'O':778,'P':667,'Q':778,
19+
'R':722,'S':667,'T':611,'U':722,'V':667,
20+
'W':944,'X':667,'Y':667,'Z':611,'[':333,
21+
'\\':278,']':333,'^':584,'_':556,'`':333,
22+
'a':556,'b':611,'c':556,'d':611,'e':556,
23+
'f':333,'g':611,'h':611,'i':278,'j':278,
24+
'k':556,'l':278,'m':889,'n':611,'o':611,
25+
'p':611,'q':611,'r':389,'s':556,'t':333,
26+
'u':611,'v':556,'w':778,'x':556,'y':556,
27+
'z':500,'{':389,'|':280,'}':389,'~':584
2828
},
2929
enc: 'cp1252',
3030
uv: {

src/fpdf_js.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ module.exports = class FPDF {
128128
// Interior cell margin (1 mm)
129129
this.cMargin = margin / 10;
130130
// Line width (0.2 mm)
131-
this.LineWidth = .567 / this.k;
131+
this.LineWidth = 0.567 / this.k;
132132
// Automatic page break
133133
this.SetAutoPageBreak(true, 2 * margin);
134134
// Default display mode
@@ -884,10 +884,8 @@ module.exports = class FPDF {
884884
}
885885

886886
let cw = this.CurrentFont['cw'];
887-
//this.x = this.lMargin;
888887
let w = this.w - this.rMargin - this.x;
889888
let wmax = ((w - 2 * this.cMargin) * 1000 / this.FontSize);
890-
//console.log('wmax primer calculo',wmax)
891889

892890
let s = str_replace("\r", '', txt);
893891
let nb = strlen(s);
@@ -926,7 +924,7 @@ module.exports = class FPDF {
926924
}
927925

928926
l += cw[c];
929-
927+
930928
if (l > wmax) {
931929
// Automatic line break
932930
if (sep === -1) {
@@ -941,11 +939,11 @@ module.exports = class FPDF {
941939
nl++;
942940
continue;
943941
}
944-
942+
945943
if (i == j) {
946944
i++;
947945
}
948-
946+
949947
this.Cell(w, h, substr(s, j, i - j), 0, 2, '', false, link);
950948
} else {
951949
this.Cell(w, h, substr(s, j, sep - j), 0, 2, '', false, link);
@@ -967,6 +965,7 @@ module.exports = class FPDF {
967965
}
968966

969967
}
968+
970969
// Last chunk
971970
if (i !== j) {
972971
this.Cell(l / 1000 * this.FontSize, h, substr(s, j), 0, 0, '', false, link);
@@ -2742,4 +2741,28 @@ module.exports = class FPDF {
27422741
UPC_A(this,x, y, barcode, h=16, w=.35)
27432742
}
27442743

2744+
subWrite(h, txt, link='', subFontSize=12, subOffset=0)
2745+
{
2746+
// resize font
2747+
let subFontSizeold = this.FontSizePt;
2748+
this.SetFontSize(subFontSize);
2749+
2750+
// reposition y
2751+
subOffset = (((subFontSize - subFontSizeold) / this.k) * 0.3) + (subOffset / this.k);
2752+
let subX = this.x;
2753+
let subY = this.y;
2754+
this.SetXY(subX, subY - subOffset);
2755+
2756+
//Output text
2757+
this.Write(h, txt, link);
2758+
2759+
// restore y position
2760+
subX = this.x;
2761+
subY = this.y;
2762+
this.SetXY(subX, subY + subOffset);
2763+
2764+
// restore font size
2765+
this.SetFontSize(subFontSizeold);
2766+
}
2767+
27452768
}

test/subWrite.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const FPDF = require('../index')
2+
const pdf=new FPDF();
3+
4+
let cPdfName=`${__dirname}/subwrite.pdf`
5+
pdf.AddPage();
6+
7+
pdf.SetFont('Arial','B',12);
8+
9+
pdf.Write(5,'Hello World!');
10+
pdf.SetX(100);
11+
pdf.Write(5,"This is standard text.\n");
12+
pdf.Ln(12);
13+
14+
pdf.subWrite(10,'H','',33);
15+
pdf.Write(10,'ello World!');
16+
pdf.SetX(100);
17+
pdf.Write(10,"This is text with a capital first letter.\n");
18+
pdf.Ln(12);
19+
20+
pdf.subWrite(5,'Y','',6);
21+
pdf.Write(5,'ou can also begin the sentence with a small letter. And word wrap also works if the line is too long!');
22+
23+
pdf.SetX(100);
24+
pdf.Write(5,"This is text with a small first letter.\n");
25+
pdf.Ln(12);
26+
27+
pdf.Write(5,'The world has a lot of km');
28+
pdf.subWrite(5,'2','',6,4);
29+
pdf.SetX(100);
30+
pdf.Write(5,"This is text with a superscripted letter.\n");
31+
pdf.Ln(12);
32+
33+
pdf.Write(5,'The world has a lot of H');
34+
pdf.subWrite(5,'2','',6,-3);
35+
pdf.Write(5,'O');
36+
pdf.SetX(100);
37+
pdf.Write(5,"This is text with a subscripted letter.\n");
38+
39+
pdf.Output('F', cPdfName)

0 commit comments

Comments
 (0)