-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
225 lines (213 loc) · 5.71 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
package main
import (
"flag"
"fmt"
"image/color"
"log"
ig "github.com/hmmftg/image-generator"
)
const borderSpace = 0.05
var (
dpi1 = flag.Float64("dpi1", 72, "screen resolution in Dots Per Inch")
dpi2 = flag.Float64("dpi2", 150, "screen resolution in Dots Per Inch")
dpi3 = flag.Float64("dpi3", 300, "screen resolution in Dots Per Inch")
basePath = flag.String("base", "..", "base path")
imagesFolder = flag.String("images", "images", "name of the images folder")
fontFolder = flag.String("fonts", "fonts", "name of the fonts folder")
fontfile = flag.String("fontfile", "arial.ttf", "filename of the ttf font")
// hinting = flag.String("hinting", "full", "none | full")
size = flag.Float64("size", 30, "font size in points")
imageX = flag.Int("imageX", 1000, "imageX")
imageY = flag.Int("imageY", 1000, "imageY")
text1X = flag.Float64("text1X", borderSpace*2, "textX")
text1Y = flag.Float64("text1Y", borderSpace*5, "texty")
text2X = flag.Float64("text2X", borderSpace*2, "textX")
text2Y = flag.Float64("text2Y", borderSpace*15, "texty")
text1 = string("سلام نوشته 11111 ۱۱۱۱")
text2 = string("سلام نوشته 11111 ۱۱۱۱ sd;alsd asd سشمیبسمیبنتمسشیبتکمشسینتبکمشت ینمشسیتب شسیتب شسنمیاب شسیاکبا شکسیاب کشسیابشکسایبا")
text3 = string("145282220.25")
)
func main() {
flag.Parse()
fonts, err := ig.LoadFonts(fmt.Sprintf("%s/%s", *basePath, *fontFolder))
if err != nil {
log.Fatal(err)
}
var faceName = fmt.Sprintf("%s:%f", *fontfile, *size)
images, err := ig.LoadImages(fmt.Sprintf("%s/%s", *basePath, *imagesFolder))
if err != nil {
log.Fatal(err)
}
req := ig.PrintRequest{
Margin: borderSpace * 2,
Drawings: []ig.Drawable{
ig.Text{
Text: text1,
X: *text1X,
Y: *text1Y,
RightAlign: false,
FontFace: faceName,
},
ig.Text{
Text: text3,
X: *text1X + 0.1,
Y: *text1Y + 0.1,
RightAlign: false,
FontFace: faceName,
NumberToPersianWords: true,
},
ig.Text{
Text: text3,
X: *text1X + 0.2,
Y: *text1Y + 0.2,
RightAlign: false,
FontFace: faceName,
NumberToWords: true,
},
ig.Text{
Text: text2,
X: *text2X,
Y: *text2Y,
RightAlign: true,
MaxWidth: 0.9,
FontFace: fmt.Sprintf("%s:%f", *fontfile, 17.85),
},
ig.Text{
Text: text2,
X: *text2X + borderSpace,
Y: *text2Y + borderSpace,
RightAlign: true,
NumbersToArabic: true,
MaxWidth: 0.9,
FontFace: faceName,
},
ig.Text{
Text: "l;asdj aklsdj ajsd lasjdl asjlkd asjd laksdljasl d lasjdl aslkdj lasjdl alsda",
X: *text2X,
Y: *text2Y + borderSpace*2,
RightAlign: false,
MaxWidth: 0.6,
FontFace: faceName,
},
ig.Text{
Text: "l;asdj aklsdj ajsd lasjdl asjlkd asjd laksdljasl d lasjdl aslkdj lasjdl alsda",
X: *text2X,
Y: *text2Y + borderSpace*3,
RightAlign: false,
MaxWidth: 0.7,
FontFace: faceName,
},
ig.Text{
Text: "l;asdj aklsdj ajsd lasjdl asjlkd asjd laksdljasl d lasjdl aslkdj lasjdl alsda",
X: *text2X,
Y: *text2Y + borderSpace*4,
RightAlign: false,
MaxWidth: 0.8,
FontFace: faceName,
},
ig.Rect{
Thickness: 2,
X1: borderSpace,
X2: 1 - borderSpace,
Y1: borderSpace,
Y2: 1 - borderSpace,
Color: ig.GreenRuler,
},
ig.Rect{
Thickness: 2,
X1: borderSpace * 2,
X2: 1 - (borderSpace * 2),
Y1: borderSpace * 2,
Y2: 1 - (borderSpace * 2),
Color: ig.RedRuler,
},
&ig.Image{
ID: "logo1.png",
X: borderSpace * 2,
Y: borderSpace * 2,
RightAlign: true,
Scale: 0.3,
},
},
Images: []ig.ImageData{
{
Dpi: *dpi1,
BackgroundFile: "bg1.png",
Height: *imageY,
Width: *imageX,
FileFormat: ig.Png,
File: "sB.png",
NeedB64: false,
},
{
Dpi: *dpi1,
Height: *imageY,
Width: *imageX,
FileFormat: ig.Png,
File: "s1.png",
NeedB64: false,
},
{
Dpi: *dpi2,
Height: *imageY,
Width: *imageX,
FileFormat: ig.Png,
File: "s2.png",
NeedB64: false,
},
{
Dpi: *dpi3,
Height: *imageY,
Width: *imageX,
FileFormat: ig.Png,
File: "s3.png",
NeedB64: false,
},
{
Dpi: *dpi1,
Height: *imageY,
Width: *imageX,
FileFormat: ig.Bmp,
File: "s1.bmp",
NeedB64: false,
},
{
Dpi: *dpi2,
Height: *imageY,
Width: *imageX,
FileFormat: ig.Bmp,
File: "s2.bmp",
NeedB64: false,
},
{
Dpi: *dpi3,
Height: *imageY,
Width: *imageX,
FileFormat: ig.Bmp,
File: "s3.bmp",
NeedB64: false,
},
{
Dpi: *dpi3,
Height: *imageY,
Width: *imageX,
FileFormat: ig.Bmp,
File: "s4-1.bmp",
NeedB64: false,
MonoChrome: false,
},
{
Dpi: *dpi3,
Height: *imageY,
Width: *imageX,
FileFormat: ig.Bmp,
File: "s4-2.bmp",
NeedB64: false,
MonoChrome: true,
MonoChromeColor: color.Black,
},
},
}
result, err := ig.ProcessRequest(map[string]ig.PrintRequest{"t1": req}, fonts, images)
fmt.Println(err, result)
}