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