]> git.saurik.com Git - wxWidgets.git/blame - utils/tex2rtf/src/rtfutils.cpp
note broken code, cast hack to fix warning on pickier compilers
[wxWidgets.git] / utils / tex2rtf / src / rtfutils.cpp
Content-type: text/html ]> git.saurik.com Git - wxWidgets.git/blame - utils/tex2rtf/src/rtfutils.cpp


500 - Internal Server Error

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