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