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