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