/
tl_paint.cpp
258 lines (219 loc) · 8.4 KB
/
tl_paint.cpp
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
/*
tl_paint.cpp (emx+gcc)
Tape Label Editor Version 0.09
1995 1996 Giovanni Iachello
This is freeware software. You can use or modify it as you wish,
provided that the part of code that I wrote remains freeware.
Freeware means that the source code must be available on request
to anyone.
You must also include this notice in all files derived from this
file.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include "tapelab.h"
#include "pmdlg.h"
#include "pmgpi.h"
#include "pmstdres.h"
BOOL TapeLab::paint(PMPresSpace& ps)
{
PMRect rcl;
rcl=this;
// inizializzazione
ps.fillRect(&rcl,CLR_PALEGRAY);
SIZEL size;
size.cx=1500;
size.cy=fixpoints[labelformat.size][0].y+100;
ps.set(&size,PU_LOMETRIC);
PMRect q;
ps.queryPageViewport(&q);
if ( sizey==-1 ) {
sizey=rcl.yTop;
}
if ( posy==-1 ) {
posy=q.yTop-sizey;
}
PMRect r(0,-posy,q.xRight,q.yTop-posy);
ps.setPageViewport(&r);
sb->setScrollBar(q.yTop-sizey-posy,0,q.yTop-sizey);
sb->setThumbSize(sizey,q.yTop);
// scatola bianca | white box
ps.setColor(CLR_WHITE);
ps.move(&fixpoints[labelformat.size][0]);
ps.box(DRO_FILL,&fixpoints[labelformat.size][labelformat.flaps*2 +1]);
return paintlabel(ps);
}
// parte in comune fra stampante e schermo
BOOL TapeLab::paintlabel(PMPresSpace& ps)
{
ps.setColor(CLR_BLACK);
// righe orizzontali
int i;
for (i=0; i<=labelformat.flaps; i++) {
if (i>0 && i<labelformat.flaps) ps.setLineType(LINETYPE_DOT);
else ps.setLineType(LINETYPE_DEFAULT);
ps.move(&fixpoints[labelformat.size][i*2]);
ps.line(&fixpoints[labelformat.size][i*2+1]);
}
// righe verticali
ps.move(&fixpoints[labelformat.size][0]);
ps.line(&fixpoints[labelformat.size][ labelformat.flaps * 2 ]);
ps.move(&fixpoints[labelformat.size][1]);
ps.line(&fixpoints[labelformat.size][ ( labelformat.flaps * 2 ) + 1 ]);
// esegue clip dentro a rettangolo dell'etichetta!
PMRect clip(fixpoints[labelformat.size][labelformat.flaps*2],fixpoints[labelformat.size][1]);
ps.intersectClipRectangle(&clip);
// titolo
PMPoint a;
if (labelformat.title2[0] != '\0') { // ci sono 2 titoli
a.y=(fixpoints[labelformat.size][2].y+fixpoints[labelformat.size][4].y)/2;
a.x=fixpoints[labelformat.size][2].x+labelformat.form.titlelm;
a.y=a.y+ (((fixpoints[labelformat.size][2].y-fixpoints[labelformat.size][4].y)/2)-pts2dmm(labelformat.title1font.height))/2 ;
paintString(labelformat.title1,&labelformat.title1font,1000L,a,ps);
a.y=fixpoints[labelformat.size][4].y;
a.x=fixpoints[labelformat.size][2].x+labelformat.form.titlelm;
a.y=a.y+ (((fixpoints[labelformat.size][2].y-fixpoints[labelformat.size][4].y)/2)-pts2dmm(labelformat.title2font.height))/2 ;
paintString(labelformat.title2,&labelformat.title2font,1000L,a,ps);
} else { // c'e' un solo titolo
a.x=fixpoints[labelformat.size][2].x+labelformat.form.titlelm;
a.y=(fixpoints[labelformat.size][2].y+fixpoints[labelformat.size][4].y-pts2dmm(labelformat.title1font.height)) / 2 ;
paintString(labelformat.title1,&labelformat.title1font,1000L,a,ps);
}
// testo
a.y=fixpoints[labelformat.size][4].y-pts2dmm(labelformat.text1font.height)-labelformat.form.texttm;
a.x=fixpoints[labelformat.size][4].x+labelformat.form.textlm;
paintString(labelformat.text1,&labelformat.text1font,labelformat.form.textvert1,a,ps);
a.y=fixpoints[labelformat.size][4].y-pts2dmm(labelformat.text1font.height)-labelformat.form.texttm;
a.x=(fixpoints[labelformat.size][4].x+fixpoints[labelformat.size][5].x)/2+labelformat.form.textlm;
paintString(labelformat.text2,&labelformat.text2font,labelformat.form.textvert2,a,ps);
if (labelformat.size != 2 && labelformat.flaps > 2) {
a.y=fixpoints[labelformat.size][0].y-pts2dmm(labelformat.datefont.height)-15;
// data A
if (labelformat.whatinfo[0]) {
a.x=fixpoints[labelformat.size][0].x+20;
paintString(labelformat.date1,&labelformat.datefont,1000L,a,ps);
}
// data B
if (labelformat.whatinfo[1]) {
a.x=fixpoints[labelformat.size][1].x-queryStrWidth(labelformat.date2,&labelformat.datefont,ps)-20;
paintString(labelformat.date2,&labelformat.datefont,1000L,a,ps);
}
// "DATE"
if (labelformat.whatinfo[1] || labelformat.whatinfo[0]) {
a.x=(fixpoints[labelformat.size][0].x+fixpoints[labelformat.size][1].x-queryStrWidth("DATE",&labelformat.datefont,ps))/2;
paintString("DATE",&labelformat.datefont,1000L,a,ps);
a.y-=pts2dmm(labelformat.sourcefont.height); // se c'era uno dei due abbassati...
}
// source A
if (labelformat.whatinfo[4]) {
a.x=fixpoints[labelformat.size][0].x+20;
paintString(apchSources[labelformat.source1],&labelformat.sourcefont,1000L,a,ps);
}
// source B
if (labelformat.whatinfo[5]) {
a.x=fixpoints[labelformat.size][1].x-queryStrWidth(apchSources[labelformat.source2],&labelformat.sourcefont,ps)-20;
paintString(apchSources[labelformat.source2],&labelformat.sourcefont,1000L,a,ps);
}
// "SOURCE"
if (labelformat.whatinfo[4] || labelformat.whatinfo[5]) {
a.x=(fixpoints[labelformat.size][0].x+fixpoints[labelformat.size][1].x-queryStrWidth("SOURCE",&labelformat.sourcefont,ps))/2;
paintString("SOURCE",&labelformat.sourcefont,1000L,a,ps);
a.y-=pts2dmm(labelformat.nrfont.height);
}
// NR A
if (labelformat.whatinfo[2]) {
a.x=fixpoints[labelformat.size][0].x+20;
paintString(apchNR[labelformat.nr1],&labelformat.nrfont,1000L,a,ps);
}
// NR B
if (labelformat.whatinfo[3]) {
a.x=fixpoints[labelformat.size][1].x-queryStrWidth(apchNR[labelformat.nr2],&labelformat.nrfont,ps)-20;
paintString(apchNR[labelformat.nr2],&labelformat.nrfont,1000L,a,ps);
}
// "NR"
if (labelformat.whatinfo[2] || labelformat.whatinfo[3]) {
a.x=(fixpoints[labelformat.size][0].x+fixpoints[labelformat.size][1].x-queryStrWidth("NR",&labelformat.nrfont,ps))/2;
paintString("NR",&labelformat.sourcefont,1000L,a,ps);
}
}
return TRUE;
}
BOOL TapeLab::paintString(char* str,_fontinfo *font,int spc,PMPoint pos,PMPresSpace &ps)
{
FONTMETRICS fm;
PMLogFont f(ps,&font->fattrs);
ps.setCharSet(f);
SIZEF csize;
csize.cy=MAKEFIXED(font->height*254L/72L,0); // [punti] * [decimillimetri]/[pollice] * 1/[punti]/[pollice]
csize.cx=(font->height << 16)*254L/72L;
ps.setCharBox(&csize);
ps.queryFontMetrics(&fm); // chiedi i fontmetrics
pos.y += fm.lMaxDescender; // e alza il font a causa del descender
char* p=str,*start;
int line=0,x=0,pageadj=0;
while (*p) { // finche' la str non finisce
int len=0;
start=p;
while (*p!=0xd && *p!=0x9 && *p) { len++; p++; } // cerca newline, tab, o fine str
PMPoint off(x,-pageadj-( line*( ( font->height * spc / 1000L ) + font->extleading ) *254L /72L) ); // calcola posizione
off=off+pos;
if (off.y-fm.lMaxDescender<fixpoints[labelformat.size][6].y && pageadj==0) { // siamo passati sulla nuova pagina, aggiusta di conseguenza...
pageadj=off.y-(pos.y-fixpoints[labelformat.size][4].y+fixpoints[labelformat.size][6].y);
off.y-=pageadj;
}
ps.charStringAt(&off,len,start); // stampa
if (*p==0x9) { // tabba
POINTL aptlPoints[TXTBOX_COUNT];
p++;
ps.queryTextBox (len,start, TXTBOX_COUNT, aptlPoints);
x+=(aptlPoints[TXTBOX_TOPRIGHT].x/labelformat.form.tabsize + 1 )* labelformat.form.tabsize;
} else {
line++;
x=0; // ritorno a capo significa eliminare offset x
if (*p==0xd) p++; // skippa 0xd
if (*p==0xa) p++; // skippa 0xa
}
}
return TRUE;
}
LONG TapeLab::queryStrWidth(PSZ pszString,_fontinfo *font,PMPresSpace &ps)
{
PMLogFont f(ps,&font->fattrs);
ps.setCharSet(f);
return ps.queryTextBoxWidth(pszString);
}
BOOL TapeLab::setFont(_fontinfo *font,char* title)
{
FONTMETRICS fm;
PMWindowPresSpace ps(this); // crea pres space della finestra
SIZEL size;
size.cx=1500;
size.cy=1800;
ps.set(&size,PU_LOMETRIC);
PMLogFont f(ps,&font->fattrs); // crea font
ps.setCharSet(f); // imposta font
SIZEF csize;
csize.cy=(font->height << 16)*254L/72L;
csize.cx=(font->height << 16)*254L/72L;
ps.setCharBox(&csize);
ps.queryFontMetrics(&fm); // chiedi i fontmetrics
fm.sNominalPointSize=font->point*10;
PMFontDialog fd(HWND_DESKTOP,hwnd, &fm,font->type,title,"Preview");
int ret=fd.createWin(); // fai scegliere all'utente
FONTDLG fi=fd;
if ( ret == DID_OK ) {
font->fattrs=fi.fAttrs;
font->height=fi.lEmHeight;
font->extleading=fi.lExternalLeading;
font->type=fi.flType;
font->point=FIXEDINT(fi.fxPointSize);
font->fattrs.lMaxBaselineExt = 0L;
font->fattrs.lAveCharWidth = 0L;
setModified(TRUE);
invalidate(TRUE);
return TRUE;
}
return FALSE;
}