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