author | ca |
Tue, 23 Oct 2007 07:08:45 +0200 | |
changeset 2342 | 78014f6a3c32 |
parent 2341 | cf7b3de4f3ef |
child 2343 | b7ef200fbfad |
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)) { |
|
2342 | 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", |
|
2342 | 1659 |
__intVal(x0), __intVal(y0), |
1660 |
__x1, __y1)); |
|
2323 | 1661 |
*/ |
1662 |
||
2342 | 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 |
||
2342 | 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 |
LineTo(hDC, xL+w, yT+h); // move pen one pixel more |
|
1972 |
||
1973 |
SelectObject(hDC, prevPen); |
|
1974 |
DeleteObject(hPen); |
|
1975 |
||
1976 |
} |
|
1977 |
RETURN ( self ); |
|
2323 | 1978 |
} |
1979 |
%}. |
|
1980 |
self primitiveFailed |
|
1981 |
||
1982 |
"Created: / 28-07-2006 / 20:18:25 / fm" |
|
1983 |
! |
|
1984 |
||
1985 |
displayString:aString from:index1 to:index2 x:x y:y in:aDrawableId with:aGCId |
|
1986 |
"draw a sub-string - draw foreground only. |
|
1987 |
If the coordinates are not integers, retry with rounded." |
|
1988 |
||
1989 |
self |
|
2328 | 1990 |
displayString:aString |
1991 |
from:index1 |
|
1992 |
to:index2 |
|
1993 |
x:x |
|
1994 |
y:y |
|
1995 |
in:aDrawableId |
|
1996 |
with:aGCId |
|
1997 |
opaque:false |
|
2323 | 1998 |
! |
1999 |
||
2000 |
displayString:aString from:index1 to:index2 x:x y:y in:ignoredDrawableId with:aDC opaque:opaque |
|
2001 |
"draw a sub-string - if opaque is false, draw foreground only; otherwise, draw both |
|
2002 |
foreground and background characters. |
|
2003 |
If the coordinates are not integers, an error is triggered." |
|
2004 |
||
2005 |
%{ /* NOCONTEXT */ |
|
2006 |
unsigned char *cp; |
|
2007 |
OBJ cls; |
|
2008 |
int i1, i2, l, n; |
|
2009 |
int nInstBytes; |
|
2010 |
||
2011 |
if (__isExternalAddressLike(aDC) |
|
2012 |
&& __isNonNilObject(aString) |
|
2013 |
&& __bothSmallInteger(index1, index2) |
|
2014 |
&& __bothSmallInteger(x, y)) |
|
2015 |
{ |
|
2327 | 2016 |
HANDLE hDC = (HANDLE)(__externalAddressVal(aDC)); |
2017 |
int pX, pY; |
|
2018 |
COLORREF fgColor; |
|
2019 |
||
2020 |
pX = __intVal(x); |
|
2021 |
pY = __intVal(y); |
|
2022 |
||
2023 |
if (opaque == true) { |
|
2024 |
SetBkMode(hDC, OPAQUE); |
|
2025 |
} else { |
|
2026 |
SetBkMode(hDC, TRANSPARENT); |
|
2027 |
} |
|
2028 |
fgColor = GetTextColor(hDC); |
|
2029 |
SetTextColor(hDC, fgColor); |
|
2030 |
SetBkColor(hDC, 0xFFFFFFFF); |
|
2031 |
||
2032 |
cls = __qClass(aString); |
|
2033 |
||
2034 |
i1 = __intVal(index1) - 1; |
|
2035 |
if (i1 >= 0) { |
|
2036 |
i2 = __intVal(index2) - 1; |
|
2037 |
if (i2 < i1) { |
|
2038 |
goto ret; |
|
2039 |
} |
|
2040 |
||
2041 |
cp = _stringVal(aString); |
|
2042 |
l = i2 - i1 + 1; |
|
2043 |
||
2044 |
if ((cls == @global(String)) || (cls == @global(Symbol))) { |
|
2045 |
n = _stringSize(aString); |
|
2046 |
if (i2 < n) { |
|
2047 |
cp += i1; |
|
2048 |
DPRINTF(("string1: %s pos=%d/%d l=%d hDC=%x\n", cp, pX, pY,l,hDC)); |
|
2049 |
||
2050 |
if (l > 32767) { |
|
2051 |
l = 32767; |
|
2052 |
} |
|
2053 |
if (! TextOut(hDC, pX, pY, (char *)cp, l)) { |
|
2054 |
DFPRINTF((stderr, "WinPrinter [warning]: Textout failed. %d\n", GetLastError())); |
|
2055 |
} |
|
2056 |
goto ret; |
|
2057 |
} |
|
2058 |
} |
|
2059 |
||
2060 |
nInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
2061 |
cp += nInstBytes; |
|
2062 |
n = __byteArraySize(aString) - nInstBytes; |
|
2063 |
||
2064 |
if (__isBytes(aString)) { |
|
2065 |
if (i2 < n) { |
|
2066 |
cp += i1; |
|
2067 |
DPRINTF(("string: %s pos=%d/%d\n", cp, pX, pY)); |
|
2068 |
if (l > 32767) { |
|
2069 |
l = 32767; |
|
2070 |
} |
|
2071 |
if (! TextOut(hDC, pX, pY, (char *)cp, l)) { |
|
2072 |
DFPRINTF((stderr, "WinPrinter [warning]: Textout failed. %d\n", GetLastError())); |
|
2073 |
} |
|
2074 |
goto ret; |
|
2075 |
} |
|
2076 |
} |
|
2077 |
||
2078 |
/* Unicode */ |
|
2079 |
if (__isWords(aString)) { |
|
2080 |
n = n / 2; |
|
2081 |
if (i2 < n) { |
|
2082 |
WIDECHAR *w_cp = (WIDECHAR *)cp; |
|
2083 |
||
2084 |
w_cp += i1; |
|
2085 |
||
2086 |
if (! TextOutW(hDC, pX, pY, w_cp, l)) { |
|
2087 |
DFPRINTF((stderr, "WinPrinter [warning]: TextoutW failed. %d\n", GetLastError())); |
|
2088 |
} |
|
2089 |
goto ret; |
|
2090 |
} |
|
2091 |
} |
|
2092 |
} |
|
2323 | 2093 |
ret: |
2327 | 2094 |
RETURN ( self ); |
2323 | 2095 |
} |
2096 |
%}. |
|
2097 |
self primitiveFailed |
|
2098 |
||
2099 |
"Created: / 28-07-2006 / 20:35:19 / fm" |
|
2100 |
! |
|
2101 |
||
2102 |
displayString:aString from:index1 to:index2 x:x y:y in:ignoredDrawableId with:aDC opaque:opaque fontAscent:fontAscent |
|
2103 |
"draw a sub-string - if opaque is false, draw foreground only; otherwise, draw both |
|
2104 |
foreground and background characters. |
|
2105 |
If the coordinates are not integers, an error is triggered." |
|
2106 |
||
2107 |
%{ /* NOCONTEXT */ |
|
2108 |
unsigned char *cp; |
|
2109 |
OBJ cls; |
|
2110 |
int i1, i2, l, n; |
|
2111 |
int nInstBytes; |
|
2112 |
||
2113 |
if (__isExternalAddressLike(aDC) |
|
2114 |
&& __isNonNilObject(aString) |
|
2115 |
&& __bothSmallInteger(index1, index2) |
|
2116 |
&& __bothSmallInteger(x, y)) |
|
2117 |
{ |
|
2327 | 2118 |
HANDLE hDC = (HANDLE)(__externalAddressVal(aDC)); |
2119 |
int pX, pY; |
|
2120 |
COLORREF fgColor; |
|
2121 |
||
2122 |
pX = __intVal(x); |
|
2123 |
pY = __intVal(y); |
|
2124 |
pY -= __intVal(fontAscent); |
|
2125 |
||
2126 |
if (opaque == true) { |
|
2127 |
SetBkMode(hDC, OPAQUE); |
|
2128 |
} else { |
|
2129 |
SetBkMode(hDC, TRANSPARENT); |
|
2130 |
} |
|
2131 |
fgColor = GetTextColor(hDC); |
|
2132 |
SetTextColor(hDC, fgColor); |
|
2133 |
SetBkColor(hDC, 0xFFFFFFFF); |
|
2134 |
||
2135 |
cls = __qClass(aString); |
|
2136 |
||
2137 |
i1 = __intVal(index1) - 1; |
|
2138 |
if (i1 >= 0) { |
|
2139 |
i2 = __intVal(index2) - 1; |
|
2140 |
if (i2 < i1) { |
|
2141 |
goto ret; |
|
2142 |
} |
|
2143 |
||
2144 |
cp = _stringVal(aString); |
|
2145 |
l = i2 - i1 + 1; |
|
2146 |
||
2147 |
if ((cls == @global(String)) || (cls == @global(Symbol))) { |
|
2148 |
n = _stringSize(aString); |
|
2149 |
if (i2 < n) { |
|
2150 |
cp += i1; |
|
2151 |
DPRINTF(("string1: %s pos=%d/%d l=%d hDC=%x\n", cp, pX, pY,l,hDC)); |
|
2152 |
||
2153 |
if (l > 32767) { |
|
2154 |
l = 32767; |
|
2155 |
} |
|
2156 |
if (! TextOut(hDC, pX, pY, (char *)cp, l)) { |
|
2157 |
DFPRINTF((stderr, "WinPrinter [warning]: Textout failed. %d\n", GetLastError())); |
|
2158 |
} |
|
2159 |
goto ret; |
|
2160 |
} |
|
2161 |
} |
|
2162 |
||
2163 |
nInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
2164 |
cp += nInstBytes; |
|
2165 |
n = __byteArraySize(aString) - nInstBytes; |
|
2166 |
||
2167 |
if (__isBytes(aString)) { |
|
2168 |
if (i2 < n) { |
|
2169 |
cp += i1; |
|
2170 |
DPRINTF(("string: %s pos=%d/%d\n", cp, pX, pY)); |
|
2171 |
if (l > 32767) { |
|
2172 |
l = 32767; |
|
2173 |
} |
|
2174 |
if (! TextOut(hDC, pX, pY, (char *)cp, l)) { |
|
2175 |
DFPRINTF((stderr, "WinPrinter [warning]: Textout failed. %d\n", GetLastError())); |
|
2176 |
} |
|
2177 |
goto ret; |
|
2178 |
} |
|
2179 |
} |
|
2180 |
||
2181 |
/* Unicode */ |
|
2182 |
if (__isWords(aString)) { |
|
2183 |
n = n / 2; |
|
2184 |
if (i2 < n) { |
|
2185 |
WIDECHAR *w_cp = (WIDECHAR *)cp; |
|
2186 |
||
2187 |
w_cp += i1; |
|
2188 |
||
2189 |
if (! TextOutW(hDC, pX, pY, w_cp, l)) { |
|
2190 |
DFPRINTF((stderr, "WinPrinter [warning]: TextoutW failed. %d\n", GetLastError())); |
|
2191 |
} |
|
2192 |
goto ret; |
|
2193 |
} |
|
2194 |
} |
|
2195 |
} |
|
2323 | 2196 |
ret: |
2327 | 2197 |
RETURN ( self ); |
2323 | 2198 |
} |
2199 |
%}. |
|
2200 |
self primitiveFailed |
|
2201 |
||
2202 |
"Created: / 28-07-2006 / 20:35:19 / fm" |
|
2203 |
! |
|
2204 |
||
2205 |
displayString:aString x:x y:y in:aDrawableId with:aDC |
|
2206 |
"draw a string - draw foreground only. |
|
2207 |
If the coordinates are not integers, retry with rounded." |
|
2208 |
||
2209 |
self |
|
2328 | 2210 |
displayString:aString |
2211 |
x:x |
|
2212 |
y:y |
|
2213 |
in:aDrawableId |
|
2214 |
with:aDC |
|
2215 |
opaque:false |
|
2323 | 2216 |
! |
2217 |
||
2218 |
displayString:aString x:x y:y in:aDrawableId with:aDC opaque:opaque |
|
2219 |
"draw a string" |
|
2220 |
||
2221 |
self displayString:aString |
|
2328 | 2222 |
from:1 |
2223 |
to:aString size |
|
2224 |
x:x |
|
2225 |
y:y |
|
2226 |
in:aDrawableId |
|
2227 |
with:aDC |
|
2228 |
opaque:opaque |
|
2323 | 2229 |
! |
2230 |
||
2231 |
fillArcX:x y:y width:width height:height from:startAngle angle:angle |
|
2330 | 2232 |
in:ignoredDrawableId with:aDC |
2323 | 2233 |
"fill an arc. If any coordinate is not integer, an error is triggered. |
2234 |
The angles may be floats or integer - they are given in degrees." |
|
2235 |
||
2330 | 2236 |
| hatchSymbol | |
2237 |
||
2238 |
hatchSymbol := self hatch. |
|
2239 |
||
2323 | 2240 |
%{ |
2241 |
int __x, __y, w, h; |
|
2242 |
float angle1, angle2; |
|
2243 |
||
2244 |
if (__isSmallInteger(startAngle)) |
|
2330 | 2245 |
angle1 = (float)(__intVal(startAngle)); |
2323 | 2246 |
else if (__isFloat(startAngle)) { |
2330 | 2247 |
angle1 = __floatVal(startAngle); |
2323 | 2248 |
} else if (__isShortFloat(startAngle)) { |
2330 | 2249 |
angle1 = __shortFloatVal(startAngle); |
2323 | 2250 |
} else goto bad; |
2251 |
||
2252 |
if (__isSmallInteger(angle)) |
|
2330 | 2253 |
angle2 = (float)(__intVal(angle)); |
2323 | 2254 |
else if (__isFloat(angle)) { |
2330 | 2255 |
angle2 = __floatVal(angle); |
2323 | 2256 |
} else if (__isShortFloat(angle)) { |
2330 | 2257 |
angle2 = __shortFloatVal(angle); |
2323 | 2258 |
} else goto bad; |
2259 |
||
2260 |
if (angle2 <= 0) { |
|
2330 | 2261 |
RETURN (self); |
2323 | 2262 |
} |
2263 |
||
2264 |
if (__isExternalAddressLike(aDC) |
|
2265 |
&& __bothSmallInteger(x, y) |
|
2266 |
&& __bothSmallInteger(width, height)) |
|
2267 |
{ |
|
2330 | 2268 |
HANDLE hDC = (HANDLE)(__externalAddressVal(aDC)); |
2269 |
HBRUSH hBrush, prevBrush; |
|
2270 |
HPEN prevPen = 0; |
|
2271 |
COLORREF fgColor; |
|
2272 |
int hatch, hasHatch; |
|
2273 |
||
2274 |
w = __intVal(width); |
|
2275 |
h = __intVal(height); |
|
2276 |
__x = __intVal(x); |
|
2277 |
__y = __intVal(y); |
|
2278 |
||
2279 |
fgColor = GetTextColor(hDC); |
|
2280 |
||
2281 |
hasHatch= 1; |
|
2282 |
||
2283 |
if (hatchSymbol == @symbol(none)) { |
|
2284 |
hasHatch= 0; |
|
2285 |
} else if (hatchSymbol == @symbol(horizontal)) { |
|
2286 |
hatch= HS_HORIZONTAL; |
|
2287 |
} else if (hatchSymbol == @symbol(vertical)) { |
|
2288 |
hatch= HS_VERTICAL; |
|
2289 |
} else if (hatchSymbol == @symbol(cross)) { |
|
2290 |
hatch= HS_CROSS; |
|
2291 |
} else if (hatchSymbol == @symbol(bDiagonal)) { |
|
2292 |
hatch= HS_BDIAGONAL; |
|
2293 |
} else if (hatchSymbol == @symbol(fDiagonal)) { |
|
2294 |
hatch= HS_FDIAGONAL; |
|
2295 |
} else if (hatchSymbol == @symbol(diagonalCross)) { |
|
2296 |
hatch= HS_DIAGCROSS; |
|
2297 |
} else |
|
2298 |
hasHatch= 0; |
|
2299 |
||
2300 |
if (hasHatch) { |
|
2301 |
hBrush = CreateHatchBrush(hatch, fgColor); |
|
2302 |
} else { |
|
2303 |
hBrush = CreateSolidBrush(fgColor); |
|
2304 |
} |
|
2305 |
||
2306 |
prevBrush = SelectObject(hDC, hBrush); |
|
2307 |
if (hBrush == 0) { |
|
2308 |
DPRINTF(("fillArc: no brush\n")); |
|
2309 |
} else { |
|
2310 |
HPEN hPen = 0; |
|
2311 |
||
2312 |
if (0 /* __isWinNT */) { |
|
2313 |
fgColor = GetTextColor(hDC); |
|
2314 |
hPen = CreatePen(PS_SOLID, 1, fgColor); |
|
2315 |
prevPen = SelectObject(hDC, hPen); |
|
2316 |
if (hPen == 0) { |
|
2317 |
DPRINTF(("fillArc: no pen\n")); |
|
2318 |
goto failpen; |
|
2319 |
} |
|
2320 |
} else { |
|
2321 |
prevPen = SelectObject(hDC, GetStockObject(NULL_PEN)); |
|
2322 |
w++; |
|
2323 |
h++; |
|
2324 |
} |
|
2325 |
||
2326 |
{ |
|
2327 |
double xB, yB, xE, yE, xR, yR; |
|
2328 |
||
2329 |
xR = w / 2; |
|
2330 |
yR = h / 2; |
|
2331 |
if (angle2 - angle1 >= 360) { |
|
2332 |
xB = xE = __x + xR + 0.5; |
|
2333 |
yB = yE = __y /*+ yR + 0.5*/; |
|
2334 |
} else { |
|
2335 |
double sin(), cos(); |
|
2336 |
float rad1, rad2; |
|
2337 |
||
2338 |
if (angle1 <= 180) |
|
2339 |
angle1 = 180 - angle1; |
|
2340 |
else |
|
2341 |
angle1 = 360 + 180 - angle1; |
|
2342 |
angle2 = angle1 - angle2; |
|
2343 |
/* sigh - compute the intersections ... */ |
|
2344 |
rad1 = (angle1 * 3.14159265359) / 180.0; |
|
2345 |
rad2 = (angle2 * 3.14159265359) / 180.0; |
|
2346 |
xB = cos(rad1) * xR; |
|
2347 |
yB = sin(rad1) * yR; |
|
2348 |
xE = cos(rad2) * xR; |
|
2349 |
yE = sin(rad2) * yR; |
|
2350 |
xB = __x + xR - xB + 0.5; |
|
2351 |
yB = __y + yR - yB + 0.5; |
|
2352 |
xE = __x + xR - xE + 0.5; |
|
2353 |
yE = __y + yR - yE + 0.5; |
|
2354 |
} |
|
2355 |
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)); |
|
2356 |
||
2357 |
Pie(hDC, |
|
2358 |
__x, __y, |
|
2359 |
__x + w + 1, __y + h + 1, |
|
2360 |
(int)xB, (int)yB, |
|
2361 |
(int)xE, (int)yE); |
|
2362 |
||
2363 |
if (hPen) { |
|
2364 |
DeleteObject(hPen); |
|
2365 |
} |
|
2366 |
} |
|
2323 | 2367 |
failpen: |
2330 | 2368 |
if (prevPen) SelectObject(hDC, prevPen); |
2369 |
DeleteObject(hPen); |
|
2370 |
||
2371 |
SelectObject(hDC, prevBrush); |
|
2372 |
DeleteObject(hBrush); |
|
2373 |
} |
|
2374 |
RETURN ( self ); |
|
2323 | 2375 |
} |
2376 |
bad: ; |
|
2377 |
%}. |
|
2378 |
self primitiveFailed |
|
2379 |
! |
|
2380 |
||
2381 |
fillPolygon:aPolygon in:ignoredDrawableId with:aGCId |
|
2382 |
"fill a polygon given by its points. |
|
2383 |
If any coordinate is not integer, an error is triggered." |
|
2384 |
||
2385 |
|numberOfPoints| |
|
2386 |
||
2387 |
numberOfPoints := aPolygon size. |
|
2388 |
self |
|
2328 | 2389 |
primFillPolygon:aPolygon n:numberOfPoints |
2390 |
in:ignoredDrawableId with:aGCId |
|
2323 | 2391 |
! |
2392 |
||
2393 |
fillRectangleX:x y:y width:width height:height in:ignoredDrawableId with:aDC |
|
2394 |
"fill a rectangle. If any coordinate is not integer, an error is triggered." |
|
2395 |
||
2330 | 2396 |
|hatchSymbol| |
2397 |
||
2398 |
hatchSymbol := self hatch. |
|
2399 |
||
2323 | 2400 |
%{ /* NOCONTEXT */ |
2401 |
||
2402 |
int w, h; |
|
2403 |
if (__isExternalAddressLike(aDC) |
|
2404 |
&& __bothSmallInteger(x, y) |
|
2405 |
&& __bothSmallInteger(width, height)) { |
|
2326 | 2406 |
w = __intVal(width); |
2407 |
h = __intVal(height); |
|
2408 |
||
2409 |
if ((w >= 0) && (h >= 0)) { |
|
2410 |
HANDLE hDC = (HANDLE)(__externalAddressVal(aDC)); |
|
2411 |
HBRUSH hBrush, prevBrush; |
|
2412 |
RECT rct; |
|
2413 |
COLORREF fgColor; |
|
2330 | 2414 |
int hatch, hasHatch; |
2326 | 2415 |
|
2416 |
fgColor = GetTextColor(hDC); |
|
2330 | 2417 |
hasHatch= 1; |
2418 |
||
2419 |
if (hatchSymbol == @symbol(none)) { |
|
2420 |
hasHatch= 0; |
|
2421 |
} else if (hatchSymbol == @symbol(horizontal)) { |
|
2422 |
hatch= HS_HORIZONTAL; |
|
2423 |
} else if (hatchSymbol == @symbol(vertical)) { |
|
2424 |
hatch= HS_VERTICAL; |
|
2425 |
} else if (hatchSymbol == @symbol(cross)) { |
|
2426 |
hatch= HS_CROSS; |
|
2427 |
} else if (hatchSymbol == @symbol(bDiagonal)) { |
|
2428 |
hatch= HS_BDIAGONAL; |
|
2429 |
} else if (hatchSymbol == @symbol(fDiagonal)) { |
|
2430 |
hatch= HS_FDIAGONAL; |
|
2431 |
} else if (hatchSymbol == @symbol(diagonalCross)) { |
|
2432 |
hatch= HS_DIAGCROSS; |
|
2433 |
} else |
|
2434 |
hasHatch= 0; |
|
2435 |
||
2436 |
if (hasHatch) { |
|
2437 |
hBrush = CreateHatchBrush(hatch, fgColor); |
|
2438 |
} else { |
|
2439 |
hBrush = CreateSolidBrush(fgColor); |
|
2440 |
} |
|
2441 |
||
2326 | 2442 |
rct.left = __intVal(x); |
2443 |
rct.top = __intVal(y); |
|
2342 | 2444 |
rct.right = rct.left + w; // + 1; |
2445 |
rct.bottom = rct.top + h; // + 1; |
|
2326 | 2446 |
|
2447 |
prevBrush = SelectObject(hDC, hBrush); |
|
2448 |
FillRect(hDC, &rct, hBrush); |
|
2449 |
SelectObject(hDC, prevBrush); |
|
2450 |
DeleteObject(hBrush); |
|
2451 |
||
2452 |
} |
|
2453 |
} |
|
2454 |
RETURN ( self ); |
|
2327 | 2455 |
|
2456 |
||
2323 | 2457 |
%} |
2458 |
! |
|
2459 |
||
2460 |
primFillPolygon:aPolygon n:numberOfPoints in:ignoredDrawableId with:aDC |
|
2461 |
||
2330 | 2462 |
|hatchSymbol| |
2463 |
||
2464 |
hatchSymbol := self hatch. |
|
2465 |
||
2323 | 2466 |
%{ |
2467 |
OBJ point, px, py; |
|
2468 |
int i, num; |
|
2469 |
||
2470 |
if (__isExternalAddressLike(aDC) |
|
2471 |
&& __isSmallInteger(numberOfPoints)) { |
|
2330 | 2472 |
HANDLE hDC = (HANDLE)(__externalAddressVal(aDC)); |
2473 |
POINT p; |
|
2474 |
HBRUSH hBrush, prevBrush; |
|
2475 |
COLORREF fgColor; |
|
2476 |
int hatch, hasHatch; |
|
2477 |
||
2478 |
num = __intVal(numberOfPoints); |
|
2479 |
if (num < 3) { |
|
2480 |
RETURN ( self ); |
|
2481 |
} |
|
2482 |
for (i=0; i<num; i++) { |
|
2483 |
point = __AT_(aPolygon, __MKSMALLINT(i+1)); |
|
2484 |
if (! __isPoint(point)) goto fail; |
|
2485 |
px = _point_X(point); |
|
2486 |
py = _point_Y(point); |
|
2487 |
if (! __bothSmallInteger(px, py)) |
|
2488 |
goto fail; |
|
2489 |
} |
|
2490 |
||
2491 |
fgColor = GetTextColor(hDC); |
|
2492 |
hasHatch= 1; |
|
2493 |
||
2494 |
if (hatchSymbol == @symbol(none)) { |
|
2495 |
hasHatch= 0; |
|
2496 |
} else if (hatchSymbol == @symbol(horizontal)) { |
|
2497 |
hatch= HS_HORIZONTAL; |
|
2498 |
} else if (hatchSymbol == @symbol(vertical)) { |
|
2499 |
hatch= HS_VERTICAL; |
|
2500 |
} else if (hatchSymbol == @symbol(cross)) { |
|
2501 |
hatch= HS_CROSS; |
|
2502 |
} else if (hatchSymbol == @symbol(bDiagonal)) { |
|
2503 |
hatch= HS_BDIAGONAL; |
|
2504 |
} else if (hatchSymbol == @symbol(fDiagonal)) { |
|
2505 |
hatch= HS_FDIAGONAL; |
|
2506 |
} else if (hatchSymbol == @symbol(diagonalCross)) { |
|
2507 |
hatch= HS_DIAGCROSS; |
|
2508 |
} else |
|
2509 |
hasHatch= 0; |
|
2510 |
||
2511 |
if (hasHatch) { |
|
2512 |
hBrush = CreateHatchBrush(hatch, fgColor); |
|
2513 |
} else { |
|
2514 |
hBrush = CreateSolidBrush(fgColor); |
|
2515 |
} |
|
2516 |
||
2517 |
if (hBrush == 0) { |
|
2518 |
DPRINTF(("fillPolygon: no brush\n")); |
|
2519 |
} else { |
|
2520 |
HPEN prevPen; |
|
2521 |
||
2522 |
prevBrush = SelectObject(hDC, hBrush); |
|
2523 |
prevPen = SelectObject(hDC, GetStockObject(NULL_PEN)); |
|
2524 |
||
2525 |
BeginPath(hDC); |
|
2526 |
||
2527 |
for (i=0; i<num; i++) { |
|
2528 |
point = __AT_(aPolygon, __MKSMALLINT(i+1)); |
|
2529 |
px = _point_X(point); |
|
2530 |
py = _point_Y(point); |
|
2531 |
if (i == 0) { |
|
2532 |
MoveToEx(hDC, __intVal(px), __intVal(py), NULL); |
|
2533 |
} else { |
|
2534 |
if (i == (num-1)) { |
|
2535 |
p.x = __intVal(px); |
|
2536 |
p.y = __intVal(py); |
|
2537 |
PolylineTo(hDC, &p, 1); |
|
2538 |
} else { |
|
2539 |
LineTo(hDC, __intVal(px), __intVal(py)); |
|
2540 |
} |
|
2541 |
} |
|
2542 |
} |
|
2543 |
||
2544 |
EndPath(hDC); |
|
2545 |
FillPath(hDC); |
|
2546 |
SelectObject(hDC, prevPen); |
|
2547 |
SelectObject(hDC, prevBrush); |
|
2548 |
DeleteObject(hBrush); |
|
2549 |
} |
|
2550 |
RETURN ( self ); |
|
2323 | 2551 |
|
2552 |
fail: ; |
|
2553 |
} |
|
2554 |
%} |
|
2555 |
! ! |
|
2556 |
||
2557 |
!WinPrinterContext methodsFor:'drawing bitmaps'! |
|
2558 |
||
2559 |
bitsBlue |
|
2560 |
"return the number of valid bits in the red component." |
|
2561 |
||
2562 |
"/ bitsRed isNil ifTrue:[ |
|
2563 |
"/ "/ not a truecolor display |
|
2564 |
"/ ^ bitsPerRGB |
|
2565 |
"/ ]. |
|
2566 |
"/ ^ bitsRed |
|
2567 |
||
2568 |
^Display bitsBlue |
|
2569 |
! |
|
2570 |
||
2571 |
bitsGreen |
|
2572 |
"return the number of valid bits in the red component." |
|
2573 |
||
2574 |
"/ bitsRed isNil ifTrue:[ |
|
2575 |
"/ "/ not a truecolor display |
|
2576 |
"/ ^ bitsPerRGB |
|
2577 |
"/ ]. |
|
2578 |
"/ ^ bitsRed |
|
2579 |
||
2580 |
^Display bitsGreen |
|
2581 |
! |
|
2582 |
||
2583 |
bitsRed |
|
2584 |
"return the number of valid bits in the red component." |
|
2585 |
||
2586 |
"/ bitsRed isNil ifTrue:[ |
|
2587 |
"/ "/ not a truecolor display |
|
2588 |
"/ ^ bitsPerRGB |
|
2589 |
"/ ]. |
|
2590 |
"/ ^ bitsRed |
|
2591 |
||
2592 |
^Display bitsRed |
|
2593 |
! |
|
2594 |
||
2338 | 2595 |
compressColorMapImage: image |
2596 |
"calculates a new color map for the image, using only used colors" |
|
2597 |
||
2598 |
|depth newColorMap newImage oldImage usedColors oldToNew oldBits newBits tmpBits| |
|
2599 |
||
2600 |
oldImage := image. |
|
2601 |
depth := oldImage depth. |
|
2602 |
||
2603 |
oldImage photometric ~~ #palette ifTrue:[ |
|
2604 |
Transcript showCR:'Compress colorMap: Only palette images have colormaps.'. |
|
2605 |
^ image |
|
2606 |
]. |
|
2607 |
||
2608 |
usedColors := oldImage realUsedColors. |
|
2609 |
usedColors size == (1 bitShift:depth) ifTrue:[ |
|
2610 |
Transcript showCR:'Compress colorMap: All colors are used - no compression.'. |
|
2611 |
^ image |
|
2612 |
]. |
|
2613 |
usedColors size == oldImage colorMap size ifTrue:[ |
|
2614 |
Transcript showCR:'Compress colorMap: Colormap already compressed - no compression.'. |
|
2615 |
^ image |
|
2616 |
]. |
|
2617 |
||
2618 |
"/ translation table |
|
2619 |
oldToNew := ByteArray new:(1 bitShift:depth). |
|
2620 |
newColorMap := usedColors asArray. |
|
2621 |
newColorMap sort:self sortBlockForColors. |
|
2622 |
||
2623 |
oldImage colorMap asArray keysAndValuesDo:[:oldIdx :clr | |
|
2624 |
|newPixel| |
|
2625 |
||
2626 |
(usedColors includes:clr) ifTrue:[ |
|
2627 |
newPixel := newColorMap indexOf:clr. |
|
2628 |
oldToNew at:oldIdx put:newPixel-1. |
|
2629 |
] |
|
2630 |
]. |
|
2631 |
||
2632 |
oldBits := oldImage bits. |
|
2633 |
newBits := ByteArray new:(oldBits size). |
|
2634 |
depth ~~ 8 ifTrue:[ |
|
2635 |
"/ expand/compress can only handle 8bits |
|
2636 |
tmpBits := ByteArray uninitializedNew:(oldImage width*oldImage height). |
|
2637 |
oldBits |
|
2638 |
expandPixels:depth |
|
2639 |
width:oldImage width |
|
2640 |
height:oldImage height |
|
2641 |
into:tmpBits |
|
2642 |
mapping:oldToNew. |
|
2643 |
tmpBits |
|
2644 |
compressPixels:depth |
|
2645 |
width:oldImage width |
|
2646 |
height:oldImage height |
|
2647 |
into:newBits |
|
2648 |
mapping:nil |
|
2649 |
] ifFalse:[ |
|
2650 |
oldBits |
|
2651 |
expandPixels:depth |
|
2652 |
width:oldImage width |
|
2653 |
height:oldImage height |
|
2654 |
into:newBits |
|
2655 |
mapping:oldToNew. |
|
2656 |
]. |
|
2657 |
||
2658 |
newImage := oldImage species new |
|
2659 |
width:oldImage width |
|
2660 |
height:oldImage height |
|
2661 |
depth:depth |
|
2662 |
fromArray:newBits. |
|
2663 |
||
2664 |
newImage colorMap:newColorMap. |
|
2665 |
newImage fileName:oldImage fileName. |
|
2666 |
newImage mask:(oldImage mask copy). |
|
2667 |
||
2668 |
^ newImage |
|
2669 |
||
2670 |
"Created: / 28.7.1998 / 20:03:11 / cg" |
|
2671 |
"Modified: / 15.9.1998 / 17:53:32 / cg" |
|
2672 |
! |
|
2673 |
||
2323 | 2674 |
copyFromId:sourceId x:srcX y:srcY gc:srcGCId to:destId x:dstX y:dstY gc:dstGCId |
2338 | 2675 |
width:w height:h |
2323 | 2676 |
"do a bit-blt; copy bits from the rectangle defined by |
2677 |
srcX/srcY and w/h from the sourceId drawable to the rectangle |
|
2678 |
below dstX/dstY in the destId drawable. Trigger an error if any |
|
2679 |
argument is not integer." |
|
2680 |
||
2681 |
%{ |
|
2682 |
int dstGcOwnerThreadID; |
|
2683 |
HWND dstGcHWIN; |
|
2684 |
HBITMAP dstGcHBITMAP; |
|
2685 |
||
2686 |
if (! __isExternalAddressLike(srcGCId) |
|
2687 |
|| ! __isExternalAddressLike(dstGCId)) { |
|
2338 | 2688 |
goto fail; |
2323 | 2689 |
} |
2690 |
||
2691 |
if (__bothSmallInteger(w, h) |
|
2692 |
&& __bothSmallInteger(srcX, srcY) |
|
2693 |
&& __bothSmallInteger(dstX, dstY)) { |
|
2338 | 2694 |
HANDLE srcDC = (HANDLE)(__externalAddressVal(srcGCId)); |
2695 |
HANDLE dstDC = (HANDLE)(__externalAddressVal(dstGCId)); |
|
2696 |
||
2697 |
int fun, aFunctionSymbol; |
|
2698 |
int src_fg, src_bg, dst_fg, dst_bg; |
|
2699 |
char buf[5]; |
|
2323 | 2700 |
|
2701 |
// fun = dstGcData->bitbltrop2; |
|
2702 |
||
2338 | 2703 |
aFunctionSymbol= __INST(function); |
2704 |
||
2705 |
if (aFunctionSymbol == @symbol(copy)) { |
|
2706 |
fun = SRCCOPY /* R2_COPYPEN */ ; |
|
2323 | 2707 |
/* bfun = BITBLT_COPY; */ |
2338 | 2708 |
} else if (aFunctionSymbol == @symbol(copyInverted)) { |
2709 |
fun = NOTSRCCOPY /* R2_NOTCOPYPEN */; |
|
2323 | 2710 |
/* bfun = BITBLT_COPYINVERTED; */ |
2338 | 2711 |
} else if (aFunctionSymbol == @symbol(xor)) { |
2712 |
fun = SRCINVERT /* R2_XORPEN */; |
|
2323 | 2713 |
/* bfun = BITBLT_XOR; */ |
2338 | 2714 |
} else if (aFunctionSymbol == @symbol(and)) { |
2715 |
fun = SRCAND /* R2_MASKPEN */ ; |
|
2323 | 2716 |
/* bfun = BITBLT_AND; */ |
2338 | 2717 |
} else if (aFunctionSymbol == @symbol(or)) { |
2718 |
fun = MERGECOPY /* R2_MERGEPEN */ ; |
|
2323 | 2719 |
/* bfun = BITBLT_OR; */ |
2338 | 2720 |
} |
2323 | 2721 |
|
2722 |
// convert 123 to string [buf] |
|
2324 | 2723 |
// itoa(fun, buf, 10); |
2724 |
||
2725 |
// console_printf(" ", buf); |
|
2323 | 2726 |
|
2727 |
/* |
|
2728 |
#if 0 |
|
2338 | 2729 |
switch (fun) { |
2730 |
case BITBLT_COPY: |
|
2731 |
console_printf("BITBLT_COPY\n"); |
|
2732 |
break; |
|
2733 |
case BITBLT_COPYINVERTED: |
|
2734 |
console_printf("BITBLT_COPYINVERTED\n"); |
|
2735 |
break; |
|
2736 |
case BITBLT_XOR: |
|
2737 |
console_printf("BITBLT_XOR\n"); |
|
2738 |
break; |
|
2739 |
case BITBLT_AND: |
|
2740 |
console_printf("BITBLT_AND\n"); |
|
2741 |
break; |
|
2742 |
case BITBLT_OR: |
|
2743 |
console_printf("BITBLT_OR\n"); |
|
2744 |
break; |
|
2745 |
} |
|
2323 | 2746 |
#endif |
2747 |
*/ |
|
2748 |
||
2749 |
// fun = dstGcData->bitbltrop2; |
|
2750 |
||
2338 | 2751 |
if (0 /* fun == BITBLT_COPY */) { |
2752 |
src_fg = dst_fg = 0xFFFFFF; |
|
2753 |
src_bg = dst_bg = 0x000000; |
|
2754 |
} else { |
|
2755 |
src_fg = GetTextColor(srcDC) /* srcGcData->fgColor */; |
|
2756 |
src_bg = GetBkColor(dstDC) /* srcGcData->bgColor */; |
|
2757 |
dst_fg = GetTextColor(srcDC) /* dstGcData->fgColor */; |
|
2758 |
dst_bg = GetBkColor(dstDC) /* dstGcData->bgColor */; |
|
2759 |
} |
|
2760 |
||
2761 |
SetBkColor(dstDC, dst_fg); |
|
2762 |
SetTextColor(dstDC, dst_bg); |
|
2763 |
||
2764 |
SetBkColor(srcDC, src_fg); |
|
2765 |
SetTextColor(srcDC, src_bg); |
|
2323 | 2766 |
|
2767 |
/* |
|
2338 | 2768 |
CPRINTF(("bitblt src f:%x b:%x",GetTextColor(srcDC),GetBkColor(srcDC))); |
2769 |
CPRINTF(("dst f:%x b:%x\n",GetTextColor(dstDC),GetBkColor(dstDC))); |
|
2323 | 2770 |
*/ |
2338 | 2771 |
if (BitBlt(dstDC, |
2772 |
__intVal(dstX), __intVal(dstY), |
|
2773 |
__intVal(w), __intVal(h), |
|
2774 |
srcDC, |
|
2775 |
__intVal(srcX), __intVal(srcY), |
|
2776 |
fun) |
|
2777 |
== 0 |
|
2778 |
) { |
|
2779 |
console_fprintf(stderr, "WinWorkstation [info]: ERROR in BitBlt\n"); |
|
2780 |
} |
|
2323 | 2781 |
|
2782 |
/* |
|
2338 | 2783 |
if (dstGcData != srcGcData) { |
2784 |
SetBkColor(dstDC, dstGcData->bgColor); |
|
2785 |
SetTextColor(dstDC, dstGcData->fgColor); |
|
2786 |
} |
|
2787 |
SetBkColor(srcDC, srcGcData->bgColor); |
|
2788 |
SetTextColor(srcDC, srcGcData->fgColor); |
|
2323 | 2789 |
*/ |
2790 |
||
2791 |
/* |
|
2338 | 2792 |
if (srcGcData != dstGcData) { |
2793 |
_releaseDC(srcGcData); |
|
2794 |
} |
|
2795 |
_releaseDC(dstGcData); |
|
2323 | 2796 |
*/ |
2338 | 2797 |
RETURN ( self ); |
2323 | 2798 |
} |
2799 |
||
2800 |
fail: ; |
|
2801 |
%}. |
|
2802 |
self primitiveFailed. |
|
2803 |
^ nil |
|
2804 |
! |
|
2805 |
||
2806 |
copyFromPixmapId:sourceId x:srcX y:srcY gc:srcGCId to:destId x:dstX y:dstY gc:dstGCId width:w height:h |
|
2807 |
"do a bit-blt from a pix- or bitmap. |
|
2808 |
Here, fall back into copyFromId:, which should also work. |
|
2809 |
Subclasses may redefine this for more performance or if required" |
|
2810 |
||
2811 |
^ self copyFromId:sourceId x:srcX y:srcY gc:srcGCId to:destId x:dstX y:dstY gc:dstGCId width:w height:h |
|
2812 |
! |
|
2813 |
||
2814 |
copyPlaneFromId:sourceId x:srcX y:srcY gc:srcDCId to:destId x:dstX y:dstY gc:dstDCId |
|
2328 | 2815 |
width:w height:h |
2323 | 2816 |
"do a bit-blt, but only copy the low-bit plane; |
2817 |
copy bits from the rectangle defined by |
|
2818 |
srcX/srcY and w/h from the sourceId drawable to the rectangle |
|
2819 |
below dstX/dstY in the destId drawable. Trigger an error if any |
|
2820 |
argument is not integer." |
|
2821 |
||
2822 |
^ self |
|
2328 | 2823 |
copyFromId:sourceId |
2824 |
x:srcX y:srcY gc:srcDCId |
|
2825 |
to:destId x:dstX y:dstY gc:dstDCId |
|
2826 |
width:w height:h |
|
2323 | 2827 |
! |
2828 |
||
2829 |
copyPlaneFromPixmapId:sourceId x:srcX y:srcY gc:srcGCId to:destId x:dstX y:dstY gc:dstGCId width:w height:h |
|
2830 |
"do a bit-blt from a pix- or bitmap, using the low-bit plane of the source only. |
|
2831 |
Here, fall back into copyPlaneFromId:, which should also work. |
|
2832 |
Subclasses may redefine this for more performance or if required" |
|
2833 |
||
2834 |
^ self copyPlaneFromId:sourceId x:srcX y:srcY gc:srcGCId to:destId x:dstX y:dstY gc:dstGCId width:w height:h |
|
2835 |
! |
|
2836 |
||
2837 |
createBitmapFromArray:anArray width:w height:h |
|
2838 |
|bitmapId| |
|
2839 |
||
2325 | 2840 |
|
2323 | 2841 |
bitmapId := self primCreateBitmapFromArray:anArray width:w height:h. |
2842 |
||
2843 |
bitmapId isNil ifTrue:[ |
|
2328 | 2844 |
'WINWORKSTATION: cannot create bitmap' errorPrintCR. |
2323 | 2845 |
]. |
2846 |
^ bitmapId |
|
2847 |
! |
|
2848 |
||
2324 | 2849 |
createPixmapWidth:w height:h depth:d |
2850 |
"allocate a pixmap on the Xserver, the contents is undefined |
|
2851 |
(i.e. random). Return a bitmap id or nil" |
|
2852 |
||
2853 |
%{ |
|
2854 |
HANDLE newBitmapHandle; |
|
2855 |
HANDLE rootDC = CreateDC("DISPLAY", NULL, NULL, NULL); |
|
2856 |
||
2857 |
/*console_printf("CreateBitmap Color\n");*/ |
|
2858 |
if (__bothSmallInteger(w, h) && __isSmallInteger(d) /*&& ISCONNECTED */) { |
|
2328 | 2859 |
if (__intVal(d) == 1) { |
2860 |
newBitmapHandle = CreateBitmap(__intVal(w), __intVal(h) , 1, 1, NULL); |
|
2861 |
} else { |
|
2324 | 2862 |
#if 0 |
2328 | 2863 |
if (__intVal(d) != __depth) { |
2864 |
console_printf("invalid depth\n"); |
|
2865 |
RETURN (nil); |
|
2866 |
} |
|
2324 | 2867 |
#endif |
2328 | 2868 |
newBitmapHandle = CreateCompatibleBitmap(rootDC, __intVal(w), __intVal(h) ); |
2869 |
} |
|
2870 |
||
2871 |
if (newBitmapHandle) { |
|
2872 |
RETURN ( __MKOBJ(newBitmapHandle)); |
|
2873 |
} |
|
2324 | 2874 |
/* |
2328 | 2875 |
DPRINTF(("empty bitmap handle = %x\n", newBitmapHandle)); |
2324 | 2876 |
*/ |
2877 |
} |
|
2878 |
RETURN (nil); |
|
2879 |
%} |
|
2880 |
! |
|
2881 |
||
2323 | 2882 |
destroyPixmap:aDrawableId |
2883 |
||
2884 |
%{ /* NOCONTEXT */ |
|
2885 |
if (__isExternalAddress(aDrawableId) /* && ISCONNECTED */ ) { |
|
2328 | 2886 |
HANDLE bitmapHandle = _HANDLEVal(aDrawableId); |
2887 |
||
2888 |
if (bitmapHandle) { |
|
2889 |
DeleteObject(bitmapHandle); |
|
2890 |
/* _DeleteObject(bitmapHandle, __LINE__); */ |
|
2891 |
} |
|
2323 | 2892 |
} |
2893 |
%} |
|
2894 |
! |
|
2895 |
||
2329 | 2896 |
displayDeviceForm:aForm x:x y:y |
2338 | 2897 |
|
2898 |
|sortedImage formMask bitsWithTransparency| |
|
2899 |
||
2900 |
sortedImage := aForm. |
|
2341 | 2901 |
|
2902 |
aForm depth ~~ 8 ifTrue:[ |
|
2903 |
sortedImage := aForm asImageWithDepth: 8. |
|
2904 |
]. |
|
2338 | 2905 |
"/ sortedImage := self sortColorMapImage: aForm. |
2906 |
sortedImage := self compressColorMapImage: sortedImage. |
|
2907 |
||
2908 |
formMask := sortedImage mask. |
|
2909 |
formMask isNil |
|
2341 | 2910 |
ifTrue:[bitsWithTransparency := sortedImage bits ] |
2338 | 2911 |
ifFalse:[ |
2912 |
|bitsWithTransparencySize| |
|
2341 | 2913 |
formMask := formMask asImageWithDepth: sortedImage depth. |
2338 | 2914 |
bitsWithTransparency := sortedImage bits copy. |
2915 |
bitsWithTransparencySize := bitsWithTransparency size. |
|
2916 |
formMask bits doWithIndex:[:maskBit :index | |
|
2917 |
bitsWithTransparencySize >= index ifTrue:[ |
|
2918 |
maskBit == 0 ifTrue:[bitsWithTransparency at: index put: 255 "60" "bitClearAt: index"]. |
|
2919 |
"/ maskBit == 1 ifTrue:[bitsWithTransparency at: index put: (bitsWithTransparency at: index)]. |
|
2920 |
]. |
|
2921 |
]. |
|
2922 |
]. |
|
2923 |
||
2924 |
"/ sortedImage colorMap redVector at:255 put: 255. |
|
2925 |
"/ sortedImage colorMap greenVector at:255 put: 255. |
|
2926 |
"/ sortedImage colorMap blueVector at:255 put: 255. |
|
2927 |
||
2928 |
self |
|
2929 |
drawBits: bitsWithTransparency ? sortedImage bits |
|
2930 |
redVector: sortedImage colorMap redVector |
|
2931 |
greenVector: sortedImage colorMap greenVector |
|
2932 |
blueVector: sortedImage colorMap blueVector |
|
2933 |
bitsPerPixel: sortedImage bitsPerPixel |
|
2934 |
depth: sortedImage depth |
|
2935 |
width: sortedImage width |
|
2936 |
height: sortedImage height |
|
2937 |
into: self id |
|
2938 |
x: x |
|
2939 |
y: y |
|
2940 |
width: sortedImage width |
|
2941 |
height: sortedImage height |
|
2942 |
with: gcId. |
|
2329 | 2943 |
! |
2944 |
||
2323 | 2945 |
drawBits:imageBits bitsPerPixel:bitsPerPixel depth:imageDepth padding:padd |
2342 | 2946 |
width:imageWidth height:imageHeight |
2947 |
x:srcx y:srcy |
|
2948 |
into:ignoredDrawableId |
|
2949 |
x:dstx y:dsty |
|
2950 |
width:w height:h |
|
2951 |
with:aGCId |
|
2323 | 2952 |
|
2953 |
"draw a bitImage which has depth id, width iw and height ih into |
|
2954 |
the drawable. draw a region of w/h pixels from srcx/srcy to dstx/dsty. |
|
2955 |
Individual source pixels have bitsPerPixel bits, allowing to draw |
|
2956 |
depth and pixel-units to be different. |
|
2957 |
It has to be checked elsewhere, that the server can do it with the given |
|
2958 |
depth - otherwise, primitive failure will be signalled. |
|
2959 |
Also it is assumed, that the colormap is setup correctly and the |
|
2960 |
colors are allocated - otherwise the colors may be wrong." |
|
2961 |
||
2962 |
" |
|
2963 |
sorry; I had to separate it into 2 methods, since XPutImage needs |
|
2964 |
an unlimited stack, and thus cannot send primitiveFailed |
|
2965 |
" |
|
2966 |
(self primDrawBits:imageBits bitsPerPixel:bitsPerPixel depth:imageDepth padding:padd |
|
2342 | 2967 |
width:imageWidth height:imageHeight |
2968 |
x:srcx y:srcy |
|
2969 |
into:ignoredDrawableId |
|
2970 |
x:(dstx rounded) y:(dsty rounded) |
|
2971 |
width:w height:h |
|
2972 |
with:aGCId) |
|
2323 | 2973 |
ifFalse:[ |
2342 | 2974 |
" |
2975 |
also happens, if a segmentation violation occurs in the |
|
2976 |
XPutImage ... |
|
2977 |
" |
|
2978 |
self primitiveFailed |
|
2323 | 2979 |
]. |
2980 |
! |
|
2981 |
||
2338 | 2982 |
drawBits:imageBits redVector:redVector greenVector:greenVector blueVector:blueVector bitsPerPixel:bitsPerPixel depth:imageDepth |
2983 |
width:imageWidth height:imageHeight |
|
2984 |
into:ignoredDrawableId |
|
2985 |
x:dstx y:dsty |
|
2986 |
width:w height:h |
|
2987 |
with:aGCId |
|
2988 |
||
2989 |
"draw a bitImage which has depth id, width iw and height ih into |
|
2990 |
the drawable. draw a region of w/h pixels from srcx/srcy to dstx/dsty. |
|
2991 |
Individual source pixels have bitsPerPixel bits, allowing to draw |
|
2992 |
depth and pixel-units to be different. |
|
2993 |
It has to be checked elsewhere, that the server can do it with the given |
|
2994 |
depth - otherwise, primitive failure will be signalled. |
|
2995 |
Also it is assumed, that the colormap is setup correctly and the |
|
2996 |
colors are allocated - otherwise the colors may be wrong." |
|
2997 |
||
2998 |
" |
|
2999 |
sorry; I had to separate it into 2 methods, since XPutImage needs |
|
3000 |
an unlimited stack, and thus cannot send primitiveFailed |
|
3001 |
" |
|
3002 |
(self primDrawBits:imageBits redVector:redVector greenVector:greenVector blueVector:blueVector bitsPerPixel:bitsPerPixel depth:imageDepth |
|
3003 |
width:imageWidth height:imageHeight |
|
3004 |
into:ignoredDrawableId |
|
2342 | 3005 |
x:(dstx rounded) y:(dsty rounded) |
2338 | 3006 |
width:w height:h |
3007 |
with:aGCId) |
|
3008 |
ifFalse:[ |
|
3009 |
" |
|
3010 |
also happens, if a segmentation violation occurs in the |
|
3011 |
XPutImage ... |
|
3012 |
" |
|
3013 |
self primitiveFailed |
|
3014 |
]. |
|
3015 |
! |
|
3016 |
||
2324 | 3017 |
primCreateBitmapFromArray:anArray width:w height:h |
3018 |
%{ |
|
3019 |
||
3020 |
HBITMAP newBitmapHandle; |
|
3021 |
int b_width, b_height, bytesPerRowST, bytesPerRowWN, padding; |
|
3022 |
int row, col; |
|
3023 |
unsigned char *cp, *bPits; |
|
3024 |
unsigned char *b_bits = 0; |
|
3025 |
int index; |
|
3026 |
OBJ num; |
|
3027 |
unsigned char *allocatedBits = 0; |
|
3028 |
unsigned char fastBits[10000]; |
|
3029 |
||
3030 |
if (__bothSmallInteger(w, h) |
|
3031 |
&& _isNonNilObject(anArray)) { |
|
2328 | 3032 |
OBJ cls = __qClass(anArray); |
3033 |
||
3034 |
b_width = __intVal(w); |
|
3035 |
b_height = __intVal(h); |
|
3036 |
bytesPerRowST = (b_width + 7) / 8; |
|
3037 |
bytesPerRowWN = ((b_width + 15) / 16) * 2; |
|
3038 |
padding = bytesPerRowWN - bytesPerRowST; |
|
3039 |
||
3040 |
if ((padding == 0) && (cls == @global(ByteArray))) { |
|
3041 |
b_bits = __ByteArrayInstPtr(anArray)->ba_element; |
|
3042 |
cp = 0; |
|
3043 |
} else { |
|
3044 |
int nBytes = b_height * bytesPerRowWN; |
|
3045 |
||
3046 |
if (nBytes < sizeof(fastBits)) { |
|
3047 |
cp = b_bits = fastBits; |
|
3048 |
} else { |
|
3049 |
cp = b_bits = allocatedBits = (unsigned char *) malloc(nBytes); |
|
3050 |
if (! cp) goto fail; |
|
3051 |
} |
|
3052 |
} |
|
3053 |
if (cp) { |
|
3054 |
if (cls == @global(Array)) { |
|
3055 |
OBJ *op; |
|
3056 |
||
3057 |
index = 1; |
|
3058 |
op = &(__ArrayInstPtr(anArray)->a_element[index - 1]); |
|
3059 |
for (row = b_height; row; row--) { |
|
3060 |
for (col = bytesPerRowST; col; col--) { |
|
3061 |
num = *op++; |
|
3062 |
if (! __isSmallInteger(num)) |
|
3063 |
goto fail; |
|
3064 |
*cp++ = __intVal(num); |
|
3065 |
} |
|
3066 |
cp += padding; |
|
3067 |
} |
|
3068 |
} else if (cls == @global(ByteArray)) { |
|
3069 |
unsigned char *pBits; |
|
3070 |
||
3071 |
pBits = __ByteArrayInstPtr(anArray)->ba_element; |
|
3072 |
for (row = b_height; row; row--) { |
|
3073 |
for (col = bytesPerRowST; col; col--) { |
|
3074 |
*cp++ = ( *pBits++ /*^ 0xFF*/ ); |
|
3075 |
} |
|
3076 |
cp += padding; |
|
3077 |
} |
|
3078 |
} else { |
|
3079 |
goto fail; |
|
3080 |
} |
|
3081 |
} |
|
2324 | 3082 |
/* |
2328 | 3083 |
CPRINTF(("create bitmap ...\n")); |
2324 | 3084 |
*/ |
2328 | 3085 |
newBitmapHandle = CreateBitmap(b_width, b_height, 1, 1, b_bits ); |
3086 |
||
3087 |
if (newBitmapHandle ) { |
|
2324 | 3088 |
/* |
2328 | 3089 |
DDPRINTF(("returning bitmap %x ...\n", newBitmapHandle)); |
2324 | 3090 |
*/ |
2328 | 3091 |
if (allocatedBits) { |
3092 |
free(allocatedBits); |
|
3093 |
} |
|
3094 |
RETURN ( __MKOBJ(newBitmapHandle)); |
|
3095 |
} |
|
2324 | 3096 |
} |
3097 |
fail: ; |
|
3098 |
/* |
|
3099 |
DDPRINTF(("create bitmap FAILED!!!\n")); |
|
3100 |
*/ |
|
3101 |
if (allocatedBits) { |
|
3102 |
/* |
|
2328 | 3103 |
CPRINTF(("freeing up bitmap bits ...\n")); |
2324 | 3104 |
*/ |
2328 | 3105 |
free(allocatedBits); |
2324 | 3106 |
} |
3107 |
/* |
|
3108 |
CPRINTF(("returning nil ...\n")); |
|
3109 |
*/ |
|
3110 |
RETURN ( nil ); |
|
3111 |
%} |
|
3112 |
! |
|
3113 |
||
2323 | 3114 |
primDrawBits:imageBits bitsPerPixel:bitsPerPixel depth:imageDepth padding:padd |
2338 | 3115 |
width:imageWidth height:imageHeight |
3116 |
x:srcx y:srcy |
|
3117 |
into:ignoredDrawableId |
|
3118 |
x:dstx y:dsty |
|
3119 |
width:w height:h |
|
3120 |
with:aGCId |
|
2323 | 3121 |
|
3122 |
"since XPutImage may allocate huge amount of stack space |
|
3123 |
(some implementations use alloca), this must run with unlimited stack." |
|
3124 |
||
3125 |
%{ |
|
3126 |
unsigned char fastBits[10000]; |
|
3127 |
unsigned char *b_bits = 0; |
|
3128 |
unsigned char *allocatedBits = 0; |
|
3129 |
unsigned char *__imageBits = 0; |
|
3130 |
||
3131 |
if (__isByteArray(imageBits)) { |
|
2338 | 3132 |
__imageBits = __ByteArrayInstPtr(imageBits)->ba_element; |
2323 | 3133 |
} else if (__isExternalBytesLike(imageBits)) { |
2338 | 3134 |
__imageBits = (unsigned char *)(__externalBytesAddress(imageBits)); |
2323 | 3135 |
} |
3136 |
||
3137 |
if (/* ISCONNECTED |
|
3138 |
&& */ __isExternalAddressLike(aGCId) |
|
3139 |
&& __bothSmallInteger(srcx, srcy) |
|
3140 |
&& __bothSmallInteger(dstx, dsty) |
|
3141 |
&& __bothSmallInteger(w, h) |
|
3142 |
&& __bothSmallInteger(imageWidth, imageHeight) |
|
3143 |
&& __bothSmallInteger(imageDepth, bitsPerPixel) |
|
3144 |
&& __isSmallInteger(padd) |
|
3145 |
&& __imageBits) |
|
3146 |
{ |
|
2338 | 3147 |
struct |
3148 |
{ |
|
3149 |
BITMAPINFOHEADER bmiHeader; |
|
3150 |
DWORD r; |
|
3151 |
DWORD g; |
|
3152 |
DWORD b; |
|
3153 |
} bitmap; |
|
3154 |
||
3155 |
HANDLE hDC = (HANDLE)(__externalAddressVal(aGCId)); |
|
3156 |
HBITMAP hBitmap = _HBITMAPVAL(__INST(drawableId)); |
|
2323 | 3157 |
|
3158 |
/* |
|
2338 | 3159 |
DDPRINTF(("hDC = %x\n", hDC)); |
2323 | 3160 |
*/ |
2338 | 3161 |
if (__intVal(padd) != WIN32PADDING) { |
3162 |
int row, col; |
|
3163 |
unsigned char *cp; |
|
3164 |
unsigned char *pBits; |
|
3165 |
int b_width, b_height, bytesPerRowST, bytesPerRowWN, padding, nBytes; |
|
3166 |
int bi = __intVal(bitsPerPixel); |
|
3167 |
||
3168 |
b_width = __intVal(w); |
|
3169 |
b_height = __intVal(h); |
|
3170 |
bytesPerRowST = (b_width * bi + (__intVal(padd)-1)) / __intVal(padd); |
|
3171 |
bytesPerRowWN = (b_width * bi + (WIN32PADDING-1)) / WIN32PADDING * (WIN32PADDING/8); |
|
3172 |
padding = bytesPerRowWN - bytesPerRowST; |
|
3173 |
nBytes = b_height * bytesPerRowWN; |
|
3174 |
/*console_printf("padd %d bs %d bw %d p %d\n",__intVal(padd),bytesPerRowST,bytesPerRowWN,padding);*/ |
|
3175 |
if (padding) { |
|
3176 |
if (nBytes < sizeof(fastBits)) { |
|
3177 |
cp = b_bits = fastBits; |
|
3178 |
} else { |
|
3179 |
cp = b_bits = allocatedBits = (unsigned char *) malloc(nBytes); |
|
3180 |
} |
|
3181 |
if (cp) { |
|
3182 |
pBits = __imageBits; |
|
3183 |
for (row = b_height; row; row--) { |
|
3184 |
for (col = bytesPerRowST; col; col--) { |
|
3185 |
*cp++ = *pBits++; |
|
3186 |
} |
|
3187 |
cp += padding; |
|
3188 |
} |
|
3189 |
} else |
|
3190 |
goto fail; |
|
3191 |
} |
|
3192 |
} |
|
3193 |
||
3194 |
if (b_bits == 0) { |
|
3195 |
b_bits = __imageBits; |
|
3196 |
} |
|
3197 |
||
3198 |
bitmap.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); |
|
3199 |
bitmap.bmiHeader.biPlanes = 1; |
|
3200 |
if (__intVal(imageDepth) == 24) { |
|
3201 |
/*bitmap.bmiHeader.biCompression = BI_BITFIELDS; |
|
3202 |
bitmap.r = 0xff0000; |
|
3203 |
bitmap.g = 0x00ff00; |
|
3204 |
bitmap.b = 0x0000ff;*/ |
|
3205 |
bitmap.bmiHeader.biCompression = BI_RGB; |
|
3206 |
} else if (__intVal(imageDepth) == 16) { |
|
3207 |
/*bitmap.bmiHeader.biCompression = BI_RGB; |
|
3208 |
bitmap.bmiHeader.biCompression = BI_BITFIELDS; |
|
3209 |
bitmap.b = 0x001f; |
|
3210 |
bitmap.g = 0x07e0; |
|
3211 |
bitmap.r = 0xf800;*/ |
|
3212 |
bitmap.b = 0; |
|
3213 |
bitmap.g = 0; |
|
3214 |
bitmap.r = 0; |
|
3215 |
bitmap.bmiHeader.biCompression = BI_RGB; |
|
3216 |
} |
|
3217 |
bitmap.bmiHeader.biSizeImage = 0; |
|
3218 |
bitmap.bmiHeader.biXPelsPerMeter = 0; |
|
3219 |
bitmap.bmiHeader.biYPelsPerMeter = 0; |
|
3220 |
bitmap.bmiHeader.biClrUsed = 0; |
|
3221 |
bitmap.bmiHeader.biClrImportant = 0; |
|
3222 |
bitmap.bmiHeader.biWidth = __intVal(imageWidth); |
|
3223 |
bitmap.bmiHeader.biHeight = -(__intVal(imageHeight)); |
|
3224 |
bitmap.bmiHeader.biBitCount = __intVal(bitsPerPixel); |
|
3225 |
/*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);*/ |
|
3226 |
||
3227 |
SetDIBitsToDevice(hDC,__intVal(dstx),__intVal(dsty), |
|
3228 |
__intVal(w), __intVal(h), |
|
3229 |
__intVal(srcx), __intVal(srcy), |
|
3230 |
0,__intVal(h), |
|
3231 |
(void *)b_bits, |
|
3232 |
(BITMAPINFO*)&bitmap,DIB_RGB_COLORS); |
|
2324 | 3233 |
|
3234 |
/* |
|
2338 | 3235 |
SetDIBits(hDC,hBitmap, |
3236 |
0,__intVal(h), |
|
3237 |
(void *)b_bits, |
|
3238 |
(BITMAPINFO*)&bitmap,DIB_RGB_COLORS); |
|
2324 | 3239 |
*/ |
2323 | 3240 |
/* |
2338 | 3241 |
StretchDIBits(hDC, |
3242 |
__intVal(dstx),(__intVal(dsty)), // x & y coord of destination upper-left corner |
|
3243 |
__intVal(w), __intVal(h), // width & height of destination rectangle |
|
3244 |
__intVal(srcx), __intVal(srcy), // x & y coord of source upper-left corner |
|
3245 |
__intVal(w), __intVal(h), // width & height of source rectangle |
|
3246 |
(void *)b_bits, // bitmap bits |
|
3247 |
(BITMAPINFO*)&bitmap, // bitmap data |
|
3248 |
DIB_RGB_COLORS, // usage options |
|
3249 |
SRCCOPY // raster operation code |
|
3250 |
); |
|
2323 | 3251 |
*/ |
2338 | 3252 |
if (allocatedBits) { |
3253 |
free(allocatedBits); |
|
3254 |
} |
|
2323 | 3255 |
/* |
3256 |
#ifndef CACHE_LAST_DC |
|
2338 | 3257 |
_releaseDC(gcData); |
2323 | 3258 |
#endif |
3259 |
*/ |
|
2338 | 3260 |
RETURN ( true ); |
2323 | 3261 |
} |
3262 |
||
3263 |
fail: ; |
|
3264 |
/* |
|
3265 |
PRINTF(("create temp bitmap FAILED!!!\n")); |
|
3266 |
*/ |
|
3267 |
if (allocatedBits) { |
|
3268 |
/* |
|
2338 | 3269 |
PRINTF(("freeing up temp bitmap bits ...\n")); |
2323 | 3270 |
*/ |
2338 | 3271 |
free(allocatedBits); |
2323 | 3272 |
} |
3273 |
/* |
|
3274 |
#ifndef CACHE_LAST_DC |
|
3275 |
if (hDC) { |
|
2338 | 3276 |
_releaseDC(gcData); |
3277 |
} |
|
3278 |
#endif |
|
3279 |
*/ |
|
3280 |
%} |
|
3281 |
. |
|
3282 |
^ false |
|
3283 |
! |
|
3284 |
||
3285 |
primDrawBits:imageBits redVector:redVector greenVector:greenVector blueVector:blueVector bitsPerPixel:bitsPerPixel depth:imageDepth |
|
3286 |
width:imageWidth height:imageHeight |
|
3287 |
into:ignoredDrawableId |
|
3288 |
x:dstx y:dsty |
|
3289 |
width:w height:h |
|
3290 |
with:aGCId |
|
3291 |
||
3292 |
"since XPutImage may allocate huge amount of stack space |
|
3293 |
(some implementations use alloca), this must run with unlimited stack." |
|
3294 |
||
3295 |
%{ |
|
3296 |
unsigned char fastBits[10000]; |
|
3297 |
unsigned char *b_bits = 0; |
|
3298 |
unsigned char *allocatedBits = 0; |
|
3299 |
unsigned char *__imageBits = 0; |
|
3300 |
unsigned char *__redVector = 0; |
|
3301 |
unsigned char *__greenVector = 0; |
|
3302 |
unsigned char *__blueVector = 0; |
|
3303 |
int padd = 8; |
|
3304 |
||
3305 |
if (__isByteArray(imageBits)) { |
|
3306 |
__imageBits = __ByteArrayInstPtr(imageBits)->ba_element; |
|
3307 |
} else if (__isExternalBytesLike(imageBits)) { |
|
3308 |
__imageBits = (unsigned char *)(__externalBytesAddress(imageBits)); |
|
3309 |
} |
|
3310 |
||
3311 |
if (__isByteArray(redVector)) { |
|
3312 |
__redVector = __ByteArrayInstPtr(redVector)->ba_element; |
|
3313 |
} else if (__isExternalBytesLike(redVector)) { |
|
3314 |
__redVector = (unsigned char *)(__externalBytesAddress(redVector)); |
|
3315 |
} |
|
3316 |
||
3317 |
if (__isByteArray(greenVector)) { |
|
3318 |
__greenVector = __ByteArrayInstPtr(greenVector)->ba_element; |
|
3319 |
} else if (__isExternalBytesLike(greenVector)) { |
|
3320 |
__greenVector = (unsigned char *)(__externalBytesAddress(greenVector)); |
|
3321 |
} |
|
3322 |
||
3323 |
if (__isByteArray(blueVector)) { |
|
3324 |
__blueVector = __ByteArrayInstPtr(blueVector)->ba_element; |
|
3325 |
} else if (__isExternalBytesLike(blueVector)) { |
|
3326 |
__blueVector = (unsigned char *)(__externalBytesAddress(blueVector)); |
|
3327 |
} |
|
3328 |
||
3329 |
if (/* ISCONNECTED |
|
3330 |
&& */ __isExternalAddressLike(aGCId) |
|
3331 |
// && __bothSmallInteger(srcx, srcy) |
|
3332 |
&& __bothSmallInteger(dstx, dsty) |
|
3333 |
&& __bothSmallInteger(w, h) |
|
3334 |
&& __bothSmallInteger(imageWidth, imageHeight) |
|
3335 |
&& __bothSmallInteger(imageDepth, bitsPerPixel) |
|
3336 |
&& __imageBits |
|
3337 |
&& __redVector |
|
3338 |
&& __greenVector |
|
3339 |
&& __blueVector) |
|
3340 |
{ |
|
3341 |
struct |
|
3342 |
{ |
|
3343 |
BITMAPINFOHEADER bmiHeader; |
|
3344 |
RGBQUAD bmiColors[256]; |
|
3345 |
} bitmap; |
|
3346 |
||
3347 |
HANDLE hDC = (HANDLE)(__externalAddressVal(aGCId)); |
|
3348 |
HBITMAP hBitmap = _HBITMAPVAL(__INST(drawableId)); |
|
3349 |
int col; |
|
3350 |
/* |
|
3351 |
DDPRINTF(("hDC = %x\n", hDC)); |
|
3352 |
*/ |
|
3353 |
||
3354 |
if (padd != WIN32PADDING) { |
|
3355 |
||
3356 |
int row, col; |
|
3357 |
unsigned char *cp; |
|
3358 |
unsigned char *pBits; |
|
3359 |
int b_width, b_height, bytesPerRowST, bytesPerRowWN, padding, nBytes; |
|
3360 |
int bi = __intVal(bitsPerPixel); |
|
3361 |
||
2340
7aada47a2ec0
changed #primDrawBits:redVector:greenVector:blueVector:bitsPerPixel:depth:width:height:into:x:y:width:height:with:
fm
parents:
2339
diff
changeset
|
3362 |
// console_fprintf(stderr, "Non WIN32PADDING"); |
2338 | 3363 |
|
3364 |
b_width = __intVal(w); |
|
3365 |
b_height = __intVal(h); |
|
3366 |
bytesPerRowST = (b_width * bi + (padd - 1 )) / padd; |
|
3367 |
bytesPerRowWN = (b_width * bi + (WIN32PADDING-1)) / WIN32PADDING * (WIN32PADDING/8); |
|
3368 |
padding = bytesPerRowWN - bytesPerRowST; |
|
3369 |
nBytes = b_height * bytesPerRowWN; |
|
3370 |
/*console_printf("padd %d bs %d bw %d p %d\n",__intVal(padd),bytesPerRowST,bytesPerRowWN,padding);*/ |
|
3371 |
if (padding) { |
|
3372 |
if (nBytes < sizeof(fastBits)) { |
|
3373 |
cp = b_bits = fastBits; |
|
3374 |
} else { |
|
3375 |
cp = b_bits = allocatedBits = (unsigned char *) malloc(nBytes); |
|
3376 |
} |
|
3377 |
if (cp) { |
|
3378 |
pBits = __imageBits; |
|
3379 |
for (row = b_height; row; row--) { |
|
3380 |
for (col = bytesPerRowST; col; col--) { |
|
3381 |
*cp++ = *pBits++; |
|
3382 |
} |
|
3383 |
cp += padding; |
|
3384 |
} |
|
3385 |
} else |
|
3386 |
goto fail; |
|
3387 |
} |
|
3388 |
} |
|
3389 |
||
3390 |
if (b_bits == 0) { |
|
3391 |
b_bits = __imageBits; |
|
3392 |
} |
|
3393 |
||
3394 |
bitmap.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); |
|
3395 |
bitmap.bmiHeader.biPlanes = 1; |
|
3396 |
bitmap.bmiHeader.biCompression = BI_RGB; |
|
3397 |
bitmap.bmiHeader.biSizeImage = 0; |
|
3398 |
bitmap.bmiHeader.biXPelsPerMeter = 0; |
|
3399 |
bitmap.bmiHeader.biYPelsPerMeter = 0; |
|
3400 |
bitmap.bmiHeader.biClrUsed = 0; |
|
3401 |
bitmap.bmiHeader.biClrImportant = 0; |
|
3402 |
bitmap.bmiHeader.biWidth = __intVal(imageWidth); |
|
3403 |
bitmap.bmiHeader.biHeight = -(__intVal(imageHeight)); |
|
3404 |
bitmap.bmiHeader.biBitCount = __intVal(bitsPerPixel); |
|
3405 |
/*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);*/ |
|
3406 |
||
2341 | 3407 |
// if (__intVal(imageDepth) == 8) { |
2338 | 3408 |
for(col=0;col<256;col++) |
3409 |
{ |
|
3410 |
bitmap.bmiColors[col].rgbBlue = __blueVector[col]; // Microsoft idea: change rgbBlue to rgbRed |
|
3411 |
bitmap.bmiColors[col].rgbGreen = __greenVector[col]; |
|
3412 |
bitmap.bmiColors[col].rgbRed = __redVector[col]; // Microsoft idea: change rgbRed to rgbBlue |
|
3413 |
bitmap.bmiColors[col].rgbReserved = 0; |
|
3414 |
||
3415 |
} |
|
2341 | 3416 |
// } |
2338 | 3417 |
|
3418 |
bitmap.bmiColors[255].rgbBlue=255; |
|
3419 |
bitmap.bmiColors[255].rgbGreen=255; |
|
3420 |
bitmap.bmiColors[255].rgbRed =255; |
|
3421 |
||
3422 |
SetDIBitsToDevice(hDC,__intVal(dstx),__intVal(dsty), |
|
3423 |
__intVal(w), __intVal(h), |
|
3424 |
0, 0, /* __intVal(srcx), __intVal(srcy), */ |
|
3425 |
0,__intVal(h), |
|
3426 |
(void *)b_bits, |
|
3427 |
(BITMAPINFO*)&bitmap,DIB_RGB_COLORS); |
|
3428 |
/* |
|
3429 |
SetDIBits(hDC,hBitmap, |
|
3430 |
0,__intVal(h), |
|
3431 |
(void *)b_bits, |
|
3432 |
(BITMAPINFO*)&bitmap,DIB_RGB_COLORS); |
|
3433 |
*/ |
|
3434 |
/* |
|
3435 |
StretchDIBits(hDC, |
|
3436 |
__intVal(dstx),(__intVal(dsty)), // x & y coord of destination upper-left corner |
|
3437 |
__intVal(w), __intVal(h), // width & height of destination rectangle |
|
3438 |
__intVal(srcx), __intVal(srcy), // x & y coord of source upper-left corner |
|
3439 |
__intVal(w), __intVal(h), // width & height of source rectangle |
|
3440 |
(void *)b_bits, // bitmap bits |
|
3441 |
(BITMAPINFO*)&bitmap, // bitmap data |
|
3442 |
DIB_RGB_COLORS, // usage options |
|
3443 |
SRCCOPY // raster operation code |
|
3444 |
); |
|
3445 |
*/ |
|
3446 |
if (allocatedBits) { |
|
3447 |
free(allocatedBits); |
|
3448 |
} |
|
3449 |
/* |
|
3450 |
#ifndef CACHE_LAST_DC |
|
3451 |
_releaseDC(gcData); |
|
3452 |
#endif |
|
3453 |
*/ |
|
3454 |
RETURN ( true ); |
|
3455 |
} |
|
3456 |
||
3457 |
fail: ; |
|
3458 |
/* |
|
3459 |
PRINTF(("create temp bitmap FAILED!!!\n")); |
|
3460 |
*/ |
|
3461 |
if (allocatedBits) { |
|
3462 |
/* |
|
3463 |
PRINTF(("freeing up temp bitmap bits ...\n")); |
|
3464 |
*/ |
|
3465 |
free(allocatedBits); |
|
3466 |
} |
|
3467 |
/* |
|
3468 |
#ifndef CACHE_LAST_DC |
|
3469 |
if (hDC) { |
|
3470 |
_releaseDC(gcData); |
|
2323 | 3471 |
} |
3472 |
#endif |
|
3473 |
*/ |
|
3474 |
%} |
|
3475 |
. |
|
3476 |
^ false |
|
3477 |
! |
|
3478 |
||
3479 |
setFunction:aFunctionSymbol in:aGCId |
|
3480 |
"set alu function to be drawn with" |
|
3481 |
||
3482 |
Transcript showCR: aFunctionSymbol printString. |
|
3483 |
function := aFunctionSymbol. |
|
3484 |
||
3485 |
"/%{ /* NOCONTEXT */ |
|
3486 |
"/ |
|
3487 |
"/ if (__isExternalAddress(aGCId)) { |
|
3488 |
"/ struct gcData *gcData = _GCDATA(aGCId); |
|
3489 |
"/ int fun = -1; |
|
3490 |
"/ int bfun = -1; |
|
3491 |
"/ |
|
3492 |
"/ if (aFunctionSymbol == @symbol(copy)) { |
|
3493 |
"/ fun = R2_COPYPEN; |
|
3494 |
"/ bfun = BITBLT_COPY; |
|
3495 |
"/ } else if (aFunctionSymbol == @symbol(copyInverted)) { |
|
3496 |
"/ fun = R2_NOTCOPYPEN; |
|
3497 |
"/ bfun = BITBLT_COPYINVERTED; |
|
3498 |
"/ } else if (aFunctionSymbol == @symbol(xor)) { |
|
3499 |
"/ fun = R2_XORPEN; |
|
3500 |
"/ bfun = BITBLT_XOR; |
|
3501 |
"/ } else if (aFunctionSymbol == @symbol(and)) { |
|
3502 |
"/ fun = R2_MASKPEN; |
|
3503 |
"/ bfun = BITBLT_AND; |
|
3504 |
"/ } else if (aFunctionSymbol == @symbol(or)) { |
|
3505 |
"/ fun = R2_MERGEPEN; |
|
3506 |
"/ bfun = BITBLT_OR; |
|
3507 |
"/ } |
|
3508 |
"/ |
|
2325 | 3509 |
"/ if (fun |
2323 | 3510 |
! |
3511 |
||
3512 |
setGraphicsExposures:aBoolean in:aGCId |
|
3513 |
"set or clear the graphics exposures flag" |
|
3514 |
! |
|
3515 |
||
3516 |
shiftBlue |
|
3517 |
"return the number of valid bits in the red component." |
|
3518 |
||
3519 |
"/ bitsRed isNil ifTrue:[ |
|
3520 |
"/ "/ not a truecolor display |
|
3521 |
"/ ^ bitsPerRGB |
|
3522 |
"/ ]. |
|
3523 |
"/ ^ bitsRed |
|
3524 |
||
3525 |
^Display shiftBlue |
|
3526 |
! |
|
3527 |
||
3528 |
shiftGreen |
|
3529 |
"return the number of valid bits in the red component." |
|
3530 |
||
3531 |
"/ bitsRed isNil ifTrue:[ |
|
3532 |
"/ "/ not a truecolor display |
|
3533 |
"/ ^ bitsPerRGB |
|
3534 |
"/ ]. |
|
3535 |
"/ ^ bitsRed |
|
3536 |
||
3537 |
^Display shiftGreen |
|
3538 |
! |
|
3539 |
||
3540 |
shiftRed |
|
3541 |
"return the number of valid bits in the red component." |
|
3542 |
||
3543 |
"/ bitsRed isNil ifTrue:[ |
|
3544 |
"/ "/ not a truecolor display |
|
3545 |
"/ ^ bitsPerRGB |
|
3546 |
"/ ]. |
|
3547 |
"/ ^ bitsRed |
|
3548 |
||
3549 |
^Display shiftRed |
|
2338 | 3550 |
! |
3551 |
||
3552 |
sortBlockForColors |
|
3553 |
||
3554 |
^ [:a :b | |
|
3555 |
a redByte == b redByte ifTrue:[ |
|
3556 |
a greenByte == b greenByte ifTrue:[ |
|
3557 |
a blueByte < b blueByte |
|
3558 |
] ifFalse:[ |
|
3559 |
a greenByte < b greenByte |
|
3560 |
] |
|
3561 |
] ifFalse:[ |
|
3562 |
a redByte < b redByte |
|
3563 |
] |
|
3564 |
]. |
|
3565 |
! |
|
3566 |
||
3567 |
sortColorMapImage: image |
|
3568 |
"calculates a new color map for the image, sorting colors" |
|
3569 |
||
3570 |
|sortBlock depth newColorMap newImage oldImage usedColors oldToNew oldBits newBits tmpBits| |
|
3571 |
||
3572 |
sortBlock := self sortBlockForColors. |
|
3573 |
oldImage := image. |
|
3574 |
depth := oldImage depth. |
|
3575 |
||
3576 |
oldImage photometric ~~ #palette ifTrue:[ |
|
3577 |
Transcript showCR:'Compress colorMap: Only palette images have colormaps.'. |
|
3578 |
^ image |
|
3579 |
]. |
|
3580 |
||
3581 |
usedColors := oldImage realColorMap. |
|
3582 |
||
3583 |
||
3584 |
"/ translation table |
|
3585 |
oldToNew := ByteArray new:(1 bitShift:depth). |
|
3586 |
newColorMap := usedColors asArray. |
|
3587 |
newColorMap sort:sortBlock. |
|
3588 |
||
3589 |
oldImage colorMap asArray keysAndValuesDo:[:oldIdx :clr | |
|
3590 |
|newPixel| |
|
3591 |
||
3592 |
(usedColors includes:clr) ifTrue:[ |
|
3593 |
newPixel := newColorMap indexOf:clr. |
|
3594 |
oldToNew at:oldIdx put:newPixel-1. |
|
3595 |
] |
|
3596 |
]. |
|
3597 |
||
3598 |
oldBits := oldImage bits. |
|
3599 |
newBits := ByteArray new:(oldBits size). |
|
3600 |
depth ~~ 8 ifTrue:[ |
|
3601 |
"/ expand/compress can only handle 8bits |
|
3602 |
tmpBits := ByteArray uninitializedNew:(oldImage width*oldImage height). |
|
3603 |
oldBits |
|
3604 |
expandPixels:depth |
|
3605 |
width:oldImage width |
|
3606 |
height:oldImage height |
|
3607 |
into:tmpBits |
|
3608 |
mapping:oldToNew. |
|
3609 |
tmpBits |
|
3610 |
compressPixels:depth |
|
3611 |
width:oldImage width |
|
3612 |
height:oldImage height |
|
3613 |
into:newBits |
|
3614 |
mapping:nil |
|
3615 |
] ifFalse:[ |
|
3616 |
oldBits |
|
3617 |
expandPixels:depth |
|
3618 |
width:oldImage width |
|
3619 |
height:oldImage height |
|
3620 |
into:newBits |
|
3621 |
mapping:oldToNew. |
|
3622 |
]. |
|
3623 |
||
3624 |
newImage := oldImage species new |
|
3625 |
width:oldImage width |
|
3626 |
height:oldImage height |
|
3627 |
depth:depth |
|
3628 |
fromArray:newBits. |
|
3629 |
||
3630 |
newImage colorMap:newColorMap. |
|
3631 |
newImage fileName:oldImage fileName. |
|
3632 |
newImage mask:(oldImage mask copy). |
|
3633 |
||
3634 |
^newImage |
|
2323 | 3635 |
! ! |
3636 |
||
3637 |
!WinPrinterContext methodsFor:'font stuff'! |
|
3638 |
||
3639 |
createFontFor:aFontName |
|
3640 |
"a basic method for font allocation; this method allows |
|
3641 |
any font to be aquired (even those not conforming to |
|
3642 |
standard naming conventions, such as cursor, fixed or k14)" |
|
3643 |
||
3644 |
%{ |
|
3645 |
HGDIOBJ hFont; |
|
3646 |
char *fn; |
|
3647 |
||
3648 |
if (__isString(aFontName) || __isSymbol(aFontName)) { |
|
2328 | 3649 |
fn = __stringVal(aFontName); |
3650 |
if ((strcmp(fn, "fixed") == 0) || (strcmp(fn, "ANSI_FIXED_FONT") == 0)) { |
|
3651 |
hFont = GetStockObject(ANSI_FIXED_FONT); |
|
3652 |
} else if ((strcmp(fn, "variable") == 0) || (strcmp(fn, "ANSI_VAR_FONT") == 0)) { |
|
3653 |
hFont = GetStockObject(ANSI_VAR_FONT); |
|
3654 |
} else if ((strcmp(fn, "system") == 0) || (strcmp(fn, "SYSTEM_FONT") == 0)) { |
|
3655 |
hFont = GetStockObject(SYSTEM_FONT); |
|
3656 |
} else if ((strcmp(fn, "systemFixed") == 0) || (strcmp(fn, "SYSTEM_FIXED_FONT") == 0)) { |
|
3657 |
hFont = GetStockObject(SYSTEM_FIXED_FONT); |
|
3658 |
} else if ((strcmp(fn, "deviceDefault") == 0) || (strcmp(fn, "DEVICE_DEFAULT_FONT") == 0)) { |
|
3659 |
hFont = GetStockObject(DEVICE_DEFAULT_FONT); |
|
3660 |
} else { |
|
3661 |
hFont = GetStockObject(ANSI_FIXED_FONT); |
|
3662 |
} |
|
3663 |
if (hFont) { |
|
3664 |
DPRINTF(("createFontFor:%s -> %x\n", fn, hFont)); |
|
3665 |
RETURN ( __MKOBJ(hFont) ); |
|
3666 |
} |
|
2323 | 3667 |
} |
3668 |
%}. |
|
3669 |
^ nil |
|
3670 |
! |
|
3671 |
||
3672 |
fontMetricsOf:fontId |
|
3673 |
"return a fonts metrics info object" |
|
3674 |
||
3675 |
|rawData info| |
|
3676 |
||
3677 |
rawData := Array new:15. |
|
3678 |
(self primFontMetricsOf:fontId hdc:gcId intoArray:rawData) isNil ifTrue:[ |
|
2328 | 3679 |
self primitiveFailed. |
3680 |
^ self |
|
2323 | 3681 |
]. |
3682 |
||
3683 |
rawData at:11 put:#'ms-ansi'. |
|
3684 |
||
3685 |
info := DeviceWorkstation::DeviceFontMetrics new. |
|
3686 |
info |
|
3687 |
ascent:(rawData at:1) |
|
3688 |
descent:(rawData at:2) |
|
3689 |
maxAscent:(rawData at:3) |
|
3690 |
maxDescent:(rawData at:4) |
|
3691 |
minWidth:(rawData at:5) |
|
3692 |
maxWidth:(rawData at:6) |
|
3693 |
avgWidth:(rawData at:7) |
|
3694 |
minCode:(rawData at:8) |
|
3695 |
maxCode:16rFFFF "(rawData at:9)" |
|
3696 |
direction:nil |
|
3697 |
encoding:(rawData at:11). |
|
3698 |
||
3699 |
||
3700 |
^ info |
|
3701 |
! |
|
3702 |
||
3703 |
getDefaultFont |
|
3704 |
"return a default font id - used when class Font cannot |
|
3705 |
find anything usable" |
|
3706 |
||
3707 |
^ self createFontFor:'fixed' |
|
3708 |
! |
|
3709 |
||
3710 |
getFontWithFamily:familyString face:faceString |
|
2328 | 3711 |
style:styleArgString size:sizeArg encoding:encodingSym |
2323 | 3712 |
|
3713 |
"try to get the specified font, if not available, try the next smaller |
|
3714 |
font." |
|
3715 |
||
3716 |
|styleString theName theId xlatedStyle id spacing| |
|
3717 |
||
3718 |
styleString := styleArgString. |
|
3719 |
||
3720 |
"special: if face is nil, allow access to X-fonts" |
|
3721 |
faceString isNil ifTrue:[ |
|
2328 | 3722 |
sizeArg notNil ifTrue:[ |
3723 |
theName := familyString , '-' , sizeArg printString |
|
3724 |
] ifFalse:[ |
|
3725 |
theName := familyString |
|
3726 |
]. |
|
3727 |
theName isNil ifTrue:[ |
|
3728 |
" |
|
3729 |
mhmh - fall back to the default font |
|
3730 |
" |
|
3731 |
theName := 'fixed' |
|
3732 |
]. |
|
3733 |
theId := self createFontFor:theName. |
|
3734 |
theId isNil ifTrue:[ |
|
3735 |
theId := self getDefaultFont |
|
3736 |
]. |
|
3737 |
^ theId |
|
2323 | 3738 |
]. |
3739 |
||
3740 |
"/ spacing other than 'normal' is contained as last component |
|
3741 |
"/ in style |
|
3742 |
styleString notNil ifTrue:[ |
|
2328 | 3743 |
((styleString endsWith:'-narrow') |
3744 |
or:[styleString endsWith:'-semicondensed']) ifTrue:[ |
|
3745 |
|i| |
|
3746 |
i := styleString lastIndexOf:$-. |
|
3747 |
spacing := styleString copyFrom:(i+1). |
|
3748 |
styleString := styleString copyTo:(i-1). |
|
3749 |
] ifFalse:[ |
|
3750 |
spacing := 'normal'. |
|
3751 |
]. |
|
2323 | 3752 |
]. |
3753 |
||
3754 |
xlatedStyle := styleString. |
|
3755 |
xlatedStyle notNil ifTrue:[ |
|
2328 | 3756 |
xlatedStyle := xlatedStyle first asString |
2323 | 3757 |
]. |
3758 |
||
3759 |
id := self |
|
2328 | 3760 |
getFontWithFoundry:'*' |
3761 |
family:familyString asLowercase |
|
3762 |
weight:faceString |
|
3763 |
slant:styleString "/ xlatedStyle |
|
3764 |
spacing:spacing |
|
3765 |
pixelSize:nil |
|
3766 |
size:sizeArg |
|
3767 |
registry:'*' |
|
3768 |
encoding:encodingSym. |
|
2323 | 3769 |
|
3770 |
id isNil ifTrue:[ |
|
2328 | 3771 |
(encodingSym notNil and:[encodingSym ~= '*']) ifTrue:[ |
3772 |
"/ too stupid: encodings come in both cases |
|
3773 |
"/ |
|
3774 |
id := self |
|
3775 |
getFontWithFoundry:'*' |
|
3776 |
family:familyString asLowercase |
|
3777 |
weight:faceString |
|
3778 |
slant:styleString "/ xlatedStyle |
|
3779 |
spacing:spacing |
|
3780 |
pixelSize:nil |
|
3781 |
size:sizeArg |
|
3782 |
registry:'*' |
|
3783 |
encoding:encodingSym asUppercase. |
|
3784 |
id isNil ifTrue:[ |
|
3785 |
id := self |
|
3786 |
getFontWithFoundry:'*' |
|
3787 |
family:familyString asLowercase |
|
3788 |
weight:faceString |
|
3789 |
slant:styleString "/ xlatedStyle |
|
3790 |
spacing:spacing |
|
3791 |
pixelSize:nil |
|
3792 |
size:sizeArg |
|
3793 |
registry:'*' |
|
3794 |
encoding:encodingSym asLowercase. |
|
3795 |
||
3796 |
id isNil ifTrue:[ |
|
3797 |
id := self |
|
3798 |
getFontWithFoundry:'*' |
|
3799 |
family:familyString asLowercase |
|
3800 |
weight:faceString asLowercase |
|
3801 |
slant:styleString asLowercase |
|
3802 |
spacing:spacing |
|
3803 |
pixelSize:nil |
|
3804 |
size:sizeArg |
|
3805 |
registry:'*' |
|
3806 |
encoding:encodingSym asLowercase. |
|
3807 |
] |
|
3808 |
] |
|
3809 |
] |
|
2323 | 3810 |
]. |
3811 |
^ id |
|
3812 |
||
3813 |
"Modified: 24.2.1996 / 22:37:24 / cg" |
|
3814 |
"Modified: 4.7.1996 / 11:38:47 / stefan" |
|
3815 |
! |
|
3816 |
||
3817 |
getFontWithFoundry:foundry family:family weight:weight |
|
2328 | 3818 |
slant:slant spacing:spc pixelSize:pixelSize size:pointSize |
3819 |
registry:registry encoding:encoding |
|
2323 | 3820 |
|
3821 |
"get the specified font, if not available, return nil. |
|
3822 |
For now, this is a poor (incomplete) emulation of the X code ... |
|
3823 |
Individual attributes can be left empty (i.e. '') or nil to match any. |
|
3824 |
||
3825 |
foundry: 'adobe', 'misc', 'dec', 'schumacher' ... usually '*' |
|
3826 |
family: 'helvetica' 'courier' 'times' ... |
|
3827 |
weight: 'bold' 'medium' 'demi' ... |
|
3828 |
slant: 'r(oman)' 'i(talic)' 'o(blique)' |
|
3829 |
spacing: 'narrow' 'normal' semicondensed' ... usually '*' |
|
3830 |
pixelSize: 16,18 ... usually left empty |
|
3831 |
size: size in point (1/72th of an inch) |
|
3832 |
registry: iso8859, sgi ... '*' |
|
3833 |
encoding: vendor specific encoding (usually '*') |
|
3834 |
" |
|
3835 |
||
3836 |
" |
|
3837 |
Windows-NT/95 allows the creation of a font with the following parameters |
|
3838 |
||
2328 | 3839 |
nHeight |
3840 |
nWidth |
|
3841 |
nEscapement |
|
3842 |
nOrientation |
|
3843 |
fnWeight FW_DONTCARE, FW_NORMAL, FW_MEDIUM, FW_BOLD, ... |
|
3844 |
fdwItalic TRUE or FALSE |
|
3845 |
fdwUnderline TRUE or FALSE |
|
3846 |
fdwStrikeOut TRUE or FALSE |
|
3847 |
fdwCharSet ANSI_CHARSET, UNICODE_, SYMBOL_, SHIFTJIS_,... |
|
3848 |
fdwOutputPrecision DEFAULT, STRING, CHAR, ... |
|
3849 |
fdwClipPrecision DEFAULT, CHAR, STROKE, MASK, ... |
|
3850 |
fdwQuality DEFAULT, DRAFT, or PROOF. |
|
3851 |
fdwPitchAndFamily |
|
3852 |
DEFAULT, FIXED or VARIABLE pitch |
|
3853 |
DECORATIVE, DONTCASE, MODERN, ROMAN, SCRIPT, or SWISS. |
|
3854 |
lpszFace |
|
3855 |
Typeface Name |
|
2323 | 3856 |
|
3857 |
These two above descriptions will be matched as follows: |
|
3858 |
||
2328 | 3859 |
foundry - ignored |
3860 |
family - mapped to type face name. |
|
3861 |
weight - mapped to fnWeight |
|
3862 |
slant - used for style |
|
3863 |
spacing - NOT USED INITIALLY |
|
3864 |
pixelSize - NOT USED INITIALLY |
|
3865 |
size - mapped to nHeight |
|
3866 |
registry - NOT USED INITIALLY |
|
3867 |
encoding - mapped to fdwCharSet |
|
2323 | 3868 |
" |
3869 |
||
3870 |
|logSize| |
|
3871 |
||
3872 |
pixelSize notNil ifTrue:[ |
|
2328 | 3873 |
logSize := pixelSize |
2323 | 3874 |
] ifFalse:[ |
2328 | 3875 |
logSize := (pointSize * (self getLogicalPixelSizeY) / 72.0) rounded. |
2323 | 3876 |
]. |
3877 |
%{ |
|
3878 |
HGDIOBJ hFont; |
|
3879 |
int pointSize, nHeight, nWidth, nEscapement, nOrientation; |
|
3880 |
char* work; |
|
3881 |
char* work2; |
|
3882 |
DWORD fnWeight; |
|
3883 |
DWORD fdwItalic; |
|
3884 |
DWORD fdwUnderline; |
|
3885 |
DWORD fdwStrikeOut; |
|
3886 |
DWORD fdwCharSet; |
|
3887 |
DWORD fdwOutputPrecision; |
|
3888 |
DWORD fdwClipPrecision; |
|
3889 |
DWORD fdwQuality; |
|
3890 |
DWORD fdwPitchAndFamily; |
|
3891 |
static char faceName[256]; |
|
3892 |
||
3893 |
/* INITIALIZE */ |
|
3894 |
strcpy( faceName, "NULL" ); |
|
3895 |
nHeight = 0; |
|
3896 |
nWidth = 0; |
|
3897 |
nEscapement = 0; |
|
3898 |
nOrientation = 0; |
|
3899 |
fnWeight = FW_NORMAL; |
|
3900 |
fdwItalic = FALSE; |
|
3901 |
fdwUnderline = FALSE; |
|
3902 |
fdwStrikeOut = FALSE; |
|
3903 |
fdwOutputPrecision = OUT_DEFAULT_PRECIS; |
|
3904 |
fdwClipPrecision = CLIP_DEFAULT_PRECIS; |
|
3905 |
fdwQuality = DEFAULT_QUALITY; |
|
3906 |
fdwPitchAndFamily = FF_DONTCARE; |
|
3907 |
||
3908 |
fdwCharSet = ANSI_CHARSET; |
|
3909 |
if ((encoding == @symbol('ms-ansi'))) { |
|
2328 | 3910 |
fdwCharSet = ANSI_CHARSET; |
2323 | 3911 |
} else if (encoding == @symbol('ms-default')) { |
2328 | 3912 |
fdwCharSet = DEFAULT_CHARSET; |
2323 | 3913 |
} else if ((encoding == @symbol('ms-symbol')) |
2328 | 3914 |
|| (encoding == @symbol('misc-fontspecific'))) { |
3915 |
fdwCharSet = SYMBOL_CHARSET; |
|
2323 | 3916 |
} else if ((encoding == @symbol('ms-shiftjis')) |
2328 | 3917 |
|| (encoding == @symbol('jisx0208.1983-0'))){ |
3918 |
fdwCharSet = SHIFTJIS_CHARSET; |
|
2323 | 3919 |
} else if ((encoding == @symbol('ms-gb2312')) |
2328 | 3920 |
|| (encoding == @symbol('gb2312.1980-0'))) { |
3921 |
fdwCharSet = GB2312_CHARSET; |
|
2323 | 3922 |
} else if ((encoding == @symbol('ms-hangeul')) |
2328 | 3923 |
|| (encoding == @symbol('ksc5601.1987-0'))) { |
3924 |
fdwCharSet = HANGEUL_CHARSET; |
|
2323 | 3925 |
} else if ((encoding == @symbol('ms-chinesebig5')) |
2328 | 3926 |
|| (encoding == @symbol('big5'))) { |
3927 |
fdwCharSet = CHINESEBIG5_CHARSET; |
|
2323 | 3928 |
} else if (encoding == @symbol('ms-oem')) { |
2328 | 3929 |
fdwCharSet = OEM_CHARSET; |
2323 | 3930 |
} else if (encoding == @symbol('ms-johab')) { |
2328 | 3931 |
fdwCharSet = JOHAB_CHARSET; |
2323 | 3932 |
} else if ((encoding == @symbol('ms-hebrew')) |
2328 | 3933 |
|| (encoding == @symbol('ms-cp1255'))) { |
3934 |
fdwCharSet = HEBREW_CHARSET; |
|
2323 | 3935 |
} else if ((encoding == @symbol('ms-arabic')) |
2328 | 3936 |
|| (encoding == @symbol('ms-cp1256'))) { |
3937 |
fdwCharSet = ARABIC_CHARSET; |
|
2323 | 3938 |
} else if ((encoding == @symbol('ms-greek')) |
2328 | 3939 |
|| (encoding == @symbol('ms-cp1253'))) { |
3940 |
fdwCharSet = GREEK_CHARSET; |
|
2323 | 3941 |
} else if ((encoding == @symbol('ms-turkish')) |
2328 | 3942 |
|| (encoding == @symbol('ms-cp1254'))) { |
3943 |
fdwCharSet = TURKISH_CHARSET; |
|
2323 | 3944 |
} else if ((encoding == @symbol('ms-russian')) |
2328 | 3945 |
|| (encoding == @symbol('ms-cp1251'))) { |
3946 |
fdwCharSet = RUSSIAN_CHARSET; |
|
2323 | 3947 |
} else if ((encoding == @symbol('ms-easteurope')) |
2328 | 3948 |
|| (encoding == @symbol('ms-cp1250'))) { |
3949 |
fdwCharSet = EASTEUROPE_CHARSET; |
|
2323 | 3950 |
} else if ((encoding == @symbol('ms-baltic')) |
2328 | 3951 |
|| (encoding == @symbol('ms-cp1257'))) { |
3952 |
fdwCharSet = BALTIC_CHARSET; |
|
2323 | 3953 |
} else if ((encoding == @symbol('ms-vietnamese'))) { |
2328 | 3954 |
fdwCharSet = VIETNAMESE_CHARSET; |
2323 | 3955 |
} else if ((encoding == @symbol('ms-thai'))) { |
2328 | 3956 |
fdwCharSet = THAI_CHARSET; |
2323 | 3957 |
} else if ((encoding == @symbol('ms-mac'))) { |
2328 | 3958 |
fdwCharSet = MAC_CHARSET; |
2323 | 3959 |
#ifdef UNICODE_CHARSET |
3960 |
} else if ((encoding == @symbol('ms-unicode'))) { |
|
2328 | 3961 |
fdwCharSet = UNICODE_CHARSET; |
2323 | 3962 |
#endif |
3963 |
} |
|
3964 |
||
3965 |
if ( __isString( family ) ) { |
|
2328 | 3966 |
work = __stringVal( family ); |
3967 |
if (strcmp( work, "nil" ) != 0 ) { |
|
3968 |
strncpy( faceName, work, sizeof(faceName)-1 ); |
|
3969 |
} |
|
2323 | 3970 |
} |
3971 |
||
3972 |
/* Q: should we allow those ? (they make ST/X programs less portable to X */ |
|
3973 |
if( __isString( weight ) ) { |
|
2328 | 3974 |
work = __stringVal( weight ); |
3975 |
if (strcmp( work, "bold" ) == 0 ) { |
|
3976 |
fnWeight = FW_BOLD; |
|
3977 |
} else if (strcmp( work, "medium" ) == 0 ) { |
|
3978 |
fnWeight = FW_MEDIUM; |
|
3979 |
} else if (strcmp( work, "normal" ) == 0 ) { |
|
3980 |
fnWeight = FW_NORMAL; |
|
3981 |
} else if (strcmp( work, "light" ) == 0 ) { |
|
3982 |
fnWeight = FW_LIGHT; |
|
3983 |
} else if (strcmp( work, "demi" ) == 0 ) { |
|
3984 |
fnWeight = FW_LIGHT; |
|
3985 |
} else if (strcmp( work, "heavy" ) == 0 ) { |
|
3986 |
fnWeight = FW_HEAVY; |
|
3987 |
} else if (strcmp( work, "extraBold" ) == 0 ) { |
|
3988 |
fnWeight = FW_EXTRABOLD; |
|
3989 |
} else if (strcmp( work, "semiBold" ) == 0 ) { |
|
3990 |
fnWeight = FW_SEMIBOLD; |
|
3991 |
} else if (strcmp( work, "thin" ) == 0 ) { |
|
3992 |
fnWeight = FW_THIN; |
|
3993 |
} else if (strcmp( work, "extraLight" ) == 0 ) { |
|
3994 |
fnWeight = FW_EXTRALIGHT; |
|
3995 |
} |
|
2323 | 3996 |
} else if (__isSmallInteger(weight)) { |
2328 | 3997 |
fnWeight = __intVal(weight); |
2323 | 3998 |
} |
3999 |
||
4000 |
if(__isSmallInteger( logSize )) { |
|
2328 | 4001 |
nHeight = __intVal( logSize ); |
2323 | 4002 |
} |
4003 |
||
4004 |
if (__isString(slant)) { |
|
2328 | 4005 |
work2 = __stringVal( slant ); |
4006 |
work = __stringVal( slant ); |
|
4007 |
||
4008 |
if (strncmp(work2, "italic", 6) == 0) { |
|
4009 |
fdwItalic = TRUE; |
|
4010 |
if ( work2[6] == '-' ) |
|
4011 |
strncpy( work, &work2[7], ( strlen( work2) - 7) ); |
|
4012 |
} else { |
|
4013 |
if (strncmp(work2, "oblique", 7) == 0) { |
|
4014 |
fdwItalic = TRUE; |
|
4015 |
if ( work2[7] == '-' ) |
|
4016 |
strncpy( work, &work2[8], ( strlen( work2) - 8) ); |
|
4017 |
} |
|
4018 |
} |
|
4019 |
if (strncmp( work, "underline", 9 ) == 0 ) { |
|
4020 |
fdwUnderline = TRUE; |
|
4021 |
if( work[10] == '-' ) |
|
4022 |
strncpy( work2, &work[11], ( strlen( work ) - 10 ) ); |
|
4023 |
} |
|
4024 |
if (strncmp( work2, "strikeOut", 9 ) == 0 ) { |
|
4025 |
fdwStrikeOut = TRUE; |
|
4026 |
} |
|
2323 | 4027 |
} |
4028 |
||
4029 |
DPRINTF(("CreateFont face:%s h=%d w=%d wght=%d\n", |
|
2328 | 4030 |
faceName, nHeight, nWidth, fnWeight)); |
2323 | 4031 |
|
4032 |
hFont = CreateFont( -nHeight, /* character height - not cell height */ |
|
2328 | 4033 |
nWidth, |
4034 |
nEscapement, |
|
4035 |
nOrientation, |
|
4036 |
fnWeight, |
|
4037 |
fdwItalic, |
|
4038 |
fdwUnderline, |
|
4039 |
fdwStrikeOut, |
|
4040 |
fdwCharSet, |
|
4041 |
fdwOutputPrecision, |
|
4042 |
fdwClipPrecision, |
|
4043 |
fdwQuality, |
|
4044 |
fdwPitchAndFamily, |
|
4045 |
faceName ); |
|
2323 | 4046 |
|
4047 |
if (hFont != NULL) { |
|
2328 | 4048 |
DPRINTF(("createFont: %x\n", hFont)); |
2323 | 4049 |
/* |
4050 |
#ifdef COUNT_RESOURCES |
|
2328 | 4051 |
__cnt_font++; |
4052 |
RES1PRINTF(("CreateFont %d\n", __cnt_font)); |
|
2323 | 4053 |
#endif |
4054 |
*/ |
|
2328 | 4055 |
RETURN ( __MKOBJ(hFont) ); |
2323 | 4056 |
} |
4057 |
||
4058 |
DPRINTF(("***** ERROR createFontWithFoundry failed ERROR *****\n" )); |
|
4059 |
%}. |
|
4060 |
^ nil |
|
4061 |
||
4062 |
" |
|
4063 |
Display getFontWithFoundry:'*' |
|
2328 | 4064 |
family:'courier' |
4065 |
weight:'medium' |
|
4066 |
slant:'r' |
|
4067 |
spacing:nil |
|
4068 |
pixelSize:nil |
|
4069 |
size:13 |
|
4070 |
registry:'iso8859' |
|
4071 |
encoding:'*' |
|
2323 | 4072 |
" |
4073 |
||
4074 |
"new NT Version: 20.2.1997 / 22:33:29 / dq" |
|
4075 |
! |
|
4076 |
||
4077 |
primFontMetricsOf:fontId hdc:aDC intoArray:rawData |
|
4078 |
"evaluate aBlock, passing a fonts metrics as arguments. |
|
4079 |
fill passed array as: |
|
4080 |
ascent -> (data at:1) |
|
4081 |
descent -> (data at:2) |
|
4082 |
maxAscent -> (data at:3) |
|
4083 |
maxDescent -> (data at:4) |
|
4084 |
minWidth -> (data at:5) |
|
4085 |
maxWidth -> (data at:6) |
|
4086 |
avgWidth -> (data at:7). |
|
4087 |
minChar -> (data at:8). |
|
4088 |
maxChar -> (data at:9). |
|
4089 |
defaultChar-> (data at:10). |
|
4090 |
charSet -> (data at:11). |
|
4091 |
" |
|
4092 |
||
4093 |
%{ |
|
4094 |
||
4095 |
if (__isExternalAddress(fontId) |
|
4096 |
&& __isExternalAddressLike(aDC) |
|
4097 |
&& __isArray(rawData) |
|
4098 |
&& (__arraySize(rawData) >= 11)) { |
|
2328 | 4099 |
SIZE size; |
4100 |
int avgWidth; |
|
4101 |
HGDIOBJ hFont; |
|
4102 |
HGDIOBJ prevFont; |
|
4103 |
TEXTMETRIC tmet; |
|
4104 |
static char *s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; |
|
4105 |
static int len; |
|
4106 |
OBJ t; |
|
4107 |
HANDLE hDC; |
|
4108 |
||
4109 |
hFont = _HGDIOBJVal(fontId); |
|
4110 |
hDC = (HANDLE)(__externalAddressVal(aDC)); |
|
4111 |
||
4112 |
/* |
|
4113 |
* temporarily set this font in the tmpDC (root-) context |
|
4114 |
*/ |
|
4115 |
||
4116 |
prevFont = SelectObject(hDC, hFont); |
|
4117 |
||
4118 |
GetTextMetricsW(hDC, &tmet); |
|
4119 |
if (len == 0) { |
|
4120 |
len = strlen(s); |
|
4121 |
} |
|
2323 | 4122 |
#if 0 |
2328 | 4123 |
GetTextExtentPoint32(hDC, s, len, &size); |
4124 |
avgWidth = (size.cx / (len / 2) + 1) / 2; |
|
2323 | 4125 |
#else |
2328 | 4126 |
avgWidth = tmet.tmAveCharWidth; |
2323 | 4127 |
#endif |
4128 |
||
2328 | 4129 |
__ArrayInstPtr(rawData)->a_element[0] = __MKSMALLINT(tmet.tmAscent); /* ascent -> (data at:1) */ |
4130 |
__ArrayInstPtr(rawData)->a_element[1] = __MKSMALLINT(tmet.tmDescent); /* descent -> (data at:2) */ |
|
4131 |
__ArrayInstPtr(rawData)->a_element[2] = __MKSMALLINT(tmet.tmAscent); /* maxAscent -> (data at:3) */ |
|
4132 |
__ArrayInstPtr(rawData)->a_element[3] = __MKSMALLINT(tmet.tmDescent); /* maxDescent -> (data at:4) */ |
|
4133 |
__ArrayInstPtr(rawData)->a_element[4] = __MKSMALLINT(avgWidth); /* minWidth -> (data at:5) */ |
|
4134 |
__ArrayInstPtr(rawData)->a_element[5] = __MKSMALLINT(tmet.tmMaxCharWidth); /* maxWidth -> (data at:6) */ |
|
4135 |
__ArrayInstPtr(rawData)->a_element[6] = __MKSMALLINT(avgWidth); /* avgWidth -> (data at:7) */ |
|
4136 |
__ArrayInstPtr(rawData)->a_element[7] = __MKSMALLINT(tmet.tmFirstChar); /* min -> (data at:8) */ |
|
4137 |
__ArrayInstPtr(rawData)->a_element[8] = __MKSMALLINT(tmet.tmLastChar); /* max -> (data at:9) */ |
|
4138 |
__ArrayInstPtr(rawData)->a_element[9] = __MKSMALLINT(tmet.tmDefaultChar); /* default -> (data at:10) */ |
|
2323 | 4139 |
#if 0 |
2328 | 4140 |
t = __charSetSymbolFor(tmet.tmCharSet); |
4141 |
__ArrayInstPtr(rawData)->a_element[10]= t; __STORE(rawData, t); /* charSet -> (data at:11) */ |
|
2323 | 4142 |
#endif |
4143 |
||
2328 | 4144 |
DPRINTF(("textMetrics h=%x avgAsc=%d avgDesc=%d minW=%d maxW=%d avgW=%d\n", |
4145 |
hFont, tmet.tmAscent, tmet.tmDescent, avgWidth, tmet.tmMaxCharWidth, |
|
4146 |
tmet.tmAveCharWidth)); |
|
4147 |
||
4148 |
SelectObject(hDC, prevFont); |
|
4149 |
RETURN (self); |
|
2323 | 4150 |
} |
4151 |
RETURN (nil); |
|
4152 |
%} |
|
4153 |
! |
|
4154 |
||
4155 |
releaseFont:aFontId |
|
4156 |
||
4157 |
%{ /* NOCONTEXT */ |
|
4158 |
if (__isExternalAddress(aFontId)) { |
|
2328 | 4159 |
HGDIOBJ hFont = _HGDIOBJVal(aFontId); |
4160 |
||
4161 |
if (hFont) { |
|
4162 |
DPRINTF(("ReleaseFont: %x\n", hFont)); |
|
4163 |
DeleteObject(hFont); |
|
4164 |
} |
|
2323 | 4165 |
} |
4166 |
%} |
|
4167 |
! |
|
4168 |
||
4169 |
setFont:aFontId in:aDC |
|
4170 |
"set font to be drawn in" |
|
4171 |
||
4172 |
%{ /* NOCONTEXT */ |
|
4173 |
||
4174 |
if (__isExternalAddressLike(aDC) |
|
4175 |
&& __isExternalAddress(aFontId)) |
|
4176 |
{ |
|
2328 | 4177 |
HANDLE hDC = (HANDLE)(__externalAddressVal(aDC)); |
4178 |
HGDIOBJ prevFont, hFont; |
|
4179 |
||
4180 |
hFont = _HGDIOBJVal(aFontId); |
|
4181 |
prevFont = SelectObject(hDC, hFont); |
|
4182 |
||
4183 |
RETURN ( self ); |
|
2323 | 4184 |
} |
4185 |
%}. |
|
4186 |
self primitiveFailed |
|
4187 |
||
4188 |
"Created: / 04-08-2006 / 12:32:53 / fm" |
|
4189 |
! |
|
4190 |
||
4191 |
widthOf:aString from:index1 to:index2 inFont:aFontId |
|
4192 |
||
4193 |
%{ /* NOCONTEXT */ |
|
4194 |
unsigned char *cp; |
|
4195 |
int len, n, i1, i2, l; |
|
4196 |
OBJ cls; |
|
4197 |
int nInstBytes; |
|
4198 |
||
4199 |
if (__bothSmallInteger(index1, index2) |
|
4200 |
&& __isExternalAddress(aFontId) |
|
4201 |
&& __isExternalAddressLike(__INST(gcId)) |
|
4202 |
&& __isNonNilObject(aString)) { |
|
2328 | 4203 |
HGDIOBJ hFont,prevFont; |
4204 |
HANDLE hDC; |
|
4205 |
SIZE tsize; |
|
2323 | 4206 |
|
4207 |
#ifndef PRE_22_FEP_2007 |
|
4208 |
# define N_QUICK_CHARS 1024 |
|
2328 | 4209 |
unsigned short quickWchars[N_QUICK_CHARS]; |
4210 |
unsigned short *wcharPtr; |
|
4211 |
int mustFree = 0; |
|
4212 |
int i; |
|
2323 | 4213 |
#endif |
4214 |
||
2328 | 4215 |
hFont = _HGDIOBJVal(aFontId); |
4216 |
hDC = (HANDLE)(__externalAddressVal(__INST(gcId))); |
|
4217 |
||
4218 |
prevFont = SelectObject(hDC, hFont); |
|
4219 |
||
4220 |
i1 = __intVal(index1) - 1; |
|
4221 |
cls = __qClass(aString); |
|
4222 |
||
4223 |
if (i1 >= 0) { |
|
4224 |
i2 = __intVal(index2) - 1; |
|
4225 |
if (i2 < i1) { |
|
4226 |
RETURN ( __MKSMALLINT( 0 ) ); |
|
4227 |
} |
|
4228 |
||
4229 |
cp = (char *) _stringVal(aString); |
|
4230 |
l = i2 - i1 + 1; |
|
4231 |
||
4232 |
if ((cls == @global(String)) || (cls == @global(Symbol))) { |
|
4233 |
n = _stringSize(aString); |
|
2323 | 4234 |
commonWidthChars: |
2328 | 4235 |
if (i2 < n) { |
4236 |
cp += i1; |
|
2323 | 4237 |
|
4238 |
#ifdef PRE_22_FEP_2007 |
|
2328 | 4239 |
GetTextExtentPoint32(hDC, cp, l, &tsize); |
2323 | 4240 |
#else |
2328 | 4241 |
if (l <= N_QUICK_CHARS) { |
4242 |
wcharPtr = quickWchars; |
|
4243 |
mustFree = 0; |
|
4244 |
} else { |
|
4245 |
wcharPtr = malloc(sizeof(short)*l); |
|
4246 |
if (! wcharPtr) RETURN (__MKSMALLINT(0)); |
|
4247 |
mustFree = 1; |
|
4248 |
} |
|
4249 |
for (i=0; i<l; i++) wcharPtr[i] = ((unsigned char *)cp)[i]; |
|
4250 |
GetTextExtentPoint32W(hDC, wcharPtr, l, &tsize); |
|
4251 |
if (mustFree) free(wcharPtr); |
|
2323 | 4252 |
#endif |
4253 |
||
4254 |
#ifdef SUPERDEBUG |
|
2328 | 4255 |
if (__debug__) { |
4256 |
char buf[80]; |
|
4257 |
||
4258 |
GetTextFace(hDC,80,buf); |
|
4259 |
console_printf("font1 %x %s >%s< l=%d dx=%d\n",hFont,buf,cp,l,tsize.cx); |
|
4260 |
} |
|
2323 | 4261 |
#endif |
2328 | 4262 |
SelectObject(hDC, prevFont); |
4263 |
RETURN ( __MKSMALLINT(tsize.cx) ); |
|
4264 |
} |
|
4265 |
RETURN (__MKSMALLINT(0)); |
|
4266 |
} |
|
4267 |
||
4268 |
nInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
4269 |
cp += nInstBytes; |
|
4270 |
n = __byteArraySize(aString) - nInstBytes; |
|
4271 |
||
4272 |
if (__isBytes(aString)) { |
|
4273 |
goto commonWidthChars; |
|
4274 |
} |
|
4275 |
||
4276 |
/* Unicode */ |
|
4277 |
if (__isWords(aString)) { |
|
4278 |
n = n / 2; |
|
4279 |
if (i2 < n) { |
|
4280 |
WIDECHAR *w_cp = (WIDECHAR *)cp; |
|
4281 |
||
4282 |
w_cp += i1; |
|
4283 |
||
4284 |
GetTextExtentPoint32W(hDC, w_cp, l, &tsize); |
|
4285 |
SelectObject(hDC, prevFont); |
|
4286 |
RETURN ( __MKSMALLINT(tsize.cx) ); |
|
4287 |
} |
|
4288 |
RETURN (__MKSMALLINT(0)); |
|
4289 |
} |
|
4290 |
} |
|
2323 | 4291 |
} |
4292 |
%}. |
|
4293 |
self primitiveFailed. |
|
4294 |
^ 0 |
|
4295 |
! |
|
4296 |
||
4297 |
widthOf:aString inFont:aFontId |
|
4298 |
"return the width in pixels of a string in a specific font" |
|
4299 |
||
4300 |
^ self widthOf:aString from:1 to:(aString size) inFont:aFontId |
|
2316 | 4301 |
! ! |
4302 |
||
2299 | 4303 |
!WinPrinterContext methodsFor:'initialization & release'! |
4304 |
||
4305 |
createDC |
|
4306 |
"Private - Create a device context for the receiver" |
|
2317 | 4307 |
|
2299 | 4308 |
gcId := printerInfo createDC |
4309 |
||
4310 |
"Created: / 27-07-2006 / 10:21:05 / fm" |
|
4311 |
"Modified: / 02-08-2006 / 17:30:47 / fm" |
|
4312 |
"Modified: / 10-10-2006 / 18:14:28 / cg" |
|
4313 |
! |
|
4314 |
||
2315 | 4315 |
deleteDC |
4316 |
"Private - Delete a device context for the receiver" |
|
4317 |
||
4318 |
OperatingSystem deletePrinterDC: gcId. |
|
4319 |
! |
|
4320 |
||
2323 | 4321 |
destroy |
4322 |
"Destroy the GC." |
|
4323 |
||
4324 |
|id| |
|
4325 |
||
4326 |
id := gcId. |
|
4327 |
id notNil ifTrue:[ |
|
2328 | 4328 |
gcId := nil. |
4329 |
self deleteDC. |
|
2323 | 4330 |
]. |
4331 |
"/ Lobby unregister:self. |
|
4332 |
! |
|
4333 |
||
4334 |
destroyGC:aDC |
|
4335 |
%{ |
|
4336 |
if (__isExternalAddressLike(aDC)) { |
|
2328 | 4337 |
HANDLE hDC = (HANDLE)(__externalAddressVal(aDC)); |
4338 |
||
4339 |
DeleteDC(hDC); |
|
2323 | 4340 |
|
4341 |
/* |
|
4342 |
#ifdef CACHE_LAST_DC |
|
2328 | 4343 |
if (lastGcData == gcData) { |
4344 |
_releaseDC(gcData); |
|
4345 |
} |
|
2323 | 4346 |
#endif |
4347 |
*/ |
|
4348 |
||
4349 |
} |
|
4350 |
%} |
|
4351 |
! |
|
4352 |
||
2299 | 4353 |
executor |
4354 |
|aCopy| |
|
4355 |
||
4356 |
aCopy := WinWorkstation::PrinterDeviceContextHandle basicNew. |
|
4357 |
aCopy setDevice:device id:nil gcId:gcId. |
|
4358 |
^ aCopy |
|
4359 |
||
4360 |
"Created: / 16-04-2007 / 12:39:02 / cg" |
|
2315 | 4361 |
! |
4362 |
||
2323 | 4363 |
initialize |
4364 |
super initialize. |
|
4365 |
"/ deviceForms := Registry new. |
|
4366 |
"/ deviceColors := Registry new. |
|
4367 |
deviceFonts := CachingRegistry new cacheSize:10. |
|
4368 |
! |
|
4369 |
||
2315 | 4370 |
releaseDC |
4371 |
"Private - Delete and clear the device context of the receiver." |
|
4372 |
||
4373 |
self deleteDC. |
|
2316 | 4374 |
"/ device close. |
2323 | 4375 |
gcId := nil. |
4376 |
self releaseDeviceFonts |
|
4377 |
! |
|
4378 |
||
4379 |
releaseDeviceFonts |
|
4380 |
deviceFonts isEmptyOrNil ifFalse:[ |
|
2328 | 4381 |
deviceFonts do:[:afont | |
4382 |
afont releaseFromDevice. |
|
4383 |
]. |
|
2323 | 4384 |
]. |
4385 |
deviceFonts := CachingRegistry new cacheSize:10. |
|
4386 |
! ! |
|
4387 |
||
2328 | 4388 |
!WinPrinterContext methodsFor:'non standard methods'! |
4389 |
||
4390 |
stringWidthOf:aString at:index |
|
4391 |
"Return the width of aString up to index |
|
4392 |
when written using the current font; expand tabs out |
|
4393 |
to 4 spaces for calculations" |
|
4394 |
||
4395 |
|answer str size spaceWidth| |
|
4396 |
||
4397 |
index <= 0 ifTrue:[ ^ 0 ]. |
|
4398 |
str := index >= aString size ifTrue:[ aString ] ifFalse:[ aString copyFrom:1 to:index ]. |
|
4399 |
true "self font isNil" ifTrue:[ |
|
4400 |
"if font not set yet, calculate based on default font" |
|
4401 |
"/ extString := str asExternalString. |
|
4402 |
size := Win32OperatingSystem::WinPointStructure new. |
|
4403 |
(OperatingSystem |
|
4404 |
getTextExtentPoint:gcId |
|
4405 |
string:str |
|
4406 |
size:size) ifFalse:[ ^ self error ]. |
|
4407 |
answer := size x. |
|
4408 |
"/ Transcript showCR: 'FROM PRIM ******* ', str, ' ', answer printString. |
|
4409 |
"/ Transcript showCR: 'FROM DEVICE ***** ', str, ' ',(self font widthOf:str on:self device) printString. |
|
4410 |
#TODO. |
|
4411 |
] ifFalse:[ |
|
4412 |
answer := self font widthOf:str on:self device |
|
4413 |
]. |
|
4414 |
index > aString size ifTrue:[ |
|
4415 |
spaceWidth := self font widthOf:Character space on:self device. |
|
4416 |
answer := answer + ((index - aString size) * spaceWidth) |
|
4417 |
]. |
|
4418 |
^ answer. |
|
4419 |
||
4420 |
"Created: / 03-08-2006 / 10:27:20 / fm" |
|
4421 |
"Modified: / 04-08-2006 / 12:27:26 / fm" |
|
4422 |
"Modified: / 10-10-2006 / 18:20:43 / cg" |
|
4423 |
! ! |
|
4424 |
||
2323 | 4425 |
!WinPrinterContext methodsFor:'not supported yet'! |
4426 |
||
4427 |
displayAdvanceLineFrom:point1 to:point2 |
|
4428 |
"draw a line" |
|
4429 |
||
4430 |
self displayAdvanceLineFromX:(point1 x) y:(point1 y) |
|
2328 | 4431 |
toX:(point2 x) y:(point2 y) |
2323 | 4432 |
! |
4433 |
||
4434 |
displayAdvanceLineFromX:x0 y:y0 toX:x1 y:y1 |
|
4435 |
"draw a line (with current paint-color); apply transformation if nonNil" |
|
4436 |
||
4437 |
|pX0 pY0 pX1 pY1 easy fgId bgId| |
|
4438 |
||
4439 |
gcId isNil ifTrue:[ |
|
2328 | 4440 |
self initGC |
2323 | 4441 |
]. |
4442 |
||
4443 |
lineStyle == #doubleDashed ifTrue:[ |
|
2328 | 4444 |
" |
4445 |
if bgPaint or paint is not a real color, we have to do it the hard way ... |
|
4446 |
" |
|
4447 |
easy := true. |
|
4448 |
paint isColor ifFalse:[ |
|
4449 |
easy := false |
|
4450 |
] ifTrue:[ |
|
4451 |
fgId := paint colorId. |
|
4452 |
fgId isNil ifTrue:[ |
|
4453 |
easy := false |
|
4454 |
] |
|
4455 |
]. |
|
4456 |
bgPaint isColor ifFalse:[ |
|
4457 |
easy := false |
|
4458 |
] ifTrue:[ |
|
4459 |
bgId := bgPaint colorId. |
|
4460 |
bgId isNil ifTrue:[ |
|
4461 |
easy := false |
|
4462 |
] |
|
4463 |
]. |
|
4464 |
||
4465 |
easy ifTrue:[ |
|
4466 |
((foreground ~~ paint) or:[background ~~ bgPaint]) ifTrue:[ |
|
4467 |
device setForeground:fgId background:bgId in:gcId. |
|
4468 |
foreground := paint. |
|
4469 |
background := bgPaint. |
|
4470 |
]. |
|
4471 |
] ifFalse:[ |
|
4472 |
'DeviceGraphicsContext [warning]: cannot draw dashes with dithered colors' errorPrintCR |
|
4473 |
]. |
|
2323 | 4474 |
]. |
4475 |
||
4476 |
transformation notNil ifTrue:[ |
|
2328 | 4477 |
pX0 := transformation applyToX:x0. |
4478 |
pY0 := transformation applyToY:y0. |
|
4479 |
pX1 := transformation applyToX:x1. |
|
4480 |
pY1 := transformation applyToY:y1. |
|
2323 | 4481 |
] ifFalse:[ |
2328 | 4482 |
pX0 := x0. |
4483 |
pY0 := y0. |
|
4484 |
pX1 := x1. |
|
4485 |
pY1 := y1 |
|
2323 | 4486 |
]. |
4487 |
||
4488 |
pX0 := pX0 rounded. |
|
4489 |
pY0 := pY0 rounded. |
|
4490 |
pX1 := pX1 rounded. |
|
4491 |
pY1 := pY1 rounded. |
|
4492 |
||
4493 |
device displayAdvanceLineFromX:pX0 y:pY0 toX:pX1 y:pY1 in:drawableId with:gcId |
|
4494 |
||
4495 |
"Modified: 10.1.1997 / 17:46:32 / cg" |
|
4496 |
! |
|
4497 |
||
4498 |
displayAdvanceLineFromX:x0 y:y0 toX:x1 y:y1 in:ignoredDrawableId with:aDC |
|
4499 |
"draw a line. If the coordinates are not integers, an error is triggered." |
|
4500 |
||
4501 |
self getPenForMyContext. |
|
4502 |
||
4503 |
%{ /* NOCONTEXT */ |
|
4504 |
if (__isExternalAddressLike(aDC) |
|
4505 |
&& __bothSmallInteger(x0, y0) |
|
4506 |
&& __bothSmallInteger(x1, y1)) { |
|
2328 | 4507 |
HANDLE hDC = (HANDLE)(__externalAddressVal(aDC)); |
4508 |
COLORREF fgColor; |
|
4509 |
int __x1 = __intVal(x1), __y1 = __intVal(y1); |
|
2323 | 4510 |
|
4511 |
||
4512 |
/* DPRINTF(("displayLine: %d/%d -> %d/%d\n", |
|
2328 | 4513 |
__intVal(x0), __intVal(y0), |
4514 |
__x1, __y1)); |
|
2323 | 4515 |
*/ |
4516 |
||
4517 |
/* fgColor = GetTextColor(hDC); |
|
4518 |
* hPen = CreatePen(PS_SOLID, 1, fgColor); |
|
4519 |
*/ |
|
4520 |
||
2328 | 4521 |
MoveToEx(hDC, __intVal(x0), __intVal(y0), NULL); |
4522 |
||
4523 |
LineTo(hDC, __x1, __y1); |
|
4524 |
||
4525 |
/* |
|
4526 |
* end-point ... |
|
4527 |
*/ |
|
4528 |
LineTo(hDC, __x1+1, __y1); |
|
4529 |
||
4530 |
||
4531 |
||
4532 |
RETURN ( self ); |
|
2323 | 4533 |
} |
4534 |
%} |
|
4535 |
! |
|
4536 |
||
2328 | 4537 |
gcForBitmap:aDrawableId |
4538 |
||
4539 |
%{ /* NOCONTEXT */ |
|
4540 |
||
4541 |
if (__isExternalAddress(aDrawableId)){ |
|
2338 | 4542 |
BITMAP bitmap; |
4543 |
HBITMAP hBitmap = _HBITMAPVAL(aDrawableId); |
|
4544 |
HBITMAP memBM; |
|
4545 |
HANDLE compatibleDC, rootDC, hdcScreen; |
|
2328 | 4546 |
// HANDLE printerDC = (HANDLE)(__externalAddressVal(__INST(gcId))); |
4547 |
||
2338 | 4548 |
if (! hBitmap) { |
4549 |
RETURN (nil); |
|
4550 |
} |
|
4551 |
||
4552 |
if (GetObject(hBitmap, sizeof(bitmap), &bitmap)) { |
|
2328 | 4553 |
/* |
2338 | 4554 |
DDPRINTF(("bitmap info:%d\n", bitmap.bmBitsPixel)); |
2328 | 4555 |
*/ |
2338 | 4556 |
} else { |
2328 | 4557 |
/* |
2338 | 4558 |
DPRINTF(("noinfo returned for bitmap\n")); |
2328 | 4559 |
*/ |
2338 | 4560 |
/* mhmh - can this happen ? */ |
4561 |
bitmap.bmBitsPixel = 1; |
|
4562 |
} |
|
2328 | 4563 |
/* |
2338 | 4564 |
gcData->hBitmap = hBitmap; |
4565 |
gcData->bitmapColorBitCount = bitmap.bmBitsPixel; |
|
2328 | 4566 |
*/ |
4567 |
||
2338 | 4568 |
rootDC = CreateDC("DISPLAY", NULL, NULL, NULL); |
4569 |
compatibleDC = CreateCompatibleDC(rootDC); |
|
4570 |
SelectObject(compatibleDC, hBitmap); |
|
2328 | 4571 |
|
4572 |
// hdcScreen= CreateDC("NULL", NULL, NULL, NULL); |
|
4573 |
// compatibleDC = rootDC; |
|
4574 |
// compatibleDC = CreateCompatibleDC(printerDC); |
|
4575 |
// compatibleDC = CreateCompatibleDC(0); |
|
2338 | 4576 |
|
2328 | 4577 |
// memBM = CreateCompatibleBitmap ( compatibleDC, bitmap.bmWidth, bitmap.bmHeight ); |
4578 |
// SelectObject ( compatibleDC, memBM ); |
|
4579 |
||
2338 | 4580 |
RETURN (__MKOBJ(compatibleDC)); |
2328 | 4581 |
|
4582 |
/* |
|
2338 | 4583 |
RETURN ( __MKOBJ(gcData) ); |
2328 | 4584 |
*/ |
4585 |
} |
|
4586 |
RETURN (nil); |
|
4587 |
%} |
|
4588 |
! |
|
4589 |
||
2324 | 4590 |
getPenForMyContext |
4591 |
"Get a pen for my context" |
|
4592 |
||
4593 |
|maskOriginX maskOriginY| |
|
4594 |
||
4595 |
self maskOrigin isNil ifFalse:[ |
|
2328 | 4596 |
maskOriginX := self maskOrigin x. |
4597 |
maskOriginY := self maskOrigin y. |
|
2324 | 4598 |
]. |
4599 |
||
2325 | 4600 |
%{ |
2324 | 4601 |
HPEN hPen = 0; |
4602 |
HPEN prevPen; |
|
4603 |
LOGBRUSH Brush; |
|
4604 |
COLORREF fgColor; |
|
4605 |
HANDLE hDC = (HANDLE)(__externalAddressVal(__INST(gcId))); |
|
4606 |
int lStyle, bkMode, hMask, maskOrgX, maskOrgY; |
|
4607 |
int style, lineStyle, capStyle, joinStyle; |
|
4608 |
int lw; |
|
4609 |
int BK_TRANSPARENT; |
|
4610 |
||
4611 |
BK_TRANSPARENT = 1; |
|
4612 |
||
4613 |
lw= __INST(lineWidth); |
|
4614 |
/* fgColor = __intVal(__INST(foreground)) & 0xffffff; */ |
|
4615 |
||
2325 | 4616 |
fgColor = GetTextColor(hDC); |
2324 | 4617 |
lineStyle=__INST(lineStyle); |
4618 |
capStyle=__INST(capStyle); |
|
4619 |
joinStyle=__INST(joinStyle); |
|
4620 |
hMask= __INST(mask); |
|
4621 |
maskOrgX=__intVal(maskOriginX); |
|
4622 |
maskOrgY=__intVal(maskOriginY); |
|
4623 |
||
4624 |
if (lineStyle == @symbol(solid)) { |
|
2328 | 4625 |
style = PS_SOLID; |
2324 | 4626 |
} else if (lineStyle == @symbol(dashed)) { |
2328 | 4627 |
style= PS_DASH; |
2324 | 4628 |
} else if (lineStyle == @symbol(dotted)) { |
2328 | 4629 |
style= PS_DOT; |
2324 | 4630 |
} else if (lineStyle == @symbol(dashDot)) { |
2328 | 4631 |
style= PS_DASHDOT; |
2324 | 4632 |
} else if (lineStyle == @symbol(dashDotDot)) { |
2328 | 4633 |
style= PS_DASHDOTDOT; |
2324 | 4634 |
} else |
2328 | 4635 |
style= PS_SOLID; |
2324 | 4636 |
lStyle &= ~PS_STYLE_MASK; |
4637 |
lStyle |= style; |
|
4638 |
||
4639 |
||
4640 |
if (capStyle == @symbol(round)) { |
|
2328 | 4641 |
style = PS_ENDCAP_ROUND; |
2324 | 4642 |
} else if (capStyle == @symbol(square)) { |
2328 | 4643 |
style = PS_ENDCAP_SQUARE; |
2324 | 4644 |
} else if (capStyle == @symbol(flat)) { |
2328 | 4645 |
style = PS_ENDCAP_FLAT; |
2324 | 4646 |
} else |
2328 | 4647 |
style = PS_ENDCAP_FLAT; |
2324 | 4648 |
lStyle &= ~PS_ENDCAP_MASK; |
4649 |
lStyle |= style; |
|
4650 |
||
4651 |
if (joinStyle == @symbol(bevel)) { |
|
2328 | 4652 |
style = PS_JOIN_BEVEL; |
2324 | 4653 |
} else if (joinStyle == @symbol(miter)) { |
2328 | 4654 |
style = PS_JOIN_MITER; |
2324 | 4655 |
} else if (joinStyle == @symbol(round)) { |
2328 | 4656 |
style = PS_JOIN_ROUND; |
2324 | 4657 |
} else |
2328 | 4658 |
style = PS_JOIN_MITER; |
2324 | 4659 |
lStyle &= ~PS_JOIN_MASK; |
4660 |
lStyle |= style; |
|
4661 |
||
4662 |
||
4663 |
if (((lStyle & PS_STYLE_MASK) == PS_SOLID) |
|
4664 |
&& (hMask == 0) |
|
4665 |
&& (lw /* lineWidth */ <= 1)) { |
|
2328 | 4666 |
if (fgColor == 0 /* BlackPixel */ ) { |
4667 |
hPen = GetStockObject(BLACK_PEN); |
|
4668 |
prevPen = SelectObject(hDC, hPen); |
|
4669 |
RETURN( hPen ); |
|
4670 |
} |
|
4671 |
if (fgColor == 1 /* WhitePixel */) { |
|
4672 |
hPen = GetStockObject(WHITE_PEN); |
|
4673 |
prevPen = SelectObject(hDC, hPen); |
|
4674 |
RETURN( hPen ); |
|
4675 |
} |
|
2324 | 4676 |
} |
4677 |
||
4678 |
hPen = (HPEN) 0; |
|
4679 |
||
4680 |
if (0 /* __isWinNT */) { |
|
4681 |
||
2328 | 4682 |
if (lw == 0) { |
4683 |
lw = 1; |
|
4684 |
} |
|
4685 |
/* |
|
4686 |
* NT supports masked drawing with any lineStyle, |
|
4687 |
* and also non-solid lines with any lineWidth. |
|
4688 |
*/ |
|
4689 |
if (hMask) { |
|
4690 |
Brush.lbStyle = BS_PATTERN; |
|
4691 |
Brush.lbHatch = (DWORD)hMask; |
|
4692 |
Brush.lbColor = fgColor; |
|
4693 |
} else { |
|
2324 | 4694 |
|
4695 |
#ifndef PRE_07_APR_04 |
|
4696 |
||
2328 | 4697 |
hPen = CreatePen((lStyle & PS_STYLE_MASK), lw, fgColor); |
2324 | 4698 |
|
4699 |
/* RESPRINTF(("CreatePen %x %d(%d) %x %x\n", |
|
4700 |
* lStyle, |
|
4701 |
* lw, __INST(lineWidth), |
|
4702 |
* fgColor, hMask)); |
|
4703 |
*/ |
|
4704 |
||
2328 | 4705 |
SetBkMode(hDC, TRANSPARENT); |
4706 |
bkMode = BK_TRANSPARENT; |
|
2324 | 4707 |
|
4708 |
#else |
|
2328 | 4709 |
Brush.lbStyle = BS_SOLID; |
4710 |
Brush.lbHatch = 0; |
|
4711 |
Brush.lbColor = fgColor; |
|
2324 | 4712 |
#endif |
2328 | 4713 |
} |
4714 |
||
4715 |
if (! hPen) |
|
4716 |
{ |
|
4717 |
hPen = ExtCreatePen(PS_GEOMETRIC | lStyle, |
|
4718 |
lw, /* lineWidth, */ |
|
4719 |
&Brush, |
|
4720 |
0, 0); |
|
2324 | 4721 |
|
4722 |
/* RESPRINTF(("ExtCreatePen1 %x %d(%d) %x %x\n", |
|
4723 |
* lStyle, |
|
4724 |
* lw, __INST(lineWidth), |
|
4725 |
* fgColor, hMask)); |
|
4726 |
*/ |
|
2328 | 4727 |
if (hMask) { |
4728 |
SetBrushOrgEx(hDC, maskOrgX, maskOrgY, 0); |
|
4729 |
} |
|
4730 |
} |
|
2324 | 4731 |
} else { |
2328 | 4732 |
/* |
4733 |
* W95 only supports masked drawing with SOLID lines |
|
4734 |
* also, we should use COSMETIC pens if possible |
|
4735 |
* with non-solid lineStyles. |
|
4736 |
*/ |
|
4737 |
if ((lStyle & PS_STYLE_MASK) == PS_SOLID) { |
|
4738 |
int ps = PS_GEOMETRIC; |
|
4739 |
||
4740 |
if (hMask) { |
|
4741 |
Brush.lbStyle = BS_PATTERN; |
|
4742 |
Brush.lbHatch = (DWORD)hMask; |
|
4743 |
Brush.lbColor = fgColor; |
|
4744 |
} else { |
|
4745 |
Brush.lbStyle = BS_SOLID; |
|
4746 |
Brush.lbHatch = 0; |
|
4747 |
Brush.lbColor = fgColor; |
|
4748 |
if (lw /* lineWidth */ <= 1) { |
|
4749 |
ps = PS_COSMETIC; |
|
4750 |
} |
|
4751 |
} |
|
4752 |
||
4753 |
hPen = ExtCreatePen(ps | lStyle, |
|
4754 |
lw, /* lineWidth */ |
|
4755 |
&Brush, |
|
4756 |
0, 0); |
|
2324 | 4757 |
|
4758 |
/* RESPRINTF(("ExtCreatePen1 %x %d %x %x\n", |
|
4759 |
* lStyle, |
|
2325 | 4760 |
* lw, |
2324 | 4761 |
* fgColor, hMask)); |
4762 |
*/ |
|
2328 | 4763 |
if (hMask) { |
4764 |
SetBrushOrgEx(hDC, maskOrgX, maskOrgY, 0); |
|
4765 |
} |
|
4766 |
} else { |
|
4767 |
||
4768 |
if (lw == 1) { |
|
4769 |
lw = 0; |
|
4770 |
} |
|
4771 |
||
4772 |
/* |
|
4773 |
* dashes only supported with lineWidth 0 |
|
4774 |
*/ |
|
4775 |
||
4776 |
hPen = CreatePen((lStyle & PS_STYLE_MASK), |
|
4777 |
lw, |
|
4778 |
fgColor); |
|
2324 | 4779 |
|
4780 |
/* RESPRINTF(("CreatePen %x %d %x\n", |
|
4781 |
* (lStyle & PS_STYLE_MASK), |
|
2325 | 4782 |
* lw, |
2324 | 4783 |
* fgColor)); |
4784 |
*/ |
|
2328 | 4785 |
// |
4786 |
// CG: wrong; must set to opaque, if doubleDashed |
|
4787 |
// |
|
4788 |
SetBkMode(hDC, TRANSPARENT); |
|
4789 |
bkMode = BK_TRANSPARENT; |
|
4790 |
} |
|
2324 | 4791 |
} |
4792 |
||
4793 |
prevPen = SelectObject(hDC, hPen); |
|
4794 |
||
4795 |
RETURN (hPen); |
|
4796 |
||
4797 |
%} |
|
4798 |
! |
|
4799 |
||
2328 | 4800 |
xprimDrawBits:imageBits bitsPerPixel:bitsPerPixel depth:imageDepth padding:padd width:imageWidth height:imageHeight |
4801 |
x:srcx y:srcy |
|
4802 |
into:ignoredDrawableId |
|
4803 |
x:dstx y:dsty |
|
4804 |
width:w height:h |
|
4805 |
with:aDC |
|
4806 |
||
4807 |
"since XPutImage may allocate huge amount of stack space |
|
4808 |
(some implementations use alloca), this must run with unlimited stack." |
|
4809 |
||
4810 |
%{ |
|
4811 |
unsigned char fastBits[10000]; |
|
4812 |
unsigned char *b_bits = 0; |
|
4813 |
unsigned char *allocatedBits = 0; |
|
4814 |
unsigned char *__imageBits = 0; |
|
4815 |
||
4816 |
if (__isByteArray(imageBits)) { |
|
4817 |
__imageBits = __ByteArrayInstPtr(imageBits)->ba_element; |
|
4818 |
} else if (__isExternalBytesLike(imageBits)) { |
|
4819 |
__imageBits = (unsigned char *)(__externalBytesAddress(imageBits)); |
|
4820 |
} |
|
4821 |
||
4822 |
if (/* ISCONNECTED |
|
4823 |
&& */ __isExternalAddressLike(aDC) |
|
4824 |
&& __bothSmallInteger(srcx, srcy) |
|
4825 |
&& __bothSmallInteger(dstx, dsty) |
|
4826 |
&& __bothSmallInteger(w, h) |
|
4827 |
&& __bothSmallInteger(imageWidth, imageHeight) |
|
4828 |
&& __bothSmallInteger(imageDepth, bitsPerPixel) |
|
4829 |
&& __isSmallInteger(padd) |
|
4830 |
&& __imageBits) |
|
4831 |
{ |
|
4832 |
HANDLE hDC = (HANDLE)(__externalAddressVal(aDC)); |
|
4833 |
struct |
|
4834 |
{ |
|
4835 |
BITMAPINFOHEADER bmiHeader; |
|
4836 |
DWORD r; |
|
4837 |
DWORD g; |
|
4838 |
DWORD b; |
|
4839 |
} bitmap; |
|
4840 |
||
4841 |
if (__intVal(padd) != WIN32PADDING) { |
|
4842 |
int row, col; |
|
4843 |
unsigned char *cp; |
|
4844 |
unsigned char *pBits; |
|
4845 |
int b_width, b_height, bytesPerRowST, bytesPerRowWN, padding, nBytes; |
|
4846 |
int bi = __intVal(bitsPerPixel); |
|
4847 |
||
4848 |
b_width = __intVal(w); |
|
4849 |
b_height = __intVal(h); |
|
4850 |
bytesPerRowST = (b_width * bi + (__intVal(padd)-1)) / __intVal(padd); |
|
4851 |
bytesPerRowWN = (b_width * bi + (WIN32PADDING-1)) / WIN32PADDING * (WIN32PADDING/8); |
|
4852 |
padding = bytesPerRowWN - bytesPerRowST; |
|
4853 |
nBytes = b_height * bytesPerRowWN; |
|
4854 |
/*console_printf("padd %d bs %d bw %d p %d\n",__intVal(padd),bytesPerRowST,bytesPerRowWN,padding);*/ |
|
4855 |
if (padding) { |
|
4856 |
if (nBytes < sizeof(fastBits)) { |
|
4857 |
cp = b_bits = fastBits; |
|
4858 |
} else { |
|
4859 |
cp = b_bits = allocatedBits = (unsigned char *) malloc(nBytes); |
|
4860 |
} |
|
4861 |
if (cp) { |
|
4862 |
pBits = __imageBits; |
|
4863 |
for (row = b_height; row; row--) { |
|
4864 |
for (col = bytesPerRowST; col; col--) { |
|
4865 |
*cp++ = *pBits++; |
|
4866 |
} |
|
4867 |
cp += padding; |
|
4868 |
} |
|
4869 |
} else |
|
4870 |
goto fail; |
|
4871 |
} |
|
4872 |
} |
|
4873 |
||
4874 |
if (b_bits == 0) { |
|
4875 |
b_bits = __imageBits; |
|
4876 |
} |
|
4877 |
||
4878 |
bitmap.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); |
|
4879 |
bitmap.bmiHeader.biPlanes = 1; |
|
4880 |
if (__intVal(imageDepth) == 24) { |
|
4881 |
/*bitmap.bmiHeader.biCompression = BI_BITFIELDS; |
|
4882 |
bitmap.r = 0xff0000; |
|
4883 |
bitmap.g = 0x00ff00; |
|
4884 |
bitmap.b = 0x0000ff;*/ |
|
4885 |
bitmap.bmiHeader.biCompression = BI_RGB; |
|
4886 |
} else if (__intVal(imageDepth) == 16) { |
|
4887 |
/*bitmap.bmiHeader.biCompression = BI_RGB; |
|
4888 |
bitmap.bmiHeader.biCompression = BI_BITFIELDS; |
|
4889 |
bitmap.b = 0x001f; |
|
4890 |
bitmap.g = 0x07e0; |
|
4891 |
bitmap.r = 0xf800;*/ |
|
4892 |
bitmap.b = 0; |
|
4893 |
bitmap.g = 0; |
|
4894 |
bitmap.r = 0; |
|
4895 |
bitmap.bmiHeader.biCompression = BI_RGB; |
|
4896 |
} |
|
4897 |
bitmap.bmiHeader.biSizeImage = 0; |
|
4898 |
bitmap.bmiHeader.biXPelsPerMeter = 0; |
|
4899 |
bitmap.bmiHeader.biYPelsPerMeter = 0; |
|
4900 |
bitmap.bmiHeader.biClrUsed = 0; |
|
4901 |
bitmap.bmiHeader.biClrImportant = 0; |
|
4902 |
bitmap.bmiHeader.biWidth = __intVal(imageWidth); |
|
4903 |
bitmap.bmiHeader.biHeight = -(__intVal(imageHeight)); |
|
4904 |
bitmap.bmiHeader.biBitCount = __intVal(bitsPerPixel); |
|
4905 |
/*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);*/ |
|
4906 |
SetDIBitsToDevice(hDC,__intVal(dstx),__intVal(dsty), |
|
4907 |
__intVal(w), __intVal(h), |
|
4908 |
__intVal(srcx), __intVal(srcy), |
|
4909 |
0,__intVal(h), |
|
4910 |
(void *)b_bits, |
|
4911 |
(BITMAPINFO*)&bitmap,DIB_RGB_COLORS); |
|
4912 |
if (allocatedBits) { |
|
4913 |
free(allocatedBits); |
|
4914 |
} |
|
4915 |
RETURN ( true ); |
|
4916 |
} |
|
4917 |
||
4918 |
fail: ; |
|
4919 |
/* |
|
4920 |
PRINTF(("create temp bitmap FAILED!!!\n")); |
|
4921 |
*/ |
|
4922 |
if (allocatedBits) { |
|
4923 |
/* |
|
4924 |
PRINTF(("freeing up temp bitmap bits ...\n")); |
|
4925 |
*/ |
|
4926 |
free(allocatedBits); |
|
4927 |
} |
|
4928 |
%} |
|
4929 |
. |
|
4930 |
^ false |
|
4931 |
! |
|
4932 |
||
2323 | 4933 |
xxdisplayLineFromX:x0 y:y0 toX:x1 y:y1 in:ignoredDrawableId with:aDC |
4934 |
"draw a line. If the coordinates are not integers, an error is triggered." |
|
4935 |
||
4936 |
|pen| |
|
4937 |
||
4938 |
pen := self getPenForMyContext. |
|
4939 |
||
4940 |
%{ /* NOCONTEXT */ |
|
4941 |
if (__isExternalAddressLike(aDC) |
|
4942 |
&& __bothSmallInteger(x0, y0) |
|
4943 |
&& __bothSmallInteger(x1, y1)) { |
|
2328 | 4944 |
HANDLE hDC = (HANDLE)(__externalAddressVal(aDC)); |
4945 |
COLORREF fgColor; |
|
4946 |
HANDLE prevPen, hPen; |
|
4947 |
int __x1 = __intVal(x1), __y1 = __intVal(y1); |
|
4948 |
/* Obtaining Pen */ |
|
4949 |
int style, styleInt, lineWidth; |
|
4950 |
||
4951 |
lineWidth= __INST(lineWidth); |
|
4952 |
||
4953 |
if (__INST(lineStyle) == @symbol(solid)) { |
|
4954 |
style= PS_SOLID; |
|
4955 |
} else if (__INST(lineStyle) == @symbol(dashed)) { |
|
4956 |
style= PS_DASH; |
|
4957 |
} else if (__INST(lineStyle) == @symbol(dotted)) { |
|
4958 |
style= PS_DOT; |
|
4959 |
} else if (__INST(lineStyle) == @symbol(dashDot)) { |
|
4960 |
style= PS_DASHDOT; |
|
4961 |
} else if (__INST(lineStyle) == @symbol(dashDotDot)) { |
|
4962 |
style= PS_DASHDOTDOT; |
|
4963 |
} else |
|
4964 |
style= PS_SOLID; |
|
4965 |
styleInt &= ~PS_STYLE_MASK; |
|
4966 |
styleInt |= style; |
|
4967 |
||
4968 |
||
4969 |
if (__INST(capStyle) == @symbol(round)) { |
|
4970 |
style= PS_ENDCAP_ROUND; |
|
4971 |
} else if (__INST(capStyle) == @symbol(square)) { |
|
4972 |
style= PS_ENDCAP_SQUARE; |
|
4973 |
} else if (__INST(capStyle) == @symbol(flat)) { |
|
4974 |
style= PS_ENDCAP_FLAT; |
|
4975 |
} else |
|
4976 |
style= PS_ENDCAP_FLAT; |
|
4977 |
styleInt &= ~PS_ENDCAP_MASK; |
|
4978 |
styleInt |= style; |
|
4979 |
||
4980 |
||
4981 |
if (__INST(joinStyle) == @symbol(bevel)) { |
|
4982 |
style= PS_JOIN_BEVEL; |
|
4983 |
} else if (__INST(joinStyle) == @symbol(miter)) { |
|
4984 |
style= PS_JOIN_MITER; |
|
4985 |
} else if (__INST(joinStyle) == @symbol(round)) { |
|
4986 |
style= PS_JOIN_ROUND; |
|
4987 |
} else |
|
4988 |
style= PS_JOIN_MITER; |
|
4989 |
styleInt &= ~PS_JOIN_MASK; |
|
4990 |
styleInt |= style; |
|
4991 |
||
4992 |
||
4993 |
fgColor = GetTextColor(hDC); |
|
4994 |
hPen = CreatePen((styleInt & PS_STYLE_MASK), lineWidth, fgColor); |
|
4995 |
||
4996 |
/* Finish Obtaining Pen */ |
|
2323 | 4997 |
|
4998 |
||
4999 |
/* DPRINTF(("displayLine: %d/%d -> %d/%d\n", |
|
2328 | 5000 |
__intVal(x0), __intVal(y0), |
5001 |
__x1, __y1)); |
|
2323 | 5002 |
*/ |
5003 |
||
2328 | 5004 |
prevPen = SelectObject(hDC, hPen); |
5005 |
||
5006 |
MoveToEx(hDC, __intVal(x0), __intVal(y0), NULL); |
|
5007 |
||
5008 |
LineTo(hDC, __x1, __y1); |
|
5009 |
||
5010 |
/* |
|
5011 |
* end-point ... |
|
5012 |
*/ |
|
5013 |
LineTo(hDC, __x1+1, __y1); |
|
5014 |
||
5015 |
SelectObject(hDC, prevPen); |
|
5016 |
||
5017 |
||
5018 |
RETURN ( self ); |
|
2323 | 5019 |
} |
5020 |
%} |
|
5021 |
! |
|
5022 |
||
5023 |
xxxdisplayLineFromX:x0 y:y0 toX:x1 y:y1 in:ignoredDrawableId with:aDC |
|
5024 |
"draw a line. If the coordinates are not integers, an error is triggered." |
|
5025 |
||
5026 |
|penHandle| |
|
5027 |
||
5028 |
penHandle := ExternalBytes address: self getPenForMyContext. |
|
5029 |
||
5030 |
%{ /* NOCONTEXT */ |
|
5031 |
if (__isExternalAddressLike(aDC) |
|
5032 |
&& __isExternalAddressLike(penHandle) |
|
5033 |
&& __bothSmallInteger(x0, y0) |
|
5034 |
&& __bothSmallInteger(x1, y1)) { |
|
2328 | 5035 |
HANDLE hDC = (HANDLE)(__externalAddressVal(aDC)); |
5036 |
HANDLE hPen = (HANDLE)(__externalAddressVal(penHandle)); |
|
5037 |
COLORREF fgColor; |
|
5038 |
HANDLE prevPen; |
|
5039 |
int __x1 = __intVal(x1), __y1 = __intVal(y1); |
|
2323 | 5040 |
|
5041 |
||
5042 |
/* DPRINTF(("displayLine: %d/%d -> %d/%d\n", |
|
2328 | 5043 |
__intVal(x0), __intVal(y0), |
5044 |
__x1, __y1)); |
|
2323 | 5045 |
*/ |
5046 |
||
5047 |
/* fgColor = GetTextColor(hDC); |
|
5048 |
* hPen = CreatePen(PS_SOLID, 1, fgColor); |
|
5049 |
*/ |
|
5050 |
||
2328 | 5051 |
prevPen = SelectObject(hDC, hPen); |
5052 |
||
5053 |
MoveToEx(hDC, __intVal(x0), __intVal(y0), NULL); |
|
5054 |
||
5055 |
LineTo(hDC, __x1, __y1); |
|
5056 |
||
5057 |
/* |
|
5058 |
* end-point ... |
|
5059 |
*/ |
|
5060 |
LineTo(hDC, __x1+1, __y1); |
|
5061 |
||
5062 |
SelectObject(hDC, prevPen); |
|
5063 |
||
5064 |
||
5065 |
RETURN ( self ); |
|
2323 | 5066 |
} |
5067 |
%} |
|
2299 | 5068 |
! ! |
5069 |
||
5070 |
!WinPrinterContext methodsFor:'printing process'! |
|
5071 |
||
5072 |
endPage |
|
5073 |
"Informs device that we are finished writing to a page." |
|
2317 | 5074 |
|
2299 | 5075 |
(OperatingSystem endPage:gcId) > 0 ifFalse:[ |
2328 | 5076 |
self error |
2299 | 5077 |
] |
5078 |
||
5079 |
"Created: / 27-07-2006 / 18:20:48 / fm" |
|
5080 |
"Modified: / 01-08-2006 / 16:01:34 / fm" |
|
5081 |
"Modified: / 10-10-2006 / 18:14:44 / cg" |
|
5082 |
! |
|
5083 |
||
2315 | 5084 |
endPrintJobWithoutRelease |
2299 | 5085 |
"End the print job. Everything drawn between startPrintJob |
5086 |
and endPrintJob will become one entry in the print queue." |
|
2317 | 5087 |
|
2299 | 5088 |
|result| |
5089 |
||
5090 |
self endPage. |
|
5091 |
result := OperatingSystem endDoc:gcId. |
|
5092 |
jobid := nil. |
|
5093 |
result >= 0 ifFalse:[ self error ] |
|
5094 |
||
5095 |
"Created: / 27-07-2006 / 18:21:04 / fm" |
|
5096 |
"Modified: / 01-08-2006 / 16:01:38 / fm" |
|
5097 |
"Modified: / 10-10-2006 / 18:50:43 / cg" |
|
5098 |
! |
|
5099 |
||
2330 | 5100 |
getSupportsColor |
5101 |
||
5102 |
| retVal info | |
|
5103 |
||
5104 |
info := (self class getPrinterInformationString: self name) asUppercase. |
|
5105 |
(info includesSubString: ',PSCRIPT,') |
|
5106 |
ifTrue: [ |
|
5107 |
retVal := (DAPASX::DapasSystemInfo getYesNoInfoApp: 'Printer' profile: 'PostScriptBlackWhite') not. |
|
5108 |
] |
|
5109 |
ifFalse: [ |
|
5110 |
retVal := (info includesSubString: 'PDF') |
|
5111 |
ifTrue: [true] |
|
5112 |
ifFalse: [self numberOfColorBitsPerPixel > 1]. |
|
5113 |
]. |
|
5114 |
||
5115 |
^retVal |
|
5116 |
! |
|
5117 |
||
2299 | 5118 |
startPage |
5119 |
"Starts a page." |
|
2317 | 5120 |
|
2299 | 5121 |
(OperatingSystem startPage:gcId) > 0 ifFalse:[ |
2328 | 5122 |
^ self error |
2299 | 5123 |
]. |
5124 |
||
5125 |
"Created: / 27-07-2006 / 18:25:55 / fm" |
|
5126 |
"Modified: / 28-07-2006 / 18:19:04 / fm" |
|
5127 |
"Modified: / 10-10-2006 / 18:19:02 / cg" |
|
5128 |
! |
|
5129 |
||
2317 | 5130 |
startPrintJob:aString fileName:aFileName |
2299 | 5131 |
"Start a print job, using aString as the job title; everything |
5132 |
drawn between startPrintJob and endPrintJob will become |
|
5133 |
one entry in the print queue." |
|
2317 | 5134 |
|
2299 | 5135 |
|docInfoStruct nameAddress title fileNameAddress| |
5136 |
||
5137 |
gcId isNil ifTrue:[ |
|
2328 | 5138 |
self buildPrinter |
2299 | 5139 |
]. |
5140 |
abort := false. |
|
5141 |
title := aString ? 'Smalltalk/X'. |
|
5142 |
nameAddress := title asExternalBytes unprotectFromGC. |
|
5143 |
aFileName isNil ifFalse:[ |
|
2328 | 5144 |
fileNameAddress := aFileName pathName asExternalBytes unprotectFromGC |
2299 | 5145 |
]. |
5146 |
docInfoStruct := Win32OperatingSystem::DocInfoStructure new. |
|
5147 |
docInfoStruct |
|
2328 | 5148 |
cbSize:docInfoStruct sizeInBytes; |
5149 |
lpszDocName:nameAddress address. |
|
2299 | 5150 |
fileNameAddress isNil ifFalse:[ |
2328 | 5151 |
docInfoStruct lpszOutput:fileNameAddress address |
2299 | 5152 |
]. |
5153 |
jobid := OperatingSystem startDoc:gcId docInfo:docInfoStruct. |
|
5154 |
jobid > 0 ifFalse:[ |
|
2328 | 5155 |
jobid = -1 ifTrue:[ |
5156 |
abort := true. |
|
5157 |
^ nil |
|
5158 |
]. |
|
5159 |
^ self error |
|
2299 | 5160 |
]. |
5161 |
self startPage |
|
5162 |
||
5163 |
"Created: / 27-07-2006 / 18:19:31 / fm" |
|
5164 |
"Modified: / 03-08-2006 / 15:11:19 / fm" |
|
5165 |
"Modified: / 10-10-2006 / 18:20:01 / cg" |
|
5166 |
! ! |
|
5167 |
||
5168 |
!WinPrinterContext methodsFor:'queries'! |
|
5169 |
||
2323 | 5170 |
hasGrayscales |
5171 |
"return true, if this workstation supports grayscales |
|
5172 |
(also true for color displays)" |
|
5173 |
||
5174 |
^ true |
|
5175 |
! |
|
5176 |
||
5177 |
isOpen |
|
5178 |
||
5179 |
^ gcId notNil |
|
5180 |
! |
|
5181 |
||
2324 | 5182 |
isPersistentInSnapshot |
5183 |
"return true, if resources on this device are to be made |
|
5184 |
persistent in a snapshot image." |
|
5185 |
||
5186 |
^ false |
|
5187 |
! |
|
5188 |
||
2299 | 5189 |
supportsColor |
5190 |
||
2330 | 5191 |
supportsColor isNil ifTrue:[supportsColor := self getSupportsColor]. |
5192 |
^supportsColor |
|
2299 | 5193 |
! |
5194 |
||
5195 |
supportsGraphics |
|
2301
135f21a3d127
refactorred OS-independent stuff
Claus Gittinger <cg@exept.de>
parents:
2299
diff
changeset
|
5196 |
^(OperatingSystem getDeviceCaps: gcId index: 2 "Technology") ~= 4 |
2299 | 5197 |
|
5198 |
"Created: / 03-08-2006 / 10:07:43 / fm" |
|
2301
135f21a3d127
refactorred OS-independent stuff
Claus Gittinger <cg@exept.de>
parents:
2299
diff
changeset
|
5199 |
"Modified: / 16-04-2007 / 12:44:03 / cg" |
2299 | 5200 |
! ! |
5201 |
||
2323 | 5202 |
!WinPrinterContext methodsFor:'registration'! |
5203 |
||
5204 |
registerFont:aFont |
|
5205 |
deviceFonts register:aFont. |
|
5206 |
! |
|
5207 |
||
5208 |
unregisterFont:aFont |
|
5209 |
deviceFonts unregister:aFont. |
|
5210 |
! ! |
|
5211 |
||
2299 | 5212 |
!WinPrinterContext class methodsFor:'documentation'! |
5213 |
||
5214 |
version |
|
2342 | 5215 |
^ '$Header: /cvs/stx/stx/libview2/WinPrinterContext.st,v 1.20 2007-10-23 05:08:45 ca Exp $' |
2299 | 5216 |
! ! |