1 /************************************************************************/
2 /*									*/
3 /*  Read/Write paragraph properties to/from RTF.			*/
4 /*									*/
5 /************************************************************************/
6 
7 #   include	"docRtfConfig.h"
8 
9 #   include	<stdio.h>
10 #   include	<ctype.h>
11 
12 #   include	<appDebugon.h>
13 
14 #   include	"docRtfReaderImpl.h"
15 #   include	<docTreeNode.h>
16 #   include	<docNodeTree.h>
17 
18 /************************************************************************/
19 /*									*/
20 /*  Handle a paragraph property when reading RTF.			*/
21 /*									*/
22 /************************************************************************/
23 
docRtfRememberParaShadingProperty(const RtfControlWord * rcw,int arg,RtfReader * rrc)24 int docRtfRememberParaShadingProperty(	const RtfControlWord *	rcw,
25 					int			arg,
26 					RtfReader *	rrc )
27     {
28     RtfReadingState *		rrs= rrc->rrcState;
29 
30     if  ( docSetShadingProperty( &(rrs->rrsParagraphShading),
31 						    rcw->rcwID, arg ) < 0 )
32 	{ SLDEB(rcw->rcwWord,arg); return -1;	}
33 
34     /*
35     PROPmaskADD( &(rrs->rrsParaPropertyMask), PPpropSHADING );
36     */
37 
38     return 0;
39     }
40 
docRtfRememberParagraphProperty(const RtfControlWord * rcw,int arg,RtfReader * rrc)41 int docRtfRememberParagraphProperty(	const RtfControlWord *	rcw,
42 					int			arg,
43 					RtfReader *		rrc )
44     {
45     RtfReadingState *		rrs= rrc->rrcState;
46     ParagraphProperties *	pp= &(rrs->rrsParagraphProperties);
47 
48     switch( rcw->rcwID )
49 	{
50 	case PPprop_NONE:
51 	    docRtfResetParagraphProperties( rrs );
52 	    return 0;
53 
54 	case PPpropSTYLE:
55 	    rrc->rrcStyle.dsLevel= DOClevPARA;
56 	    break;
57 
58 	case PPpropLISTOVERRIDE:
59 	    rrc->rrcListOverride.loIndex= arg;
60 	    break;
61 
62 	case PPpropTOP_BORDER:
63 	case PPpropBOTTOM_BORDER:
64 	case PPpropLEFT_BORDER:
65 	case PPpropRIGHT_BORDER:
66 	case PPprop_BOX_BORDER:
67 	case PPpropBETWEEN_BORDER:
68 	case PPpropBAR_BORDER:
69 	    arg= docRtfReadGetBorderNumber( rrc );
70 	    if  ( arg < 0 )
71 		{ SLDEB(rcw->rcwWord,arg); return -1;	}
72 	    break;
73 	}
74 
75     if  ( docSetParaProperty( pp, rcw->rcwID, arg ) < 0 )
76 	{ SLDEB(rcw->rcwWord,arg); return -1;	}
77 
78     PROPmaskADD( &(rrc->rrcStyle.dsParaMask), rcw->rcwID );
79 
80     switch( rcw->rcwID )
81 	{
82 	case PPprop_IN_TABLE:  /* intbl */
83 	    if  ( rrc->rrDocument && pp->ppTableNesting > 0 )
84 		{ rrc->rrDocument->bdProperties.dpContainsTables= 1;	}
85 	    break;
86 	case PPpropTABLE_NESTING:  /* itap */
87 	    if  ( rrc->rrDocument && pp->ppTableNesting > 0 )
88 		{ rrc->rrDocument->bdProperties.dpContainsTables= 1;	}
89 	    break;
90 	}
91 
92     return 0;
93     }
94 
95 /************************************************************************/
96 /*									*/
97 /*  Refresh the values in the paragraph properties that indirectly	*/
98 /*  refer to structures in a numbered property admin.			*/
99 /*									*/
100 /************************************************************************/
101 
docRtfRefreshParagraphProperties(BufferDocument * bd,RtfReadingState * rrs)102 int docRtfRefreshParagraphProperties(	BufferDocument *	bd,
103 					RtfReadingState *	rrs )
104     {
105     rrs->rrsParagraphProperties.ppShadingNumber= docItemShadingNumber( bd,
106 					&(rrs->rrsParagraphShading) );
107 
108     rrs->rrsParagraphProperties.ppTabStopListNumber= docTabStopListNumber( bd,
109 					&(rrs->rrsTabStopList) );
110 
111     rrs->rrsParagraphProperties.ppFrameNumber= docFramePropertiesNumber( bd,
112 					&(rrs->rrsParaFrameProperties) );
113 
114     return 0;
115     }
116 
117 /************************************************************************/
118 /*									*/
119 /*  Transfer paragraph properties to a paragraph or to a style.		*/
120 /*									*/
121 /************************************************************************/
122 
docRtfSetParaProperties(ParagraphProperties * pp,BufferDocument * bd,int mindTable,RtfReadingState * rrs,int breakOverride)123 int docRtfSetParaProperties(	ParagraphProperties *	pp,
124 				BufferDocument *	bd,
125 				int			mindTable,
126 				RtfReadingState *	rrs,
127 				int			breakOverride )
128     {
129     PropertyMask		ppSetMask;
130 
131     docRtfRefreshParagraphProperties( bd, rrs );
132 
133     utilPropMaskClear( &ppSetMask );
134     utilPropMaskFill( &ppSetMask, PPprop_FULL_COUNT );
135     if  ( ! mindTable )
136 	{ PROPmaskUNSET( &ppSetMask, PPpropTABLE_NESTING );	}
137 
138     /*  3  */
139     if  ( docUpdParaProperties( (PropertyMask *)0, pp,
140 				    &ppSetMask, &(rrs->rrsParagraphProperties),
141 				    (const DocumentAttributeMap *)0 ) )
142 	{ LDEB(1); return -1;	}
143 
144     if  ( breakOverride >= 0 )
145 	{ pp->ppBreakKind= breakOverride;	}
146 
147     return 0;
148     }
149 
docRtfAdaptToParaProperties(struct BufferItem * paraNode,BufferDocument * bd,RtfReadingState * rrs,int breakOverride)150 int docRtfAdaptToParaProperties(	struct BufferItem *	paraNode,
151 					BufferDocument *	bd,
152 					RtfReadingState *	rrs,
153 					int			breakOverride )
154     {
155     const int		mindTable= 1;
156     BufferItem *	rowNode;
157 
158     if  ( docRtfSetParaProperties( &(paraNode->biParaProperties),
159 					bd, mindTable, rrs, breakOverride ) )
160 	{ LDEB(1); return -1;	}
161 
162     rowNode= docGetRowLevelNode( paraNode );
163     if  ( paraNode->biParaTableNesting > 0 )
164 	{
165 	if  ( ! rowNode->biRowForTable )
166 	    {
167 	    BufferItem *	cellNode= paraNode->biParent;
168 
169 	    if  ( paraNode->biNumberInParent > 0	||
170 		  cellNode->biNumberInParent > 0	)
171 		{
172 		if  ( docSplitGroupNodeAtLevel( bd,
173 			    (BufferItem **)0, (BufferItem **)0, cellNode,
174 			    paraNode->biNumberInParent, DOClevROW ) )
175 		    { LDEB(1); return -1;	}
176 
177 		docCleanRowProperties( &(rowNode->biRowProperties) );
178 		docInitRowProperties( &(rowNode->biRowProperties) );
179 		}
180 
181 	    docRtfSetForRow( paraNode );
182 	    }
183 	}
184     else{
185 	if  ( rowNode->biRowForTable )
186 	    {
187 	    if  ( rowNode->biChildCount == 1 )
188 		{
189 		rowNode->biRowForTable= 0;
190 		}
191 	    else{
192 		LDEB(rowNode->biChildCount);
193 		LLDEB(paraNode->biParaTableNesting,rowNode->biRowForTable);
194 		}
195 	    }
196 	}
197 
198     return 0;
199     }
200 
docRtfResetParagraphProperties(RtfReadingState * rrs)201 void docRtfResetParagraphProperties(	RtfReadingState *	rrs )
202     {
203     docCleanParagraphProperties( &(rrs->rrsParagraphProperties) );
204     docInitParagraphProperties( &(rrs->rrsParagraphProperties) );
205 
206     docCleanTabStopList( &(rrs->rrsTabStopList) );
207     docInitTabStopList( &(rrs->rrsTabStopList) );
208 
209     docInitItemShading( &(rrs->rrsParagraphShading) );
210     docInitFrameProperties( &(rrs->rrsParaFrameProperties) );
211 
212     return;
213     }
214 
215