Commit e584f4bb by Luciano Barletta

each text gets its own style

1 parent b33385d8
......@@ -70,17 +70,22 @@ class Text {
/**
* Both arguments should be real coordinates and not a percentage based on parent element
* @param {string} text
* @param {Vector} position
* @param {Vector} position
* @param {object} font
*/
constructor(text, position) {
constructor(text, position, font) {
this.text = text;
this.position = position;
this.font = font
}
/**
* @param {jsPDF} pdf
*/
draw(pdf) {
pdf.setFont(this.font.font);
pdf.setFontType(this.font.type);
pdf.setFontSize(this.font.size);
pdf.text(
this.text,
this.position.x,
......@@ -224,21 +229,6 @@ const Pos = {
};
function compile(tree, pdf) {
pdf.setFont("Courier");
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;
}
});
tree.children.forEach(child => child.draw(pdf));
return pdf;
}
\ No newline at end of file
......@@ -2,15 +2,20 @@ class PDF1 {
"use strict";
constructor() {
/** Coordinate container that occupies the whole page **/
this.A4 = new Div(
new Vector(0, 0),
new Vector(595, 842)
);
this.containerSize = 86;
this.font = {
"font": "courier",
"type": "normal",
"size": 10
};
}
......@@ -47,12 +52,12 @@ class PDF1 {
const header = this.A4.addRelativeChild(new Div(pointer, new Vector(Pos.end, 3)));
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) {
......@@ -60,11 +65,11 @@ class PDF1 {
const alineador = this.A4.addRelativeChild(new Div(pointer, new Vector(Pos.end, 5)));
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);
......@@ -82,34 +87,34 @@ class PDF1 {
]);
const table = (container, eje, RI, peso, RD) => {
container.addRelativeChildren([
new Text(`Resultado Pruebas en Banco de Suspensión - Eje ${eje}`, new Vector(0, Pos.third)),
new Text("Rendimiento Izquierdo", new Vector(Pos.beg, Pos.two_thirds)),
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), this.font),
new Text(RI, new Vector(Pos.beg + 10, Pos.end, ), this.font),
new Text(RI, new Vector(Pos.beg + 10, Pos.end)),
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("Rendimiento Derecho", new Vector(Pos.three_quarters - 5, Pos.two_thirds)),
new Text(peso, new Vector(Pos.middle - 3, Pos.end), this.font),
new Text(RD, new Vector(Pos.three_quarters + 5, Pos.end))
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), this.font)
]);
};
for (let i = 0; i < ejes.length; 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);
}
frenosToPDF(pointer, data) {
const frenos = this.A4.addRelativeChild(new Div(pointer, new Vector(Pos.end, 60)));
const divsize = new Vector(this.containerSize, Pos.quarter);
......@@ -124,62 +129,62 @@ class PDF1 {
const table = (container, eje, FI, RI, OI, peso, FD, RD, OD) => {
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), this.font),
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), this.font),
new Text(RI, new Vector(Pos.beg_margin + 3, Pos.middle + 10), this.font),
new Text("Fuerza IZ", new Vector(Pos.beg_margin, Pos.quarter)),
new Text(FI, new Vector(Pos.beg_margin + 3, Pos.quarter + 10)),
new Text("Res.Rodadura IZ", new Vector(Pos.beg_margin, Pos.middle)),
new Text(RI, new Vector(Pos.beg_margin + 3, Pos.middle + 10)),
new Text("Ovalidad IZ", new Vector(Pos.beg_margin, Pos.three_quarters)),
new Text(OI, new Vector(Pos.beg_margin + 3, Pos.three_quarters + 10)),
new Text("Peso del Eje", new Vector(Pos.middle - 10, Pos.quarter)),
new Text(peso, new Vector(Pos.middle - 5, Pos.quarter + 10)),
new Text("Ovalidad IZ", new Vector(Pos.beg_margin, Pos.three_quarters), this.font),
new Text("Fuerza DE", new Vector(Pos.three_quarters, Pos.quarter)),
new Text(OI, new Vector(Pos.beg_margin + 3, Pos.three_quarters + 10), this.font),
new Text(FD, new Vector(Pos.three_quarters + 3, Pos.quarter + 10)),
new Text("Peso del Eje", new Vector(Pos.middle - 10, Pos.quarter), this.font),
new Text("Res.Rodadura DE", new Vector(Pos.three_quarters, Pos.middle)),
new Text(peso, new Vector(Pos.middle - 5, Pos.quarter + 10), this.font),
new Text(RD, new Vector(Pos.three_quarters + 3, Pos.middle + 10)),
new Text("Fuerza DE", new Vector(Pos.three_quarters, Pos.quarter), this.font),
new Text("Ovalidad DE", new Vector(Pos.three_quarters, Pos.three_quarters)),
new Text(FD, new Vector(Pos.three_quarters + 3, Pos.quarter + 10), this.font),
new Text(OD, new Vector(Pos.three_quarters + 3, Pos.three_quarters + 10))
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), this.font),
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), this.font)
]);
};
for (let i = 0; i < ejes.length; 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);
}
traseroToPDF(pointer, data) {
const trasero = this.A4.addRelativeChild(new Div(pointer.addxy(Pos.beg_margin + 2, 0), new Vector(this.containerSize, 9)));
trasero.addRelativeChildren([
new Text("Diagnóstico de Frenos - Eje Trasero - Frenos de Mano", new Vector(Pos.beg, Pos.third)),
new Text("Fuerza IZ", new Vector(Pos.beg_margin, Pos.two_thirds)),
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), 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),
]);
......@@ -187,19 +192,19 @@ class PDF1 {
}
gaseshumosToPDF(pointer, data) {
const gaseshumos = this.A4.addRelativeChild(new Div(pointer.addxy(Pos.beg_margin + 2, 0), new Vector(this.containerSize, 9)));
gaseshumos.addRelativeChildren([
new Text("Resultado Analizador de Gases", new Vector(Pos.beg, Pos.third)),
new Text("Resultado Analizador de Humos", new Vector(Pos.two_thirds, Pos.third)),
new Text(`CO ${data['co']} % HC ${data['hc']} ppm`, new Vector(Pos.beg, Pos.two_thirds)),
new Text(`Medición ${data['med']}`, new Vector(Pos.three_quarters, Pos.two_thirds))
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), this.font),
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), this.font)
]);
return pointer.addxy(0, 9);
......
class PDF2 {
class PDF1 {
"use strict";
......@@ -11,6 +11,11 @@ class PDF2 {
);
this.containerSize = 86;
this.font = {
"font": "courier",
"type": "normal",
"size": 10
};
}
......@@ -22,6 +27,7 @@ class PDF2 {
*/
const pdfthis = this;
const functionMapping = [
(pointer, data) => pdfthis.maha(pointer, data['header']),
(pointer, data) => pdfthis.headerToPDF(pointer, data['header']),
(pointer, data) => pdfthis.alineadorToPDF(pointer, data['alineador']),
(pointer, data) => pdfthis.suspensionToPDF(pointer, data['suspension']),
......@@ -47,9 +53,9 @@ class PDF2 {
const header = this.A4.addRelativeChild(new Div(pointer, new Vector(Pos.end, 3)));
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);
......@@ -60,11 +66,11 @@ class PDF2 {
const alineador = this.A4.addRelativeChild(new Div(pointer, new Vector(Pos.end, 5)));
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);
......@@ -84,19 +90,19 @@ class PDF2 {
const table = (container, eje, RI, peso, RD) => {
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 {
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.quarter), divsize),
new Div(new Vector(Pos.beg_margin + 2, Pos.middle), divsize),
new Div(new Vector(Pos.beg_margin + 2, Pos.three_quarters), divsize)
)
]);
const table = (container, eje, FI, RI, OI, peso, FD, RD, OD) => {
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 {
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 {
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 @@
<body>
<div class="PDFButtonContainer">
<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
</button>
<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
</button>
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!