author | fm |
Thu, 08 Nov 2007 14:06:18 +0100 | |
changeset 2347 | e5b1c5c1ad88 |
parent 2344 | 507334e9746f |
child 2348 | ab36aad361f6 |
permissions | -rw-r--r-- |
2299 | 1 |
" |
2 |
COPYRIGHT (c) 2006 by eXept Software AG |
|
2344 | 3 |
All Rights Reserved |
2299 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
"{ Package: 'stx:libview2' }" |
|
13 |
||
2301
135f21a3d127
refactorred OS-independent stuff
Claus Gittinger <cg@exept.de>
parents:
2299
diff
changeset
|
14 |
PrinterContext subclass:#WinPrinterContext |
2344 | 15 |
instanceVariableNames:'deviceFonts hatch supportsColor' |
16 |
classVariableNames:'' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'Interface-Printing' |
|
2299 | 19 |
! |
20 |
||
2317 | 21 |
!WinPrinterContext primitiveDefinitions! |
22 |
%{ |
|
23 |
#undef INT |
|
24 |
#define INT WIN_INT |
|
25 |
#undef Array |
|
26 |
#define Array WIN_Array |
|
27 |
#undef Number |
|
28 |
#define Number WIN_Number |
|
29 |
#undef Method |
|
30 |
#define Method WIN_Method |
|
31 |
#undef Point |
|
32 |
#define Point WIN_Point |
|
33 |
#undef Rectangle |
|
34 |
/* #define Rectangle WIN_Rectangle */ |
|
35 |
#undef True |
|
36 |
#define True WIN_True |
|
37 |
#undef False |
|
38 |
#define False WIN_False |
|
39 |
#undef Block |
|
40 |
#define Block WIN_Block |
|
41 |
#undef Context |
|
42 |
#define Context WIN_Context |
|
43 |
#undef Date |
|
44 |
#define Date WIN_Date |
|
45 |
#undef Time |
|
46 |
#define Time WIN_Time |
|
47 |
#undef Delay |
|
48 |
#define Delay WIN_Delay |
|
49 |
#undef Signal |
|
50 |
#define Signal WIN_Signal |
|
51 |
#undef Set |
|
52 |
#define Set WIN_Set |
|
53 |
#undef Process |
|
54 |
#define Process WIN_Process |
|
55 |
#undef Processor |
|
56 |
#define Processor WIN_Processor |
|
57 |
#undef Message |
|
58 |
#define Message WIN_Message |
|
59 |
||
60 |
#include <stdio.h> |
|
61 |
#include <errno.h> |
|
62 |
||
63 |
#ifdef __BORLANDC__ |
|
64 |
# define NOATOM |
|
65 |
# define NOGDICAPMASKS |
|
66 |
# define NOMETAFILE |
|
67 |
# define NOMINMAX |
|
68 |
# define NOOPENFILE |
|
69 |
# define NOSOUND |
|
70 |
# define NOWH |
|
71 |
# define NOCOMM |
|
72 |
# define NOKANJI |
|
73 |
# define NOCRYPT |
|
74 |
# define NOMCX |
|
75 |
# define WIN32_LEAN_AND_MEAN |
|
76 |
# include <windows.h> |
|
77 |
# include <shellapi.h> |
|
78 |
# include <sys\timeb.h> |
|
79 |
# include <dir.h> |
|
80 |
#else |
|
81 |
# define _USERENTRY /**/ |
|
82 |
# define NOATOM |
|
83 |
# define NOGDICAPMASKS |
|
84 |
# define NOMETAFILE |
|
85 |
# define NOMINMAX |
|
86 |
# define NOOPENFILE |
|
87 |
# define NOSOUND |
|
88 |
# define NOWH |
|
89 |
# define NOCOMM |
|
90 |
# define NOKANJI |
|
91 |
# define NOCRYPT |
|
92 |
# define NOMCX |
|
93 |
# define WIN32_LEAN_AND_MEAN |
|
94 |
# include <windows.h> |
|
95 |
# include <sys\timeb.h> |
|
96 |
#endif |
|
97 |
||
98 |
#include <process.h> |
|
99 |
||
100 |
#ifdef __DEF_Array |
|
101 |
# undef Array |
|
102 |
# define Array __DEF_Array |
|
103 |
#endif |
|
104 |
#ifdef __DEF_Number |
|
105 |
# undef Number |
|
106 |
# define Number __DEF_Number |
|
107 |
#endif |
|
108 |
#ifdef __DEF_Method |
|
109 |
# undef Method |
|
110 |
# define Method __DEF_Method |
|
111 |
#endif |
|
112 |
#ifdef __DEF_Point |
|
113 |
# undef Point |
|
114 |
# define Point __DEF_Point |
|
115 |
#endif |
|
116 |
#ifdef __DEF_Rectangle |
|
117 |
# undef Rectangle |
|
118 |
# define Rectangle __DEF_Rectangle |
|
119 |
#else |
|
120 |
# undef Rectangle |
|
121 |
#endif |
|
122 |
#ifdef __DEF_Block |
|
123 |
# undef Block |
|
124 |
# define Block __DEF_Block |
|
125 |
#endif |
|
126 |
#ifdef __DEF_Context |
|
127 |
# undef Context |
|
128 |
# define Context __DEF_Context |
|
129 |
#endif |
|
130 |
#ifdef __DEF_Date |
|
131 |
# undef Date |
|
132 |
# define Date __DEF_Date |
|
133 |
#endif |
|
134 |
#ifdef __DEF_Time |
|
135 |
# undef Time |
|
136 |
# define Time __DEF_Time |
|
137 |
#endif |
|
138 |
# ifdef __DEF_Set |
|
139 |
# undef Set |
|
140 |
# define Set __DEF_Set |
|
141 |
# endif |
|
142 |
# ifdef __DEF_Signal |
|
143 |
# undef Signal |
|
144 |
# define Signal __DEF_Signal |
|
145 |
# endif |
|
146 |
# ifdef __DEF_Delay |
|
147 |
# undef Delay |
|
148 |
# define Delay __DEF_Delay |
|
149 |
# endif |
|
150 |
# ifdef __DEF_Process |
|
151 |
# undef Process |
|
152 |
# define Process __DEF_Process |
|
153 |
# endif |
|
154 |
# ifdef __DEF_Processor |
|
155 |
# undef Processor |
|
156 |
# define Processor __DEF_Processor |
|
157 |
# endif |
|
158 |
# ifdef __DEF_Message |
|
159 |
# undef Message |
|
160 |
# define Message __DEF_Message |
|
161 |
# endif |
|
162 |
||
163 |
#undef INT |
|
164 |
#define INT int |
|
165 |
||
166 |
/* |
|
167 |
* some defines - tired of typing ... |
|
168 |
*/ |
|
169 |
#define _HANDLEVal(o) (HANDLE)(__MKCP(o)) |
|
170 |
#define _HBITMAPVAL(o) (HBITMAP)(__MKCP(o)) |
|
171 |
#define _HWNDVal(o) (HWND)(__MKCP(o)) |
|
172 |
#define _HPALETTEVal(o) (HPALETTE)(__MKCP(o)) |
|
173 |
#define _HCURSORVal(o) (HCURSOR)(__MKCP(o)) |
|
174 |
#define _HGDIOBJVal(o) (HGDIOBJ)(__MKCP(o)) |
|
175 |
#define _LOGPALETTEVal(o) (LOGPALETTE *)(__MKCP(o)) |
|
176 |
#define _COLORREFVal(o) (COLORREF)(__MKCP(o)) |
|
177 |
||
178 |
#define WIDECHAR unsigned short |
|
179 |
||
180 |
#define WIN32PADDING 32 |
|
181 |
||
182 |
#ifdef DEBUG |
|
2325 | 183 |
# define DPRINTF(x) /* printf x */ |
184 |
# define DFPRINTF(x) /* fprintf x */ |
|
2317 | 185 |
#else |
186 |
# define DPRINTF(x) /* */ |
|
187 |
# define DFPRINTF(x) /* */ |
|
188 |
#endif |
|
189 |
||
190 |
typedef int (*intf)(int); |
|
191 |
%} |
|
192 |
! ! |
|
193 |
||
2299 | 194 |
!WinPrinterContext class methodsFor:'documentation'! |
195 |
||
196 |
copyright |
|
197 |
" |
|
198 |
COPYRIGHT (c) 2006 by eXept Software AG |
|
2344 | 199 |
All Rights Reserved |
2299 | 200 |
|
201 |
This software is furnished under a license and may be used |
|
202 |
only in accordance with the terms of that license and with the |
|
203 |
inclusion of the above copyright notice. This software may not |
|
204 |
be provided or otherwise made available to, or used by, any |
|
205 |
other person. No title to or ownership of the software is |
|
206 |
hereby transferred. |
|
207 |
" |
|
208 |
! |
|
209 |
||
210 |
documentation |
|
211 |
" |
|
2317 | 212 |
I am the mediator between the smalltalk printing protocol |
2299 | 213 |
(which is the same as the graphics drawing protocol) and the |
214 |
windows printer. |
|
2317 | 215 |
When you open a printer, you will typically talk to me. |
2299 | 216 |
|
217 |
[author:] |
|
2344 | 218 |
Felix Madrid (fm@exept.de) |
2299 | 219 |
" |
220 |
! ! |
|
221 |
||
222 |
!WinPrinterContext class methodsFor:'instance creation'! |
|
223 |
||
224 |
fromPrinterInfo: aPrinterInfo |
|
2317 | 225 |
| printerContext printerDevice hDC| |
2299 | 226 |
|
227 |
hDC := aPrinterInfo createDC. |
|
228 |
hDC = 0 ifTrue: [ ^self error: 'Error while opening printer.' ]. |
|
229 |
||
2316 | 230 |
printerContext := self new. |
2323 | 231 |
|
232 |
printerDevice := printerContext. |
|
233 |
"/ printerDevice := WinPrinter on: aPrinterInfo. |
|
234 |
"/ printerDevice printerDC:hDC. |
|
235 |
||
2316 | 236 |
printerContext printerInfo: aPrinterInfo. |
237 |
printerContext setDevice:printerDevice id:nil gcId:hDC. |
|
238 |
printerContext initExtent. |
|
239 |
^printerContext |
|
2299 | 240 |
|
241 |
"Created: / 03-08-2006 / 12:53:52 / fm" |
|
242 |
"Modified: / 04-08-2006 / 12:55:01 / fm" |
|
243 |
"Modified: / 16-04-2007 / 12:36:26 / cg" |
|
244 |
! ! |
|
245 |
||
246 |
!WinPrinterContext class methodsFor:'accessing'! |
|
247 |
||
2317 | 248 |
getPrinterInformation:printerNameString |
2299 | 249 |
" Answer the printer information for the printer named printerNameString. If no name is specified, |
250 |
answer the information for the default printer." |
|
2317 | 251 |
|
2299 | 252 |
|h| |
253 |
||
254 |
h := OperatingSystem openPrinter:printerNameString. |
|
2317 | 255 |
^ OperatingSystem |
2344 | 256 |
getDocumentProperties:nil |
257 |
hPrinter:h |
|
258 |
pDeviceName:printerNameString. |
|
2299 | 259 |
|
260 |
"Created: / 27-07-2006 / 10:22:32 / fm" |
|
261 |
"Modified: / 01-08-2006 / 16:01:44 / fm" |
|
262 |
"Modified: / 10-10-2006 / 18:57:45 / cg" |
|
263 |
! |
|
264 |
||
2330 | 265 |
getPrinterInformationString: printerNameString |
266 |
" Answer the printer information string from the WIN.INI file |
|
267 |
for the printer named printerNameString. If no name is specified, |
|
268 |
answer the information for the default printer. " |
|
269 |
| printerInfo result | |
|
270 |
printerInfo := ( String new: 80 ). |
|
271 |
result := OperatingSystem primGetProfileString: 'windows' |
|
272 |
keyName: 'device' |
|
273 |
default: ( printerNameString isNil ifTrue: [ '' ] ifFalse: [ printerNameString ] ) |
|
274 |
returnedString: printerInfo |
|
275 |
size: printerInfo size. |
|
276 |
^result > 0 |
|
277 |
ifTrue: [printerInfo copyFrom: 1 to: result] |
|
278 |
ifFalse: [''] |
|
279 |
! |
|
280 |
||
2299 | 281 |
named: aName |
282 |
"Answer a new instance of Printer which represents |
|
283 |
the printer named aName as specified in the host |
|
284 |
Control Panel." |
|
285 |
||
286 |
aName isNil ifTrue: [ ^self default ]. |
|
287 |
^self new printerInfoWithName: aName |
|
288 |
||
289 |
"Created: / 27-07-2006 / 17:51:27 / fm" |
|
290 |
"Modified: / 02-08-2006 / 17:26:29 / fm" |
|
291 |
"Modified: / 10-10-2006 / 17:33:29 / cg" |
|
292 |
! ! |
|
293 |
||
2323 | 294 |
!WinPrinterContext class methodsFor:'not supported yet'! |
295 |
||
296 |
printAdvancedLines: pairOfPointsArray |
|
297 |
"Opens a print dialog and prints the given lines" |
|
298 |
||
299 |
| printerInfo printer | |
|
300 |
||
301 |
printerInfo := PrintingDialog getPrinterInfo. |
|
302 |
printerInfo isNil ifTrue:[^self]. |
|
303 |
||
304 |
printer := self fromPrinterInfo: printerInfo. |
|
305 |
[ |
|
2344 | 306 |
printer startPrintJob: 'Advanced Lines'. |
307 |
printer foreground:Color red background:Color white. |
|
308 |
pairOfPointsArray |
|
309 |
do:[:pairOfPointsAndContext | |
|
310 |
|pairOfPoints| |
|
311 |
pairOfPoints := pairOfPointsAndContext at:1. |
|
312 |
printer |
|
313 |
lineWidth: (pairOfPointsAndContext at:2); |
|
314 |
lineStyle: (pairOfPointsAndContext at:3); |
|
315 |
capStyle: (pairOfPointsAndContext at:4); |
|
316 |
joinStyle: (pairOfPointsAndContext at:5); |
|
317 |
foreground: (pairOfPointsAndContext at:6); |
|
318 |
||
319 |
displayAdvanceLineFrom: (pairOfPoints at:1) to: (pairOfPoints at:2). |
|
320 |
]. |
|
321 |
printer endPrintJob. |
|
2323 | 322 |
] forkAt: 3 |
323 |
||
324 |
" |
|
325 |
WinPrinterContext printAdvancedLines: |
|
2344 | 326 |
(Array with: (Array with: (Array with:10@10 with:1000@5000) with: 3 with:#dashed with: #butt with: #miter with: Color green) |
327 |
with: (Array with: (Array with:10@10 with:3500@2000) with: 2 with:#solid with: #butt with: #miter with: Color yellow) |
|
328 |
with: (Array with: (Array with:1000@800 with:6000@5000) with: 8 with:#dashed with: #butt with: #miter with: Color black) |
|
329 |
with: (Array with: (Array with:2000@2800 with:2000@5000) with: 1 with:#dashed with: #butt with: #miter with: Color red) |
|
330 |
) |
|
2323 | 331 |
" |
332 |
||
333 |
"Created: / 07-08-2006 / 12:09:48 / fm" |
|
334 |
"Modified: / 07-08-2006 / 14:11:17 / fm" |
|
335 |
"Modified: / 16-04-2007 / 15:37:41 / cg" |
|
336 |
! ! |
|
337 |
||
2343 | 338 |
!WinPrinterContext class methodsFor:'testing'! |
339 |
||
340 |
computeScaleForPrinter:aPrinter |
|
341 |
^ Point x:(aPrinter pixelsPerInchOfScreenWidth / Screen current horizontalPixelPerInch) |
|
342 |
y:(aPrinter pixelsPerInchOfScreenHeight / Screen current verticalPixelPerInch) |
|
343 |
! |
|
344 |
||
345 |
testPrintingDo:anOneArgBlock |
|
346 |
||
347 |
"Opens a print dialog and invokes the action with the printer" |
|
348 |
||
349 |
| printerInfo printer | |
|
350 |
||
351 |
printerInfo := PrintingDialog getPrinterInfo. |
|
352 |
printerInfo isNil ifTrue:[^self]. |
|
353 |
||
354 |
printer := self fromPrinterInfo: printerInfo. |
|
355 |
||
356 |
printer startPrintJob: 'Testing'. |
|
357 |
anOneArgBlock value:printer. |
|
358 |
printer endPrintJob. |
|
359 |
||
360 |
||
361 |
" |
|
362 |
self testPrintingDo:[:aPrinter| |icon| |
|
363 |
aPrinter scale:(self computeScaleForPrinter:aPrinter). |
|
364 |
||
365 |
aPrinter displayLineFrom:10@10 to:100@10. |
|
366 |
aPrinter displayLineFrom:100@10 to:100@100. |
|
367 |
aPrinter displayLineFrom:100@100 to:10@100. |
|
368 |
aPrinter displayLineFrom:10@100 to:10@10. |
|
369 |
||
370 |
icon := XPToolbarIconLibrary eraseXP28x28Icon. |
|
371 |
icon displayOn:aPrinter x:10 y:10. |
|
372 |
||
373 |
]. |
|
374 |
||
375 |
self testPrintingDo:[:aPrinter| |scale| |
|
376 |
scale := self computeScaleForPrinter:aPrinter. |
|
377 |
aPrinter scale:(1 * scale). |
|
378 |
||
379 |
aPrinter font:(Font family:'Arial' face:'medium' size:8). |
|
380 |
aPrinter displayLineFrom:8@16 to:100@16. |
|
381 |
aPrinter displayLineFrom:8@16 to:8@128. |
|
382 |
||
383 |
'hallo' displayOn:aPrinter x:8 y:16. |
|
384 |
aPrinter scale:(2 * scale). |
|
385 |
'hallo' displayOn:aPrinter x:4 y:32. |
|
386 |
||
387 |
aPrinter scale:(4 * scale). |
|
388 |
'hallo' displayOn:aPrinter x:2 y:32. |
|
389 |
]. |
|
390 |
" |
|
391 |
! ! |
|
392 |
||
2299 | 393 |
!WinPrinterContext class methodsFor:'testing & examples'! |
394 |
||
2323 | 395 |
fillCircles: arrayOfPointsAndRadiusWithContextArray |
396 |
"Opens a print dialog and prints the given circles" |
|
397 |
||
398 |
| printerInfo printer | |
|
399 |
||
400 |
printerInfo := PrintingDialog getPrinterInfo. |
|
401 |
printerInfo isNil ifTrue:[^self]. |
|
402 |
||
403 |
printer := self fromPrinterInfo: printerInfo. |
|
404 |
[ |
|
2344 | 405 |
printer startPrintJob: 'Fill Circles'. |
406 |
arrayOfPointsAndRadiusWithContextArray |
|
407 |
do:[:pointsAndRadiusWithContextArray | |
|
408 |
printer foreground:(pointsAndRadiusWithContextArray at:3). |
|
409 |
printer fillCircle:(pointsAndRadiusWithContextArray at:1) |
|
410 |
radius:(pointsAndRadiusWithContextArray at:2). |
|
411 |
]. |
|
412 |
printer endPrintJob. |
|
2323 | 413 |
] forkAt: 3 |
414 |
||
415 |
" |
|
416 |
WinPrinterContext fillCircles: |
|
2344 | 417 |
(Array with: (Array with: 800@800 with: 600 with:Color red) |
418 |
with: (Array with: 1500@1500 with: 1000 with:Color blue) |
|
419 |
with: (Array with: 4000@2500 with: 2000 with:Color gray)) |
|
2323 | 420 |
" |
421 |
||
422 |
"Created: / 07-08-2006 / 11:46:52 / fm" |
|
423 |
"Modified: / 16-04-2007 / 15:37:34 / cg" |
|
424 |
! |
|
425 |
||
2330 | 426 |
fillHatchCircles: arrayOfPointsAndRadiusWithContextArray |
427 |
"Opens a print dialog and prints the given circles" |
|
428 |
||
429 |
| printerInfo printer | |
|
430 |
||
431 |
printerInfo := PrintingDialog getPrinterInfo. |
|
432 |
printerInfo isNil ifTrue:[^self]. |
|
433 |
||
434 |
printer := self fromPrinterInfo: printerInfo. |
|
435 |
[ |
|
436 |
printer startPrintJob: 'Fill Hatch Circles'. |
|
437 |
arrayOfPointsAndRadiusWithContextArray |
|
438 |
do:[:pointsAndRadiusWithContextArray | |
|
439 |
| point radius color hatch| |
|
440 |
point := (pointsAndRadiusWithContextArray at:1). |
|
441 |
radius := (pointsAndRadiusWithContextArray at:2). |
|
442 |
color := (pointsAndRadiusWithContextArray at:3). |
|
443 |
hatch := (pointsAndRadiusWithContextArray at:4). |
|
444 |
printer foreground: color; |
|
445 |
hatch: hatch. |
|
446 |
printer fillCircle:point |
|
447 |
radius:radius. |
|
448 |
]. |
|
449 |
printer endPrintJob. |
|
450 |
] forkAt: 3 |
|
451 |
||
452 |
" |
|
453 |
WinPrinterContext fillHatchCircles: |
|
454 |
(Array with: (Array with: 800@800 with: 600 with:Color red with: #diagonalCross) |
|
455 |
with: (Array with: 1500@1500 with: 1000 with:Color blue with: #vertical) |
|
456 |
with: (Array with: 4000@2500 with: 2000 with:Color gray with: #bDiagonal)) |
|
457 |
" |
|
458 |
||
459 |
"Created: / 07-08-2006 / 11:46:52 / fm" |
|
460 |
"Modified: / 16-04-2007 / 15:37:34 / cg" |
|
461 |
! |
|
462 |
||
463 |
fillHatchPolygons: polygonsWithContextArray |
|
464 |
"Opens a print dialog and prints the given polygons" |
|
465 |
||
466 |
| printerInfo printer | |
|
467 |
||
468 |
printerInfo := PrintingDialog getPrinterInfo. |
|
469 |
printerInfo isNil ifTrue:[^self]. |
|
470 |
||
471 |
printer := self fromPrinterInfo: printerInfo. |
|
472 |
[ |
|
473 |
printer startPrintJob: 'Fill Hatch Polygons'. |
|
474 |
polygonsWithContextArray |
|
475 |
do:[:polygonWithContextArray | |
|
476 |
|aPolygon color hatch| |
|
477 |
aPolygon := polygonWithContextArray at: 1. |
|
478 |
color := (polygonWithContextArray at: 2). |
|
479 |
hatch := (polygonWithContextArray at: 3). |
|
480 |
printer foreground: color; |
|
481 |
hatch: hatch. |
|
482 |
aPolygon displayFilledOn: printer. |
|
483 |
]. |
|
484 |
printer endPrintJob. |
|
485 |
] forkAt: 3 |
|
486 |
||
487 |
" |
|
488 |
WinPrinterContext fillHatchPolygons: |
|
489 |
(Array with: (Array with: (Polygon vertices:( |
|
490 |
Array |
|
491 |
with:100@100 |
|
492 |
with:600@1000 |
|
493 |
with:3500@4000 |
|
494 |
with:100@4000 |
|
495 |
with:100@100)) |
|
496 |
with: Color red |
|
497 |
with: #cross) |
|
498 |
with: (Array with: (Polygon vertices:( |
|
499 |
Array |
|
500 |
with:1000@1000 |
|
501 |
with:1000@2000 |
|
502 |
with:2000@1000)) |
|
503 |
with: Color blue |
|
504 |
with: #none) |
|
505 |
) |
|
506 |
" |
|
507 |
||
508 |
"Created: / 07-08-2006 / 12:09:48 / fm" |
|
509 |
"Modified: / 07-08-2006 / 14:11:17 / fm" |
|
510 |
"Modified: / 16-04-2007 / 15:37:43 / cg" |
|
511 |
! |
|
512 |
||
513 |
fillHatchRectangles: rectanglesWithHatch |
|
514 |
"Opens a print dialog and prints the given rectangles" |
|
515 |
||
516 |
| printerInfo printer | |
|
517 |
||
518 |
printerInfo := PrintingDialog getPrinterInfo. |
|
519 |
printerInfo isNil ifTrue:[^self]. |
|
520 |
||
521 |
printer := self fromPrinterInfo: printerInfo. |
|
522 |
[ |
|
523 |
printer startPrintJob: 'Fill Hatch Rectangles'. |
|
524 |
printer foreground:Color blue background:Color white. |
|
525 |
rectanglesWithHatch |
|
526 |
do:[:rectangleWithHatch | |
|
527 |
|rectangle hatch| |
|
528 |
rectangle := rectangleWithHatch at: 1. |
|
529 |
hatch := rectangleWithHatch at: 2. |
|
530 |
printer hatch: hatch. |
|
531 |
printer fillRectangleX: rectangle origin x |
|
532 |
y: rectangle origin y |
|
533 |
width: rectangle width |
|
534 |
height: rectangle height. |
|
535 |
]. |
|
536 |
printer endPrintJob. |
|
537 |
] forkAt: 3 |
|
538 |
||
539 |
" |
|
540 |
WinPrinterContext fillHatchRectangles: |
|
541 |
(Array with: (Array with: (Rectangle left:20 top:20 width:400 height:600) with: #horizontal) |
|
542 |
with: (Array with: (Rectangle left:500 top:700 width:600 height:400) with: #vertical) |
|
543 |
with: (Array with: (Rectangle left:800 top:1000 width:1600 height:2000) with: #cross) |
|
544 |
with: (Array with: (Rectangle left:1040 top:1240 width:3000 height:3000) with: #bDiagonal) |
|
545 |
) |
|
546 |
" |
|
547 |
||
548 |
"Created: / 07-08-2006 / 11:40:48 / fm" |
|
549 |
"Modified: / 16-04-2007 / 15:37:46 / cg" |
|
550 |
! |
|
551 |
||
2323 | 552 |
fillPolygons: polygonsWithContextArray |
553 |
"Opens a print dialog and prints the given polygons" |
|
554 |
||
555 |
| printerInfo printer | |
|
556 |
||
557 |
printerInfo := PrintingDialog getPrinterInfo. |
|
558 |
printerInfo isNil ifTrue:[^self]. |
|
559 |
||
560 |
printer := self fromPrinterInfo: printerInfo. |
|
561 |
[ |
|
2344 | 562 |
printer startPrintJob: 'Fill Polygons'. |
563 |
polygonsWithContextArray |
|
564 |
do:[:polygonWithContextArray | |
|
565 |
|aPolygon| |
|
566 |
aPolygon := polygonWithContextArray at: 1. |
|
567 |
printer foreground:(polygonWithContextArray at: 2). |
|
568 |
aPolygon displayFilledOn: printer. |
|
569 |
]. |
|
570 |
printer endPrintJob. |
|
2323 | 571 |
] forkAt: 3 |
572 |
||
573 |
" |
|
574 |
WinPrinterContext fillPolygons: |
|
2344 | 575 |
(Array with: (Array with: (Polygon vertices:( |
576 |
Array |
|
577 |
with:100@100 |
|
578 |
with:600@1000 |
|
579 |
with:3500@4000 |
|
580 |
with:100@4000 |
|
581 |
with:100@100)) |
|
582 |
with: Color red) |
|
583 |
with: (Array with: (Polygon vertices:( |
|
584 |
Array |
|
585 |
with:1000@1000 |
|
586 |
with:1000@2000 |
|
587 |
with:2000@1000)) |
|
588 |
with: Color blue) |
|
2323 | 589 |
) |
590 |
" |
|
591 |
||
592 |
"Created: / 07-08-2006 / 12:09:48 / fm" |
|
593 |
"Modified: / 07-08-2006 / 14:11:17 / fm" |
|
594 |
"Modified: / 16-04-2007 / 15:37:43 / cg" |
|
595 |
! |
|
596 |
||
2316 | 597 |
fillRectangles: rectangles |
598 |
"Opens a print dialog and prints the given rectangles" |
|
599 |
||
600 |
| printerInfo printer | |
|
601 |
||
602 |
printerInfo := PrintingDialog getPrinterInfo. |
|
603 |
printerInfo isNil ifTrue:[^self]. |
|
604 |
||
605 |
printer := self fromPrinterInfo: printerInfo. |
|
2317 | 606 |
[ |
2344 | 607 |
printer startPrintJob: 'Fill Rectangles'. |
608 |
printer foreground:Color blue background:Color white. |
|
609 |
rectangles |
|
610 |
do:[:rectangle | |
|
611 |
printer fillRectangleX: rectangle origin x |
|
612 |
y: rectangle origin y |
|
613 |
width: rectangle width |
|
614 |
height: rectangle height. |
|
615 |
]. |
|
616 |
printer endPrintJob. |
|
2316 | 617 |
] forkAt: 3 |
618 |
||
619 |
" |
|
2317 | 620 |
WinPrinterContext fillRectangles: |
2344 | 621 |
(Array with: (Rectangle left:20 top:20 width:400 height:600) |
622 |
with: (Rectangle left:500 top:700 width:600 height:400) |
|
623 |
with: (Rectangle left:800 top:1000 width:1600 height:2000) |
|
624 |
with: (Rectangle left:1040 top:1240 width:3000 height:3000) |
|
625 |
) |
|
2316 | 626 |
" |
627 |
||
628 |
"Created: / 07-08-2006 / 11:40:48 / fm" |
|
629 |
"Modified: / 16-04-2007 / 15:37:46 / cg" |
|
630 |
! |
|
631 |
||
2299 | 632 |
print: aString font: aFont title: aTitle |
633 |
"Open a print dialog to allow printing of the given string |
|
634 |
using the given title & font." |
|
635 |
||
2317 | 636 |
self print: aString font: aFont title: aTitle wordWrap: false |
2299 | 637 |
|
638 |
" |
|
2313 | 639 |
WinPrinterContext print: 'Holaaaa!! (from: WinPrinterContext>>print:aString font:aFont title:aTitle)' font: nil title: 'Printing Test' |
2315 | 640 |
WinPrinterContext print: (WinPrinterContext class sourceCodeAt:#'print:font:title:wordWrap:') font: nil title: 'Printing Test String' |
641 |
WinPrinterContext print: (WinPrinterContext class sourceCodeAt:#'print:font:title:wordWrap:') font: (Font family:'Arial' face:'medium' size:8) title: 'Printing Test String' |
|
2299 | 642 |
" |
643 |
||
644 |
"Created: / 27-07-2006 / 17:52:33 / fm" |
|
645 |
"Modified: / 03-08-2006 / 18:52:31 / fm" |
|
2313 | 646 |
"Modified: / 16-04-2007 / 13:54:40 / cg" |
2299 | 647 |
! |
648 |
||
649 |
print: aString font: aFont title: aTitle wordWrap: wordWrap |
|
650 |
"Open a print dialog to allow printing of the given string |
|
651 |
using the given title & font." |
|
652 |
||
653 |
| printerInfo printer | |
|
654 |
||
655 |
printerInfo := PrintingDialog getPrinterInfo. |
|
656 |
printerInfo isNil ifTrue:[^self]. |
|
657 |
||
658 |
printer := self fromPrinterInfo: printerInfo. |
|
2317 | 659 |
[ |
2338 | 660 |
printer |
661 |
print: aString |
|
662 |
font: aFont |
|
663 |
title: aTitle |
|
664 |
wordWrap: wordWrap |
|
665 |
marginsRect: nil |
|
2299 | 666 |
] forkAt: 3 |
667 |
||
668 |
" |
|
2313 | 669 |
WinPrinterContext print: 'Holaaaa!! (from: PrinterContext>>print:aString font:aFont title:aTitle)' font: nil title: 'Printing Test' wordWrap: true |
2315 | 670 |
WinPrinterContext print: (WinPrinterContext class sourceCodeAt:#'print:font:title:wordWrap:') font:nil title:'Printing Test String' wordWrap:true |
671 |
WinPrinterContext print: (WinPrinterContext class sourceCodeAt:#'print:font:title:wordWrap:') font: (Font family:'Arial' face:'medium' size:8) title: 'Printing Test String' wordWrap: true |
|
2299 | 672 |
" |
673 |
||
674 |
"Created: / 03-08-2006 / 18:51:53 / fm" |
|
2313 | 675 |
"Modified: / 16-04-2007 / 15:37:31 / cg" |
2299 | 676 |
! |
677 |
||
678 |
printCircles: arrayOfPointsAndRadius |
|
679 |
"Opens a print dialog and prints the given circles" |
|
680 |
||
681 |
| printerInfo printer | |
|
682 |
||
683 |
printerInfo := PrintingDialog getPrinterInfo. |
|
684 |
printerInfo isNil ifTrue:[^self]. |
|
685 |
||
686 |
printer := self fromPrinterInfo: printerInfo. |
|
2317 | 687 |
[ |
2344 | 688 |
printer startPrintJob: 'Circles'. |
689 |
printer foreground:Color green background:Color white. |
|
690 |
arrayOfPointsAndRadius |
|
691 |
do:[:pointAndRadius | |
|
692 |
printer displayCircle:(pointAndRadius at:1) |
|
693 |
radius:(pointAndRadius at:2). |
|
694 |
]. |
|
695 |
printer endPrintJob. |
|
2299 | 696 |
] forkAt: 3 |
697 |
||
698 |
" |
|
2317 | 699 |
WinPrinterContext printCircles: |
2344 | 700 |
(Array with: (Array with: 800@800 with: 600) |
701 |
with: (Array with: 1500@1500 with: 1000) |
|
702 |
with: (Array with: 4000@2500 with: 2000)) |
|
2299 | 703 |
" |
704 |
||
705 |
"Created: / 07-08-2006 / 11:46:52 / fm" |
|
2313 | 706 |
"Modified: / 16-04-2007 / 15:37:34 / cg" |
2299 | 707 |
! |
708 |
||
709 |
printCirclesIn: rectangles |
|
710 |
"Opens a print dialog and prints the given circles" |
|
711 |
||
712 |
| printerInfo printer | |
|
713 |
||
714 |
printerInfo := PrintingDialog getPrinterInfo. |
|
715 |
printerInfo isNil ifTrue:[^self]. |
|
716 |
||
717 |
printer := self fromPrinterInfo: printerInfo. |
|
2317 | 718 |
[ |
2344 | 719 |
printer startPrintJob: 'Circles In Rectangles'. |
720 |
rectangles |
|
721 |
do:[:rectangle | |
|
722 |
printer displayCircleIn: rectangle. |
|
723 |
]. |
|
2299 | 724 |
printer endPrintJob. |
725 |
] forkAt: 3 |
|
726 |
||
727 |
" |
|
2317 | 728 |
WinPrinterContext printCirclesIn: |
2344 | 729 |
(Array with: (Rectangle left:20 top:20 width:400 height:600) |
730 |
with: (Rectangle left:40 top:40 width:600 height:400) |
|
731 |
) |
|
2299 | 732 |
" |
733 |
||
734 |
"Created: / 07-08-2006 / 11:48:46 / fm" |
|
2313 | 735 |
"Modified: / 16-04-2007 / 15:37:38 / cg" |
2299 | 736 |
! |
737 |
||
2338 | 738 |
printImage: anImage |
739 |
"Opens a print dialog and prints the given image" |
|
740 |
||
741 |
| printerInfo printer | |
|
742 |
||
743 |
printerInfo := PrintingDialog getPrinterInfo. |
|
744 |
printerInfo isNil ifTrue:[^self]. |
|
745 |
||
746 |
printer := self fromPrinterInfo: printerInfo. |
|
747 |
[ |
|
748 |
printer startPrintJob: 'Image'. |
|
749 |
printer background:Color white. |
|
750 |
anImage displayOn:printer x:1000 y:1000. |
|
751 |
printer endPrintJob. |
|
752 |
] forkAt: 3 |
|
753 |
||
754 |
" |
|
755 |
WinPrinterContext printImage: (Image fromFile:'C:\vsw311\pavheadr.gif'). |
|
756 |
WinPrinterContext printImage: XPToolbarIconLibrary help32x32Icon. |
|
757 |
WinPrinterContext printImage: XPToolbarIconLibrary eraseXP28x28Icon. |
|
758 |
WinPrinterContext printImage: XPToolbarIconLibrary saveImageBlack22x22Icon. |
|
759 |
WinPrinterContext printImage: XPToolbarIconLibrary changesBrowser18x22Icon. |
|
760 |
" |
|
761 |
||
762 |
"Created: / 07-08-2006 / 11:46:52 / fm" |
|
763 |
"Modified: / 16-04-2007 / 15:37:34 / cg" |
|
764 |
! |
|
765 |
||
2323 | 766 |
printLines: pairOfPointsWithContextArray |
2299 | 767 |
"Opens a print dialog and prints the given lines" |
768 |
||
769 |
| printerInfo printer | |
|
770 |
||
771 |
printerInfo := PrintingDialog getPrinterInfo. |
|
772 |
printerInfo isNil ifTrue:[^self]. |
|
773 |
||
774 |
printer := self fromPrinterInfo: printerInfo. |
|
2317 | 775 |
[ |
2344 | 776 |
printer startPrintJob: 'Lines'. |
777 |
pairOfPointsWithContextArray |
|
778 |
do:[:pairOfPointsAndContext | |
|
779 |
|pairOfPoints| |
|
780 |
pairOfPoints := pairOfPointsAndContext at: 1. |
|
781 |
printer |
|
782 |
foreground:(pairOfPointsAndContext at:2); |
|
783 |
lineWidth: (pairOfPointsAndContext at:3); |
|
784 |
lineStyle: (pairOfPointsAndContext at:4); |
|
785 |
displayLineFrom: (pairOfPoints at:1) to: (pairOfPoints at:2). |
|
786 |
]. |
|
787 |
printer endPrintJob. |
|
2299 | 788 |
] forkAt: 3 |
789 |
||
790 |
" |
|
2317 | 791 |
WinPrinterContext printLines: |
2344 | 792 |
(Array with: (Array with:(Array with:10@10 with:1000@5000) with: Color red with:4 with: #solid) |
793 |
with: (Array with:(Array with:10@10 with:3500@2000) with: Color blue with:1 with: #dashed) |
|
794 |
with: (Array with:(Array with:1000@800 with:6000@5000) with: Color black with: 1 with:#dotted) |
|
795 |
with: (Array with: (Array with:2000@2800 with:2000@5000) with: Color green with:8 with: nil)) |
|
2299 | 796 |
" |
797 |
||
798 |
"Created: / 07-08-2006 / 12:09:48 / fm" |
|
799 |
"Modified: / 07-08-2006 / 14:11:17 / fm" |
|
2313 | 800 |
"Modified: / 16-04-2007 / 15:37:41 / cg" |
2299 | 801 |
! |
802 |
||
2316 | 803 |
printPoints: aCollectionOfPoints |
804 |
"Opens a print dialog and prints the given points" |
|
805 |
||
806 |
| printerInfo printer | |
|
807 |
||
808 |
printerInfo := PrintingDialog getPrinterInfo. |
|
809 |
printerInfo isNil ifTrue:[^self]. |
|
810 |
||
811 |
printer := self fromPrinterInfo: printerInfo. |
|
2317 | 812 |
[ |
2344 | 813 |
printer startPrintJob: 'Points'. |
814 |
aCollectionOfPoints do:[:each | |
|
815 |
printer displayPointX: each x y: each y. |
|
816 |
]. |
|
817 |
printer endPrintJob. |
|
2316 | 818 |
] forkAt: 3 |
819 |
||
820 |
" |
|
2317 | 821 |
WinPrinterContext printPoints: |
2344 | 822 |
(Array with: (10 @ 10) |
823 |
with: (500 @ 700) |
|
824 |
with: (900 @ 1000) |
|
825 |
with: (1500 @ 1700) |
|
826 |
with: (2100 @ 2000) |
|
827 |
with: (2500 @ 2700) |
|
828 |
) |
|
2316 | 829 |
" |
830 |
! |
|
831 |
||
2299 | 832 |
printPolygons: polygons |
833 |
"Opens a print dialog and prints the given polygons" |
|
834 |
||
835 |
| printerInfo printer | |
|
836 |
||
837 |
printerInfo := PrintingDialog getPrinterInfo. |
|
838 |
printerInfo isNil ifTrue:[^self]. |
|
839 |
||
840 |
printer := self fromPrinterInfo: printerInfo. |
|
2317 | 841 |
[ |
2344 | 842 |
printer startPrintJob: 'Polygons'. |
843 |
printer foreground:Color black background:Color white. |
|
844 |
polygons |
|
845 |
do:[:aPolygon | |
|
846 |
aPolygon displayStrokedOn: printer. |
|
847 |
]. |
|
848 |
printer endPrintJob. |
|
2299 | 849 |
] forkAt: 3 |
850 |
||
851 |
" |
|
2317 | 852 |
WinPrinterContext printPolygons: |
2344 | 853 |
(Array with: (Polygon vertices:( |
854 |
Array |
|
855 |
with:100@100 |
|
856 |
with:600@1000 |
|
857 |
with:3500@4000 |
|
858 |
with:100@4000 |
|
859 |
with:100@100)) |
|
860 |
with: (Polygon vertices:( |
|
861 |
Array |
|
862 |
with:1000@1000 |
|
863 |
with:1000@2000 |
|
864 |
with:2000@1000))) |
|
2299 | 865 |
" |
866 |
||
867 |
"Created: / 07-08-2006 / 12:09:48 / fm" |
|
868 |
"Modified: / 07-08-2006 / 14:11:17 / fm" |
|
2313 | 869 |
"Modified: / 16-04-2007 / 15:37:43 / cg" |
2299 | 870 |
! |
871 |
||
2316 | 872 |
printPolylines: evenCollectionOfPoints |
873 |
"Opens a print dialog and prints the given rectangles" |
|
874 |
||
875 |
| printerInfo printer | |
|
876 |
||
877 |
printerInfo := PrintingDialog getPrinterInfo. |
|
878 |
printerInfo isNil ifTrue:[^self]. |
|
879 |
||
880 |
printer := self fromPrinterInfo: printerInfo. |
|
2317 | 881 |
[ |
2344 | 882 |
printer startPrintJob: 'Polylines'. |
883 |
printer displayPolylines:evenCollectionOfPoints. |
|
884 |
printer endPrintJob. |
|
2316 | 885 |
] forkAt: 3 |
886 |
||
887 |
" |
|
2317 | 888 |
WinPrinterContext printPolylines: |
2344 | 889 |
(Array with: (10 @ 10) |
890 |
with: (500 @ 700) |
|
891 |
with: (900 @ 1000) |
|
892 |
with: (1500 @ 1700) |
|
893 |
with: (2100 @ 2000) |
|
894 |
with: (2500 @ 2700) |
|
895 |
) |
|
2316 | 896 |
" |
897 |
||
898 |
"Created: / 07-08-2006 / 11:40:48 / fm" |
|
899 |
"Modified: / 16-04-2007 / 15:37:46 / cg" |
|
900 |
! |
|
901 |
||
2323 | 902 |
printRectangles: rectanglesWithContextArray |
2299 | 903 |
"Opens a print dialog and prints the given rectangles" |
904 |
||
905 |
| printerInfo printer | |
|
906 |
||
907 |
printerInfo := PrintingDialog getPrinterInfo. |
|
908 |
printerInfo isNil ifTrue:[^self]. |
|
909 |
||
910 |
printer := self fromPrinterInfo: printerInfo. |
|
2317 | 911 |
[ |
2344 | 912 |
printer startPrintJob: 'Rectangles'. |
913 |
printer foreground:Color red background:Color white. |
|
914 |
rectanglesWithContextArray do:[:rectangleWithContextArray | |
|
915 |
|rectangle| |
|
916 |
rectangle := rectangleWithContextArray at: 1. |
|
917 |
printer |
|
918 |
foreground:(rectangleWithContextArray at:2); |
|
919 |
lineWidth: (rectangleWithContextArray at:3); |
|
920 |
lineStyle: (rectangleWithContextArray at:4); |
|
921 |
displayRectangleX: rectangle origin x |
|
922 |
y: rectangle origin y |
|
923 |
width: rectangle width |
|
924 |
height: rectangle height. |
|
925 |
]. |
|
926 |
printer endPrintJob. |
|
2299 | 927 |
] forkAt: 3 |
928 |
||
929 |
" |
|
2317 | 930 |
WinPrinterContext printRectangles: |
2344 | 931 |
(Array with: (Array with: (Rectangle left:30 top:10 width:400 height:600) with: Color red with:4 with: #solid) |
932 |
with: (Array with: (Rectangle left:100 top:140 width:700 height:800) with: Color blue with:1 with: #dashed) |
|
933 |
with: (Array with: (Rectangle left:800 top:1500 width:2600 height:3400) with: Color green with:1 with: #dotted) |
|
934 |
with: (Array with: (Rectangle left:1000 top:1200 width:1400 height:1600) with: Color gray with:8 with: #dashed) |
|
935 |
with: (Array with: (Rectangle left:2600 top:1200 width:1400 height:1600) with: Color darkGray with:1 with: #dashDotDot) |
|
936 |
) |
|
2299 | 937 |
" |
938 |
||
939 |
"Created: / 07-08-2006 / 11:40:48 / fm" |
|
2313 | 940 |
"Modified: / 16-04-2007 / 15:37:46 / cg" |
2299 | 941 |
! |
942 |
||
943 |
printStrings: stringAndPositionsArray |
|
944 |
"Opens a print dialog and prints the given strings" |
|
945 |
||
946 |
| printerInfo printer | |
|
947 |
||
948 |
printerInfo := PrintingDialog getPrinterInfo. |
|
949 |
printerInfo isNil ifTrue:[^self]. |
|
950 |
||
951 |
printer := self fromPrinterInfo: printerInfo. |
|
2317 | 952 |
[ |
2344 | 953 |
printer startPrintJob: 'Strings with Position'. |
954 |
printer foreground:Color black background:Color white. |
|
955 |
stringAndPositionsArray |
|
956 |
do:[:pairOfPointsAndPosition | |
|
957 |
printer displayString:(pairOfPointsAndPosition at: 1) |
|
958 |
x:(pairOfPointsAndPosition at: 2) x |
|
959 |
y:(pairOfPointsAndPosition at: 2) y |
|
960 |
]. |
|
961 |
printer endPrintJob. |
|
2299 | 962 |
] forkAt: 3 |
963 |
||
964 |
" |
|
2317 | 965 |
WinPrinterContext printStrings: |
2344 | 966 |
(Array with: (Array with:'Testing printing with standart method' with:10@10) |
967 |
with: (Array with:'Another test string to print' with:80@200)) |
|
2299 | 968 |
" |
969 |
||
970 |
"Created: / 07-08-2006 / 12:09:48 / fm" |
|
971 |
"Modified: / 07-08-2006 / 14:11:17 / fm" |
|
2313 | 972 |
"Modified: / 16-04-2007 / 15:37:49 / cg" |
2299 | 973 |
! ! |
974 |
||
975 |
!WinPrinterContext methodsFor:'accessing'! |
|
976 |
||
2323 | 977 |
depth |
978 |
^ 24 |
|
979 |
! |
|
980 |
||
981 |
deviceColors |
|
982 |
||
983 |
^#() |
|
984 |
! |
|
985 |
||
986 |
deviceFonts |
|
987 |
||
988 |
deviceFonts isNil ifTrue:[deviceFonts := CachingRegistry new cacheSize:10.]. |
|
989 |
^deviceFonts |
|
990 |
! |
|
991 |
||
2299 | 992 |
getCharHeight |
993 |
"Private - answer the height of the font selected in the receiver's |
|
994 |
device context." |
|
2317 | 995 |
|
2299 | 996 |
|textMetrics answer| |
997 |
||
2317 | 998 |
|
2299 | 999 |
textMetrics := Win32OperatingSystem::TextMetricsStructure new. |
1000 |
"/ (OperatingSystem getTextMetrics:gcId lpMetrics:textMetrics) ifFalse:[ ^ self error ]. |
|
1001 |
"/ Transcript showCR: 'CHAR HEIGHT PRIM ******* ', ' ', (textMetrics tmHeight + textMetrics tmExternalLeading) printString. |
|
1002 |
"/ Transcript showCR: 'CHAR HEIGHT DEVICE ***** ', ' ', (self font heightOf:'PQWEXCZ' on:self device) printString. |
|
1003 |
answer := (self font heightOf:'PQWEXCZ' on:self device). |
|
1004 |
"/ answer := textMetrics tmHeight + textMetrics tmExternalLeading. |
|
2317 | 1005 |
^answer |
2299 | 1006 |
|
1007 |
"Created: / 02-08-2006 / 17:47:20 / fm" |
|
1008 |
"Modified: / 03-08-2006 / 10:09:01 / fm" |
|
1009 |
"Modified: / 10-10-2006 / 18:15:17 / cg" |
|
1010 |
! |
|
1011 |
||
2323 | 1012 |
getLogicalPixelSizeX |
1013 |
^ printerInfo printQuality ? 600 |
|
1014 |
! |
|
1015 |
||
1016 |
getLogicalPixelSizeY |
|
1017 |
^ printerInfo printQuality ? 600 |
|
1018 |
! |
|
1019 |
||
2299 | 1020 |
numberOfColorBitsPerPixel |
1021 |
^ OperatingSystem getDeviceCaps:gcId index:12 "Bitspixel" |
|
1022 |
||
1023 |
"Created: / 03-08-2006 / 09:58:18 / fm" |
|
1024 |
"Modified: / 10-10-2006 / 18:15:40 / cg" |
|
1025 |
! |
|
1026 |
||
1027 |
physicalOffsetX |
|
1028 |
^ OperatingSystem getDeviceCaps:gcId index:112 "PhysicalOffsetX" |
|
1029 |
||
1030 |
"Created: / 01-08-2006 / 16:28:34 / fm" |
|
2301
135f21a3d127
refactorred OS-independent stuff
Claus Gittinger <cg@exept.de>
parents:
2299
diff
changeset
|
1031 |
"Modified: / 16-04-2007 / 12:52:06 / cg" |
2299 | 1032 |
! |
1033 |
||
1034 |
physicalOffsetY |
|
1035 |
^ OperatingSystem getDeviceCaps:gcId index:113 "PhysicalOffsetY" |
|
1036 |
||
1037 |
"Created: / 01-08-2006 / 16:28:34 / fm" |
|
2301
135f21a3d127
refactorred OS-independent stuff
Claus Gittinger <cg@exept.de>
parents:
2299
diff
changeset
|
1038 |
"Modified: / 16-04-2007 / 12:52:01 / cg" |
2299 | 1039 |
! |
1040 |
||
1041 |
pixelsPerInchOfScreenHeight |
|
1042 |
^ OperatingSystem getDeviceCaps:gcId index:90 "Logpixelsy" |
|
1043 |
||
1044 |
"Created: / 01-08-2006 / 16:29:16 / fm" |
|
1045 |
! |
|
1046 |
||
1047 |
pixelsPerInchOfScreenWidth |
|
1048 |
^ OperatingSystem getDeviceCaps:gcId index:88 "Logpixelsx" |
|
1049 |
||
1050 |
"Created: / 01-08-2006 / 16:28:34 / fm" |
|
1051 |
! |
|
1052 |
||
1053 |
printerHeightArea |
|
1054 |
^ (OperatingSystem getDeviceCaps:gcId index:10) |
|
1055 |
||
1056 |
"Modified: / 10-10-2006 / 18:18:31 / cg" |
|
1057 |
! |
|
1058 |
||
1059 |
printerPhysicalHeight |
|
1060 |
^ OperatingSystem getDeviceCaps:gcId "deviceContext" index:111 "PhysicalHeight" |
|
1061 |
||
1062 |
"Created: / 01-08-2006 / 16:14:08 / fm" |
|
1063 |
! |
|
1064 |
||
1065 |
printerPhysicalWidth |
|
1066 |
^ OperatingSystem getDeviceCaps:gcId "deviceContext" index:110 "PhysicalWidth" |
|
1067 |
||
1068 |
"Created: / 01-08-2006 / 16:14:08 / fm" |
|
1069 |
! |
|
1070 |
||
1071 |
printerWidthArea |
|
1072 |
^ OperatingSystem getDeviceCaps:gcId "deviceContext" index:8 "Horzres" |
|
1073 |
||
1074 |
"Created: / 01-08-2006 / 16:14:08 / fm" |
|
1075 |
! |
|
1076 |
||
2323 | 1077 |
supportedImageFormats |
1078 |
"return an array with supported image formats; each array entry |
|
1079 |
is another array, consisting of depth and bitsPerPixel values." |
|
1080 |
||
1081 |
|info| |
|
1082 |
||
1083 |
info := IdentityDictionary new. |
|
1084 |
info at:#depth put:self depth. |
|
1085 |
info at:#bitsPerPixel put:self depth. |
|
1086 |
info at:#padding put:32. |
|
1087 |
^ Array with:info |
|
1088 |
||
1089 |
" |
|
1090 |
Disply supportedImageFormats |
|
1091 |
" |
|
1092 |
||
1093 |
"Modified: / 10.9.1998 / 23:14:05 / cg" |
|
1094 |
! |
|
1095 |
||
1096 |
visualType |
|
1097 |
^ #TrueColor |
|
1098 |
! ! |
|
1099 |
||
1100 |
!WinPrinterContext methodsFor:'color stuff'! |
|
1101 |
||
1102 |
colorScaledRed:r scaledGreen:g scaledBlue:b |
|
1103 |
"allocate a color with rgb values (0..16rFFFF) - return the color index |
|
1104 |
(i.e. colorID)" |
|
1105 |
||
1106 |
%{ /* NOCONTEXT */ |
|
1107 |
int id, ir, ig, ib; |
|
1108 |
||
1109 |
if (__bothSmallInteger(r, g) && __isSmallInteger(b)) { |
|
2344 | 1110 |
ir = (__intVal(r) >> 8) & 0xff; |
1111 |
ig = (__intVal(g) >> 8) & 0xff; |
|
1112 |
ib = (__intVal(b) >> 8) & 0xff; |
|
1113 |
||
1114 |
id = RGB( ir, ig, ib); |
|
1115 |
||
1116 |
RETURN ( __MKSMALLINT(id) ); |
|
2323 | 1117 |
} |
1118 |
%}. |
|
1119 |
self primitiveFailed. |
|
1120 |
^ nil |
|
1121 |
! |
|
1122 |
||
1123 |
setBackground:bgColorIndex in:aDC |
|
1124 |
"set background color to be drawn with" |
|
1125 |
||
1126 |
%{ /* NOCONTEXT */ |
|
1127 |
||
1128 |
HDC hDC; |
|
1129 |
||
1130 |
if (__isExternalAddressLike(aDC)) { |
|
2344 | 1131 |
HANDLE hDC = (HANDLE)(__externalAddressVal(aDC)); |
1132 |
COLORREF bg, oldBg; |
|
1133 |
||
1134 |
oldBg = GetBkColor(hDC); |
|
1135 |
||
1136 |
bg = __intVal(bgColorIndex) & 0xffffff; |
|
2323 | 1137 |
/* bg = (COLORREF)st2RGB(__intVal(bgColorIndex),gcData); */ |
1138 |
||
2344 | 1139 |
if (bg != oldBg) { |
1140 |
SetBkColor(hDC, bg); |
|
1141 |
} |
|
1142 |
||
1143 |
RETURN (self); |
|
2323 | 1144 |
} |
1145 |
%} |
|
1146 |
! |
|
1147 |
||
1148 |
setBackgroundColor:color in:aGCId |
|
1149 |
"set background color to be drawn with" |
|
1150 |
||
1151 |
|colorId deviceColor| |
|
1152 |
||
1153 |
(color isOnDevice:self) ifTrue:[ |
|
2344 | 1154 |
colorId := color colorId. |
2323 | 1155 |
] ifFalse:[ |
2344 | 1156 |
deviceColor := color onDevice:self. |
1157 |
deviceColor notNil ifTrue:[ |
|
1158 |
colorId := deviceColor colorId. |
|
1159 |
] |
|
2323 | 1160 |
]. |
1161 |
colorId isNil ifTrue:[ |
|
2344 | 1162 |
'DeviceWorkstation [warning]: could not set bg color' infoPrintCR. |
2323 | 1163 |
] ifFalse:[ |
2344 | 1164 |
self setBackground:colorId in:aGCId. |
2323 | 1165 |
] |
1166 |
! |
|
1167 |
||
1168 |
setForeground:fgColorIndex background:bgColorIndex in:aDC |
|
1169 |
"set foreground and background colors to be drawn with" |
|
1170 |
||
1171 |
%{ /* NOCONTEXT */ |
|
1172 |
||
1173 |
if (__isExternalAddressLike(aDC)) { |
|
2344 | 1174 |
HANDLE hDC = (HANDLE)(__externalAddressVal(aDC)); |
1175 |
COLORREF fg, bg, oldFg, oldBg; |
|
2323 | 1176 |
|
1177 |
/* fg = (COLORREF)st2RGB(__intVal(fgColorIndex),gcData); */ |
|
2344 | 1178 |
fg = __intVal(fgColorIndex) & 0xffffff; |
2323 | 1179 |
/* bg = (COLORREF)st2RGB(__intVal(bgColorIndex),gcData); */ |
2344 | 1180 |
bg = __intVal(bgColorIndex) & 0xffffff; |
1181 |
||
1182 |
oldFg = GetTextColor(hDC); |
|
1183 |
oldBg = GetBkColor(hDC); |
|
1184 |
||
1185 |
if ((fg != oldFg) || (bg != oldBg)) { |
|
1186 |
/* Pen only depends upon fg-color */ |
|
1187 |
if (fg != oldFg) { |
|
1188 |
SetTextColor(hDC, fg); |
|
1189 |
} |
|
1190 |
if (bg != oldBg) { |
|
1191 |
SetBkColor(hDC, bg); |
|
1192 |
} |
|
1193 |
} |
|
1194 |
RETURN (self); |
|
2323 | 1195 |
} |
1196 |
%} |
|
1197 |
! |
|
1198 |
||
1199 |
setForeground:fgColorIndex in:aDC |
|
1200 |
"set foreground color to be drawn with" |
|
1201 |
||
1202 |
%{ /* NOCONTEXT */ |
|
1203 |
||
1204 |
HDC hDC; |
|
1205 |
||
1206 |
if (__isExternalAddressLike(aDC)) { |
|
2344 | 1207 |
HANDLE hDC = (HANDLE)(__externalAddressVal(aDC)); |
1208 |
COLORREF fg, oldFg; |
|
1209 |
||
1210 |
oldFg = GetTextColor(hDC); |
|
1211 |
||
1212 |
fg = __intVal(fgColorIndex) & 0xffffff; |
|
2323 | 1213 |
/* fg = (COLORREF)st2RGB(__intVal(fgColorIndex),gcData); */ |
1214 |
||
2344 | 1215 |
if (fg != oldFg) { |
1216 |
SetTextColor(hDC, fg); |
|
1217 |
} |
|
1218 |
||
1219 |
RETURN (self); |
|
2323 | 1220 |
} |
1221 |
%} |
|
1222 |
! |
|
1223 |
||
1224 |
setForegroundColor:color in:aGCId |
|
1225 |
"set the foreground color to be drawn with" |
|
1226 |
||
1227 |
|colorId deviceColor| |
|
1228 |
||
1229 |
(color isOnDevice:self) ifTrue:[ |
|
2344 | 1230 |
colorId := color colorId. |
2323 | 1231 |
] ifFalse:[ |
2344 | 1232 |
deviceColor := color onDevice:self. |
1233 |
deviceColor notNil ifTrue:[ |
|
1234 |
colorId := deviceColor colorId. |
|
1235 |
] |
|
2323 | 1236 |
]. |
1237 |
colorId isNil ifTrue:[ |
|
2344 | 1238 |
'DeviceWorkstation [warning]: could not set fg color' infoPrintCR. |
2323 | 1239 |
] ifFalse:[ |
2344 | 1240 |
self setForeground:colorId in:aGCId. |
2323 | 1241 |
] |
1242 |
! ! |
|
1243 |
||
1244 |
!WinPrinterContext methodsFor:'context stuff'! |
|
1245 |
||
1246 |
getPenFor:aDC |
|
1247 |
"set line attributes" |
|
1248 |
||
1249 |
%{ /* NOCONTEXT */ |
|
1250 |
||
1251 |
if (__isExternalAddressLike(aDC) |
|
1252 |
&& __isSmallInteger(__INST(lineWidth))) { |
|
2344 | 1253 |
HANDLE hDC = (HANDLE)(__externalAddressVal(aDC)); |
1254 |
COLORREF fgColor; |
|
1255 |
HANDLE hPen, prevPen; |
|
1256 |
int lineStyleInt, capStyleInt, joinStyleInt, lineWidth; |
|
1257 |
||
1258 |
lineWidth= __INST(lineWidth); |
|
1259 |
||
1260 |
if (__INST(lineStyle) == @symbol(solid)) { |
|
1261 |
lineStyleInt= PS_SOLID; |
|
1262 |
} else if (__INST(lineStyle) == @symbol(dashed)) { |
|
1263 |
lineStyleInt= PS_DASH; |
|
1264 |
} else if (__INST(lineStyle) == @symbol(dotted)) { |
|
1265 |
lineStyleInt= PS_DOT; |
|
1266 |
} else if (__INST(lineStyle) == @symbol(dashDot)) { |
|
1267 |
lineStyleInt= PS_DASHDOT; |
|
1268 |
} else if (__INST(lineStyle) == @symbol(dashDotDot)) { |
|
1269 |
lineStyleInt= PS_DASHDOTDOT; |
|
1270 |
} else |
|
1271 |
lineStyleInt= PS_SOLID; |
|
1272 |
||
1273 |
if (__INST(capStyle) == @symbol(round)) { |
|
1274 |
capStyleInt= PS_ENDCAP_ROUND; |
|
1275 |
} else if (__INST(capStyle) == @symbol(square)) { |
|
1276 |
capStyleInt= PS_ENDCAP_SQUARE; |
|
1277 |
} else if (__INST(capStyle) == @symbol(flat)) { |
|
1278 |
capStyleInt= PS_ENDCAP_FLAT; |
|
1279 |
} else |
|
1280 |
capStyleInt= PS_ENDCAP_FLAT; |
|
1281 |
||
1282 |
if (__INST(joinStyle) == @symbol(bevel)) { |
|
1283 |
joinStyleInt= PS_JOIN_BEVEL; |
|
1284 |
} else if (__INST(joinStyle) == @symbol(miter)) { |
|
1285 |
joinStyleInt= PS_JOIN_MITER; |
|
1286 |
} else if (__INST(joinStyle) == @symbol(round)) { |
|
1287 |
joinStyleInt= PS_JOIN_ROUND; |
|
1288 |
} else |
|
1289 |
joinStyleInt= PS_JOIN_MITER; |
|
1290 |
||
1291 |
||
1292 |
fgColor = GetTextColor(hDC); |
|
1293 |
||
1294 |
hPen = CreatePen(lineStyleInt | capStyleInt | joinStyleInt, lineWidth, fgColor); |
|
1295 |
prevPen = SelectObject(hDC, hPen); |
|
1296 |
||
1297 |
||
1298 |
RETURN (self); |
|
2323 | 1299 |
} |
1300 |
%}. |
|
1301 |
self primitiveFailed |
|
1302 |
! |
|
1303 |
||
1304 |
getPenForContext |
|
1305 |
"set line attributes" |
|
1306 |
||
1307 |
%{ /* NOCONTEXT */ |
|
1308 |
||
1309 |
if (__isExternalAddressLike(__INST(gcId)) |
|
1310 |
&& __isSmallInteger(__INST(lineWidth))) { |
|
2344 | 1311 |
HANDLE hDC = (HANDLE)(__externalAddressVal(__INST(gcId))); |
1312 |
COLORREF fgColor; |
|
1313 |
HANDLE hPen; |
|
1314 |
int lineStyleInt, capStyleInt, joinStyleInt, lineWidth; |
|
1315 |
||
1316 |
lineWidth= __INST(lineWidth); |
|
1317 |
||
1318 |
if (__INST(lineStyle) == @symbol(solid)) { |
|
1319 |
lineStyleInt= PS_SOLID; |
|
1320 |
} else if (__INST(lineStyle) == @symbol(dashed)) { |
|
1321 |
lineStyleInt= PS_DASH; |
|
1322 |
} else if (__INST(lineStyle) == @symbol(dotted)) { |
|
1323 |
lineStyleInt= PS_DOT; |
|
1324 |
} else if (__INST(lineStyle) == @symbol(dashDot)) { |
|
1325 |
lineStyleInt= PS_DASHDOT; |
|
1326 |
} else if (__INST(lineStyle) == @symbol(dashDotDot)) { |
|
1327 |
lineStyleInt= PS_DASHDOTDOT; |
|
1328 |
} else |
|
1329 |
lineStyleInt= PS_SOLID; |
|
1330 |
||
1331 |
if (__INST(capStyle) == @symbol(round)) { |
|
1332 |
capStyleInt= PS_ENDCAP_ROUND; |
|
1333 |
} else if (__INST(capStyle) == @symbol(square)) { |
|
1334 |
capStyleInt= PS_ENDCAP_SQUARE; |
|
1335 |
} else if (__INST(capStyle) == @symbol(flat)) { |
|
1336 |
capStyleInt= PS_ENDCAP_FLAT; |
|
1337 |
} else |
|
1338 |
capStyleInt= PS_ENDCAP_FLAT; |
|
1339 |
||
1340 |
if (__INST(joinStyle) == @symbol(bevel)) { |
|
1341 |
joinStyleInt= PS_JOIN_BEVEL; |
|
1342 |
} else if (__INST(joinStyle) == @symbol(miter)) { |
|
1343 |
joinStyleInt= PS_JOIN_MITER; |
|
1344 |
} else if (__INST(joinStyle) == @symbol(round)) { |
|
1345 |
joinStyleInt= PS_JOIN_ROUND; |
|
1346 |
} else |
|
1347 |
joinStyleInt= PS_JOIN_MITER; |
|
1348 |
||
1349 |
||
1350 |
fgColor = GetTextColor(hDC); |
|
1351 |
||
1352 |
hPen = CreatePen(lineStyleInt | capStyleInt | joinStyleInt, lineWidth, fgColor); |
|
1353 |
||
1354 |
RETURN (self); |
|
2323 | 1355 |
} |
1356 |
%}. |
|
1357 |
self primitiveFailed |
|
1358 |
! |
|
1359 |
||
2330 | 1360 |
hatch |
1361 |
||
1362 |
"The hatch style will define a hatched brush between these patterns: |
|
1363 |
||
1364 |
#none |
|
1365 |
#horizontal ----- HS_HORIZONTAL = 0 |
|
1366 |
#vertical ||||| HS_VERTICAL = 1 |
|
1367 |
#fDiagonal \\\\\ HS_FDIAGONAL = 2 |
|
1368 |
#bDiagonal ///// HS_BDIAGONAL = 3 |
|
1369 |
#cross +++++ HS_CROSS = 4 |
|
1370 |
#diagonalCross xxxxx HS_DIAGCROSS = 5 |
|
1371 |
" |
|
1372 |
||
1373 |
hatch isNil ifTrue:[^#none]. |
|
1374 |
^ hatch |
|
1375 |
! |
|
1376 |
||
1377 |
hatch: aSymbol |
|
1378 |
||
1379 |
"The hatch style will define a hatched brush between these patterns: |
|
1380 |
||
1381 |
#none |
|
1382 |
#horizontal ----- HS_HORIZONTAL = 0 |
|
1383 |
#vertical ||||| HS_VERTICAL = 1 |
|
1384 |
#fDiagonal \\\\\ HS_FDIAGONAL = 2 |
|
1385 |
#bDiagonal ///// HS_BDIAGONAL = 3 |
|
1386 |
#cross +++++ HS_CROSS = 4 |
|
1387 |
#diagonalCross xxxxx HS_DIAGCROSS = 5 |
|
1388 |
" |
|
1389 |
||
1390 |
hatch := aSymbol |
|
1391 |
! |
|
1392 |
||
2323 | 1393 |
noClipIn:aWindowId gc:aDC |
1394 |
"disable clipping rectangle" |
|
1395 |
||
1396 |
%{ /* NOCONTEXT */ |
|
1397 |
||
1398 |
if (__isExternalAddressLike(aDC)) { |
|
2344 | 1399 |
HANDLE hDC = (HANDLE)(__externalAddressVal(aDC)); |
1400 |
||
1401 |
SelectClipRgn(hDC, NULL); |
|
1402 |
RETURN (self); |
|
2323 | 1403 |
} |
1404 |
%} |
|
1405 |
! |
|
1406 |
||
1407 |
setBitmapMask:aBitmapId in:aDC |
|
1408 |
"set or clear the drawing mask - a bitmap mask using current fg/bg" |
|
1409 |
||
1410 |
%{ /* NOCONTEXT */ |
|
1411 |
||
1412 |
if (__isExternalAddressLike(aDC)) { |
|
2344 | 1413 |
HANDLE hDC = (HANDLE)(__externalAddressVal(aDC)); |
1414 |
HBITMAP oldM; |
|
2323 | 1415 |
|
1416 |
/* oldM = gcData->hMask; |
|
2344 | 1417 |
if (__isExternalAddress(aBitmapId)) |
1418 |
gcData->hMask = _HBITMAPVAL(aBitmapId); |
|
1419 |
else |
|
1420 |
gcData->hMask = 0; |
|
1421 |
||
1422 |
if (oldM != gcData->hMask) { |
|
1423 |
FLUSH_CACHED_DC(gcData); |
|
1424 |
CPRINTF(("masks set to %x\n",gcData->hMask)); |
|
1425 |
} */ |
|
1426 |
RETURN (self); |
|
2323 | 1427 |
} |
1428 |
%} |
|
1429 |
! |
|
1430 |
||
1431 |
setClipX:clipX y:clipY width:clipWidth height:clipHeight in:ignoredDrawableId gc:aDC |
|
1432 |
"clip to a rectangle" |
|
1433 |
||
1434 |
" |
|
1435 |
p--w--- |
|
1436 |
| | |
|
1437 |
h | the clipping rectangle |
|
1438 |
| | |
|
1439 |
------- |
|
2344 | 1440 |
where p = ( clipX, clipY ), w = clipWidth, h = clipHeight |
2323 | 1441 |
" |
1442 |
||
1443 |
%{ /* NOCONTEXT */ |
|
1444 |
||
1445 |
if (__isExternalAddressLike(aDC) |
|
1446 |
&& __bothSmallInteger(clipX, clipY) |
|
1447 |
&& __bothSmallInteger(clipWidth, clipHeight) ) { |
|
2344 | 1448 |
HANDLE hDC; |
1449 |
int cX, cY, cW, cH; |
|
1450 |
POINT ptOrg; |
|
1451 |
||
1452 |
||
1453 |
hDC = (HANDLE)(__externalAddressVal(aDC)); |
|
1454 |
||
1455 |
GetViewportOrgEx(hDC,&ptOrg); |
|
1456 |
||
1457 |
// set the clip rectangle |
|
1458 |
// and offset the rectangle by the viewport origin |
|
1459 |
||
1460 |
cX = __intVal(clipX) + ptOrg.x; |
|
1461 |
cY = __intVal(clipY) + ptOrg.y; |
|
1462 |
cW = __intVal(clipWidth)+ ptOrg.x; |
|
1463 |
cH = __intVal(clipHeight)+ ptOrg.y; |
|
1464 |
||
1465 |
{ |
|
1466 |
HRGN region = CreateRectRgn(cX, cY, cX + cW, cY + cH); |
|
1467 |
||
1468 |
if (region == NULL ) { |
|
1469 |
console_fprintf(stderr, "WinWorkstat [warning]: clipping region creation failed\n"); |
|
1470 |
} else { |
|
1471 |
if (SelectClipRgn(hDC, region) == ERROR ) { |
|
1472 |
console_fprintf(stderr, "WinWorkstat [warning]: select clipping region failed\n"); |
|
1473 |
} |
|
1474 |
DeleteObject(region); |
|
1475 |
} |
|
1476 |
} |
|
1477 |
RETURN (self); |
|
2323 | 1478 |
} |
1479 |
%}. |
|
1480 |
self primitiveFailed |
|
1481 |
! |
|
1482 |
||
1483 |
setDashes:dashList dashOffset:offset in:aGCId |
|
1484 |
"set line attributes" |
|
1485 |
||
1486 |
%{ /* NOCONTEXT */ |
|
1487 |
||
1488 |
if (__isExternalAddressLike(aGCId)) { |
|
2344 | 1489 |
DPRINTF(("WinWorkstat [warning]: dashes not (yet) implemented\n")); |
2323 | 1490 |
} |
1491 |
%} |
|
1492 |
! |
|
1493 |
||
1494 |
setLineWidth:aNumber style:lineStyle cap:capStyle join:joinStyle in:aDC |
|
1495 |
"set line attributes" |
|
1496 |
||
1497 |
%{ /* NOCONTEXT */ |
|
1498 |
||
1499 |
HDC hDC; |
|
1500 |
||
1501 |
if (__isExternalAddressLike(aDC) |
|
1502 |
&& __isSmallInteger(aNumber)) { |
|
2344 | 1503 |
HANDLE hDC = (HANDLE)(__externalAddressVal(aDC)); |
1504 |
int style; |
|
1505 |
||
1506 |
if (lineStyle == @symbol(solid)) { |
|
1507 |
style = PS_SOLID; |
|
1508 |
} else if (lineStyle == @symbol(dashed)) { |
|
1509 |
style= PS_DASH; |
|
1510 |
} else if (lineStyle == @symbol(dotted)) { |
|
1511 |
style= PS_DOT; |
|
1512 |
} else if (lineStyle == @symbol(dashDot)) { |
|
1513 |
style= PS_DASHDOT; |
|
1514 |
} else if (lineStyle == @symbol(dashDotDot)) { |
|
1515 |
style= PS_DASHDOTDOT; |
|
1516 |
} else |
|
1517 |
style= PS_SOLID; |
|
1518 |
||
1519 |
if (capStyle == @symbol(round)) { |
|
1520 |
style = PS_ENDCAP_ROUND; |
|
1521 |
} else if (capStyle == @symbol(square)) { |
|
1522 |
style = PS_ENDCAP_SQUARE; |
|
1523 |
} else if (capStyle == @symbol(flat)) { |
|
1524 |
style = PS_ENDCAP_FLAT; |
|
1525 |
} else |
|
1526 |
style = PS_ENDCAP_FLAT; |
|
1527 |
||
1528 |
if (joinStyle == @symbol(bevel)) { |
|
1529 |
style = PS_JOIN_BEVEL; |
|
1530 |
} else if (joinStyle == @symbol(miter)) { |
|
1531 |
style = PS_JOIN_MITER; |
|
1532 |
} else if (joinStyle == @symbol(round)) { |
|
1533 |
style = PS_JOIN_ROUND; |
|
1534 |
} else |
|
1535 |
style = PS_JOIN_MITER; |
|
1536 |
||
1537 |
||
1538 |
RETURN (self); |
|
2323 | 1539 |
} |
1540 |
%}. |
|
1541 |
self primitiveFailed |
|
1542 |
! |
|
1543 |
||
1544 |
setMaskOriginX:orgX y:orgY in:aDC |
|
1545 |
"set the mask origin" |
|
1546 |
||
1547 |
%{ /* NOCONTEXT */ |
|
1548 |
||
1549 |
if (__isExternalAddress(aDC) |
|
1550 |
&& __bothSmallInteger(orgX,orgY)) { |
|
2344 | 1551 |
HANDLE hDC = (HANDLE)(__externalAddressVal(aDC)); |
1552 |
int oX, oY, maskOrgX, maskOrgY; |
|
1553 |
||
1554 |
oX = __intVal(orgX); |
|
1555 |
oY = __intVal(orgY); |
|
1556 |
if ((oX != maskOrgX) |
|
1557 |
|| (oY != maskOrgY)) { |
|
1558 |
maskOrgX = __intVal(orgX); |
|
1559 |
maskOrgY = __intVal(orgY);; |
|
1560 |
} |
|
1561 |
RETURN (self); |
|
2323 | 1562 |
} |
1563 |
%} |
|
1564 |
! |
|
1565 |
||
2299 | 1566 |
setViewportOrg: aPoint |
1567 |
||
2323 | 1568 |
"Sets the viewport origin (LOGICAL point (0,0)) of the device context" |
1569 |
||
2317 | 1570 |
^ OperatingSystem |
2344 | 1571 |
setViewportOrg: gcId "deviceContext" |
1572 |
x: aPoint x |
|
1573 |
y: aPoint y |
|
1574 |
oldOrigin: nil |
|
2299 | 1575 |
|
1576 |
"Created: / 01-08-2006 / 16:14:08 / fm" |
|
1577 |
! ! |
|
1578 |
||
2316 | 1579 |
!WinPrinterContext methodsFor:'drawing'! |
1580 |
||
2323 | 1581 |
displayArcX:x y:y width:width height:height from:startAngle angle:angle in:ignoredDrawableId with:aDC |
1582 |
"draw an arc. If any of x,y, w or h is not an integer, an error is triggered. |
|
1583 |
The angles may be floats or integer - they are given in degrees." |
|
1584 |
||
1585 |
%{ |
|
1586 |
int __x, __y, w, h; |
|
1587 |
float angle1, angle2; |
|
1588 |
double f; |
|
1589 |
||
1590 |
if (__isSmallInteger(startAngle)) |
|
2344 | 1591 |
angle1 = (float)(__intVal(startAngle)); |
2323 | 1592 |
else if (__isFloat(startAngle)) { |
2344 | 1593 |
angle1 = (float) __floatVal(startAngle); |
2323 | 1594 |
} else if (__isShortFloat(startAngle)) { |
2344 | 1595 |
angle1 = __shortFloatVal(startAngle); |
2323 | 1596 |
} else goto bad; |
1597 |
||
1598 |
if (__isSmallInteger(angle)) |
|
2344 | 1599 |
angle2 = (float)(__intVal(angle)); |
2323 | 1600 |
else if (__isFloat(angle)) { |
2344 | 1601 |
angle2 = (float) __floatVal(angle); |
2323 | 1602 |
} else if (__isShortFloat(angle)) { |
2344 | 1603 |
angle2 = __shortFloatVal(angle); |
2323 | 1604 |
} else goto bad; |
1605 |
||
1606 |
if (angle2 <= 0) { |
|
2344 | 1607 |
RETURN (self); |
2323 | 1608 |
} |
1609 |
||
1610 |
if (__isExternalAddressLike(aDC) |
|
1611 |
&& __bothSmallInteger(x, y) |
|
1612 |
&& __bothSmallInteger(width, height)) |
|
1613 |
{ |
|
2344 | 1614 |
POINT p; |
1615 |
HANDLE hDC = (HANDLE)(__externalAddressVal(aDC)); |
|
1616 |
DWORD clr = 0 /* 0xFFFFFFFF */; |
|
1617 |
HANDLE prevPen, hPen; |
|
1618 |
double xB, yB, xE, yE, xR, yR; |
|
1619 |
COLORREF fgColor; |
|
1620 |
int lStyleSymbol, lStyleInt; |
|
1621 |
int lw; |
|
1622 |
||
1623 |
lw= __intVal(__INST(lineWidth)); |
|
1624 |
lStyleSymbol= __INST(lineStyle); |
|
1625 |
||
1626 |
/* PS_DASH, PS_DOT, PS_DASHDOT, PS_DASHDOTDOT |
|
1627 |
only works with lineWidth = 1 */ |
|
1628 |
||
1629 |
if (lStyleSymbol == @symbol(solid)) { |
|
1630 |
lStyleInt= PS_SOLID; |
|
1631 |
} else if (lStyleSymbol == @symbol(dashed)) { |
|
1632 |
lStyleInt= PS_DASH; |
|
1633 |
} else if (lStyleSymbol == @symbol(dotted)) { |
|
1634 |
lStyleInt= PS_DOT; |
|
1635 |
} else if (lStyleSymbol == @symbol(dashDot)) { |
|
1636 |
lStyleInt= PS_DASHDOT; |
|
1637 |
} else if (lStyleSymbol == @symbol(dashDotDot)) { |
|
1638 |
lStyleInt= PS_DASHDOTDOT; |
|
1639 |
} else if (lStyleSymbol == @symbol(insideFrame)) { |
|
1640 |
lStyleInt= PS_INSIDEFRAME; |
|
1641 |
} else |
|
1642 |
lStyleInt= PS_SOLID; |
|
1643 |
||
1644 |
fgColor = GetTextColor(hDC); |
|
1645 |
hPen = CreatePen(lStyleInt, lw, fgColor); |
|
1646 |
||
1647 |
w = __intVal(width); |
|
1648 |
h = __intVal(height); |
|
1649 |
__x = __intVal(x); |
|
1650 |
__y = __intVal(y); |
|
1651 |
||
1652 |
xR = w / 2; |
|
1653 |
yR = h / 2; |
|
1654 |
if (angle2 - angle1 >= 360) { |
|
1655 |
xB = xE = __x + xR + 0.5; |
|
1656 |
yB = yE = __y /*+ yR + 0.5*/; |
|
1657 |
} else { |
|
1658 |
double sin(), cos(); |
|
1659 |
float rad1, rad2; |
|
1660 |
||
1661 |
if (angle1 <= 180) |
|
1662 |
angle1 = 180 - angle1; |
|
1663 |
else |
|
1664 |
angle1 = 360 + 180 - angle1; |
|
1665 |
angle2 = angle1 - angle2; |
|
1666 |
/* sigh - compute the intersections ... */ |
|
1667 |
rad1 = (angle1 * 3.14159265359) / 180.0; |
|
1668 |
rad2 = (angle2 * 3.14159265359) / 180.0; |
|
1669 |
xB = cos(rad1) * xR; |
|
1670 |
yB = sin(rad1) * yR; |
|
1671 |
xE = cos(rad2) * xR; |
|
1672 |
yE = sin(rad2) * yR; |
|
1673 |
xB = __x + xR - xB + 0.5; |
|
1674 |
yB = __y + yR - yB + 0.5; |
|
1675 |
xE = __x + xR - xE + 0.5; |
|
1676 |
yE = __y + yR - yE + 0.5; |
|
1677 |
} |
|
1678 |
prevPen = SelectObject(hDC, hPen); |
|
1679 |
DPRINTF(("Arc x=%d y=%d w=%d h=%d xB=%d xE=%d yB=%d yE=%d a1=%f a2=%f\n",__x,__y,w,h,(int)xB,(int)xE,(int)yB,(int)yE,angle1,angle2)); |
|
1680 |
Arc(hDC, |
|
1681 |
__x, __y, |
|
1682 |
__x + w, __y + h, |
|
1683 |
(int)xB, (int)yB, |
|
1684 |
(int)xE, (int)yE); |
|
1685 |
||
1686 |
SelectObject(hDC, prevPen); |
|
1687 |
DeleteObject(hPen); |
|
1688 |
||
1689 |
RETURN ( self ); |
|
2323 | 1690 |
} |
1691 |
bad: ; |
|
1692 |
%}. |
|
1693 |
self primitiveFailed |
|
1694 |
||
1695 |
"Created: / 07-08-2006 / 10:40:27 / fm" |
|
1696 |
"Modified: / 07-08-2006 / 14:44:21 / fm" |
|
1697 |
! |
|
1698 |
||
1699 |
displayLineFromX:x0 y:y0 toX:x1 y:y1 in:ignoredDrawableId with:aDC |
|
1700 |
"draw a line. If the coordinates are not integers, an error is triggered." |
|
1701 |
||
1702 |
%{ /* NOCONTEXT */ |
|
1703 |
if (__isExternalAddressLike(aDC) |
|
1704 |
&& __bothSmallInteger(x0, y0) |
|
1705 |
&& __bothSmallInteger(x1, y1)) { |
|
2342 | 1706 |
HANDLE hDC = (HANDLE)(__externalAddressVal(aDC)); |
1707 |
COLORREF fgColor; |
|
1708 |
HANDLE prevPen, hPen; |
|
1709 |
int __x1 = __intVal(x1), __y1 = __intVal(y1); |
|
1710 |
int lStyleSymbol, lStyleInt; |
|
1711 |
int lw; |
|
2323 | 1712 |
|
1713 |
/* DPRINTF(("displayLine: %d/%d -> %d/%d\n", |
|
2342 | 1714 |
__intVal(x0), __intVal(y0), |
1715 |
__x1, __y1)); |
|
2323 | 1716 |
*/ |
1717 |
||
2342 | 1718 |
lw= __intVal(__INST(lineWidth)); |
1719 |
lStyleSymbol= __INST(lineStyle); |
|
1720 |
||
1721 |
/* PS_DASH, PS_DOT, PS_DASHDOT, PS_DASHDOTDOT |
|
1722 |
only works with lineWidth = 1 */ |
|
1723 |
||
1724 |
if (lStyleSymbol == @symbol(solid)) { |
|
1725 |
lStyleInt= PS_SOLID; |
|
1726 |
} else if (lStyleSymbol == @symbol(dashed)) { |
|
1727 |
lStyleInt= PS_DASH; |
|
1728 |
} else if (lStyleSymbol == @symbol(dotted)) { |
|
1729 |
lStyleInt= PS_DOT; |
|
1730 |
} else if (lStyleSymbol == @symbol(dashDot)) { |
|
1731 |
lStyleInt= PS_DASHDOT; |
|
1732 |
} else if (lStyleSymbol == @symbol(dashDotDot)) { |
|
1733 |
lStyleInt= PS_DASHDOTDOT; |
|
1734 |
} else if (lStyleSymbol == @symbol(insideFrame)) { |
|
1735 |
lStyleInt= PS_INSIDEFRAME; |
|
1736 |
} else |
|
1737 |
lStyleInt= PS_SOLID; |
|
1738 |
||
1739 |
fgColor = GetTextColor(hDC); |
|
1740 |
hPen = CreatePen(lStyleInt, lw, fgColor); |
|
1741 |
prevPen = SelectObject(hDC, hPen); |
|
1742 |
MoveToEx(hDC, __intVal(x0), __intVal(y0), NULL); |
|
1743 |
LineTo(hDC, __x1, __y1); |
|
1744 |
/* |
|
1745 |
* end-point ... |
|
1746 |
*/ |
|
1747 |
// LineTo(hDC, __x1+1, __y1); |
|
1748 |
||
1749 |
SelectObject(hDC, prevPen); |
|
1750 |
DeleteObject(hPen); |
|
1751 |
||
1752 |
RETURN ( self ); |
|
2323 | 1753 |
} |
1754 |
%} |
|
1755 |
! |
|
1756 |
||
1757 |
displayPointX:px y:py in:ignoredDrawableId with:aDC |
|
1758 |
"draw a point. If x/y are not integers, an error is triggered." |
|
1759 |
||
1760 |
%{ /* NOCONTEXT */ |
|
1761 |
if (__isExternalAddressLike(aDC) |
|
1762 |
&& __bothSmallInteger(px, py)) { |
|
2344 | 1763 |
HANDLE hDC = (HANDLE)(__externalAddressVal(aDC)); |
1764 |
POINT p; |
|
1765 |
COLORREF fgColor; |
|
1766 |
||
1767 |
int __x = __intVal(px), __y = __intVal(py); |
|
1768 |
||
1769 |
fgColor = GetTextColor(hDC); |
|
1770 |
SetPixelV(hDC, __x, __y, fgColor); |
|
1771 |
||
1772 |
RETURN ( self ); |
|
2323 | 1773 |
} |
1774 |
%} |
|
1775 |
! |
|
1776 |
||
1777 |
displayPolygon:aPolygon in:aDrawableId with:aDC |
|
1778 |
"draw a polygon, the argument aPolygon is a Collection of individual points, |
|
1779 |
which define the polygon. |
|
1780 |
If any coordinate is not integer, an error is triggered." |
|
1781 |
||
1782 |
|numberOfPoints| |
|
1783 |
||
1784 |
numberOfPoints := aPolygon size. |
|
1785 |
%{ |
|
1786 |
OBJ point, px, py; |
|
1787 |
int i, num; |
|
1788 |
||
1789 |
if (__isExternalAddressLike(aDC) |
|
1790 |
/* && __isExternalAddress(aDrawableId) */ |
|
1791 |
&& __isSmallInteger(numberOfPoints)) { |
|
2344 | 1792 |
HANDLE hDC = (HANDLE)(__externalAddressVal(aDC)); |
1793 |
POINT p; |
|
1794 |
DWORD clr = 0 /* 0xFFFFFFFF */; |
|
1795 |
HANDLE prevPen, hPen; |
|
1796 |
int lw; |
|
1797 |
COLORREF fgColor; |
|
1798 |
int lStyleSymbol, lStyleInt; |
|
1799 |
||
1800 |
lw= __intVal(__INST(lineWidth)); |
|
1801 |
lStyleSymbol= __INST(lineStyle); |
|
1802 |
||
1803 |
/* PS_DASH, PS_DOT, PS_DASHDOT, PS_DASHDOTDOT |
|
1804 |
only works with lineWidth = 1 */ |
|
1805 |
||
1806 |
if (lStyleSymbol == @symbol(solid)) { |
|
1807 |
lStyleInt= PS_SOLID; |
|
1808 |
} else if (lStyleSymbol == @symbol(dashed)) { |
|
1809 |
lStyleInt= PS_DASH; |
|
1810 |
} else if (lStyleSymbol == @symbol(dotted)) { |
|
1811 |
lStyleInt= PS_DOT; |
|
1812 |
} else if (lStyleSymbol == @symbol(dashDot)) { |
|
1813 |
lStyleInt= PS_DASHDOT; |
|
1814 |
} else if (lStyleSymbol == @symbol(dashDotDot)) { |
|
1815 |
lStyleInt= PS_DASHDOTDOT; |
|
1816 |
} else if (lStyleSymbol == @symbol(insideFrame)) { |
|
1817 |
lStyleInt= PS_INSIDEFRAME; |
|
1818 |
} else |
|
1819 |
lStyleInt= PS_SOLID; |
|
1820 |
||
1821 |
num = __intVal(numberOfPoints); |
|
1822 |
||
1823 |
for (i=0; i<num; i++) { |
|
1824 |
point = __AT_(aPolygon, __MKSMALLINT(i+1)); |
|
1825 |
if (! __isPoint(point)) goto fail; |
|
1826 |
px = _point_X(point); |
|
1827 |
py = _point_Y(point); |
|
1828 |
if (! __bothSmallInteger(px, py)) { |
|
1829 |
goto fail; |
|
1830 |
} |
|
1831 |
} |
|
1832 |
||
1833 |
fgColor = GetTextColor(hDC); |
|
1834 |
||
1835 |
hPen = CreatePen(lStyleInt, lw, fgColor); |
|
1836 |
prevPen = SelectObject(hDC, hPen); |
|
1837 |
||
1838 |
for (i=0; i<num; i++) { |
|
1839 |
point = __AT_(aPolygon, __MKSMALLINT(i+1)); |
|
1840 |
px = _point_X(point); |
|
1841 |
py = _point_Y(point); |
|
1842 |
p.x = __intVal(px); |
|
1843 |
p.y = __intVal(py); |
|
1844 |
if (i == 0) { |
|
1845 |
MoveToEx(hDC, p.x, p.y, NULL); |
|
1846 |
} else { |
|
1847 |
if (i == (num-1)) { |
|
1848 |
PolylineTo(hDC, &p, 1); |
|
1849 |
} else { |
|
1850 |
LineTo(hDC, p.x, p.y); |
|
2323 | 1851 |
#ifdef PRE_04_JUN_04 |
2344 | 1852 |
/* |
1853 |
* end-point ... |
|
1854 |
*/ |
|
1855 |
LineTo(hDC, p.x+1, p.y); |
|
2323 | 1856 |
#endif |
2344 | 1857 |
} |
1858 |
} |
|
1859 |
} |
|
1860 |
SelectObject(hDC, prevPen); |
|
1861 |
DeleteObject(hPen); |
|
1862 |
||
1863 |
||
1864 |
RETURN ( self ); |
|
2323 | 1865 |
} |
1866 |
fail: ; |
|
1867 |
%} |
|
1868 |
||
1869 |
"Created: / 07-08-2006 / 14:46:55 / fm" |
|
1870 |
! |
|
1871 |
||
2317 | 1872 |
displayPolylines:arrayOfPoints |
2316 | 1873 |
|
1874 |
device displayPolylines:arrayOfPoints in:nil with:gcId |
|
2323 | 1875 |
! |
1876 |
||
1877 |
displayPolylines:aPolyline in:ignoredDrawableId with:aDC |
|
1878 |
"draw a polyline, the argument aPolyline is a collection of individual points, |
|
1879 |
which define the lines (p1/p2 pairs); must be even in size. |
|
1880 |
If any coordinate is not integer, an error is triggered." |
|
1881 |
||
1882 |
|numberOfPoints| |
|
1883 |
||
1884 |
numberOfPoints := aPolyline size. |
|
1885 |
||
1886 |
%{ |
|
1887 |
OBJ point, px, py; |
|
1888 |
int i, num; |
|
1889 |
||
1890 |
if (__isExternalAddressLike(aDC) |
|
1891 |
&& __isSmallInteger(numberOfPoints)) { |
|
1892 |
||
2344 | 1893 |
HANDLE hDC = (HANDLE)(__externalAddressVal(aDC)); |
1894 |
POINT p; |
|
1895 |
HANDLE prevPen, hPen; |
|
1896 |
COLORREF fgColor; |
|
1897 |
int lw; |
|
1898 |
int lStyleSymbol, lStyleInt; |
|
1899 |
||
1900 |
||
1901 |
lw= __intVal(__INST(lineWidth)); |
|
1902 |
lStyleSymbol= __INST(lineStyle); |
|
1903 |
||
1904 |
/* PS_DASH, PS_DOT, PS_DASHDOT, PS_DASHDOTDOT |
|
1905 |
only works with lineWidth = 1 */ |
|
1906 |
||
1907 |
if (lStyleSymbol == @symbol(solid)) { |
|
1908 |
lStyleInt= PS_SOLID; |
|
1909 |
} else if (lStyleSymbol == @symbol(dashed)) { |
|
1910 |
lStyleInt= PS_DASH; |
|
1911 |
} else if (lStyleSymbol == @symbol(dotted)) { |
|
1912 |
lStyleInt= PS_DOT; |
|
1913 |
} else if (lStyleSymbol == @symbol(dashDot)) { |
|
1914 |
lStyleInt= PS_DASHDOT; |
|
1915 |
} else if (lStyleSymbol == @symbol(dashDotDot)) { |
|
1916 |
lStyleInt= PS_DASHDOTDOT; |
|
1917 |
} else if (lStyleSymbol == @symbol(insideFrame)) { |
|
1918 |
lStyleInt= PS_INSIDEFRAME; |
|
1919 |
} else |
|
1920 |
lStyleInt= PS_SOLID; |
|
1921 |
||
1922 |
fgColor = GetTextColor(hDC); |
|
1923 |
||
1924 |
num = __intVal(numberOfPoints); |
|
1925 |
||
1926 |
for (i=0; i<num; i++) { |
|
1927 |
point = __AT_(aPolyline, __MKSMALLINT(i+1)); |
|
1928 |
if (! __isPoint(point)) goto fail; |
|
1929 |
px = _point_X(point); |
|
1930 |
py = _point_Y(point); |
|
1931 |
if (! __bothSmallInteger(px, py)) { |
|
1932 |
goto fail; |
|
1933 |
} |
|
1934 |
} |
|
1935 |
||
1936 |
hPen = CreatePen(lStyleInt, lw, fgColor); |
|
1937 |
prevPen = SelectObject(hDC, hPen); |
|
1938 |
||
1939 |
for (i=0; i<num; i++) { |
|
1940 |
point = __AT_(aPolyline, __MKSMALLINT(i+1)); |
|
1941 |
px = _point_X(point); |
|
1942 |
py = _point_Y(point); |
|
1943 |
p.x = __intVal(px); |
|
1944 |
p.y = __intVal(py); |
|
1945 |
DPRINTF(("printing point")); |
|
1946 |
DPRINTF(("displayPolygon: no pen\n")); |
|
1947 |
||
1948 |
if ((i & 1) == 0) { |
|
1949 |
MoveToEx(hDC, p.x, p.y, NULL); |
|
1950 |
} else { |
|
1951 |
LineTo(hDC, p.x, p.y); |
|
1952 |
/* |
|
1953 |
* end-point ... |
|
1954 |
*/ |
|
1955 |
LineTo(hDC, p.x+1, p.y); |
|
1956 |
} |
|
1957 |
} |
|
1958 |
SelectObject(hDC, prevPen); |
|
1959 |
DeleteObject(hPen); |
|
1960 |
RETURN ( self ); |
|
2323 | 1961 |
} |
1962 |
fail: ; |
|
1963 |
%} |
|
1964 |
! |
|
1965 |
||
1966 |
displayRectangleX:x y:y width:width height:height in:ignoredDrawableId with:aDC |
|
1967 |
"draw a rectangle. If the coordinates are not integers, an error is triggered." |
|
1968 |
||
1969 |
%{ |
|
1970 |
int w, h; |
|
1971 |
int xL, yT; |
|
1972 |
if (__isExternalAddressLike(aDC) |
|
1973 |
&& __bothSmallInteger(x, y) |
|
1974 |
&& __bothSmallInteger(width, height)) { |
|
1975 |
||
2342 | 1976 |
xL = __intVal(x); |
1977 |
yT = __intVal(y); |
|
1978 |
w = __intVal(width); |
|
1979 |
h = __intVal(height); |
|
1980 |
||
1981 |
DPRINTF(("displayRectangle: %d/%d -> %d/%d\n", xL, yT, w, h)); |
|
1982 |
||
1983 |
if ((w >= 0) && (h >= 0)) { |
|
1984 |
HANDLE hDC = (HANDLE)(__externalAddressVal(aDC)); |
|
1985 |
COLORREF fgColor; |
|
1986 |
HANDLE prevPen, hPen; |
|
1987 |
int lStyleSymbol, lStyleInt; |
|
1988 |
||
1989 |
int lw; |
|
1990 |
||
1991 |
lw= __intVal(__INST(lineWidth)); |
|
1992 |
lStyleSymbol= __INST(lineStyle); |
|
1993 |
||
1994 |
/* PS_DASH, PS_DOT, PS_DASHDOT, PS_DASHDOTDOT |
|
1995 |
only works with lineWidth = 1 */ |
|
1996 |
||
1997 |
if (lStyleSymbol == @symbol(solid)) { |
|
1998 |
lStyleInt= PS_SOLID; |
|
1999 |
} else if (lStyleSymbol == @symbol(dashed)) { |
|
2000 |
lStyleInt= PS_DASH; |
|
2001 |
} else if (lStyleSymbol == @symbol(dotted)) { |
|
2002 |
lStyleInt= PS_DOT; |
|
2003 |
} else if (lStyleSymbol == @symbol(dashDot)) { |
|
2004 |
lStyleInt= PS_DASHDOT; |
|
2005 |
} else if (lStyleSymbol == @symbol(dashDotDot)) { |
|
2006 |
lStyleInt= PS_DASHDOTDOT; |
|
2007 |
} else if (lStyleSymbol == @symbol(insideFrame)) { |
|
2008 |
lStyleInt= PS_INSIDEFRAME; |
|
2009 |
} else |
|
2010 |
lStyleInt= PS_SOLID; |
|
2011 |
||
2012 |
fgColor = GetTextColor(hDC); |
|
2013 |
hPen = CreatePen(lStyleInt, lw, fgColor); |
|
2014 |
||
2015 |
prevPen = SelectObject(hDC, hPen); |
|
2016 |
MoveToEx(hDC, xL, yT, NULL); |
|
2017 |
LineTo(hDC, xL+w, yT); // to top-right |
|
2018 |
LineTo(hDC, xL+w, yT+h); // to bot-right |
|
2019 |
MoveToEx(hDC, xL, yT, NULL); // back to top-left |
|
2020 |
LineTo(hDC, xL, yT+h); // to bot-left |
|
2021 |
// LineTo(hDC, xL+w+1, yT+h); // move pen one pixel more |
|
2022 |
LineTo(hDC, xL+w, yT+h); // move pen one pixel more |
|
2023 |
||
2024 |
SelectObject(hDC, prevPen); |
|
2025 |
DeleteObject(hPen); |
|
2026 |
||
2027 |
} |
|
2028 |
RETURN ( self ); |
|
2323 | 2029 |
} |
2030 |
%}. |
|
2031 |
self primitiveFailed |
|
2032 |
||
2033 |
"Created: / 28-07-2006 / 20:18:25 / fm" |
|
2034 |
! |
|
2035 |
||
2036 |
displayString:aString from:index1 to:index2 x:x y:y in:aDrawableId with:aGCId |
|
2037 |
"draw a sub-string - draw foreground only. |
|
2038 |
If the coordinates are not integers, retry with rounded." |
|
2039 |
||
2040 |
self |
|
2344 | 2041 |
displayString:aString |
2042 |
from:index1 |
|
2043 |
to:index2 |
|
2044 |
x:x |
|
2045 |
y:y |
|
2046 |
in:aDrawableId |
|
2047 |
with:aGCId |
|
2048 |
opaque:false |
|
2323 | 2049 |
! |
2050 |
||
2051 |
displayString:aString from:index1 to:index2 x:x y:y in:ignoredDrawableId with:aDC opaque:opaque |
|
2052 |
"draw a sub-string - if opaque is false, draw foreground only; otherwise, draw both |
|
2053 |
foreground and background characters. |
|
2054 |
If the coordinates are not integers, an error is triggered." |
|
2055 |
||
2056 |
%{ /* NOCONTEXT */ |
|
2057 |
unsigned char *cp; |
|
2058 |
OBJ cls; |
|
2059 |
int i1, i2, l, n; |
|
2060 |
int nInstBytes; |
|
2061 |
||
2062 |
if (__isExternalAddressLike(aDC) |
|
2063 |
&& __isNonNilObject(aString) |
|
2064 |
&& __bothSmallInteger(index1, index2) |
|
2065 |
&& __bothSmallInteger(x, y)) |
|
2066 |
{ |
|
2327 | 2067 |
HANDLE hDC = (HANDLE)(__externalAddressVal(aDC)); |
2068 |
int pX, pY; |
|
2069 |
COLORREF fgColor; |
|
2070 |
||
2071 |
pX = __intVal(x); |
|
2072 |
pY = __intVal(y); |
|
2073 |
||
2074 |
if (opaque == true) { |
|
2075 |
SetBkMode(hDC, OPAQUE); |
|
2076 |
} else { |
|
2077 |
SetBkMode(hDC, TRANSPARENT); |
|
2078 |
} |
|
2079 |
fgColor = GetTextColor(hDC); |
|
2080 |
SetTextColor(hDC, fgColor); |
|
2081 |
SetBkColor(hDC, 0xFFFFFFFF); |
|
2082 |
||
2083 |
cls = __qClass(aString); |
|
2084 |
||
2085 |
i1 = __intVal(index1) - 1; |
|
2086 |
if (i1 >= 0) { |
|
2087 |
i2 = __intVal(index2) - 1; |
|
2088 |
if (i2 < i1) { |
|
2089 |
goto ret; |
|
2090 |
} |
|
2091 |
||
2092 |
cp = _stringVal(aString); |
|
2093 |
l = i2 - i1 + 1; |
|
2094 |
||
2095 |
if ((cls == @global(String)) || (cls == @global(Symbol))) { |
|
2096 |
n = _stringSize(aString); |
|
2097 |
if (i2 < n) { |
|
2098 |
cp += i1; |
|
2099 |
DPRINTF(("string1: %s pos=%d/%d l=%d hDC=%x\n", cp, pX, pY,l,hDC)); |
|
2100 |
||
2101 |
if (l > 32767) { |
|
2102 |
l = 32767; |
|
2103 |
} |
|
2104 |
if (! TextOut(hDC, pX, pY, (char *)cp, l)) { |
|
2105 |
DFPRINTF((stderr, "WinPrinter [warning]: Textout failed. %d\n", GetLastError())); |
|
2106 |
} |
|
2107 |
goto ret; |
|
2108 |
} |
|
2109 |
} |
|
2110 |
||
2111 |
nInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
2112 |
cp += nInstBytes; |
|
2113 |
n = __byteArraySize(aString) - nInstBytes; |
|
2114 |
||
2115 |
if (__isBytes(aString)) { |
|
2116 |
if (i2 < n) { |
|
2117 |
cp += i1; |
|
2118 |
DPRINTF(("string: %s pos=%d/%d\n", cp, pX, pY)); |
|
2119 |
if (l > 32767) { |
|
2120 |
l = 32767; |
|
2121 |
} |
|
2122 |
if (! TextOut(hDC, pX, pY, (char *)cp, l)) { |
|
2123 |
DFPRINTF((stderr, "WinPrinter [warning]: Textout failed. %d\n", GetLastError())); |
|
2124 |
} |
|
2125 |
goto ret; |
|
2126 |
} |
|
2127 |
} |
|
2128 |
||
2129 |
/* Unicode */ |
|
2130 |
if (__isWords(aString)) { |
|
2131 |
n = n / 2; |
|
2132 |
if (i2 < n) { |
|
2133 |
WIDECHAR *w_cp = (WIDECHAR *)cp; |
|
2134 |
||
2135 |
w_cp += i1; |
|
2136 |
||
2137 |
if (! TextOutW(hDC, pX, pY, w_cp, l)) { |
|
2138 |
DFPRINTF((stderr, "WinPrinter [warning]: TextoutW failed. %d\n", GetLastError())); |
|
2139 |
} |
|
2140 |
goto ret; |
|
2141 |
} |
|
2142 |
} |
|
2143 |
} |
|
2323 | 2144 |
ret: |
2327 | 2145 |
RETURN ( self ); |
2323 | 2146 |
} |
2147 |
%}. |
|
2148 |
self primitiveFailed |
|
2149 |
||
2150 |
"Created: / 28-07-2006 / 20:35:19 / fm" |
|
2151 |
! |
|
2152 |
||
2153 |
displayString:aString from:index1 to:index2 x:x y:y in:ignoredDrawableId with:aDC opaque:opaque fontAscent:fontAscent |
|
2154 |
"draw a sub-string - if opaque is false, draw foreground only; otherwise, draw both |
|
2155 |
foreground and background characters. |
|
2156 |
If the coordinates are not integers, an error is triggered." |
|
2157 |
||
2158 |
%{ /* NOCONTEXT */ |
|
2159 |
unsigned char *cp; |
|
2160 |
OBJ cls; |
|
2161 |
int i1, i2, l, n; |
|
2162 |
int nInstBytes; |
|
2163 |
||
2164 |
if (__isExternalAddressLike(aDC) |
|
2165 |
&& __isNonNilObject(aString) |
|
2166 |
&& __bothSmallInteger(index1, index2) |
|
2167 |
&& __bothSmallInteger(x, y)) |
|
2168 |
{ |
|
2327 | 2169 |
HANDLE hDC = (HANDLE)(__externalAddressVal(aDC)); |
2170 |
int pX, pY; |
|
2171 |
COLORREF fgColor; |
|
2172 |
||
2173 |
pX = __intVal(x); |
|
2174 |
pY = __intVal(y); |
|
2175 |
pY -= __intVal(fontAscent); |
|
2176 |
||
2177 |
if (opaque == true) { |
|
2178 |
SetBkMode(hDC, OPAQUE); |
|
2179 |
} else { |
|
2180 |
SetBkMode(hDC, TRANSPARENT); |
|
2181 |
} |
|
2182 |
fgColor = GetTextColor(hDC); |
|
2183 |
SetTextColor(hDC, fgColor); |
|
2184 |
SetBkColor(hDC, 0xFFFFFFFF); |
|
2185 |
||
2186 |
cls = __qClass(aString); |
|
2187 |
||
2188 |
i1 = __intVal(index1) - 1; |
|
2189 |
if (i1 >= 0) { |
|
2190 |
i2 = __intVal(index2) - 1; |
|
2191 |
if (i2 < i1) { |
|
2192 |
goto ret; |
|
2193 |
} |
|
2194 |
||
2195 |
cp = _stringVal(aString); |
|
2196 |
l = i2 - i1 + 1; |
|
2197 |
||
2198 |
if ((cls == @global(String)) || (cls == @global(Symbol))) { |
|
2199 |
n = _stringSize(aString); |
|
2200 |
if (i2 < n) { |
|
2201 |
cp += i1; |
|
2202 |
DPRINTF(("string1: %s pos=%d/%d l=%d hDC=%x\n", cp, pX, pY,l,hDC)); |
|
2203 |
||
2204 |
if (l > 32767) { |
|
2205 |
l = 32767; |
|
2206 |
} |
|
2207 |
if (! TextOut(hDC, pX, pY, (char *)cp, l)) { |
|
2208 |
DFPRINTF((stderr, "WinPrinter [warning]: Textout failed. %d\n", GetLastError())); |
|
2209 |
} |
|
2210 |
goto ret; |
|
2211 |
} |
|
2212 |
} |
|
2213 |
||
2214 |
nInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
2215 |
cp += nInstBytes; |
|
2216 |
n = __byteArraySize(aString) - nInstBytes; |
|
2217 |
||
2218 |
if (__isBytes(aString)) { |
|
2219 |
if (i2 < n) { |
|
2220 |
cp += i1; |
|
2221 |
DPRINTF(("string: %s pos=%d/%d\n", cp, pX, pY)); |
|
2222 |
if (l > 32767) { |
|
2223 |
l = 32767; |
|
2224 |
} |
|
2225 |
if (! TextOut(hDC, pX, pY, (char *)cp, l)) { |
|
2226 |
DFPRINTF((stderr, "WinPrinter [warning]: Textout failed. %d\n", GetLastError())); |
|
2227 |
} |
|
2228 |
goto ret; |
|
2229 |
} |
|
2230 |
} |
|
2231 |
||
2232 |
/* Unicode */ |
|
2233 |
if (__isWords(aString)) { |
|
2234 |
n = n / 2; |
|
2235 |
if (i2 < n) { |
|
2236 |
WIDECHAR *w_cp = (WIDECHAR *)cp; |
|
2237 |
||
2238 |
w_cp += i1; |
|
2239 |
||
2240 |
if (! TextOutW(hDC, pX, pY, w_cp, l)) { |
|
2241 |
DFPRINTF((stderr, "WinPrinter [warning]: TextoutW failed. %d\n", GetLastError())); |
|
2242 |
} |
|
2243 |
goto ret; |
|
2244 |
} |
|
2245 |
} |
|
2246 |
} |
|
2323 | 2247 |
ret: |
2327 | 2248 |
RETURN ( self ); |
2323 | 2249 |
} |
2250 |
%}. |
|
2251 |
self primitiveFailed |
|
2252 |
||
2253 |
"Created: / 28-07-2006 / 20:35:19 / fm" |
|
2254 |
! |
|
2255 |
||
2256 |
displayString:aString x:x y:y in:aDrawableId with:aDC |
|
2257 |
"draw a string - draw foreground only. |
|
2258 |
If the coordinates are not integers, retry with rounded." |
|
2259 |
||
2260 |
self |
|
2344 | 2261 |
displayString:aString |
2262 |
x:x |
|
2263 |
y:y |
|
2264 |
in:aDrawableId |
|
2265 |
with:aDC |
|
2266 |
opaque:false |
|
2323 | 2267 |
! |
2268 |
||
2269 |
displayString:aString x:x y:y in:aDrawableId with:aDC opaque:opaque |
|
2270 |
"draw a string" |
|
2271 |
||
2272 |
self displayString:aString |
|
2344 | 2273 |
from:1 |
2274 |
to:aString size |
|
2275 |
x:x |
|
2276 |
y:y |
|
2277 |
in:aDrawableId |
|
2278 |
with:aDC |
|
2279 |
opaque:opaque |
|
2323 | 2280 |
! |
2281 |
||
2282 |
fillArcX:x y:y width:width height:height from:startAngle angle:angle |
|
2330 | 2283 |
in:ignoredDrawableId with:aDC |
2323 | 2284 |
"fill an arc. If any coordinate is not integer, an error is triggered. |
2285 |
The angles may be floats or integer - they are given in degrees." |
|
2286 |
||
2330 | 2287 |
| hatchSymbol | |
2288 |
||
2289 |
hatchSymbol := self hatch. |
|
2290 |
||
2323 | 2291 |
%{ |
2292 |
int __x, __y, w, h; |
|
2293 |
float angle1, angle2; |
|
2294 |
||
2295 |
if (__isSmallInteger(startAngle)) |
|
2330 | 2296 |
angle1 = (float)(__intVal(startAngle)); |
2323 | 2297 |
else if (__isFloat(startAngle)) { |
2330 | 2298 |
angle1 = __floatVal(startAngle); |
2323 | 2299 |
} else if (__isShortFloat(startAngle)) { |
2330 | 2300 |
angle1 = __shortFloatVal(startAngle); |
2323 | 2301 |
} else goto bad; |
2302 |
||
2303 |
if (__isSmallInteger(angle)) |
|
2330 | 2304 |
angle2 = (float)(__intVal(angle)); |
2323 | 2305 |
else if (__isFloat(angle)) { |
2330 | 2306 |
angle2 = __floatVal(angle); |
2323 | 2307 |
} else if (__isShortFloat(angle)) { |
2330 | 2308 |
angle2 = __shortFloatVal(angle); |
2323 | 2309 |
} else goto bad; |
2310 |
||
2311 |
if (angle2 <= 0) { |
|
2330 | 2312 |
RETURN (self); |
2323 | 2313 |
} |
2314 |
||
2315 |
if (__isExternalAddressLike(aDC) |
|
2316 |
&& __bothSmallInteger(x, y) |
|
2317 |
&& __bothSmallInteger(width, height)) |
|
2318 |
{ |
|
2330 | 2319 |
HANDLE hDC = (HANDLE)(__externalAddressVal(aDC)); |
2320 |
HBRUSH hBrush, prevBrush; |
|
2321 |
HPEN prevPen = 0; |
|
2322 |
COLORREF fgColor; |
|
2323 |
int hatch, hasHatch; |
|
2324 |
||
2325 |
w = __intVal(width); |
|
2326 |
h = __intVal(height); |
|
2327 |
__x = __intVal(x); |
|
2328 |
__y = __intVal(y); |
|
2329 |
||
2330 |
fgColor = GetTextColor(hDC); |
|
2331 |
||
2332 |
hasHatch= 1; |
|
2333 |
||
2334 |
if (hatchSymbol == @symbol(none)) { |
|
2335 |
hasHatch= 0; |
|
2336 |
} else if (hatchSymbol == @symbol(horizontal)) { |
|
2337 |
hatch= HS_HORIZONTAL; |
|
2338 |
} else if (hatchSymbol == @symbol(vertical)) { |
|
2339 |
hatch= HS_VERTICAL; |
|
2340 |
} else if (hatchSymbol == @symbol(cross)) { |
|
2341 |
hatch= HS_CROSS; |
|
2342 |
} else if (hatchSymbol == @symbol(bDiagonal)) { |
|
2343 |
hatch= HS_BDIAGONAL; |
|
2344 |
} else if (hatchSymbol == @symbol(fDiagonal)) { |
|
2345 |
hatch= HS_FDIAGONAL; |
|
2346 |
} else if (hatchSymbol == @symbol(diagonalCross)) { |
|
2347 |
hatch= HS_DIAGCROSS; |
|
2348 |
} else |
|
2349 |
hasHatch= 0; |
|
2350 |
||
2351 |
if (hasHatch) { |
|
2352 |
hBrush = CreateHatchBrush(hatch, fgColor); |
|
2353 |
} else { |
|
2354 |
hBrush = CreateSolidBrush(fgColor); |
|
2355 |
} |
|
2356 |
||
2357 |
prevBrush = SelectObject(hDC, hBrush); |
|
2358 |
if (hBrush == 0) { |
|
2359 |
DPRINTF(("fillArc: no brush\n")); |
|
2360 |
} else { |
|
2361 |
HPEN hPen = 0; |
|
2362 |
||
2363 |
if (0 /* __isWinNT */) { |
|
2364 |
fgColor = GetTextColor(hDC); |
|
2365 |
hPen = CreatePen(PS_SOLID, 1, fgColor); |
|
2366 |
prevPen = SelectObject(hDC, hPen); |
|
2367 |
if (hPen == 0) { |
|
2368 |
DPRINTF(("fillArc: no pen\n")); |
|
2369 |
goto failpen; |
|
2370 |
} |
|
2371 |
} else { |
|
2372 |
prevPen = SelectObject(hDC, GetStockObject(NULL_PEN)); |
|
2373 |
w++; |
|
2374 |
h++; |
|
2375 |
} |
|
2376 |
||
2377 |
{ |
|
2378 |
double xB, yB, xE, yE, xR, yR; |
|
2379 |
||
2380 |
xR = w / 2; |
|
2381 |
yR = h / 2; |
|
2382 |
if (angle2 - angle1 >= 360) { |
|
2383 |
xB = xE = __x + xR + 0.5; |
|
2384 |
yB = yE = __y /*+ yR + 0.5*/; |
|
2385 |
} else { |
|
2386 |
double sin(), cos(); |
|
2387 |
float rad1, rad2; |
|
2388 |
||
2389 |
if (angle1 <= 180) |
|
2390 |
angle1 = 180 - angle1; |
|
2391 |
else |
|
2392 |
angle1 = 360 + 180 - angle1; |
|
2393 |
angle2 = angle1 - angle2; |
|
2394 |
/* sigh - compute the intersections ... */ |
|
2395 |
rad1 = (angle1 * 3.14159265359) / 180.0; |
|
2396 |
rad2 = (angle2 * 3.14159265359) / 180.0; |
|
2397 |
xB = cos(rad1) * xR; |
|
2398 |
yB = sin(rad1) * yR; |
|
2399 |
xE = cos(rad2) * xR; |
|
2400 |
yE = sin(rad2) * yR; |
|
2401 |
xB = __x + xR - xB + 0.5; |
|
2402 |
yB = __y + yR - yB + 0.5; |
|
2403 |
xE = __x + xR - xE + 0.5; |
|
2404 |
yE = __y + yR - yE + 0.5; |
|
2405 |
} |
|
2406 |
DPRINTF(("fillArc x=%d y=%d w=%d h=%d xB=%d xE=%d yB=%d yE=%d a1=%f a2=%f\n",__x,__y,w,h,(int)xB,(int)xE,(int)yB,(int)yE,angle1,angle2)); |
|
2407 |
||
2408 |
Pie(hDC, |
|
2409 |
__x, __y, |
|
2410 |
__x + w + 1, __y + h + 1, |
|
2411 |
(int)xB, (int)yB, |
|
2412 |
(int)xE, (int)yE); |
|
2413 |
||
2414 |
if (hPen) { |
|
2415 |
DeleteObject(hPen); |
|
2416 |
} |
|
2417 |
} |
|
2323 | 2418 |
failpen: |
2330 | 2419 |
if (prevPen) SelectObject(hDC, prevPen); |
2420 |
DeleteObject(hPen); |
|
2421 |
||
2422 |
SelectObject(hDC, prevBrush); |
|
2423 |
DeleteObject(hBrush); |
|
2424 |
} |
|
2425 |
RETURN ( self ); |
|
2323 | 2426 |
} |
2427 |
bad: ; |
|
2428 |
%}. |
|
2429 |
self primitiveFailed |
|
2430 |
! |
|
2431 |
||
2432 |
fillPolygon:aPolygon in:ignoredDrawableId with:aGCId |
|
2433 |
"fill a polygon given by its points. |
|
2434 |
If any coordinate is not integer, an error is triggered." |
|
2435 |
||
2436 |
|numberOfPoints| |
|
2437 |
||
2438 |
numberOfPoints := aPolygon size. |
|
2439 |
self |
|
2344 | 2440 |
primFillPolygon:aPolygon n:numberOfPoints |
2441 |
in:ignoredDrawableId with:aGCId |
|
2323 | 2442 |
! |
2443 |
||
2444 |
fillRectangleX:x y:y width:width height:height in:ignoredDrawableId with:aDC |
|
2445 |
"fill a rectangle. If any coordinate is not integer, an error is triggered." |
|
2446 |
||
2330 | 2447 |
|hatchSymbol| |
2448 |
||
2449 |
hatchSymbol := self hatch. |
|
2450 |
||
2323 | 2451 |
%{ /* NOCONTEXT */ |
2452 |
||
2453 |
int w, h; |
|
2454 |
if (__isExternalAddressLike(aDC) |
|
2455 |
&& __bothSmallInteger(x, y) |
|
2456 |
&& __bothSmallInteger(width, height)) { |
|
2326 | 2457 |
w = __intVal(width); |
2458 |
h = __intVal(height); |
|
2459 |
||
2460 |
if ((w >= 0) && (h >= 0)) { |
|
2461 |
HANDLE hDC = (HANDLE)(__externalAddressVal(aDC)); |
|
2462 |
HBRUSH hBrush, prevBrush; |
|
2463 |
RECT rct; |
|
2464 |
COLORREF fgColor; |
|
2330 | 2465 |
int hatch, hasHatch; |
2326 | 2466 |
|
2467 |
fgColor = GetTextColor(hDC); |
|
2330 | 2468 |
hasHatch= 1; |
2469 |
||
2470 |
if (hatchSymbol == @symbol(none)) { |
|
2471 |
hasHatch= 0; |
|
2472 |
} else if (hatchSymbol == @symbol(horizontal)) { |
|
2473 |
hatch= HS_HORIZONTAL; |
|
2474 |
} else if (hatchSymbol == @symbol(vertical)) { |
|
2475 |
hatch= HS_VERTICAL; |
|
2476 |
} else if (hatchSymbol == @symbol(cross)) { |
|
2477 |
hatch= HS_CROSS; |
|
2478 |
} else if (hatchSymbol == @symbol(bDiagonal)) { |
|
2479 |
hatch= HS_BDIAGONAL; |
|
2480 |
} else if (hatchSymbol == @symbol(fDiagonal)) { |
|
2481 |
hatch= HS_FDIAGONAL; |
|
2482 |
} else if (hatchSymbol == @symbol(diagonalCross)) { |
|
2483 |
hatch= HS_DIAGCROSS; |
|
2484 |
} else |
|
2485 |
hasHatch= 0; |
|
2486 |
||
2487 |
if (hasHatch) { |
|
2488 |
hBrush = CreateHatchBrush(hatch, fgColor); |
|
2489 |
} else { |
|
2490 |
hBrush = CreateSolidBrush(fgColor); |
|
2491 |
} |
|
2492 |
||
2326 | 2493 |
rct.left = __intVal(x); |
2494 |
rct.top = __intVal(y); |
|
2342 | 2495 |
rct.right = rct.left + w; // + 1; |
2496 |
rct.bottom = rct.top + h; // + 1; |
|
2326 | 2497 |
|
2498 |
prevBrush = SelectObject(hDC, hBrush); |
|
2499 |
FillRect(hDC, &rct, hBrush); |
|
2500 |
SelectObject(hDC, prevBrush); |
|
2501 |
DeleteObject(hBrush); |
|
2502 |
||
2503 |
} |
|
2504 |
} |
|
2505 |
RETURN ( self ); |
|
2327 | 2506 |
|
2507 |
||
2323 | 2508 |
%} |
2509 |
! |
|
2510 |
||
2511 |
primFillPolygon:aPolygon n:numberOfPoints in:ignoredDrawableId with:aDC |
|
2512 |
||
2330 | 2513 |
|hatchSymbol| |
2514 |
||
2515 |
hatchSymbol := self hatch. |
|
2516 |
||
2323 | 2517 |
%{ |
2518 |
OBJ point, px, py; |
|
2519 |
int i, num; |
|
2520 |
||
2521 |
if (__isExternalAddressLike(aDC) |
|
2522 |
&& __isSmallInteger(numberOfPoints)) { |
|
2330 | 2523 |
HANDLE hDC = (HANDLE)(__externalAddressVal(aDC)); |
2524 |
POINT p; |
|
2525 |
HBRUSH hBrush, prevBrush; |
|
2526 |
COLORREF fgColor; |
|
2527 |
int hatch, hasHatch; |
|
2528 |
||
2529 |
num = __intVal(numberOfPoints); |
|
2530 |
if (num < 3) { |
|
2531 |
RETURN ( self ); |
|
2532 |
} |
|
2533 |
for (i=0; i<num; i++) { |
|
2534 |
point = __AT_(aPolygon, __MKSMALLINT(i+1)); |
|
2535 |
if (! __isPoint(point)) goto fail; |
|
2536 |
px = _point_X(point); |
|
2537 |
py = _point_Y(point); |
|
2538 |
if (! __bothSmallInteger(px, py)) |
|
2539 |
goto fail; |
|
2540 |
} |
|
2541 |
||
2542 |
fgColor = GetTextColor(hDC); |
|
2543 |
hasHatch= 1; |
|
2544 |
||
2545 |
if (hatchSymbol == @symbol(none)) { |
|
2546 |
hasHatch= 0; |
|
2547 |
} else if (hatchSymbol == @symbol(horizontal)) { |
|
2548 |
hatch= HS_HORIZONTAL; |
|
2549 |
} else if (hatchSymbol == @symbol(vertical)) { |
|
2550 |
hatch= HS_VERTICAL; |
|
2551 |
} else if (hatchSymbol == @symbol(cross)) { |
|
2552 |
hatch= HS_CROSS; |
|
2553 |
} else if (hatchSymbol == @symbol(bDiagonal)) { |
|
2554 |
hatch= HS_BDIAGONAL; |
|
2555 |
} else if (hatchSymbol == @symbol(fDiagonal)) { |
|
2556 |
hatch= HS_FDIAGONAL; |
|
2557 |
} else if (hatchSymbol == @symbol(diagonalCross)) { |
|
2558 |
hatch= HS_DIAGCROSS; |
|
2559 |
} else |
|
2560 |
hasHatch= 0; |
|
2561 |
||
2562 |
if (hasHatch) { |
|
2563 |
hBrush = CreateHatchBrush(hatch, fgColor); |
|
2564 |
} else { |
|
2565 |
hBrush = CreateSolidBrush(fgColor); |
|
2566 |
} |
|
2567 |
||
2568 |
if (hBrush == 0) { |
|
2569 |
DPRINTF(("fillPolygon: no brush\n")); |
|
2570 |
} else { |
|
2571 |
HPEN prevPen; |
|
2572 |
||
2573 |
prevBrush = SelectObject(hDC, hBrush); |
|
2574 |
prevPen = SelectObject(hDC, GetStockObject(NULL_PEN)); |
|
2575 |
||
2576 |
BeginPath(hDC); |
|
2577 |
||
2578 |
for (i=0; i<num; i++) { |
|
2579 |
point = __AT_(aPolygon, __MKSMALLINT(i+1)); |
|
2580 |
px = _point_X(point); |
|
2581 |
py = _point_Y(point); |
|
2582 |
if (i == 0) { |
|
2583 |
MoveToEx(hDC, __intVal(px), __intVal(py), NULL); |
|
2584 |
} else { |
|
2585 |
if (i == (num-1)) { |
|
2586 |
p.x = __intVal(px); |
|
2587 |
p.y = __intVal(py); |
|
2588 |
PolylineTo(hDC, &p, 1); |
|
2589 |
} else { |
|
2590 |
LineTo(hDC, __intVal(px), __intVal(py)); |
|
2591 |
} |
|
2592 |
} |
|
2593 |
} |
|
2594 |
||
2595 |
EndPath(hDC); |
|
2596 |
FillPath(hDC); |
|
2597 |
SelectObject(hDC, prevPen); |
|
2598 |
SelectObject(hDC, prevBrush); |
|
2599 |
DeleteObject(hBrush); |
|
2600 |
} |
|
2601 |
RETURN ( self ); |
|
2323 | 2602 |
|
2603 |
fail: ; |
|
2604 |
} |
|
2605 |
%} |
|
2343 | 2606 |
! |
2607 |
||
2608 |
scaleTest_displayString:aString x:x y:y |
|
2609 |
"draw a string at the coordinate x/y - |
|
2610 |
draw foreground-pixels only (in current paint-color), |
|
2611 |
leaving background as-is. If the transformation involves scaling, |
|
2612 |
the fonts point-size is scaled as appropriate." |
|
2613 |
||
2614 |
|id pX pY fontUsed sz s fontsEncoding| |
|
2615 |
||
2616 |
"hook for non-strings (i.e. attributed text)" |
|
2617 |
(aString isString not |
|
2618 |
or:[aString isText]) ifTrue:[ |
|
2619 |
^ aString displayOn:self x:x y:y |
|
2620 |
]. |
|
2621 |
||
2622 |
gcId isNil ifTrue:[ |
|
2623 |
self initGC |
|
2624 |
]. |
|
2625 |
||
2626 |
fontUsed := font. |
|
2627 |
transformation notNil ifTrue:[ |
|
2628 |
pX := transformation applyToX:x. |
|
2629 |
pY := transformation applyToY:y. |
|
2630 |
transformation noScale ifFalse:[ |
|
2631 |
sz := font size. |
|
2632 |
sz isNil ifTrue:[ |
|
2633 |
"/ oops - not a real font; use original font |
|
2634 |
fontUsed := font |
|
2635 |
] ifFalse:[ |yS| |
|
2636 |
yS := self pixelsPerInchOfScreenHeight / Screen current verticalPixelPerInch. |
|
2637 |
yS := self scale y / yS. |
|
2638 |
fontUsed := font size:(sz * yS) rounded. |
|
2639 |
] |
|
2640 |
] |
|
2641 |
] ifFalse:[ |
|
2642 |
pX := x. |
|
2643 |
pY := y. |
|
2644 |
]. |
|
2645 |
pX := pX rounded. |
|
2646 |
pY := pY rounded. |
|
2647 |
||
2648 |
s := aString. |
|
2649 |
fontUsed := fontUsed onDevice:device. |
|
2650 |
fontsEncoding := fontUsed encoding. |
|
2651 |
(characterEncoding ~~ fontsEncoding) ifTrue:[ |
|
2652 |
[ |
|
2653 |
s := CharacterEncoder encodeString:s from:characterEncoding into:fontsEncoding. |
|
2654 |
] on:CharacterEncoderError do:[:ex| |
|
2655 |
"substitute a default value for codes that cannot be represented |
|
2656 |
in the new character set" |
|
2657 |
ex proceedWith:ex defaultValue. |
|
2658 |
]. |
|
2659 |
]. |
|
2660 |
||
2661 |
id := fontUsed fontId. |
|
2662 |
id isNil ifTrue:[ |
|
2663 |
"hook for alien fonts" |
|
2664 |
fontUsed displayString:s x:x y:y in:self |
|
2665 |
] ifFalse:[ |
|
2666 |
deviceFont ~~ fontUsed ifTrue:[ |
|
2667 |
device setFont:id in:gcId. |
|
2668 |
deviceFont := fontUsed |
|
2669 |
]. |
|
2670 |
device displayString:s x:pX y:pY in:drawableId with:gcId |
|
2671 |
] |
|
2672 |
||
2673 |
"Modified: 1.7.1997 / 17:08:35 / cg" |
|
2323 | 2674 |
! ! |
2675 |
||
2676 |
!WinPrinterContext methodsFor:'drawing bitmaps'! |
|
2677 |
||
2678 |
bitsBlue |
|
2679 |
"return the number of valid bits in the red component." |
|
2680 |
||
2681 |
"/ bitsRed isNil ifTrue:[ |
|
2682 |
"/ "/ not a truecolor display |
|
2683 |
"/ ^ bitsPerRGB |
|
2684 |
"/ ]. |
|
2685 |
"/ ^ bitsRed |
|
2686 |
||
2687 |
^Display bitsBlue |
|
2688 |
! |
|
2689 |
||
2690 |
bitsGreen |
|
2691 |
"return the number of valid bits in the red component." |
|
2692 |
||
2693 |
"/ bitsRed isNil ifTrue:[ |
|
2694 |
"/ "/ not a truecolor display |
|
2695 |
"/ ^ bitsPerRGB |
|
2696 |
"/ ]. |
|
2697 |
"/ ^ bitsRed |
|
2698 |
||
2699 |
^Display bitsGreen |
|
2700 |
! |
|
2701 |
||
2702 |
bitsRed |
|
2703 |
"return the number of valid bits in the red component." |
|
2704 |
||
2705 |
"/ bitsRed isNil ifTrue:[ |
|
2706 |
"/ "/ not a truecolor display |
|
2707 |
"/ ^ bitsPerRGB |
|
2708 |
"/ ]. |
|
2709 |
"/ ^ bitsRed |
|
2710 |
||
2711 |
^Display bitsRed |
|
2712 |
! |
|
2713 |
||
2338 | 2714 |
compressColorMapImage: image |
2715 |
"calculates a new color map for the image, using only used colors" |
|
2716 |
||
2717 |
|depth newColorMap newImage oldImage usedColors oldToNew oldBits newBits tmpBits| |
|
2718 |
||
2719 |
oldImage := image. |
|
2720 |
depth := oldImage depth. |
|
2721 |
||
2722 |
oldImage photometric ~~ #palette ifTrue:[ |
|
2723 |
Transcript showCR:'Compress colorMap: Only palette images have colormaps.'. |
|
2724 |
^ image |
|
2725 |
]. |
|
2726 |
||
2727 |
usedColors := oldImage realUsedColors. |
|
2728 |
usedColors size == (1 bitShift:depth) ifTrue:[ |
|
2729 |
Transcript showCR:'Compress colorMap: All colors are used - no compression.'. |
|
2730 |
^ image |
|
2731 |
]. |
|
2732 |
usedColors size == oldImage colorMap size ifTrue:[ |
|
2733 |
Transcript showCR:'Compress colorMap: Colormap already compressed - no compression.'. |
|
2734 |
^ image |
|
2735 |
]. |
|
2736 |
||
2737 |
"/ translation table |
|
2738 |
oldToNew := ByteArray new:(1 bitShift:depth). |
|
2739 |
newColorMap := usedColors asArray. |
|
2740 |
newColorMap sort:self sortBlockForColors. |
|
2741 |
||
2742 |
oldImage colorMap asArray keysAndValuesDo:[:oldIdx :clr | |
|
2743 |
|newPixel| |
|
2744 |
||
2745 |
(usedColors includes:clr) ifTrue:[ |
|
2746 |
newPixel := newColorMap indexOf:clr. |
|
2747 |
oldToNew at:oldIdx put:newPixel-1. |
|
2748 |
] |
|
2749 |
]. |
|
2750 |
||
2751 |
oldBits := oldImage bits. |
|
2752 |
newBits := ByteArray new:(oldBits size). |
|
2753 |
depth ~~ 8 ifTrue:[ |
|
2754 |
"/ expand/compress can only handle 8bits |
|
2755 |
tmpBits := ByteArray uninitializedNew:(oldImage width*oldImage height). |
|
2756 |
oldBits |
|
2757 |
expandPixels:depth |
|
2758 |
width:oldImage width |
|
2759 |
height:oldImage height |
|
2760 |
into:tmpBits |
|
2761 |
mapping:oldToNew. |
|
2762 |
tmpBits |
|
2763 |
compressPixels:depth |
|
2764 |
width:oldImage width |
|
2765 |
height:oldImage height |
|
2766 |
into:newBits |
|
2767 |
mapping:nil |
|
2768 |
] ifFalse:[ |
|
2769 |
oldBits |
|
2770 |
expandPixels:depth |
|
2771 |
width:oldImage width |
|
2772 |
height:oldImage height |
|
2773 |
into:newBits |
|
2774 |
mapping:oldToNew. |
|
2775 |
]. |
|
2776 |
||
2777 |
newImage := oldImage species new |
|
2778 |
width:oldImage width |
|
2779 |
height:oldImage height |
|
2780 |
depth:depth |
|
2781 |
fromArray:newBits. |
|
2782 |
||
2783 |
newImage colorMap:newColorMap. |
|
2784 |
newImage fileName:oldImage fileName. |
|
2785 |
newImage mask:(oldImage mask copy). |
|
2786 |
||
2787 |
^ newImage |
|
2788 |
||
2789 |
"Created: / 28.7.1998 / 20:03:11 / cg" |
|
2790 |
"Modified: / 15.9.1998 / 17:53:32 / cg" |
|
2791 |
! |
|
2792 |
||
2323 | 2793 |
copyFromId:sourceId x:srcX y:srcY gc:srcGCId to:destId x:dstX y:dstY gc:dstGCId |
2338 | 2794 |
width:w height:h |
2323 | 2795 |
"do a bit-blt; copy bits from the rectangle defined by |
2796 |
srcX/srcY and w/h from the sourceId drawable to the rectangle |
|
2797 |
below dstX/dstY in the destId drawable. Trigger an error if any |
|
2798 |
argument is not integer." |
|
2799 |
||
2800 |
%{ |
|
2801 |
int dstGcOwnerThreadID; |
|
2802 |
HWND dstGcHWIN; |
|
2803 |
HBITMAP dstGcHBITMAP; |
|
2804 |
||
2805 |
if (! __isExternalAddressLike(srcGCId) |
|
2806 |
|| ! __isExternalAddressLike(dstGCId)) { |
|
2338 | 2807 |
goto fail; |
2323 | 2808 |
} |
2809 |
||
2810 |
if (__bothSmallInteger(w, h) |
|
2811 |
&& __bothSmallInteger(srcX, srcY) |
|
2812 |
&& __bothSmallInteger(dstX, dstY)) { |
|
2338 | 2813 |
HANDLE srcDC = (HANDLE)(__externalAddressVal(srcGCId)); |
2814 |
HANDLE dstDC = (HANDLE)(__externalAddressVal(dstGCId)); |
|
2815 |
||
2816 |
int fun, aFunctionSymbol; |
|
2817 |
int src_fg, src_bg, dst_fg, dst_bg; |
|
2818 |
char buf[5]; |
|
2323 | 2819 |
|
2820 |
// fun = dstGcData->bitbltrop2; |
|
2821 |
||
2338 | 2822 |
aFunctionSymbol= __INST(function); |
2823 |
||
2824 |
if (aFunctionSymbol == @symbol(copy)) { |
|
2825 |
fun = SRCCOPY /* R2_COPYPEN */ ; |
|
2323 | 2826 |
/* bfun = BITBLT_COPY; */ |
2338 | 2827 |
} else if (aFunctionSymbol == @symbol(copyInverted)) { |
2828 |
fun = NOTSRCCOPY /* R2_NOTCOPYPEN */; |
|
2323 | 2829 |
/* bfun = BITBLT_COPYINVERTED; */ |
2338 | 2830 |
} else if (aFunctionSymbol == @symbol(xor)) { |
2831 |
fun = SRCINVERT /* R2_XORPEN */; |
|
2323 | 2832 |
/* bfun = BITBLT_XOR; */ |
2338 | 2833 |
} else if (aFunctionSymbol == @symbol(and)) { |
2834 |
fun = SRCAND /* R2_MASKPEN */ ; |
|
2323 | 2835 |
/* bfun = BITBLT_AND; */ |
2338 | 2836 |
} else if (aFunctionSymbol == @symbol(or)) { |
2837 |
fun = MERGECOPY /* R2_MERGEPEN */ ; |
|
2323 | 2838 |
/* bfun = BITBLT_OR; */ |
2338 | 2839 |
} |
2323 | 2840 |
|
2841 |
// convert 123 to string [buf] |
|
2324 | 2842 |
// itoa(fun, buf, 10); |
2843 |
||
2844 |
// console_printf(" ", buf); |
|
2323 | 2845 |
|
2846 |
/* |
|
2847 |
#if 0 |
|
2338 | 2848 |
switch (fun) { |
2849 |
case BITBLT_COPY: |
|
2850 |
console_printf("BITBLT_COPY\n"); |
|
2851 |
break; |
|
2852 |
case BITBLT_COPYINVERTED: |
|
2853 |
console_printf("BITBLT_COPYINVERTED\n"); |
|
2854 |
break; |
|
2855 |
case BITBLT_XOR: |
|
2856 |
console_printf("BITBLT_XOR\n"); |
|
2857 |
break; |
|
2858 |
case BITBLT_AND: |
|
2859 |
console_printf("BITBLT_AND\n"); |
|
2860 |
break; |
|
2861 |
case BITBLT_OR: |
|
2862 |
console_printf("BITBLT_OR\n"); |
|
2863 |
break; |
|
2864 |
} |
|
2323 | 2865 |
#endif |
2866 |
*/ |
|
2867 |
||
2868 |
// fun = dstGcData->bitbltrop2; |
|
2869 |
||
2338 | 2870 |
if (0 /* fun == BITBLT_COPY */) { |
2871 |
src_fg = dst_fg = 0xFFFFFF; |
|
2872 |
src_bg = dst_bg = 0x000000; |
|
2873 |
} else { |
|
2874 |
src_fg = GetTextColor(srcDC) /* srcGcData->fgColor */; |
|
2875 |
src_bg = GetBkColor(dstDC) /* srcGcData->bgColor */; |
|
2876 |
dst_fg = GetTextColor(srcDC) /* dstGcData->fgColor */; |
|
2877 |
dst_bg = GetBkColor(dstDC) /* dstGcData->bgColor */; |
|
2878 |
} |
|
2879 |
||
2880 |
SetBkColor(dstDC, dst_fg); |
|
2881 |
SetTextColor(dstDC, dst_bg); |
|
2882 |
||
2883 |
SetBkColor(srcDC, src_fg); |
|
2884 |
SetTextColor(srcDC, src_bg); |
|
2323 | 2885 |
|
2886 |
/* |
|
2338 | 2887 |
CPRINTF(("bitblt src f:%x b:%x",GetTextColor(srcDC),GetBkColor(srcDC))); |
2888 |
CPRINTF(("dst f:%x b:%x\n",GetTextColor(dstDC),GetBkColor(dstDC))); |
|
2323 | 2889 |
*/ |
2338 | 2890 |
if (BitBlt(dstDC, |
2891 |
__intVal(dstX), __intVal(dstY), |
|
2892 |
__intVal(w), __intVal(h), |
|
2893 |
srcDC, |
|
2894 |
__intVal(srcX), __intVal(srcY), |
|
2895 |
fun) |
|
2896 |
== 0 |
|
2897 |
) { |
|
2898 |
console_fprintf(stderr, "WinWorkstation [info]: ERROR in BitBlt\n"); |
|
2899 |
} |
|
2323 | 2900 |
|
2901 |
/* |
|
2338 | 2902 |
if (dstGcData != srcGcData) { |
2903 |
SetBkColor(dstDC, dstGcData->bgColor); |
|
2904 |
SetTextColor(dstDC, dstGcData->fgColor); |
|
2905 |
} |
|
2906 |
SetBkColor(srcDC, srcGcData->bgColor); |
|
2907 |
SetTextColor(srcDC, srcGcData->fgColor); |
|
2323 | 2908 |
*/ |
2909 |
||
2910 |
/* |
|
2338 | 2911 |
if (srcGcData != dstGcData) { |
2912 |
_releaseDC(srcGcData); |
|
2913 |
} |
|
2914 |
_releaseDC(dstGcData); |
|
2323 | 2915 |
*/ |
2338 | 2916 |
RETURN ( self ); |
2323 | 2917 |
} |
2918 |
||
2919 |
fail: ; |
|
2920 |
%}. |
|
2921 |
self primitiveFailed. |
|
2922 |
^ nil |
|
2923 |
! |
|
2924 |
||
2925 |
copyFromPixmapId:sourceId x:srcX y:srcY gc:srcGCId to:destId x:dstX y:dstY gc:dstGCId width:w height:h |
|
2926 |
"do a bit-blt from a pix- or bitmap. |
|
2927 |
Here, fall back into copyFromId:, which should also work. |
|
2928 |
Subclasses may redefine this for more performance or if required" |
|
2929 |
||
2930 |
^ self copyFromId:sourceId x:srcX y:srcY gc:srcGCId to:destId x:dstX y:dstY gc:dstGCId width:w height:h |
|
2931 |
! |
|
2932 |
||
2933 |
copyPlaneFromId:sourceId x:srcX y:srcY gc:srcDCId to:destId x:dstX y:dstY gc:dstDCId |
|
2344 | 2934 |
width:w height:h |
2323 | 2935 |
"do a bit-blt, but only copy the low-bit plane; |
2936 |
copy bits from the rectangle defined by |
|
2937 |
srcX/srcY and w/h from the sourceId drawable to the rectangle |
|
2938 |
below dstX/dstY in the destId drawable. Trigger an error if any |
|
2939 |
argument is not integer." |
|
2940 |
||
2941 |
^ self |
|
2344 | 2942 |
copyFromId:sourceId |
2943 |
x:srcX y:srcY gc:srcDCId |
|
2944 |
to:destId x:dstX y:dstY gc:dstDCId |
|
2945 |
width:w height:h |
|
2323 | 2946 |
! |
2947 |
||
2948 |
copyPlaneFromPixmapId:sourceId x:srcX y:srcY gc:srcGCId to:destId x:dstX y:dstY gc:dstGCId width:w height:h |
|
2949 |
"do a bit-blt from a pix- or bitmap, using the low-bit plane of the source only. |
|
2950 |
Here, fall back into copyPlaneFromId:, which should also work. |
|
2951 |
Subclasses may redefine this for more performance or if required" |
|
2952 |
||
2953 |
^ self copyPlaneFromId:sourceId x:srcX y:srcY gc:srcGCId to:destId x:dstX y:dstY gc:dstGCId width:w height:h |
|
2954 |
! |
|
2955 |
||
2956 |
createBitmapFromArray:anArray width:w height:h |
|
2957 |
|bitmapId| |
|
2958 |
||
2325 | 2959 |
|
2323 | 2960 |
bitmapId := self primCreateBitmapFromArray:anArray width:w height:h. |
2961 |
||
2962 |
bitmapId isNil ifTrue:[ |
|
2344 | 2963 |
'WINWORKSTATION: cannot create bitmap' errorPrintCR. |
2323 | 2964 |
]. |
2965 |
^ bitmapId |
|
2966 |
! |
|
2967 |
||
2324 | 2968 |
createPixmapWidth:w height:h depth:d |
2969 |
"allocate a pixmap on the Xserver, the contents is undefined |
|
2970 |
(i.e. random). Return a bitmap id or nil" |
|
2971 |
||
2972 |
%{ |
|
2973 |
HANDLE newBitmapHandle; |
|
2974 |
HANDLE rootDC = CreateDC("DISPLAY", NULL, NULL, NULL); |
|
2975 |
||
2976 |
/*console_printf("CreateBitmap Color\n");*/ |
|
2977 |
if (__bothSmallInteger(w, h) && __isSmallInteger(d) /*&& ISCONNECTED */) { |
|
2344 | 2978 |
if (__intVal(d) == 1) { |
2979 |
newBitmapHandle = CreateBitmap(__intVal(w), __intVal(h) , 1, 1, NULL); |
|
2980 |
} else { |
|
2324 | 2981 |
#if 0 |
2344 | 2982 |
if (__intVal(d) != __depth) { |
2983 |
console_printf("invalid depth\n"); |
|
2984 |
RETURN (nil); |
|
2985 |
} |
|
2324 | 2986 |
#endif |
2344 | 2987 |
newBitmapHandle = CreateCompatibleBitmap(rootDC, __intVal(w), __intVal(h) ); |
2988 |
} |
|
2989 |
||
2990 |
if (newBitmapHandle) { |
|
2991 |
RETURN ( __MKOBJ(newBitmapHandle)); |
|
2992 |
} |
|
2324 | 2993 |
/* |
2344 | 2994 |
DPRINTF(("empty bitmap handle = %x\n", newBitmapHandle)); |
2324 | 2995 |
*/ |
2996 |
} |
|
2997 |
RETURN (nil); |
|
2998 |
%} |
|
2999 |
! |
|
3000 |
||
2323 | 3001 |
destroyPixmap:aDrawableId |
3002 |
||
3003 |
%{ /* NOCONTEXT */ |
|
3004 |
if (__isExternalAddress(aDrawableId) /* && ISCONNECTED */ ) { |
|
2344 | 3005 |
HANDLE bitmapHandle = _HANDLEVal(aDrawableId); |
3006 |
||
3007 |
if (bitmapHandle) { |
|
3008 |
DeleteObject(bitmapHandle); |
|
3009 |
/* _DeleteObject(bitmapHandle, __LINE__); */ |
|
3010 |
} |
|
2323 | 3011 |
} |
3012 |
%} |
|
3013 |
! |
|
3014 |
||
2329 | 3015 |
displayDeviceForm:aForm x:x y:y |
2338 | 3016 |
|
2343 | 3017 |
|sortedImage formMask bitsWithTransparency redVector greenVector blueVector| |
2338 | 3018 |
|
3019 |
sortedImage := aForm. |
|
2341 | 3020 |
|
2344 | 3021 |
"Image 16 bits" |
3022 |
aForm depth = 16 ifTrue:[ |
|
3023 |
bitsWithTransparency := aForm bits. |
|
2341 | 3024 |
]. |
2344 | 3025 |
"Image 24 and 32 bits" |
3026 |
aForm depth >= 24 ifTrue:[ |
|
3027 |
|bestFormat| |
|
3028 |
bestFormat := aForm bestSupportedImageFormatFor: Display. |
|
3029 |
bitsWithTransparency := aForm rgbImageBitsOn: Display bestFormat: bestFormat. |
|
3030 |
]. |
|
3031 |
"Image up to 8 bits" |
|
2343 | 3032 |
aForm depth <= 8 ifTrue:[ |
3033 |
aForm depth < 8 ifTrue:[ |
|
3034 |
sortedImage := aForm asImageWithDepth: 8. |
|
3035 |
]. |
|
3036 |
"/ sortedImage := self sortColorMapImage: aForm. |
|
3037 |
sortedImage := self compressColorMapImage: sortedImage. |
|
3038 |
||
3039 |
formMask := sortedImage mask. |
|
3040 |
formMask isNil |
|
3041 |
ifTrue:[bitsWithTransparency := sortedImage bits ] |
|
3042 |
ifFalse:[ |
|
3043 |
|bitsWithTransparencySize| |
|
3044 |
formMask := formMask asImageWithDepth: sortedImage depth. |
|
3045 |
bitsWithTransparency := sortedImage bits copy. |
|
3046 |
bitsWithTransparencySize := bitsWithTransparency size. |
|
3047 |
formMask bits doWithIndex:[:maskBit :index | |
|
3048 |
bitsWithTransparencySize >= index ifTrue:[ |
|
3049 |
maskBit == 0 ifTrue:[bitsWithTransparency at: index put: 255 "60" "bitClearAt: index"]. |
|
3050 |
"/ maskBit == 1 ifTrue:[bitsWithTransparency at: index put: (bitsWithTransparency at: index)]. |
|
3051 |
]. |
|
2338 | 3052 |
]. |
2343 | 3053 |
]. |
3054 |
||
3055 |
redVector := sortedImage colorMap redVector. |
|
3056 |
greenVector := sortedImage colorMap greenVector. |
|
3057 |
blueVector := sortedImage colorMap blueVector. |
|
2338 | 3058 |
]. |
3059 |
||
3060 |
self |
|
2343 | 3061 |
drawBits: bitsWithTransparency |
3062 |
redVector: redVector |
|
3063 |
greenVector: greenVector |
|
3064 |
blueVector: blueVector |
|
2338 | 3065 |
bitsPerPixel: sortedImage bitsPerPixel |
3066 |
depth: sortedImage depth |
|
3067 |
width: sortedImage width |
|
3068 |
height: sortedImage height |
|
3069 |
into: self id |
|
3070 |
x: x |
|
3071 |
y: y |
|
3072 |
width: sortedImage width |
|
3073 |
height: sortedImage height |
|
3074 |
with: gcId. |
|
2329 | 3075 |
! |
3076 |
||
2323 | 3077 |
drawBits:imageBits bitsPerPixel:bitsPerPixel depth:imageDepth padding:padd |
2342 | 3078 |
width:imageWidth height:imageHeight |
3079 |
x:srcx y:srcy |
|
3080 |
into:ignoredDrawableId |
|
3081 |
x:dstx y:dsty |
|
3082 |
width:w height:h |
|
3083 |
with:aGCId |
|
2323 | 3084 |
|
3085 |
"draw a bitImage which has depth id, width iw and height ih into |
|
3086 |
the drawable. draw a region of w/h pixels from srcx/srcy to dstx/dsty. |
|
3087 |
Individual source pixels have bitsPerPixel bits, allowing to draw |
|
3088 |
depth and pixel-units to be different. |
|
3089 |
It has to be checked elsewhere, that the server can do it with the given |
|
3090 |
depth - otherwise, primitive failure will be signalled. |
|
3091 |
Also it is assumed, that the colormap is setup correctly and the |
|
3092 |
colors are allocated - otherwise the colors may be wrong." |
|
3093 |
||
3094 |
" |
|
3095 |
sorry; I had to separate it into 2 methods, since XPutImage needs |
|
3096 |
an unlimited stack, and thus cannot send primitiveFailed |
|
3097 |
" |
|
3098 |
(self primDrawBits:imageBits bitsPerPixel:bitsPerPixel depth:imageDepth padding:padd |
|
2342 | 3099 |
width:imageWidth height:imageHeight |
3100 |
x:srcx y:srcy |
|
3101 |
into:ignoredDrawableId |
|
3102 |
x:(dstx rounded) y:(dsty rounded) |
|
3103 |
width:w height:h |
|
3104 |
with:aGCId) |
|
2323 | 3105 |
ifFalse:[ |
2342 | 3106 |
" |
3107 |
also happens, if a segmentation violation occurs in the |
|
3108 |
XPutImage ... |
|
3109 |
" |
|
3110 |
self primitiveFailed |
|
2323 | 3111 |
]. |
3112 |
! |
|
3113 |
||
2338 | 3114 |
drawBits:imageBits redVector:redVector greenVector:greenVector blueVector:blueVector bitsPerPixel:bitsPerPixel depth:imageDepth |
3115 |
width:imageWidth height:imageHeight |
|
3116 |
into:ignoredDrawableId |
|
3117 |
x:dstx y:dsty |
|
3118 |
width:w height:h |
|
3119 |
with:aGCId |
|
3120 |
||
3121 |
"draw a bitImage which has depth id, width iw and height ih into |
|
3122 |
the drawable. draw a region of w/h pixels from srcx/srcy to dstx/dsty. |
|
3123 |
Individual source pixels have bitsPerPixel bits, allowing to draw |
|
3124 |
depth and pixel-units to be different. |
|
3125 |
It has to be checked elsewhere, that the server can do it with the given |
|
3126 |
depth - otherwise, primitive failure will be signalled. |
|
3127 |
Also it is assumed, that the colormap is setup correctly and the |
|
3128 |
colors are allocated - otherwise the colors may be wrong." |
|
3129 |
||
3130 |
" |
|
3131 |
sorry; I had to separate it into 2 methods, since XPutImage needs |
|
3132 |
an unlimited stack, and thus cannot send primitiveFailed |
|
3133 |
" |
|
3134 |
(self primDrawBits:imageBits redVector:redVector greenVector:greenVector blueVector:blueVector bitsPerPixel:bitsPerPixel depth:imageDepth |
|
3135 |
width:imageWidth height:imageHeight |
|
3136 |
into:ignoredDrawableId |
|
2342 | 3137 |
x:(dstx rounded) y:(dsty rounded) |
2338 | 3138 |
width:w height:h |
3139 |
with:aGCId) |
|
3140 |
ifFalse:[ |
|
3141 |
self primitiveFailed |
|
3142 |
]. |
|
3143 |
! |
|
3144 |
||
2324 | 3145 |
primCreateBitmapFromArray:anArray width:w height:h |
3146 |
%{ |
|
3147 |
||
3148 |
HBITMAP newBitmapHandle; |
|
3149 |
int b_width, b_height, bytesPerRowST, bytesPerRowWN, padding; |
|
3150 |
int row, col; |
|
3151 |
unsigned char *cp, *bPits; |
|
3152 |
unsigned char *b_bits = 0; |
|
3153 |
int index; |
|
3154 |
OBJ num; |
|
3155 |
unsigned char *allocatedBits = 0; |
|
3156 |
unsigned char fastBits[10000]; |
|
3157 |
||
3158 |
if (__bothSmallInteger(w, h) |
|
3159 |
&& _isNonNilObject(anArray)) { |
|
2344 | 3160 |
OBJ cls = __qClass(anArray); |
3161 |
||
3162 |
b_width = __intVal(w); |
|
3163 |
b_height = __intVal(h); |
|
3164 |
bytesPerRowST = (b_width + 7) / 8; |
|
3165 |
bytesPerRowWN = ((b_width + 15) / 16) * 2; |
|
3166 |
padding = bytesPerRowWN - bytesPerRowST; |
|
3167 |
||
3168 |
if ((padding == 0) && (cls == @global(ByteArray))) { |
|
3169 |
b_bits = __ByteArrayInstPtr(anArray)->ba_element; |
|
3170 |
cp = 0; |
|
3171 |
} else { |
|
3172 |
int nBytes = b_height * bytesPerRowWN; |
|
3173 |
||
3174 |
if (nBytes < sizeof(fastBits)) { |
|
3175 |
cp = b_bits = fastBits; |
|
3176 |
} else { |
|
3177 |
cp = b_bits = allocatedBits = (unsigned char *) malloc(nBytes); |
|
3178 |
if (! cp) goto fail; |
|
3179 |
} |
|
3180 |
} |
|
3181 |
if (cp) { |
|
3182 |
if (cls == @global(Array)) { |
|
3183 |
OBJ *op; |
|
3184 |
||
3185 |
index = 1; |
|
3186 |
op = &(__ArrayInstPtr(anArray)->a_element[index - 1]); |
|
3187 |
for (row = b_height; row; row--) { |
|
3188 |
for (col = bytesPerRowST; col; col--) { |
|
3189 |
num = *op++; |
|
3190 |
if (! __isSmallInteger(num)) |
|
3191 |
goto fail; |
|
3192 |
*cp++ = __intVal(num); |
|
3193 |
} |
|
3194 |
cp += padding; |
|
3195 |
} |
|
3196 |
} else if (cls == @global(ByteArray)) { |
|
3197 |
unsigned char *pBits; |
|
3198 |
||
3199 |
pBits = __ByteArrayInstPtr(anArray)->ba_element; |
|
3200 |
for (row = b_height; row; row--) { |
|
3201 |
for (col = bytesPerRowST; col; col--) { |
|
3202 |
*cp++ = ( *pBits++ /*^ 0xFF*/ ); |
|
3203 |
} |
|
3204 |
cp += padding; |
|
3205 |
} |
|
3206 |
} else { |
|
3207 |
goto fail; |
|
3208 |
} |
|
3209 |
} |
|
2324 | 3210 |
/* |
2344 | 3211 |
CPRINTF(("create bitmap ...\n")); |
2324 | 3212 |
*/ |
2344 | 3213 |
newBitmapHandle = CreateBitmap(b_width, b_height, 1, 1, b_bits ); |
3214 |
||
3215 |
if (newBitmapHandle ) { |
|
2324 | 3216 |
/* |
2344 | 3217 |
DDPRINTF(("returning bitmap %x ...\n", newBitmapHandle)); |
2324 | 3218 |
*/ |
2344 | 3219 |
if (allocatedBits) { |
3220 |
free(allocatedBits); |
|
3221 |
} |
|
3222 |
RETURN ( __MKOBJ(newBitmapHandle)); |
|
3223 |
} |
|
2324 | 3224 |
} |
3225 |
fail: ; |
|
3226 |
/* |
|
3227 |
DDPRINTF(("create bitmap FAILED!!!\n")); |
|
3228 |
*/ |
|
3229 |
if (allocatedBits) { |
|
3230 |
/* |
|
2344 | 3231 |
CPRINTF(("freeing up bitmap bits ...\n")); |
2324 | 3232 |
*/ |
2344 | 3233 |
free(allocatedBits); |
2324 | 3234 |
} |
3235 |
/* |
|
3236 |
CPRINTF(("returning nil ...\n")); |
|
3237 |
*/ |
|
3238 |
RETURN ( nil ); |
|
3239 |
%} |
|
3240 |
! |
|
3241 |
||
2323 | 3242 |
primDrawBits:imageBits bitsPerPixel:bitsPerPixel depth:imageDepth padding:padd |
2338 | 3243 |
width:imageWidth height:imageHeight |
3244 |
x:srcx y:srcy |
|
3245 |
into:ignoredDrawableId |
|
3246 |
x:dstx y:dsty |
|
3247 |
width:w height:h |
|
3248 |
with:aGCId |
|
2323 | 3249 |
|
3250 |
"since XPutImage may allocate huge amount of stack space |
|
3251 |
(some implementations use alloca), this must run with unlimited stack." |
|
3252 |
||
3253 |
%{ |
|
3254 |
unsigned char fastBits[10000]; |
|
3255 |
unsigned char *b_bits = 0; |
|
3256 |
unsigned char *allocatedBits = 0; |
|
3257 |
unsigned char *__imageBits = 0; |
|
3258 |
||
3259 |
if (__isByteArray(imageBits)) { |
|
2338 | 3260 |
__imageBits = __ByteArrayInstPtr(imageBits)->ba_element; |
2323 | 3261 |
} else if (__isExternalBytesLike(imageBits)) { |
2338 | 3262 |
__imageBits = (unsigned char *)(__externalBytesAddress(imageBits)); |
2323 | 3263 |
} |
3264 |
||
3265 |
if (/* ISCONNECTED |
|
3266 |
&& */ __isExternalAddressLike(aGCId) |
|
3267 |
&& __bothSmallInteger(srcx, srcy) |
|
3268 |
&& __bothSmallInteger(dstx, dsty) |
|
3269 |
&& __bothSmallInteger(w, h) |
|
3270 |
&& __bothSmallInteger(imageWidth, imageHeight) |
|
3271 |
&& __bothSmallInteger(imageDepth, bitsPerPixel) |
|
3272 |
&& __isSmallInteger(padd) |
|
3273 |
&& __imageBits) |
|
3274 |
{ |
|
2338 | 3275 |
struct |
3276 |
{ |
|
3277 |
BITMAPINFOHEADER bmiHeader; |
|
3278 |
DWORD r; |
|
3279 |
DWORD g; |
|
3280 |
DWORD b; |
|
3281 |
} bitmap; |
|
3282 |
||
3283 |
HANDLE hDC = (HANDLE)(__externalAddressVal(aGCId)); |
|
3284 |
HBITMAP hBitmap = _HBITMAPVAL(__INST(drawableId)); |
|
2323 | 3285 |
|
3286 |
/* |
|
2338 | 3287 |
DDPRINTF(("hDC = %x\n", hDC)); |
2323 | 3288 |
*/ |
2338 | 3289 |
if (__intVal(padd) != WIN32PADDING) { |
3290 |
int row, col; |
|
3291 |
unsigned char *cp; |
|
3292 |
unsigned char *pBits; |
|
3293 |
int b_width, b_height, bytesPerRowST, bytesPerRowWN, padding, nBytes; |
|
3294 |
int bi = __intVal(bitsPerPixel); |
|
3295 |
||
3296 |
b_width = __intVal(w); |
|
3297 |
b_height = __intVal(h); |
|
3298 |
bytesPerRowST = (b_width * bi + (__intVal(padd)-1)) / __intVal(padd); |
|
3299 |
bytesPerRowWN = (b_width * bi + (WIN32PADDING-1)) / WIN32PADDING * (WIN32PADDING/8); |
|
3300 |
padding = bytesPerRowWN - bytesPerRowST; |
|
3301 |
nBytes = b_height * bytesPerRowWN; |
|
3302 |
/*console_printf("padd %d bs %d bw %d p %d\n",__intVal(padd),bytesPerRowST,bytesPerRowWN,padding);*/ |
|
3303 |
if (padding) { |
|
3304 |
if (nBytes < sizeof(fastBits)) { |
|
3305 |
cp = b_bits = fastBits; |
|
3306 |
} else { |
|
3307 |
cp = b_bits = allocatedBits = (unsigned char *) malloc(nBytes); |
|
3308 |
} |
|
3309 |
if (cp) { |
|
3310 |
pBits = __imageBits; |
|
3311 |
for (row = b_height; row; row--) { |
|
3312 |
for (col = bytesPerRowST; col; col--) { |
|
3313 |
*cp++ = *pBits++; |
|
3314 |
} |
|
3315 |
cp += padding; |
|
3316 |
} |
|
3317 |
} else |
|
3318 |
goto fail; |
|
3319 |
} |
|
3320 |
} |
|
3321 |
||
3322 |
if (b_bits == 0) { |
|
3323 |
b_bits = __imageBits; |
|
3324 |
} |
|
3325 |
||
3326 |
bitmap.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); |
|
3327 |
bitmap.bmiHeader.biPlanes = 1; |
|
3328 |
if (__intVal(imageDepth) == 24) { |
|
3329 |
/*bitmap.bmiHeader.biCompression = BI_BITFIELDS; |
|
3330 |
bitmap.r = 0xff0000; |
|
3331 |
bitmap.g = 0x00ff00; |
|
3332 |
bitmap.b = 0x0000ff;*/ |
|
3333 |
bitmap.bmiHeader.biCompression = BI_RGB; |
|
3334 |
} else if (__intVal(imageDepth) == 16) { |
|
3335 |
/*bitmap.bmiHeader.biCompression = BI_RGB; |
|
3336 |
bitmap.bmiHeader.biCompression = BI_BITFIELDS; |
|
3337 |
bitmap.b = 0x001f; |
|
3338 |
bitmap.g = 0x07e0; |
|
3339 |
bitmap.r = 0xf800;*/ |
|
3340 |
bitmap.b = 0; |
|
3341 |
bitmap.g = 0; |
|
3342 |
bitmap.r = 0; |
|
3343 |
bitmap.bmiHeader.biCompression = BI_RGB; |
|
3344 |
} |
|
3345 |
bitmap.bmiHeader.biSizeImage = 0; |
|
3346 |
bitmap.bmiHeader.biXPelsPerMeter = 0; |
|
3347 |
bitmap.bmiHeader.biYPelsPerMeter = 0; |
|
3348 |
bitmap.bmiHeader.biClrUsed = 0; |
|
3349 |
bitmap.bmiHeader.biClrImportant = 0; |
|
3350 |
bitmap.bmiHeader.biWidth = __intVal(imageWidth); |
|
3351 |
bitmap.bmiHeader.biHeight = -(__intVal(imageHeight)); |
|
3352 |
bitmap.bmiHeader.biBitCount = __intVal(bitsPerPixel); |
|
3353 |
/*console_printf("drawBits depth:%d bitsPerPixel:%d IW%d W:%d H:%d\n",__intVal(imageDepth),bitmap.bmiHeader.biBitCount,bitmap.bmiHeader.biWidth,__intVal(w),bitmap.bmiHeader.biHeight);*/ |
|
3354 |
||
3355 |
SetDIBitsToDevice(hDC,__intVal(dstx),__intVal(dsty), |
|
3356 |
__intVal(w), __intVal(h), |
|
3357 |
__intVal(srcx), __intVal(srcy), |
|
3358 |
0,__intVal(h), |
|
3359 |
(void *)b_bits, |
|
3360 |
(BITMAPINFO*)&bitmap,DIB_RGB_COLORS); |
|
2324 | 3361 |
|
3362 |
/* |
|
2338 | 3363 |
SetDIBits(hDC,hBitmap, |
3364 |
0,__intVal(h), |
|
3365 |
(void *)b_bits, |
|
3366 |
(BITMAPINFO*)&bitmap,DIB_RGB_COLORS); |
|
2324 | 3367 |
*/ |
2323 | 3368 |
/* |
2338 | 3369 |
StretchDIBits(hDC, |
3370 |
__intVal(dstx),(__intVal(dsty)), // x & y coord of destination upper-left corner |
|
3371 |
__intVal(w), __intVal(h), // width & height of destination rectangle |
|
3372 |
__intVal(srcx), __intVal(srcy), // x & y coord of source upper-left corner |
|
3373 |
__intVal(w), __intVal(h), // width & height of source rectangle |
|
3374 |
(void *)b_bits, // bitmap bits |
|
3375 |
(BITMAPINFO*)&bitmap, // bitmap data |
|
3376 |
DIB_RGB_COLORS, // usage options |
|
3377 |
SRCCOPY // raster operation code |
|
3378 |
); |
|
2323 | 3379 |
*/ |
2338 | 3380 |
if (allocatedBits) { |
3381 |
free(allocatedBits); |
|
3382 |
} |
|
2323 | 3383 |
/* |
3384 |
#ifndef CACHE_LAST_DC |
|
2338 | 3385 |
_releaseDC(gcData); |
2323 | 3386 |
#endif |
3387 |
*/ |
|
2338 | 3388 |
RETURN ( true ); |
2323 | 3389 |
} |
3390 |
||
3391 |
fail: ; |
|
3392 |
/* |
|
3393 |
PRINTF(("create temp bitmap FAILED!!!\n")); |
|
3394 |
*/ |
|
3395 |
if (allocatedBits) { |
|
3396 |
/* |
|
2338 | 3397 |
PRINTF(("freeing up temp bitmap bits ...\n")); |
2323 | 3398 |
*/ |
2338 | 3399 |
free(allocatedBits); |
2323 | 3400 |
} |
3401 |
/* |
|
3402 |
#ifndef CACHE_LAST_DC |
|
3403 |
if (hDC) { |
|
2338 | 3404 |
_releaseDC(gcData); |
3405 |
} |
|
3406 |
#endif |
|
3407 |
*/ |
|
3408 |
%} |
|
3409 |
. |
|
3410 |
^ false |
|
3411 |
! |
|
3412 |
||
3413 |
primDrawBits:imageBits redVector:redVector greenVector:greenVector blueVector:blueVector bitsPerPixel:bitsPerPixel depth:imageDepth |
|
3414 |
width:imageWidth height:imageHeight |
|
3415 |
into:ignoredDrawableId |
|
3416 |
x:dstx y:dsty |
|
3417 |
width:w height:h |
|
3418 |
with:aGCId |
|
3419 |
||
3420 |
"since XPutImage may allocate huge amount of stack space |
|
3421 |
(some implementations use alloca), this must run with unlimited stack." |
|
3422 |
||
3423 |
%{ |
|
3424 |
unsigned char fastBits[10000]; |
|
3425 |
unsigned char *b_bits = 0; |
|
3426 |
unsigned char *allocatedBits = 0; |
|
3427 |
unsigned char *__imageBits = 0; |
|
3428 |
unsigned char *__redVector = 0; |
|
3429 |
unsigned char *__greenVector = 0; |
|
3430 |
unsigned char *__blueVector = 0; |
|
3431 |
int padd = 8; |
|
3432 |
||
3433 |
if (__isByteArray(imageBits)) { |
|
3434 |
__imageBits = __ByteArrayInstPtr(imageBits)->ba_element; |
|
3435 |
} else if (__isExternalBytesLike(imageBits)) { |
|
3436 |
__imageBits = (unsigned char *)(__externalBytesAddress(imageBits)); |
|
3437 |
} |
|
3438 |
||
3439 |
if (__isByteArray(redVector)) { |
|
3440 |
__redVector = __ByteArrayInstPtr(redVector)->ba_element; |
|
3441 |
} else if (__isExternalBytesLike(redVector)) { |
|
3442 |
__redVector = (unsigned char *)(__externalBytesAddress(redVector)); |
|
3443 |
} |
|
3444 |
||
3445 |
if (__isByteArray(greenVector)) { |
|
3446 |
__greenVector = __ByteArrayInstPtr(greenVector)->ba_element; |
|
3447 |
} else if (__isExternalBytesLike(greenVector)) { |
|
3448 |
__greenVector = (unsigned char *)(__externalBytesAddress(greenVector)); |
|
3449 |
} |
|
3450 |
||
3451 |
if (__isByteArray(blueVector)) { |
|
3452 |
__blueVector = __ByteArrayInstPtr(blueVector)->ba_element; |
|
3453 |
} else if (__isExternalBytesLike(blueVector)) { |
|
3454 |
__blueVector = (unsigned char *)(__externalBytesAddress(blueVector)); |
|
3455 |
} |
|
3456 |
||
3457 |
if (/* ISCONNECTED |
|
3458 |
&& */ __isExternalAddressLike(aGCId) |
|
3459 |
// && __bothSmallInteger(srcx, srcy) |
|
3460 |
&& __bothSmallInteger(dstx, dsty) |
|
3461 |
&& __bothSmallInteger(w, h) |
|
3462 |
&& __bothSmallInteger(imageWidth, imageHeight) |
|
3463 |
&& __bothSmallInteger(imageDepth, bitsPerPixel) |
|
2343 | 3464 |
&& __imageBits) |
2338 | 3465 |
{ |
3466 |
struct |
|
3467 |
{ |
|
3468 |
BITMAPINFOHEADER bmiHeader; |
|
3469 |
RGBQUAD bmiColors[256]; |
|
3470 |
} bitmap; |
|
3471 |
||
3472 |
HANDLE hDC = (HANDLE)(__externalAddressVal(aGCId)); |
|
3473 |
HBITMAP hBitmap = _HBITMAPVAL(__INST(drawableId)); |
|
3474 |
int col; |
|
3475 |
/* |
|
3476 |
DDPRINTF(("hDC = %x\n", hDC)); |
|
3477 |
*/ |
|
3478 |
||
3479 |
if (padd != WIN32PADDING) { |
|
3480 |
||
3481 |
int row, col; |
|
3482 |
unsigned char *cp; |
|
3483 |
unsigned char *pBits; |
|
3484 |
int b_width, b_height, bytesPerRowST, bytesPerRowWN, padding, nBytes; |
|
3485 |
int bi = __intVal(bitsPerPixel); |
|
3486 |
||
2340
7aada47a2ec0
changed #primDrawBits:redVector:greenVector:blueVector:bitsPerPixel:depth:width:height:into:x:y:width:height:with:
fm
parents:
2339
diff
changeset
|
3487 |
// console_fprintf(stderr, "Non WIN32PADDING"); |
2338 | 3488 |
|
3489 |
b_width = __intVal(w); |
|
3490 |
b_height = __intVal(h); |
|
3491 |
bytesPerRowST = (b_width * bi + (padd - 1 )) / padd; |
|
3492 |
bytesPerRowWN = (b_width * bi + (WIN32PADDING-1)) / WIN32PADDING * (WIN32PADDING/8); |
|
3493 |
padding = bytesPerRowWN - bytesPerRowST; |
|
3494 |
nBytes = b_height * bytesPerRowWN; |
|
3495 |
/*console_printf("padd %d bs %d bw %d p %d\n",__intVal(padd),bytesPerRowST,bytesPerRowWN,padding);*/ |
|
3496 |
if (padding) { |
|
3497 |
if (nBytes < sizeof(fastBits)) { |
|
3498 |
cp = b_bits = fastBits; |
|
3499 |
} else { |
|
3500 |
cp = b_bits = allocatedBits = (unsigned char *) malloc(nBytes); |
|
3501 |
} |
|
3502 |
if (cp) { |
|
3503 |
pBits = __imageBits; |
|
3504 |
for (row = b_height; row; row--) { |
|
3505 |
for (col = bytesPerRowST; col; col--) { |
|
3506 |
*cp++ = *pBits++; |
|
3507 |
} |
|
3508 |
cp += padding; |
|
3509 |
} |
|
3510 |
} else |
|
3511 |
goto fail; |
|
3512 |
} |
|
3513 |
} |
|
3514 |
||
3515 |
if (b_bits == 0) { |
|
3516 |
b_bits = __imageBits; |
|
3517 |
} |
|
3518 |
||
3519 |
bitmap.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); |
|
3520 |
bitmap.bmiHeader.biPlanes = 1; |
|
3521 |
bitmap.bmiHeader.biCompression = BI_RGB; |
|
3522 |
bitmap.bmiHeader.biSizeImage = 0; |
|
3523 |
bitmap.bmiHeader.biXPelsPerMeter = 0; |
|
3524 |
bitmap.bmiHeader.biYPelsPerMeter = 0; |
|
3525 |
bitmap.bmiHeader.biClrUsed = 0; |
|
3526 |
bitmap.bmiHeader.biClrImportant = 0; |
|
3527 |
bitmap.bmiHeader.biWidth = __intVal(imageWidth); |
|
3528 |
bitmap.bmiHeader.biHeight = -(__intVal(imageHeight)); |
|
3529 |
bitmap.bmiHeader.biBitCount = __intVal(bitsPerPixel); |
|
3530 |
/*console_printf("drawBits depth:%d bitsPerPixel:%d IW%d W:%d H:%d\n",__intVal(imageDepth),bitmap.bmiHeader.biBitCount,bitmap.bmiHeader.biWidth,__intVal(w),bitmap.bmiHeader.biHeight);*/ |
|
3531 |
||
2343 | 3532 |
if (__intVal(imageDepth) <= 8) { |
2338 | 3533 |
for(col=0;col<256;col++) |
3534 |
{ |
|
3535 |
bitmap.bmiColors[col].rgbBlue = __blueVector[col]; // Microsoft idea: change rgbBlue to rgbRed |
|
3536 |
bitmap.bmiColors[col].rgbGreen = __greenVector[col]; |
|
3537 |
bitmap.bmiColors[col].rgbRed = __redVector[col]; // Microsoft idea: change rgbRed to rgbBlue |
|
3538 |
bitmap.bmiColors[col].rgbReserved = 0; |
|
3539 |
||
3540 |
} |
|
2343 | 3541 |
} |
2338 | 3542 |
|
3543 |
bitmap.bmiColors[255].rgbBlue=255; |
|
3544 |
bitmap.bmiColors[255].rgbGreen=255; |
|
3545 |
bitmap.bmiColors[255].rgbRed =255; |
|
3546 |
||
3547 |
SetDIBitsToDevice(hDC,__intVal(dstx),__intVal(dsty), |
|
3548 |
__intVal(w), __intVal(h), |
|
3549 |
0, 0, /* __intVal(srcx), __intVal(srcy), */ |
|
3550 |
0,__intVal(h), |
|
3551 |
(void *)b_bits, |
|
3552 |
(BITMAPINFO*)&bitmap,DIB_RGB_COLORS); |
|
3553 |
/* |
|
3554 |
SetDIBits(hDC,hBitmap, |
|
3555 |
0,__intVal(h), |
|
3556 |
(void *)b_bits, |
|
3557 |
(BITMAPINFO*)&bitmap,DIB_RGB_COLORS); |
|
3558 |
*/ |
|
3559 |
/* |
|
3560 |
StretchDIBits(hDC, |
|
3561 |
__intVal(dstx),(__intVal(dsty)), // x & y coord of destination upper-left corner |
|
3562 |
__intVal(w), __intVal(h), // width & height of destination rectangle |
|
3563 |
__intVal(srcx), __intVal(srcy), // x & y coord of source upper-left corner |
|
3564 |
__intVal(w), __intVal(h), // width & height of source rectangle |
|
3565 |
(void *)b_bits, // bitmap bits |
|
3566 |
(BITMAPINFO*)&bitmap, // bitmap data |
|
3567 |
DIB_RGB_COLORS, // usage options |
|
3568 |
SRCCOPY // raster operation code |
|
3569 |
); |
|
3570 |
*/ |
|
3571 |
if (allocatedBits) { |
|
3572 |
free(allocatedBits); |
|
3573 |
} |
|
3574 |
/* |
|
3575 |
#ifndef CACHE_LAST_DC |
|
3576 |
_releaseDC(gcData); |
|
3577 |
#endif |
|
3578 |
*/ |
|
3579 |
RETURN ( true ); |
|
3580 |
} |
|
3581 |
||
3582 |
fail: ; |
|
3583 |
/* |
|
3584 |
PRINTF(("create temp bitmap FAILED!!!\n")); |
|
3585 |
*/ |
|
3586 |
if (allocatedBits) { |
|
3587 |
/* |
|
3588 |
PRINTF(("freeing up temp bitmap bits ...\n")); |
|
3589 |
*/ |
|
3590 |
free(allocatedBits); |
|
3591 |
} |
|
3592 |
/* |
|
3593 |
#ifndef CACHE_LAST_DC |
|
3594 |
if (hDC) { |
|
3595 |
_releaseDC(gcData); |
|
2323 | 3596 |
} |
3597 |
#endif |
|
3598 |
*/ |
|
3599 |
%} |
|
3600 |
. |
|
3601 |
^ false |
|
3602 |
! |
|
3603 |
||
3604 |
setFunction:aFunctionSymbol in:aGCId |
|
3605 |
"set alu function to be drawn with" |
|
3606 |
||
3607 |
Transcript showCR: aFunctionSymbol printString. |
|
3608 |
function := aFunctionSymbol. |
|
3609 |
||
3610 |
"/%{ /* NOCONTEXT */ |
|
3611 |
"/ |
|
3612 |
"/ if (__isExternalAddress(aGCId)) { |
|
3613 |
"/ struct gcData *gcData = _GCDATA(aGCId); |
|
3614 |
"/ int fun = -1; |
|
3615 |
"/ int bfun = -1; |
|
3616 |
"/ |
|
3617 |
"/ if (aFunctionSymbol == @symbol(copy)) { |
|
3618 |
"/ fun = R2_COPYPEN; |
|
3619 |
"/ bfun = BITBLT_COPY; |
|
3620 |
"/ } else if (aFunctionSymbol == @symbol(copyInverted)) { |
|
3621 |
"/ fun = R2_NOTCOPYPEN; |
|
3622 |
"/ bfun = BITBLT_COPYINVERTED; |
|
3623 |
"/ } else if (aFunctionSymbol == @symbol(xor)) { |
|
3624 |
"/ fun = R2_XORPEN; |
|
3625 |
"/ bfun = BITBLT_XOR; |
|
3626 |
"/ } else if (aFunctionSymbol == @symbol(and)) { |
|
3627 |
"/ fun = R2_MASKPEN; |
|
3628 |
"/ bfun = BITBLT_AND; |
|
3629 |
"/ } else if (aFunctionSymbol == @symbol(or)) { |
|
3630 |
"/ fun = R2_MERGEPEN; |
|
3631 |
"/ bfun = BITBLT_OR; |
|
3632 |
"/ } |
|
3633 |
"/ |
|
2325 | 3634 |
"/ if (fun |
2323 | 3635 |
! |
3636 |
||
3637 |
setGraphicsExposures:aBoolean in:aGCId |
|
3638 |
"set or clear the graphics exposures flag" |
|
3639 |
! |
|
3640 |
||
3641 |
shiftBlue |
|
3642 |
"return the number of valid bits in the red component." |
|
3643 |
||
3644 |
"/ bitsRed isNil ifTrue:[ |
|
3645 |
"/ "/ not a truecolor display |
|
3646 |
"/ ^ bitsPerRGB |
|
3647 |
"/ ]. |
|
3648 |
"/ ^ bitsRed |
|
3649 |
||
3650 |
^Display shiftBlue |
|
3651 |
! |
|
3652 |
||
3653 |
shiftGreen |
|
3654 |
"return the number of valid bits in the red component." |
|
3655 |
||
3656 |
"/ bitsRed isNil ifTrue:[ |
|
3657 |
"/ "/ not a truecolor display |
|
3658 |
"/ ^ bitsPerRGB |
|
3659 |
"/ ]. |
|
3660 |
"/ ^ bitsRed |
|
3661 |
||
3662 |
^Display shiftGreen |
|
3663 |
! |
|
3664 |
||
3665 |
shiftRed |
|
3666 |
"return the number of valid bits in the red component." |
|
3667 |
||
3668 |
"/ bitsRed isNil ifTrue:[ |
|
3669 |
"/ "/ not a truecolor display |
|
3670 |
"/ ^ bitsPerRGB |
|
3671 |
"/ ]. |
|
3672 |
"/ ^ bitsRed |
|
3673 |
||
3674 |
^Display shiftRed |
|
2338 | 3675 |
! |
3676 |
||
3677 |
sortBlockForColors |
|
3678 |
||
3679 |
^ [:a :b | |
|
3680 |
a redByte == b redByte ifTrue:[ |
|
3681 |
a greenByte == b greenByte ifTrue:[ |
|
3682 |
a blueByte < b blueByte |
|
3683 |
] ifFalse:[ |
|
3684 |
a greenByte < b greenByte |
|
3685 |
] |
|
3686 |
] ifFalse:[ |
|
3687 |
a redByte < b redByte |
|
3688 |
] |
|
3689 |
]. |
|
3690 |
! |
|
3691 |
||
3692 |
sortColorMapImage: image |
|
3693 |
"calculates a new color map for the image, sorting colors" |
|
3694 |
||
3695 |
|sortBlock depth newColorMap newImage oldImage usedColors oldToNew oldBits newBits tmpBits| |
|
3696 |
||
3697 |
sortBlock := self sortBlockForColors. |
|
3698 |
oldImage := image. |
|
3699 |
depth := oldImage depth. |
|
3700 |
||
3701 |
oldImage photometric ~~ #palette ifTrue:[ |
|
3702 |
Transcript showCR:'Compress colorMap: Only palette images have colormaps.'. |
|
3703 |
^ image |
|
3704 |
]. |
|
3705 |
||
3706 |
usedColors := oldImage realColorMap. |
|
3707 |
||
3708 |
||
3709 |
"/ translation table |
|
3710 |
oldToNew := ByteArray new:(1 bitShift:depth). |
|
3711 |
newColorMap := usedColors asArray. |
|
3712 |
newColorMap sort:sortBlock. |
|
3713 |
||
3714 |
oldImage colorMap asArray keysAndValuesDo:[:oldIdx :clr | |
|
3715 |
|newPixel| |
|
3716 |
||
3717 |
(usedColors includes:clr) ifTrue:[ |
|
3718 |
newPixel := newColorMap indexOf:clr. |
|
3719 |
oldToNew at:oldIdx put:newPixel-1. |
|
3720 |
] |
|
3721 |
]. |
|
3722 |
||
3723 |
oldBits := oldImage bits. |
|
3724 |
newBits := ByteArray new:(oldBits size). |
|
3725 |
depth ~~ 8 ifTrue:[ |
|
3726 |
"/ expand/compress can only handle 8bits |
|
3727 |
tmpBits := ByteArray uninitializedNew:(oldImage width*oldImage height). |
|
3728 |
oldBits |
|
3729 |
expandPixels:depth |
|
3730 |
width:oldImage width |
|
3731 |
height:oldImage height |
|
3732 |
into:tmpBits |
|
3733 |
mapping:oldToNew. |
|
3734 |
tmpBits |
|
3735 |
compressPixels:depth |
|
3736 |
width:oldImage width |
|
3737 |
height:oldImage height |
|
3738 |
into:newBits |
|
3739 |
mapping:nil |
|
3740 |
] ifFalse:[ |
|
3741 |
oldBits |
|
3742 |
expandPixels:depth |
|
3743 |
width:oldImage width |
|
3744 |
height:oldImage height |
|
3745 |
into:newBits |
|
3746 |
mapping:oldToNew. |
|
3747 |
]. |
|
3748 |
||
3749 |
newImage := oldImage species new |
|
3750 |
width:oldImage width |
|
3751 |
height:oldImage height |
|
3752 |
depth:depth |
|
3753 |
fromArray:newBits. |
|
3754 |
||
3755 |
newImage colorMap:newColorMap. |
|
3756 |
newImage fileName:oldImage fileName. |
|
3757 |
newImage mask:(oldImage mask copy). |
|
3758 |
||
3759 |
^newImage |
|
2343 | 3760 |
! |
3761 |
||
3762 |
transparencyTest_primDrawBits:imageBits redVector:redVector greenVector:greenVector blueVector:blueVector bitsPerPixel:bitsPerPixel depth:imageDepth |
|
3763 |
width:imageWidth height:imageHeight |
|
3764 |
into:ignoredDrawableId |
|
3765 |
x:dstx y:dsty |
|
3766 |
width:w height:h |
|
3767 |
with:aGCId |
|
3768 |
||
3769 |
"since XPutImage may allocate huge amount of stack space |
|
3770 |
(some implementations use alloca), this must run with unlimited stack." |
|
3771 |
||
3772 |
%{ |
|
3773 |
unsigned char fastBits[10000]; |
|
3774 |
unsigned char *b_bits = 0; |
|
3775 |
unsigned char *allocatedBits = 0; |
|
3776 |
unsigned char *__imageBits = 0; |
|
3777 |
unsigned char *__redVector = 0; |
|
3778 |
unsigned char *__greenVector = 0; |
|
3779 |
unsigned char *__blueVector = 0; |
|
3780 |
int padd = 8; |
|
3781 |
||
3782 |
if (__isByteArray(imageBits)) { |
|
3783 |
__imageBits = __ByteArrayInstPtr(imageBits)->ba_element; |
|
3784 |
} else if (__isExternalBytesLike(imageBits)) { |
|
3785 |
__imageBits = (unsigned char *)(__externalBytesAddress(imageBits)); |
|
3786 |
} |
|
3787 |
||
3788 |
if (__isByteArray(redVector)) { |
|
3789 |
__redVector = __ByteArrayInstPtr(redVector)->ba_element; |
|
3790 |
} else if (__isExternalBytesLike(redVector)) { |
|
3791 |
__redVector = (unsigned char *)(__externalBytesAddress(redVector)); |
|
3792 |
} |
|
3793 |
||
3794 |
if (__isByteArray(greenVector)) { |
|
3795 |
__greenVector = __ByteArrayInstPtr(greenVector)->ba_element; |
|
3796 |
} else if (__isExternalBytesLike(greenVector)) { |
|
3797 |
__greenVector = (unsigned char *)(__externalBytesAddress(greenVector)); |
|
3798 |
} |
|
3799 |
||
3800 |
if (__isByteArray(blueVector)) { |
|
3801 |
__blueVector = __ByteArrayInstPtr(blueVector)->ba_element; |
|
3802 |
} else if (__isExternalBytesLike(blueVector)) { |
|
3803 |
__blueVector = (unsigned char *)(__externalBytesAddress(blueVector)); |
|
3804 |
} |
|
3805 |
||
3806 |
if (/* ISCONNECTED |
|
3807 |
&& */ __isExternalAddressLike(aGCId) |
|
3808 |
// && __bothSmallInteger(srcx, srcy) |
|
3809 |
&& __bothSmallInteger(dstx, dsty) |
|
3810 |
&& __bothSmallInteger(w, h) |
|
3811 |
&& __bothSmallInteger(imageWidth, imageHeight) |
|
3812 |
&& __bothSmallInteger(imageDepth, bitsPerPixel) |
|
3813 |
&& __imageBits) |
|
3814 |
{ |
|
3815 |
struct |
|
3816 |
{ |
|
3817 |
BITMAPINFOHEADER bmiHeader; |
|
3818 |
RGBQUAD bmiColors[256]; |
|
3819 |
} bitmap; |
|
3820 |
||
3821 |
HANDLE hDC = (HANDLE)(__externalAddressVal(aGCId)); |
|
3822 |
HBITMAP hBitmap = _HBITMAPVAL(__INST(drawableId)); |
|
3823 |
int col; |
|
3824 |
/* |
|
3825 |
DDPRINTF(("hDC = %x\n", hDC)); |
|
3826 |
*/ |
|
3827 |
||
3828 |
if (padd != WIN32PADDING) { |
|
3829 |
||
3830 |
int row, col; |
|
3831 |
unsigned char *cp; |
|
3832 |
unsigned char *pBits; |
|
3833 |
int b_width, b_height, bytesPerRowST, bytesPerRowWN, padding, nBytes; |
|
3834 |
int bi = __intVal(bitsPerPixel); |
|
3835 |
||
3836 |
// console_fprintf(stderr, "Non WIN32PADDING"); |
|
3837 |
||
3838 |
b_width = __intVal(w); |
|
3839 |
b_height = __intVal(h); |
|
3840 |
bytesPerRowST = (b_width * bi + (padd - 1 )) / padd; |
|
3841 |
bytesPerRowWN = (b_width * bi + (WIN32PADDING-1)) / WIN32PADDING * (WIN32PADDING/8); |
|
3842 |
padding = bytesPerRowWN - bytesPerRowST; |
|
3843 |
nBytes = b_height * bytesPerRowWN; |
|
3844 |
/*console_printf("padd %d bs %d bw %d p %d\n",__intVal(padd),bytesPerRowST,bytesPerRowWN,padding);*/ |
|
3845 |
if (padding) { |
|
3846 |
if (nBytes < sizeof(fastBits)) { |
|
3847 |
cp = b_bits = fastBits; |
|
3848 |
} else { |
|
3849 |
cp = b_bits = allocatedBits = (unsigned char *) malloc(nBytes); |
|
3850 |
} |
|
3851 |
if (cp) { |
|
3852 |
pBits = __imageBits; |
|
3853 |
for (row = b_height; row; row--) { |
|
3854 |
for (col = bytesPerRowST; col; col--) { |
|
3855 |
*cp++ = *pBits++; |
|
3856 |
} |
|
3857 |
cp += padding; |
|
3858 |
} |
|
3859 |
} else |
|
3860 |
goto fail; |
|
3861 |
} |
|
3862 |
} |
|
3863 |
||
3864 |
if (b_bits == 0) { |
|
3865 |
b_bits = __imageBits; |
|
3866 |
} |
|
3867 |
||
3868 |
bitmap.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); |
|
3869 |
bitmap.bmiHeader.biPlanes = 1; |
|
3870 |
bitmap.bmiHeader.biCompression = BI_RGB; |
|
3871 |
bitmap.bmiHeader.biSizeImage = 0; |
|
3872 |
bitmap.bmiHeader.biXPelsPerMeter = 0; |
|
3873 |
bitmap.bmiHeader.biYPelsPerMeter = 0; |
|
3874 |
bitmap.bmiHeader.biClrUsed = 0; |
|
3875 |
bitmap.bmiHeader.biClrImportant = 0; |
|
3876 |
bitmap.bmiHeader.biWidth = __intVal(imageWidth); |
|
3877 |
bitmap.bmiHeader.biHeight = -(__intVal(imageHeight)); |
|
3878 |
bitmap.bmiHeader.biBitCount = __intVal(bitsPerPixel); |
|
3879 |
/*console_printf("drawBits depth:%d bitsPerPixel:%d IW%d W:%d H:%d\n",__intVal(imageDepth),bitmap.bmiHeader.biBitCount,bitmap.bmiHeader.biWidth,__intVal(w),bitmap.bmiHeader.biHeight);*/ |
|
3880 |
||
3881 |
if (__intVal(imageDepth) <= 8) { |
|
3882 |
for(col=0;col<256;col++) |
|
3883 |
{ |
|
3884 |
bitmap.bmiColors[col].rgbBlue = 0; |
|
3885 |
bitmap.bmiColors[col].rgbGreen = 0; |
|
3886 |
bitmap.bmiColors[col].rgbRed = 0; |
|
3887 |
bitmap.bmiColors[col].rgbReserved = 0; |
|
3888 |
||
3889 |
} |
|
3890 |
} |
|
3891 |
||
3892 |
bitmap.bmiColors[255].rgbBlue=255; |
|
3893 |
bitmap.bmiColors[255].rgbGreen=255; |
|
3894 |
bitmap.bmiColors[255].rgbRed =255; |
|
3895 |
bitmap.bmiColors[255].rgbReserved = 0; |
|
3896 |
StretchDIBits(hDC, |
|
3897 |
__intVal(dstx),(__intVal(dsty)), // x & y coord of destination upper-left corner |
|
3898 |
__intVal(w), __intVal(h), // width & height of destination rectangle |
|
3899 |
0, 0, /* __intVal(srcx), __intVal(srcy), */ // x & y coord of source upper-left corner |
|
3900 |
__intVal(w), __intVal(h), // width & height of source rectangle |
|
3901 |
(void *)b_bits, // bitmap bits |
|
3902 |
(BITMAPINFO*)&bitmap, // bitmap data |
|
3903 |
DIB_RGB_COLORS, // usage options |
|
3904 |
SRCAND // raster operation code |
|
3905 |
); |
|
3906 |
/* |
|
3907 |
if (__intVal(imageDepth) <= 8) { |
|
3908 |
for(col=0;col<256;col++) |
|
3909 |
{ |
|
3910 |
bitmap.bmiColors[col].rgbBlue = __blueVector[col]; // Microsoft idea: change rgbBlue to rgbRed |
|
3911 |
bitmap.bmiColors[col].rgbGreen = __greenVector[col]; |
|
3912 |
bitmap.bmiColors[col].rgbRed = __redVector[col]; // Microsoft idea: change rgbRed to rgbBlue |
|
3913 |
bitmap.bmiColors[col].rgbReserved = 0; |
|
3914 |
||
3915 |
} |
|
3916 |
} |
|
3917 |
||
3918 |
bitmap.bmiColors[255].rgbBlue=0; |
|
3919 |
bitmap.bmiColors[255].rgbGreen=0; |
|
3920 |
bitmap.bmiColors[255].rgbRed =0; |
|
3921 |
bitmap.bmiColors[255].rgbReserved = 0; |
|
3922 |
StretchDIBits(hDC, |
|
3923 |
__intVal(dstx),(__intVal(dsty)), // x & y coord of destination upper-left corner |
|
3924 |
__intVal(w), __intVal(h), // width & height of destination rectangle |
|
3925 |
0, 0, // x & y coord of source upper-left corner |
|
3926 |
__intVal(w), __intVal(h), // width & height of source rectangle |
|
3927 |
(void *)b_bits, // bitmap bits |
|
3928 |
(BITMAPINFO*)&bitmap, // bitmap data |
|
3929 |
DIB_RGB_COLORS, // usage options |
|
3930 |
SRCPAINT // raster operation code |
|
3931 |
); |
|
3932 |
*/ |
|
3933 |
/* |
|
3934 |
SetDIBitsToDevice(hDC,__intVal(dstx),__intVal(dsty), |
|
3935 |
__intVal(w), __intVal(h), |
|
3936 |
0, 0, |
|
3937 |
0,__intVal(h), |
|
3938 |
(void *)b_bits, |
|
3939 |
(BITMAPINFO*)&bitmap,DIB_RGB_COLORS); |
|
3940 |
*/ |
|
3941 |
/* |
|
3942 |
SetDIBits(hDC,hBitmap, |
|
3943 |
0,__intVal(h), |
|
3944 |
(void *)b_bits, |
|
3945 |
(BITMAPINFO*)&bitmap,DIB_RGB_COLORS); |
|
3946 |
*/ |
|
3947 |
/* |
|
3948 |
StretchDIBits(hDC, |
|
3949 |
__intVal(dstx),(__intVal(dsty)), // x & y coord of destination upper-left corner |
|
3950 |
__intVal(w), __intVal(h), // width & height of destination rectangle |
|
3951 |
__intVal(srcx), __intVal(srcy), // x & y coord of source upper-left corner |
|
3952 |
__intVal(w), __intVal(h), // width & height of source rectangle |
|
3953 |
(void *)b_bits, // bitmap bits |
|
3954 |
(BITMAPINFO*)&bitmap, // bitmap data |
|
3955 |
DIB_RGB_COLORS, // usage options |
|
3956 |
SRCCOPY // raster operation code |
|
3957 |
); |
|
3958 |
*/ |
|
3959 |
if (allocatedBits) { |
|
3960 |
free(allocatedBits); |
|
3961 |
} |
|
3962 |
/* |
|
3963 |
#ifndef CACHE_LAST_DC |
|
3964 |
_releaseDC(gcData); |
|
3965 |
#endif |
|
3966 |
*/ |
|
3967 |
RETURN ( true ); |
|
3968 |
} |
|
3969 |
||
3970 |
fail: ; |
|
3971 |
/* |
|
3972 |
PRINTF(("create temp bitmap FAILED!!!\n")); |
|
3973 |
*/ |
|
3974 |
if (allocatedBits) { |
|
3975 |
/* |
|
3976 |
PRINTF(("freeing up temp bitmap bits ...\n")); |
|
3977 |
*/ |
|
3978 |
free(allocatedBits); |
|
3979 |
} |
|
3980 |
/* |
|
3981 |
#ifndef CACHE_LAST_DC |
|
3982 |
if (hDC) { |
|
3983 |
_releaseDC(gcData); |
|
3984 |
} |
|
3985 |
#endif |
|
3986 |
*/ |
|
3987 |
%} |
|
3988 |
. |
|
3989 |
^ false |
|
2323 | 3990 |
! ! |
3991 |
||
3992 |
!WinPrinterContext methodsFor:'font stuff'! |
|
3993 |
||
3994 |
createFontFor:aFontName |
|
3995 |
"a basic method for font allocation; this method allows |
|
3996 |
any font to be aquired (even those not conforming to |
|
3997 |
standard naming conventions, such as cursor, fixed or k14)" |
|
3998 |
||
3999 |
%{ |
|
4000 |
HGDIOBJ hFont; |
|
4001 |
char *fn; |
|
4002 |
||
4003 |
if (__isString(aFontName) || __isSymbol(aFontName)) { |
|
2344 | 4004 |
fn = __stringVal(aFontName); |
4005 |
if ((strcmp(fn, "fixed") == 0) || (strcmp(fn, "ANSI_FIXED_FONT") == 0)) { |
|
4006 |
hFont = GetStockObject(ANSI_FIXED_FONT); |
|
4007 |
} else if ((strcmp(fn, "variable") == 0) || (strcmp(fn, "ANSI_VAR_FONT") == 0)) { |
|
4008 |
hFont = GetStockObject(ANSI_VAR_FONT); |
|
4009 |
} else if ((strcmp(fn, "system") == 0) || (strcmp(fn, "SYSTEM_FONT") == 0)) { |
|
4010 |
hFont = GetStockObject(SYSTEM_FONT); |
|
4011 |
} else if ((strcmp(fn, "systemFixed") == 0) || (strcmp(fn, "SYSTEM_FIXED_FONT") == 0)) { |
|
4012 |
hFont = GetStockObject(SYSTEM_FIXED_FONT); |
|
4013 |
} else if ((strcmp(fn, "deviceDefault") == 0) || (strcmp(fn, "DEVICE_DEFAULT_FONT") == 0)) { |
|
4014 |
hFont = GetStockObject(DEVICE_DEFAULT_FONT); |
|
4015 |
} else { |
|
4016 |
hFont = GetStockObject(ANSI_FIXED_FONT); |
|
4017 |
} |
|
4018 |
if (hFont) { |
|
4019 |
DPRINTF(("createFontFor:%s -> %x\n", fn, hFont)); |
|
4020 |
RETURN ( __MKOBJ(hFont) ); |
|
4021 |
} |
|
2323 | 4022 |
} |
4023 |
%}. |
|
4024 |
^ nil |
|
4025 |
! |
|
4026 |
||
4027 |
fontMetricsOf:fontId |
|
4028 |
"return a fonts metrics info object" |
|
4029 |
||
4030 |
|rawData info| |
|
4031 |
||
4032 |
rawData := Array new:15. |
|
4033 |
(self primFontMetricsOf:fontId hdc:gcId intoArray:rawData) isNil ifTrue:[ |
|
2344 | 4034 |
self primitiveFailed. |
4035 |
^ self |
|
2323 | 4036 |
]. |
4037 |
||
4038 |
rawData at:11 put:#'ms-ansi'. |
|
4039 |
||
4040 |
info := DeviceWorkstation::DeviceFontMetrics new. |
|
4041 |
info |
|
4042 |
ascent:(rawData at:1) |
|
4043 |
descent:(rawData at:2) |
|
4044 |
maxAscent:(rawData at:3) |
|
4045 |
maxDescent:(rawData at:4) |
|
4046 |
minWidth:(rawData at:5) |
|
4047 |
maxWidth:(rawData at:6) |
|
4048 |
avgWidth:(rawData at:7) |
|
4049 |
minCode:(rawData at:8) |
|
4050 |
maxCode:16rFFFF "(rawData at:9)" |
|
4051 |
direction:nil |
|
4052 |
encoding:(rawData at:11). |
|
4053 |
||
4054 |
||
4055 |
^ info |
|
4056 |
! |
|
4057 |
||
4058 |
getDefaultFont |
|
4059 |
"return a default font id - used when class Font cannot |
|
4060 |
find anything usable" |
|
4061 |
||
4062 |
^ self createFontFor:'fixed' |
|
4063 |
! |
|
4064 |
||
4065 |
getFontWithFamily:familyString face:faceString |
|
2344 | 4066 |
style:styleArgString size:sizeArg encoding:encodingSym |
2323 | 4067 |
|
4068 |
"try to get the specified font, if not available, try the next smaller |
|
4069 |
font." |
|
4070 |
||
4071 |
|styleString theName theId xlatedStyle id spacing| |
|
4072 |
||
4073 |
styleString := styleArgString. |
|
4074 |
||
4075 |
"special: if face is nil, allow access to X-fonts" |
|
4076 |
faceString isNil ifTrue:[ |
|
2344 | 4077 |
sizeArg notNil ifTrue:[ |
4078 |
theName := familyString , '-' , sizeArg printString |
|
4079 |
] ifFalse:[ |
|
4080 |
theName := familyString |
|
4081 |
]. |
|
4082 |
theName isNil ifTrue:[ |
|
4083 |
" |
|
4084 |
mhmh - fall back to the default font |
|
4085 |
" |
|
4086 |
theName := 'fixed' |
|
4087 |
]. |
|
4088 |
theId := self createFontFor:theName. |
|
4089 |
theId isNil ifTrue:[ |
|
4090 |
theId := self getDefaultFont |
|
4091 |
]. |
|
4092 |
^ theId |
|
2323 | 4093 |
]. |
4094 |
||
4095 |
"/ spacing other than 'normal' is contained as last component |
|
4096 |
"/ in style |
|
4097 |
styleString notNil ifTrue:[ |
|
2344 | 4098 |
((styleString endsWith:'-narrow') |
4099 |
or:[styleString endsWith:'-semicondensed']) ifTrue:[ |
|
4100 |
|i| |
|
4101 |
i := styleString lastIndexOf:$-. |
|
4102 |
spacing := styleString copyFrom:(i+1). |
|
4103 |
styleString := styleString copyTo:(i-1). |
|
4104 |
] ifFalse:[ |
|
4105 |
spacing := 'normal'. |
|
4106 |
]. |
|
2323 | 4107 |
]. |
4108 |
||
4109 |
xlatedStyle := styleString. |
|
4110 |
xlatedStyle notNil ifTrue:[ |
|
2344 | 4111 |
xlatedStyle := xlatedStyle first asString |
2323 | 4112 |
]. |
4113 |
||
4114 |
id := self |
|
2344 | 4115 |
getFontWithFoundry:'*' |
4116 |
family:familyString asLowercase |
|
4117 |
weight:faceString |
|
4118 |
slant:styleString "/ xlatedStyle |
|
4119 |
spacing:spacing |
|
4120 |
pixelSize:nil |
|
4121 |
size:sizeArg |
|
4122 |
registry:'*' |
|
4123 |
encoding:encodingSym. |
|
2323 | 4124 |
|
4125 |
id isNil ifTrue:[ |
|
2344 | 4126 |
(encodingSym notNil and:[encodingSym ~= '*']) ifTrue:[ |
4127 |
"/ too stupid: encodings come in both cases |
|
4128 |
"/ |
|
4129 |
id := self |
|
4130 |
getFontWithFoundry:'*' |
|
4131 |
family:familyString asLowercase |
|
4132 |
weight:faceString |
|
4133 |
slant:styleString "/ xlatedStyle |
|
4134 |
spacing:spacing |
|
4135 |
pixelSize:nil |
|
4136 |
size:sizeArg |
|
4137 |
registry:'*' |
|
4138 |
encoding:encodingSym asUppercase. |
|
4139 |
id isNil ifTrue:[ |
|
4140 |
id := self |
|
4141 |
getFontWithFoundry:'*' |
|
4142 |
family:familyString asLowercase |
|
4143 |
weight:faceString |
|
4144 |
slant:styleString "/ xlatedStyle |
|
4145 |
spacing:spacing |
|
4146 |
pixelSize:nil |
|
4147 |
size:sizeArg |
|
4148 |
registry:'*' |
|
4149 |
encoding:encodingSym asLowercase. |
|
4150 |
||
4151 |
id isNil ifTrue:[ |
|
4152 |
id := self |
|
4153 |
getFontWithFoundry:'*' |
|
4154 |
family:familyString asLowercase |
|
4155 |
weight:faceString asLowercase |
|
4156 |
slant:styleString asLowercase |
|
4157 |
spacing:spacing |
|
4158 |
pixelSize:nil |
|
4159 |
size:sizeArg |
|
4160 |
registry:'*' |
|
4161 |
encoding:encodingSym asLowercase. |
|
4162 |
] |
|
4163 |
] |
|
4164 |
] |
|
2323 | 4165 |
]. |
4166 |
^ id |
|
4167 |
||
4168 |
"Modified: 24.2.1996 / 22:37:24 / cg" |
|
4169 |
"Modified: 4.7.1996 / 11:38:47 / stefan" |
|
4170 |
! |
|
4171 |
||
4172 |
getFontWithFoundry:foundry family:family weight:weight |
|
2344 | 4173 |
slant:slant spacing:spc pixelSize:pixelSize size:pointSize |
4174 |
registry:registry encoding:encoding |
|
2323 | 4175 |
|
4176 |
"get the specified font, if not available, return nil. |
|
4177 |
For now, this is a poor (incomplete) emulation of the X code ... |
|
4178 |
Individual attributes can be left empty (i.e. '') or nil to match any. |
|
4179 |
||
4180 |
foundry: 'adobe', 'misc', 'dec', 'schumacher' ... usually '*' |
|
4181 |
family: 'helvetica' 'courier' 'times' ... |
|
4182 |
weight: 'bold' 'medium' 'demi' ... |
|
4183 |
slant: 'r(oman)' 'i(talic)' 'o(blique)' |
|
4184 |
spacing: 'narrow' 'normal' semicondensed' ... usually '*' |
|
4185 |
pixelSize: 16,18 ... usually left empty |
|
4186 |
size: size in point (1/72th of an inch) |
|
4187 |
registry: iso8859, sgi ... '*' |
|
4188 |
encoding: vendor specific encoding (usually '*') |
|
4189 |
" |
|
4190 |
||
4191 |
" |
|
4192 |
Windows-NT/95 allows the creation of a font with the following parameters |
|
4193 |
||
2344 | 4194 |
nHeight |
4195 |
nWidth |
|
4196 |
nEscapement |
|
4197 |
nOrientation |
|
4198 |
fnWeight FW_DONTCARE, FW_NORMAL, FW_MEDIUM, FW_BOLD, ... |
|
4199 |
fdwItalic TRUE or FALSE |
|
4200 |
fdwUnderline TRUE or FALSE |
|
4201 |
fdwStrikeOut TRUE or FALSE |
|
4202 |
fdwCharSet ANSI_CHARSET, UNICODE_, SYMBOL_, SHIFTJIS_,... |
|
4203 |
fdwOutputPrecision DEFAULT, STRING, CHAR, ... |
|
4204 |
fdwClipPrecision DEFAULT, CHAR, STROKE, MASK, ... |
|
4205 |
fdwQuality DEFAULT, DRAFT, or PROOF. |
|
4206 |
fdwPitchAndFamily |
|
4207 |
DEFAULT, FIXED or VARIABLE pitch |
|
4208 |
DECORATIVE, DONTCASE, MODERN, ROMAN, SCRIPT, or SWISS. |
|
4209 |
lpszFace |
|
4210 |
Typeface Name |
|
2323 | 4211 |
|
4212 |
These two above descriptions will be matched as follows: |
|
4213 |
||
2344 | 4214 |
foundry - ignored |
4215 |
family - mapped to type face name. |
|
4216 |
weight - mapped to fnWeight |
|
4217 |
slant - used for style |
|
4218 |
spacing - NOT USED INITIALLY |
|
4219 |
pixelSize - NOT USED INITIALLY |
|
4220 |
size - mapped to nHeight |
|
4221 |
registry - NOT USED INITIALLY |
|
4222 |
encoding - mapped to fdwCharSet |
|
2323 | 4223 |
" |
4224 |
||
4225 |
|logSize| |
|
4226 |
||
4227 |
pixelSize notNil ifTrue:[ |
|
2344 | 4228 |
logSize := pixelSize |
2323 | 4229 |
] ifFalse:[ |
2344 | 4230 |
logSize := (pointSize * (self getLogicalPixelSizeY) / 72.0) rounded. |
2323 | 4231 |
]. |
4232 |
%{ |
|
4233 |
HGDIOBJ hFont; |
|
4234 |
int pointSize, nHeight, nWidth, nEscapement, nOrientation; |
|
4235 |
char* work; |
|
4236 |
char* work2; |
|
4237 |
DWORD fnWeight; |
|
4238 |
DWORD fdwItalic; |
|
4239 |
DWORD fdwUnderline; |
|
4240 |
DWORD fdwStrikeOut; |
|
4241 |
DWORD fdwCharSet; |
|
4242 |
DWORD fdwOutputPrecision; |
|
4243 |
DWORD fdwClipPrecision; |
|
4244 |
DWORD fdwQuality; |
|
4245 |
DWORD fdwPitchAndFamily; |
|
4246 |
static char faceName[256]; |
|
4247 |
||
4248 |
/* INITIALIZE */ |
|
4249 |
strcpy( faceName, "NULL" ); |
|
4250 |
nHeight = 0; |
|
4251 |
nWidth = 0; |
|
4252 |
nEscapement = 0; |
|
4253 |
nOrientation = 0; |
|
4254 |
fnWeight = FW_NORMAL; |
|
4255 |
fdwItalic = FALSE; |
|
4256 |
fdwUnderline = FALSE; |
|
4257 |
fdwStrikeOut = FALSE; |
|
4258 |
fdwOutputPrecision = OUT_DEFAULT_PRECIS; |
|
4259 |
fdwClipPrecision = CLIP_DEFAULT_PRECIS; |
|
4260 |
fdwQuality = DEFAULT_QUALITY; |
|
4261 |
fdwPitchAndFamily = FF_DONTCARE; |
|
4262 |
||
4263 |
fdwCharSet = ANSI_CHARSET; |
|
4264 |
if ((encoding == @symbol('ms-ansi'))) { |
|
2344 | 4265 |
fdwCharSet = ANSI_CHARSET; |
2323 | 4266 |
} else if (encoding == @symbol('ms-default')) { |
2344 | 4267 |
fdwCharSet = DEFAULT_CHARSET; |
2323 | 4268 |
} else if ((encoding == @symbol('ms-symbol')) |
2344 | 4269 |
|| (encoding == @symbol('misc-fontspecific'))) { |
4270 |
fdwCharSet = SYMBOL_CHARSET; |
|
2323 | 4271 |
} else if ((encoding == @symbol('ms-shiftjis')) |
2344 | 4272 |
|| (encoding == @symbol('jisx0208.1983-0'))){ |
4273 |
fdwCharSet = SHIFTJIS_CHARSET; |
|
2323 | 4274 |
} else if ((encoding == @symbol('ms-gb2312')) |
2344 | 4275 |
|| (encoding == @symbol('gb2312.1980-0'))) { |
4276 |
fdwCharSet = GB2312_CHARSET; |
|
2323 | 4277 |
} else if ((encoding == @symbol('ms-hangeul')) |
2344 | 4278 |
|| (encoding == @symbol('ksc5601.1987-0'))) { |
4279 |
fdwCharSet = HANGEUL_CHARSET; |
|
2323 | 4280 |
} else if ((encoding == @symbol('ms-chinesebig5')) |
2344 | 4281 |
|| (encoding == @symbol('big5'))) { |
4282 |
fdwCharSet = CHINESEBIG5_CHARSET; |
|
2323 | 4283 |
} else if (encoding == @symbol('ms-oem')) { |
2344 | 4284 |
fdwCharSet = OEM_CHARSET; |
2323 | 4285 |
} else if (encoding == @symbol('ms-johab')) { |
2344 | 4286 |
fdwCharSet = JOHAB_CHARSET; |
2323 | 4287 |
} else if ((encoding == @symbol('ms-hebrew')) |
2344 | 4288 |
|| (encoding == @symbol('ms-cp1255'))) { |
4289 |
fdwCharSet = HEBREW_CHARSET; |
|
2323 | 4290 |
} else if ((encoding == @symbol('ms-arabic')) |
2344 | 4291 |
|| (encoding == @symbol('ms-cp1256'))) { |
4292 |
fdwCharSet = ARABIC_CHARSET; |
|
2323 | 4293 |
} else if ((encoding == @symbol('ms-greek')) |
2344 | 4294 |
|| (encoding == @symbol('ms-cp1253'))) { |
4295 |
fdwCharSet = GREEK_CHARSET; |
|
2323 | 4296 |
} else if ((encoding == @symbol('ms-turkish')) |
2344 | 4297 |
|| (encoding == @symbol('ms-cp1254'))) { |
4298 |
fdwCharSet = TURKISH_CHARSET; |
|
2323 | 4299 |
} else if ((encoding == @symbol('ms-russian')) |
2344 | 4300 |
|| (encoding == @symbol('ms-cp1251'))) { |
4301 |
fdwCharSet = RUSSIAN_CHARSET; |
|
2323 | 4302 |
} else if ((encoding == @symbol('ms-easteurope')) |
2344 | 4303 |
|| (encoding == @symbol('ms-cp1250'))) { |
4304 |
fdwCharSet = EASTEUROPE_CHARSET; |
|
2323 | 4305 |
} else if ((encoding == @symbol('ms-baltic')) |
2344 | 4306 |
|| (encoding == @symbol('ms-cp1257'))) { |
4307 |
fdwCharSet = BALTIC_CHARSET; |
|
2323 | 4308 |
} else if ((encoding == @symbol('ms-vietnamese'))) { |
2344 | 4309 |
fdwCharSet = VIETNAMESE_CHARSET; |
2323 | 4310 |
} else if ((encoding == @symbol('ms-thai'))) { |
2344 | 4311 |
fdwCharSet = THAI_CHARSET; |
2323 | 4312 |
} else if ((encoding == @symbol('ms-mac'))) { |
2344 | 4313 |
fdwCharSet = MAC_CHARSET; |
2323 | 4314 |
#ifdef UNICODE_CHARSET |
4315 |
} else if ((encoding == @symbol('ms-unicode'))) { |
|
2344 | 4316 |
fdwCharSet = UNICODE_CHARSET; |
2323 | 4317 |
#endif |
4318 |
} |
|
4319 |
||
4320 |
if ( __isString( family ) ) { |
|
2344 | 4321 |
work = __stringVal( family ); |
4322 |
if (strcmp( work, "nil" ) != 0 ) { |
|
4323 |
strncpy( faceName, work, sizeof(faceName)-1 ); |
|
4324 |
} |
|
2323 | 4325 |
} |
4326 |
||
4327 |
/* Q: should we allow those ? (they make ST/X programs less portable to X */ |
|
4328 |
if( __isString( weight ) ) { |
|
2344 | 4329 |
work = __stringVal( weight ); |
4330 |
if (strcmp( work, "bold" ) == 0 ) { |
|
4331 |
fnWeight = FW_BOLD; |
|
4332 |
} else if (strcmp( work, "medium" ) == 0 ) { |
|
4333 |
fnWeight = FW_MEDIUM; |
|
4334 |
} else if (strcmp( work, "normal" ) == 0 ) { |
|
4335 |
fnWeight = FW_NORMAL; |
|
4336 |
} else if (strcmp( work, "light" ) == 0 ) { |
|
4337 |
fnWeight = FW_LIGHT; |
|
4338 |
} else if (strcmp( work, "demi" ) == 0 ) { |
|
4339 |
fnWeight = FW_LIGHT; |
|
4340 |
} else if (strcmp( work, "heavy" ) == 0 ) { |
|
4341 |
fnWeight = FW_HEAVY; |
|
4342 |
} else if (strcmp( work, "extraBold" ) == 0 ) { |
|
4343 |
fnWeight = FW_EXTRABOLD; |
|
4344 |
} else if (strcmp( work, "semiBold" ) == 0 ) { |
|
4345 |
fnWeight = FW_SEMIBOLD; |
|
4346 |
} else if (strcmp( work, "thin" ) == 0 ) { |
|
4347 |
fnWeight = FW_THIN; |
|
4348 |
} else if (strcmp( work, "extraLight" ) == 0 ) { |
|
4349 |
fnWeight = FW_EXTRALIGHT; |
|
4350 |
} |
|
2323 | 4351 |
} else if (__isSmallInteger(weight)) { |
2344 | 4352 |
fnWeight = __intVal(weight); |
2323 | 4353 |
} |
4354 |
||
4355 |
if(__isSmallInteger( logSize )) { |
|
2344 | 4356 |
nHeight = __intVal( logSize ); |
2323 | 4357 |
} |
4358 |
||
4359 |
if (__isString(slant)) { |
|
2344 | 4360 |
work2 = __stringVal( slant ); |
4361 |
work = __stringVal( slant ); |
|
4362 |
||
4363 |
if (strncmp(work2, "italic", 6) == 0) { |
|
4364 |
fdwItalic = TRUE; |
|
4365 |
if ( work2[6] == '-' ) |
|
4366 |
strncpy( work, &work2[7], ( strlen( work2) - 7) ); |
|
4367 |
} else { |
|
4368 |
if (strncmp(work2, "oblique", 7) == 0) { |
|
4369 |
fdwItalic = TRUE; |
|
4370 |
if ( work2[7] == '-' ) |
|
4371 |
strncpy( work, &work2[8], ( strlen( work2) - 8) ); |
|
4372 |
} |
|
4373 |
} |
|
4374 |
if (strncmp( work, "underline", 9 ) == 0 ) { |
|
4375 |
fdwUnderline = TRUE; |
|
4376 |
if( work[10] == '-' ) |
|
4377 |
strncpy( work2, &work[11], ( strlen( work ) - 10 ) ); |
|
4378 |
} |
|
4379 |
if (strncmp( work2, "strikeOut", 9 ) == 0 ) { |
|
4380 |
fdwStrikeOut = TRUE; |
|
4381 |
} |
|
2323 | 4382 |
} |
4383 |
||
4384 |
DPRINTF(("CreateFont face:%s h=%d w=%d wght=%d\n", |
|
2344 | 4385 |
faceName, nHeight, nWidth, fnWeight)); |
2323 | 4386 |
|
4387 |
hFont = CreateFont( -nHeight, /* character height - not cell height */ |
|
2344 | 4388 |
nWidth, |
4389 |
nEscapement, |
|
4390 |
nOrientation, |
|
4391 |
fnWeight, |
|
4392 |
fdwItalic, |
|
4393 |
fdwUnderline, |
|
4394 |
fdwStrikeOut, |
|
4395 |
fdwCharSet, |
|
4396 |
fdwOutputPrecision, |
|
4397 |
fdwClipPrecision, |
|
4398 |
fdwQuality, |
|
4399 |
fdwPitchAndFamily, |
|
4400 |
faceName ); |
|
2323 | 4401 |
|
4402 |
if (hFont != NULL) { |
|
2344 | 4403 |
DPRINTF(("createFont: %x\n", hFont)); |
2323 | 4404 |
/* |
4405 |
#ifdef COUNT_RESOURCES |
|
2344 | 4406 |
__cnt_font++; |
4407 |
RES1PRINTF(("CreateFont %d\n", __cnt_font)); |
|
2323 | 4408 |
#endif |
4409 |
*/ |
|
2344 | 4410 |
RETURN ( __MKOBJ(hFont) ); |
2323 | 4411 |
} |
4412 |
||
4413 |
DPRINTF(("***** ERROR createFontWithFoundry failed ERROR *****\n" )); |
|
4414 |
%}. |
|
4415 |
^ nil |
|
4416 |
||
4417 |
" |
|
4418 |
Display getFontWithFoundry:'*' |
|
2344 | 4419 |
family:'courier' |
4420 |
weight:'medium' |
|
4421 |
slant:'r' |
|
4422 |
spacing:nil |
|
4423 |
pixelSize:nil |
|
4424 |
size:13 |
|
4425 |
registry:'iso8859' |
|
4426 |
encoding:'*' |
|
2323 | 4427 |
" |
4428 |
||
4429 |
"new NT Version: 20.2.1997 / 22:33:29 / dq" |
|
4430 |
! |
|
4431 |
||
4432 |
primFontMetricsOf:fontId hdc:aDC intoArray:rawData |
|
4433 |
"evaluate aBlock, passing a fonts metrics as arguments. |
|
4434 |
fill passed array as: |
|
4435 |
ascent -> (data at:1) |
|
4436 |
descent -> (data at:2) |
|
4437 |
maxAscent -> (data at:3) |
|
4438 |
maxDescent -> (data at:4) |
|
4439 |
minWidth -> (data at:5) |
|
4440 |
maxWidth -> (data at:6) |
|
4441 |
avgWidth -> (data at:7). |
|
4442 |
minChar -> (data at:8). |
|
4443 |
maxChar -> (data at:9). |
|
4444 |
defaultChar-> (data at:10). |
|
4445 |
charSet -> (data at:11). |
|
4446 |
" |
|
4447 |
||
4448 |
%{ |
|
4449 |
||
4450 |
if (__isExternalAddress(fontId) |
|
4451 |
&& __isExternalAddressLike(aDC) |
|
4452 |
&& __isArray(rawData) |
|
4453 |
&& (__arraySize(rawData) >= 11)) { |
|
2344 | 4454 |
SIZE size; |
4455 |
int avgWidth; |
|
4456 |
HGDIOBJ hFont; |
|
4457 |
HGDIOBJ prevFont; |
|
4458 |
TEXTMETRIC tmet; |
|
4459 |
static char *s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; |
|
4460 |
static int len; |
|
4461 |
OBJ t; |
|
4462 |
HANDLE hDC; |
|
4463 |
||
4464 |
hFont = _HGDIOBJVal(fontId); |
|
4465 |
hDC = (HANDLE)(__externalAddressVal(aDC)); |
|
4466 |
||
4467 |
/* |
|
4468 |
* temporarily set this font in the tmpDC (root-) context |
|
4469 |
*/ |
|
4470 |
||
4471 |
prevFont = SelectObject(hDC, hFont); |
|
4472 |
||
4473 |
GetTextMetricsW(hDC, &tmet); |
|
4474 |
if (len == 0) { |
|
4475 |
len = strlen(s); |
|
4476 |
} |
|
2323 | 4477 |
#if 0 |
2344 | 4478 |
GetTextExtentPoint32(hDC, s, len, &size); |
4479 |
avgWidth = (size.cx / (len / 2) + 1) / 2; |
|
2323 | 4480 |
#else |
2344 | 4481 |
avgWidth = tmet.tmAveCharWidth; |
2323 | 4482 |
#endif |
4483 |
||
2344 | 4484 |
__ArrayInstPtr(rawData)->a_element[0] = __MKSMALLINT(tmet.tmAscent); /* ascent -> (data at:1) */ |
4485 |
__ArrayInstPtr(rawData)->a_element[1] = __MKSMALLINT(tmet.tmDescent); /* descent -> (data at:2) */ |
|
4486 |
__ArrayInstPtr(rawData)->a_element[2] = __MKSMALLINT(tmet.tmAscent); /* maxAscent -> (data at:3) */ |
|
4487 |
__ArrayInstPtr(rawData)->a_element[3] = __MKSMALLINT(tmet.tmDescent); /* maxDescent -> (data at:4) */ |
|
4488 |
__ArrayInstPtr(rawData)->a_element[4] = __MKSMALLINT(avgWidth); /* minWidth -> (data at:5) */ |
|
4489 |
__ArrayInstPtr(rawData)->a_element[5] = __MKSMALLINT(tmet.tmMaxCharWidth); /* maxWidth -> (data at:6) */ |
|
4490 |
__ArrayInstPtr(rawData)->a_element[6] = __MKSMALLINT(avgWidth); /* avgWidth -> (data at:7) */ |
|
4491 |
__ArrayInstPtr(rawData)->a_element[7] = __MKSMALLINT(tmet.tmFirstChar); /* min -> (data at:8) */ |
|
4492 |
__ArrayInstPtr(rawData)->a_element[8] = __MKSMALLINT(tmet.tmLastChar); /* max -> (data at:9) */ |
|
4493 |
__ArrayInstPtr(rawData)->a_element[9] = __MKSMALLINT(tmet.tmDefaultChar); /* default -> (data at:10) */ |
|
2323 | 4494 |
#if 0 |
2344 | 4495 |
t = __charSetSymbolFor(tmet.tmCharSet); |
4496 |
__ArrayInstPtr(rawData)->a_element[10]= t; __STORE(rawData, t); /* charSet -> (data at:11) */ |
|
2323 | 4497 |
#endif |
4498 |
||
2344 | 4499 |
DPRINTF(("textMetrics h=%x avgAsc=%d avgDesc=%d minW=%d maxW=%d avgW=%d\n", |
4500 |
hFont, tmet.tmAscent, tmet.tmDescent, avgWidth, tmet.tmMaxCharWidth, |
|
4501 |
tmet.tmAveCharWidth)); |
|
4502 |
||
4503 |
SelectObject(hDC, prevFont); |
|
4504 |
RETURN (self); |
|
2323 | 4505 |
} |
4506 |
RETURN (nil); |
|
4507 |
%} |
|
4508 |
! |
|
4509 |
||
4510 |
releaseFont:aFontId |
|
4511 |
||
4512 |
%{ /* NOCONTEXT */ |
|
4513 |
if (__isExternalAddress(aFontId)) { |
|
2344 | 4514 |
HGDIOBJ hFont = _HGDIOBJVal(aFontId); |
4515 |
||
4516 |
if (hFont) { |
|
4517 |
DPRINTF(("ReleaseFont: %x\n", hFont)); |
|
4518 |
DeleteObject(hFont); |
|
4519 |
} |
|
2323 | 4520 |
} |
4521 |
%} |
|
4522 |
! |
|
4523 |
||
4524 |
setFont:aFontId in:aDC |
|
4525 |
"set font to be drawn in" |
|
4526 |
||
4527 |
%{ /* NOCONTEXT */ |
|
4528 |
||
4529 |
if (__isExternalAddressLike(aDC) |
|
4530 |
&& __isExternalAddress(aFontId)) |
|
4531 |
{ |
|
2344 | 4532 |
HANDLE hDC = (HANDLE)(__externalAddressVal(aDC)); |
4533 |
HGDIOBJ prevFont, hFont; |
|
4534 |
||
4535 |
hFont = _HGDIOBJVal(aFontId); |
|
4536 |
prevFont = SelectObject(hDC, hFont); |
|
4537 |
||
4538 |
RETURN ( self ); |
|
2323 | 4539 |
} |
4540 |
%}. |
|
4541 |
self primitiveFailed |
|
4542 |
||
4543 |
"Created: / 04-08-2006 / 12:32:53 / fm" |
|
4544 |
! |
|
4545 |
||
4546 |
widthOf:aString from:index1 to:index2 inFont:aFontId |
|
4547 |
||
4548 |
%{ /* NOCONTEXT */ |
|
4549 |
unsigned char *cp; |
|
4550 |
int len, n, i1, i2, l; |
|
4551 |
OBJ cls; |
|
4552 |
int nInstBytes; |
|
4553 |
||
4554 |
if (__bothSmallInteger(index1, index2) |
|
4555 |
&& __isExternalAddress(aFontId) |
|
4556 |
&& __isExternalAddressLike(__INST(gcId)) |
|
4557 |
&& __isNonNilObject(aString)) { |
|
2344 | 4558 |
HGDIOBJ hFont,prevFont; |
4559 |
HANDLE hDC; |
|
4560 |
SIZE tsize; |
|
2323 | 4561 |
|
4562 |
#ifndef PRE_22_FEP_2007 |
|
4563 |
# define N_QUICK_CHARS 1024 |
|
2344 | 4564 |
unsigned short quickWchars[N_QUICK_CHARS]; |
4565 |
unsigned short *wcharPtr; |
|
4566 |
int mustFree = 0; |
|
4567 |
int i; |
|
2323 | 4568 |
#endif |
4569 |
||
2344 | 4570 |
hFont = _HGDIOBJVal(aFontId); |
4571 |
hDC = (HANDLE)(__externalAddressVal(__INST(gcId))); |
|
4572 |
||
4573 |
prevFont = SelectObject(hDC, hFont); |
|
4574 |
||
4575 |
i1 = __intVal(index1) - 1; |
|
4576 |
cls = __qClass(aString); |
|
4577 |
||
4578 |
if (i1 >= 0) { |
|
4579 |
i2 = __intVal(index2) - 1; |
|
4580 |
if (i2 < i1) { |
|
4581 |
RETURN ( __MKSMALLINT( 0 ) ); |
|
4582 |
} |
|
4583 |
||
4584 |
cp = (char *) _stringVal(aString); |
|
4585 |
l = i2 - i1 + 1; |
|
4586 |
||
4587 |
if ((cls == @global(String)) || (cls == @global(Symbol))) { |
|
4588 |
n = _stringSize(aString); |
|
2323 | 4589 |
commonWidthChars: |
2344 | 4590 |
if (i2 < n) { |
4591 |
cp += i1; |
|
2323 | 4592 |
|
4593 |
#ifdef PRE_22_FEP_2007 |
|
2344 | 4594 |
GetTextExtentPoint32(hDC, cp, l, &tsize); |
2323 | 4595 |
#else |
2344 | 4596 |
if (l <= N_QUICK_CHARS) { |
4597 |
wcharPtr = quickWchars; |
|
4598 |
mustFree = 0; |
|
4599 |
} else { |
|
4600 |
wcharPtr = malloc(sizeof(short)*l); |
|
4601 |
if (! wcharPtr) RETURN (__MKSMALLINT(0)); |
|
4602 |
mustFree = 1; |
|
4603 |
} |
|
4604 |
for (i=0; i<l; i++) wcharPtr[i] = ((unsigned char *)cp)[i]; |
|
4605 |
GetTextExtentPoint32W(hDC, wcharPtr, l, &tsize); |
|
4606 |
if (mustFree) free(wcharPtr); |
|
2323 | 4607 |
#endif |
4608 |
||
4609 |
#ifdef SUPERDEBUG |
|
2344 | 4610 |
if (__debug__) { |
4611 |
char buf[80]; |
|
4612 |
||
4613 |
GetTextFace(hDC,80,buf); |
|
4614 |
console_printf("font1 %x %s >%s< l=%d dx=%d\n",hFont,buf,cp,l,tsize.cx); |
|
4615 |
} |
|
2323 | 4616 |
#endif |
2344 | 4617 |
SelectObject(hDC, prevFont); |
4618 |
RETURN ( __MKSMALLINT(tsize.cx) ); |
|
4619 |
} |
|
4620 |
RETURN (__MKSMALLINT(0)); |
|
4621 |
} |
|
4622 |
||
4623 |
nInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
4624 |
cp += nInstBytes; |
|
4625 |
n = __byteArraySize(aString) - nInstBytes; |
|
4626 |
||
4627 |
if (__isBytes(aString)) { |
|
4628 |
goto commonWidthChars; |
|
4629 |
} |
|
4630 |
||
4631 |
/* Unicode */ |
|
4632 |
if (__isWords(aString)) { |
|
4633 |
n = n / 2; |
|
4634 |
if (i2 < n) { |
|
4635 |
WIDECHAR *w_cp = (WIDECHAR *)cp; |
|
4636 |
||
4637 |
w_cp += i1; |
|
4638 |
||
4639 |
GetTextExtentPoint32W(hDC, w_cp, l, &tsize); |
|
4640 |
SelectObject(hDC, prevFont); |
|
4641 |
RETURN ( __MKSMALLINT(tsize.cx) ); |
|
4642 |
} |
|
4643 |
RETURN (__MKSMALLINT(0)); |
|
4644 |
} |
|
4645 |
} |
|
2323 | 4646 |
} |
4647 |
%}. |
|
4648 |
self primitiveFailed. |
|
4649 |
^ 0 |
|
4650 |
! |
|
4651 |
||
4652 |
widthOf:aString inFont:aFontId |
|
4653 |
"return the width in pixels of a string in a specific font" |
|
4654 |
||
4655 |
^ self widthOf:aString from:1 to:(aString size) inFont:aFontId |
|
2316 | 4656 |
! ! |
4657 |
||
2299 | 4658 |
!WinPrinterContext methodsFor:'initialization & release'! |
4659 |
||
4660 |
createDC |
|
4661 |
"Private - Create a device context for the receiver" |
|
2317 | 4662 |
|
2299 | 4663 |
gcId := printerInfo createDC |
4664 |
||
4665 |
"Created: / 27-07-2006 / 10:21:05 / fm" |
|
4666 |
"Modified: / 02-08-2006 / 17:30:47 / fm" |
|
4667 |
"Modified: / 10-10-2006 / 18:14:28 / cg" |
|
4668 |
! |
|
4669 |
||
2315 | 4670 |
deleteDC |
4671 |
"Private - Delete a device context for the receiver" |
|
4672 |
||
4673 |
OperatingSystem deletePrinterDC: gcId. |
|
4674 |
! |
|
4675 |
||
2323 | 4676 |
destroy |
4677 |
"Destroy the GC." |
|
4678 |
||
4679 |
|id| |
|
4680 |
||
4681 |
id := gcId. |
|
4682 |
id notNil ifTrue:[ |
|
2344 | 4683 |
gcId := nil. |
4684 |
self deleteDC. |
|
2323 | 4685 |
]. |
4686 |
"/ Lobby unregister:self. |
|
4687 |
! |
|
4688 |
||
4689 |
destroyGC:aDC |
|
4690 |
%{ |
|
4691 |
if (__isExternalAddressLike(aDC)) { |
|
2344 | 4692 |
HANDLE hDC = (HANDLE)(__externalAddressVal(aDC)); |
4693 |
||
4694 |
DeleteDC(hDC); |
|
2323 | 4695 |
|
4696 |
/* |
|
4697 |
#ifdef CACHE_LAST_DC |
|
2344 | 4698 |
if (lastGcData == gcData) { |
4699 |
_releaseDC(gcData); |
|
4700 |
} |
|
2323 | 4701 |
#endif |
4702 |
*/ |
|
4703 |
||
4704 |
} |
|
4705 |
%} |
|
4706 |
! |
|
4707 |
||
2299 | 4708 |
executor |
4709 |
|aCopy| |
|
4710 |
||
4711 |
aCopy := WinWorkstation::PrinterDeviceContextHandle basicNew. |
|
4712 |
aCopy setDevice:device id:nil gcId:gcId. |
|
4713 |
^ aCopy |
|
4714 |
||
4715 |
"Created: / 16-04-2007 / 12:39:02 / cg" |
|
2315 | 4716 |
! |
4717 |
||
2323 | 4718 |
initialize |
4719 |
super initialize. |
|
4720 |
"/ deviceForms := Registry new. |
|
4721 |
"/ deviceColors := Registry new. |
|
4722 |
deviceFonts := CachingRegistry new cacheSize:10. |
|
4723 |
! |
|
4724 |
||
2315 | 4725 |
releaseDC |
4726 |
"Private - Delete and clear the device context of the receiver." |
|
4727 |
||
4728 |
self deleteDC. |
|
2316 | 4729 |
"/ device close. |
2323 | 4730 |
gcId := nil. |
4731 |
self releaseDeviceFonts |
|
4732 |
! |
|
4733 |
||
4734 |
releaseDeviceFonts |
|
4735 |
deviceFonts isEmptyOrNil ifFalse:[ |
|
2344 | 4736 |
deviceFonts do:[:afont | |
4737 |
afont releaseFromDevice. |
|
4738 |
]. |
|
2323 | 4739 |
]. |
4740 |
deviceFonts := CachingRegistry new cacheSize:10. |
|
4741 |
! ! |
|
4742 |
||
2328 | 4743 |
!WinPrinterContext methodsFor:'non standard methods'! |
4744 |
||
4745 |
stringWidthOf:aString at:index |
|
4746 |
"Return the width of aString up to index |
|
4747 |
when written using the current font; expand tabs out |
|
4748 |
to 4 spaces for calculations" |
|
4749 |
||
4750 |
|answer str size spaceWidth| |
|
4751 |
||
4752 |
index <= 0 ifTrue:[ ^ 0 ]. |
|
4753 |
str := index >= aString size ifTrue:[ aString ] ifFalse:[ aString copyFrom:1 to:index ]. |
|
4754 |
true "self font isNil" ifTrue:[ |
|
2344 | 4755 |
"if font not set yet, calculate based on default font" |
4756 |
"/ extString := str asExternalString. |
|
4757 |
size := Win32OperatingSystem::WinPointStructure new. |
|
4758 |
(OperatingSystem |
|
4759 |
getTextExtentPoint:gcId |
|
4760 |
string:str |
|
4761 |
size:size) ifFalse:[ ^ self error ]. |
|
4762 |
answer := size x. |
|
2328 | 4763 |
"/ Transcript showCR: 'FROM PRIM ******* ', str, ' ', answer printString. |
4764 |
"/ Transcript showCR: 'FROM DEVICE ***** ', str, ' ',(self font widthOf:str on:self device) printString. |
|
2344 | 4765 |
#TODO. |
2328 | 4766 |
] ifFalse:[ |
2344 | 4767 |
answer := self font widthOf:str on:self device |
2328 | 4768 |
]. |
4769 |
index > aString size ifTrue:[ |
|
2344 | 4770 |
spaceWidth := self font widthOf:Character space on:self device. |
4771 |
answer := answer + ((index - aString size) * spaceWidth) |
|
2328 | 4772 |
]. |
4773 |
^ answer. |
|
4774 |
||
4775 |
"Created: / 03-08-2006 / 10:27:20 / fm" |
|
4776 |
"Modified: / 04-08-2006 / 12:27:26 / fm" |
|
4777 |
"Modified: / 10-10-2006 / 18:20:43 / cg" |
|
4778 |
! ! |
|
4779 |
||
2323 | 4780 |
!WinPrinterContext methodsFor:'not supported yet'! |
4781 |
||
4782 |
displayAdvanceLineFrom:point1 to:point2 |
|
4783 |
"draw a line" |
|
4784 |
||
4785 |
self displayAdvanceLineFromX:(point1 x) y:(point1 y) |
|
2344 | 4786 |
toX:(point2 x) y:(point2 y) |
2323 | 4787 |
! |
4788 |
||
4789 |
displayAdvanceLineFromX:x0 y:y0 toX:x1 y:y1 |
|
4790 |
"draw a line (with current paint-color); apply transformation if nonNil" |
|
4791 |
||
4792 |
|pX0 pY0 pX1 pY1 easy fgId bgId| |
|
4793 |
||
4794 |
gcId isNil ifTrue:[ |
|
2344 | 4795 |
self initGC |
2323 | 4796 |
]. |
4797 |
||
4798 |
lineStyle == #doubleDashed ifTrue:[ |
|
2344 | 4799 |
" |
4800 |
if bgPaint or paint is not a real color, we have to do it the hard way ... |
|
4801 |
" |
|
4802 |
easy := true. |
|
4803 |
paint isColor ifFalse:[ |
|
4804 |
easy := false |
|
4805 |
] ifTrue:[ |
|
4806 |
fgId := paint colorId. |
|
4807 |
fgId isNil ifTrue:[ |
|
4808 |
easy := false |
|
4809 |
] |
|
4810 |
]. |
|
4811 |
bgPaint isColor ifFalse:[ |
|
4812 |
easy := false |
|
4813 |
] ifTrue:[ |
|
4814 |
bgId := bgPaint colorId. |
|
4815 |
bgId isNil ifTrue:[ |
|
4816 |
easy := false |
|
4817 |
] |
|
4818 |
]. |
|
4819 |
||
4820 |
easy ifTrue:[ |
|
4821 |
((foreground ~~ paint) or:[background ~~ bgPaint]) ifTrue:[ |
|
4822 |
device setForeground:fgId background:bgId in:gcId. |
|
4823 |
foreground := paint. |
|
4824 |
background := bgPaint. |
|
4825 |
]. |
|
4826 |
] ifFalse:[ |
|
4827 |
'DeviceGraphicsContext [warning]: cannot draw dashes with dithered colors' errorPrintCR |
|
4828 |
]. |
|
2323 | 4829 |
]. |
4830 |
||
4831 |
transformation notNil ifTrue:[ |
|
2344 | 4832 |
pX0 := transformation applyToX:x0. |
4833 |
pY0 := transformation applyToY:y0. |
|
4834 |
pX1 := transformation applyToX:x1. |
|
4835 |
pY1 := transformation applyToY:y1. |
|
2323 | 4836 |
] ifFalse:[ |
2344 | 4837 |
pX0 := x0. |
4838 |
pY0 := y0. |
|
4839 |
pX1 := x1. |
|
4840 |
pY1 := y1 |
|
2323 | 4841 |
]. |
4842 |
||
4843 |
pX0 := pX0 rounded. |
|
4844 |
pY0 := pY0 rounded. |
|
4845 |
pX1 := pX1 rounded. |
|
4846 |
pY1 := pY1 rounded. |
|
4847 |
||
4848 |
device displayAdvanceLineFromX:pX0 y:pY0 toX:pX1 y:pY1 in:drawableId with:gcId |
|
4849 |
||
4850 |
"Modified: 10.1.1997 / 17:46:32 / cg" |
|
4851 |
! |
|
4852 |
||
4853 |
displayAdvanceLineFromX:x0 y:y0 toX:x1 y:y1 in:ignoredDrawableId with:aDC |
|
4854 |
"draw a line. If the coordinates are not integers, an error is triggered." |
|
4855 |
||
4856 |
self getPenForMyContext. |
|
4857 |
||
4858 |
%{ /* NOCONTEXT */ |
|
4859 |
if (__isExternalAddressLike(aDC) |
|
4860 |
&& __bothSmallInteger(x0, y0) |
|
4861 |
&& __bothSmallInteger(x1, y1)) { |
|
2344 | 4862 |
HANDLE hDC = (HANDLE)(__externalAddressVal(aDC)); |
4863 |
COLORREF fgColor; |
|
4864 |
int __x1 = __intVal(x1), __y1 = __intVal(y1); |
|
2323 | 4865 |
|
4866 |
||
4867 |
/* DPRINTF(("displayLine: %d/%d -> %d/%d\n", |
|
2344 | 4868 |
__intVal(x0), __intVal(y0), |
4869 |
__x1, __y1)); |
|
2323 | 4870 |
*/ |
4871 |
||
4872 |
/* fgColor = GetTextColor(hDC); |
|
4873 |
* hPen = CreatePen(PS_SOLID, 1, fgColor); |
|
4874 |
*/ |
|
4875 |
||
2344 | 4876 |
MoveToEx(hDC, __intVal(x0), __intVal(y0), NULL); |
4877 |
||
4878 |
LineTo(hDC, __x1, __y1); |
|
4879 |
||
4880 |
/* |
|
4881 |
* end-point ... |
|
4882 |
*/ |
|
4883 |
LineTo(hDC, __x1+1, __y1); |
|
4884 |
||
4885 |
||
4886 |
||
4887 |
RETURN ( self ); |
|
2323 | 4888 |
} |
4889 |
%} |
|
4890 |
! |
|
4891 |
||
2328 | 4892 |
gcForBitmap:aDrawableId |
4893 |
||
4894 |
%{ /* NOCONTEXT */ |
|
4895 |
||
4896 |
if (__isExternalAddress(aDrawableId)){ |
|
2338 | 4897 |
BITMAP bitmap; |
4898 |
HBITMAP hBitmap = _HBITMAPVAL(aDrawableId); |
|
4899 |
HBITMAP memBM; |
|
4900 |
HANDLE compatibleDC, rootDC, hdcScreen; |
|
2328 | 4901 |
// HANDLE printerDC = (HANDLE)(__externalAddressVal(__INST(gcId))); |
4902 |
||
2338 | 4903 |
if (! hBitmap) { |
4904 |
RETURN (nil); |
|
4905 |
} |
|
4906 |
||
4907 |
if (GetObject(hBitmap, sizeof(bitmap), &bitmap)) { |
|
2328 | 4908 |
/* |
2338 | 4909 |
DDPRINTF(("bitmap info:%d\n", bitmap.bmBitsPixel)); |
2328 | 4910 |
*/ |
2338 | 4911 |
} else { |
2328 | 4912 |
/* |
2338 | 4913 |
DPRINTF(("noinfo returned for bitmap\n")); |
2328 | 4914 |
*/ |
2338 | 4915 |
/* mhmh - can this happen ? */ |
4916 |
bitmap.bmBitsPixel = 1; |
|
4917 |
} |
|
2328 | 4918 |
/* |
2338 | 4919 |
gcData->hBitmap = hBitmap; |
4920 |
gcData->bitmapColorBitCount = bitmap.bmBitsPixel; |
|
2328 | 4921 |
*/ |
4922 |
||
2338 | 4923 |
rootDC = CreateDC("DISPLAY", NULL, NULL, NULL); |
4924 |
compatibleDC = CreateCompatibleDC(rootDC); |
|
4925 |
SelectObject(compatibleDC, hBitmap); |
|
2328 | 4926 |
|
4927 |
// hdcScreen= CreateDC("NULL", NULL, NULL, NULL); |
|
4928 |
// compatibleDC = rootDC; |
|
4929 |
// compatibleDC = CreateCompatibleDC(printerDC); |
|
4930 |
// compatibleDC = CreateCompatibleDC(0); |
|
2338 | 4931 |
|
2328 | 4932 |
// memBM = CreateCompatibleBitmap ( compatibleDC, bitmap.bmWidth, bitmap.bmHeight ); |
4933 |
// SelectObject ( compatibleDC, memBM ); |
|
4934 |
||
2338 | 4935 |
RETURN (__MKOBJ(compatibleDC)); |
2328 | 4936 |
|
4937 |
/* |
|
2338 | 4938 |
RETURN ( __MKOBJ(gcData) ); |
2328 | 4939 |
*/ |
4940 |
} |
|
4941 |
RETURN (nil); |
|
4942 |
%} |
|
4943 |
! |
|
4944 |
||
2324 | 4945 |
getPenForMyContext |
4946 |
"Get a pen for my context" |
|
4947 |
||
4948 |
|maskOriginX maskOriginY| |
|
4949 |
||
4950 |
self maskOrigin isNil ifFalse:[ |
|
2344 | 4951 |
maskOriginX := self maskOrigin x. |
4952 |
maskOriginY := self maskOrigin y. |
|
2324 | 4953 |
]. |
4954 |
||
2325 | 4955 |
%{ |
2324 | 4956 |
HPEN hPen = 0; |
4957 |
HPEN prevPen; |
|
4958 |
LOGBRUSH Brush; |
|
4959 |
COLORREF fgColor; |
|
4960 |
HANDLE hDC = (HANDLE)(__externalAddressVal(__INST(gcId))); |
|
4961 |
int lStyle, bkMode, hMask, maskOrgX, maskOrgY; |
|
4962 |
int style, lineStyle, capStyle, joinStyle; |
|
4963 |
int lw; |
|
4964 |
int BK_TRANSPARENT; |
|
4965 |
||
4966 |
BK_TRANSPARENT = 1; |
|
4967 |
||
4968 |
lw= __INST(lineWidth); |
|
4969 |
/* fgColor = __intVal(__INST(foreground)) & 0xffffff; */ |
|
4970 |
||
2325 | 4971 |
fgColor = GetTextColor(hDC); |
2324 | 4972 |
lineStyle=__INST(lineStyle); |
4973 |
capStyle=__INST(capStyle); |
|
4974 |
joinStyle=__INST(joinStyle); |
|
4975 |
hMask= __INST(mask); |
|
4976 |
maskOrgX=__intVal(maskOriginX); |
|
4977 |
maskOrgY=__intVal(maskOriginY); |
|
4978 |
||
4979 |
if (lineStyle == @symbol(solid)) { |
|
2344 | 4980 |
style = PS_SOLID; |
2324 | 4981 |
} else if (lineStyle == @symbol(dashed)) { |
2344 | 4982 |
style= PS_DASH; |
2324 | 4983 |
} else if (lineStyle == @symbol(dotted)) { |
2344 | 4984 |
style= PS_DOT; |
2324 | 4985 |
} else if (lineStyle == @symbol(dashDot)) { |
2344 | 4986 |
style= PS_DASHDOT; |
2324 | 4987 |
} else if (lineStyle == @symbol(dashDotDot)) { |
2344 | 4988 |
style= PS_DASHDOTDOT; |
2324 | 4989 |
} else |
2344 | 4990 |
style= PS_SOLID; |
2324 | 4991 |
lStyle &= ~PS_STYLE_MASK; |
4992 |
lStyle |= style; |
|
4993 |
||
4994 |
||
4995 |
if (capStyle == @symbol(round)) { |
|
2344 | 4996 |
style = PS_ENDCAP_ROUND; |
2324 | 4997 |
} else if (capStyle == @symbol(square)) { |
2344 | 4998 |
style = PS_ENDCAP_SQUARE; |
2324 | 4999 |
} else if (capStyle == @symbol(flat)) { |
2344 | 5000 |
style = PS_ENDCAP_FLAT; |
2324 | 5001 |
} else |
2344 | 5002 |
style = PS_ENDCAP_FLAT; |
2324 | 5003 |
lStyle &= ~PS_ENDCAP_MASK; |
5004 |
lStyle |= style; |
|
5005 |
||
5006 |
if (joinStyle == @symbol(bevel)) { |
|
2344 | 5007 |
style = PS_JOIN_BEVEL; |
2324 | 5008 |
} else if (joinStyle == @symbol(miter)) { |
2344 | 5009 |
style = PS_JOIN_MITER; |
2324 | 5010 |
} else if (joinStyle == @symbol(round)) { |
2344 | 5011 |
style = PS_JOIN_ROUND; |
2324 | 5012 |
} else |
2344 | 5013 |
style = PS_JOIN_MITER; |
2324 | 5014 |
lStyle &= ~PS_JOIN_MASK; |
5015 |
lStyle |= style; |
|
5016 |
||
5017 |
||
5018 |
if (((lStyle & PS_STYLE_MASK) == PS_SOLID) |
|
5019 |
&& (hMask == 0) |
|
5020 |
&& (lw /* lineWidth */ <= 1)) { |
|
2344 | 5021 |
if (fgColor == 0 /* BlackPixel */ ) { |
5022 |
hPen = GetStockObject(BLACK_PEN); |
|
5023 |
prevPen = SelectObject(hDC, hPen); |
|
5024 |
RETURN( hPen ); |
|
5025 |
} |
|
5026 |
if (fgColor == 1 /* WhitePixel */) { |
|
5027 |
hPen = GetStockObject(WHITE_PEN); |
|
5028 |
prevPen = SelectObject(hDC, hPen); |
|
5029 |
RETURN( hPen ); |
|
5030 |
} |
|
2324 | 5031 |
} |
5032 |
||
5033 |
hPen = (HPEN) 0; |
|
5034 |
||
5035 |
if (0 /* __isWinNT */) { |
|
5036 |
||
2344 | 5037 |
if (lw == 0) { |
5038 |
lw = 1; |
|
5039 |
} |
|
5040 |
/* |
|
5041 |
* NT supports masked drawing with any lineStyle, |
|
5042 |
* and also non-solid lines with any lineWidth. |
|
5043 |
*/ |
|
5044 |
if (hMask) { |
|
5045 |
Brush.lbStyle = BS_PATTERN; |
|
5046 |
Brush.lbHatch = (DWORD)hMask; |
|
5047 |
Brush.lbColor = fgColor; |
|
5048 |
} else { |
|
2324 | 5049 |
|
5050 |
#ifndef PRE_07_APR_04 |
|
5051 |
||
2344 | 5052 |
hPen = CreatePen((lStyle & PS_STYLE_MASK), lw, fgColor); |
2324 | 5053 |
|
5054 |
/* RESPRINTF(("CreatePen %x %d(%d) %x %x\n", |
|
5055 |
* lStyle, |
|
5056 |
* lw, __INST(lineWidth), |
|
5057 |
* fgColor, hMask)); |
|
5058 |
*/ |
|
5059 |
||
2344 | 5060 |
SetBkMode(hDC, TRANSPARENT); |
5061 |
bkMode = BK_TRANSPARENT; |
|
2324 | 5062 |
|
5063 |
#else |
|
2344 | 5064 |
Brush.lbStyle = BS_SOLID; |
5065 |
Brush.lbHatch = 0; |
|
5066 |
Brush.lbColor = fgColor; |
|
2324 | 5067 |
#endif |
2344 | 5068 |
} |
5069 |
||
5070 |
if (! hPen) |
|
5071 |
{ |
|
5072 |
hPen = ExtCreatePen(PS_GEOMETRIC | lStyle, |
|
5073 |
lw, /* lineWidth, */ |
|
5074 |
&Brush, |
|
5075 |
0, 0); |
|
2324 | 5076 |
|
5077 |
/* RESPRINTF(("ExtCreatePen1 %x %d(%d) %x %x\n", |
|
5078 |
* lStyle, |
|
5079 |
* lw, __INST(lineWidth), |
|
5080 |
* fgColor, hMask)); |
|
5081 |
*/ |
|
2344 | 5082 |
if (hMask) { |
5083 |
SetBrushOrgEx(hDC, maskOrgX, maskOrgY, 0); |
|
5084 |
} |
|
5085 |
} |
|
2324 | 5086 |
} else { |
2344 | 5087 |
/* |
5088 |
* W95 only supports masked drawing with SOLID lines |
|
5089 |
* also, we should use COSMETIC pens if possible |
|
5090 |
* with non-solid lineStyles. |
|
5091 |
*/ |
|
5092 |
if ((lStyle & PS_STYLE_MASK) == PS_SOLID) { |
|
5093 |
int ps = PS_GEOMETRIC; |
|
5094 |
||
5095 |
if (hMask) { |
|
5096 |
Brush.lbStyle = BS_PATTERN; |
|
5097 |
Brush.lbHatch = (DWORD)hMask; |
|
5098 |
Brush.lbColor = fgColor; |
|
5099 |
} else { |
|
5100 |
Brush.lbStyle = BS_SOLID; |
|
5101 |
Brush.lbHatch = 0; |
|
5102 |
Brush.lbColor = fgColor; |
|
5103 |
if (lw /* lineWidth */ <= 1) { |
|
5104 |
ps = PS_COSMETIC; |
|
5105 |
} |
|
5106 |
} |
|
5107 |
||
5108 |
hPen = ExtCreatePen(ps | lStyle, |
|
5109 |
lw, /* lineWidth */ |
|
5110 |
&Brush, |
|
5111 |
0, 0); |
|
2324 | 5112 |
|
5113 |
/* RESPRINTF(("ExtCreatePen1 %x %d %x %x\n", |
|
5114 |
* lStyle, |
|
2325 | 5115 |
* lw, |
2324 | 5116 |
* fgColor, hMask)); |
5117 |
*/ |
|
2344 | 5118 |
if (hMask) { |
5119 |
SetBrushOrgEx(hDC, maskOrgX, maskOrgY, 0); |
|
5120 |
} |
|
5121 |
} else { |
|
5122 |
||
5123 |
if (lw == 1) { |
|
5124 |
lw = 0; |
|
5125 |
} |
|
5126 |
||
5127 |
/* |
|
5128 |
* dashes only supported with lineWidth 0 |
|
5129 |
*/ |
|
5130 |
||
5131 |
hPen = CreatePen((lStyle & PS_STYLE_MASK), |
|
5132 |
lw, |
|
5133 |
fgColor); |
|
2324 | 5134 |
|
5135 |
/* RESPRINTF(("CreatePen %x %d %x\n", |
|
5136 |
* (lStyle & PS_STYLE_MASK), |
|
2325 | 5137 |
* lw, |
2324 | 5138 |
* fgColor)); |
5139 |
*/ |
|
2344 | 5140 |
// |
5141 |
// CG: wrong; must set to opaque, if doubleDashed |
|
5142 |
// |
|
5143 |
SetBkMode(hDC, TRANSPARENT); |
|
5144 |
bkMode = BK_TRANSPARENT; |
|
5145 |
} |
|
2324 | 5146 |
} |
5147 |
||
5148 |
prevPen = SelectObject(hDC, hPen); |
|
5149 |
||
5150 |
RETURN (hPen); |
|
5151 |
||
5152 |
%} |
|
5153 |
! |
|
5154 |
||
2328 | 5155 |
xprimDrawBits:imageBits bitsPerPixel:bitsPerPixel depth:imageDepth padding:padd width:imageWidth height:imageHeight |
2344 | 5156 |
x:srcx y:srcy |
5157 |
into:ignoredDrawableId |
|
5158 |
x:dstx y:dsty |
|
5159 |
width:w height:h |
|
5160 |
with:aDC |
|
2328 | 5161 |
|
5162 |
"since XPutImage may allocate huge amount of stack space |
|
5163 |
(some implementations use alloca), this must run with unlimited stack." |
|
5164 |
||
5165 |
%{ |
|
5166 |
unsigned char fastBits[10000]; |
|
5167 |
unsigned char *b_bits = 0; |
|
5168 |
unsigned char *allocatedBits = 0; |
|
5169 |
unsigned char *__imageBits = 0; |
|
5170 |
||
5171 |
if (__isByteArray(imageBits)) { |
|
2344 | 5172 |
__imageBits = __ByteArrayInstPtr(imageBits)->ba_element; |
2328 | 5173 |
} else if (__isExternalBytesLike(imageBits)) { |
2344 | 5174 |
__imageBits = (unsigned char *)(__externalBytesAddress(imageBits)); |
2328 | 5175 |
} |
5176 |
||
5177 |
if (/* ISCONNECTED |
|
5178 |
&& */ __isExternalAddressLike(aDC) |
|
5179 |
&& __bothSmallInteger(srcx, srcy) |
|
5180 |
&& __bothSmallInteger(dstx, dsty) |
|
5181 |
&& __bothSmallInteger(w, h) |
|
5182 |
&& __bothSmallInteger(imageWidth, imageHeight) |
|
5183 |
&& __bothSmallInteger(imageDepth, bitsPerPixel) |
|
5184 |
&& __isSmallInteger(padd) |
|
5185 |
&& __imageBits) |
|
5186 |
{ |
|
2344 | 5187 |
HANDLE hDC = (HANDLE)(__externalAddressVal(aDC)); |
5188 |
struct |
|
5189 |
{ |
|
5190 |
BITMAPINFOHEADER bmiHeader; |
|
5191 |
DWORD r; |
|
5192 |
DWORD g; |
|
5193 |
DWORD b; |
|
5194 |
} bitmap; |
|
5195 |
||
5196 |
if (__intVal(padd) != WIN32PADDING) { |
|
5197 |
int row, col; |
|
5198 |
unsigned char *cp; |
|
5199 |
unsigned char *pBits; |
|
5200 |
int b_width, b_height, bytesPerRowST, bytesPerRowWN, padding, nBytes; |
|
5201 |
int bi = __intVal(bitsPerPixel); |
|
5202 |
||
5203 |
b_width = __intVal(w); |
|
5204 |
b_height = __intVal(h); |
|
5205 |
bytesPerRowST = (b_width * bi + (__intVal(padd)-1)) / __intVal(padd); |
|
5206 |
bytesPerRowWN = (b_width * bi + (WIN32PADDING-1)) / WIN32PADDING * (WIN32PADDING/8); |
|
5207 |
padding = bytesPerRowWN - bytesPerRowST; |
|
5208 |
nBytes = b_height * bytesPerRowWN; |
|
5209 |
/*console_printf("padd %d bs %d bw %d p %d\n",__intVal(padd),bytesPerRowST,bytesPerRowWN,padding);*/ |
|
5210 |
if (padding) { |
|
5211 |
if (nBytes < sizeof(fastBits)) { |
|
5212 |
cp = b_bits = fastBits; |
|
5213 |
} else { |
|
5214 |
cp = b_bits = allocatedBits = (unsigned char *) malloc(nBytes); |
|
5215 |
} |
|
5216 |
if (cp) { |
|
5217 |
pBits = __imageBits; |
|
5218 |
for (row = b_height; row; row--) { |
|
5219 |
for (col = bytesPerRowST; col; col--) { |
|
5220 |
*cp++ = *pBits++; |
|
5221 |
} |
|
5222 |
cp += padding; |
|
5223 |
} |
|
5224 |
} else |
|
5225 |
goto fail; |
|
5226 |
} |
|
5227 |
} |
|
5228 |
||
5229 |
if (b_bits == 0) { |
|
5230 |
b_bits = __imageBits; |
|
5231 |
} |
|
5232 |
||
5233 |
bitmap.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); |
|
5234 |
bitmap.bmiHeader.biPlanes = 1; |
|
5235 |
if (__intVal(imageDepth) == 24) { |
|
5236 |
/*bitmap.bmiHeader.biCompression = BI_BITFIELDS; |
|
5237 |
bitmap.r = 0xff0000; |
|
5238 |
bitmap.g = 0x00ff00; |
|
5239 |
bitmap.b = 0x0000ff;*/ |
|
5240 |
bitmap.bmiHeader.biCompression = BI_RGB; |
|
5241 |
} else if (__intVal(imageDepth) == 16) { |
|
5242 |
/*bitmap.bmiHeader.biCompression = BI_RGB; |
|
5243 |
bitmap.bmiHeader.biCompression = BI_BITFIELDS; |
|
5244 |
bitmap.b = 0x001f; |
|
5245 |
bitmap.g = 0x07e0; |
|
5246 |
bitmap.r = 0xf800;*/ |
|
5247 |
bitmap.b = 0; |
|
5248 |
bitmap.g = 0; |
|
5249 |
bitmap.r = 0; |
|
5250 |
bitmap.bmiHeader.biCompression = BI_RGB; |
|
5251 |
} |
|
5252 |
bitmap.bmiHeader.biSizeImage = 0; |
|
5253 |
bitmap.bmiHeader.biXPelsPerMeter = 0; |
|
5254 |
bitmap.bmiHeader.biYPelsPerMeter = 0; |
|
5255 |
bitmap.bmiHeader.biClrUsed = 0; |
|
5256 |
bitmap.bmiHeader.biClrImportant = 0; |
|
5257 |
bitmap.bmiHeader.biWidth = __intVal(imageWidth); |
|
5258 |
bitmap.bmiHeader.biHeight = -(__intVal(imageHeight)); |
|
5259 |
bitmap.bmiHeader.biBitCount = __intVal(bitsPerPixel); |
|
5260 |
/*console_printf("drawBits depth:%d bitsPerPixel:%d IW%d W:%d H:%d\n",__intVal(imageDepth),bitmap.bmiHeader.biBitCount,bitmap.bmiHeader.biWidth,__intVal(w),bitmap.bmiHeader.biHeight);*/ |
|
5261 |
SetDIBitsToDevice(hDC,__intVal(dstx),__intVal(dsty), |
|
5262 |
__intVal(w), __intVal(h), |
|
5263 |
__intVal(srcx), __intVal(srcy), |
|
5264 |
0,__intVal(h), |
|
5265 |
(void *)b_bits, |
|
5266 |
(BITMAPINFO*)&bitmap,DIB_RGB_COLORS); |
|
5267 |
if (allocatedBits) { |
|
5268 |
free(allocatedBits); |
|
5269 |
} |
|
5270 |
RETURN ( true ); |
|
2328 | 5271 |
} |
5272 |
||
5273 |
fail: ; |
|
5274 |
/* |
|
5275 |
PRINTF(("create temp bitmap FAILED!!!\n")); |
|
5276 |
*/ |
|
5277 |
if (allocatedBits) { |
|
5278 |
/* |
|
2344 | 5279 |
PRINTF(("freeing up temp bitmap bits ...\n")); |
2328 | 5280 |
*/ |
2344 | 5281 |
free(allocatedBits); |
2328 | 5282 |
} |
5283 |
%} |
|
5284 |
. |
|
5285 |
^ false |
|
5286 |
! |
|
5287 |
||
2323 | 5288 |
xxxdisplayLineFromX:x0 y:y0 toX:x1 y:y1 in:ignoredDrawableId with:aDC |
5289 |
"draw a line. If the coordinates are not integers, an error is triggered." |
|
5290 |
||
5291 |
|penHandle| |
|
5292 |
||
5293 |
penHandle := ExternalBytes address: self getPenForMyContext. |
|
5294 |
||
5295 |
%{ /* NOCONTEXT */ |
|
5296 |
if (__isExternalAddressLike(aDC) |
|
5297 |
&& __isExternalAddressLike(penHandle) |
|
5298 |
&& __bothSmallInteger(x0, y0) |
|
5299 |
&& __bothSmallInteger(x1, y1)) { |
|
2344 | 5300 |
HANDLE hDC = (HANDLE)(__externalAddressVal(aDC)); |
5301 |
HANDLE hPen = (HANDLE)(__externalAddressVal(penHandle)); |
|
5302 |
COLORREF fgColor; |
|
5303 |
HANDLE prevPen; |
|
5304 |
int __x1 = __intVal(x1), __y1 = __intVal(y1); |
|
2323 | 5305 |
|
5306 |
||
5307 |
/* DPRINTF(("displayLine: %d/%d -> %d/%d\n", |
|
2344 | 5308 |
__intVal(x0), __intVal(y0), |
5309 |
__x1, __y1)); |
|
2323 | 5310 |
*/ |
5311 |
||
5312 |
/* fgColor = GetTextColor(hDC); |
|
5313 |
* hPen = CreatePen(PS_SOLID, 1, fgColor); |
|
5314 |
*/ |
|
5315 |
||
2344 | 5316 |
prevPen = SelectObject(hDC, hPen); |
5317 |
||
5318 |
MoveToEx(hDC, __intVal(x0), __intVal(y0), NULL); |
|
5319 |
||
5320 |
LineTo(hDC, __x1, __y1); |
|
5321 |
||
5322 |
/* |
|
5323 |
* end-point ... |
|
5324 |
*/ |
|
5325 |
LineTo(hDC, __x1+1, __y1); |
|
5326 |
||
5327 |
SelectObject(hDC, prevPen); |
|
5328 |
||
5329 |
||
5330 |
RETURN ( self ); |
|
2323 | 5331 |
} |
5332 |
%} |
|
2299 | 5333 |
! ! |
5334 |
||
5335 |
!WinPrinterContext methodsFor:'printing process'! |
|
5336 |
||
5337 |
endPage |
|
5338 |
"Informs device that we are finished writing to a page." |
|
2317 | 5339 |
|
2299 | 5340 |
(OperatingSystem endPage:gcId) > 0 ifFalse:[ |
2344 | 5341 |
self error |
2299 | 5342 |
] |
5343 |
||
5344 |
"Created: / 27-07-2006 / 18:20:48 / fm" |
|
5345 |
"Modified: / 01-08-2006 / 16:01:34 / fm" |
|
5346 |
"Modified: / 10-10-2006 / 18:14:44 / cg" |
|
5347 |
! |
|
5348 |
||
2315 | 5349 |
endPrintJobWithoutRelease |
2299 | 5350 |
"End the print job. Everything drawn between startPrintJob |
5351 |
and endPrintJob will become one entry in the print queue." |
|
2317 | 5352 |
|
2299 | 5353 |
|result| |
5354 |
||
5355 |
self endPage. |
|
5356 |
result := OperatingSystem endDoc:gcId. |
|
5357 |
jobid := nil. |
|
5358 |
result >= 0 ifFalse:[ self error ] |
|
5359 |
||
5360 |
"Created: / 27-07-2006 / 18:21:04 / fm" |
|
5361 |
"Modified: / 01-08-2006 / 16:01:38 / fm" |
|
5362 |
"Modified: / 10-10-2006 / 18:50:43 / cg" |
|
5363 |
! |
|
5364 |
||
2330 | 5365 |
getSupportsColor |
5366 |
||
5367 |
| retVal info | |
|
5368 |
||
5369 |
info := (self class getPrinterInformationString: self name) asUppercase. |
|
5370 |
(info includesSubString: ',PSCRIPT,') |
|
5371 |
ifTrue: [ |
|
2347 | 5372 |
retVal := true. |
5373 |
"/ retVal := (DAPASX::DapasSystemInfo getYesNoInfoApp: 'Printer' profile: 'PostScriptBlackWhite') not. |
|
2330 | 5374 |
] |
5375 |
ifFalse: [ |
|
5376 |
retVal := (info includesSubString: 'PDF') |
|
5377 |
ifTrue: [true] |
|
5378 |
ifFalse: [self numberOfColorBitsPerPixel > 1]. |
|
5379 |
]. |
|
5380 |
||
5381 |
^retVal |
|
5382 |
! |
|
5383 |
||
2299 | 5384 |
startPage |
5385 |
"Starts a page." |
|
2317 | 5386 |
|
2299 | 5387 |
(OperatingSystem startPage:gcId) > 0 ifFalse:[ |
2344 | 5388 |
^ self error |
2299 | 5389 |
]. |
5390 |
||
5391 |
"Created: / 27-07-2006 / 18:25:55 / fm" |
|
5392 |
"Modified: / 28-07-2006 / 18:19:04 / fm" |
|
5393 |
"Modified: / 10-10-2006 / 18:19:02 / cg" |
|
5394 |
! |
|
5395 |
||
2317 | 5396 |
startPrintJob:aString fileName:aFileName |
2299 | 5397 |
"Start a print job, using aString as the job title; everything |
5398 |
drawn between startPrintJob and endPrintJob will become |
|
5399 |
one entry in the print queue." |
|
2317 | 5400 |
|
2299 | 5401 |
|docInfoStruct nameAddress title fileNameAddress| |
5402 |
||
5403 |
gcId isNil ifTrue:[ |
|
2344 | 5404 |
self buildPrinter |
2299 | 5405 |
]. |
5406 |
abort := false. |
|
5407 |
title := aString ? 'Smalltalk/X'. |
|
5408 |
nameAddress := title asExternalBytes unprotectFromGC. |
|
5409 |
aFileName isNil ifFalse:[ |
|
2344 | 5410 |
fileNameAddress := aFileName pathName asExternalBytes unprotectFromGC |
2299 | 5411 |
]. |
5412 |
docInfoStruct := Win32OperatingSystem::DocInfoStructure new. |
|
5413 |
docInfoStruct |
|
2344 | 5414 |
cbSize:docInfoStruct sizeInBytes; |
5415 |
lpszDocName:nameAddress address. |
|
2299 | 5416 |
fileNameAddress isNil ifFalse:[ |
2344 | 5417 |
docInfoStruct lpszOutput:fileNameAddress address |
2299 | 5418 |
]. |
5419 |
jobid := OperatingSystem startDoc:gcId docInfo:docInfoStruct. |
|
5420 |
jobid > 0 ifFalse:[ |
|
2344 | 5421 |
jobid = -1 ifTrue:[ |
5422 |
abort := true. |
|
5423 |
^ nil |
|
5424 |
]. |
|
5425 |
^ self error |
|
2299 | 5426 |
]. |
5427 |
self startPage |
|
5428 |
||
5429 |
"Created: / 27-07-2006 / 18:19:31 / fm" |
|
5430 |
"Modified: / 03-08-2006 / 15:11:19 / fm" |
|
5431 |
"Modified: / 10-10-2006 / 18:20:01 / cg" |
|
5432 |
! ! |
|
5433 |
||
5434 |
!WinPrinterContext methodsFor:'queries'! |
|
5435 |
||
2323 | 5436 |
hasGrayscales |
5437 |
"return true, if this workstation supports grayscales |
|
5438 |
(also true for color displays)" |
|
5439 |
||
5440 |
^ true |
|
5441 |
! |
|
5442 |
||
5443 |
isOpen |
|
5444 |
||
5445 |
^ gcId notNil |
|
5446 |
! |
|
5447 |
||
2324 | 5448 |
isPersistentInSnapshot |
5449 |
"return true, if resources on this device are to be made |
|
5450 |
persistent in a snapshot image." |
|
5451 |
||
5452 |
^ false |
|
5453 |
! |
|
5454 |
||
2299 | 5455 |
supportsColor |
5456 |
||
2330 | 5457 |
supportsColor isNil ifTrue:[supportsColor := self getSupportsColor]. |
5458 |
^supportsColor |
|
2299 | 5459 |
! |
5460 |
||
5461 |
supportsGraphics |
|
2301
135f21a3d127
refactorred OS-independent stuff
Claus Gittinger <cg@exept.de>
parents:
2299
diff
changeset
|
5462 |
^(OperatingSystem getDeviceCaps: gcId index: 2 "Technology") ~= 4 |
2299 | 5463 |
|
5464 |
"Created: / 03-08-2006 / 10:07:43 / fm" |
|
2301
135f21a3d127
refactorred OS-independent stuff
Claus Gittinger <cg@exept.de>
parents:
2299
diff
changeset
|
5465 |
"Modified: / 16-04-2007 / 12:44:03 / cg" |
2299 | 5466 |
! ! |
5467 |
||
2323 | 5468 |
!WinPrinterContext methodsFor:'registration'! |
5469 |
||
5470 |
registerFont:aFont |
|
5471 |
deviceFonts register:aFont. |
|
5472 |
! |
|
5473 |
||
5474 |
unregisterFont:aFont |
|
5475 |
deviceFonts unregister:aFont. |
|
5476 |
! ! |
|
5477 |
||
2299 | 5478 |
!WinPrinterContext class methodsFor:'documentation'! |
5479 |
||
5480 |
version |
|
2347 | 5481 |
^ '$Header: /cvs/stx/stx/libview2/WinPrinterContext.st,v 1.23 2007-11-08 13:06:18 fm Exp $' |
2299 | 5482 |
! ! |