1 #   include	"drawMetaConfig.h"
2 
3 #   include	<stddef.h>
4 #   include	<stdlib.h>
5 #   include	<string.h>
6 
7 #   include	"drawWinMetaImpl.h"
8 #   include	"drawMacPictImpl.h"
9 #   include	<utilMatchFont.h>
10 #   include	<sioEndian.h>
11 #   include	<uniLegacyEncoding.h>
12 #   include	<uniUtf8.h>
13 #   include	<psDocumentFontStyle.h>
14 #   include	<bmio.h>
15 
16 #   include	<math.h>
17 
18 #   include	<appDebugon.h>
19 
20 # if 0
21 #    define	PICTDEB(x)	(x)
22 #    define	TRANSLATE_NAMES	1
23 # else
24 #    define	PICTDEB(x)	/*nothing*/
25 #    define	TRANSLATE_NAMES	0
26 # endif
27 
28 # if TRANSLATE_NAMES
appMacPictCommentName(int n)29 static const char * appMacPictCommentName( int		n )
30     {
31     static char	scratch[22];
32 
33     switch( n )
34 	{
35 	case PICTCMT_Proprietary:	return "Proprietary";
36 	case PICTCMT_MacDrawBegin:	return "MacDrawBegin";
37 	case PICTCMT_MacDrawEnd:	return "MacDrawEnd";
38 	case PICTCMT_GroupedBegin:	return "GroupedBegin";
39 	case PICTCMT_GroupedEnd:	return "GroupedEnd";
40 	case PICTCMT_BitmapBegin:	return "BitmapBegin";
41 	case PICTCMT_BitmapEnd:		return "BitmapEnd";
42 	case PICTCMT_ArrowAtEnd:	return "ArrowAtEnd";
43 	case PICTCMT_ArrowAtStart:	return "ArrowAtStart";
44 	case PICTCMT_ArrowBothEnds:	return "ArrowBothEnds";
45 	case PICTCMT_ArrowEnd:		return "ArrowEnd";
46 	case PICTCMT_SetGray:		return "SetGray";
47 	case PICTCMT_TextBegin:		return "TextBegin";
48 	case PICTCMT_TextEnd:		return "TextEnd";
49 	case PICTCMT_StringBegin:	return "StringBegin";
50 	case PICTCMT_StringEnd:		return "StringEnd";
51 	case PICTCMT_TextCenter:	return "TextCenter";
52 	case PICTCMT_LineLayoutOff:	return "LineLayoutOff";
53 	case PICTCMT_LineLayoutOn:	return "LineLayoutOn";
54 	case PICTCMT_ClientLineLayout:	return "ClientLineLayout";
55 	case PICTCMT_PolyBegin:		return "PolyBegin";
56 	case PICTCMT_PolyEnd:		return "PolyEnd";
57 	case PICTCMT_PolyIgnore:	return "PolyIgnore";
58 	case PICTCMT_PolySmooth:	return "PolySmooth";
59 	case PICTCMT_PolyClose:		return "PolyClose";
60 	case PICTCMT_RotateBegin:	return "RotateBegin";
61 	case PICTCMT_RotateEnd:		return "RotateEnd";
62 	case PICTCMT_RotateCenter:	return "RotateCenter";
63 	case PICTCMT_DashedLine:	return "DashedLine";
64 	case PICTCMT_DashedStop:	return "DashedStop";
65 	case PICTCMT_SetLineWidth:	return "SetLineWidth";
66 	case PICTCMT_PostScriptBegin:	return "PostScriptBegin";
67 	case PICTCMT_PostScriptEnd:	return "PostScriptEnd";
68 	case PICTCMT_PostScriptHandle:	return "PostScriptHandle";
69 	case PICTCMT_PostScriptFile:	return "PostScriptFile";
70 	case PICTCMT_TextIsPostScript:	return "TextIsPostScript";
71 	case PICTCMT_ResourcePS:	return "ResourcePS";
72 	case PICTCMT_PSBeginNoSave:	return "PSBeginNoSave";
73 	case PICTCMT_FormsPrinting:	return "FormsPrinting";
74 	case PICTCMT_EndFormsPrinting:	return "EndFormsPrinting";
75 	case PICTCMT_CMBeginProfile:	return "CMBeginProfile";
76 	case PICTCMT_CMEndProfile:	return "CMEndProfile";
77 	case PICTCMT_CMEnableMatching:	return "CMEnableMatching";
78 	case PICTCMT_CMDisableMatching:	return "CMDisableMatching";
79 	}
80 
81     sprintf( scratch, "%d", n );
82     return scratch;
83     }
84 # endif
85 
86 /************************************************************************/
87 
appMacPictGetRect(DocumentRectangle * dr,SimpleInputStream * sis)88 static int appMacPictGetRect(		DocumentRectangle *	dr,
89 					SimpleInputStream *	sis )
90     {
91     int		done= 0;
92 
93     dr->drY0= sioEndianGetBeInt16( sis ); done += 2;
94     dr->drX0= sioEndianGetBeInt16( sis ); done += 2;
95     dr->drY1= sioEndianGetBeInt16( sis ); done += 2;
96     dr->drX1= sioEndianGetBeInt16( sis ); done += 2;
97 
98     return done;
99     }
100 
101 /************************************************************************/
102 
appMacPictGetOvSize(DeviceContext * dc,SimpleInputStream * sis)103 static int appMacPictGetOvSize(		DeviceContext *		dc,
104 					SimpleInputStream *	sis )
105     {
106     dc->dcMacPictRRectOvalHigh= sioEndianGetBeInt16( sis );
107     dc->dcMacPictRRectOvalWide= sioEndianGetBeInt16( sis );
108 
109     PICTDEB(appDebug( "OvSize( %d, %d )\n",
110 			    dc->dcMacPictRRectOvalWide,
111 			    dc->dcMacPictRRectOvalHigh ));
112 
113     return 0;
114     }
115 
appMacPictGetArc(DeviceContext * dc,SimpleInputStream * sis)116 static int appMacPictGetArc(		DeviceContext *		dc,
117 					SimpleInputStream *	sis )
118     {
119     double		as;
120     double		ae;
121     int			x;
122     int			y;
123     int			dx;
124     int			dy;
125 
126     appMacPictGetRect( &(dc->dcMacPictArcRect), sis );
127 
128     dc->dcMacPictArcA0= sioEndianGetBeInt16( sis );
129     dc->dcMacPictArcA1= sioEndianGetBeInt16( sis );
130 
131     as= 90.0- dc->dcMacPictArcA0;
132     ae= 90.0- ( dc->dcMacPictArcA0+ dc->dcMacPictArcA1 );
133 
134     as= ( M_PI* as )/ 180.0;
135     ae= ( M_PI* ae )/ 180.0;
136 
137     x= ( dc->dcMacPictArcRect.drX0+ dc->dcMacPictArcRect.drX1 )/ 2;
138     y= ( dc->dcMacPictArcRect.drY0+ dc->dcMacPictArcRect.drY1 )/ 2;
139     dx= dc->dcMacPictArcRect.drX1- dc->dcMacPictArcRect.drX0;
140     dy= dc->dcMacPictArcRect.drY1- dc->dcMacPictArcRect.drY0;
141 
142     dc->dcMacPictArcXs= x+ 0.5* dx* cos( as );
143     dc->dcMacPictArcYs= y+ 0.5* dy* sin( as );
144     dc->dcMacPictArcXe= x+ 0.5* dx* cos( ae );
145     dc->dcMacPictArcYe= y+ 0.5* dy* sin( ae );
146 
147     return 0;
148     }
149 
150 /************************************************************************/
151 /*									*/
152 /*  Retrieve a color.							*/
153 /*									*/
154 /************************************************************************/
155 
appMacPictGetColor(RGB8Color * rgb8,SimpleInputStream * sis)156 static int appMacPictGetColor(	RGB8Color *		rgb8,
157 				SimpleInputStream *	sis )
158     {
159     unsigned int	r= sioEndianGetBeUint16( sis );
160     unsigned int	g= sioEndianGetBeUint16( sis );
161     unsigned int	b= sioEndianGetBeUint16( sis );
162 
163     rgb8->rgb8Red= r/ 256;
164     rgb8->rgb8Green= g/ 256;
165     rgb8->rgb8Blue= b/ 256;
166 
167     return 0;
168     }
169 
170 /************************************************************************/
171 /*									*/
172 /*  Read a pattern.							*/
173 /*									*/
174 /************************************************************************/
175 
appMacPictGetPattern(DeviceContext * dc,SimpleInputStream * sis,RGB8Color * pSolidColor,int * pIsSolid,unsigned char pattern[8])176 static int appMacPictGetPattern(	DeviceContext *		dc,
177 					SimpleInputStream *	sis,
178 					RGB8Color *		pSolidColor,
179 					int *			pIsSolid,
180 					unsigned char		pattern[8] )
181     {
182     int		i;
183     int		isSolid;
184     /*
185     int		gray= 0xff;
186     */
187 
188     pattern[0]= sioInGetByte( sis );
189     isSolid= ( pattern[0] == 0x00 || pattern[0] == 0xff );
190 
191     /*
192     if  ( pattern[0] == 0xff )
193 	{ gray= 0x00;	}
194     */
195 
196     for ( i= 1; i < 8; i++ )
197 	{
198 	pattern[i]= sioInGetByte( sis );
199 
200 	if  ( pattern[i] != pattern[0] )
201 	    { isSolid= 0;	}
202 	}
203 
204     if  ( isSolid )
205 	{
206 	if  ( pattern[0] == 0xff )
207 	    { *pSolidColor= dc->dcMacPictForeColor;	}
208 	else{
209 	    if  ( pattern[0] == 0x00 )
210 		{ *pSolidColor= dc->dcMacPictBackColor;	}
211 	    else{ XDEB(pattern[0]);			}
212 	    }
213 	}
214 
215     *pIsSolid= isSolid;
216     return 0;
217     }
218 
appMacPictGetShortLine(int * pX0,int * pY0,int * pX1,int * pY1,DeviceContext * dc,SimpleInputStream * sis)219 static int appMacPictGetShortLine(	int *			pX0,
220 					int *			pY0,
221 					int *			pX1,
222 					int *			pY1,
223 					DeviceContext *		dc,
224 					SimpleInputStream *	sis )
225     {
226     int			y0= sioEndianGetBeInt16( sis );
227     int			x0= sioEndianGetBeInt16( sis );
228     int			y1;
229     int			x1;
230     int			c;
231 
232     c= sioInGetByte( sis );
233     if  ( c & 0x80 )
234 	{ x1= x0+ c- 256;	}
235     else{ x1= x0+ c;		}
236 
237     c= sioInGetByte( sis );
238     if  ( c & 0x80 )
239 	{ y1= y0+ c- 256;	}
240     else{ y1= y0+ c;		}
241 
242     PICTDEB(appDebug( "ShortLine( %d+ %d, %d+ %d )\n",
243 				    x0, x1- x0, y0, y1- y0 ));
244 
245     dc->dcX= x1;
246     dc->dcY= y1;
247 
248     *pX0= x0;
249     *pY0= y0;
250     *pX1= x1;
251     *pY1= y1;
252 
253     return 0;
254     }
255 
appMacPictGetShortLineFrom(int * pX0,int * pY0,int * pX1,int * pY1,DeviceContext * dc,SimpleInputStream * sis)256 static int appMacPictGetShortLineFrom(	int *			pX0,
257 					int *			pY0,
258 					int *			pX1,
259 					int *			pY1,
260 					DeviceContext *		dc,
261 					SimpleInputStream *	sis )
262     {
263     int			y0= dc->dcY;
264     int			x0= dc->dcX;
265     int			y1;
266     int			x1;
267     int			c;
268 
269     c= sioInGetByte( sis );
270     if  ( c & 0x80 )
271 	{ x1= x0+ c- 256;	}
272     else{ x1= x0+ c;		}
273 
274     c= sioInGetByte( sis );
275     if  ( c & 0x80 )
276 	{ y1= y0+ c- 256;	}
277     else{ y1= y0+ c;		}
278 
279     PICTDEB(appDebug( "ShortLineFrom( %d+ %d, %d+ %d )\n",
280 				    x0, x1- x0, y0, y1- y0 ));
281 
282     *pX0= x0;
283     *pY0= y0;
284     *pX1= x1;
285     *pY1= y1;
286 
287     return 0;
288     }
289 
appMacPictGetLineFrom(int * pX0,int * pY0,int * pX1,int * pY1,DeviceContext * dc,SimpleInputStream * sis)290 static int appMacPictGetLineFrom(	int *			pX0,
291 					int *			pY0,
292 					int *			pX1,
293 					int *			pY1,
294 					DeviceContext *		dc,
295 					SimpleInputStream *	sis )
296     {
297     int		y0= sioEndianGetBeInt16( sis );
298     int		x0= sioEndianGetBeInt16( sis );
299     int		y1= dc->dcY;
300     int		x1= dc->dcX;
301 
302     PICTDEB(appDebug( "LineFrom( %d, %d )\n", x0, y0 ));
303 
304     *pX0= x0;
305     *pY0= y0;
306     *pX1= x1;
307     *pY1= y1;
308 
309     return 0;
310     }
311 
appMacPictGetLine(int * pX0,int * pY0,int * pX1,int * pY1,DeviceContext * dc,SimpleInputStream * sis)312 static int appMacPictGetLine(	int *			pX0,
313 				int *			pY0,
314 				int *			pX1,
315 				int *			pY1,
316 				DeviceContext *		dc,
317 				SimpleInputStream *	sis )
318     {
319     int			y0= sioEndianGetBeInt16( sis );
320     int			x0= sioEndianGetBeInt16( sis );
321     int			y1= sioEndianGetBeInt16( sis );
322     int			x1= sioEndianGetBeInt16( sis );
323 
324     PICTDEB(appDebug( "Line( %d, %d, %d, %d )\n", x0, y0, x1, y1 ));
325 
326     dc->dcX= x1;
327     dc->dcY= y1;
328 
329     *pX0= x0;
330     *pY0= y0;
331     *pX1= x1;
332     *pY1= y1;
333 
334     return 0;
335     }
336 
337 /************************************************************************/
338 
appMacPictAddFont(DeviceContext * dc,const char * name)339 static int appMacPictAddFont(		DeviceContext *		dc,
340 					const char *		name )
341     {
342     int			rval= 0;
343 
344     int			fontNum;
345     int			fontStyle;
346 
347     DocumentFont	dfNew;
348 
349     docInitDocumentFont( &dfNew );
350 
351     if  ( docFontSetFamilyName( &dfNew, name ) )
352 	{ LDEB(1); rval= -1; goto ready;	}
353 
354     fontStyle= psFontFamilyStyle( name );
355     if  ( docFontSetFamilyStyle( &dfNew, fontStyle ) )
356 	{ SLDEB(name,fontStyle); rval= -1; goto ready; }
357 
358     fontNum= docMergeFontIntoFontlist( &(dc->dcFontList), &dfNew );
359     if  ( fontNum < 0 )
360 	{ SLDEB(name,fontNum); rval= -1; goto ready; }
361 
362     if  ( dc->dcFont.lfTextAttribute.taFontNumber != fontNum )
363 	{
364 	dc->dcFont.lfTextAttribute.taFontNumber= fontNum;
365 	dc->dcFont.lfPrivateFont= -1;
366 	dc->dcAfi= (AfmFontInfo *)0;
367 	}
368 
369   ready:
370     docCleanDocumentFont( &dfNew );
371 
372     return rval;
373     }
374 
appMacPictGetFontName(DeviceContext * dc,SimpleInputStream * sis)375 static int appMacPictGetFontName(	DeviceContext *		dc,
376 					SimpleInputStream *	sis )
377     {
378     int			rval= 0;
379 
380     int			dataLength= sioEndianGetBeInt16( sis );
381     int			oldFontId= sioEndianGetBeInt16( sis );
382     int			nameLength= sioInGetByte( sis );
383     int			nbytes= 5;
384 
385     int			i;
386     char *		to;
387     char *		fontName= (char *)0;
388 
389     oldFontId= oldFontId; /*  Avoid compiler warning */
390 
391     fontName= to= (char *)malloc( nameLength+ 1 );
392     if  ( ! fontName || ! to )
393 	{ LXDEB(nameLength,fontName); rval= -1; goto ready;	}
394 
395     for ( i= 0; i < nameLength; to++, i++ )
396 	{ *to= sioInGetByte( sis ); nbytes++; }
397     *to= '\0';
398 
399     PICTDEB(appDebug( "FontName( %d, %d, %d, \"%s\" )\n",
400 	    dataLength, oldFontId, nameLength, fontName ));
401 
402     if  ( dataLength > 3+ nameLength )
403 	{ LLDEB(dataLength,3+nameLength); }
404 
405     for ( i= 3+ nameLength; i < dataLength; i++ )
406 	{ (void) sioInGetByte( sis ); nbytes++;	}
407 
408     if  ( dc->dcMacPictVersion > 1 && nbytes % 2 )
409 	{ (void)sioInGetByte( sis ); nbytes++;	}
410 
411     if  ( appMacPictAddFont( dc, fontName ) )
412 	{ LDEB(1); rval= -1; goto ready;	}
413 
414   ready:
415 
416     if  ( fontName )
417 	{ free( fontName );	}
418 
419     return rval;
420     }
421 
appMacPictGetTxFont(DeviceContext * dc,SimpleInputStream * sis)422 static int appMacPictGetTxFont(		DeviceContext *		dc,
423 					SimpleInputStream *	sis )
424     {
425     int			rval= 0;
426 
427     int			val= sioEndianGetBeInt16( sis );
428     const char *	name= "?";
429 
430     switch( val )
431 	{
432 	case 0:		name= "Chicago";	break;
433 	case 1:		name= "Helvetica";	break;
434 	case 2:		name= "Times";		break;
435 	case 3:		name= "Helvetica";	break;
436 	case 4:		name= "Courier";	break;
437 	case 20:	name= "Times";		break;
438 	case 21:	name= "Helvetica";	break;
439 	case 22:	name= "Courier";	break;
440 	case 23:	name= "Symbol";		break;
441 	case 15011:	name= "Avantgarde";	break;
442 
443 	default:
444 	    PICTDEB(appDebug( "TxFont( %d )\n", val ));
445 	    goto ready;
446 	}
447 
448     PICTDEB(appDebug( "TxFont( %d -> \"%s\" )\n", val, name ));
449 
450     if  ( appMacPictAddFont( dc, name ) )
451 	{ LDEB(1); rval= -1; goto ready;	}
452 
453   ready:
454 
455     return rval;
456     }
457 
appMacPictGetTxFace(DeviceContext * dc,SimpleInputStream * sis)458 static int appMacPictGetTxFace(		DeviceContext *		dc,
459 					SimpleInputStream *	sis )
460     {
461     unsigned int	val= sioInGetByte( sis );
462 
463     int			isBold= 0;
464     int			isSlanted= 0;
465 
466     if  ( val & 1 )
467 	{ isBold= 1; val &= ~1;	}
468     if  ( val & 2 )
469 	{ isSlanted= 1; val &= ~2;	}
470 
471     if(val)XDEB(val);
472 
473     PICTDEB(appDebug( "TxFace( 0x%02x )%s%s\n", val,
474 					isBold?"":" BOLD",
475 					isSlanted?"":" SLANTED" ));
476 
477     if  ( dc->dcMacPictVersion > 1 )
478 	{ (void)sioInGetByte( sis );	}
479 
480     if  ( dc->dcFont.lfTextAttribute.taFontIsBold != isBold )
481 	{
482 	dc->dcFont.lfTextAttribute.taFontIsBold= isBold;
483 	dc->dcFont.lfPrivateFont= -1;
484 	dc->dcAfi= (AfmFontInfo *)0;
485 	}
486 
487     if  ( dc->dcFont.lfTextAttribute.taFontIsSlanted != isSlanted )
488 	{
489 	dc->dcFont.lfTextAttribute.taFontIsSlanted= isSlanted;
490 	dc->dcFont.lfPrivateFont= -1;
491 	dc->dcAfi= (AfmFontInfo *)0;
492 	}
493 
494     return 0;
495     }
496 
appMacPictGetGlyphState(DeviceContext * dc,SimpleInputStream * sis)497 static int appMacPictGetGlyphState(	DeviceContext *		dc,
498 					SimpleInputStream *	sis )
499     {
500     int	dataLength= sioEndianGetBeInt16( sis );
501     int	i;
502 
503 #   if 0
504     int	outlinePreferred= 0;
505     int	preserveGlyph= 0;
506     int	fractionalWidth= 0;
507     int	scalingDisabled= 0;
508 #   endif
509 
510     for ( i= 0; i < dataLength; i++ )
511 	{
512 	(void) /* int c= */ sioInGetByte( sis );
513 
514 #	if 0
515 	if  ( i == 0 )
516 	    { outlinePreferred= c;	}
517 	if  ( i == 1 )
518 	    { preserveGlyph= c;	}
519 	if  ( i == 2 )
520 	    { fractionalWidth= c;	}
521 	if  ( i == 3 )
522 	    { scalingDisabled= c;	}
523 #	endif
524 	}
525 
526     PICTDEB(appDebug( "GlyphState( %d:%x,%x,%x,%x )\n",
527 				dataLength,
528 				outlinePreferred,
529 				preserveGlyph,
530 				fractionalWidth,
531 				scalingDisabled ));
532 
533     dc->dcX= 0;
534     dc->dcY= 0;
535 
536     return 0;
537     }
538 
539 /************************************************************************/
540 /*									*/
541 /*  Retrieve a text string.						*/
542 /*									*/
543 /************************************************************************/
544 
appMacPictGetString(DeviceContext * dc,SimpleInputStream * sis)545 static int appMacPictGetString(		DeviceContext *		dc,
546 					SimpleInputStream *	sis )
547     {
548     int			done;
549     int			count= sioInGetByte( sis );
550 
551     int			nbytes= 1;
552 
553     utilEmptyMemoryBuffer( &(dc->dcCollectedText) );
554 
555     for ( done= 0; done < count; nbytes++, done++ )
556 	{
557 	int		step;
558 	char		scratch[6+1];
559 	int		c= sioInGetByte( sis );
560 	int		unicode;
561 
562 	if  ( c == 0 )
563 	    { break;		}
564 
565 	if  ( c == '\r' )
566 	    { unicode= '\n';				}
567 	else{ unicode= uniMacRomanGlyphUnicodes[c];	}
568 
569 	if  ( unicode < 0 || unicode == 0xffff )
570 	    { LLDEB(c,unicode); unicode= '?';	}
571 
572 	step= uniPutUtf8( scratch, unicode );
573 	if  ( step < 1 || step > 3 )
574 	    { XLDEB(unicode,step); break;	}
575 
576 	if  ( utilMemoryBufferAppendBytes( &(dc->dcCollectedText),
577 				    (const unsigned char *)scratch, step ) )
578 	    { LDEB(step); return -1;	}
579 	}
580 
581     while( done < count )
582 	{
583 	if  ( sioInGetByte( sis ) < 0 )
584 	    { LDEB(1); return -1;	}
585 
586 	nbytes++; done++;
587 	}
588 
589     return nbytes;
590     }
591 
appMacPictGetDHText(DeviceContext * dc,int * pDh,SimpleInputStream * sis)592 static int appMacPictGetDHText(	DeviceContext *		dc,
593 				int *			pDh,
594 				SimpleInputStream *	sis )
595     {
596     int		dh= sioInGetByte( sis );
597     int		nbytes= 1;
598     int		step;
599 
600     step= appMacPictGetString( dc, sis );
601     if  ( step < 0 )
602 	{ LDEB(step); return -1;	}
603     nbytes += step;
604 
605     if  ( dc->dcMacPictVersion > 1 && nbytes % 2 )
606 	{ (void)sioInGetByte( sis ); nbytes++;	}
607 
608     PICTDEB(appDebug( "DHText( %d, %d: \"%.*s\" )\n", dh,
609 				dc->dcCollectedText.mbSize,
610 				dc->dcCollectedText.mbSize,
611 				(char *)dc->dcCollectedText.mbBytes ));
612 
613     *pDh= dh;
614 
615     return 0;
616     }
617 
appMacPictGetDVText(DeviceContext * dc,int * pDv,SimpleInputStream * sis)618 static int appMacPictGetDVText(	DeviceContext *		dc,
619 				int *			pDv,
620 				SimpleInputStream *	sis )
621     {
622     int		dv= sioInGetByte( sis );
623     int		nbytes= 1;
624     int		step;
625 
626     step= appMacPictGetString( dc, sis );
627     if  ( step < 0 )
628 	{ LDEB(step); return -1;	}
629     nbytes += step;
630 
631     if  ( dc->dcMacPictVersion > 1 && nbytes % 2 )
632 	{ (void)sioInGetByte( sis ); nbytes++;	}
633 
634     PICTDEB(appDebug( "DVText( %d, %d: \"%.*s\" )\n", dv,
635 				dc->dcCollectedText.mbSize,
636 				dc->dcCollectedText.mbSize,
637 				(char *)dc->dcCollectedText.mbBytes ));
638 
639     *pDv= dv;
640 
641     return 0;
642     }
643 
appMacPictGetDHDVText(DeviceContext * dc,int * pDh,int * pDv,SimpleInputStream * sis)644 static int appMacPictGetDHDVText(	DeviceContext *		dc,
645 					int *			pDh,
646 					int *			pDv,
647 					SimpleInputStream *	sis )
648     {
649     int		dh= sioInGetByte( sis );
650     int		dv= sioInGetByte( sis );
651     int		nbytes= 2;
652     int		step;
653 
654     step= appMacPictGetString( dc, sis );
655     if  ( step < 0 )
656 	{ LDEB(step); return -1;	}
657     nbytes += step;
658 
659     if  ( dc->dcMacPictVersion > 1 && nbytes % 2 )
660 	{ (void)sioInGetByte( sis ); nbytes++;	}
661 
662     PICTDEB(appDebug( "DHDVText( %d, %d, %d: \"%.*s\" )\n", dh, dv,
663 				dc->dcCollectedText.mbSize,
664 				dc->dcCollectedText.mbSize,
665 				(char *)dc->dcCollectedText.mbBytes ));
666 
667     *pDh= dh;
668     *pDv= dv;
669 
670     return 0;
671     }
672 
appMacPictGetLongText(DeviceContext * dc,SimpleInputStream * sis)673 static int appMacPictGetLongText(	DeviceContext *		dc,
674 					SimpleInputStream *	sis )
675     {
676     int		y= sioEndianGetBeInt16( sis );
677     int		x= sioEndianGetBeInt16( sis );
678     int		nbytes= 4;
679     int		step;
680 
681     step= appMacPictGetString( dc, sis );
682     if  ( step < 0 )
683 	{ LDEB(step); return -1;	}
684     nbytes += step;
685 
686     if  ( dc->dcMacPictVersion > 1 && nbytes % 2 )
687 	{ (void)sioInGetByte( sis ); nbytes++;	}
688 
689     PICTDEB(appDebug( "LongText( %d, %d, %d: \"%.*s\" )\n", x, y,
690 				dc->dcCollectedText.mbSize,
691 				dc->dcCollectedText.mbSize,
692 				(char *)dc->dcCollectedText.mbBytes ));
693 
694     dc->dcX= x;
695     dc->dcY= y;
696 
697     return 0;
698     }
699 
700 /************************************************************************/
701 /*									*/
702 /*  Retrieve the points of a polyline/polygon.				*/
703 /*									*/
704 /************************************************************************/
705 
appMacPictGetPoly(DeviceContext * dc,SimpleInputStream * sis)706 static int appMacPictGetPoly(		DeviceContext *		dc,
707 					SimpleInputStream *	sis )
708     {
709     int			count;
710     int			done= 0;
711     int			step;
712     int			bytes;
713 
714     Point2DI *		xp;
715     int			i;
716 
717     bytes= sioEndianGetBeInt16( sis ); done += 2;
718 
719     step= appMacPictGetRect( &(dc->dcMacPictPolyRect), sis );
720     if  ( step < 0 )
721 	{ LDEB(step); return -1;	}
722     done += step;
723 
724     {
725     int		left= bytes- done;
726 
727     if  ( left % 4 || left <= 4 )
728 	{ LDEB(left); return -1;	}
729 
730     count= left/ 4;
731     }
732 
733     xp= (Point2DI *)realloc( dc->dcPoints, (count+ 1)* sizeof(Point2DI) );
734     if  ( ! xp )
735 	{ LXDEB(count,xp); return -1;	}
736 
737     dc->dcPoints= xp;
738     dc->dcPointCount= count;
739 
740     for ( i= 0; i < count; xp++, i++ )
741 	{
742 	int	x, y;
743 
744 	y= sioEndianGetBeInt16( sis ); done += 2;
745 	x= sioEndianGetBeInt16( sis ); done += 2;
746 
747 	xp->x= DC_xViewport( x, y, dc );
748 	xp->y= DC_yViewport( x, y, dc );
749 	}
750 
751     *xp= dc->dcPoints[0];
752 
753     return done;
754     }
755 
appMacPictGetLongComment(DeviceContext * dc,SimpleInputStream * sis)756 static int appMacPictGetLongComment(	DeviceContext *		dc,
757 					SimpleInputStream *	sis )
758     {
759     int		i;
760 
761     int		kind= sioEndianGetBeInt16( sis );
762     int		size= sioEndianGetBeInt16( sis );
763 
764     kind= kind;
765 
766     PICTDEB(appDebug( "LongComment( %d:%s, %d, .. )\n",
767 	    kind, appMacPictCommentName( kind ), size ));
768 
769     switch( kind )
770 	{
771 	case PICTCMT_TextBegin:
772 	    {
773 	    if  ( size != 12 )
774 		{ goto defaultCase;	}
775 
776 	    (void) /* justify= */ sioEndianGetBeInt16( sis );
777 	    (void) /* flip= */ sioEndianGetBeInt16( sis );
778 	    (void) /* angle= */ sioEndianGetBeInt16( sis );
779 	    (void) /* line= */ sioEndianGetBeInt16( sis );
780 	    (void) /* cmnt= */ sioEndianGetBeInt16( sis );
781 	    (void) /* angleFixed= */ sioEndianGetBeInt16( sis );
782 
783 	    PICTDEB(appDebug(
784 		"%s: justify=%d, flip=%d, angle=%d, angleFixed=%d\n",
785 		    appMacPictCommentName( kind ),
786 		    justify, flip, angle, angleFixed ));
787 	    }
788 	    break;
789 
790 	case  PICTCMT_DashedLine:
791 	    dc->dcObjects[MACPICThandleFRAME_PEN].mfoLogicalPen.lpStyle= PS_DASH;
792 	    for ( i= 0; i < size; i++ )
793 		{ (void) /* c= */ sioInGetByte( sis ); PICTDEB(LDEB(c)); }
794 	    break;
795 
796 	case  PICTCMT_DashedStop:
797 	    if  ( size != 0 )
798 		{ LDEB(size); goto defaultCase;	}
799 	    dc->dcObjects[MACPICThandleFRAME_PEN].mfoLogicalPen.lpStyle= PS_SOLID;
800 	    break;
801 
802 	case  PICTCMT_SetLineWidth:
803 	    if  ( size != 4 )
804 		{ LDEB(size); goto defaultCase;	}
805 	    {
806 	    (void) /* int x= */ sioEndianGetBeInt16( sis );
807 	    (void) /* int y= */ sioEndianGetBeInt16( sis );
808 	    PICTDEB(appDebug( "LongComment( %d:%s, %d bytes, %d/%d )\n",
809 		    kind, appMacPictCommentName( kind ), size, x, y ));
810 	    }
811 	    break;
812 
813 	default:
814 	defaultCase:
815 	    for ( i= 0; i < size; i++ )
816 		{ (void) /* c= */ sioInGetByte( sis );	}
817 	    break;
818 	}
819 
820     if  ( dc->dcMacPictVersion > 1 && size % 2 )
821 	{ (void)sioInGetByte( sis );	}
822 
823     return 0;
824     }
825 
826 /************************************************************************/
827 
appMacPictGetTxSize(DeviceContext * dc,SimpleInputStream * sis)828 static int appMacPictGetTxSize(		DeviceContext *		dc,
829 					SimpleInputStream *	sis )
830     {
831     int		size= sioEndianGetBeInt16( sis );
832 
833     PICTDEB(appDebug( "TxSize( %d -> %d )\n", dc->dcFont.lfHeight, size ));
834 
835     if  ( dc->dcFont.lfHeight != size )
836 	{
837 	dc->dcFont.lfPrivateFont= -1;
838 	dc->dcAfi= (AfmFontInfo *)0;
839 	dc->dcFont.lfHeight= size;
840 	dc->dcFont.lfWidth= ( 65* size )/ 100;
841 	}
842 
843     return 0;
844     }
845 
846 /************************************************************************/
847 /*									*/
848 /*  Draw a string.							*/
849 /*									*/
850 /************************************************************************/
851 
appMacPictDrawString(DeviceContext * dc,int dh,int dv,void * through)852 static int appMacPictDrawString(	DeviceContext *		dc,
853 					int			dh,
854 					int			dv,
855 					void *			through )
856     {
857     const char *	s= (const char *)dc->dcCollectedText.mbBytes;
858     int			count= dc->dcCollectedText.mbSize;
859 
860     int			x0;
861     int			y0;
862 
863     while( count > 0 && isspace( s[count-1] ) )
864 	{ count--;	}
865 
866     if  ( count == 0 )
867 	{ return 0;	}
868 
869     dc->dcX += dh;
870     dc->dcY += dv;
871 
872     x0= DC_xViewport( dc->dcX, dc->dcY, dc );
873     y0= DC_yViewport( dc->dcX, dc->dcY, dc );
874 
875     if  ( ! dc->dcAfi )
876 	{
877 	if  ( (*dc->dcSelectFontObject)( dc, through, &(dc->dcFont) ) )
878 	    { LDEB(1); return -1;	}
879 	}
880 
881     if  ( (*dc->dcDrawString)( dc, through, x0, y0, &(dc->dcCollectedText) ) )
882 	{ LDEB(count); return -1;	}
883 
884     return 0;
885     }
886 
887 /************************************************************************/
888 /*									*/
889 /*  MACPICT_PackBitsRect and similar images.				*/
890 /*									*/
891 /*  1)  Initialise bitmap.						*/
892 /*  2)  Get image.							*/
893 /*  12) Draw image.							*/
894 /*  13) Ready: clean image related data.				*/
895 /*									*/
896 /************************************************************************/
897 
appMacPictDrawImage(DeviceContext * dc,void * through,SimpleInputStream * sis,int packed,int direct,int clipRegion)898 static int appMacPictDrawImage(		DeviceContext *		dc,
899 					void *			through,
900 					SimpleInputStream *	sis,
901 					int			packed,
902 					int			direct,
903 					int			clipRegion )
904     {
905     int			rval= 0;
906     int			step;
907 
908     DocumentRectangle	drSrc;
909     DocumentRectangle	drDest;
910 
911     RasterImage	abi;
912     DocumentRectangle	drOutput;
913 
914     /*  1  */
915     bmInitRasterImage( &abi );
916 
917     /*  2  */
918     step= bmMacPictGetImage( &abi, &drSrc, &drDest,
919 					    sis, packed, direct, clipRegion );
920     if  ( step < 0 )
921 	{ LDEB(step); rval= -1; goto ready;	}
922 
923     /*  11  */
924     if  ( dc->dcMacPictVersion > 1 && step % 2 )
925 	{ (void)sioInGetByte( sis ); step++;	}
926 
927 
928     appWinMetaTransformRectangle( &drDest, dc, &drDest );
929 
930     if  ( ! geoIntersectRectangle( &drOutput, &drDest, &(dc->dcOutputRect) ) )
931 	{
932 	RECTDEB(&drDest);
933 	RECTDEB(&(dc->dcOutputRect));
934 	return 0;
935 	}
936 
937     /*  12  */
938     if  ( (*dc->dcDrawRasterImage)( dc, through, &abi, &drSrc, &drDest ) )
939 	{ LDEB(1); return -1;	}
940 
941   ready:
942 
943     /*  13  */
944     bmCleanRasterImage( &abi );
945 
946     return rval;
947     }
948 
appMacPictDrawLine(DeviceContext * dc,void * through,int x0,int y0,int x1,int y1)949 static int appMacPictDrawLine(	DeviceContext *		dc,
950 				void *			through,
951 				int			x0,
952 				int			y0,
953 				int			x1,
954 				int			y1 )
955     {
956     int		count= 2;
957     Point2DI	points[2];
958 
959     points[0].x= DC_xViewport( x0, y0, dc );
960     points[0].y= DC_yViewport( x0, y0, dc );
961     points[1].x= DC_xViewport( x1, y1, dc );
962     points[1].y= DC_yViewport( x1, y1, dc );
963 
964     if  ( (*dc->dcDrawPolyPolygon)( dc, through,
965 				    1, &count, points, 0, 1, 0 ) )
966 	{ LDEB(count); return -1;	}
967 
968     return 0;
969     }
970 
971 /************************************************************************/
972 
appMacPictSetPatternBrush(DeviceContext * dc,PatternBrush * pb,const unsigned char * pattern)973 static int appMacPictSetPatternBrush(	DeviceContext *		dc,
974 					PatternBrush *		pb,
975 					const unsigned char *	pattern )
976     {
977     int			foreBlack;
978     int			foreWhite;
979     int			backBlack;
980     int			backWhite;
981 
982     foreBlack=	dc->dcMacPictForeColor.rgb8Red == 0 &&
983 		dc->dcMacPictForeColor.rgb8Green == 0 &&
984 		dc->dcMacPictForeColor.rgb8Blue == 0;
985     foreWhite=	dc->dcMacPictForeColor.rgb8Red == 255 &&
986 		dc->dcMacPictForeColor.rgb8Green == 255 &&
987 		dc->dcMacPictForeColor.rgb8Blue == 255;
988     backBlack=	dc->dcMacPictBackColor.rgb8Red == 0 &&
989 		dc->dcMacPictBackColor.rgb8Green == 0 &&
990 		dc->dcMacPictBackColor.rgb8Blue == 0;
991     backWhite=	dc->dcMacPictBackColor.rgb8Red == 255 &&
992 		dc->dcMacPictBackColor.rgb8Green == 255 &&
993 		dc->dcMacPictBackColor.rgb8Blue == 255;
994 
995     pb->pbAbi= (RasterImage *)malloc( sizeof(RasterImage) );
996     if  ( ! pb->pbAbi )
997 	{ XDEB(pb->pbAbi); return -1;	}
998     bmInitRasterImage( pb->pbAbi );
999     pb->pbAbi->riBytes= (unsigned char *)malloc( 8 );
1000     if  ( ! pb->pbAbi->riBytes )
1001 	{ XDEB(pb->pbAbi->riBytes); return -1;	}
1002     memcpy( pb->pbAbi->riBytes, pattern, 8 );
1003 
1004     pb->pbAbi->riDescription.bdPixelsWide= 8;
1005     pb->pbAbi->riDescription.bdPixelsHigh= 8;
1006     pb->pbAbi->riDescription.bdBitsPerSample= 1;
1007     pb->pbAbi->riDescription.bdXResolution= 1;
1008     pb->pbAbi->riDescription.bdYResolution= 1;
1009     pb->pbAbi->riDescription.bdUnit= BMunPIXEL;
1010 
1011     if  ( foreBlack && backWhite )
1012 	{
1013 	pb->pbAbi->riDescription.bdSamplesPerPixel= 1;
1014 	pb->pbAbi->riDescription.bdColorEncoding= BMcoBLACKWHITE;
1015 	}
1016     else{
1017 	if  ( foreWhite && backBlack )
1018 	    {
1019 	    pb->pbAbi->riDescription.bdSamplesPerPixel= 1;
1020 	    pb->pbAbi->riDescription.bdColorEncoding= BMcoWHITEBLACK;
1021 	    }
1022 	else{
1023 	    ColorPalette *	cp= &(pb->pbAbi->riDescription.bdPalette);
1024 
1025 	    pb->pbAbi->riDescription.bdSamplesPerPixel= 3;
1026 	    pb->pbAbi->riDescription.bdColorEncoding= BMcoRGB8PALETTE;
1027 
1028 	    if  ( utilPaletteSetCount( cp, 2 ) )
1029 		{ LDEB(2); return -1;	}
1030 
1031 	    cp->cpColors[0]= dc->dcMacPictBackColor;
1032 	    cp->cpColors[1]= dc->dcMacPictForeColor;
1033 	    }
1034 	}
1035 
1036     bmCalculateSizes( &(pb->pbAbi->riDescription) );
1037     pb->pbType= 5;
1038     pb->pbUsage= 0;
1039     return 0;
1040     }
1041 
appMacPictSetPattern(DeviceContext * dc,void * through,int brushHandle,int penHandle,int solid,const RGB8Color * solidColor,const unsigned char * pattern)1042 static int appMacPictSetPattern(	DeviceContext *		dc,
1043 					void *			through,
1044 					int			brushHandle,
1045 					int			penHandle,
1046 					int			solid,
1047 					const RGB8Color *	solidColor,
1048 					const unsigned char *	pattern )
1049     {
1050     MetaFileObject *	mfo;
1051 
1052     if  ( solid )
1053 	{
1054 	if  ( brushHandle != MACPICThandle_NONE )
1055 	    {
1056 	    mfo= &(dc->dcObjects[brushHandle]);
1057 	    (*dc->dcCleanObject)( dc, through,  mfo );
1058 	    appMetaCleanObject( mfo );
1059 
1060 	    mfo->mfoType= MFtypeBRUSH;
1061 	    mfo->mfoLogicalBrush.lbStyle= BS_SOLID;
1062 	    mfo->mfoLogicalBrush.lbColor= *solidColor;
1063 	    mfo->mfoLogicalBrush.lbTilePixmap= (struct DrawingSurface *)0;
1064 	    mfo->mfoLogicalBrush.lbTileNumber= -1;
1065 	    }
1066 
1067 	if  ( penHandle != MACPICThandle_NONE )
1068 	    {
1069 	    mfo= &(dc->dcObjects[penHandle]);
1070 	    (*dc->dcCleanObject)( dc, through,  mfo );
1071 	    appMetaCleanObject( mfo );
1072 
1073 	    mfo->mfoType= MFtypePEN;
1074 	    mfo->mfoLogicalPen.lpStyle= PS_SOLID;
1075 	    mfo->mfoLogicalPen.lpColor= *solidColor;
1076 	    }
1077 	}
1078     else{
1079 	if  ( brushHandle != MACPICThandle_NONE )
1080 	    {
1081 	    mfo= &(dc->dcObjects[brushHandle]);
1082 	    (*dc->dcCleanObject)( dc, through,  mfo );
1083 	    appMetaCleanObject( mfo );
1084 
1085 	    mfo->mfoType= MFtypePATTERNBRUSH;
1086 	    mfo->mfoPatternBrush.pbTilePixmap= (struct DrawingSurface *)0;
1087 	    mfo->mfoPatternBrush.pbTileNumber= -1;
1088 	    if  ( appMacPictSetPatternBrush( dc, &(mfo->mfoPatternBrush),
1089 						dc->dcMacPictPenPattern ) )
1090 		{
1091 		appMetaCleanObject( mfo );
1092 		mfo->mfoType= MFtypeFREE;
1093 		return -1;
1094 		}
1095 	    }
1096 	}
1097 
1098     return 0;
1099     }
1100 
1101 /************************************************************************/
1102 
appMacPictRefreshDrawingGear(DeviceContext * dc,void * through)1103 static int appMacPictRefreshDrawingGear(	DeviceContext *	dc,
1104 						void *		through )
1105     {
1106     if  ( appMacPictSetPattern( dc, through,
1107 				    MACPICThandlePAINT_BRUSH,
1108 				    MACPICThandleFRAME_PEN,
1109 				    dc->dcMacPictPenIsSolid,
1110 				    &(dc->dcMacPictPenSolid),
1111 				    dc->dcMacPictPenPattern ) )
1112 	{ LDEB(1); return -1;	}
1113 
1114     if  ( appMacPictSetPattern( dc, through,
1115 				    MACPICThandleFILL_BRUSH,
1116 				    MACPICThandle_NONE,
1117 				    dc->dcMacPictFillIsSolid,
1118 				    &(dc->dcMacPictFillSolid),
1119 				    dc->dcMacPictFillPattern ) )
1120 	{ LDEB(1); return -1;	}
1121 
1122     if  ( appMacPictSetPattern( dc, through,
1123 				    MACPICThandleERASE_BRUSH,
1124 				    MACPICThandle_NONE,
1125 				    dc->dcMacPictBackIsSolid,
1126 				    &(dc->dcMacPictBackSolid),
1127 				    dc->dcMacPictBackPattern ) )
1128 	{ LDEB(1); return -1;	}
1129 
1130     return 0;
1131     }
1132 
1133 
appMacPictChooseGear(DeviceContext * dc,void * through,int brushHandle,int penHandle)1134 static int appMacPictChooseGear(	DeviceContext *	dc,
1135 					void *		through,
1136 					int		brushHandle,
1137 					int		penHandle )
1138     {
1139     if  ( brushHandle != MACPICThandle_NONE )
1140 	{
1141 	if  ( appWinMetaSelectObject( dc, through, brushHandle ) )
1142 	    { LDEB(brushHandle); return -1;	}
1143 	}
1144     if  ( penHandle != MACPICThandle_NONE )
1145 	{
1146 	if  ( appWinMetaSelectObject( dc, through, penHandle ) )
1147 	    { LDEB(brushHandle); return -1;	}
1148 	}
1149 
1150     return 0;
1151     }
1152 
1153 /************************************************************************/
1154 /*									*/
1155 /*  Play a macintosh pict file.						*/
1156 /*									*/
1157 /************************************************************************/
1158 
appMacPictPlayPict(DeviceContext * dc,void * through)1159 int appMacPictPlayPict( DeviceContext *			dc,
1160 			void *				through )
1161     {
1162     SimpleInputStream *	sis= dc->dcPlayer->mpInputStream;
1163 
1164     int			rval= 0;
1165 
1166     dc->dcMacPictRRectOvalWide= 20;
1167     dc->dcMacPictRRectOvalHigh= 20;
1168 
1169     dc->dcFont.lfPrivateFont= -1;
1170     dc->dcFont.lfHeight= 12;
1171     dc->dcTextAlignment= TA_LEFT|TA_BASELINE;
1172 
1173     if  ( appMacPictRefreshDrawingGear( dc, through ) )
1174 	{ LDEB(1); return -1;	}
1175 
1176     dc->dcObjects[MACPICThandleFRAME_PEN].mfoLogicalPen.lpWidth= 1;
1177     dc->dcObjects[MACPICThandleDUMMY_PEN].mfoLogicalPen.lpWidth= 0;
1178 
1179     {
1180     MetaFileObject *	mfo= &(dc->dcObjects[MACPICThandleDUMMY_BRUSH]);
1181 
1182     mfo->mfoType= MFtypeBRUSH;
1183     mfo->mfoLogicalBrush.lbStyle= BS_NULL;
1184     mfo->mfoLogicalBrush.lbTilePixmap= (struct DrawingSurface *)0;
1185     mfo->mfoLogicalBrush.lbTileNumber= -1;
1186     }
1187 
1188     {
1189     MetaFileObject *	mfo= &(dc->dcObjects[MACPICThandleDUMMY_PEN]);
1190 
1191     mfo->mfoType= MFtypePEN;
1192     mfo->mfoLogicalPen.lpStyle= PS_NULL;
1193     }
1194 
1195     for (;;)
1196 	{
1197 	unsigned int	opcode;
1198 	int		bytes;
1199 
1200 	switch( dc->dcMacPictVersion )
1201 	    {
1202 	    case 1:
1203 		opcode= sioInGetByte( sis );
1204 		break;
1205 	    case 2:
1206 		opcode= sioEndianGetBeUint16( sis );
1207 		break;
1208 	    default:
1209 		LDEB(dc->dcMacPictVersion); return -1;
1210 	    }
1211 
1212 	if  ( opcode == EOF )
1213 	    { LDEB(opcode); return -1;	}
1214 
1215 	bytes= -1;
1216 	if  ( opcode >= 0x100 && opcode <= 0x7fff )
1217 	    {
1218 	    bytes= 2* ( ( opcode >> 8 ) & 0xff );
1219 	    opcode= opcode & 0xff;
1220 	    }
1221 
1222 	switch( opcode )
1223 	    {
1224 	    case MACPICT_NOP:
1225 		PICTDEB(appDebug( "NOP() bytes= %d\n", bytes ));
1226 		continue;
1227 
1228 	    case MACPICT_PnSize:
1229 		{
1230 		int w, h;
1231 
1232 		h= sioEndianGetBeInt16( sis );
1233 		w= sioEndianGetBeInt16( sis );
1234 		PICTDEB(appDebug( "PnSize( %d, %d )\n", w, h ));
1235 
1236 		dc->dcObjects[MACPICThandleFRAME_PEN].mfoLogicalPen.lpWidth=
1237 								( w+ h )/ 2;
1238 		}
1239 		continue;
1240 
1241 	    case MACPICT_OvSize:
1242 		if  ( appMacPictGetOvSize( dc, sis ) )
1243 		    { LDEB(1); rval= -1; goto ready;	}
1244 		continue;
1245 
1246 	    case MACPICT_DefHilite:
1247 		PICTDEB(appDebug( "DefHilite()\n" ));
1248 		continue;
1249 
1250 	    case MACPICT_Clip:
1251 		{
1252 		int	regionBytes= sioEndianGetBeInt16( sis );
1253 		int	skip;
1254 
1255 		PICTDEB(appDebug( "Clip( %d )\n", regionBytes/ 2 ));
1256 
1257 		for ( skip= 2; skip < regionBytes; skip += 2 )
1258 		    {
1259 		    (void) /* regionCoord= */ sioEndianGetBeInt16( sis );
1260 		    }
1261 		}
1262 		continue;
1263 
1264 	    case MACPICT_PnMode:
1265 		dc->dcMacPictPenMode= sioEndianGetBeInt16( sis );
1266 
1267 		PICTDEB(appDebug( "PnMode(%d)\n", dc->dcMacPictPenMode ));
1268 
1269 		continue;
1270 
1271 	    case MACPICT_PnLocHFrac:
1272 		{
1273 		(void) /* val= */ sioEndianGetBeInt16( sis );
1274 
1275 		PICTDEB(appDebug( "PnLocHFrac(%d)\n", val ));
1276 
1277 		}
1278 		continue;
1279 
1280 	    case MACPICT_RGBFgCol:
1281 		if  ( appMacPictGetColor( &(dc->dcMacPictForeColor), sis ) )
1282 		    { LDEB(1); rval= -1; goto ready;	}
1283 
1284 		PICTDEB(appDebug( "RGBFgCol(%d,%d,%d)\n",
1285 					dc->dcMacPictForeColor.rgb8Red,
1286 					dc->dcMacPictForeColor.rgb8Green,
1287 					dc->dcMacPictForeColor.rgb8Blue ));
1288 
1289 		if  ( appMacPictRefreshDrawingGear( dc, through ) )
1290 		    { LDEB(1); return -1;	}
1291 
1292 		continue;
1293 
1294 	    case MACPICT_RGBBkCol:
1295 		if  ( appMacPictGetColor( &(dc->dcMacPictBackColor), sis ) )
1296 		    { LDEB(1); rval= -1; goto ready;	}
1297 
1298 		PICTDEB(appDebug( "RGBBkCol(%d,%d,%d)\n",
1299 					dc->dcMacPictBackColor.rgb8Red,
1300 					dc->dcMacPictBackColor.rgb8Green,
1301 					dc->dcMacPictBackColor.rgb8Blue ));
1302 
1303 		if  ( appMacPictRefreshDrawingGear( dc, through ) )
1304 		    { LDEB(1); return -1;	}
1305 
1306 		continue;
1307 
1308 	    case MACPICT_PnPat:
1309 		if  ( appMacPictGetPattern( dc, sis, &(dc->dcMacPictPenSolid),
1310 						&(dc->dcMacPictPenIsSolid),
1311 						dc->dcMacPictPenPattern ) )
1312 		    { LDEB(1); rval= -1; goto ready;	}
1313 
1314 		PICTDEB(appDebug(
1315 			"PnPat(%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x)\n",
1316 					    dc->dcMacPictPenPattern[0],
1317 					    dc->dcMacPictPenPattern[1],
1318 					    dc->dcMacPictPenPattern[2],
1319 					    dc->dcMacPictPenPattern[3],
1320 					    dc->dcMacPictPenPattern[4],
1321 					    dc->dcMacPictPenPattern[4],
1322 					    dc->dcMacPictPenPattern[6],
1323 					    dc->dcMacPictPenPattern[7] ));
1324 
1325 		if  ( appMacPictSetPattern( dc, through,
1326 						MACPICThandlePAINT_BRUSH,
1327 						MACPICThandleFRAME_PEN,
1328 						dc->dcMacPictPenIsSolid,
1329 						&(dc->dcMacPictPenSolid),
1330 						dc->dcMacPictPenPattern ) )
1331 		    { LDEB(1); return -1;	}
1332 		continue;
1333 
1334 	    case MACPICT_FillPat:
1335 		if  ( appMacPictGetPattern( dc, sis, &(dc->dcMacPictFillSolid),
1336 						&(dc->dcMacPictFillIsSolid),
1337 						dc->dcMacPictFillPattern ) )
1338 		    { LDEB(1); rval= -1; goto ready;	}
1339 
1340 		PICTDEB(appDebug(
1341 			"FillPat(%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x)\n",
1342 					    dc->dcMacPictFillPattern[0],
1343 					    dc->dcMacPictFillPattern[1],
1344 					    dc->dcMacPictFillPattern[2],
1345 					    dc->dcMacPictFillPattern[3],
1346 					    dc->dcMacPictFillPattern[4],
1347 					    dc->dcMacPictFillPattern[4],
1348 					    dc->dcMacPictFillPattern[6],
1349 					    dc->dcMacPictFillPattern[7] ));
1350 
1351 		if  ( appMacPictSetPattern( dc, through,
1352 						MACPICThandlePAINT_BRUSH,
1353 						MACPICThandle_NONE,
1354 						dc->dcMacPictFillIsSolid,
1355 						&(dc->dcMacPictFillSolid),
1356 						dc->dcMacPictFillPattern ) )
1357 		    { LDEB(1); return -1;	}
1358 
1359 		continue;
1360 
1361 	    case MACPICT_BkPat:
1362 		if  ( appMacPictGetPattern( dc, sis, &(dc->dcMacPictBackSolid),
1363 						&(dc->dcMacPictBackIsSolid),
1364 						dc->dcMacPictBackPattern ) )
1365 		    { LDEB(1); rval= -1; goto ready;	}
1366 
1367 		PICTDEB(appDebug(
1368 			"BkPat(%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x)\n",
1369 					    dc->dcMacPictBackPattern[0],
1370 					    dc->dcMacPictBackPattern[1],
1371 					    dc->dcMacPictBackPattern[2],
1372 					    dc->dcMacPictBackPattern[3],
1373 					    dc->dcMacPictBackPattern[4],
1374 					    dc->dcMacPictBackPattern[4],
1375 					    dc->dcMacPictBackPattern[6],
1376 					    dc->dcMacPictBackPattern[7] ));
1377 
1378 		if  ( appMacPictSetPattern( dc, through,
1379 						MACPICThandleERASE_BRUSH,
1380 						MACPICThandle_NONE,
1381 						dc->dcMacPictBackIsSolid,
1382 						&(dc->dcMacPictBackSolid),
1383 						dc->dcMacPictBackPattern ) )
1384 		    { LDEB(1); return -1;	}
1385 		continue;
1386 
1387 	    case MACPICT_OpColor:
1388 		{
1389 		dc->dcMacPictRedMax= sioEndianGetBeUint16( sis );
1390 		dc->dcMacPictGreenMax= sioEndianGetBeUint16( sis );
1391 		dc->dcMacPictBlueMax= sioEndianGetBeUint16( sis );
1392 
1393 		PICTDEB(appDebug( "OpColor(%u,%u,%u)\n",
1394 						dc->dcMacPictRedMax,
1395 						dc->dcMacPictGreenMax,
1396 						dc->dcMacPictBlueMax ));
1397 		}
1398 		continue;
1399 
1400 	    case MACPICT_TxRatio:
1401 		{
1402 		(void) /* y0= */ sioEndianGetBeInt16( sis );
1403 		(void) /* x0= */ sioEndianGetBeInt16( sis );
1404 		(void) /* y1= */ sioEndianGetBeInt16( sis );
1405 		(void) /* x1= */ sioEndianGetBeInt16( sis );
1406 
1407 		PICTDEB(appDebug( "TxRatio( %d, %d, %d, %d )\n",
1408 							x0, y0, x1, y1 ));
1409 		}
1410 		continue;
1411 
1412 	    case MACPICT_FrameOval:
1413 		appMacPictGetRect( &(dc->dcMacPictOvalRect), sis );
1414 		/*FALLTHROUGH*/
1415 	    case MACPICT_FrameSameOval:
1416 		{
1417 		PICTDEB(appDebug( "FrameOval([%d..%d x %d..%d)\n",
1418 		    dc->dcMacPictOvalRect.drX0, dc->dcMacPictOvalRect.drX1,
1419 		    dc->dcMacPictOvalRect.drY0, dc->dcMacPictOvalRect.drY1 ));
1420 
1421 		if  ( appMacPictChooseGear( dc, through,
1422 						    MACPICThandleDUMMY_BRUSH,
1423 						    MACPICThandleFRAME_PEN ) )
1424 		    { LDEB(1); return -1;	}
1425 
1426 		if  ( appWinMetaDrawEllipse( dc, through,
1427 				    &(dc->dcMacPictOvalRect),
1428 				    dc->dcFillInsides, dc->dcDrawBorders ) )
1429 		    { LDEB(1); rval= -1; goto ready;	}
1430 		}
1431 		continue;
1432 
1433 	    case MACPICT_PaintOval:
1434 		appMacPictGetRect( &(dc->dcMacPictOvalRect), sis );
1435 		/*FALLTHROUGH*/
1436 	    case MACPICT_PaintSameOval:
1437 		{
1438 		PICTDEB(appDebug( "PaintOval([%d..%d x %d..%d)\n",
1439 		    dc->dcMacPictOvalRect.drX0, dc->dcMacPictOvalRect.drX1,
1440 		    dc->dcMacPictOvalRect.drY0, dc->dcMacPictOvalRect.drY1 ));
1441 
1442 		if  ( appMacPictChooseGear( dc, through,
1443 						    MACPICThandlePAINT_BRUSH,
1444 						    MACPICThandleDUMMY_PEN ) )
1445 		    { LDEB(1); return -1;	}
1446 
1447 		if  ( appWinMetaDrawEllipse( dc, through,
1448 				    &(dc->dcMacPictOvalRect),
1449 				    dc->dcFillInsides, dc->dcDrawBorders ) )
1450 		    { LDEB(1); rval= -1; goto ready;	}
1451 		}
1452 		continue;
1453 
1454 	    case MACPICT_FillOval:
1455 		appMacPictGetRect( &(dc->dcMacPictOvalRect), sis );
1456 		/*FALLTHROUGH*/
1457 	    case MACPICT_FillSameOval:
1458 		{
1459 		PICTDEB(appDebug( "FillOval([%d..%d x %d..%d)\n",
1460 		    dc->dcMacPictOvalRect.drX0, dc->dcMacPictOvalRect.drX1,
1461 		    dc->dcMacPictOvalRect.drY0, dc->dcMacPictOvalRect.drY1 ));
1462 
1463 		if  ( appMacPictChooseGear( dc, through,
1464 						    MACPICThandleFILL_BRUSH,
1465 						    MACPICThandleDUMMY_PEN ) )
1466 		    { LDEB(1); return -1;	}
1467 
1468 		if  ( appWinMetaDrawEllipse( dc, through,
1469 				    &(dc->dcMacPictOvalRect),
1470 				    dc->dcFillInsides, dc->dcDrawBorders ) )
1471 		    { LDEB(1); rval= -1; goto ready;	}
1472 		}
1473 		continue;
1474 
1475 	    case MACPICT_EraseOval:
1476 		appMacPictGetRect( &(dc->dcMacPictOvalRect), sis );
1477 		/*FALLTHROUGH*/
1478 	    case MACPICT_EraseSameOval:
1479 		{
1480 		PICTDEB(appDebug( "EraseOval([%d..%d x %d..%d)\n",
1481 		    dc->dcMacPictOvalRect.drX0, dc->dcMacPictOvalRect.drX1,
1482 		    dc->dcMacPictOvalRect.drY0, dc->dcMacPictOvalRect.drY1 ));
1483 
1484 		if  ( appMacPictChooseGear( dc, through,
1485 						    MACPICThandleERASE_BRUSH,
1486 						    MACPICThandleDUMMY_PEN ) )
1487 		    { LDEB(1); return -1;	}
1488 
1489 		if  ( appWinMetaDrawEllipse( dc, through,
1490 				    &(dc->dcMacPictOvalRect),
1491 				    dc->dcFillInsides, dc->dcDrawBorders ) )
1492 		    { LDEB(1); rval= -1; goto ready;	}
1493 		}
1494 		continue;
1495 
1496 	    case MACPICT_FramePoly:
1497 		{
1498 		if  ( appMacPictGetPoly( dc, sis ) < 0 )
1499 		    { rval= -1; goto ready;	}
1500 
1501 		PICTDEB(appDebug( "FramePoly(,%d)\n", dc->dcPointCount ));
1502 
1503 		if  ( appMacPictChooseGear( dc, through,
1504 						    MACPICThandleDUMMY_BRUSH,
1505 						    MACPICThandleFRAME_PEN ) )
1506 		    { LDEB(1); return -1;	}
1507 
1508 		if  ( (*dc->dcDrawPolyPolygon)( dc, through, 1,
1509 				    &(dc->dcPointCount), dc->dcPoints,
1510 				    dc->dcFillInsides, dc->dcDrawBorders, 1 ) )
1511 		    { LDEB(1); return -1;	}
1512 		}
1513 		continue;
1514 
1515 	    case MACPICT_PaintPoly:
1516 		{
1517 		if  ( appMacPictGetPoly( dc, sis ) < 0 )
1518 		    { rval= -1; goto ready;	}
1519 
1520 		PICTDEB(appDebug( "PaintPoly(,%d)\n", dc->dcPointCount ));
1521 
1522 		if  ( appMacPictChooseGear( dc, through,
1523 						    MACPICThandlePAINT_BRUSH,
1524 						    MACPICThandleDUMMY_PEN ) )
1525 		    { LDEB(1); return -1;	}
1526 
1527 		if  ( (*dc->dcDrawPolyPolygon)( dc, through, 1,
1528 				    &dc->dcPointCount, dc->dcPoints,
1529 				    dc->dcFillInsides, dc->dcDrawBorders, 1 ) )
1530 		    { LDEB(1); return -1;	}
1531 		}
1532 		continue;
1533 
1534 	    /* case MACPICT_FillPoly: does not exist */
1535 
1536 	    case MACPICT_ErasePoly:
1537 		/* Format different from documented? */
1538 		if  ( bytes > 0 )
1539 		    {
1540 		    PICTDEB(appDebug( "ErasePoly() bytes= %d\n", bytes ));
1541 		    goto skipBytes;
1542 		    }
1543 		{
1544 		if  ( appMacPictGetPoly( dc, sis ) < 0 )
1545 		    { rval= -1; goto ready;	}
1546 
1547 		PICTDEB(appDebug( "ErasePoly(,%d)\n", dc->dcPointCount ));
1548 
1549 		if  ( appMacPictChooseGear( dc, through,
1550 						    MACPICThandleERASE_BRUSH,
1551 						    MACPICThandleDUMMY_PEN ) )
1552 		    { LDEB(1); return -1;	}
1553 
1554 		if  ( (*dc->dcDrawPolyPolygon)( dc, through, 1,
1555 				    &(dc->dcPointCount), dc->dcPoints,
1556 				    dc->dcFillInsides, dc->dcDrawBorders, 1 ) )
1557 		    { LDEB(1); return -1;	}
1558 		}
1559 		continue;
1560 
1561 	    case MACPICT_ShortLine:
1562 		{
1563 		int			x0;
1564 		int			y0;
1565 		int			x1;
1566 		int			y1;
1567 
1568 		if  ( appMacPictGetShortLine( &x0, &y0, &x1, &y1, dc, sis ) )
1569 		    { LDEB(1); rval= -1; goto ready;	}
1570 
1571 		if  ( appMacPictChooseGear( dc, through,
1572 						    MACPICThandle_NONE,
1573 						    MACPICThandleFRAME_PEN ) )
1574 		    { LDEB(1); return -1;	}
1575 
1576 		if  ( appMacPictDrawLine( dc, through, x0, y0, x1, y1 ) )
1577 		    { LDEB(1); rval= -1; goto ready;	}
1578 		}
1579 		continue;
1580 
1581 	    case MACPICT_ShortLineFrom:
1582 		{
1583 		int			y0;
1584 		int			x0;
1585 		int			y1;
1586 		int			x1;
1587 
1588 		if  ( appMacPictGetShortLineFrom( &x0, &y0, &x1, &y1,
1589 								dc, sis ) )
1590 		    { LDEB(1); rval= -1; goto ready;	}
1591 
1592 		if  ( appMacPictChooseGear( dc, through,
1593 						    MACPICThandle_NONE,
1594 						    MACPICThandleFRAME_PEN ) )
1595 		    { LDEB(1); return -1;	}
1596 
1597 		if  ( appMacPictDrawLine( dc, through, x0, y0, x1, y1 ) )
1598 		    { LDEB(1); rval= -1; goto ready;	}
1599 		}
1600 		continue;
1601 
1602 	    case MACPICT_LineFrom:
1603 		{
1604 		int			y0;
1605 		int			x0;
1606 		int			y1;
1607 		int			x1;
1608 
1609 		if  ( appMacPictGetLineFrom( &x0, &y0, &x1, &y1, dc, sis ) )
1610 		    { LDEB(1); rval= -1; goto ready;	}
1611 
1612 		if  ( appMacPictChooseGear( dc, through,
1613 						    MACPICThandle_NONE,
1614 						    MACPICThandleFRAME_PEN ) )
1615 		    { LDEB(1); return -1;	}
1616 
1617 		if  ( appMacPictDrawLine( dc, through, x0, y0, x1, y1 ) )
1618 		    { LDEB(1); rval= -1; goto ready;	}
1619 		}
1620 		continue;
1621 
1622 	    case MACPICT_Line:
1623 		{
1624 		int			y0;
1625 		int			x0;
1626 		int			y1;
1627 		int			x1;
1628 
1629 		if  ( appMacPictGetLine( &x0, &y0, &x1, &y1, dc, sis ) )
1630 		    { LDEB(1); rval= -1; goto ready;	}
1631 
1632 		if  ( appMacPictChooseGear( dc, through,
1633 						    MACPICThandle_NONE,
1634 						    MACPICThandleFRAME_PEN ) )
1635 		    { LDEB(1); return -1;	}
1636 
1637 		if  ( appMacPictDrawLine( dc, through, x0, y0, x1, y1 ) )
1638 		    { LDEB(1); rval= -1; goto ready;	}
1639 		}
1640 		continue;
1641 
1642 	    case MACPICT_FrameRRect:
1643 		appMacPictGetRect( &(dc->dcMacPictRRectRect), sis );
1644 		/*FALLTHROUGH*/
1645 	    case MACPICT_FrameSameRRect:
1646 		{
1647 		DocumentRectangle	dr;
1648 		int			h;
1649 		int			w;
1650 
1651 		PICTDEB(appDebug( "FrameRRect([%d..%d x %d..%d])\n",
1652 		    dc->dcMacPictRRectRect.drX0, dc->dcMacPictRRectRect.drX1,
1653 		    dc->dcMacPictRRectRect.drY0, dc->dcMacPictRRectRect.drY1 ));
1654 
1655 		appWinMetaTransformRectangle( &dr, dc,
1656 						&(dc->dcMacPictRRectRect) );
1657 		h= DC_hViewport( dc->dcMacPictRRectOvalHigh, dc );
1658 		w= DC_wViewport( dc->dcMacPictRRectOvalWide, dc );
1659 
1660 		if  ( appMacPictChooseGear( dc, through,
1661 						    MACPICThandleDUMMY_BRUSH,
1662 						    MACPICThandleFRAME_PEN ) )
1663 		    { LDEB(1); return -1;	}
1664 
1665 		if  ( (*dc->dcDrawRoundedRectangle)( dc, through, &dr, w, h,
1666 					dc->dcFillInsides, dc->dcDrawBorders ) )
1667 		    { LDEB(1); return -1;	}
1668 		}
1669 		continue;
1670 
1671 	    case MACPICT_PaintRRect:
1672 		appMacPictGetRect( &(dc->dcMacPictRRectRect), sis );
1673 		/*FALLTHROUGH*/
1674 	    case MACPICT_PaintSameRRect:
1675 		{
1676 		DocumentRectangle	dr;
1677 		int			h;
1678 		int			w;
1679 
1680 
1681 		PICTDEB(appDebug( "PaintRRect([%d..%d x %d..%d])\n",
1682 		    dc->dcMacPictRRectRect.drX0, dc->dcMacPictRRectRect.drX1,
1683 		    dc->dcMacPictRRectRect.drY0, dc->dcMacPictRRectRect.drY1 ));
1684 
1685 		appWinMetaTransformRectangle( &dr, dc,
1686 						&(dc->dcMacPictRRectRect) );
1687 		h= DC_hViewport( dc->dcMacPictRRectOvalHigh, dc );
1688 		w= DC_wViewport( dc->dcMacPictRRectOvalWide, dc );
1689 
1690 		if  ( appMacPictChooseGear( dc, through,
1691 						    MACPICThandlePAINT_BRUSH,
1692 						    MACPICThandleDUMMY_PEN ) )
1693 		    { LDEB(1); return -1;	}
1694 
1695 		if  ( (*dc->dcDrawRoundedRectangle)( dc, through, &dr, w, h,
1696 					dc->dcFillInsides, dc->dcDrawBorders ) )
1697 		    { LDEB(1); return -1;	}
1698 		}
1699 		continue;
1700 
1701 	    case MACPICT_FillRRect:
1702 		appMacPictGetRect( &(dc->dcMacPictRRectRect), sis );
1703 		/*FALLTHROUGH*/
1704 	    case MACPICT_FillSameRRect:
1705 		{
1706 		DocumentRectangle	dr;
1707 		int			h;
1708 		int			w;
1709 
1710 
1711 		PICTDEB(appDebug( "FillRRect([%d..%d x %d..%d])\n",
1712 		    dc->dcMacPictRRectRect.drX0, dc->dcMacPictRRectRect.drX1,
1713 		    dc->dcMacPictRRectRect.drY0, dc->dcMacPictRRectRect.drY1 ));
1714 
1715 		appWinMetaTransformRectangle( &dr, dc,
1716 						&(dc->dcMacPictRRectRect) );
1717 		h= DC_hViewport( dc->dcMacPictRRectOvalHigh, dc );
1718 		w= DC_wViewport( dc->dcMacPictRRectOvalWide, dc );
1719 
1720 		if  ( appMacPictChooseGear( dc, through,
1721 						    MACPICThandleFILL_BRUSH,
1722 						    MACPICThandleDUMMY_PEN ) )
1723 		    { LDEB(1); return -1;	}
1724 
1725 		if  ( (*dc->dcDrawRoundedRectangle)( dc, through, &dr, w, h,
1726 					dc->dcFillInsides, dc->dcDrawBorders ) )
1727 		    { LDEB(1); return -1;	}
1728 		}
1729 		continue;
1730 
1731 	    case MACPICT_EraseRRect:
1732 		appMacPictGetRect( &(dc->dcMacPictRRectRect), sis );
1733 		/*FALLTHROUGH*/
1734 	    case MACPICT_EraseSameRRect:
1735 		{
1736 		DocumentRectangle	dr;
1737 		int			h;
1738 		int			w;
1739 
1740 
1741 		PICTDEB(appDebug( "EraseRRect([%d..%d x %d..%d])\n",
1742 		    dc->dcMacPictRRectRect.drX0, dc->dcMacPictRRectRect.drX1,
1743 		    dc->dcMacPictRRectRect.drY0, dc->dcMacPictRRectRect.drY1 ));
1744 
1745 		appWinMetaTransformRectangle( &dr, dc,
1746 						&(dc->dcMacPictRRectRect) );
1747 		h= DC_hViewport( dc->dcMacPictRRectOvalHigh, dc );
1748 		w= DC_wViewport( dc->dcMacPictRRectOvalWide, dc );
1749 
1750 		if  ( appMacPictChooseGear( dc, through,
1751 						    MACPICThandleERASE_BRUSH,
1752 						    MACPICThandleDUMMY_PEN ) )
1753 		    { LDEB(1); return -1;	}
1754 
1755 		if  ( (*dc->dcDrawRoundedRectangle)( dc, through, &dr, w, h,
1756 					dc->dcFillInsides, dc->dcDrawBorders ) )
1757 		    { LDEB(1); return -1;	}
1758 		}
1759 		continue;
1760 
1761 	    case MACPICT_FrameRect:
1762 		appMacPictGetRect( &(dc->dcMacPictRectRect), sis );
1763 		/*FALLTHROUGH*/
1764 	    case MACPICT_FrameSameRect:
1765 		{
1766 		PICTDEB(appDebug( "FrameRect([%d..%d x %d..%d])\n",
1767 		    dc->dcMacPictRectRect.drX0, dc->dcMacPictRectRect.drX1,
1768 		    dc->dcMacPictRectRect.drY0, dc->dcMacPictRectRect.drY1 ));
1769 
1770 		if  ( appMacPictChooseGear( dc, through,
1771 						    MACPICThandleDUMMY_BRUSH,
1772 						    MACPICThandleFRAME_PEN ) )
1773 		    { LDEB(1); return -1;	}
1774 
1775 		if  ( appWinMetaDrawRectangle( dc, through,
1776 					&(dc->dcMacPictRectRect),
1777 					dc->dcFillInsides, dc->dcDrawBorders ) )
1778 		    { LDEB(1); rval= -1; goto ready;	}
1779 		}
1780 		continue;
1781 
1782 	    case MACPICT_PaintRect:
1783 		appMacPictGetRect( &(dc->dcMacPictRectRect), sis );
1784 		/*FALLTHROUGH*/
1785 	    case MACPICT_PaintSameRect:
1786 		{
1787 		PICTDEB(appDebug( "PaintRect([%d..%d x %d..%d])\n",
1788 		    dc->dcMacPictRectRect.drX0, dc->dcMacPictRectRect.drX1,
1789 		    dc->dcMacPictRectRect.drY0, dc->dcMacPictRectRect.drY1 ));
1790 
1791 		if  ( appMacPictChooseGear( dc, through,
1792 						    MACPICThandlePAINT_BRUSH,
1793 						    MACPICThandleDUMMY_PEN ) )
1794 		    { LDEB(1); return -1;	}
1795 
1796 		if  ( appWinMetaDrawRectangle( dc, through,
1797 					&(dc->dcMacPictRectRect),
1798 					dc->dcFillInsides, dc->dcDrawBorders ) )
1799 		    { LDEB(1); rval= -1; goto ready;	}
1800 		}
1801 		continue;
1802 
1803 	    case MACPICT_FillRect:
1804 		appMacPictGetRect( &(dc->dcMacPictRectRect), sis );
1805 		/*FALLTHROUGH*/
1806 	    case MACPICT_FillSameRect:
1807 		{
1808 		PICTDEB(appDebug( "FillRect([%d..%d x %d..%d])\n",
1809 		    dc->dcMacPictRectRect.drX0, dc->dcMacPictRectRect.drX1,
1810 		    dc->dcMacPictRectRect.drY0, dc->dcMacPictRectRect.drY1 ));
1811 
1812 		if  ( appMacPictChooseGear( dc, through,
1813 						    MACPICThandleFILL_BRUSH,
1814 						    MACPICThandleDUMMY_PEN ) )
1815 		    { LDEB(1); return -1;	}
1816 
1817 		if  ( appWinMetaDrawRectangle( dc, through,
1818 					&(dc->dcMacPictRectRect),
1819 					dc->dcFillInsides, dc->dcDrawBorders ) )
1820 		    { LDEB(1); rval= -1; goto ready;	}
1821 		}
1822 		continue;
1823 
1824 	    case MACPICT_EraseRect:
1825 		appMacPictGetRect( &(dc->dcMacPictRectRect), sis );
1826 		/*FALLTHROUGH*/
1827 	    case MACPICT_EraseSameRect:
1828 		{
1829 		PICTDEB(appDebug( "EraseRect([%d..%d x %d..%d])\n",
1830 		    dc->dcMacPictRectRect.drX0, dc->dcMacPictRectRect.drX1,
1831 		    dc->dcMacPictRectRect.drY0, dc->dcMacPictRectRect.drY1 ));
1832 
1833 		if  ( appMacPictChooseGear( dc, through,
1834 						    MACPICThandleERASE_BRUSH,
1835 						    MACPICThandleDUMMY_PEN ) )
1836 		    { LDEB(1); return -1;	}
1837 
1838 		if  ( appWinMetaDrawRectangle( dc, through,
1839 					&(dc->dcMacPictRectRect),
1840 					dc->dcFillInsides, dc->dcDrawBorders ) )
1841 		    { LDEB(1); rval= -1; goto ready;	}
1842 		}
1843 		continue;
1844 
1845 	    case MACPICT_FrameArc:
1846 		if  ( appMacPictGetArc( dc, sis ) )
1847 		    { LDEB(1); return -1;	}
1848 		/*FALLTHROUGH*/
1849 	    case MACPICT_FrameSameArc:
1850 		{
1851 		PICTDEB(appDebug( "FrameArc([%d..%d x %d..%d], %d -> %d)\n",
1852 		    dc->dcMacPictArcRect.drX0, dc->dcMacPictArcRect.drX1,
1853 		    dc->dcMacPictArcRect.drY0, dc->dcMacPictArcRect.drY1,
1854 		    dc->dcMacPictArcA0, dc->dcMacPictArcA1 ));
1855 
1856 		if  ( appMacPictChooseGear( dc, through,
1857 						    MACPICThandleDUMMY_BRUSH,
1858 						    MACPICThandleFRAME_PEN ) )
1859 		    { LDEB(1); return -1;	}
1860 
1861 		if  ( (*dc->dcDrawArc)( dc, through, &(dc->dcMacPictArcRect),
1862 				    dc->dcMacPictArcXs, dc->dcMacPictArcYs,
1863 				    dc->dcMacPictArcXe, dc->dcMacPictArcYe,
1864 				    dc->dcFillInsides, dc->dcDrawBorders ) )
1865 		    { LDEB(1); rval= -1; goto ready;	}
1866 		}
1867 		continue;
1868 
1869 	    case MACPICT_PaintArc:
1870 		if  ( appMacPictGetArc( dc, sis ) )
1871 		    { LDEB(1); return -1;	}
1872 		/*FALLTHROUGH*/
1873 	    case MACPICT_PaintSameArc:
1874 		{
1875 		PICTDEB(appDebug( "PaintArc([%d..%d x %d..%d], %d -> %d)\n",
1876 		    dc->dcMacPictArcRect.drX0, dc->dcMacPictArcRect.drX1,
1877 		    dc->dcMacPictArcRect.drY0, dc->dcMacPictArcRect.drY1,
1878 		    dc->dcMacPictArcA0, dc->dcMacPictArcA1 ));
1879 
1880 		if  ( appMacPictChooseGear( dc, through,
1881 						    MACPICThandlePAINT_BRUSH,
1882 						    MACPICThandleDUMMY_PEN ) )
1883 		    { LDEB(1); return -1;	}
1884 
1885 		if  ( (*dc->dcDrawArc)( dc, through, &(dc->dcMacPictArcRect),
1886 				    dc->dcMacPictArcXs, dc->dcMacPictArcYs,
1887 				    dc->dcMacPictArcXe, dc->dcMacPictArcYe,
1888 				    dc->dcFillInsides, dc->dcDrawBorders ) )
1889 		    { LDEB(1); rval= -1; goto ready;	}
1890 		}
1891 		continue;
1892 
1893 	    case MACPICT_FontName:
1894 		if  ( appMacPictGetFontName( dc, sis ) )
1895 		    { LDEB(1); rval= -1; goto ready;	}
1896 		continue;
1897 
1898 	    case MACPICT_TxFont:
1899 		if  ( appMacPictGetTxFont( dc, sis ) )
1900 		    { LDEB(1); rval= -1; goto ready;	}
1901 		continue;
1902 
1903 	    case MACPICT_TxFace:
1904 		if  ( appMacPictGetTxFace( dc, sis ) )
1905 		    { LDEB(1); rval= -1; goto ready;	}
1906 		continue;
1907 
1908 	    case MACPICT_GlyphState:
1909 		if  ( appMacPictGetGlyphState( dc, sis ) )
1910 		    { LDEB(1); rval= -1; goto ready;	}
1911 		continue;
1912 
1913 	    case MACPICT_DHText:
1914 		{
1915 		int		dh;
1916 		const int	dv= 0;
1917 
1918 		if  ( appMacPictGetDHText( dc, &dh, sis ) )
1919 		    { LDEB(1); rval= -1; goto ready;	}
1920 
1921 		if  ( appMacPictDrawString( dc, dh, dv, through ) )
1922 		    { LDEB(1); rval= -1; goto ready;	}
1923 		}
1924 		continue;
1925 
1926 	    case MACPICT_DVText:
1927 		{
1928 		const int	dh= 0;
1929 		int		dv;
1930 
1931 		if  ( appMacPictGetDVText( dc, &dv, sis ) )
1932 		    { LDEB(1); rval= -1; goto ready;	}
1933 
1934 		if  ( appMacPictDrawString( dc, dh, dv, through ) )
1935 		    { LDEB(1); rval= -1; goto ready;	}
1936 		}
1937 		continue;
1938 
1939 	    case MACPICT_DHDVText:
1940 		{
1941 		int		dh;
1942 		int		dv;
1943 
1944 		if  ( appMacPictGetDHDVText( dc, &dh, &dv, sis ) )
1945 		    { LDEB(1); rval= -1; goto ready;	}
1946 
1947 		if  ( appMacPictDrawString( dc, dh, dv, through ) )
1948 		    { LDEB(1); rval= -1; goto ready;	}
1949 		}
1950 		continue;
1951 
1952 	    case MACPICT_LongText:
1953 		{
1954 		const int	dh= 0;
1955 		const int	dv= 0;
1956 
1957 		if  ( appMacPictGetLongText( dc, sis ) )
1958 		    { LDEB(1); rval= -1; goto ready;	}
1959 
1960 		if  ( appMacPictDrawString( dc, dh, dv, through ) )
1961 		    { LDEB(1); rval= -1; goto ready;	}
1962 		}
1963 		continue;
1964 
1965 	    case MACPICT_LongComment:
1966 		if  ( appMacPictGetLongComment( dc, sis ) )
1967 		    { LDEB(1); rval= -1; goto ready;	}
1968 		continue;
1969 
1970 	    case MACPICT_ShortComment:
1971 		{
1972 		int	kind= sioEndianGetBeInt16( sis );
1973 
1974 		PICTDEB(appDebug( "ShortComment( %d:%s )\n",
1975 				kind, appMacPictCommentName( kind ) ));
1976 
1977 		kind= kind;
1978 		}
1979 		continue;
1980 
1981 	    case MACPICT_FrameRgn:
1982 		{
1983 		int	regionBytes= sioEndianGetBeInt16( sis );
1984 		int	skip;
1985 
1986 		PICTDEB(appDebug( "FrameRgn( %d )\n", regionBytes ));
1987 
1988 		for ( skip= 2; skip < regionBytes; skip++ )
1989 		    {
1990 		    (void) /* regionCoord= */ sioInGetByte( sis );
1991 		    }
1992 		}
1993 		continue;
1994 
1995 	    case MACPICT_PaintRgn:
1996 		{
1997 		int	regionBytes= sioEndianGetBeInt16( sis );
1998 		int	skip;
1999 
2000 		PICTDEB(appDebug( "PaintRgn( %d )\n", regionBytes ));
2001 
2002 		for ( skip= 2; skip < regionBytes; skip++ )
2003 		    {
2004 		    (void) /* regionCoord= */ sioInGetByte( sis );
2005 		    }
2006 		}
2007 		continue;
2008 
2009 	    case MACPICT_BitsRect:
2010 		{
2011 		const int	packed= 0;
2012 		const int	direct= 0;
2013 		const int	clipRegion= 0;
2014 
2015 		PICTDEB(appDebug( "BitsRect( .. ) %d bytes\n", bytes ));
2016 
2017 		if  ( appMacPictDrawImage( dc, through, sis,
2018 						packed, direct, clipRegion ) )
2019 		    { LDEB(1); rval= -1; goto ready;	}
2020 		}
2021 		continue;
2022 
2023 	    case MACPICT_PackBitsRect:
2024 		{
2025 		const int	packed= 1;
2026 		const int	direct= 0;
2027 		const int	clipRegion= 0;
2028 
2029 		PICTDEB(appDebug( "PackBitsRect( .. ) %d bytes\n", bytes ));
2030 
2031 		if  ( appMacPictDrawImage( dc, through, sis,
2032 						packed, direct, clipRegion ) )
2033 		    { LDEB(1); rval= -1; goto ready;	}
2034 		}
2035 		continue;
2036 
2037 	    case MACPICT_PackBitsRgn:
2038 		{
2039 		const int	packed= 1;
2040 		const int	direct= 0;
2041 		const int	clipRegion= 1;
2042 
2043 		PICTDEB(appDebug( "PackBitsRgn( .. ) %d bytes\n", bytes ));
2044 
2045 		if  ( appMacPictDrawImage( dc, through, sis,
2046 						packed, direct, clipRegion ) )
2047 		    { LDEB(1); rval= -1; goto ready;	}
2048 		}
2049 		continue;
2050 
2051 	    case MACPICT_DirectBitsRect:
2052 		{
2053 		const int	packed= 0;
2054 		const int	direct= 1;
2055 		const int	clipRegion= 0;
2056 
2057 		PICTDEB(appDebug( "DirectBitsRect( .. ) %d bytes\n", bytes ));
2058 
2059 		if  ( appMacPictDrawImage( dc, through, sis,
2060 						packed, direct, clipRegion ) )
2061 		    { LDEB(1); rval= -1; goto ready;	}
2062 		}
2063 		continue;
2064 
2065 	    case MACPICT_DirectBitsRgn:
2066 		{
2067 		const int	packed= 0;
2068 		const int	direct= 1;
2069 		const int	clipRegion= 1;
2070 
2071 		PICTDEB(appDebug( "DirectBitsRgn( .. )\n" ));
2072 
2073 		if  ( appMacPictDrawImage( dc, through, sis,
2074 						packed, direct, clipRegion ) )
2075 		    { LDEB(1); rval= -1; goto ready;	}
2076 		}
2077 		continue;
2078 
2079 	    case MACPICT_CompressedQuickTime:
2080 		{
2081 		long	qtbytes= sioEndianGetBeInt32( sis );
2082 		int	skip;
2083 
2084 		PICTDEB(appDebug( "CompressedQuickTime( %ld )\n",
2085 							    qtbytes ));
2086 
2087 		for ( skip= 0; skip < qtbytes; skip++ )
2088 		    {
2089 		    (void) /* qtdata= */ sioInGetByte( sis );
2090 		    }
2091 
2092 		}
2093 		continue;
2094 
2095 	    case MACPICT_UncompressedQuickTime:
2096 		{
2097 		long	qtbytes= sioEndianGetBeInt32( sis );
2098 		int	skip;
2099 
2100 		PICTDEB(appDebug( "UncompressedQuickTime( %ld )\n",
2101 							    qtbytes ));
2102 
2103 		for ( skip= 0; skip < qtbytes; skip++ )
2104 		    {
2105 		    (void) /* qtdata= */ sioInGetByte( sis );
2106 		    }
2107 
2108 		}
2109 		continue;
2110 
2111 	    case MACPICT_TxSize:
2112 		if  ( appMacPictGetTxSize( dc, sis ) )
2113 		    { LDEB(1); rval= -1; goto ready;	}
2114 		continue;
2115 
2116 	    case MACPICT_Origin:
2117 		{
2118 		int	dh= sioEndianGetBeUint16( sis );
2119 		int	dv= sioEndianGetBeUint16( sis );
2120 
2121 		dh= dh; dv= dv;
2122 
2123 		PICTDEB(appDebug( "Origin(%d,%d)\n", dh, dv ));
2124 		}
2125 		continue;
2126 
2127 	    case 0x66:
2128 		XLDEB(opcode,bytes);
2129 		bytes= 12;
2130 		goto skipBytes;
2131 
2132 	    default:
2133 		XDEB(opcode);
2134 	    skipBytes:
2135 		if  ( bytes >= 0 )
2136 		    {
2137 		    int		skip;
2138 		    XLDEB(opcode,bytes);
2139 
2140 		    for ( skip= 0; skip < bytes; skip++ )
2141 			{ (void) /* c= */ sioInGetByte( sis );	}
2142 
2143 		    continue;
2144 		    }
2145 		XDEB(opcode); rval= -1; goto ready;
2146 
2147 	    case MACPICT_OpEndPic:
2148 		PICTDEB(appDebug( "OpEndPic()\n" ));
2149 		break;
2150 	    }
2151 
2152 	break;
2153 	}
2154 
2155   ready:
2156 
2157     return rval;
2158     }
2159 
2160 /************************************************************************/
2161 /*									*/
2162 /*  Read the header of a macpict metafile.				*/
2163 /*									*/
2164 /*  2)  Read picture size.						*/
2165 /*  3)  Read picture frame.						*/
2166 /*  4)  Read version.							*/
2167 /*									*/
2168 /************************************************************************/
2169 
appMacPictGetDeviceHeader(MacPictHeader * mph,SimpleInputStream * sis)2170 int appMacPictGetDeviceHeader(	MacPictHeader *		mph,
2171 				SimpleInputStream *	sis )
2172     {
2173     int			c;
2174     int			i;
2175 
2176     /*  2  */
2177     mph->mphPictureSize= sioEndianGetBeInt16( sis );
2178 
2179     /*  3  */
2180     mph->mphFrame.drY0= sioEndianGetBeInt16( sis );
2181     mph->mphFrame.drX0= sioEndianGetBeInt16( sis );
2182     mph->mphFrame.drY1= sioEndianGetBeInt16( sis );
2183     mph->mphFrame.drX1= sioEndianGetBeInt16( sis );
2184 
2185     /*  4  */
2186     c= sioInGetByte( sis );
2187     switch( c )
2188 	{
2189 	case 0:
2190 	    c= sioInGetByte( sis );
2191 	    if  ( c != 0x11 )
2192 		{ XDEB(c); return -1;	}
2193 
2194 	    mph->mphVersion= sioInGetByte( sis );
2195 	    if  ( mph->mphVersion != 2 )
2196 		{ LDEB(mph->mphVersion); return -1;	}
2197 
2198 	    c= sioInGetByte( sis );
2199 	    if  ( c != 0xff )
2200 		{ XDEB(c); return -1;	}
2201 
2202 	    c= sioEndianGetBeInt16( sis );
2203 	    if  ( c != 0xc00 )
2204 		{ XDEB(c); return -1;	}
2205 
2206 	    (void) /* l= */ sioEndianGetBeInt32( sis );
2207 	    /*
2208 	    if  ( l != -1 )
2209 		{ LDEB(l); return -1;	}
2210 	    */
2211 
2212 	    for ( i= 0; i < 8; i++ )
2213 		{ c= sioEndianGetBeInt16( sis ); }
2214 
2215 	    c= sioEndianGetBeInt16( sis );
2216 	    if  ( c != 0x00 )
2217 		{ XDEB(c); /*return -1;*/	}
2218 	    c= sioEndianGetBeInt16( sis );
2219 	    if  ( c != 0x00 )
2220 		{ XDEB(c); /*return -1;*/	}
2221 	    break;
2222 
2223 	case 0x11:
2224 	    mph->mphVersion= sioInGetByte( sis );
2225 	    if  ( mph->mphVersion != 1 )
2226 		{ LDEB(mph->mphVersion); return -1;	}
2227 	    break;
2228 
2229 	default:
2230 	    XDEB(c); return -1;
2231 	}
2232 
2233     return 0;
2234     }
2235 
2236