1 /************************************************************************/
2 /* */
3 /* Save a BufferDocument into an RTF file. */
4 /* */
5 /************************************************************************/
6
7 # include "docRtfConfig.h"
8
9 # include <stdio.h>
10 # include <ctype.h>
11
12 # include <appDebugon.h>
13
14 # include "docRtfReadWrite.h"
15 # include "docRtfWriterImpl.h"
16 # include "docRtfTags.h"
17 # include <docNotes.h>
18 # include <docTreeType.h>
19
docRtfSaveDocument(SimpleOutputStream * sos,BufferDocument * bd,const DocumentSelection * ds,int flags)20 int docRtfSaveDocument( SimpleOutputStream * sos,
21 BufferDocument * bd,
22 const DocumentSelection * ds,
23 int flags )
24 {
25 int rval= 0;
26 RtfWriter * rwc= (RtfWriter *)0;
27
28 PropertyMask dpSaveMask;
29
30 struct DocumentNote * dn;
31 int hasFootNotes= 0;
32 int hasEndNotes= 0;
33 int fet;
34
35 rwc= docRtfOpenWriter( sos, bd, flags );
36 if ( ! rwc )
37 { XDEB(rwc); rval= -1; goto ready; }
38
39 if ( docRtfDocPropMask( &dpSaveMask, &(bd->bdProperties) ) )
40 { LDEB(1); rval= -1; goto ready; }
41
42 if ( bd->bdProperties.dpFontList->dflFontCount > 0 )
43 { PROPmaskADD( &dpSaveMask, DPpropFONTTABLE ); }
44 if ( bd->bdProperties.dpColorPalette->cpColorCount > 0 )
45 { PROPmaskADD( &dpSaveMask, DPpropCOLORTABLE ); }
46 if ( bd->bdProperties.dpListAdmin->laListTable.dltListCount > 0 )
47 { PROPmaskADD( &dpSaveMask, DPpropLISTTABLE ); }
48 if ( bd->bdProperties.dpListAdmin->laListOverrideTable.lotOverrideCount > 0 )
49 { PROPmaskADD( &dpSaveMask, DPpropLISTOVERRIDETABLE ); }
50 if ( bd->bdStyleSheet.dssStyleCount > 0 )
51 { PROPmaskADD( &dpSaveMask, DPpropSTYLESHEET ); }
52
53 if ( ! utilMemoryBufferIsEmpty( &(bd->bdProperties.dpGeneratorWrite) ) )
54 { PROPmaskADD( &dpSaveMask, DPpropGENERATOR ); }
55
56 if ( docRtfWriteBuildFontAdmin( rwc ) )
57 { LDEB(1); rval= -1; goto ready; }
58
59 docRtfWriteDestinationBegin( rwc, "rtf1\\ansi" );
60 docRtfWriteNextLine( rwc );
61
62 if ( docGetFirstNoteOfDocument( &dn, bd, DOCinFOOTNOTE ) )
63 {
64 hasFootNotes= 1;
65 PROPmaskADD( &dpSaveMask, DPpropFOOTNOTE_JUSTIFICATION );
66 }
67
68 if ( docGetFirstNoteOfDocument( &dn, bd, DOCinENDNOTE ) )
69 {
70 hasEndNotes= 1;
71 PROPmaskADD( &dpSaveMask, DPpropENDNOTE_JUSTIFICATION );
72 }
73
74 if ( hasEndNotes )
75 {
76 if ( hasFootNotes )
77 { fet= 2; }
78 else{ fet= 1; }
79 }
80 else{ fet= 0; }
81
82 if ( docRtfSaveDocumentProperties( rwc, fet,
83 &dpSaveMask, &(bd->bdProperties) ) )
84 { LDEB(1); rval= -1; goto ready; }
85
86 if ( ds )
87 {
88 docRtfWriteDestinationBegin( rwc, RTFtag__SelOpen );
89 docRtfWriteDestinationEnd( rwc );
90 }
91
92 if ( docRtfSaveDocNotesSeparators( rwc, bd ) )
93 { LDEB(1); rval= -1; goto ready; }
94
95 if ( docRtfWriteSelection( rwc, ds ) )
96 { LDEB(1); rval= -1; goto ready; }
97
98 docRtfWriteDestinationEnd( rwc );
99 docRtfWriteNextLine( rwc );
100
101 ready:
102
103 if ( rwc )
104 { docRtfCloseWriter( rwc ); }
105
106 return rval;
107 }
108
109