File: tedAppFont.c

package info (click to toggle)
ted 2.16-5
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 13,944 kB
  • ctags: 20,273
  • sloc: ansic: 167,980; makefile: 12,518; sh: 263
file content (473 lines) | stat: -rw-r--r-- 12,577 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
/************************************************************************/
/*									*/
/*  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	"tedLayout.h"
#   include	<docExpandedTextAttribute.h>
#   include	<appSymbolPicker.h>

#   include	<appDebugon.h>

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

static void tedSetCurrentAttribute(
				TedDocument *			td,
				AppDrawingData *		add )
    {
    BufferDocument *		bd= td->tdDocument;
    ScreenFontList *		sfl= &(td->tdScreenFontList);

    td->tdCurrentTextAttributeNumber= utilTextAttributeNumber(
					    &(bd->bdTextAttributeList),
					    &(td->tdCurrentTextAttribute) );

    if  ( td->tdCurrentTextAttributeNumber < 0 )
	{ LDEB(td->tdCurrentTextAttributeNumber); return;	}

    td->tdCurrentScreenFont= tedOpenScreenFont( bd, add, sfl,
					    td->tdCurrentTextAttributeNumber );

    return;
    }

static void tedDocChangeSelectionAttribute(
					EditDocument *		ed,
					const PropertyMask *	taSetMask,
					const TextAttribute *	taSet )
    {
    AppDrawingData *		add= &(ed->edDrawingData);
    TedDocument *		td= (TedDocument *)ed->edPrivateData;

    PropertyMask		ppUpdMask;
    PropertyMask		spUpdMask;
    PropertyMask		changeMask;

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

    PROPmaskCLEAR( &changeMask );

    utilUpdateTextAttribute( &changeMask,
			    &(td->tdCurrentTextAttribute), taSet, taSetMask );

    if  ( ! PROPmaskISEMPTY( &changeMask )	||
	  td->tdCurrentScreenFont < 0		)
	{ tedSetCurrentAttribute( td, add );	}

    tedChangeSelectionProperties( ed,
			    taSetMask, taSet,
			    &ppUpdMask, (const ParagraphProperties *)0,
			    &spUpdMask, (const SectionProperties *)0 );

    return;
    }

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

static void tedAdaptSymbolPickerToDocument(	EditApplication *	ea,
						EditDocument *		ed )
    {
    if  ( ea->eaSymbolPicker )
	{
	TedDocument *			td= (TedDocument *)ed->edPrivateData;
	BufferDocument *		bd= td->tdDocument;
	const DocumentProperties *	dp= &(bd->bdProperties);
	const DocumentFontList *	dfl= &(dp->dpFontList);

	PropertyMask			doneMask;
	PropertyMask			taSetMask;
	TextAttribute			taSet;

	PROPmaskCLEAR( &doneMask );
	PROPmaskCLEAR( &taSetMask );
	utilInitTextAttribute( &taSet );

	if  ( tedGetDocumentAttributes( td, &taSetMask, &taSet ) )
	    { return;	}

	if  ( appAdaptSymbolPickerToFontFamily( ea->eaSymbolPicker,
					    ed->edDocumentId,
					    dfl, &taSet, &taSetMask ) )
	    { LDEB(1);	}
	}

    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,
					const PropertyMask *	taSetMask,
					TextAttribute *		taSet )
    {
    EditApplication *	ea= ed->edApplication;
    TedDocument *	td= (TedDocument *)ed->edPrivateData;

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

	if  ( appAdaptSymbolPickerToFontFamily( ea->eaSymbolPicker,
						    ed->edDocumentId,
						    dfl, taSet, taSetMask ) )
	    { LDEB(1);	}
	}

    appGuiSetToggleItemState( td->tdFontBoldOption,
			    PROPmaskISSET( taSetMask, TApropFONTBOLD ) &&
			    taSet->taFontIsBold );

    appGuiSetToggleItemState( td->tdFontItalicOption,
			    PROPmaskISSET( taSetMask, TApropFONTSLANTED ) &&
			    taSet->taFontIsSlanted );

    appGuiSetToggleItemState( td->tdFontUnderlinedOption,
			    PROPmaskISSET( taSetMask, TApropTEXTUNDERLINED ) &&
			    taSet->taTextIsUnderlined );

    appGuiSetToggleItemState( td->tdFontSuperscriptOption,
			    PROPmaskISSET( taSetMask, TApropSUPERSUB ) &&
			    taSet->taSuperSub == DOCfontSUPERSCRIPT );

    appGuiSetToggleItemState( td->tdFontSubscriptOption,
			    PROPmaskISSET( taSetMask, TApropSUPERSUB ) &&
			    taSet->taSuperSub == DOCfontSUBSCRIPT );

    return;
    }

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

    PropertyMask		doneMask;
    PropertyMask		taSetMask;
    TextAttribute		taSet;

    PROPmaskCLEAR( &doneMask );
    PROPmaskCLEAR( &taSetMask );
    utilInitTextAttribute( &taSet );

    if  ( tedGetDocumentAttributes( td, &taSetMask, &taSet ) )
	{ goto ready;	}

    tedAdaptFontIndicatorsToValues( ed, &taSetMask, &taSet );

  ready:

    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;
    int			set;

    TextAttribute	taSet;
    PropertyMask	taSetMask;

    PROPmaskCLEAR( &taSetMask );
    utilInitTextAttribute( &taSet );

    set= appGuiGetMenuToggleStateFromCallback( attributeOption, voidcbs );

    switch( prop )
	{
	case TApropFONTBOLD:
	    taSet.taFontIsBold= ( set != 0 );
	    PROPmaskADD( &taSetMask, prop );
	    break;

	case TApropFONTSLANTED:
	    taSet.taFontIsSlanted= ( set != 0 );
	    PROPmaskADD( &taSetMask, prop );
	    break;

	case TApropTEXTUNDERLINED:
	    taSet.taTextIsUnderlined= ( set != 0 );
	    PROPmaskADD( &taSetMask, prop );
	    break;

	default:
	    LDEB(prop);
	    return;
	}

    tedDocChangeSelectionAttribute( ed, &taSetMask, &taSet );

    return;
    }

int tedAppChangeSelectionAttributeString(	EditDocument *	ed,
						char *		attrString )
    {
    TedDocument *		td= (TedDocument *)ed->edPrivateData;
    BufferDocument *		bd= td->tdDocument;
    DocumentProperties *	dp= &(bd->bdProperties);
    DocumentFontList *		dfl= &(dp->dpFontList);

    TextAttribute		taSet;
    ExpandedTextAttribute	etaSet;
    PropertyMask		doneMask;
    PropertyMask		taSetMask;

    EditApplication *		ea= ed->edApplication;

    int				rval= 0;

    PROPmaskCLEAR( &doneMask );
    PROPmaskCLEAR( &taSetMask );
    docInitExpandedTextAttribute( &etaSet );
    utilInitTextAttribute( &taSet );

    if  ( docExpandedAttributeFromString( &taSetMask, &etaSet,
							dfl, attrString ) )
	{ SDEB( attrString ); rval= -1; goto ready;	}

    docIndirectTextAttribute( &doneMask, &taSet, &etaSet, &taSetMask,
				    &(dp->dpColors), &(dp->dpColorCount) );

    tedDocChangeSelectionAttribute( ed, &taSetMask, &taSet );

    tedAdaptFontIndicatorsToSelection( ea, ed );

  ready:
    docCleanExpandedTextAttribute( &etaSet );

    return rval;
    }

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	taSetMask;
    TextAttribute	taSet;
    int			set;

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

    utilInitTextAttribute( &taSet );

    set= appGuiGetMenuToggleStateFromCallback( option, voidcbs );

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

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

    tedDocChangeSelectionAttribute( ed, &taSetMask, &taSet );

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

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

    return;
    }

/************************************************************************/
/*									*/
/*  Ted: The 'Set' button on the font tool was pushed.			*/
/*									*/
/************************************************************************/

void tedFontToolSet(		void *				voidea,
				const ExpandedTextAttribute *	etaSet,
				const PropertyMask *		taSetMask )
    {
    EditApplication *		ea= (EditApplication *)voidea;
    EditDocument *		ed= ea->eaCurrentDocument;
    TedDocument *		td;
    BufferDocument *		bd;
    DocumentProperties *	dp;
    DocumentFontList *		dfl;

    PropertyMask		doneMask;
    TextAttribute		taSet;

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

    td= (TedDocument *)ed->edPrivateData;
    bd= td->tdDocument;
    dp= &(bd->bdProperties);
    dfl= &(dp->dpFontList);

    utilInitTextAttribute( &taSet );
    PROPmaskCLEAR( &doneMask );

    docIndirectTextAttribute( &doneMask, &taSet, etaSet, taSetMask,
				&(dp->dpColors), &(dp->dpColorCount) );

    tedDocChangeSelectionAttribute( ed, taSetMask, &taSet );

    tedAdaptFontIndicatorsToSelection( ea, ed );

    return;
    }

/************************************************************************/
/*									*/
/*  Show or create a symbol picker.					*/
/*									*/
/*  1)  Counts the font as used, so no need to do so here.		*/
/*									*/
/************************************************************************/

static void tedSymbolPickerInsert(
				void *			voidea,
				int			symbol,
				const TextAttribute *	taSet,
				const PropertyMask *	taSetMask )
    {
    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	)
	{
	if  ( PROPmaskISSET( taSetMask, TApropDOC_FONT_NUMBER ) )
	    {
	    PropertyMask	tadoneMask;

	    PROPmaskCLEAR( &tadoneMask );

	    if  ( taSet->taFontNumber < 0 )
		{ LDEB(taSet->taFontNumber); return;	}

	    td->tdCurrentTextAttribute.taFontNumber= taSet->taFontNumber;

	    tedSetCurrentAttribute( td, add );
	    }

	/*  1  */
	tedDocReplaceSelection( 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;

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

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

	tedAdaptSymbolPickerToDocument( ea, ed );
	}
    else{ appShowSymbolPicker( ea->eaSymbolPicker ); }

    return;
    }