Skip to content

Commit eda15ef

Browse files
*se agrego extension labels
1 parent 4870bd4 commit eda15ef

File tree

5 files changed

+485
-317
lines changed

5 files changed

+485
-317
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,7 @@ pdf.Output('F',`test.pdf`);
9898
- [x] *Circle - Dibuja un circulo*
9999
- [x] *DashedRect - Dibuja un rectangulo con borde punteado*
100100
- [x] *subWrite - Escribe Texto De Diferentes tamaños*
101+
- [x] *Set_Font_Size_Label - establece el tamaño de la fuente de la etiqueta*
102+
- [x] *Add_Label - Agrega una etiqueta al documento*
101103
102104
**Puedes encontrar ejemplos de uso [aqui](https://github.com/gamalielmendez/node-fpdf/tree/master/test)**

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
"test18": "node ./test/RoundedRect.js",
2828
"test19": "node ./test/circle_ellipse.js",
2929
"test20": "node ./test/DashedRect.js",
30-
"test21": "node ./test/subWrite.js"
30+
"test21": "node ./test/subWrite.js",
31+
"test22": "node ./test/labels_test.js"
3132
},
3233
"repository": {
3334
"type": "git",

src/extends/labels.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
const { isset } = require('../PHP_CoreFunctions')
2+
3+
function _Set_Format(parent, format) {
4+
5+
parent._Margin_Left = _Convert_Metric(parent, format['marginLeft'], format['metric']);
6+
parent._Margin_Top = _Convert_Metric(parent, format['marginTop'], format['metric']);
7+
parent._X_Space = _Convert_Metric(parent, format['SpaceX'], format['metric']);
8+
parent._Y_Space = _Convert_Metric(parent, format['SpaceY'], format['metric']);
9+
parent._X_Number = format['NX'];
10+
parent._Y_Number = format['NY'];
11+
parent._Width = _Convert_Metric(parent, format['width'], format['metric']);
12+
parent._Height = _Convert_Metric(parent, format['height'], format['metric']);
13+
_Set_Font_Size_Label(parent,format['font-size']);
14+
parent._Padding = _Convert_Metric(parent, 3, 'mm');
15+
16+
}
17+
18+
// convert units (in to mm, mm to in)
19+
// $src must be 'in' or 'mm'
20+
function _Convert_Metric(parent, value, src) {
21+
22+
let dest = parent._Metric_Doc;
23+
24+
if (src !== dest) {
25+
let a = { 'in': 39.37008, 'mm': 1000 }
26+
return value * a[dest] / a[src];
27+
} else {
28+
return value;
29+
}
30+
31+
}
32+
33+
// Give the line height for a given font size
34+
function _Get_Height_Chars(parent, pt) {
35+
36+
let a = { 6: 2, 7: 2.5, 8: 3, 9: 4, 10: 5, 11: 6, 12: 7, 13: 8, 14: 9, 15: 10 }
37+
if (!isset(a[pt])) {
38+
parent.Error('Invalid font size: '.pt);
39+
}
40+
41+
return _Convert_Metric(parent, a[pt], 'mm');
42+
}
43+
44+
// Set the character size
45+
// This changes the line height too
46+
function _Set_Font_Size_Label(parent, pt) {
47+
parent._Line_Height = _Get_Height_Chars(parent, pt);
48+
parent.SetFontSize(pt);
49+
}
50+
51+
// Print a label
52+
function _Add_Label(parent, text) {
53+
54+
parent._COUNTX++;
55+
if (parent._COUNTX == parent._X_Number) {
56+
// Row full, we start a new one
57+
parent._COUNTX = 0;
58+
parent._COUNTY++;
59+
if (parent._COUNTY === parent._Y_Number) {
60+
// End of page reached, we start a new one
61+
parent._COUNTY = 0;
62+
parent.AddPage();
63+
}
64+
}
65+
66+
let _PosX = parent._Margin_Left + parent._COUNTX * (parent._Width + parent._X_Space) + parent._Padding;
67+
let _PosY = parent._Margin_Top + parent._COUNTY * (parent._Height + parent._Y_Space) + parent._Padding;
68+
parent.SetXY(_PosX, _PosY);
69+
parent.MultiCell(parent._Width - parent._Padding, parent._Line_Height, text, 0, 'L');
70+
71+
}
72+
73+
module.exports={
74+
_Set_Font_Size_Label,
75+
_Add_Label,
76+
_Set_Format
77+
}

0 commit comments

Comments
 (0)