1 /************************************************************************/
2 /* */
3 /* Calculate 'Symbol' fields. */
4 /* */
5 /************************************************************************/
6
7 # include "docBufConfig.h"
8
9 # include <appDebugon.h>
10
11 # include <docSymbolField.h>
12 # include <uniLegacyEncoding.h>
13 # include <uniUtf8.h>
14
15 # include "docBuf.h"
16 # include "docRecalculateFields.h"
17 # include "docEvalField.h"
18
19 /************************************************************************/
20 /* */
21 /* Format the value of a 'symbol' field. */
22 /* */
23 /************************************************************************/
24
docCalculateSymbolFieldString(int * pCalculated,MemoryBuffer * mbResult,const DocumentField * df,const RecalculateFields * rf)25 int docCalculateSymbolFieldString(
26 int * pCalculated,
27 MemoryBuffer * mbResult,
28 const DocumentField * df,
29 const RecalculateFields * rf )
30 {
31 int rval= 0;
32
33 int step;
34
35 char scratch[20];
36 const int * unicodes= uniWinCp1252GlyphUnicodes;
37
38 SymbolField sf;
39
40 docInitSymbolField( &sf );
41
42 if ( docFieldGetSymbol( &sf, df ) )
43 { LDEB(1); *pCalculated= 0; goto ready; }
44
45 if ( utilMemoryBufferEqualsString( &(sf.sfFontName), "Symbol" ) )
46 { unicodes= uniSymbolGlyphUnicodes; }
47
48 if ( utilMemoryBufferEqualsString( &(sf.sfFontName), "ITC Zapf Dingbats" )||
49 utilMemoryBufferEqualsString( &(sf.sfFontName), "ZapfDingbats" )||
50 utilMemoryBufferEqualsString( &(sf.sfFontName), "Dingbats" ) )
51 { unicodes= uniDingbatsGlyphUnicodes; }
52
53 switch( sf.sfEncoding )
54 {
55 case SYMBOLencANSI:
56 if ( sf.sfSymbol >= 0 &&
57 sf.sfSymbol < 256 &&
58 unicodes[sf.sfSymbol] >= 0 )
59 { sf.sfSymbol= unicodes[sf.sfSymbol]; }
60 else{ LDEB(sf.sfSymbol); *pCalculated= 0; goto ready; }
61 break;
62 case SYMBOLencUNICODE:
63 break;
64
65 case SYMBOLencSHIFT_JIS:
66 default:
67 LDEB(sf.sfEncoding); *pCalculated= 0; goto ready;
68 }
69
70 step= uniPutUtf8( scratch, sf.sfSymbol );
71 if ( step < 1 )
72 { LLDEB(sf.sfSymbol,step); *pCalculated= 0; goto ready; }
73 utilMemoryBufferAppendBytes( mbResult, (unsigned char *)scratch, step );
74 *pCalculated= 1;
75
76 ready:
77 docCleanSymbolField( &sf );
78
79 return rval;
80 }
81
82 /************************************************************************/
83 /* */
84 /* Evaluate Footnote number fields. */
85 /* */
86 /************************************************************************/
87
docRecalculateParaSymbolTextParticules(int * pCalculated,int * pPartShift,int * pStroffShift,struct BufferItem * paraBi,int part,int partCount,DocumentField * df,const RecalculateFields * rf)88 int docRecalculateParaSymbolTextParticules(
89 int * pCalculated,
90 int * pPartShift,
91 int * pStroffShift,
92 struct BufferItem * paraBi,
93 int part,
94 int partCount,
95 DocumentField * df,
96 const RecalculateFields * rf )
97 {
98 int rval= 0;
99
100 char * allocated= (char *)0;
101 SymbolField sf;
102
103 docInitSymbolField( &sf );
104
105 if ( docFieldGetSymbol( &sf, df ) )
106 { LDEB(1); *pCalculated= 0; goto ready; }
107
108 rval= docRecalculateParaStringTextParticules( pCalculated,
109 pPartShift, pStroffShift, paraBi, part, partCount, df, rf );
110
111 if ( rval )
112 { LDEB(rval); goto ready; }
113
114 if ( *pCalculated )
115 {
116 TextAttribute taSet;
117 PropertyMask taSetMask;
118
119 utilPropMaskClear( &taSetMask );
120 utilInitTextAttribute( &taSet );
121
122 if ( ! utilMemoryBufferIsEmpty( &(sf.sfFontName) ) )
123 {
124 int fontNumber;
125 DocumentProperties * dp= &(rf->rfDocument->bdProperties);
126
127 allocated= utilMemoryStrdup( &(sf.sfFontName) );
128 if ( ! allocated )
129 { XDEB(allocated); rval= -1; goto ready; }
130
131 fontNumber= docGetFontByName( dp->dpFontList, allocated );
132 if ( fontNumber < 0 )
133 { SLDEB(allocated,fontNumber); }
134 else{
135 taSet.taFontNumber= fontNumber;
136 PROPmaskADD( &taSetMask, TApropFONT_NUMBER );
137 }
138 }
139
140 if ( sf.sfSizePoints > 0 )
141 {
142 taSet.taFontSizeHalfPoints= 2* sf.sfSizePoints;
143 PROPmaskADD( &taSetMask, TApropFONTSIZE );
144 }
145
146 if ( ! utilPropMaskIsEmpty( &taSetMask ) )
147 {
148 if ( docChangeParticuleAttributes( (int *)0, (PropertyMask *)0,
149 rf->rfDocument, paraBi,
150 part+ 1, part+ 1+ partCount+ *pPartShift,
151 &taSet, &taSetMask ) )
152 { LDEB(part); rval= -1; goto ready; }
153 }
154 }
155
156 ready:
157
158 docCleanSymbolField( &sf );
159
160 return rval;
161 }
162