Skip to content

Commit

Permalink
*se agregaron Extensiones nuevas
Browse files Browse the repository at this point in the history
  • Loading branch information
gamalielmendez committed Jan 21, 2022
1 parent 752d04b commit a723345
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 3 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ pdf.Output('F',`test.pdf`);
- [x] *IncludeJS - Añade un script en el lenguaje JavaScript*
- [x] *Bookmark - Añade Bookmark*
- [x] *CreateIndexFromBookmark - Crea Un indice del documento cuando tiene Bookmark*
- [x] *DrawGrid - Crea un grid en la hoja util para diseñar reportes ejemplo en [GitHub](https://github.com/gamalielmendez/node-fpdf)*
- [x] *DrawGrid - Crea un grid en la hoja util para diseñar reportes*
- [x] *RoundedRect - Dibuja un rectangulo con las esquinas redondeadas*
- [x] *Ellipse - Dibuja un elipse*
- [x] *Circle - Dibuja un circulo*
- [x] *DashedRect - Dibuja un rectangulo con borde punteado*
**Puedes encontrar ejemplos de uso [aqui](https://github.com/gamalielmendez/node-fpdf/tree/master/test)**
7 changes: 5 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.36",
"version": "1.0.37",
"description": "port de la libreria de FPDF de PHP",
"main": "index.js",
"directories": {
Expand All @@ -23,7 +23,10 @@
"test14": "node ./test/Bookmark_index_test.js",
"test15": "node ./test/code_i25.js",
"test16": "node ./test/ean13.js",
"test17": "node ./test/gridtest.js"
"test17": "node ./test/gridtest.js",
"test18": "node ./test/RoundedRect.js",
"test19": "node ./test/circle_ellipse.js",
"test20": "node ./test/DashedRect.js"
},
"repository": {
"type": "git",
Expand Down
114 changes: 114 additions & 0 deletions src/fpdf_js.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const i25= require('./extends/code_i25')
const LineGraph = require('./extends/LineGraph')
const ShadowCell = require('./extends/ShadowCell')
const { Readable } = require('stream');
const { match } = require('assert');

module.exports = class FPDF {

Expand Down Expand Up @@ -983,6 +984,119 @@ module.exports = class FPDF {

}

RoundedRect(x, y, w, h, r, style = ''){

let k = this.k;
let hp = this.h;
let op
if(style==='F'){
op='f';
}else if(style==='FD' || style==='DF'){
op='B';
}else{
op='S';
}

let MyArc = 4/3 * (Math.sqrt(2) - 1);
this._out(sprintf('%.2f %.2f m',(x+r)*k,(hp-y)*k ));
let xc = x+w-r ;
let yc = y+r;
this._out(sprintf('%.2f %.2f l', xc*k,(hp-y)*k ));

this._Arc(xc + r*MyArc, yc - r, xc + r, yc - r*MyArc, xc + r, yc);
xc = x+w-r ;
yc = y+h-r;
this._out(sprintf('%.2f %.2f l',(x+w)*k,(hp-yc)*k));
this._Arc(xc + r, yc + r*MyArc, xc + r*MyArc, yc + r, xc, yc + r);
xc = x+r ;
yc = y+h-r;
this._out(sprintf('%.2f %.2f l',xc*k,(hp-(y+h))*k));
this._Arc(xc - r*MyArc, yc + r, xc - r, yc + r*MyArc, xc - r, yc);
xc = x+r ;
yc = y+r;
this._out(sprintf('%.2f %.2f l',(x)*k,(hp-yc)*k ));
this._Arc(xc - r, yc - r*MyArc, xc - r*MyArc, yc - r, xc, yc - r);
this._out(op);
}

_Arc(x1, y1, x2, y2, x3, y3){
let h = this.h;
this._out(sprintf('%.2f %.2f %.2f %.2f %.2f %.2f c ', x1*this.k, (h-y1)*this.k,x2*this.k, (h-y2)*this.k, x3*this.k, (h-y3)*this.k));
}

Circle(x, y, r, style='D'){
this.Ellipse(x,y,r,r,style);
}

Ellipse(x, y, rx, ry, style='D'){

let op

if(style==='F'){
op='f';
}else if(style==='FD' || style==='DF'){
op='B';
}else{
op='S';
}

let lx=4/3*(Math.SQRT2-1)*rx;
let ly=4/3*(Math.SQRT2-1)*ry;
let k=this.k;
let h=this.h;
this._out(sprintf('%.2f %.2f m %.2f %.2f %.2f %.2f %.2f %.2f c',
(x+rx)*k,(h-y)*k,
(x+rx)*k,(h-(y-ly))*k,
(x+lx)*k,(h-(y-ry))*k,
x*k,(h-(y-ry))*k));
this._out(sprintf('%.2f %.2f %.2f %.2f %.2f %.2f c',
(x-lx)*k,(h-(y-ry))*k,
(x-rx)*k,(h-(y-ly))*k,
(x-rx)*k,(h-y)*k));
this._out(sprintf('%.2f %.2f %.2f %.2f %.2f %.2f c',
(x-rx)*k,(h-(y+ly))*k,
(x-lx)*k,(h-(y+ry))*k,
x*k,(h-(y+ry))*k));
this._out(sprintf('%.2f %.2f %.2f %.2f %.2f %.2f c %s',
(x+lx)*k,(h-(y+ry))*k,
(x+rx)*k,(h-(y+ly))*k,
(x+rx)*k,(h-y)*k,
op));
}

DashedRect(x1, y1, x2, y2, width=1, nb=15){

this.SetLineWidth(width);
let longueur=Math.abs(x1-x2);
let hauteur=Math.abs(y1-y2);
let Pointilles
if(longueur>hauteur) {
Pointilles=(longueur/nb)/2; // length of dashes
}
else {
Pointilles=(hauteur/nb)/2;
}

for(let i=x1;i<=x2;i+=Pointilles+Pointilles) {
for(let j=i;j<=(i+Pointilles);j++) {
if(j<=(x2-1)) {
this.Line(j,y1,j+1,y1); // upper dashes
this.Line(j,y2,j+1,y2); // lower dashes
}
}
}

for(let i=y1;i<=y2;i+=Pointilles+Pointilles) {
for(let j=i;j<=(i+Pointilles);j++) {
if(j<=(y2-1)) {
this.Line(x1,j,x1,j+1); // left dashes
this.Line(x2,j,x2,j+1); // right dashes
}
}
}

}

Image(file, x = null, y = null, w = 0, h = 0, type = '', link = '') {
// Put an image on the page
if (file === '') {
Expand Down
11 changes: 11 additions & 0 deletions test/DashedRect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const FPDF = require('../index')
const pdf=new FPDF();

let cPdfName=`${__dirname}/DashedRect.pdf`
pdf.AddPage();
pdf.SetDrawColor(200);
pdf.DashedRect(40,30,165,60);
pdf.SetFont('Arial','B',30);
pdf.SetXY(40,30);
pdf.Cell(125,30,'Enjoy dashes!',0,0,'C');
pdf.Output('f',cPdfName)
9 changes: 9 additions & 0 deletions test/RoundedRect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const FPDF = require('../index')
let cPdfName=`${__dirname}/RoundedRect.pdf`

const pdf = new FPDF();
pdf.AddPage();
pdf.SetLineWidth(0.5);
pdf.SetFillColor(192);
pdf.RoundedRect(70, 30, 68, 46, 3.5, 'DF');
pdf.Output('f',cPdfName)
9 changes: 9 additions & 0 deletions test/circle_ellipse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const FPDF = require('../index')
let cPdfName=`${__dirname}/circle_ellipse.pdf`

const pdf = new FPDF();
pdf.AddPage();
pdf.Ellipse(100,50,30,20);
pdf.SetFillColor(255,255,0);
pdf.Circle(110,47,7,'F');
pdf.Output('f',cPdfName)

0 comments on commit a723345

Please sign in to comment.