File: tedAppFont.c

package info (click to toggle)
ted 2.11-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 11,064 kB
  • ctags: 13,935
  • sloc: ansic: 120,446; makefile: 7,469; sh: 253
file content (589 lines) | stat: -rw-r--r-- 15,468 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
/************************************************************************/
/*									*/
/*  Ted: Changing font and text attributes.				*/
/*									*/
/************************************************************************/

#   include	"tedConfig.h"

#   include	<stddef.h>
#   include	<stdlib.h>
#   include	<stdio.h>
#   include	<ctype.h>

#   include	"tedApp.h"
#   include	<appFontTool.h>
#   include	<appSymbolPicker.h>

#   include	<appDebugon.h>

/************************************************************************/
/*									*/
/*  Change to font attributes of the current selection.			*/
/*									*/
/************************************************************************/

static void tedSetCurrentAttribute(	TedDocument *		td,
					AppDrawingData *	add,
					const PropertyMask *	updMask,
					TextAttribute		taNew )
    {
    BufferDocument *		bd= td->tdDocument;
    DocumentProperties *	dp= &(bd->bdProperties);
    DocumentFontList *		dfl= &(dp->dpFontList);

    PropertyMask		changeMask;

    PROPmaskCLEAR( &changeMask );

    docUpdateTextAttribute( &changeMask,
			    &(td->tdCurrentTextAttribute), taNew, updMask );

    if  ( ! PROPmaskISEMPTY( &changeMask )	||
	  td->tdCurrentPhysicalFont < 0		)
	{
	td->tdCurrentPhysicalFont= appOpenDocumentFont( add, dfl,
						td->tdCurrentTextAttribute );
	}

    return;
    }

static void tedAppChangeSelectionAttribute(
					EditDocument *		ed,
					const PropertyMask *	taUpdMask,
					TextAttribute		taNew )
    {
    AppDrawingData *		add= &(ed->edDrawingData);
    TedDocument *		td= (TedDocument *)ed->edPrivateData;

    PropertyMask		ppUpdMask;
    PropertyMask		spUpdMask;

    PROPmaskCLEAR( &ppUpdMask );
    PROPmaskCLEAR( &spUpdMask );

    tedSetCurrentAttribute( td, add, taUpdMask, taNew );

    tedChangeSelectionProperties( ed,
			    taUpdMask, taNew,
			    &ppUpdMask, (const ParagraphProperties *)0,
			    &spUpdMask, (const SectionProperties *)0 );

    return;
    }

/************************************************************************/
/*									*/
/*  Adapt fonts tool to the current document.				*/
/*									*/
/************************************************************************/

void tedAdaptFontsToolToDocument(	EditApplication *	ea,
					EditDocument *		ed )
    {
    TedDocument *	td= (TedDocument *)ed->edPrivateData;
    AppDrawingData *	add= &(ed->edDrawingData);

    const char *	familyName= (char *)0;
    int			psFamilyNumber= -1;
    int			enc= -1;

    PropertyMask	updMask;
    TextAttribute	taNew;

    PROPmaskCLEAR( &updMask );

    if  ( tedGetDocumentAttributes( td, &familyName, &psFamilyNumber, &enc,
							&updMask, &taNew ) )
	{ return;	}

    appFontSetCurrentFont( ea->eaFontsTool, add->addMagnifiedPixelsPerTwip,
					psFamilyNumber, enc, &updMask, taNew );

    if  ( ea->eaSymbolPicker )
	{
	if  ( appAdaptSymbolPickerToFontFamily( ea->eaSymbolPicker,
						psFamilyNumber, enc ) )
	    { LLDEB(psFamilyNumber,enc);	}
	}

    appFontToolTextReadonly( ea->eaFontsTool, ed->edIsReadonly );

    return;
    }

/************************************************************************/
/*									*/
/*  1)  Adapt fonts tool &c to the current values.			*/
/*  2)  Adapt fonts tool &c to the current selection.			*/
/*									*/
/************************************************************************/

/*  1  */
static void tedAdaptFontIndicatorsToValues(
					EditDocument *		ed,
					int			psFamilyNumber,
					int			enc,
					const PropertyMask *	updMask,
					TextAttribute		taNew )
    {
    EditApplication *	ea= ed->edApplication;
    AppDrawingData *	add= &(ed->edDrawingData);
    TedDocument *	td= (TedDocument *)ed->edPrivateData;

    if  ( ea->eaFontsTool )
	{
	appFontSetCurrentFont( ea->eaFontsTool, add->addMagnifiedPixelsPerTwip,
					psFamilyNumber, enc, updMask, taNew );
	}

    if  ( ea->eaSymbolPicker )
	{
	if  ( appAdaptSymbolPickerToFontFamily( ea->eaSymbolPicker,
						psFamilyNumber, enc ) )
	    { LLDEB(psFamilyNumber,enc);	}
	}

    appGuiSetToggleItemState( td->tdFontBoldOption,
				PROPmaskISSET( updMask, TApropFONTBOLD ) &&
				taNew.taFontIsBold );

    appGuiSetToggleItemState( td->tdFontItalicOption,
				PROPmaskISSET( updMask, TApropFONTSLANTED ) &&
				taNew.taFontIsSlanted );

    appGuiSetToggleItemState( td->tdFontUnderlinedOption,
				PROPmaskISSET( updMask, TApropTEXTUNDERLINED )
				&& taNew.taIsUnderlined );

    appGuiSetToggleItemState( td->tdFontSuperscriptOption,
				PROPmaskISSET( updMask, TApropSUPERSUB ) &&
				taNew.taSuperSub == DOCfontSUPERSCRIPT );

    appGuiSetToggleItemState( td->tdFontSubscriptOption,
				PROPmaskISSET( updMask, TApropSUPERSUB ) &&
				taNew.taSuperSub == DOCfontSUBSCRIPT );

    return;
    }

/*  2  */
void tedAdaptFontIndicatorsToSelection(	EditApplication *	ea,
					EditDocument *		ed )
    {
    TedDocument *	td= (TedDocument *)ed->edPrivateData;

    const char *	familyName= (char *)0;
    int			psFamilyNumber= -1;
    int			enc= -1;

    PropertyMask	updMask;
    TextAttribute	taNew;

    PROPmaskCLEAR( &updMask );

    if  ( tedGetDocumentAttributes( td, &familyName, &psFamilyNumber, &enc,
							&updMask, &taNew ) )
	{ return;	}

    tedAdaptFontIndicatorsToValues( ed, psFamilyNumber, enc, &updMask, taNew );

    return;
    }


/************************************************************************/
/*									*/
/*  One of the text attribute options has been pushed.			*/
/*									*/
/************************************************************************/

static void tedTextAttributePushed(	APP_WIDGET	attributeOption,
					void *		voided,
					void *		voidcbs,
					int		prop )
    {
    EditDocument *	ed= (EditDocument *)voided;
    EditApplication *	ea= ed->edApplication;
    int			set;
    TextAttribute	taNew;

    PropertyMask	updMask;

    PROPmaskCLEAR( &updMask );
    docInitTextAttribute( &taNew );

    set= appGuiGetMenuToggleStateFromCallback( attributeOption, voidcbs );

    switch( prop )
	{
	case TApropFONTBOLD:
	    taNew.taFontIsBold= ( set != 0 );
	    PROPmaskADD( &updMask, prop );
	    break;
	case TApropFONTSLANTED:
	    taNew.taFontIsSlanted= ( set != 0 );
	    PROPmaskADD( &updMask, prop );
	    break;
	case TApropTEXTUNDERLINED:
	    taNew.taIsUnderlined= ( set != 0 );
	    PROPmaskADD( &updMask, prop );
	    break;
	default:
	    LDEB(prop);
	    return;
	}

    tedAppChangeSelectionAttribute( ed, &updMask, taNew );

    if  ( ea->eaFontsTool )
	{ tedAdaptFontsToolToDocument( ea, ed );	}

    return;
    }

int tedAppChangeSelectionAttributeString(	EditDocument *	ed,
						char *		attrString )
    {
    char *		familyName;

    TextAttribute	taNew;
    PropertyMask	updMask;

    EditApplication *	ea= ed->edApplication;

    if  ( appFontGetAttributes( attrString, &familyName, &updMask, &taNew ) )
	{ SDEB( attrString ); return -1;	}

    if  ( PROPmaskISSET( &updMask, TApropFONTFAMILY ) )
	{
	TedDocument *		td= (TedDocument *)ed->edPrivateData;
	BufferDocument *	bd= td->tdDocument;
	DocumentProperties *	dp= &(bd->bdProperties);
	DocumentFontList *	dfl= &(dp->dpFontList);

	taNew.taFontNumber= docGetFontByName( dfl, familyName, -1, 0 );
	if  ( taNew.taFontNumber < 0 )
	    { SLDEB(familyName,taNew.taFontNumber); return -1;	}
	}

    tedAppChangeSelectionAttribute( ed, &updMask, taNew );

    tedAdaptFontIndicatorsToSelection( ea, ed );

    return 0;
    }

void tedDocFontBold(		APP_WIDGET	option,
				void *		voided,
				void *		voidcbs	 )
    { tedTextAttributePushed( option, voided, voidcbs, TApropFONTBOLD ); }

void tedDocFontItalic(	APP_WIDGET	option,
			void *		voided,
			void *		voidcbs	 )
    {
    tedTextAttributePushed( option, voided, voidcbs, TApropFONTSLANTED );
    }

void tedDocFontUnderlined(	APP_WIDGET	option,
				void *		voided,
				void *		voidcbs	 )
    {
    tedTextAttributePushed( option, voided, voidcbs, TApropTEXTUNDERLINED );
    }

void tedDocFontSupersub(	APP_WIDGET		option,
				void *			voided,
				void *			voidcbs	 )
    {
    EditDocument *	ed= (EditDocument *)voided;
    TedDocument *	td= (TedDocument *)ed->edPrivateData;

    PropertyMask	updMask;
    TextAttribute	taNew;
    int			set;

    PROPmaskCLEAR( &updMask );
    PROPmaskADD( &updMask, TApropSUPERSUB );

    docInitTextAttribute( &taNew );

    set= appGuiGetToggleStateFromCallback( option, voidcbs );

    if  ( set )
	{
	if  ( option == td->tdFontSubscriptOption )
	    { taNew.taSuperSub= DOCfontSUBSCRIPT;	}

	if  ( option == td->tdFontSuperscriptOption )
	    { taNew.taSuperSub= DOCfontSUPERSCRIPT;	}
	}
    else{ taNew.taSuperSub= DOCfontREGULAR;	}

    tedAppChangeSelectionAttribute( ed, &updMask, taNew );

    appGuiSetToggleState( td->tdFontSuperscriptOption,
				PROPmaskISSET( &updMask, TApropSUPERSUB ) &&
				taNew.taSuperSub == DOCfontSUPERSCRIPT );

    appGuiSetToggleState( td->tdFontSubscriptOption,
				PROPmaskISSET( &updMask, TApropSUPERSUB ) &&
				taNew.taSuperSub == DOCfontSUBSCRIPT );

    return;
    }

/************************************************************************/
/*									*/
/*  Ted, cope with the fonts tool.					*/
/*									*/
/************************************************************************/

static void tedFontsToolClosed(		void *		voidea	)
    {
    EditApplication *	ea=	(EditApplication *)voidea;

    ea->eaFontsTool= (void *)0;
    }

static void tedFontToolSet(		void *		voidea,
					const char *	familyName,
					int		psFamilyNumber,
					int		enc,
					int		encodingIsDefault,
					int		fontBold,
					int		fontSlanted,
					int		fontSizeHalfPoints )
    {
    EditApplication *	ea= (EditApplication *)voidea;
    EditDocument *	ed= ea->eaCurrentDocument;
    TedDocument *	td;

    PropertyMask	updMask;
    TextAttribute	taNew;

    if  ( ! ed )
	{ XDEB(ed); return;	}

    td= (TedDocument *)ed->edPrivateData;

    docInitTextAttribute( &taNew );
    PROPmaskCLEAR( &updMask );

    if  ( familyName )
	{
	BufferDocument *	bd= td->tdDocument;
	DocumentProperties *	dp= &(bd->bdProperties);
	DocumentFontList *	dfl= &(dp->dpFontList);

	taNew.taFontNumber= docGetFontByName( dfl, familyName,
						    enc, encodingIsDefault );
	if  ( taNew.taFontNumber < 0 )
	    { SLDEB(familyName,taNew.taFontNumber); return;	}

	PROPmaskADD( &updMask, TApropFONTFAMILY );
	}

    if  ( fontBold >= 0 )
	{
	taNew.taFontIsBold= ( fontBold != 0 );
	PROPmaskADD( &updMask, TApropFONTBOLD );
	}

    if  ( fontSlanted >= 0 )
	{
	taNew.taFontIsSlanted= ( fontSlanted != 0 );
	PROPmaskADD( &updMask, TApropFONTSLANTED );
	}

    if  ( fontSizeHalfPoints > 0 )
	{
	taNew.taFontSizeHalfPoints= fontSizeHalfPoints;
	PROPmaskADD( &updMask, TApropFONTSIZE );
	}

    tedAppChangeSelectionAttribute( ed, &updMask, taNew );

    if  ( fontBold < 0 || fontSlanted < 0 )
	{
	const char *	psFamilyNameGot;

	if  ( tedGetDocumentAttributes( td,
		&psFamilyNameGot, &psFamilyNumber, &enc, &updMask, &taNew ) )
	    { LLDEB(fontBold,fontSlanted);	}
	}

    appGuiSetToggleItemState( td->tdFontBoldOption,
			    PROPmaskISSET( &updMask, TApropFONTBOLD ) &&
			    taNew.taFontIsBold );

    appGuiSetToggleItemState( td->tdFontItalicOption,
			    PROPmaskISSET( &updMask, TApropFONTSLANTED ) &&
			    taNew.taFontIsSlanted );

    if  ( ea->eaSymbolPicker )
	{
	if  ( appAdaptSymbolPickerToFontFamily( ea->eaSymbolPicker,
						psFamilyNumber, enc ) )
	    { LLDEB(psFamilyNumber,enc);	}
	}

    return;
    }


void tedShowFontsTool(		APP_WIDGET		fontsOption,
				EditApplication *	ea,
				void *			voidcbs	 )
    {
    EditDocument *	ed= ea->eaCurrentDocument;

    if  ( ! ea->eaFontsTool )
	{
	char *			pixmapName= "tedfont";
	APP_BITMAP_IMAGE	iconPixmap= (APP_BITMAP_IMAGE)0;
	APP_BITMAP_MASK		iconMask= (APP_BITMAP_MASK)0;

	if  ( ! ed )
	    { XDEB(ed); return;	}

	if  ( appGetImagePixmap( ea, pixmapName, &iconPixmap, &iconMask )  )
	    { SDEB(pixmapName); return;	}

	ea->eaFontsTool= appMakeFontsTool( fontsOption, "tedFontTool",
		    iconPixmap, iconMask,
		    tedFontsToolClosed, tedFontToolSet, ea );
	}
    else{ appShowFontsTool( ea->eaFontsTool );	}

    if  ( ed )
	{ tedAdaptFontsToolToDocument( ea, ed );	}

    return;
    }

/************************************************************************/
/*									*/
/*  Show or create a symbol picker.					*/
/*									*/
/************************************************************************/

static void tedSymbolPickerInsert(	void *		voidea,
					int		symbol,
					int		psFamilyNumberSet,
					char *		familyNameSet,
					int		encodingSet,
					int		encodingIsDefault )
    {
    unsigned char	fresh[2];

    EditApplication *	ea= (EditApplication *)voidea;
    EditDocument *	ed= ea->eaCurrentDocument;
    AppDrawingData *	add;
    TedDocument *	td;

    if  ( ! ed )
	{ XDEB(ed); return;	}

    td= (TedDocument *)ed->edPrivateData;
    add= &(ed->edDrawingData);

    fresh[0]= symbol;
    fresh[1]= '\0';

    if  ( tedHasSelection( td )		&&
	  td->tdCanReplaceSelection	)
	{
	const char *	familyNameGot= (char *)0;
	int		psFamilyNumberGot= -1;
	int		encodingGot= -1;

	PropertyMask	updMask;
	TextAttribute	taNew;

	if  ( tedGetDocumentAttributes( td, &familyNameGot,
			&psFamilyNumberGot, &encodingGot, &updMask, &taNew ) )
	    { LDEB(1); return;	}

	if  ( ! PROPmaskISSET( &updMask, TApropFONTFAMILY )	||
	      psFamilyNumberSet != psFamilyNumberGot		||
	      encodingSet != encodingGot			)
	    {
	    BufferDocument *		bd= td->tdDocument;
	    DocumentProperties *	dp= &(bd->bdProperties);
	    DocumentFontList *		dfl= &(dp->dpFontList);

	    taNew.taFontNumber= docGetFontByName( dfl, familyNameSet,
					    encodingSet, encodingIsDefault );
	    if  ( taNew.taFontNumber < 0 )
		{ SLDEB(familyNameSet,taNew.taFontNumber); return;	}

	    td->tdCurrentTextAttribute.taFontNumber= taNew.taFontNumber;
	    td->tdCurrentPhysicalFont= appOpenDocumentFont( add, dfl,
						td->tdCurrentTextAttribute );
	    }

	tedAppReplaceSelection( ed, fresh, 1 );
	}

    return;
    }

static void tedSymbolPickerClosed(	void *		voidea	)
    {
    EditApplication *	ea=	(EditApplication *)voidea;

    ea->eaSymbolPicker= (void *)0;
    }

void tedDocToolInsertSymbol(	APP_WIDGET	symbolOption,
				void *		voided,
				void *		voidcbs	 )
    {
    EditDocument *	ed= (EditDocument *)voided;
    TedDocument *	td= (TedDocument *)ed->edPrivateData;
    EditApplication *	ea= ed->edApplication;

    if  ( ! td->tdCanReplaceSelection )
	{ LDEB(td->tdCanReplaceSelection); return;	}

    if  ( ! ea->eaSymbolPicker )
	{
	char *			pixmapName= "tedsymbol";
	APP_BITMAP_IMAGE	iconPixmap= (APP_BITMAP_IMAGE)0;
	APP_BITMAP_MASK		iconMask= (APP_BITMAP_MASK)0;

	const char *	familyName= (char *)0;
	int		psFamilyNumber= -1;
	int		enc= -1;

	PropertyMask	updMask;
	TextAttribute	taNew;

	if  ( tedGetDocumentAttributes( td, &familyName, &psFamilyNumber, &enc,
							&updMask, &taNew ) )
	    { return;	}

	if  ( ! PROPmaskISSET( &updMask, TApropFONTFAMILY ) )
	    { XDEB(TApropFONTFAMILY); return;	}

	if  ( appGetImagePixmap( ea, pixmapName, &iconPixmap, &iconMask )  )
	    { SDEB(pixmapName); return;	}

	ea->eaSymbolPicker= appMakeSymbolPicker( symbolOption, ea,
			    "tedSymbolPicker",
			    iconPixmap, iconMask,
			    tedSymbolPickerInsert,
			    tedSymbolPickerClosed,
			    (void *)ea );

	if  ( appAdaptSymbolPickerToFontFamily( ea->eaSymbolPicker,
						psFamilyNumber, enc ) )
	    { LLDEB(psFamilyNumber,enc);	}
	}
    else{ appShowSymbolPicker( ea->eaSymbolPicker ); }

    return;
    }