1 /************************************************************************/
2 /* */
3 /* Buffer administration routines. */
4 /* */
5 /************************************************************************/
6
7 # include "docBufConfig.h"
8
9 # include <string.h>
10 # include <stdio.h>
11
12 # include <utilBase26.h>
13 # include <utilRoman.h>
14 # include "docBuf.h"
15 # include "docEvalField.h"
16 # include "docRecalculateFields.h"
17 # include <docTreeType.h>
18 # include <docTreeNode.h>
19 # include <docNodeTree.h>
20 # include <docDocumentNote.h>
21 # include <docNotes.h>
22
23 # include <appDebugon.h>
24
25 /************************************************************************/
26 /* */
27 /* Format the value of a 'chftn' field. */
28 /* */
29 /* I.E. the text of the reference to the note in the body of the text, */
30 /* or the identical sign at the begnning of the note. */
31 /* */
32 /************************************************************************/
33
docFormatChftnField(MemoryBuffer * mbResult,const FootEndNotesProperties * fep,const NoteProperties * np,int noteNumber)34 int docFormatChftnField( MemoryBuffer * mbResult,
35 const FootEndNotesProperties * fep,
36 const NoteProperties * np,
37 int noteNumber )
38 {
39 char scratch[100+1];
40 const NotesProperties * nsp;
41
42 utilEmptyMemoryBuffer( mbResult );
43
44 if ( ! np->npAutoNumber )
45 {
46 if ( utilCopyMemoryBuffer( mbResult, &(np->npFixedText) ) )
47 { LDEB(1); return -1; }
48 return 0;
49 }
50
51 switch( np->npTreeType )
52 {
53 case DOCinFOOTNOTE:
54 nsp= &(fep->fepFootnotesProps);
55 break;
56
57 case DOCinENDNOTE:
58 nsp= &(fep->fepEndnotesProps);
59 break;
60
61 default:
62 SDEB(docTreeTypeStr(np->npTreeType)); return -1;
63 }
64
65 if ( nsp->npRestart == FTN_RST_CONTINUOUS )
66 { noteNumber += nsp->npStartNumber- 1; }
67
68 switch( nsp->npNumberStyle )
69 {
70 case FTNstyleNAR:
71 sprintf( scratch, "%d", noteNumber+ 1 );
72 utilMemoryBufferAppendBytes( mbResult,
73 (unsigned char *)scratch, strlen( scratch ) );
74 break;
75
76 case FTNstyleNALC:
77 if ( utilBase26String( scratch, sizeof(scratch)-1,
78 noteNumber+ 1, 0 ) )
79 { LDEB(noteNumber); return -1; }
80 utilMemoryBufferAppendBytes( mbResult,
81 (unsigned char *)scratch, strlen( scratch ) );
82 break;
83
84 case FTNstyleNAUC:
85 if ( utilBase26String( scratch, sizeof(scratch)-1,
86 noteNumber+ 1, 1 ) )
87 { LDEB(noteNumber); return -1; }
88 utilMemoryBufferAppendBytes( mbResult,
89 (unsigned char *)scratch, strlen( scratch ) );
90 break;
91
92 case FTNstyleNRLC:
93 if ( utilRomanString( scratch, sizeof(scratch)-1,
94 noteNumber+ 1, 0 ) )
95 { sprintf( scratch, "NRLC:%d", noteNumber+ 1 ); }
96 utilMemoryBufferAppendBytes( mbResult,
97 (unsigned char *)scratch, strlen( scratch ) );
98 break;
99
100 case FTNstyleNRUC:
101 if ( utilRomanString( scratch, sizeof(scratch)-1,
102 noteNumber+ 1, 1 ) )
103 { sprintf( scratch, "NRUC:%d", noteNumber+ 1 ); }
104 utilMemoryBufferAppendBytes( mbResult,
105 (unsigned char *)scratch, strlen( scratch ) );
106 break;
107
108 case FTNstyleNCHI:
109 default:
110 LDEB(nsp->npNumberStyle);
111 sprintf( scratch, "(%d)", noteNumber+ 1 );
112 utilMemoryBufferAppendBytes( mbResult,
113 (unsigned char *)scratch, strlen( scratch ) );
114 break;
115 }
116
117 return 0;
118 }
119
120 /************************************************************************/
121 /* */
122 /* Evaluate Footnote number fields. */
123 /* */
124 /************************************************************************/
125
docCalculateChftnFieldString(int * pCalculated,MemoryBuffer * mbResult,const DocumentField * dfChftn,const RecalculateFields * rf)126 int docCalculateChftnFieldString(
127 int * pCalculated,
128 MemoryBuffer * mbResult,
129 const DocumentField * dfChftn,
130 const RecalculateFields * rf )
131 {
132 DocumentNote * dn;
133
134 dn= docGetNoteOfField( dfChftn, rf->rfDocument );
135 if ( dn )
136 {
137 const BufferItem * bodySectNode;
138
139 bodySectNode= docGetBodySectNode( dn->dnDocumentTree.dtRoot,
140 rf->rfDocument );
141
142 if ( docFormatChftnField( mbResult,
143 &(bodySectNode->biSectNotesProperties),
144 &(dn->dnNoteProperties),
145 dn->dnNoteNumber ) )
146 { LDEB(dn->dnNoteNumber); *pCalculated= 0; return 0; }
147
148 *pCalculated= 1;
149 return 0;
150 }
151
152 XDEB(dn);
153 *pCalculated= 0; return 0;
154 }
155
156 /************************************************************************/
157 /* */
158 /* Evaluate Footnote number fields. */
159 /* */
160 /************************************************************************/
161
docRecalculateParaChftnTextParticules(int * pCalculated,int * pPartShift,int * pStroffShift,struct BufferItem * paraBi,int part,int partCount,DocumentField * df,const RecalculateFields * rf)162 int docRecalculateParaChftnTextParticules(
163 int * pCalculated,
164 int * pPartShift,
165 int * pStroffShift,
166 struct BufferItem * paraBi,
167 int part,
168 int partCount,
169 DocumentField * df,
170 const RecalculateFields * rf )
171 {
172 int ret;
173
174 TextAttribute taSet;
175 PropertyMask taSetMask;
176 int taChanged= 0;
177
178 ret= docRecalculateParaStringTextParticules( pCalculated,
179 pPartShift, pStroffShift, paraBi, part, partCount,
180 df, rf );
181
182 if ( ret )
183 { LDEB(ret); return ret; }
184
185 docPlainTextAttribute( &taSet, rf->rfDocument );
186 utilPropMaskClear( &taSetMask );
187
188 taSet.taSuperSub= TEXTvaSUPERSCRIPT;
189 PROPmaskADD( &taSetMask, TApropSUPERSUB );
190
191 if ( docChangeParticuleAttributes( &taChanged, (PropertyMask *)0,
192 rf->rfDocument,
193 paraBi, part+ 1,
194 part+ 1+ partCount+ *pPartShift,
195 &taSet, &taSetMask ) )
196 { LDEB(1); }
197
198 if ( taChanged )
199 { *pCalculated= 1; }
200
201 return ret;
202 }
203