]> git.saurik.com Git - wxWidgets.git/blame - utils/tex2rtf/src/rtfutils.cpp
corrected a type in the constructor from two points
[wxWidgets.git] / utils / tex2rtf / src / rtfutils.cpp
CommitLineData
9a29912f
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: rtfutils.cpp
3// Purpose: Converts Latex to Word RTF/WinHelp RTF
4// Author: Julian Smart
5// Modified by:
6// Created: 7.9.93
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
23#ifndef WX_PRECOMP
24#include "wx/wx.h"
25#endif
26
27#include "tex2any.h"
28#include "tex2rtf.h"
29#include <ctype.h>
30#include <stdlib.h>
31#include <stdio.h>
32
33#ifdef __WIN32__
34#include <windows.h>
35#endif
36
37#include "bmputils.h"
38#include "table.h"
39
40wxList itemizeStack;
41static int indentLevel = 0;
42static int forbidParindent = 0; // if > 0, no parindent (e.g. in center environment)
43int forbidResetPar = 0; // If > 0, don't reset memory of having output a new par
44
45static char *contentsLineSection = NULL;
46static char *contentsLineValue = NULL;
47static TexChunk *descriptionItemArg = NULL;
48static wxStringList environmentStack; // Stack of paragraph styles we need to remember
49static int footnoteCount = 0;
50static int citeCount = 1;
51extern char *FileRoot;
52extern bool winHelp;
53extern bool startedSections;
54extern FILE *Contents;
55extern FILE *Chapters;
56extern FILE *Popups;
57extern FILE *WinHelpContentsFile;
58extern char *RTFCharset;
59// This is defined in the Tex2Any library and isn't in use after parsing
60extern char *BigBuffer;
61// Are we in verbatim mode? If so, format differently.
62static bool inVerbatim = FALSE;
63
64// We're in a series of PopRef topics, so don't output section headings
65bool inPopRefSection = FALSE;
66
67// Green colour?
68static bool hotSpotColour = TRUE;
69static bool hotSpotUnderline = TRUE;
70
71// Transparency (WHITE = transparent)
72static bool bitmapTransparency = TRUE;
73
74// Linear RTF requires us to set the style per section.
75static char *currentNumberStyle = NULL;
76static int currentItemSep = 8;
77static int CurrentTextWidth = 8640; // Say, six inches
78static int CurrentLeftMarginOdd = 400;
79static int CurrentLeftMarginEven = 1440;
80static int CurrentRightMarginOdd = 1440;
81static int CurrentRightMarginEven = 400;
82static int CurrentMarginParWidth = 2000;
83static int CurrentMarginParSep = 400; // Gap between marginpar and text
84static int CurrentMarginParX = CurrentLeftMarginOdd + CurrentTextWidth + CurrentMarginParSep;
85static int GutterWidth = 2300;
86
87// Two-column table dimensions, in twips
88static int TwoColWidthA = 1500;
89static int TwoColWidthB = 3000;
90
91const int PageWidth = 12242; // 8.25 inches wide for A4
92
93
94/*
95 * Flag to say we've just issued a \par\pard command, so don't
96 * repeat this unnecessarily.
97 *
98 */
99
100int issuedNewParagraph = 0;
101
102// Need to know whether we're in a table or figure for benefit
103// of listoffigures/listoftables
104static bool inFigure = FALSE;
105static bool inTable = FALSE;
106
107/*
108 * Current topics
109 *
110 */
111static char *CurrentChapterName = NULL;
112static char *CurrentSectionName = NULL;
113static char *CurrentSubsectionName = NULL;
114static char *CurrentTopic = NULL;
115
116static bool InPopups()
117{
118 if (CurrentChapterName && (strcmp(CurrentChapterName, "popups") == 0))
119 return TRUE;
120 if (CurrentSectionName && (strcmp(CurrentSectionName, "popups") == 0))
121 return TRUE;
122 return FALSE;
123}
124
125static void SetCurrentTopic(char *s)
126{
127 if (CurrentTopic) delete[] CurrentTopic;
128 CurrentTopic = copystring(s);
129}
130
131void SetCurrentChapterName(char *s)
132{
133 if (CurrentChapterName) delete[] CurrentChapterName;
134 CurrentChapterName = copystring(s);
135 SetCurrentTopic(s);
136}
137void SetCurrentSectionName(char *s)
138{
139 if (CurrentSectionName) delete[] CurrentSectionName;
140 CurrentSectionName = copystring(s);
141 SetCurrentTopic(s);
142}
143void SetCurrentSubsectionName(char *s)
144{
145 if (CurrentSubsectionName) delete[] CurrentSubsectionName;
146 CurrentSubsectionName = copystring(s);
147 SetCurrentTopic(s);
148}
149
150// Indicate that a parent topic at level 'level' has children.
151// Level 1 is a chapter, 2 is a section, etc.
152void NotifyParentHasChildren(int parentLevel)
153{
154 char *parentTopic = NULL;
155 switch (parentLevel)
156 {
157 case 1:
158 {
159 parentTopic = CurrentChapterName;
160 break;
161 }
162 case 2:
163 {
164 parentTopic = CurrentSectionName;
165 break;
166 }
167 case 3:
168 {
169 parentTopic = CurrentSubsectionName;
170 break;
171 }
172 default:
173 {
174 break;
175 }
176 }
177 if (parentTopic)
178 {
179 TexTopic *texTopic = (TexTopic *)TopicTable.Get(parentTopic);
180 if (!texTopic)
181 {
182 texTopic = new TexTopic;
183 TopicTable.Put(parentTopic, texTopic);
184 }
185 texTopic->hasChildren = TRUE;
186 }
187}
188
189// Have to keep a count of what levels are books, what are pages,
190// in order to correct for a Win95 bug which means that if you
191// have a book at level n, and then a page at level n, the page
192// ends up on level n + 1.
193
194bool ContentsLevels[5];
195
196// Reset below this level (starts from 1)
197void ResetContentsLevels(int l)
198{
199 int i;
200 for (i = l; i < 5; i++)
201 ContentsLevels[i] = FALSE;
202
203 // There are always books on the top level
204 ContentsLevels[0] = TRUE;
205}
206
207// Output a WinHelp section as a keyword, substituting
208// : for space.
209void OutputSectionKeyword(FILE *fd)
210{
211 OutputCurrentSectionToString(wxBuffer);
212
213 int i;
214 for (i = 0; i < strlen(wxBuffer); i++)
215 if (wxBuffer[i] == ':')
216 wxBuffer[i] = ' ';
217 // Don't write to index if there's some RTF in the string
218 else if ( wxBuffer[i] == '{' )
219 return;
220
221 fprintf(fd, "K{\\footnote {K} ");
222 fprintf(fd, "%s", wxBuffer);
223
224 fprintf(fd, "}\n");
225}
226
227// Write a line for the .cnt file, if we're doing this.
228void WriteWinHelpContentsFileLine(char *topicName, char *xitle, int level)
229{
230 // First, convert any RTF characters to ASCII
231 char title[255];
232 int s=0;
233 int d=0;
234 while ( (xitle[s]!=0)&&(d<255) )
235 {
236 char ch=xitle[s]&0xff;
237 if (ch==0x5c) {
238 char ch1=xitle[s+1]&0xff;
239 char ch2=xitle[s+2]&0xff;
240 char ch3=xitle[s+3]&0xff;
241 char ch4=xitle[s+4]&0xff;
242 s+=4; // next character
243 char a=0;
244