Commit e584f4bb by Luciano Barletta

each text gets its own style

1 parent b33385d8
...@@ -71,16 +71,21 @@ class Text { ...@@ -71,16 +71,21 @@ class Text {
* Both arguments should be real coordinates and not a percentage based on parent element * Both arguments should be real coordinates and not a percentage based on parent element
* @param {string} text * @param {string} text
* @param {Vector} position * @param {Vector} position
* @param {object} font
*/ */
constructor(text, position) { constructor(text, position, font) {
this.text = text; this.text = text;
this.position = position; this.position = position;
this.font = font
} }
/** /**
* @param {jsPDF} pdf * @param {jsPDF} pdf
*/ */
draw(pdf) { draw(pdf) {
pdf.setFont(this.font.font);
pdf.setFontType(this.font.type);
pdf.setFontSize(this.font.size);
pdf.text( pdf.text(
this.text, this.text,
this.position.x, this.position.x,
...@@ -224,21 +229,6 @@ const Pos = { ...@@ -224,21 +229,6 @@ const Pos = {
}; };
function compile(tree, pdf) { function compile(tree, pdf) {
pdf.setFont("Courier"); tree.children.forEach(child => child.draw(pdf));
pdf.setFontType("normal");
pdf.setFontSize(10);
tree.children.forEach(child => {
switch (child.constructor.name) {
case "Text":
pdf.text(child.text, child.position.x, child.position.y);
break;
case "Div":
if (child.drawOutline) {
child.drawDivBox(pdf);
}
compile(child, pdf);
break;
}
});
return pdf; return pdf;
} }
\ No newline at end of file \ No newline at end of file
...@@ -11,6 +11,11 @@ class PDF1 { ...@@ -11,6 +11,11 @@ class PDF1 {
); );
this.containerSize = 86; this.containerSize = 86;
this.font = {
"font": "courier",
"type": "normal",
"size": 10
};
} }
...@@ -47,12 +52,12 @@ class PDF1 { ...@@ -47,12 +52,12 @@ class PDF1 {
const header = this.A4.addRelativeChild(new Div(pointer, new Vector(Pos.end, 3))); const header = this.A4.addRelativeChild(new Div(pointer, new Vector(Pos.end, 3)));
header.addRelativeChildren([ header.addRelativeChildren([
new Text("Dominio: " + data['dominio'], new Vector(Pos.beg_margin, Pos.two_thirds)), new Text("Dominio: " + data['dominio'], new Vector(Pos.beg_margin, Pos.two_thirds), this.font),
new Text("Fecha: " + data['fecha'], new Vector(Pos.third, Pos.two_thirds)) new Text("Fecha: " + data['fecha'], new Vector(Pos.third, Pos.two_thirds), this.font)
]); ]);
return pointer.addxy(0,3); return pointer.addxy(0, 3);
} }
alineadorToPDF(pointer, data) { alineadorToPDF(pointer, data) {
...@@ -60,11 +65,11 @@ class PDF1 { ...@@ -60,11 +65,11 @@ class PDF1 {
const alineador = this.A4.addRelativeChild(new Div(pointer, new Vector(Pos.end, 5))); const alineador = this.A4.addRelativeChild(new Div(pointer, new Vector(Pos.end, 5)));
alineador.addRelativeChildren([ alineador.addRelativeChildren([
new Text("Resultado Pruebas en Banco de Alineador al Paso", new Vector(Pos.beg_margin + 2, Pos.third)), new Text("Resultado Pruebas en Banco de Alineador al Paso", new Vector(Pos.beg_margin + 2, Pos.third), this.font),
new Text("Eje Delantero", new Vector(Pos.beg_margin + 2, Pos.two_thirds)), new Text("Eje Delantero", new Vector(Pos.beg_margin + 2, Pos.two_thirds), this.font),
new Text(data['eje_delan'], new Vector(Pos.quarter, Pos.two_thirds)) new Text(data['eje_delan'], new Vector(Pos.quarter, Pos.two_thirds), this.font)
]); ]);
return pointer.addxy(0, 5); return pointer.addxy(0, 5);
...@@ -84,25 +89,25 @@ class PDF1 { ...@@ -84,25 +89,25 @@ class PDF1 {
const table = (container, eje, RI, peso, RD) => { const table = (container, eje, RI, peso, RD) => {
container.addRelativeChildren([ container.addRelativeChildren([
new Text(`Resultado Pruebas en Banco de Suspensión - Eje ${eje}`, new Vector(0, Pos.third)), new Text(`Resultado Pruebas en Banco de Suspensión - Eje ${eje}`, new Vector(0, Pos.third, ), this.font),
new Text("Rendimiento Izquierdo", new Vector(Pos.beg, Pos.two_thirds)), new Text("Rendimiento Izquierdo", new Vector(Pos.beg, Pos.two_thirds), this.font),
new Text(RI, new Vector(Pos.beg + 10, Pos.end)), new Text(RI, new Vector(Pos.beg + 10, Pos.end, ), this.font),
new Text("Peso Total del Eje", new Vector(Pos.middle - 10, Pos.two_thirds)), new Text("Peso Total del Eje", new Vector(Pos.middle - 10, Pos.two_thirds), this.font),
new Text(peso, new Vector(Pos.middle - 3, Pos.end)), new Text(peso, new Vector(Pos.middle - 3, Pos.end), this.font),
new Text("Rendimiento Derecho", new Vector(Pos.three_quarters - 5, Pos.two_thirds)), new Text("Rendimiento Derecho", new Vector(Pos.three_quarters - 5, Pos.two_thirds), this.font),
new Text(RD, new Vector(Pos.three_quarters + 5, Pos.end)) new Text(RD, new Vector(Pos.three_quarters + 5, Pos.end), this.font)
]); ]);
}; };
for (let i = 0; i < ejes.length; i++) { for (let i = 0; i < ejes.length; i++) {
const x = data[i]; const x = data[i];
table(ejes[i], i-1, x["ren_izq"], x["peso"], x["ren_der"]) table(ejes[i], i - 1, x["ren_izq"], x["peso"], x["ren_der"])
} }
return pointer.addxy(0, 15); return pointer.addxy(0, 15);
...@@ -124,42 +129,42 @@ class PDF1 { ...@@ -124,42 +129,42 @@ class PDF1 {
const table = (container, eje, FI, RI, OI, peso, FD, RD, OD) => { const table = (container, eje, FI, RI, OI, peso, FD, RD, OD) => {
container.addRelativeChildren([ container.addRelativeChildren([
new Text(`Diagnóstico de Frenos - Eje ${eje}`, new Vector(Pos.beg, Pos.beg_margin + 10)), new Text(`Diagnóstico de Frenos - Eje ${eje}`, new Vector(Pos.beg, Pos.beg_margin + 10), this.font),
new Text("Fuerza IZ", new Vector(Pos.beg_margin, Pos.quarter)), new Text("Fuerza IZ", new Vector(Pos.beg_margin, Pos.quarter), this.font),
new Text(FI, new Vector(Pos.beg_margin + 3, Pos.quarter + 10)), new Text(FI, new Vector(Pos.beg_margin + 3, Pos.quarter + 10), this.font),
new Text("Res.Rodadura IZ", new Vector(Pos.beg_margin, Pos.middle)), new Text("Res.Rodadura IZ", new Vector(Pos.beg_margin, Pos.middle), this.font),
new Text(RI, new Vector(Pos.beg_margin + 3, Pos.middle + 10)), new Text(RI, new Vector(Pos.beg_margin + 3, Pos.middle + 10), this.font),
new Text("Ovalidad IZ", new Vector(Pos.beg_margin, Pos.three_quarters)), new Text("Ovalidad IZ", new Vector(Pos.beg_margin, Pos.three_quarters), this.font),
new Text(OI, new Vector(Pos.beg_margin + 3, Pos.three_quarters + 10)), new Text(OI, new Vector(Pos.beg_margin + 3, Pos.three_quarters + 10), this.font),
new Text("Peso del Eje", new Vector(Pos.middle - 10, Pos.quarter)), new Text("Peso del Eje", new Vector(Pos.middle - 10, Pos.quarter), this.font),
new Text(peso, new Vector(Pos.middle - 5, Pos.quarter + 10)), new Text(peso, new Vector(Pos.middle - 5, Pos.quarter + 10), this.font),
new Text("Fuerza DE", new Vector(Pos.three_quarters, Pos.quarter)), new Text("Fuerza DE", new Vector(Pos.three_quarters, Pos.quarter), this.font),
new Text(FD, new Vector(Pos.three_quarters + 3, Pos.quarter + 10)), new Text(FD, new Vector(Pos.three_quarters + 3, Pos.quarter + 10), this.font),
new Text("Res.Rodadura DE", new Vector(Pos.three_quarters, Pos.middle)), new Text("Res.Rodadura DE", new Vector(Pos.three_quarters, Pos.middle), this.font),
new Text(RD, new Vector(Pos.three_quarters + 3, Pos.middle + 10)), new Text(RD, new Vector(Pos.three_quarters + 3, Pos.middle + 10), this.font),
new Text("Ovalidad DE", new Vector(Pos.three_quarters, Pos.three_quarters)), new Text("Ovalidad DE", new Vector(Pos.three_quarters, Pos.three_quarters), this.font),
new Text(OD, new Vector(Pos.three_quarters + 3, Pos.three_quarters + 10)) new Text(OD, new Vector(Pos.three_quarters + 3, Pos.three_quarters + 10), this.font)
]); ]);
}; };
for (let i = 0; i < ejes.length; i++) { for (let i = 0; i < ejes.length; i++) {
const x = data[i]; const x = data[i];
table(ejes[i], i-1, x["f_izq"], x["res_izq"], x["ov_izq"], x["peso"], x["f_der"], x["res_der"], x["ov_der"]); table(ejes[i], i - 1, x["f_izq"], x["res_izq"], x["ov_izq"], x["peso"], x["f_der"], x["res_der"], x["ov_der"]);
} }
return pointer.addxy(0, 60); return pointer.addxy(0, 60);
...@@ -171,15 +176,15 @@ class PDF1 { ...@@ -171,15 +176,15 @@ class PDF1 {
trasero.addRelativeChildren([ trasero.addRelativeChildren([
new Text("Diagnóstico de Frenos - Eje Trasero - Frenos de Mano", new Vector(Pos.beg, Pos.third)), new Text("Diagnóstico de Frenos - Eje Trasero - Frenos de Mano", new Vector(Pos.beg, Pos.third, ), this.font),
new Text("Fuerza IZ", new Vector(Pos.beg_margin, Pos.two_thirds)), new Text("Fuerza IZ", new Vector(Pos.beg_margin, Pos.two_thirds), this.font),
new Text(data['f_izq'], new Vector(Pos.beg_margin, Pos.end)), new Text(data['f_izq'], new Vector(Pos.beg_margin, Pos.end), this.font),
new Text("Fuerza DE", new Vector(Pos.three_quarters, Pos.two_thirds)), new Text("Fuerza DE", new Vector(Pos.three_quarters, Pos.two_thirds), this.font),
new Text(data['f_der'], new Vector(Pos.three_quarters, Pos.end)), new Text(data['f_der'], new Vector(Pos.three_quarters, Pos.end), this.font),
]); ]);
...@@ -192,13 +197,13 @@ class PDF1 { ...@@ -192,13 +197,13 @@ class PDF1 {
gaseshumos.addRelativeChildren([ gaseshumos.addRelativeChildren([
new Text("Resultado Analizador de Gases", new Vector(Pos.beg, Pos.third)), new Text("Resultado Analizador de Gases", new Vector(Pos.beg, Pos.third), this.font),
new Text("Resultado Analizador de Humos", new Vector(Pos.two_thirds, Pos.third)), new Text("Resultado Analizador de Humos", new Vector(Pos.two_thirds, Pos.third), this.font),
new Text(`CO ${data['co']} % HC ${data['hc']} ppm`, new Vector(Pos.beg, Pos.two_thirds)), new Text(`CO ${data['co']} % HC ${data['hc']} ppm`, new Vector(Pos.beg, Pos.two_thirds), this.font),
new Text(`Medición ${data['med']}`, new Vector(Pos.three_quarters, Pos.two_thirds)) new Text(`Medición ${data['med']}`, new Vector(Pos.three_quarters, Pos.two_thirds), this.font)
]); ]);
......
class PDF2 { class PDF1 {
"use strict"; "use strict";
...@@ -11,6 +11,11 @@ class PDF2 { ...@@ -11,6 +11,11 @@ class PDF2 {
); );
this.containerSize = 86; this.containerSize = 86;
this.font = {
"font": "courier",
"type": "normal",
"size": 10
};
} }
...@@ -22,6 +27,7 @@ class PDF2 { ...@@ -22,6 +27,7 @@ class PDF2 {
*/ */
const pdfthis = this; const pdfthis = this;
const functionMapping = [ const functionMapping = [
(pointer, data) => pdfthis.maha(pointer, data['header']),
(pointer, data) => pdfthis.headerToPDF(pointer, data['header']), (pointer, data) => pdfthis.headerToPDF(pointer, data['header']),
(pointer, data) => pdfthis.alineadorToPDF(pointer, data['alineador']), (pointer, data) => pdfthis.alineadorToPDF(pointer, data['alineador']),
(pointer, data) => pdfthis.suspensionToPDF(pointer, data['suspension']), (pointer, data) => pdfthis.suspensionToPDF(pointer, data['suspension']),
...@@ -47,9 +53,9 @@ class PDF2 { ...@@ -47,9 +53,9 @@ class PDF2 {
const header = this.A4.addRelativeChild(new Div(pointer, new Vector(Pos.end, 3))); const header = this.A4.addRelativeChild(new Div(pointer, new Vector(Pos.end, 3)));
header.addRelativeChildren([ header.addRelativeChildren([
new Text("Dominio: " + data['dominio'], new Vector(Pos.beg_margin, Pos.two_thirds)), new Text("Dominio: " + data['dominio'], new Vector(Pos.beg_margin, Pos.two_thirds), this.font),
new Text("Fecha: " + data['fecha'], new Vector(Pos.third, Pos.two_thirds)) new Text("Fecha: " + data['fecha'], new Vector(Pos.third, Pos.two_thirds), this.font)
]); ]);
return pointer.addxy(0, 3); return pointer.addxy(0, 3);
...@@ -60,11 +66,11 @@ class PDF2 { ...@@ -60,11 +66,11 @@ class PDF2 {
const alineador = this.A4.addRelativeChild(new Div(pointer, new Vector(Pos.end, 5))); const alineador = this.A4.addRelativeChild(new Div(pointer, new Vector(Pos.end, 5)));
alineador.addRelativeChildren([ alineador.addRelativeChildren([
new Text("Resultado Pruebas en Banco de Alineador al Paso", new Vector(Pos.beg_margin + 2, Pos.third)), new Text("Resultado Pruebas en Banco de Alineador al Paso", new Vector(Pos.beg_margin + 2, Pos.third), this.font),
new Text("Eje Delantero", new Vector(Pos.beg_margin + 2, Pos.two_thirds)), new Text("Eje Delantero", new Vector(Pos.beg_margin + 2, Pos.two_thirds), this.font),
new Text(data['eje_delan'], new Vector(Pos.quarter, Pos.two_thirds)) new Text(data['eje_delan'], new Vector(Pos.quarter, Pos.two_thirds), this.font)
]); ]);
return pointer.addxy(0, 5); return pointer.addxy(0, 5);
...@@ -84,19 +90,19 @@ class PDF2 { ...@@ -84,19 +90,19 @@ class PDF2 {
const table = (container, eje, RI, peso, RD) => { const table = (container, eje, RI, peso, RD) => {
container.addRelativeChildren([ container.addRelativeChildren([
new Text(`Resultado Pruebas en Banco de Suspensión - Eje ${eje}`, new Vector(0, Pos.third)), new Text(`Resultado Pruebas en Banco de Suspensión - Eje ${eje}`, new Vector(0, Pos.third, ), this.font),
new Text("Rendimiento Izquierdo", new Vector(Pos.beg, Pos.two_thirds)), new Text("Rendimiento Izquierdo", new Vector(Pos.beg, Pos.two_thirds), this.font),
new Text(RI, new Vector(Pos.beg + 10, Pos.end)), new Text(RI, new Vector(Pos.beg + 10, Pos.end, ), this.font),
new Text("Peso Total del Eje", new Vector(Pos.middle - 10, Pos.two_thirds)), new Text("Peso Total del Eje", new Vector(Pos.middle - 10, Pos.two_thirds), this.font),
new Text(peso, new Vector(Pos.middle - 3, Pos.end)), new Text(peso, new Vector(Pos.middle - 3, Pos.end), this.font),
new Text("Rendimiento Derecho", new Vector(Pos.three_quarters - 5, Pos.two_thirds)), new Text("Rendimiento Derecho", new Vector(Pos.three_quarters - 5, Pos.two_thirds), this.font),
new Text(RD, new Vector(Pos.three_quarters + 5, Pos.end)) new Text(RD, new Vector(Pos.three_quarters + 5, Pos.end), this.font)
]); ]);
}; };
...@@ -114,45 +120,45 @@ class PDF2 { ...@@ -114,45 +120,45 @@ class PDF2 {
const divsize = new Vector(this.containerSize, Pos.quarter); const divsize = new Vector(this.containerSize, Pos.quarter);
const ejes = frenos.addRelativeChildren( const ejes = frenos.addRelativeChildren([
new Div(new Vector(Pos.beg_margin + 2, Pos.beg), divsize), new Div(new Vector(Pos.beg_margin + 2, Pos.beg), divsize),
new Div(new Vector(Pos.beg_margin + 2, Pos.quarter), divsize), new Div(new Vector(Pos.beg_margin + 2, Pos.quarter), divsize),
new Div(new Vector(Pos.beg_margin + 2, Pos.middle), divsize), new Div(new Vector(Pos.beg_margin + 2, Pos.middle), divsize),
new Div(new Vector(Pos.beg_margin + 2, Pos.three_quarters), divsize) new Div(new Vector(Pos.beg_margin + 2, Pos.three_quarters), divsize)
) ]);
const table = (container, eje, FI, RI, OI, peso, FD, RD, OD) => { const table = (container, eje, FI, RI, OI, peso, FD, RD, OD) => {
container.addRelativeChildren([ container.addRelativeChildren([
new Text(`Diagnóstico de Frenos - Eje ${eje}`, new Vector(Pos.beg, Pos.beg_margin + 10)), new Text(`Diagnóstico de Frenos - Eje ${eje}`, new Vector(Pos.beg, Pos.beg_margin + 10), this.font),
new Text("Fuerza IZ", new Vector(Pos.beg_margin, Pos.quarter)), new Text("Fuerza IZ", new Vector(Pos.beg_margin, Pos.quarter), this.font),
new Text(FI, new Vector(Pos.beg_margin + 3, Pos.quarter + 10)), new Text(FI, new Vector(Pos.beg_margin + 3, Pos.quarter + 10), this.font),
new Text("Res.Rodadura IZ", new Vector(Pos.beg_margin, Pos.middle)), new Text("Res.Rodadura IZ", new Vector(Pos.beg_margin, Pos.middle), this.font),
new Text(RI, new Vector(Pos.beg_margin + 3, Pos.middle + 10)), new Text(RI, new Vector(Pos.beg_margin + 3, Pos.middle + 10), this.font),
new Text("Ovalidad IZ", new Vector(Pos.beg_margin, Pos.three_quarters)), new Text("Ovalidad IZ", new Vector(Pos.beg_margin, Pos.three_quarters), this.font),
new Text(OI, new Vector(Pos.beg_margin + 3, Pos.three_quarters + 10)), new Text(OI, new Vector(Pos.beg_margin + 3, Pos.three_quarters + 10), this.font),
new Text("Peso del Eje", new Vector(Pos.middle - 10, Pos.quarter)), new Text("Peso del Eje", new Vector(Pos.middle - 10, Pos.quarter), this.font),
new Text(peso, new Vector(Pos.middle - 5, Pos.quarter + 10)), new Text(peso, new Vector(Pos.middle - 5, Pos.quarter + 10), this.font),
new Text("Fuerza DE", new Vector(Pos.three_quarters, Pos.quarter)), new Text("Fuerza DE", new Vector(Pos.three_quarters, Pos.quarter), this.font),
new Text(FD, new Vector(Pos.three_quarters + 3, Pos.quarter + 10)), new Text(FD, new Vector(Pos.three_quarters + 3, Pos.quarter + 10), this.font),
new Text("Res.Rodadura DE", new Vector(Pos.three_quarters, Pos.middle)), new Text("Res.Rodadura DE", new Vector(Pos.three_quarters, Pos.middle), this.font),
new Text(RD, new Vector(Pos.three_quarters + 3, Pos.middle + 10)), new Text(RD, new Vector(Pos.three_quarters + 3, Pos.middle + 10), this.font),
new Text("Ovalidad DE", new Vector(Pos.three_quarters, Pos.three_quarters)), new Text("Ovalidad DE", new Vector(Pos.three_quarters, Pos.three_quarters), this.font),
new Text(OD, new Vector(Pos.three_quarters + 3, Pos.three_quarters + 10)) new Text(OD, new Vector(Pos.three_quarters + 3, Pos.three_quarters + 10), this.font)
]); ]);
}; };
...@@ -171,15 +177,15 @@ class PDF2 { ...@@ -171,15 +177,15 @@ class PDF2 {
trasero.addRelativeChildren([ trasero.addRelativeChildren([
new Text("Diagnóstico de Frenos - Eje Trasero - Frenos de Mano", new Vector(Pos.beg, Pos.third)), new Text("Diagnóstico de Frenos - Eje Trasero - Frenos de Mano", new Vector(Pos.beg, Pos.third, ), this.font),
new Text("Fuerza IZ", new Vector(Pos.beg_margin, Pos.two_thirds)), new Text("Fuerza IZ", new Vector(Pos.beg_margin, Pos.two_thirds), this.font),
new Text(data['f_izq'], new Vector(Pos.beg_margin, Pos.end)), new Text(data['f_izq'], new Vector(Pos.beg_margin, Pos.end), this.font),
new Text("Fuerza DE", new Vector(Pos.three_quarters, Pos.two_thirds)), new Text("Fuerza DE", new Vector(Pos.three_quarters, Pos.two_thirds), this.font),
new Text(data['f_der'], new Vector(Pos.three_quarters, Pos.end)), new Text(data['f_der'], new Vector(Pos.three_quarters, Pos.end), this.font),
]); ]);
...@@ -192,13 +198,13 @@ class PDF2 { ...@@ -192,13 +198,13 @@ class PDF2 {
gaseshumos.addRelativeChildren([ gaseshumos.addRelativeChildren([
new Text("Resultado Analizador de Gases", new Vector(Pos.beg, Pos.third)), new Text("Resultado Analizador de Gases", new Vector(Pos.beg, Pos.third), this.font),
new Text("Resultado Analizador de Humos", new Vector(Pos.two_thirds, Pos.third)), new Text("Resultado Analizador de Humos", new Vector(Pos.two_thirds, Pos.third), this.font),
new Text(`CO ${data['co']} % HC ${data['hc']} ppm`, new Vector(Pos.beg, Pos.two_thirds)), new Text(`CO ${data['co']} % HC ${data['hc']} ppm`, new Vector(Pos.beg, Pos.two_thirds), this.font),
new Text(`Medición ${data['med']}`, new Vector(Pos.three_quarters, Pos.two_thirds)) new Text(`Medición ${data['med']}`, new Vector(Pos.three_quarters, Pos.two_thirds), this.font)
]); ]);
......
...@@ -16,13 +16,25 @@ ...@@ -16,13 +16,25 @@
<body> <body>
<div class="PDFButtonContainer"> <div class="PDFButtonContainer">
<button class="PDFButton" onclick= <button class="PDFButton" onclick=
"window.open(compile((new PDF1()).pdf( {{ data }} ), new jsPDF('portrait', 'pt', 'a4')).output('bloburl'))"; "window.open(
compile(
(new PDF1()).pdf( {{ data }} ),
new jsPDF('portrait', 'pt', 'a4'),
)
.output('bloburl')
)";
> >
Convertir a PDF - 1 Convertir a PDF - 1
</button> </button>
<button class="PDFButton" onclick= <button class="PDFButton" onclick=
"window.open(compile((new PDF2()).pdf( {{ data }} ), new jsPDF('portrait', 'pt', 'a4')).output('bloburl'))"; "window.open(
compile(
(new PDF1()).pdf( {{ data }} ),
new jsPDF('portrait', 'pt', 'a4'),
)
.output('bloburl')
)";
> >
Convertir a PDF - 2 Convertir a PDF - 2
</button> </button>
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!