Skip to content

Commit

Permalink
* se arreglo fuente helvetica
Browse files Browse the repository at this point in the history
*se agrego extension subWrite
  • Loading branch information
gamalielmendez committed Feb 28, 2022
1 parent a723345 commit 4870bd4
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 25 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
### **Apoyar con brave tokens**
### ir a repositorio de [GitHub](https://github.com/gamalielmendez/node-fpdf) con el navegador brave

### **Apoyar proyecto en Patreon**
[![alt text](https://onlcontent.blob.core.windows.net/images/cimga7b6940b4f4c422180c268a12a6d39d2_ico.png)](https://www.patreon.com/user?u=70304264)

# Para Instalar
```javascript
npm i node-fpdf
Expand Down Expand Up @@ -94,5 +97,6 @@ pdf.Output('F',`test.pdf`);
- [x] *Ellipse - Dibuja un elipse*
- [x] *Circle - Dibuja un circulo*
- [x] *DashedRect - Dibuja un rectangulo con borde punteado*
- [x] *subWrite - Escribe Texto De Diferentes tamaños*
**Puedes encontrar ejemplos de uso [aqui](https://github.com/gamalielmendez/node-fpdf/tree/master/test)**
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-fpdf",
"version": "1.0.37",
"version": "1.0.38",
"description": "port de la libreria de FPDF de PHP",
"main": "index.js",
"directories": {
Expand All @@ -26,7 +26,8 @@
"test17": "node ./test/gridtest.js",
"test18": "node ./test/RoundedRect.js",
"test19": "node ./test/circle_ellipse.js",
"test20": "node ./test/DashedRect.js"
"test20": "node ./test/DashedRect.js",
"test21": "node ./test/subWrite.js"
},
"repository": {
"type": "git",
Expand Down
34 changes: 17 additions & 17 deletions src/fonts/helveticab.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@ const Font = {
name: 'Helvetica-Bold',
up: -100,
ut: 50,
cw: {
' ': 278, '!': 278, '"': 355, '#': 556, '$': 556,
'%': 889, '&': 667, '\'': 191, '(': 333, ')': 333,
cw:{
' ': 278, '!': 333, '"': 474, '#': 556, '$': 556,
'%': 889, '&': 722, '\'': 238, '(': 333, ')': 333,
'*': 389, '+': 584, ',': 278, '-': 333, '.': 278,
'/': 278, '0': 556, '1': 556, '2': 556, '3': 556,
'4': 556, '5': 556, '6': 556, '7': 556, '8': 556,
'9': 556, ':': 278, ';': 278, '<': 584, '=': 584,
'>': 584, '?': 556, '@': 1015, 'A': 667, 'B': 667,
'C': 722, 'D': 722, 'E': 667, 'F': 611, 'G': 778,
'H': 722, 'I': 278, 'J': 500, 'K': 667, 'L': 556,
'M': 833, 'N': 722, 'O': 778, 'P': 667, 'Q': 778,
'R': 722, 'S': 667, 'T': 611, 'U': 722, 'V': 667,
'W': 944, 'X': 667, 'Y': 667, 'Z': 611, '[': 278,
'\\': 278, ']': 278, '^': 469, '_': 556, '`': 333,
'a': 556, 'b': 556, 'c': 500, 'd': 556, 'e': 556,
'f': 278, 'g': 556, 'h': 556, 'i': 222, 'j': 222,
'k': 500, 'l': 222, 'm': 833, 'n': 556, 'o': 556,
'p': 556, 'q': 556, 'r': 333, 's': 500, 't': 278,
'u': 556, 'v': 500, 'w': 722, 'x': 500, 'y': 500,
'z': 500, '{': 334, '|': 260, '}': 334, '~': 584
'9': 556, ':': 333, ';': 333, '<':584,'=':584,
'>':584,'?':611,'@':975,'A':722,'B':722,
'C':722,'D':722,'E':667,'F':611,'G':778,
'H':722,'I':278,'J':556,'K':722,'L':611,
'M':833,'N':722,'O':778,'P':667,'Q':778,
'R':722,'S':667,'T':611,'U':722,'V':667,
'W':944,'X':667,'Y':667,'Z':611,'[':333,
'\\':278,']':333,'^':584,'_':556,'`':333,
'a':556,'b':611,'c':556,'d':611,'e':556,
'f':333,'g':611,'h':611,'i':278,'j':278,
'k':556,'l':278,'m':889,'n':611,'o':611,
'p':611,'q':611,'r':389,'s':556,'t':333,
'u':611,'v':556,'w':778,'x':556,'y':556,
'z':500,'{':389,'|':280,'}':389,'~':584
},
enc: 'cp1252',
uv: {
Expand Down
35 changes: 29 additions & 6 deletions src/fpdf_js.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ module.exports = class FPDF {
// Interior cell margin (1 mm)
this.cMargin = margin / 10;
// Line width (0.2 mm)
this.LineWidth = .567 / this.k;
this.LineWidth = 0.567 / this.k;
// Automatic page break
this.SetAutoPageBreak(true, 2 * margin);
// Default display mode
Expand Down Expand Up @@ -884,10 +884,8 @@ module.exports = class FPDF {
}

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

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

l += cw[c];

if (l > wmax) {
// Automatic line break
if (sep === -1) {
Expand All @@ -941,11 +939,11 @@ module.exports = class FPDF {
nl++;
continue;
}

if (i == j) {
i++;
}

this.Cell(w, h, substr(s, j, i - j), 0, 2, '', false, link);
} else {
this.Cell(w, h, substr(s, j, sep - j), 0, 2, '', false, link);
Expand All @@ -967,6 +965,7 @@ module.exports = class FPDF {
}

}

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

subWrite(h, txt, link='', subFontSize=12, subOffset=0)
{
// resize font
let subFontSizeold = this.FontSizePt;
this.SetFontSize(subFontSize);

// reposition y
subOffset = (((subFontSize - subFontSizeold) / this.k) * 0.3) + (subOffset / this.k);
let subX = this.x;
let subY = this.y;
this.SetXY(subX, subY - subOffset);

//Output text
this.Write(h, txt, link);

// restore y position
subX = this.x;
subY = this.y;
this.SetXY(subX, subY + subOffset);

// restore font size
this.SetFontSize(subFontSizeold);
}

}
39 changes: 39 additions & 0 deletions test/subWrite.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const FPDF = require('../index')
const pdf=new FPDF();

let cPdfName=`${__dirname}/subwrite.pdf`
pdf.AddPage();

pdf.SetFont('Arial','B',12);

pdf.Write(5,'Hello World!');
pdf.SetX(100);
pdf.Write(5,"This is standard text.\n");
pdf.Ln(12);

pdf.subWrite(10,'H','',33);
pdf.Write(10,'ello World!');
pdf.SetX(100);
pdf.Write(10,"This is text with a capital first letter.\n");
pdf.Ln(12);

pdf.subWrite(5,'Y','',6);
pdf.Write(5,'ou can also begin the sentence with a small letter. And word wrap also works if the line is too long!');

pdf.SetX(100);
pdf.Write(5,"This is text with a small first letter.\n");
pdf.Ln(12);

pdf.Write(5,'The world has a lot of km');
pdf.subWrite(5,'2','',6,4);
pdf.SetX(100);
pdf.Write(5,"This is text with a superscripted letter.\n");
pdf.Ln(12);

pdf.Write(5,'The world has a lot of H');
pdf.subWrite(5,'2','',6,-3);
pdf.Write(5,'O');
pdf.SetX(100);
pdf.Write(5,"This is text with a subscripted letter.\n");

pdf.Output('F', cPdfName)

0 comments on commit 4870bd4

Please sign in to comment.