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