1 /************************************************************************/
2 /*									*/
3 /*  Save a BufferDocument into an HTML file.				*/
4 /*  Depending on the parameters, this is either an HTML file with	*/
5 /*  a directory for the images, or a MHTML (rfc2112,rfc2557) aggregate.	*/
6 /*  RFC 2557 was never validated.					*/
7 /*									*/
8 /*  Additionally, the HTML writing code is used to save documents in	*/
9 /*  EPUB format. See http://www.idpf.org/specs.htm.			*/
10 /*									*/
11 /************************************************************************/
12 
13 #   ifndef		DOC_HTML_WRITE_IMPL_H
14 #   define		DOC_HTML_WRITE_IMPL_H
15 
16 #   include		"docHtmlWrite.h"
17 #   include		<xmlWriter.h>
18 #   include		<docBlockFrame.h>
19 #   include		<docStripFrame.h>
20 
21 			/**
22 			 * Map sizes: Assume 96 dpi
23 			 */
24 #   define	TWIPS_TO_PIXELS(x)	(((x)+7)/15)
25 
26 #   define	USE_PNG			1
27 #   define	USE_GIF			0
28 
29 /************************************************************************/
30 /*									*/
31 /*  Information used when writing HTML.					*/
32 /*									*/
33 /************************************************************************/
34 
35 struct HtmlWritingContext;
36 
37 typedef SimpleOutputStream * (*HtmlOpenImageStream)(
38 					struct HtmlWritingContext *	hwc,
39 					int				n,
40 					const InsertedObject *		io,
41 					const char *			mimeT,
42 					const char *			ext );
43 
44 typedef int (*HtmlGetImageSrc)(		MemoryBuffer *			target,
45 					struct HtmlWritingContext *	hwc,
46 					int				n,
47 					const InsertedObject *		io,
48 					const char *			ext );
49 
50 typedef int (*HtmlGetCssName)(		MemoryBuffer *			target,
51 					struct HtmlWritingContext *	hwc );
52 typedef struct HtmlWritingContext
53     {
54     XmlWriter			hwcXmlWriter;
55 
56     const LayoutContext *	hwcLayoutContext;
57     BlockFrame			hwcBlockFrame;
58     ParagraphFrame		hwcParagraphFrame;
59 
60     HtmlOpenImageStream		hwcOpenImageStream;
61     HtmlGetImageSrc		hwcGetImageSrc;
62     HtmlGetCssName		hwcGetCssName;
63     void *			hwcPrivate;
64     BufferDocument *		hwcDocument;
65 
66     IndexMapping		hwcDeferredNotes;
67 
68     int				hwcInlineCss;
69     int				hwcInlineNotes;
70 
71     int				hwcInHyperlink;
72     int				hwcInBookmark;
73     int				hwcInPageref;
74     int				hwcBytesInLink;
75     TextAttribute		hwcDefaultAttribute;
76     ParagraphProperties		hwcParagraphProperties;
77 
78 
79     int				hwcImageCount;
80     int				hwcNoteRefCount;
81     int				hwcNoteDefCount;
82 
83     int				hwcTableNesting;
84 
85     int				hwcCurrentAttributeNumber;
86 					/**
87 					 *  Support bullets? Only in  browser!
88 					 */
89     unsigned char		hwcSupportsBullets;
90     unsigned char		hwcEmitBackground;
91     } HtmlWritingContext;
92 
93 /************************************************************************/
94 /*									*/
95 /*  Routine declarations.						*/
96 /*									*/
97 /************************************************************************/
98 
99 extern void docInitHtmlWritingContext(	HtmlWritingContext *	hwc );
100 extern void docCleanHtmlWritingContext(	HtmlWritingContext *	hwc );
101 
102 extern void docHtmlPutString(		const char *		s,
103 					HtmlWritingContext *	hwc );
104 
105 extern void docHtmlNewLine(		HtmlWritingContext *	hwc );
106 
107 extern int docHtmlSaveImgElement(
108 				int *			pDone,
109 				HtmlWritingContext *	hwc,
110 				int			n,
111 				const struct BufferItem *	paraBi,
112 				InsertedObject *	io );
113 
114 extern int docHtmlSaveImages(	HtmlWritingContext *		hwc );
115 
116 extern void docHtmlChangeAttributes(
117 				HtmlWritingContext *		hwc,
118 				int				taNr );
119 
120 extern void docHtmlWriteStringAttribute( HtmlWritingContext *	hwc,
121 					const char *		name,
122 					const char *		value );
123 
124 extern void docHtmlWriteIntAttribute(	HtmlWritingContext *	hwc,
125 					const char *		name,
126 					int			value );
127 
128 extern void docHtmlEscapeCharacters(	HtmlWritingContext *	hwc,
129 					const char *		ss,
130 					int			len );
131 
132 extern int docHtmlStartField(	const DocumentField *		df,
133 				HtmlWritingContext *		hwc,
134 				const struct BufferItem *	bi,
135 				int				attNr );
136 
137 extern int docHtmlFinishField(	const DocumentField *		df,
138 				HtmlWritingContext *		hwc );
139 
140 extern int docHtmlSaveParaNode( HtmlWritingContext *		hwc,
141 				const struct BufferItem *	paraBi,
142 				const struct BufferItem *	bodySectNode,
143 				const DocumentSelection *	ds );
144 
145 extern int docHtmlSaveDocumentStyles(	HtmlWritingContext *	hwc,
146 					SimpleOutputStream *	sos );
147 
148 extern int docHtmlSaveSelection(	HtmlWritingContext *		hwc,
149 					DocumentTree *			dt,
150 					const DocumentSelection *	ds );
151 
152 extern void docHtmlEmitBackgroundProperty(
153 					const ItemShading *	is,
154 					HtmlWritingContext *	hwc );
155 
156 extern int docHtmlStartDocument(	HtmlWritingContext *	hwc );
157 extern int docHtmlFinishDocument(	HtmlWritingContext *	hwc );
158 
159 extern int docHtmlSaveNotes(		HtmlWritingContext *	hwc );
160 
161 extern int docHtmlObjectSaveHow(int *			pType,
162 				const char **		pMimeType,
163 				const char **		pExt,
164 				const MemoryBuffer **	pObjectData,
165 				const InsertedObject *	io );
166 
167 extern int docHtmlSaveDeferredNotes(	HtmlWritingContext *		hwc );
168 
169 extern int docHtmlStartNote(	const DocumentField *		df,
170 				HtmlWritingContext *		hwc,
171 				const struct BufferItem *	bi,
172 				int				attNr );
173 
174 extern int docHtmlStartAnchor(	HtmlWritingContext *		hwc,
175 				int				isNote,
176 				const MemoryBuffer *		fileName,
177 				const MemoryBuffer *		markName,
178 				const MemoryBuffer *		refName,
179 				const char *			title,
180 				int				titleSize );
181 
182 #   endif	/*	DOC_HTML_WRITE_IMPL_H	*/
183 
184