⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rtfutils.cpp

📁 Wxpython Implemented on Windows CE, Source code
💻 CPP
字号:
/////////////////////////////////////////////////////////////////////////////
// Name:        rtfutils.cpp
// Purpose:     Converts Latex to Word RTF/WinHelp RTF
// Author:      Julian Smart
// Modified by: Wlodzimiez ABX Skiba 2003/2004 Unicode support
//              Ron Lee
// Created:     7.9.93
// RCS-ID:      $Id: rtfutils.cpp,v 1.28 2005/11/07 13:27:09 ABX Exp $
// Copyright:   (c) Julian Smart
// Licence:     wxWindows licence
/////////////////////////////////////////////////////////////////////////////

// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
#pragma hdrstop
#endif

#ifndef WX_PRECOMP
#endif

#include "tex2any.h"
#include "tex2rtf.h"
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>

#ifdef __WIN32__
#include <windows.h>
#endif

#include "bmputils.h"
#include "table.h"

#if !WXWIN_COMPATIBILITY_2_4
static inline wxChar* copystring(const wxChar* s)
    { return wxStrcpy(new wxChar[wxStrlen(s) + 1], s); }
#endif

wxList itemizeStack;
static int indentLevel = 0;
static int forbidParindent = 0; // if > 0, no parindent (e.g. in center environment)
int forbidResetPar = 0; // If > 0, don't reset memory of having output a new par

static wxChar *contentsLineSection = NULL;
static wxChar *contentsLineValue = NULL;
static TexChunk *descriptionItemArg = NULL;
static wxStringList environmentStack; // Stack of paragraph styles we need to remember
static int footnoteCount = 0;
static int citeCount = 1;
extern bool winHelp;
extern bool startedSections;
extern FILE *Contents;
extern FILE *Chapters;
extern FILE *Popups;
extern FILE *WinHelpContentsFile;
extern wxChar *RTFCharset;
// This is defined in the Tex2Any library and isn't in use after parsing
extern wxChar *BigBuffer;

extern wxHashTable TexReferences;

// Are we in verbatim mode? If so, format differently.
static bool inVerbatim = false;

// We're in a series of PopRef topics, so don't output section headings
bool inPopRefSection = false;

// Green colour?
static bool hotSpotColour = true;
static bool hotSpotUnderline = true;

// Transparency (WHITE = transparent)
static bool bitmapTransparency = true;

// Linear RTF requires us to set the style per section.
static wxChar *currentNumberStyle = NULL;
static int currentItemSep = 8;
static int CurrentTextWidth = 8640; // Say, six inches
static int CurrentLeftMarginOdd = 400;
static int CurrentLeftMarginEven = 1440;
static int CurrentRightMarginOdd = 1440;
static int CurrentRightMarginEven = 400;
static int CurrentMarginParWidth = 2000;
static int CurrentMarginParSep = 400;  // Gap between marginpar and text
static int CurrentMarginParX = CurrentLeftMarginOdd + CurrentTextWidth + CurrentMarginParSep;
static int GutterWidth = 2300;

// Two-column table dimensions, in twips
static int TwoColWidthA = 1500;
static int TwoColWidthB = 3000;

const int PageWidth = 12242; // 8.25 inches wide for A4

// Remember the anchor in a helpref
static TexChunk *helpRefText = NULL;

/*
 * Flag to say we've just issued a \par\pard command, so don't
 * repeat this unnecessarily.
 *
 */

int issuedNewParagraph = 0;

// Need to know whether we're in a table or figure for benefit
// of listoffigures/listoftables
static bool inFigure = false;
static bool inTable = false;

/*
 * Current topics
 *
 */
static wxChar *CurrentChapterName = NULL;
static wxChar *CurrentSectionName = NULL;
static wxChar *CurrentSubsectionName = NULL;
static wxChar *CurrentTopic = NULL;

static bool InPopups()
{
  if (CurrentChapterName && (wxStrcmp(CurrentChapterName, _T("popups")) == 0))
    return true;
  if (CurrentSectionName && (wxStrcmp(CurrentSectionName, _T("popups")) == 0))
    return true;
  return false;
}

static void SetCurrentTopic(wxChar *s)
{
  if (CurrentTopic) delete[] CurrentTopic;
  CurrentTopic = copystring(s);
}

void SetCurrentChapterName(wxChar *s)
{
  if (CurrentChapterName) delete[] CurrentChapterName;
  CurrentChapterName = copystring(s);
  SetCurrentTopic(s);
}
void SetCurrentSectionName(wxChar *s)
{
  if (CurrentSectionName) delete[] CurrentSectionName;
  CurrentSectionName = copystring(s);
  SetCurrentTopic(s);
}
void SetCurrentSubsectionName(wxChar *s)
{
  if (CurrentSubsectionName) delete[] CurrentSubsectionName;
  CurrentSubsectionName = copystring(s);
  SetCurrentTopic(s);
}

// Indicate that a parent topic at level 'level' has children.
// Level 1 is a chapter, 2 is a section, etc.
void NotifyParentHasChildren(int parentLevel)
{
  wxChar *parentTopic = NULL;
  switch (parentLevel)
  {
    case 1:
    {
      parentTopic = CurrentChapterName;
      break;
    }
    case 2:
    {
      parentTopic = CurrentSectionName;
      break;
    }
    case 3:
    {
      parentTopic = CurrentSubsectionName;
      break;
    }
    default:
    {
      break;
    }
  }
  if (parentTopic)
  {
    TexTopic *texTopic = (TexTopic *)TopicTable.Get(parentTopic);
    if (!texTopic)
    {
      texTopic = new TexTopic;
      TopicTable.Put(parentTopic, texTopic);
    }
    texTopic->hasChildren = true;
  }
}

// Have to keep a count of what levels are books, what are pages,
// in order to correct for a Win95 bug which means that if you
// have a book at level n, and then a page at level n, the page
// ends up on level n + 1.

bool ContentsLevels[5];

// Reset below this level (starts from 1)
void ResetContentsLevels(int l)
{
  int i;
  for (i = l; i < 5; i++)
    ContentsLevels[i] = false;

  // There are always books on the top level
  ContentsLevels[0] = true;
}

// Output a WinHelp section as a keyword, substituting
// : for space.
void OutputSectionKeyword(FILE *fd)
{
  OutputCurrentSectionToString(wxTex2RTFBuffer);

  unsigned int i;
  for (i = 0; i < wxStrlen(wxTex2RTFBuffer); i++)
    if (wxTex2RTFBuffer[i] == ':')
      wxTex2RTFBuffer[i] = ' ';
    // Don't write to index if there's some RTF in the string
    else if ( wxTex2RTFBuffer[i] == '{' )
        return;

  wxFprintf(fd, _T("K{\\footnote {K} "));
  wxFprintf(fd, _T("%s"), wxTex2RTFBuffer);

  wxFprintf(fd, _T("}\n"));
}

// Write a line for the .cnt file, if we're doing this.
void WriteWinHelpContentsFileLine(wxChar *topicName, wxChar *xitle, int level)
{
  // First, convert any RTF characters to ASCII
  wxChar title[255];
  int s=0;
  int d=0;
  // assuming iso-8859-1 here even in Unicode build (FIXME?)
  while ( (xitle[s]!=0)&&(d<255) )
  {
    wxChar ch=wxChar(xitle[s]&0xff);
    if (ch==0x5c) {
      wxChar ch1=wxChar(xitle[s+1]&0xff);
      wxChar ch2=wxChar(xitle[s+2]&0xff);
      wxChar ch3=wxChar(xitle[s+3]&0xff);
      s+=4; // next character
      if ((ch1==0x27)&&(ch2==0x66)&&(ch3==0x36)) { title[d++]=wxChar('

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -