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