1 /************************************************************************/
2 /*									*/
3 /*  Font Chooser.							*/
4 /*									*/
5 /************************************************************************/
6 
7 #   include	"appFrameConfig.h"
8 
9 #   include	<stdio.h>
10 #   include	<stddef.h>
11 #   include	<string.h>
12 #   include	<limits.h>
13 
14 #   include	<appDebugon.h>
15 
16 #   include	<appUnit.h>
17 #   include	<geoString.h>
18 #   include	<utilPropMask.h>
19 #   include	<textAttributeUtil.h>
20 
21 #   include	"appFrame.h"
22 #   include	"guiToolUtil.h"
23 #   include	"appMatchFont.h"
24 
25 #   include	"appFontTool.h"
26 #   include	"guiWidgetDrawingSurface.h"
27 #   include	"guiDrawingWidget.h"
28 #   include	"drawDrawingSurfacePrivate.h"
29 #   include	"guiTextUtil.h"
30 
31 /************************************************************************/
32 /*									*/
33 /*  Value lists that can be used when no particular font is selected.	*/
34 /*									*/
35 /************************************************************************/
36 
37 static int EditFontToolSizesHalfPoints[]=
38 			    {
39 			    2* 8,
40 			    2* 9,
41 			    2* 10,
42 			    2* 11,
43 			    2* 12,
44 			    2* 14,
45 			    2* 16,
46 			    2* 18,
47 			    2* 24,
48 			    2* 36,
49 			    2* 48,
50 			    2* 64
51 			    };
52 
53 static const int EditFontToolSizeCount=
54 		sizeof(EditFontToolSizesHalfPoints)/sizeof(int);
55 
56 /************************************************************************/
57 /*									*/
58 /*  Format the size of the font in the Text box below the list.		*/
59 /*									*/
60 /************************************************************************/
61 
appFontToolFormatSize(char * scratch,int halfPoints)62 static void appFontToolFormatSize(	char *		scratch,
63 					int		halfPoints )
64     {
65     if  ( halfPoints % 2 )
66 	{ sprintf( scratch, "%d.5", halfPoints/ 2 );	}
67     else{ sprintf( scratch, "%d", halfPoints/ 2 );	}
68     }
69 
70 /************************************************************************/
71 /*									*/
72 /*  Find an existing face of the font.					*/
73 /*									*/
74 /************************************************************************/
75 
appFontToolFindExistingFace(const ExpandedTextAttribute * etaC,const DocumentFont * df)76 static int appFontToolFindExistingFace(	const ExpandedTextAttribute *	etaC,
77 					const DocumentFont *		df )
78     {
79     int			i;
80     /*
81     TextAttribute *	taC= &(etaC->etaTextAttribute);
82     */
83 
84     for ( i= 0; i < FONTface_COUNT; i++ )
85 	{
86 	if  ( df->dfPsFontInfo[i] )
87 	    {
88 	    /*
89 	    taC->taFontIsBold= FACE_BOLD( i );
90 	    taC->taFontIsSlanted= FACE_SLANTED( i );
91 	    */
92 	    return i;
93 	    }
94 	}
95 
96     return -1;
97     }
98 
99 /************************************************************************/
100 /*									*/
101 /*  Redraw the sample of the font chooser.				*/
102 /*									*/
103 /************************************************************************/
104 
APP_EVENT_HANDLER_H(appFontRedraw,w,voidafc,exposeEvent)105 static APP_EVENT_HANDLER_H( appFontRedraw, w, voidafc, exposeEvent )
106     {
107     AppFontChooser *			afc= (AppFontChooser *)voidafc;
108     DrawingSurface			ds= afc->afcDrawingSurface;
109 
110     DocumentRectangle			drClip;
111 
112     int					x;
113     int					y;
114     int					wide;
115     int					high;
116 
117     DocumentRectangle			drWidget;
118     DocumentRectangle			drText;
119 
120     int					l= strlen( afc->afcChoiceText );
121 
122     guiCollectExposures( &drClip, afc->afcSampleDrawing, exposeEvent );
123 
124     drawSetClipRect( ds, &drClip );
125 
126     drawSetForegroundColorWhite( ds );
127     drawFillRectangle( ds, &drClip );
128 
129     if  ( afc->afcScreenFont < 0 )
130 	{ /*SLDEB(afc->afcChoiceText,afc->afcScreenFont);*/ return;	}
131 
132     drawSetForegroundColorBlack( ds );
133 
134     guiDrawGetSizeOfWidget( &wide, &high, w );
135     drWidget.drX0= 0;
136     drWidget.drX1= wide- 1;
137     drWidget.drY0= 0;
138     drWidget.drY1= high- 1;
139 
140     x= y= 0;
141     drawGetTextExtents( &drText, ds, x, y,
142 			afc->afcScreenFont, afc->afcChoiceText, l );
143 
144     y= ( drWidget.drY1+ drWidget.drY0 )/ 2- ( drText.drY1+ drText.drY0+ 1 )/2;
145     x= ( drWidget.drX1+ drWidget.drX0 )/ 2- ( drText.drX1+ drText.drX0+ 1 )/2;
146 
147     drawString( ds, x, y, afc->afcScreenFont, afc->afcChoiceText, l );
148 
149     drawNoClipping( ds );
150 
151     return;
152     }
153 
154 /************************************************************************/
155 /*									*/
156 /*  Show the current font size.						*/
157 /*									*/
158 /************************************************************************/
159 
appFontShowSizeInList(AppFontChooser * afc,int fontSizeHalfPoints)160 static void appFontShowSizeInList(
161 				AppFontChooser *	afc,
162 				int			fontSizeHalfPoints )
163     {
164     int		pos;
165     int		sizeChosen= -1;
166 
167     afc->afcInProgrammaticChange++;
168 
169     for ( pos= 0; pos < EditFontToolSizeCount; pos++ )
170 	{
171 	if  ( fontSizeHalfPoints > 0				&&
172 	      EditFontToolSizesHalfPoints[pos] ==
173 					fontSizeHalfPoints	)
174 	    { sizeChosen= pos; break;	}
175 	}
176 
177     if  ( sizeChosen >= 0 )
178 	{ appGuiSelectPositionInListWidget( afc->afcSizeList, sizeChosen ); }
179     else{ appGuiRemoveSelectionFromListWidget( afc->afcSizeList );	    }
180 
181     afc->afcInProgrammaticChange--;
182 
183     return;
184     }
185 
appFontShowSizeInText(AppFontChooser * afc,int fontSizeHalfPoints)186 static void appFontShowSizeInText(
187 				AppFontChooser *	afc,
188 				int			fontSizeHalfPoints )
189     {
190     char	scratch[80];
191 
192     if  ( fontSizeHalfPoints >= 0 )
193 	{
194 	appFontToolFormatSize( scratch, fontSizeHalfPoints );
195 	appStringToTextWidget( afc->afcSizeText, scratch );
196 	}
197     else{
198 	appStringToTextWidget( afc->afcSizeText, "" );
199 	}
200 
201     return;
202     }
203 
204 /************************************************************************/
205 /*									*/
206 /*  Get the size of the currently selected font.			*/
207 /*									*/
208 /************************************************************************/
209 
appFontToolGetSize(int * pFontSizeHalfPoints,int anyway,AppFontChooser * afc)210 static int appFontToolGetSize(	int *			pFontSizeHalfPoints,
211 				int			anyway,
212 				AppFontChooser *	afc )
213     {
214     ExpandedTextAttribute *	eta= &(afc->afcTextAttributeChosen);
215     TextAttribute *		ta= &(eta->etaTextAttribute);
216     int				sizeHalfPoints= ta->taFontSizeHalfPoints;
217 
218     char *		val;
219     char *		s;
220 
221     const int		minValue= 1;
222     const int		adaptToMin= 0;
223     const int		maxValue= INT_MAX;
224     const int		adaptToMax= 0;
225 
226     int			isEmpty;
227 
228     if  ( afc->afcSizeText )
229 	{
230 	s= val= appGetStringFromTextWidget( afc->afcSizeText );
231 	while( isspace( *s ) )
232 	    { s++;	}
233 	isEmpty= ! *s;
234 
235 	appFreeStringFromTextWidget( val );
236 	}
237     else{ isEmpty= 1;	}
238 
239     if  ( isEmpty )
240 	{ sizeHalfPoints= -1;	}
241     else{
242 	int		changed= 0;
243 	int		sizeTwips= sizeHalfPoints;
244 
245 	if  ( sizeTwips > 0 )
246 	    { sizeTwips *= 10;	}
247 
248 	if  ( appGetLengthFromTextWidget( afc->afcSizeText,
249 				&sizeTwips, &changed, UNITtyPOINTS,
250 				minValue, adaptToMin, maxValue, adaptToMax ) )
251 	    {
252 	    if  ( anyway )
253 		{ sizeHalfPoints= -1;	}
254 	    else{ return -1;			}
255 	    }
256 	else{
257 	    char	scratch[80];
258 
259 	    sizeHalfPoints= ( sizeTwips+ 5 )/ 10;
260 
261 	    appFontToolFormatSize( scratch, sizeHalfPoints );
262 
263 	    val= appGetStringFromTextWidget( afc->afcSizeText );
264 
265 	    if  ( strcmp( val, scratch ) )
266 		{ appStringToTextWidget( afc->afcSizeText, scratch );	}
267 
268 	    appFreeStringFromTextWidget( val );
269 	    }
270 	}
271 
272     *pFontSizeHalfPoints= sizeHalfPoints;
273     return 0;
274     }
275 
276 /************************************************************************/
277 /*									*/
278 /*  Get the current baseline shift.					*/
279 /*									*/
280 /************************************************************************/
281 
appFontToolGetBaseline(int * pBaselineHalfPoints,int * pEmpty,int anyway,AppFontChooser * afc)282 static int appFontToolGetBaseline(
283 				int *			pBaselineHalfPoints,
284 				int *			pEmpty,
285 				int			anyway,
286 				AppFontChooser *	afc )
287     {
288     ExpandedTextAttribute *	eta= &(afc->afcTextAttributeChosen);
289     TextAttribute *		ta= &(eta->etaTextAttribute);
290     int				baselineHalfPoints= ta->taBaselineShiftHalfPoints;
291 
292     char *		val;
293     char *		s;
294 
295     const int		minValue= INT_MIN;
296     const int		adaptToMin= 0;
297     const int		maxValue= INT_MAX;
298     const int		adaptToMax= 0;
299 
300     if  ( afc->afcBaselineText )
301 	{
302 	s= val= appGetStringFromTextWidget( afc->afcBaselineText );
303 	while( isspace( *s ) )
304 	    { s++;	}
305 	*pEmpty= ! *s;
306 
307 	appFreeStringFromTextWidget( val );
308 	}
309     else{ *pEmpty= 1;	}
310 
311     if  ( *pEmpty )
312 	{ baselineHalfPoints= -1;	}
313     else{
314 	int		changed= 0;
315 	int		baselineTwips= baselineHalfPoints;
316 
317 	if  ( baselineTwips > 0 )
318 	    { baselineTwips *= 10;	}
319 
320 	if  ( appGetLengthFromTextWidget( afc->afcBaselineText,
321 				&baselineTwips, &changed, UNITtyPOINTS,
322 				minValue, adaptToMin, maxValue, adaptToMax ) )
323 	    {
324 	    if  ( anyway )
325 		{ baselineHalfPoints= -1;	}
326 	    else{ return -1;			}
327 	    }
328 	else{
329 	    char	scratch[80];
330 
331 	    if  ( baselineTwips < 0 )
332 		{ baselineHalfPoints= ( baselineTwips- 5 )/ 10;	}
333 	    else{ baselineHalfPoints= ( baselineTwips+ 5 )/ 10;	}
334 
335 	    appFontToolFormatSize( scratch, baselineHalfPoints );
336 
337 	    val= appGetStringFromTextWidget( afc->afcBaselineText );
338 
339 	    if  ( strcmp( val, scratch ) )
340 		{ appStringToTextWidget( afc->afcBaselineText, scratch ); }
341 
342 	    appFreeStringFromTextWidget( val );
343 	    }
344 	}
345 
346     *pBaselineHalfPoints= baselineHalfPoints;
347     return 0;
348     }
349 
appFontGetCurrent(int * pFamily,int * pFace,int * pFontSizeHalfPoints,int anyway,AppFontChooser * afc)350 static int appFontGetCurrent(	int *			pFamily,
351 				int *			pFace,
352 				int *			pFontSizeHalfPoints,
353 				int			anyway,
354 				AppFontChooser *	afc )
355     {
356     ExpandedTextAttribute *		etaC= &(afc->afcTextAttributeChosen);
357     const PropertyMask *		chosenMask= &(afc->afcChosenMask);
358 
359     DocumentFontList *			dfl= &(afc->afcDocumentFontList);
360 
361     int					fontChosen= -1;
362     int					faceChosen= afc->afcFaceChosen;
363 
364     int					sizeHalfPoints;
365 
366     if  ( appFontToolGetSize( &sizeHalfPoints, anyway, afc ) )
367 	{ return -1;	}
368 
369     if  ( PROPmaskISSET( chosenMask, TApropFONT_NUMBER )	&&
370 	  afc->afcFontSortIndexChosen >= 0			)
371 	{
372 	fontChosen= utilDocumentFontListGetArrayIndex( dfl,
373 						afc->afcFontSortIndexChosen );
374 	}
375 
376     if  ( fontChosen < 0 && anyway )
377 	{ fontChosen= 0; }
378     if  ( faceChosen < 0 && anyway )
379 	{ faceChosen= 0; }
380     if  ( sizeHalfPoints < 0 && anyway )
381 	{ sizeHalfPoints= 24; }
382 
383     if  ( anyway && fontChosen >= 0 )
384 	{
385 	DocumentFont *	df;
386 
387 	df= docFontListGetFontByNumber( dfl, fontChosen );
388 
389 	if  ( df && ( faceChosen < 0 || ! df->dfPsFontInfo[faceChosen] ) )
390 	    { faceChosen= appFontToolFindExistingFace( etaC, df );	}
391 	}
392 
393     if  ( pFamily )
394 	{ *pFamily= fontChosen;	}
395     if  ( pFace )
396 	{ *pFace= faceChosen;	}
397     if  ( pFontSizeHalfPoints )
398 	{ *pFontSizeHalfPoints= sizeHalfPoints;	}
399 
400     return 0;
401     }
402 
403 /************************************************************************/
404 /*									*/
405 /*  Format the current font name.					*/
406 /*									*/
407 /************************************************************************/
408 
appFontFormatCurrent(char * target,AppFontChooser * afc,const char * familyName,int face,int sizeHalfPoints)409 static void appFontFormatCurrent(	char *			target,
410 					AppFontChooser *	afc,
411 					const char *		familyName,
412 					int			face,
413 					int			sizeHalfPoints )
414     {
415     const char *	familyText= "*";
416     char		faceName[40];
417     char		sizeStr[40];
418 
419     faceName[0]= '*';
420     faceName[1]= '\0';
421 
422     sizeStr[0]= '*';
423     sizeStr[1]= '\0';
424 
425     if  ( familyName )
426 	{ familyText= familyName;	}
427 
428     if  ( face >= 0		&&
429 	  face < FONTface_COUNT &&
430 	  strlen( (char *)afc->afcResources.aftrFaces[face] ) <
431 							sizeof(faceName) )
432 	{ strcpy( faceName, afc->afcResources.aftrFaces[face] ); }
433 
434     if  ( sizeHalfPoints > 0 )
435 	{
436 	if  ( sizeHalfPoints % 2 )
437 	    { sprintf( sizeStr, "%d.5", sizeHalfPoints/ 2 );	}
438 	else{ sprintf( sizeStr, "%d", sizeHalfPoints/ 2 );	}
439 	}
440 
441     sprintf( target, "%s,%s,%s", familyText, faceName, sizeStr );
442 
443     return;
444     }
445 
446 /************************************************************************/
447 /*									*/
448 /*  Reflect the currently selected font.				*/
449 /*									*/
450 /************************************************************************/
451 
appFontShowExampleOfCurrent(AppFontChooser * afc)452 static void appFontShowExampleOfCurrent(	AppFontChooser *	afc )
453     {
454     const ExpandedTextAttribute *	etaC= &(afc->afcTextAttributeChosen);
455     DrawingSurface			ds= afc->afcDrawingSurface;
456     DocumentFontList *			dfl= &(afc->afcDocumentFontList);
457     int					pixelSize;
458 
459     const PostScriptFontList *		psfl= afc->afcPostScriptFontList;
460     const AfmFontInfo *			afi;
461     const IndexSet *			unicodesWanted;
462 
463     int					fontSizeHalfPoints= -1;
464 
465     int					family= -1;
466     int					face= -1;
467 
468     int			screenFont;
469 
470     TextAttribute	ta;
471     PropertyMask	taSetMask;
472     PropertyMask	taDoneMask;
473 
474     utilPropMaskClear( &taSetMask );
475     utilInitTextAttribute( &ta );
476 
477     PROPmaskADD( &taSetMask, TApropFONT_NUMBER );
478     PROPmaskADD( &taSetMask, TApropFONTSIZE );
479     PROPmaskADD( &taSetMask, TApropFONTBOLD );
480     PROPmaskADD( &taSetMask, TApropFONTSLANTED );
481 
482     utilPropMaskAnd( &taSetMask, &taSetMask, &(afc->afcChosenMask) );
483 
484     docIndirectTextAttribute( &taDoneMask, &ta, etaC, &taSetMask, dfl,
485 							(ColorPalette *)0 );
486 
487     afc->afcScreenFont= -1;
488 
489     appFontGetCurrent( &family, &face, &fontSizeHalfPoints, 0, afc );
490 
491     appFontFormatCurrent( afc->afcChoiceText, afc, etaC->etaFontName,
492 						face, fontSizeHalfPoints );
493     appFontGetCurrent( &family, &face, &fontSizeHalfPoints, 1, afc );
494     if  ( ta.taFontNumber < 0 )
495 	{ ta.taFontNumber= family; }
496     if  ( ta.taFontNumber < 0 )
497 	{ ta.taFontNumber= 0; }
498     if  ( ta.taFontSizeHalfPoints <= 0 )
499 	{ ta.taFontSizeHalfPoints= fontSizeHalfPoints; }
500 
501     afi= appGetFontInfoForAttribute( &unicodesWanted, &ta, dfl, psfl );
502     if  ( afi )
503 	{ appGuiChangeLabelText( afc->afcPsName, afi->afiFontName );	}
504     else{ appGuiChangeLabelText( afc->afcPsName, "<?>" );		}
505 
506     pixelSize= textGetPixelSize( afc->afcPixelsPerTwip, &ta );
507     screenFont= drawOpenScreenFont( ds, afi, pixelSize, unicodesWanted );
508     if  ( screenFont < 0 )
509 	{ LDEB(screenFont);	}
510     else{
511 	afc->afcScreenFont= screenFont;
512 
513 	if  ( drawFontImplementationName( afc->afcScreenChoiceText,
514 					    sizeof(afc->afcScreenChoiceText),
515 					    ds, afc->afcScreenFont ) )
516 	    { appGuiChangeLabelText( afc->afcScreenName, "<?>" );	}
517 	else{
518 	    appGuiChangeLabelText( afc->afcScreenName,
519 						afc->afcScreenChoiceText );
520 	    }
521 	}
522 
523     guiExposeDrawingWidget( afc->afcSampleDrawing );
524 
525     guiEnableWidget( afc->afcApplyButton,
526 			    ! utilPropMaskIsEmpty( &(afc->afcChosenMask) ) );
527 
528     return;
529     }
530 
531 /************************************************************************/
532 /*									*/
533 /*  A font family has been chosen, or set.				*/
534 /*  Try to find a face that matches the current attributes.		*/
535 /*									*/
536 /*  NOTE: The family list is set by the caller.				*/
537 /*									*/
538 /************************************************************************/
539 
appFontToolGetFaceNumber(AppFontChooser * afc)540 static int appFontToolGetFaceNumber(	AppFontChooser *	afc )
541     {
542     const ExpandedTextAttribute *	etaC= &(afc->afcTextAttributeChosen);
543     const TextAttribute *		taC= &(etaC->etaTextAttribute);
544     const PropertyMask *		chosenMask= &(afc->afcChosenMask);
545 
546     if  ( PROPmaskISSET( chosenMask, TApropFONTBOLD )		&&
547 	  PROPmaskISSET( chosenMask, TApropFONTSLANTED )	)
548 	{ return FACE_INDEX(taC->taFontIsSlanted,taC->taFontIsBold); }
549 
550     return -1;
551     }
552 
appFontReflectFamily(AppFontChooser * afc)553 static void appFontReflectFamily(	AppFontChooser *	afc )
554     {
555     int					face;
556     int					set;
557 
558     appGuiEmptyListWidget( afc->afcFaceList );
559 
560     for ( face= 0; face < FONTface_COUNT; face++ )
561 	{
562 	afc->afcFaceMapFwd[face]= -1;
563 	afc->afcFaceMapBck[face]= -1;
564 	}
565 
566     set= 0;
567     for ( face= 0; face < FONTface_COUNT; face++ )
568 	{
569 	appGuiAddValueToListWidget( afc->afcFaceList, -1,
570 					afc->afcResources.aftrFaces[face] );
571 
572 	afc->afcFaceMapFwd[set]= face;
573 	afc->afcFaceMapBck[face]= set;
574 	set++;
575 	}
576 
577     afc->afcFaceChosen= appFontToolGetFaceNumber( afc );
578 
579     if  ( afc->afcFaceChosen >= 0 )
580 	{
581 	appGuiSelectPositionInListWidget( afc->afcFaceList,
582 				    afc->afcFaceMapBck[afc->afcFaceChosen] );
583 	}
584     else{
585 	appGuiRemoveSelectionFromListWidget( afc->afcFaceList );
586 	}
587 
588     return;
589     }
590 
591 /************************************************************************/
592 /*									*/
593 /*  Current properties have just been set: adapt to them.		*/
594 /*									*/
595 /*  1)  If a font family is set, look for it in the list of families.	*/
596 /*  2)	Position the list accordingly.					*/
597 /*  3)	Set the encoding menu.						*/
598 /*  4)	Select the correct font face in the list widget.		*/
599 /*  5)	Display the font size.						*/
600 /*  7)	Set underline toggle.						*/
601 /*  8)	Set strikethrough toggle.					*/
602 /*  9)	Set the superscript toggle.					*/
603 /*  10)	Set the subscript toggle.					*/
604 /*  11)	Set the smallcaps toggle.					*/
605 /*  12)	Set the capitals toggle.					*/
606 /*  15)	Show an example of the current font.				*/
607 /*									*/
608 /************************************************************************/
609 
appFontReflectProperties(AppFontChooser * afc)610 static void appFontReflectProperties(	AppFontChooser *	afc )
611     {
612     int					fontIndex;
613     int					face;
614 
615     const ExpandedTextAttribute *	etaC= &(afc->afcTextAttributeChosen);
616     const TextAttribute *		taC= &(etaC->etaTextAttribute);
617     const PropertyMask *		chosenMask= &(afc->afcChosenMask);
618 
619     DocumentFontList *			dfl= &(afc->afcDocumentFontList);
620     int					set;
621 
622     /*  1  */
623     fontIndex= -1;
624 
625     if  ( PROPmaskISSET( chosenMask, TApropFONT_NUMBER )	&&
626 	  etaC->etaFontName					)
627 	{
628 	int fontNumber= docGetFontByName( dfl, etaC->etaFontName );
629 
630 	if  ( fontNumber >= 0 )
631 	    { fontIndex= utilDocumentFontListGetSortIndex( dfl, fontNumber ); }
632 	}
633 
634     /*  2  */
635     if  ( afc->afcFontSortIndexChosen != fontIndex )
636 	{
637 	afc->afcFontSortIndexChosen= fontIndex;
638 
639 	if  ( afc->afcFontSortIndexChosen >= 0 )
640 	    {
641 	    appGuiSelectPositionInListWidget( afc->afcFamilyList,
642 					afc->afcFontSortIndexChosen );
643 	    }
644 	else{
645 	    appGuiRemoveSelectionFromListWidget( afc->afcFamilyList );
646 	    }
647 
648 	appFontReflectFamily( afc );
649 	}
650 
651     /*  4  */
652     face= appFontToolGetFaceNumber( afc );
653 
654     if  ( afc->afcFaceChosen != face )
655 	{
656 	afc->afcFaceChosen= face;
657 
658 	if  ( afc->afcFaceChosen >= 0 )
659 	    {
660 	    appGuiSelectPositionInListWidget( afc->afcFaceList,
661 				    afc->afcFaceMapBck[afc->afcFaceChosen] );
662 	    }
663 	else{ appGuiRemoveSelectionFromListWidget( afc->afcFaceList );	}
664 	}
665 
666     /*  5  */
667     {
668     int		fontSizeHalfPoints= -1;
669 
670     if  ( PROPmaskISSET( chosenMask, TApropFONTSIZE ) )
671 	{ fontSizeHalfPoints= taC->taFontSizeHalfPoints;	}
672 
673     appFontShowSizeInList( afc, fontSizeHalfPoints );
674     appFontShowSizeInText( afc, fontSizeHalfPoints );
675     }
676 
677     {
678     if  ( PROPmaskISSET( chosenMask, TApropBASELINE_SHIFT ) )
679 	{
680 	char	scratch[80];
681 
682 	appFontToolFormatSize( scratch, taC->taBaselineShiftHalfPoints );
683 
684 	appStringToTextWidget( afc->afcBaselineText, scratch );
685 	}
686     else{
687 	appStringToTextWidget( afc->afcBaselineText, "" );
688 	}
689     }
690 
691     /*  7  */
692     set= 0;
693     if  ( PROPmaskISSET( &(afc->afcChosenMask), TApropTEXTUNDERLINED ) )
694 	{ set= taC->taTextIsUnderlined;	}
695     appGuiSetToggleState( afc->afcUnderlinedToggle, set );
696 
697     /*  8  */
698     set= 0;
699     if  ( PROPmaskISSET( &(afc->afcChosenMask), TApropSTRIKETHROUGH ) )
700 	{ set= taC->taHasStrikethrough;	}
701     appGuiSetToggleState( afc->afcStrikethroughToggle, set );
702 
703     /*  9  */
704     set= 0;
705     if  ( PROPmaskISSET( &(afc->afcChosenMask), TApropSUPERSUB ) )
706 	{ set= taC->taSuperSub == TEXTvaSUPERSCRIPT;	}
707     appGuiSetToggleState( afc->afcSuperscriptToggle, set );
708 
709     /*  10  */
710     set= 0;
711     if  ( PROPmaskISSET( &(afc->afcChosenMask), TApropSUPERSUB ) )
712 	{ set= taC->taSuperSub == TEXTvaSUBSCRIPT;	}
713     appGuiSetToggleState( afc->afcSubscriptToggle, set );
714 
715     /*  11  */
716     set= 0;
717     if  ( PROPmaskISSET( &(afc->afcChosenMask), TApropSMALLCAPS ) )
718 	{ set= taC->taSmallCaps;	}
719     appGuiSetToggleState( afc->afcSmallcapsToggle, set );
720 
721     /*  12  */
722     set= 0;
723     if  ( PROPmaskISSET( &(afc->afcChosenMask), TApropCAPITALS ) )
724 	{ set= taC->taCapitals;	}
725     appGuiSetToggleState( afc->afcCapitalsToggle, set );
726 
727     /*  15  */
728     appFontShowExampleOfCurrent( afc );
729 
730     return;
731     }
732 
733 /************************************************************************/
734 /*									*/
735 /*  The 'Underline' toggle was activated.				*/
736 /*  The 'Strikethrough' toggle was activated.				*/
737 /*  The 'Superscript' toggle was activated.				*/
738 /*  The 'Subscript' toggle was activated.				*/
739 /*  The 'Smallcaps' toggle was activated.				*/
740 /*  The 'Capitals' toggle was activated.				*/
741 /*									*/
742 /************************************************************************/
743 
APP_TOGGLE_CALLBACK_H(appFontUnderlinedToggled,w,voidafc,voidtbcs)744 static APP_TOGGLE_CALLBACK_H( appFontUnderlinedToggled, w, voidafc, voidtbcs )
745     {
746     AppFontChooser *		afc= (AppFontChooser *)voidafc;
747     ExpandedTextAttribute *	etaC= &(afc->afcTextAttributeChosen);
748     TextAttribute *		taC= &(etaC->etaTextAttribute);
749     int				set;
750 
751     set= appGuiGetToggleStateFromCallback( w, voidtbcs );
752 
753     if  ( ! set								&&
754 	  ! PROPmaskISSET( &(afc->afcChosenMask), TApropTEXTUNDERLINED ) )
755 	{ return;	}
756 
757     PROPmaskADD( &(afc->afcChosenMask), TApropTEXTUNDERLINED );
758     taC->taTextIsUnderlined= ( set != 0 );
759 
760     guiEnableWidget( afc->afcApplyButton,
761 			    ! utilPropMaskIsEmpty( &(afc->afcChosenMask) ) );
762 
763     return;
764     }
765 
APP_TOGGLE_CALLBACK_H(appFontStrikethroughToggled,w,voidafc,voidtbcs)766 static APP_TOGGLE_CALLBACK_H( appFontStrikethroughToggled, w, voidafc, voidtbcs )
767     {
768     AppFontChooser *		afc= (AppFontChooser *)voidafc;
769     ExpandedTextAttribute *	etaC= &(afc->afcTextAttributeChosen);
770     TextAttribute *		taC= &(etaC->etaTextAttribute);
771     int				set;
772 
773     set= appGuiGetToggleStateFromCallback( w, voidtbcs );
774 
775     if  ( ! set								&&
776 	  ! PROPmaskISSET( &(afc->afcChosenMask), TApropSTRIKETHROUGH )	)
777 	{ return;	}
778 
779     PROPmaskADD( &(afc->afcChosenMask), TApropSTRIKETHROUGH );
780     taC->taHasStrikethrough= ( set != 0 );
781 
782     guiEnableWidget( afc->afcApplyButton,
783 			    ! utilPropMaskIsEmpty( &(afc->afcChosenMask) ) );
784 
785     return;
786     }
787 
APP_TOGGLE_CALLBACK_H(appFontSuperscriptToggled,w,voidafc,voidtbcs)788 static APP_TOGGLE_CALLBACK_H( appFontSuperscriptToggled, w, voidafc, voidtbcs )
789     {
790     AppFontChooser *		afc= (AppFontChooser *)voidafc;
791     ExpandedTextAttribute *	etaC= &(afc->afcTextAttributeChosen);
792     TextAttribute *		taC= &(etaC->etaTextAttribute);
793     int				set;
794 
795     set= appGuiGetToggleStateFromCallback( w, voidtbcs );
796 
797     if  ( ! set								&&
798 	  ! PROPmaskISSET( &(afc->afcChosenMask), TApropSUPERSUB ) )
799 	{ return;	}
800 
801     PROPmaskADD( &(afc->afcChosenMask), TApropSUPERSUB );
802 
803     if  ( set )
804 	{
805 	int		resetOther= 0;
806 
807 	if  ( taC->taSuperSub == TEXTvaSUBSCRIPT )
808 	    { resetOther= 1;	}
809 
810 	taC->taSuperSub= TEXTvaSUPERSCRIPT;
811 
812 	if  ( resetOther )
813 	    { appGuiSetToggleState( afc->afcSubscriptToggle, 0 );	}
814 	}
815     else{
816 	if  ( taC->taSuperSub == TEXTvaSUPERSCRIPT )
817 	    { taC->taSuperSub= TEXTvaREGULAR;	}
818 	}
819 
820     guiEnableWidget( afc->afcApplyButton,
821 			    ! utilPropMaskIsEmpty( &(afc->afcChosenMask) ) );
822 
823     return;
824     }
825 
APP_TOGGLE_CALLBACK_H(appFontSubscriptToggled,w,voidafc,voidtbcs)826 static APP_TOGGLE_CALLBACK_H( appFontSubscriptToggled, w, voidafc, voidtbcs )
827     {
828     AppFontChooser *		afc= (AppFontChooser *)voidafc;
829     ExpandedTextAttribute *	etaC= &(afc->afcTextAttributeChosen);
830     TextAttribute *		taC= &(etaC->etaTextAttribute);
831     int				set;
832 
833     set= appGuiGetToggleStateFromCallback( w, voidtbcs );
834 
835     if  ( ! set								&&
836 	  ! PROPmaskISSET( &(afc->afcChosenMask), TApropSUPERSUB )	)
837 	{ return;	}
838 
839     PROPmaskADD( &(afc->afcChosenMask), TApropSUPERSUB );
840 
841     if  ( set )
842 	{
843 	int		resetOther= 0;
844 
845 	if  ( taC->taSuperSub == TEXTvaSUPERSCRIPT )
846 	    { resetOther= 1;	}
847 
848 	taC->taSuperSub= TEXTvaSUBSCRIPT;
849 
850 	if  ( resetOther )
851 	    { appGuiSetToggleState( afc->afcSubscriptToggle, 0 );	}
852 	}
853     else{
854 	if  ( taC->taSuperSub == TEXTvaSUBSCRIPT )
855 	    { taC->taSuperSub= TEXTvaREGULAR;	}
856 	}
857 
858     guiEnableWidget( afc->afcApplyButton,
859 			    ! utilPropMaskIsEmpty( &(afc->afcChosenMask) ) );
860 
861     return;
862     }
863 
APP_TOGGLE_CALLBACK_H(appFontSmallcapsToggled,w,voidafc,voidtbcs)864 static APP_TOGGLE_CALLBACK_H( appFontSmallcapsToggled, w, voidafc, voidtbcs )
865     {
866     AppFontChooser *		afc= (AppFontChooser *)voidafc;
867     ExpandedTextAttribute *	etaC= &(afc->afcTextAttributeChosen);
868     TextAttribute *		taC= &(etaC->etaTextAttribute);
869     int				set;
870 
871     set= appGuiGetToggleStateFromCallback( w, voidtbcs );
872 
873     if  ( ! set								&&
874 	  ! PROPmaskISSET( &(afc->afcChosenMask), TApropSMALLCAPS )	)
875 	{ return;	}
876 
877     PROPmaskADD( &(afc->afcChosenMask), TApropSMALLCAPS );
878 
879     if  ( set )
880 	{
881 	int		resetOther= 0;
882 
883 	if  ( taC->taCapitals )
884 	    { resetOther= 1;	}
885 
886 	taC->taSmallCaps= 1;
887 
888 	if  ( resetOther )
889 	    {
890 	    taC->taCapitals= 0;
891 	    appGuiSetToggleState( afc->afcCapitalsToggle, taC->taCapitals );
892 	    PROPmaskADD( &(afc->afcChosenMask), TApropCAPITALS );
893 	    }
894 	}
895     else{
896 	taC->taSmallCaps= 0;
897 	}
898 
899     guiEnableWidget( afc->afcApplyButton,
900 			    ! utilPropMaskIsEmpty( &(afc->afcChosenMask) ) );
901 
902     return;
903     }
904 
APP_TOGGLE_CALLBACK_H(appFontCapitalsToggled,w,voidafc,voidtbcs)905 static APP_TOGGLE_CALLBACK_H( appFontCapitalsToggled, w, voidafc, voidtbcs )
906     {
907     AppFontChooser *		afc= (AppFontChooser *)voidafc;
908     ExpandedTextAttribute *	etaC= &(afc->afcTextAttributeChosen);
909     TextAttribute *		taC= &(etaC->etaTextAttribute);
910     int				set;
911 
912     set= appGuiGetToggleStateFromCallback( w, voidtbcs );
913 
914     if  ( ! set								&&
915 	  ! PROPmaskISSET( &(afc->afcChosenMask), TApropCAPITALS )	)
916 	{ return;	}
917 
918     PROPmaskADD( &(afc->afcChosenMask), TApropCAPITALS );
919 
920     if  ( set )
921 	{
922 	int		resetOther= 0;
923 
924 	if  ( taC->taSmallCaps )
925 	    { resetOther= 1;	}
926 
927 	taC->taCapitals= 1;
928 
929 	if  ( resetOther )
930 	    {
931 	    taC->taSmallCaps= 0;
932 	    appGuiSetToggleState( afc->afcSmallcapsToggle, taC->taSmallCaps );
933 	    PROPmaskADD( &(afc->afcChosenMask), TApropSMALLCAPS );
934 	    }
935 	}
936     else{
937 	taC->taCapitals= 0;
938 	}
939 
940     guiEnableWidget( afc->afcApplyButton,
941 			    ! utilPropMaskIsEmpty( &(afc->afcChosenMask) ) );
942 
943     return;
944     }
945 
946 /************************************************************************/
947 /*									*/
948 /*  A font family has been chosen					*/
949 /*									*/
950 /************************************************************************/
951 
APP_LIST_CALLBACK_H(appFontFamilyChosen,w,voidafc,voidlcs)952 static APP_LIST_CALLBACK_H( appFontFamilyChosen, w, voidafc, voidlcs )
953     {
954     AppFontChooser *		afc= (AppFontChooser *)voidafc;
955     ExpandedTextAttribute *	etaC= &(afc->afcTextAttributeChosen);
956     DocumentFontList *		dfl= &(afc->afcDocumentFontList);
957 
958     int				fontIndex;
959     int				changed= 0;
960 
961     const DocumentFont *	df;
962 
963     if  ( afc->afcInProgrammaticChange > 0 )
964 	{ return;	}
965 
966     fontIndex= appGuiGetPositionFromListCallback( w, voidlcs );
967     if  ( fontIndex < 0 || fontIndex >= dfl->dflFontCount )
968 	{ LLDEB(fontIndex,dfl->dflFontCount); return;	}
969 
970     df= utilDocumentFontListGetFontBySortIndex( dfl, fontIndex );
971     if  ( ! df )
972 	{ XDEB(df); return;	}
973 
974     if  ( docExpandedTextAttributeSetFontName( etaC, &changed, df->dfName ) )
975 	{ SDEB(df->dfName); return;	}
976 
977     if  ( ! PROPmaskISSET( &(afc->afcChosenMask), TApropFONT_NUMBER ) )
978 	{ changed= 1;	}
979 
980     afc->afcFontSortIndexChosen= fontIndex;
981     PROPmaskADD( &(afc->afcChosenMask), TApropFONT_NUMBER );
982 
983     if  ( afc->afcFaceChosen >= 0			&&
984 	  ! df->dfPsFontInfo[afc->afcFaceChosen]	)
985 	{
986 	int	faceChosen;
987 
988 	faceChosen= appFontToolFindExistingFace( etaC, df );
989 	if  ( faceChosen >= 0 )
990 	    { afc->afcFaceChosen= faceChosen;	}
991 	}
992 
993     if  ( changed )
994 	{
995 	afc->afcInProgrammaticChange++;
996 
997 	appFontReflectFamily( afc );
998 	appFontShowExampleOfCurrent( afc );
999 
1000 	afc->afcInProgrammaticChange--;
1001 	}
1002 
1003     return;
1004     }
1005 
1006 /************************************************************************/
1007 /*									*/
1008 /*  A font face has been chosen						*/
1009 /*									*/
1010 /************************************************************************/
1011 
APP_LIST_CALLBACK_H(appFontFaceChosen,w,voidafc,voidlcs)1012 static APP_LIST_CALLBACK_H( appFontFaceChosen, w, voidafc, voidlcs )
1013     {
1014     AppFontChooser *		afc= (AppFontChooser *)voidafc;
1015     ExpandedTextAttribute *	etaC= &(afc->afcTextAttributeChosen);
1016     TextAttribute *		taC= &(etaC->etaTextAttribute);
1017     PropertyMask *		chosenMask= &(afc->afcChosenMask);
1018 
1019     int				i;
1020 
1021     if  ( afc->afcInProgrammaticChange > 0 )
1022 	{ return;	}
1023 
1024     i= appGuiGetPositionFromListCallback( w, voidlcs );
1025     if  ( i == afc->afcFaceChosen )
1026 	{ return;	}
1027 
1028     if  ( i < 0 || i >= FONTface_COUNT )
1029 	{ LLDEB(i,FONTface_COUNT); return;	}
1030 
1031     afc->afcFaceChosen= afc->afcFaceMapFwd[i];
1032 
1033     taC->taFontIsBold= FACE_BOLD( afc->afcFaceChosen );
1034     taC->taFontIsSlanted= FACE_SLANTED( afc->afcFaceChosen );
1035 
1036     PROPmaskADD( chosenMask, TApropFONTBOLD );
1037     PROPmaskADD( chosenMask, TApropFONTSLANTED );
1038 
1039     appFontShowExampleOfCurrent( afc );
1040 
1041     return;
1042     }
1043 
1044 /************************************************************************/
1045 /*									*/
1046 /*  A font size has been chosen in the list widget.			*/
1047 /*									*/
1048 /************************************************************************/
1049 
APP_LIST_CALLBACK_H(appFontSizeChosen,w,voidafc,voidlcs)1050 static APP_LIST_CALLBACK_H( appFontSizeChosen, w, voidafc, voidlcs )
1051     {
1052     AppFontChooser *		afc= (AppFontChooser *)voidafc;
1053     ExpandedTextAttribute *	etaC= &(afc->afcTextAttributeChosen);
1054     TextAttribute *		taC= &(etaC->etaTextAttribute);
1055 
1056     int				i;
1057 
1058     if  ( afc->afcInProgrammaticChange > 0 )
1059 	{ return;	}
1060 
1061     i= appGuiGetPositionFromListCallback( w, voidlcs );
1062     if  ( i < 0 || i >= EditFontToolSizeCount )
1063 	{ LLDEB(i,EditFontToolSizeCount); return; }
1064 
1065     taC->taFontSizeHalfPoints= EditFontToolSizesHalfPoints[i];
1066     PROPmaskADD( &(afc->afcChosenMask), TApropFONTSIZE );
1067 
1068     appFontShowSizeInText( afc, taC->taFontSizeHalfPoints );
1069 
1070     appFontShowExampleOfCurrent( afc );
1071 
1072     return;
1073     }
1074 
1075 /************************************************************************/
1076 /*									*/
1077 /*  The user typed 'Enter' in the text box with the font size.		*/
1078 /*									*/
1079 /************************************************************************/
1080 
APP_TXACTIVATE_CALLBACK_H(appFontToolSizeChanged,w,voidafc)1081 static APP_TXACTIVATE_CALLBACK_H( appFontToolSizeChanged, w, voidafc )
1082     {
1083     AppFontChooser *		afc= (AppFontChooser *)voidafc;
1084     ExpandedTextAttribute *	etaC= &(afc->afcTextAttributeChosen);
1085     TextAttribute *		taC= &(etaC->etaTextAttribute);
1086 
1087     const int			anyway= 0;
1088     int				sizeHalfPoints;
1089 
1090     if  ( appFontToolGetSize( &sizeHalfPoints, anyway, afc ) )
1091 	{ return;	}
1092 
1093     if  ( sizeHalfPoints > 0 )
1094 	{
1095 	taC->taFontSizeHalfPoints= sizeHalfPoints;
1096 	PROPmaskADD( &(afc->afcChosenMask), TApropFONTSIZE );
1097 	}
1098     else{
1099 	PROPmaskUNSET( &(afc->afcChosenMask), TApropFONTSIZE );
1100 	}
1101 
1102     appFontShowExampleOfCurrent( afc );
1103 
1104     return;
1105     }
1106 
1107 /************************************************************************/
1108 /*									*/
1109 /*  The contents of the font size text box changed: Select the new	*/
1110 /*  value in the list.							*/
1111 /*									*/
1112 /************************************************************************/
1113 
APP_TXTYPING_CALLBACK_H(appFontToolSizeTyped,w,voidafc)1114 static APP_TXTYPING_CALLBACK_H( appFontToolSizeTyped, w, voidafc )
1115     {
1116     AppFontChooser *		afc= (AppFontChooser *)voidafc;
1117     ExpandedTextAttribute *	etaC= &(afc->afcTextAttributeChosen);
1118     TextAttribute *		taC= &(etaC->etaTextAttribute);
1119 
1120     int				fontSizeHalfPoints= -1;
1121     int				fontSizeTwips= -1;
1122 
1123     char *			s;
1124 
1125     s= appGetStringFromTextWidget( afc->afcSizeText );
1126 
1127     if  ( ! geoLengthFromString( s, UNITtyPOINTS, &fontSizeTwips ) )
1128 	{
1129 	fontSizeHalfPoints= ( fontSizeTwips+ 5 )/ 10;
1130 	PROPmaskADD( &(afc->afcChosenMask), TApropFONTSIZE );
1131 	}
1132     else{
1133 	PROPmaskUNSET( &(afc->afcChosenMask), TApropFONTSIZE );
1134 	}
1135 
1136     appFreeStringFromTextWidget( s );
1137 
1138     if  ( taC->taFontSizeHalfPoints != fontSizeHalfPoints )
1139 	{ appFontShowSizeInList( afc, fontSizeHalfPoints );	}
1140 
1141     return;
1142     }
1143 
1144 /************************************************************************/
1145 /*									*/
1146 /*  Cleanup of the Font Chooser.					*/
1147 /*									*/
1148 /************************************************************************/
1149 
appFontChooserCleanPage(AppFontChooser * afc)1150 void appFontChooserCleanPage( AppFontChooser *	afc )
1151     {
1152     docCleanExpandedTextAttribute( &(afc->afcTextAttributeSet) );
1153     docCleanExpandedTextAttribute( &(afc->afcTextAttributeChosen) );
1154 
1155     docCleanFontList( &(afc->afcDocumentFontList) );
1156 
1157     if  ( afc->afcDrawingSurface )
1158 	{ drawFreeDrawingSurface( afc->afcDrawingSurface );	}
1159 
1160     return;
1161     }
1162 
1163 /************************************************************************/
1164 /*									*/
1165 /*  make the font chooser form with three listboxes.			*/
1166 /*									*/
1167 /************************************************************************/
1168 
appFontMakeChooseForm(APP_WIDGET parent,const AppFontToolResources * aftr,AppFontChooser * afc)1169 static void appFontMakeChooseForm(	APP_WIDGET			parent,
1170 					const AppFontToolResources *	aftr,
1171 					AppFontChooser *		afc )
1172     {
1173     const int		heightResizable= 1;
1174 
1175     const int		familyPosition= 0;
1176     const int		familyColspan= 5;
1177     const int		facePosition= familyPosition+ familyColspan;
1178     const int		faceColspan= 3;
1179     const int		sizePosition= facePosition+ faceColspan;
1180     const int		sizeColspan= 2;
1181     const int		colcount= sizePosition+ sizeColspan;
1182 
1183     const int		listHeight= 6;
1184 
1185     afc->afcChooseRow= appMakeRowInColumn( parent, colcount, heightResizable );
1186 
1187     /********************************************************************/
1188     /*									*/
1189     /*  Parents with listbox and label:					*/
1190     /*									*/
1191     /********************************************************************/
1192 
1193     appMakeColumnInRow( &(afc->afcFamilyColumn), afc->afcChooseRow,
1194 				familyPosition, familyColspan );
1195 
1196     appMakeLabelInColumn( &(afc->afcFamilyLabel),
1197 				afc->afcFamilyColumn, aftr->aftrFamily );
1198 
1199     appGuiMakeListInColumn( &(afc->afcFamilyList),
1200 		afc->afcFamilyColumn, listHeight,
1201 		appFontFamilyChosen, (APP_BUTTON_CALLBACK_T)0, (void *)afc );
1202 
1203     /***/
1204 
1205     appMakeColumnInRow( &(afc->afcFaceColumn), afc->afcChooseRow,
1206 						facePosition, faceColspan );
1207 
1208     appMakeLabelInColumn( &(afc->afcFaceLabel),
1209 					afc->afcFaceColumn, aftr->aftrFace );
1210 
1211     appGuiMakeListInColumn( &(afc->afcFaceList), afc->afcFaceColumn, listHeight,
1212 		appFontFaceChosen, (APP_BUTTON_CALLBACK_T)0, (void *)afc );
1213 
1214     {
1215     const int		textColumns= 4;
1216     const int		textEnabled= 1;
1217 
1218     appMakeColumnInRow( &(afc->afcSizeColumn), afc->afcChooseRow,
1219 						sizePosition, sizeColspan );
1220 
1221     appMakeLabelInColumn( &(afc->afcSizeLabel), afc->afcSizeColumn,
1222 							    aftr->aftrSize );
1223 
1224     appGuiMakeListInColumn( &(afc->afcSizeList), afc->afcSizeColumn, 0,
1225 		appFontSizeChosen, (APP_BUTTON_CALLBACK_T)0, (void *)afc );
1226 
1227     appMakeTextInColumn( &(afc->afcSizeText), afc->afcSizeColumn,
1228 						textColumns, textEnabled );
1229 
1230     appGuiSetGotValueCallbackForText( afc->afcSizeText,
1231 					appFontToolSizeChanged, (void *)afc );
1232 
1233     appGuiSetTypingCallbackForText( afc->afcSizeText,
1234 					appFontToolSizeTyped, (void *)afc );
1235     }
1236 
1237     return;
1238     }
1239 
1240 /************************************************************************/
1241 /*									*/
1242 /*  make the label to preview the font.					*/
1243 /*									*/
1244 /************************************************************************/
1245 
appFontMakePreviewDrawing(APP_WIDGET parent,AppFontChooser * afc,int twipsSize)1246 static void appFontMakePreviewDrawing(	APP_WIDGET		parent,
1247 					AppFontChooser *	afc,
1248 					int			twipsSize )
1249     {
1250     const int		wide= -1;
1251     int			high= 1.15* ( afc->afcPixelsPerTwip* twipsSize )+ 0.5;
1252     const int		heightResizable= 0;
1253 
1254     appGuiMakeDrawingAreaInColumn( &(afc->afcSampleDrawing), parent,
1255 		    wide, high, heightResizable, appFontRedraw, (void *)afc );
1256 
1257 
1258     appMakeLabelInColumn( &(afc->afcScreenName), parent, "?" );
1259     appMakeLabelInColumn( &(afc->afcPsName), parent, "?" );
1260 
1261     return;
1262     }
1263 
1264 /************************************************************************/
1265 /*									*/
1266 /*  The set button of a font tool has been pushed.			*/
1267 /*									*/
1268 /************************************************************************/
1269 
APP_BUTTON_CALLBACK_H(appFontSetPushed,w,voidafc)1270 static APP_BUTTON_CALLBACK_H( appFontSetPushed, w, voidafc )
1271     {
1272     AppFontChooser *		afc= (AppFontChooser *)voidafc;
1273     ExpandedTextAttribute *	etaC= &(afc->afcTextAttributeChosen);
1274     TextAttribute *		taC= &(etaC->etaTextAttribute);
1275 
1276     int				sizeHalfPoints;
1277     int				baselineHalfPoints;
1278     int				empty= 1;
1279     const int			anyway= 1;
1280 
1281     if  ( ! afc->afcSetFont )
1282 	{ XDEB(afc->afcSetFont); return;	}
1283 
1284     /**/
1285     if  ( appFontToolGetSize( &sizeHalfPoints, anyway, afc ) )
1286 	{ return;	}
1287 
1288     if  ( sizeHalfPoints < 0 )
1289 	{ PROPmaskUNSET( &(afc->afcChosenMask), TApropFONTSIZE );	}
1290     else{
1291 	PROPmaskADD( &(afc->afcChosenMask), TApropFONTSIZE );
1292 	taC->taFontSizeHalfPoints= sizeHalfPoints;
1293 	}
1294 
1295     /**/
1296     if  ( appFontToolGetBaseline( &baselineHalfPoints, &empty, anyway, afc ) )
1297 	{ return;	}
1298 
1299     if  ( empty )
1300 	{ PROPmaskUNSET( &(afc->afcChosenMask), TApropBASELINE_SHIFT ); }
1301     else{
1302 	taC->taBaselineShiftHalfPoints= baselineHalfPoints;
1303 	PROPmaskADD( &(afc->afcChosenMask), TApropBASELINE_SHIFT );
1304 	}
1305 
1306     /**/
1307     (*afc->afcSetFont)( afc->afcApplication, &(afc->afcChosenMask), etaC );
1308 
1309     return;
1310     }
1311 
1312 /************************************************************************/
1313 /*									*/
1314 /*  The 'Revert' button of a font tool has been pushed.			*/
1315 /*									*/
1316 /************************************************************************/
1317 
APP_BUTTON_CALLBACK_H(appFontRevertPushed,w,voidafc)1318 static APP_BUTTON_CALLBACK_H( appFontRevertPushed, w, voidafc )
1319     {
1320     AppFontChooser *		afc= (AppFontChooser *)voidafc;
1321 
1322     docCopyExpandedTextAttribute( &(afc->afcTextAttributeChosen),
1323 					    &(afc->afcTextAttributeSet) );
1324 
1325     afc->afcChosenMask= afc->afcSetMask;
1326 
1327     afc->afcInProgrammaticChange++;
1328     appFontReflectProperties( afc );
1329     afc->afcInProgrammaticChange--;
1330 
1331     return;
1332     }
1333 
1334 /************************************************************************/
1335 /*									*/
1336 /*  Reflect/Remember the current font of the application.		*/
1337 /*									*/
1338 /*  1)  Adapt the old fashioned internals to new style interface.	*/
1339 /*									*/
1340 /************************************************************************/
1341 
appFontToolSetCurrentFont(AppFontChooser * afc,const PropertyMask * newMask,const ExpandedTextAttribute * etaNew)1342 static int appFontToolSetCurrentFont(
1343 				AppFontChooser *		afc,
1344 				const PropertyMask *		newMask,
1345 				const ExpandedTextAttribute *	etaNew )
1346     {
1347     ExpandedTextAttribute *	etaS= &(afc->afcTextAttributeSet);
1348     ExpandedTextAttribute *	etaC= &(afc->afcTextAttributeChosen);
1349 
1350     PropertyMask		doneMask;
1351 
1352     docCleanExpandedTextAttribute( etaS );
1353     docInitExpandedTextAttribute( etaS );
1354 
1355     afc->afcFontSortIndexChosen= -1;
1356     afc->afcFaceChosen= -1;
1357 
1358     utilPropMaskClear( &doneMask );
1359     docUpdateExpandedTextAttribute( &doneMask, etaS, etaNew, newMask );
1360     docCopyExpandedTextAttribute( etaC, etaS );
1361 
1362     afc->afcSetMask= *newMask;
1363     afc->afcChosenMask= afc->afcSetMask;
1364 
1365     afc->afcInProgrammaticChange++;
1366     appFontReflectProperties( afc );
1367     afc->afcInProgrammaticChange--;
1368 
1369     return 0;
1370     }
1371 
appFontToolShowCurrentFont(AppFontChooser * afc,const PropertyMask * newMask,const TextAttribute * taNew,unsigned int documentId,int canChange,const DocumentFontList * dfl,const ColorPalette * cp)1372 int appFontToolShowCurrentFont(	AppFontChooser *		afc,
1373 				const PropertyMask *		newMask,
1374 				const TextAttribute *		taNew,
1375 				unsigned int			documentId,
1376 				int				canChange,
1377 				const DocumentFontList *	dfl,
1378 				const ColorPalette *		cp )
1379     {
1380     int				rval= 0;
1381     DocumentFontList *		dflTo= &(afc->afcDocumentFontList);
1382 
1383     PropertyMask		doneMask;
1384     ExpandedTextAttribute	eta;
1385 
1386     docInitExpandedTextAttribute( &eta );
1387     utilPropMaskClear( &doneMask );
1388 
1389     afc->afcInProgrammaticChange++;
1390 
1391     if  ( afc->afcCurrentDocumentId != documentId )
1392 	{
1393 	int				i;
1394 
1395 	if  ( docCopyFontList( dflTo, dfl ) )
1396 	    { LDEB(1); rval= -1; goto ready; }
1397 
1398 	appGuiRemoveSelectionFromListWidget( afc->afcFamilyList );
1399 	appGuiEmptyListWidget( afc->afcFamilyList );
1400 
1401 	for ( i= 0; i < dflTo->dflFontCount; i++ )
1402 	    {
1403 	    const DocumentFont *	df;
1404 
1405 	    df= utilDocumentFontListGetFontBySortIndex( dflTo, i );
1406 	    if  ( ! df )
1407 		{ XDEB(df); continue;	}
1408 
1409 	    appGuiAddValueToListWidget( afc->afcFamilyList, -1, df->dfName );
1410 	    }
1411 
1412 	afc->afcFontSortIndexChosen= -1;
1413 	afc->afcFaceChosen= -1;
1414 
1415 	afc->afcCurrentDocumentId= documentId;
1416 	}
1417 
1418     docExpandTextAttribute( &doneMask, &eta, taNew, newMask, dflTo, cp );
1419 
1420     if  ( appFontToolSetCurrentFont( afc, newMask, &eta ) )
1421 	{ LDEB(1);	}
1422 
1423     afc->afcCanChange= canChange;
1424 
1425     guiEnableWidget( afc->afcChooseRow, afc->afcCanChange );
1426     guiEnableWidget( afc->afcToggleRow1, afc->afcCanChange );
1427     guiEnableWidget( afc->afcToggleRow2, afc->afcCanChange );
1428     guiEnableWidget( afc->afcApplyRow, afc->afcCanChange );
1429     guiEnableWidget( afc->afcBaselineRow, afc->afcCanChange );
1430     guiEnableText( afc->afcBaselineText, afc->afcCanChange );
1431     guiEnableText( afc->afcSizeText, afc->afcCanChange );
1432 
1433   ready:
1434 
1435     docCleanExpandedTextAttribute( &eta );
1436 
1437     afc->afcInProgrammaticChange--;
1438 
1439     return rval;
1440     }
1441 
1442 /************************************************************************/
1443 /*									*/
1444 /*  make a fonts tool.							*/
1445 /*									*/
1446 /************************************************************************/
1447 
appFontToolFillPage(AppFontChooser * afc,const AppFontToolResources * aftr,int subjectPage,InspectorSubject * is,APP_WIDGET pageWidget,const InspectorSubjectResources * isr)1448 void appFontToolFillPage(	AppFontChooser *		afc,
1449 				const AppFontToolResources *	aftr,
1450 				int				subjectPage,
1451 				InspectorSubject *		is,
1452 				APP_WIDGET			pageWidget,
1453 				const InspectorSubjectResources * isr )
1454     {
1455     int				i;
1456     int				pos;
1457     APP_WIDGET			sep;
1458 
1459     EditApplication *		ea= afc->afcApplication;
1460 
1461     afc->afcPixelsPerTwip= 0;
1462     afc->afcDrawingSurface= (DrawingSurface)0;
1463 
1464     afc->afcPostScriptFontList= &(ea->eaPostScriptFontList);
1465 
1466     afc->afcInProgrammaticChange= 0;
1467     afc->afcFamilyList= (APP_WIDGET)0;
1468     afc->afcFaceList= (APP_WIDGET)0;
1469     afc->afcSizeList= (APP_WIDGET)0;
1470     afc->afcSizeText= (APP_WIDGET)0;
1471 
1472     afc->afcScreenFont= -1;
1473     afc->afcChoiceText[0]= '\0';
1474     afc->afcScreenChoiceText[0]= '\0';
1475 
1476     afc->afcSetFont= (FontChooserSetFont)0;
1477     afc->afcSubjectPage= subjectPage;
1478     afc->afcResources= *aftr;
1479 
1480     is->isPrivate= (void *)afc;
1481 
1482     for ( i= 0; i < FONTface_COUNT; i++ )
1483 	{
1484 	afc->afcFaceMapFwd[i]= -1;
1485 	afc->afcFaceMapBck[i]= -1;
1486 	}
1487 
1488     afc->afcPixelsPerTwip= ea->eaMagnification* ea->eaPixelsPerTwip;
1489 
1490     {
1491     const int			textColumns= 10;
1492     const int			twipsSize= 20* 48;
1493 
1494     appFontMakePreviewDrawing( pageWidget, afc, twipsSize );
1495 
1496     appGuiInsertSeparatorInColumn( &sep, pageWidget );
1497 
1498     appFontMakeChooseForm( pageWidget, aftr, afc );
1499 
1500     appGuiInsertSeparatorInColumn( &sep, pageWidget );
1501 
1502     guiToolMake3ToggleRow( &(afc->afcToggleRow1), pageWidget,
1503 					&(afc->afcUnderlinedToggle),
1504 					&(afc->afcSuperscriptToggle),
1505 					&(afc->afcSmallcapsToggle),
1506 
1507 					aftr->aftrTextUnderlined,
1508 					aftr->aftrSuperscript,
1509 					aftr->aftrSmallcaps,
1510 
1511 					appFontUnderlinedToggled,
1512 					appFontSuperscriptToggled,
1513 					appFontSmallcapsToggled,
1514 					(void *)afc );
1515 
1516     guiToolMake3ToggleRow( &(afc->afcToggleRow2), pageWidget,
1517 					&(afc->afcStrikethroughToggle),
1518 					&(afc->afcSubscriptToggle),
1519 					&(afc->afcCapitalsToggle),
1520 
1521 					aftr->aftrTextStrikethrough,
1522 					aftr->aftrSubscript,
1523 					aftr->aftrCapitals,
1524 
1525 					appFontStrikethroughToggled,
1526 					appFontSubscriptToggled,
1527 					appFontCapitalsToggled,
1528 					(void *)afc );
1529 
1530     guiToolMakeLabelAndTextRow( &(afc->afcBaselineRow),
1531 					&(afc->afcBaselineLabel),
1532 					&(afc->afcBaselineText), pageWidget,
1533 					aftr->aftrBaseline, textColumns, 1 );
1534 
1535     /**/
1536 
1537     appGuiInsertSeparatorInColumn( &sep, pageWidget );
1538 
1539     guiToolMake2BottonRow( &(is->isApplyRow), pageWidget,
1540 			&(is->isRevertButton), &(is->isApplyButton),
1541 			isr->isrRevert, isr->isrApplyToSubject,
1542 			appFontRevertPushed, appFontSetPushed, afc );
1543 
1544     afc->afcApplyRow= is->isApplyRow;
1545     afc->afcRevertButton= is->isRevertButton;
1546     afc->afcApplyButton= is->isApplyButton;
1547     }
1548 
1549     docInitExpandedTextAttribute( &(afc->afcTextAttributeSet) );
1550     docInitExpandedTextAttribute( &(afc->afcTextAttributeChosen) );
1551 
1552     docInitFontList( &(afc->afcDocumentFontList) );
1553     afc->afcCurrentDocumentId= 0;
1554 
1555     utilPropMaskClear( &(afc->afcChosenMask) );
1556     utilPropMaskClear( &(afc->afcSetMask) );
1557 
1558     afc->afcFontSortIndexChosen= -2;
1559     afc->afcFaceChosen= -2;
1560 
1561     /**/
1562     appGuiEmptyListWidget( afc->afcSizeList );
1563 
1564     for ( pos= 0; pos < EditFontToolSizeCount; pos++ )
1565 	{
1566 	char	scratch[80];
1567 
1568 	appFontToolFormatSize( scratch, EditFontToolSizesHalfPoints[pos] );
1569 
1570 	appGuiAddValueToListWidget( afc->afcSizeList, -1, scratch );
1571 	}
1572     /**/
1573 
1574     return;
1575     }
1576 
1577 /************************************************************************/
1578 /*									*/
1579 /*  Final stages in making the font tool.				*/
1580 /*									*/
1581 /************************************************************************/
1582 
appFontToolFillChoosers(AppFontChooser * afc,const AppFontToolResources * aftr)1583 void appFontToolFillChoosers(	AppFontChooser *		afc,
1584 				const AppFontToolResources *	aftr )
1585     {
1586     return;
1587     }
1588 
appFontToolFinishPage(AppFontChooser * afc,const AppFontToolResources * aftr)1589 void appFontToolFinishPage(	AppFontChooser *		afc,
1590 				const AppFontToolResources *	aftr )
1591     {
1592     afc->afcDrawingSurface= guiDrawingSurfaceForNativeWidget(
1593 			    afc->afcSampleDrawing,
1594 			    afc->afcPostScriptFontList->psflAvoidFontconfig );
1595 
1596     return;
1597     }
1598 
1599 /************************************************************************/
1600 /*									*/
1601 /*  Resources.								*/
1602 /*									*/
1603 /************************************************************************/
1604 
1605 static AppConfigurableResource APP_FontToolResourceTable[]=
1606     {
1607     APP_RESOURCE( "fontToolFamily",
1608 		offsetof(AppFontToolResources,aftrFamily),
1609 		"Family" ),
1610     APP_RESOURCE( "fontToolFace",
1611 		offsetof(AppFontToolResources,aftrFace),
1612 		"Typeface" ),
1613     APP_RESOURCE( "fontToolSize",
1614 		offsetof(AppFontToolResources,aftrSize),
1615 		"Size" ),
1616 
1617     APP_RESOURCE( "fontToolRegular",
1618 		offsetof(AppFontToolResources,aftrFaces[FONTfaceREGULAR]),
1619 		"Regular" ),
1620     APP_RESOURCE( "fontToolBold",
1621 		offsetof(AppFontToolResources,aftrFaces[FONTfaceBOLD]),
1622 		"Bold" ),
1623     APP_RESOURCE( "fontToolSlanted",
1624 		offsetof(AppFontToolResources,aftrFaces[FONTfaceSLANTED]),
1625 		"Italic" ),
1626     APP_RESOURCE( "fontToolBoldSlanted",
1627 		offsetof(AppFontToolResources,aftrFaces[FONTfaceBOLD_SLANTED]),
1628 		"Bold Italic" ),
1629 
1630     APP_RESOURCE( "fontToolTextUnderlined",
1631 		offsetof(AppFontToolResources,aftrTextUnderlined),
1632 		"Underlined" ),
1633     APP_RESOURCE( "fontToolTextStrikethrough",
1634 		offsetof(AppFontToolResources,aftrTextStrikethrough),
1635 		"Strikethrough" ),
1636 
1637     APP_RESOURCE( "fontToolSuperscript",
1638 		offsetof(AppFontToolResources,aftrSuperscript),
1639 		"Superscript" ),
1640     APP_RESOURCE( "fontToolSubscript",
1641 		offsetof(AppFontToolResources,aftrSubscript),
1642 		"Subscript" ),
1643 
1644     APP_RESOURCE( "fontToolSmallcaps",
1645 		offsetof(AppFontToolResources,aftrSmallcaps),
1646 		"Small caps" ),
1647     APP_RESOURCE( "fontToolCapitals",
1648 		offsetof(AppFontToolResources,aftrCapitals),
1649 		"All caps" ),
1650 
1651     APP_RESOURCE( "fontToolBaseline",
1652 		offsetof(AppFontToolResources,aftrBaseline),
1653 		"Raise" ),
1654     };
1655 
appFontToolGetResourceTable(EditApplication * ea,AppFontToolResources * aftr)1656 void appFontToolGetResourceTable(	EditApplication *		ea,
1657 					AppFontToolResources *		aftr )
1658     {
1659     static int	gotResources= 0;
1660 
1661     if  ( ! gotResources )
1662 	{
1663 	appGuiGetResourceValues( &gotResources, ea, (void *)aftr,
1664 				APP_FontToolResourceTable,
1665 				sizeof(APP_FontToolResourceTable)/
1666 				sizeof(AppConfigurableResource) );
1667 	}
1668 
1669     return;
1670     }
1671