]> git.saurik.com Git - wxWidgets.git/blame - utils/tex2rtf/src/rtfutils.cpp
remove miniframe stuff from GtkOnSize(), it's handled by wxFrame
[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 612.
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
9a29912f
JS
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
9a29912f
JS
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
ea172e69
MB
36static inline wxChar* copystring(const wxChar* s)
37 { return wxStrcpy(new wxChar[wxStrlen(s) + 1], s); }
ea172e69 38
9a29912f
JS
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
6c155d33
JS
44static wxChar *contentsLineSection = NULL;
45static wxChar *contentsLineValue = NULL;
9a29912f
JS
46static TexChunk *descriptionItemArg = NULL;
47static wxStringList environmentStack; // Stack of paragraph styles we need to remember
48static int footnoteCount = 0;
49static int citeCount = 1;
9a29912f
JS
50extern bool winHelp;
51extern bool startedSections;
52extern FILE *Contents;
53extern FILE *Chapters;
54extern FILE *Popups;
55extern FILE *WinHelpContentsFile;
6c155d33 56extern wxChar *RTFCharset;
9a29912f 57// This is defined in the Tex2Any library and isn't in use after parsing
6c155d33 58extern wxChar *BigBuffer;
3924dd22 59
3924dd22
GT
60extern wxHashTable TexReferences;
61
9a29912f 62// Are we in verbatim mode? If so, format differently.
b63b07a8 63static bool inVerbatim = false;
9a29912f
JS
64
65// We're in a series of PopRef topics, so don't output section headings
b63b07a8 66bool inPopRefSection = false;
9a29912f
JS
67
68// Green colour?
b63b07a8
RL
69static bool hotSpotColour = true;
70static bool hotSpotUnderline = true;
9a29912f
JS
71
72// Transparency (WHITE = transparent)
b63b07a8 73static bool bitmapTransparency = true;
9a29912f
JS
74
75// Linear RTF requires us to set the style per section.
6c155d33 76static wxChar *currentNumberStyle = NULL;
9a29912f
JS
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
bf16085d
JS
94// Remember the anchor in a helpref
95static TexChunk *helpRefText = NULL;
9a29912f
JS
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
b63b07a8
RL
107static bool inFigure = false;
108static bool inTable = false;
9a29912f
JS
109
110/*
111 * Current topics
112 *
113 */
6c155d33
JS
114static wxChar *CurrentChapterName = NULL;
115static wxChar *CurrentSectionName = NULL;
116static wxChar *CurrentSubsectionName = NULL;
117static wxChar *CurrentTopic = NULL;
9a29912f
JS
118
119static bool InPopups()
120{
6c155d33 121 if (CurrentChapterName && (wxStrcmp(CurrentChapterName, _T("popups")) == 0))
b63b07a8 122 return true;
6c155d33 123 if (CurrentSectionName && (wxStrcmp(CurrentSectionName, _T("popups")) == 0))
b63b07a8
RL
124 return true;
125 return false;
9a29912f
JS
126}
127
6c155d33 128static void SetCurrentTopic(wxChar *s)
9a29912f
JS
129{
130 if (CurrentTopic) delete[] CurrentTopic;
131 CurrentTopic = copystring(s);
132}
133
6c155d33 134void SetCurrentChapterName(wxChar *s)
9a29912f
JS
135{
136 if (CurrentChapterName) delete[] CurrentChapterName;
137 CurrentChapterName = copystring(s);
138 SetCurrentTopic(s);
139}
6c155d33 140void SetCurrentSectionName(wxChar *s)
9a29912f
JS
141{
142 if (CurrentSectionName) delete[] CurrentSectionName;
143 CurrentSectionName = copystring(s);
144 SetCurrentTopic(s);
145}
6c155d33 146void SetCurrentSubsectionName(wxChar *s)
9a29912f
JS
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{
6c155d33 157 wxChar *parentTopic = NULL;
9a29912f
JS
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 }
b63b07a8 188 texTopic->hasChildren = true;
9a29912f
JS
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++)
b63b07a8 204 ContentsLevels[i] = false;
254a2129 205
9a29912f 206 // There are always books on the top level
b63b07a8 207 ContentsLevels[0] = true;
9a29912f
JS
208}
209
210// Output a WinHelp section as a keyword, substituting
211// : for space.
212void OutputSectionKeyword(FILE *fd)
213{
aed3314d 214 OutputCurrentSectionToString(wxTex2RTFBuffer);
254a2129 215
241c426c 216 unsigned int i;
6c155d33 217 for (i = 0; i < wxStrlen(wxTex2RTFBuffer); i++)
aed3314d
JS
218 if (wxTex2RTFBuffer[i] == ':')
219 wxTex2RTFBuffer[i] = ' ';
9a29912f 220 // Don't write to index if there's some RTF in the string
aed3314d 221 else if ( wxTex2RTFBuffer[i] == '{' )
9a29912f
JS
222 return;
223
6c155d33
JS
224 wxFprintf(fd, _T("K{\\footnote {K} "));
225 wxFprintf(fd, _T("%s"), wxTex2RTFBuffer);
254a2129 226
6c155d33 227 wxFprintf(fd, _T("}\n"));
9a29912f
JS
228}
229
230// Write a line for the .cnt file, if we're doing this.
6c155d33 231void WriteWinHelpContentsFileLine(wxChar *topicName, wxChar *xitle, int level)
9a29912f
JS
232{
233 // First, convert any RTF characters to ASCII
6c155d33 234 wxChar title[255];
9a29912f
JS
235 int s=0;
236 int d=0;
88fd7006 237 // assuming iso-8859-1 here even in Unicode build (FIXME?)
9a29912f
JS
238 while ( (xitle[s]!=0)&&(d<255) )
239 {
254a2129 240 wxChar ch=wxChar(xitle[s]&0xff);
4fe30bce 241 if (ch==0x5c) {
254a2129
WS
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
88fd7006
VS
246