X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9a29912f608e082001ee53b9873323c4bcd71f21..ef5df12bdf587773bcd0ac0e521af9fc9013a0c9:/utils/tex2rtf/src/htmlutil.cpp diff --git a/utils/tex2rtf/src/htmlutil.cpp b/utils/tex2rtf/src/htmlutil.cpp index a67bc10be4..1029c30603 100644 --- a/utils/tex2rtf/src/htmlutil.cpp +++ b/utils/tex2rtf/src/htmlutil.cpp @@ -28,8 +28,18 @@ #include "tex2rtf.h" #include "table.h" + +extern wxHashTable TexReferences; + + extern void DecToHex(int, char *); void GenerateHTMLIndexFile(char *fname); + +void GenerateHTMLWorkshopFiles(char *fname); +void HTMLWorkshopAddToContents(int level, char *s, char *file); +void HTMLWorkshopStartContents(); +void HTMLWorkshopEndContents(); + void OutputContentsFrame(void); #include "readshg.h" // Segmented hypergraphics parsing @@ -70,6 +80,11 @@ static bool inTable = FALSE; // This is defined in the Tex2Any library. extern char *BigBuffer; +// DHS Two-column table dimensions. +static int TwoColWidthA = -1; +static int TwoColWidthB = -1; + + class HyperReference: public wxObject { public: @@ -125,7 +140,7 @@ void SetCurrentChapterName(char *s, char *file) CurrentChapterFile = copystring(file); currentFileName = CurrentChapterFile; - + SetCurrentTopic(s); } void SetCurrentSectionName(char *s, char *file) @@ -166,7 +181,7 @@ void ReopenFile(FILE **fd, char **fileName) { if (*fd) { - fprintf(*fd, "\n\n"); + fprintf(*fd, "\n\n"); fclose(*fd); } fileId ++; @@ -176,7 +191,7 @@ void ReopenFile(FILE **fd, char **fileName) else sprintf(buf, "%s%d.html", FileRoot, fileId); if (*fileName) delete[] *fileName; - *fileName = copystring(FileNameFromPath(buf)); + *fileName = copystring(wxFileNameFromPath(buf)); *fd = fopen(buf, "w"); fprintf(*fd, "\n"); } @@ -219,7 +234,7 @@ void ReopenSectionContentsFile(void) * converting Latex-isms into HTML-isms, such as 2 newlines ->

. * */ - + void ProcessText2HTML(TexChunk *chunk) { bool changed = FALSE; @@ -291,7 +306,7 @@ void ProcessText2HTML(TexChunk *chunk) * and before TraverseDocument is called. * */ - + void Text2HTML(TexChunk *chunk) { Tex2RTFYield(); @@ -368,7 +383,7 @@ void AddBrowseButtons(char *upLabel, char *upFilename, contentsReference = contentsReferenceBuf; sprintf(contentsReference, "\"Contents\"", ConvertCase("contents.gif")); } - + char *upReference = NULL; if (htmlBrowseButtons == HTML_BUTTONS_TEXT) upReference = UpNameString; @@ -378,7 +393,7 @@ void AddBrowseButtons(char *upLabel, char *upFilename, upReference = upReferenceBuf; sprintf(upReference, "\"Up\"", ConvertCase("up.gif")); } - + char *backReference = NULL; if (htmlBrowseButtons == HTML_BUTTONS_TEXT) backReference = "<<"; @@ -388,7 +403,7 @@ void AddBrowseButtons(char *upLabel, char *upFilename, backReference = backReferenceBuf; sprintf(backReference, "\"Previous\"", ConvertCase("back.gif")); } - + char *forwardReference = NULL; if (htmlBrowseButtons == HTML_BUTTONS_TEXT) forwardReference = ">>"; @@ -398,9 +413,9 @@ void AddBrowseButtons(char *upLabel, char *upFilename, forwardReference = forwardReferenceBuf; sprintf(forwardReference, "\"Next\"", ConvertCase("forward.gif")); } - + TexOutput("

"); - + char buf[200]; /* @@ -411,13 +426,13 @@ void AddBrowseButtons(char *upLabel, char *upFilename, if (truncateFilenames) { char buf1[80]; - strcpy(buf1, ConvertCase(FileNameFromPath(FileRoot))); + strcpy(buf1, ConvertCase(wxFileNameFromPath(FileRoot))); sprintf(buf, "\n%s ", buf1, ConvertCase("htm"), contentsReference); } else { char buf1[80]; - strcpy(buf1, ConvertCase(FileNameFromPath(FileRoot))); + strcpy(buf1, ConvertCase(wxFileNameFromPath(FileRoot))); sprintf(buf, "\n%s ", buf1, ConvertCase("_contents.html"), contentsReference); } // TexOutput(""); @@ -550,9 +565,9 @@ char *ParseColourString(char *bkStr, bool *isPicture) int red = atoi(tok1); int green = atoi(tok2); int blue = atoi(tok3); - + strcpy(resStr, "#"); - + char buf[3]; DecToHex(red, buf); strcat(resStr, buf); @@ -568,6 +583,20 @@ char *ParseColourString(char *bkStr, bool *isPicture) else return NULL; } +void OutputFont(void) +{ + // Only output <font face> if explicitly requested by htmlFaceName= directive in + // tex2rtf.ini. Otherwise do NOT set the font because we want to use browser's + // default font: + if (htmlFaceName) + { + // Output <FONT FACE=...> + TexOutput("<FONT FACE=\""); + TexOutput(htmlFaceName); + TexOutput("\">\n"); + } +} + // Output start of <BODY> block void OutputBodyStart(void) { @@ -590,7 +619,7 @@ void OutputBodyStart(void) TexOutput(" BGCOLOR="); TexOutput(s); } } - + // Set foreground text colour, if one is specified if (textColourString) { @@ -622,6 +651,26 @@ void OutputBodyStart(void) } } TexOutput(">\n"); + + OutputFont(); +} + +void HTMLHead() +{ + TexOutput("<head>"); + if (htmlStylesheet) { + TexOutput("<link rel=stylesheet type=\"text/css\" href=\""); + TexOutput(htmlStylesheet); + TexOutput("\">"); + } +}; + +void HTMLHeadTo(FILE* f) +{ + if (htmlStylesheet) + fprintf(f,"<head><link rel=stylesheet type=\"text/css\" href=\"%s\">",htmlStylesheet); + else + fprintf(f,"<head>"); } // Called on start/end of macro examination @@ -650,22 +699,24 @@ void HTMLOnMacro(int macroId, int no_args, bool start) AddTexRef(topicName, ChaptersName, ChapterNameString); SetCurrentChapterName(topicName, ChaptersName); + if (htmlWorkshopFiles) HTMLWorkshopAddToContents(0, topicName, ChaptersName); SetCurrentOutput(Chapters); - TexOutput("<head><title>"); + HTMLHead(); + TexOutput("<title>"); OutputCurrentSection(); // Repeat section header TexOutput("</title></head>\n"); OutputBodyStart(); char titleBuf[200]; if (truncateFilenames) - sprintf(titleBuf, "%s.htm", FileNameFromPath(FileRoot)); + sprintf(titleBuf, "%s.htm", wxFileNameFromPath(FileRoot)); else - sprintf(titleBuf, "%s_contents.html", FileNameFromPath(FileRoot)); + sprintf(titleBuf, "%s_contents.html", wxFileNameFromPath(FileRoot)); fprintf(Chapters, "<A NAME=\"%s\"></A>", topicName); - + AddBrowseButtons("", titleBuf, // Up lastTopic, lastFileName, // Last topic topicName, ChaptersName); // This topic @@ -691,8 +742,8 @@ void HTMLOnMacro(int macroId, int no_args, bool start) // Add this section title to the list of keywords if (htmlIndex) { - OutputCurrentSectionToString(wxBuffer); - AddKeyWordForTopic(topicName, wxBuffer, ConvertCase(currentFileName)); + OutputCurrentSectionToString(wxTex2RTFBuffer); + AddKeyWordForTopic(topicName, wxTex2RTFBuffer, ConvertCase(currentFileName)); } } break; @@ -710,7 +761,7 @@ void HTMLOnMacro(int macroId, int no_args, bool start) if (macroId != ltSECTIONSTAR) sectionNo ++; - + SetCurrentOutput(NULL); startedSections = TRUE; @@ -719,9 +770,11 @@ void HTMLOnMacro(int macroId, int no_args, bool start) AddTexRef(topicName, SectionsName, SectionNameString); SetCurrentSectionName(topicName, SectionsName); + if (htmlWorkshopFiles) HTMLWorkshopAddToContents(1, topicName, SectionsName); SetCurrentOutput(Sections); - TexOutput("<head><title>"); + HTMLHead(); + TexOutput("<title>"); OutputCurrentSection(); TexOutput("</title></head>\n"); OutputBodyStart(); @@ -752,8 +805,8 @@ void HTMLOnMacro(int macroId, int no_args, bool start) // Add this section title to the list of keywords if (htmlIndex) { - OutputCurrentSectionToString(wxBuffer); - AddKeyWordForTopic(topicName, wxBuffer, currentFileName); + OutputCurrentSectionToString(wxTex2RTFBuffer); + AddKeyWordForTopic(topicName, wxTex2RTFBuffer, currentFileName); } } break; @@ -811,9 +864,11 @@ void HTMLOnMacro(int macroId, int no_args, bool start) ReopenFile(&Subsections, &SubsectionsName); AddTexRef(topicName, SubsectionsName, SubsectionNameString); SetCurrentSubsectionName(topicName, SubsectionsName); + if (htmlWorkshopFiles) HTMLWorkshopAddToContents(2, topicName, SubsectionsName); SetCurrentOutput(Subsections); - TexOutput("<head><title>"); + HTMLHead(); + TexOutput("<title>"); OutputCurrentSection(); TexOutput("</title></head>\n"); OutputBodyStart(); @@ -837,6 +892,7 @@ void HTMLOnMacro(int macroId, int no_args, bool start) { AddTexRef(topicName, SectionsName, SubsectionNameString); SetCurrentSubsectionName(topicName, SectionsName); + // if ( subsectionNo != 0 ) fprintf(Sections, "\n<HR>\n"); @@ -851,13 +907,14 @@ void HTMLOnMacro(int macroId, int no_args, bool start) OutputCurrentSection(); TexOutput("</A><BR>\n"); + if (htmlWorkshopFiles) HTMLWorkshopAddToContents(2, topicName, SectionsName); SetCurrentOutput(Sections); } // Add this section title to the list of keywords if (htmlIndex) { - OutputCurrentSectionToString(wxBuffer); - AddKeyWordForTopic(topicName, wxBuffer, currentFileName); + OutputCurrentSectionToString(wxTex2RTFBuffer); + AddKeyWordForTopic(topicName, wxTex2RTFBuffer, currentFileName); } } @@ -888,9 +945,11 @@ void HTMLOnMacro(int macroId, int no_args, bool start) ReopenFile(&Subsubsections, &SubsubsectionsName); AddTexRef(topicName, SubsubsectionsName, SubsubsectionNameString); SetCurrentSubsubsectionName(topicName, SubsubsectionsName); + if (htmlWorkshopFiles) HTMLWorkshopAddToContents(3, topicName, SubsubsectionsName); SetCurrentOutput(Subsubsections); - TexOutput("<head><title>"); + HTMLHead(); + TexOutput("<title>"); OutputCurrentSection(); TexOutput("</title></head>\n"); OutputBodyStart(); @@ -926,14 +985,15 @@ void HTMLOnMacro(int macroId, int no_args, bool start) OutputCurrentSection(); TexOutput("</A><BR>"); */ + if (htmlWorkshopFiles) HTMLWorkshopAddToContents(2, topicName, SectionsName); SetCurrentOutput(Sections); } // Add this section title to the list of keywords if (htmlIndex) { - OutputCurrentSectionToString(wxBuffer); - AddKeyWordForTopic(topicName, wxBuffer, currentFileName); + OutputCurrentSectionToString(wxTex2RTFBuffer); + AddKeyWordForTopic(topicName, wxTex2RTFBuffer, currentFileName); } } } @@ -1005,8 +1065,9 @@ void HTMLOnMacro(int macroId, int no_args, bool start) if (inTabular) { // End cell, start cell - TexOutput("</TD>"); - + + TexOutput("</FONT></TD>"); + // Start new row and cell, setting alignment for the first cell. if (currentColumn < noColumns) currentColumn ++; @@ -1020,7 +1081,7 @@ void HTMLOnMacro(int macroId, int no_args, bool start) { // Convert from points * 20 into pixels. int points = TableData[currentColumn].width / 20; - + // Say the display is 100 DPI (dots/pixels per inch). // There are 72 pts to the inch. So 1pt = 1/72 inch, or 100 * 1/72 dots. int pixels = (int)(points * 100.0 / 72.0); @@ -1029,6 +1090,7 @@ void HTMLOnMacro(int macroId, int no_args, bool start) else sprintf(buf, "\n<TD ALIGN=LEFT>"); TexOutput(buf); + OutputFont(); } else TexOutput("&amp;"); @@ -1057,7 +1119,7 @@ void HTMLOnMacro(int macroId, int no_args, bool start) if (start) { currentColumn = 0; - + // Start new row and cell, setting alignment for the first cell. char buf[100]; if (TableData[currentColumn].justification == 'c') @@ -1068,7 +1130,7 @@ void HTMLOnMacro(int macroId, int no_args, bool start) { // Convert from points * 20 into pixels. int points = TableData[currentColumn].width / 20; - + // Say the display is 100 DPI (dots/pixels per inch). // There are 72 pts to the inch. So 1pt = 1/72 inch, or 100 * 1/72 dots. int pixels = (int)(points * 100.0 / 72.0); @@ -1077,12 +1139,13 @@ void HTMLOnMacro(int macroId, int no_args, bool start) else sprintf(buf, "<TR>\n<TD ALIGN=LEFT>"); TexOutput(buf); + OutputFont(); } else { // End cell and row // Start new row and cell - TexOutput("</TD>\n</TR>\n"); + TexOutput("</FONT></TD>\n</TR>\n"); } break; } @@ -1176,8 +1239,12 @@ void HTMLOnMacro(int macroId, int no_args, bool start) { if ( start ) TexOutput("\n<TABLE>\n"); - else + else { TexOutput("\n</TABLE>\n"); + // DHS + TwoColWidthA = -1; + TwoColWidthB = -1; + } break; } case ltPAR: @@ -1466,7 +1533,7 @@ void HTMLOnMacro(int macroId, int no_args, bool start) if (htmlFrameContents && FrameContents) { SetCurrentOutput(FrameContents); - + // Add a special label for the contents page. TexOutput("<CENTER>\n"); TexOutput("<H3>\n"); @@ -1486,7 +1553,7 @@ void HTMLOnMacro(int macroId, int no_args, bool start) } TexOutput("\n</CENTER>\n"); TexOutput("<P><HR><P>\n"); - + SetCurrentOutput(Titlepage); } */ @@ -1688,7 +1755,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) { if (!suppressNameDecoration) TexOutput("</B>"); } - + if (start && (arg_no == 3)) TexOutput("("); if (!start && (arg_no == 3)) @@ -1780,7 +1847,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) if (start) { char *sec = NULL; - + char *refName = GetArgData(); if (refName) { @@ -1880,7 +1947,11 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) { if (helpRefText) TraverseChildrenFromChunk(helpRefText); - TexOutput(" (REF NOT FOUND)"); + if (!ignoreBadRefs) + TexOutput(" (REF NOT FOUND)"); + wxString errBuf; + errBuf.Printf("Warning: unresolved reference '%s'", refName); + OnInform((char *)errBuf.c_str()); } } else TexOutput("??"); @@ -1903,11 +1974,11 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) alignment = " align=left"; else if (macroId == ltIMAGER) alignment = " align=right"; - + // Try to find an XBM or GIF image first. char *filename = copystring(GetArgData()); char buf[500]; - + strcpy(buf, filename); StripExtension(buf); strcat(buf, ".xbm"); @@ -1920,6 +1991,23 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) strcat(buf, ".gif"); f = TexPathList.FindValidPath(buf); } + + if (f == "") // Try for a JPEG instead + { + strcpy(buf, filename); + StripExtension(buf); + strcat(buf, ".jpg"); + f = TexPathList.FindValidPath(buf); + } + + if (f == "") // Try for a PNG instead + { + strcpy(buf, filename); + StripExtension(buf); + strcat(buf, ".png"); + f = TexPathList.FindValidPath(buf); + } + if (f != "") { char *inlineFilename = copystring(f); @@ -1941,7 +2029,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) { TexOutput("<img src=\""); TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename))); - TexOutput("\""); TexOutput(alignment); TexOutput("></A>"); + TexOutput("\""); TexOutput(alignment); TexOutput(">"); delete[] inlineFilename; } } @@ -1968,7 +2056,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) // Try to find an XBM or GIF image first. char *filename = copystring(GetArgData()); char buf[500]; - + strcpy(buf, filename); StripExtension(buf); strcat(buf, ".xbm"); @@ -1991,7 +2079,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) if (imageFile) delete[] imageFile; imageFile = NULL; - if (f) + if (!f.IsEmpty()) { imageFile = copystring(f); } @@ -2047,6 +2135,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) descriptionItemArg = GetArgChunk(); return FALSE; } + return TRUE; } case ltTWOCOLITEM: case ltTWOCOLITEMRULED: @@ -2059,17 +2148,31 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) */ if (arg_no == 1) { - if ( start ) - TexOutput("\n<TR><TD VALIGN=TOP>\n"); - else - TexOutput("\n</TD>\n"); + if ( start ) { + // DHS + if (TwoColWidthA > -1) { + char buf[100]; + sprintf(buf,"\n<TR><TD VALIGN=TOP WIDTH=%d>\n",TwoColWidthA); + TexOutput(buf); + } else + TexOutput("\n<TR><TD VALIGN=TOP>\n"); + OutputFont(); + } else + TexOutput("\n</FONT></TD>\n"); } if (arg_no == 2) { - if ( start ) - TexOutput("\n<TD VALIGN=TOP>\n"); - else - TexOutput("\n</TD></TR>\n"); + // DHS + if ( start ) { + if (TwoColWidthB > -1) { + char buf[100]; + sprintf(buf,"\n<TD VALIGN=TOP WIDTH=%d>\n",TwoColWidthB); + TexOutput(buf); + } else + TexOutput("\n<TD VALIGN=TOP>\n"); + OutputFont(); + } else + TexOutput("\n</FONT></TD></TR>\n"); } return TRUE; break; @@ -2123,6 +2226,30 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) TexOutput("<HR><P>\n"); break; } + // DHS + case ltTWOCOLWIDTHA: + { + if (start) + { + char *val = GetArgData(); + float points = ParseUnitArgument(val); + TwoColWidthA = (int)((points * 100.0) / 72.0); + } + return FALSE; + break; + } + // DHS + case ltTWOCOLWIDTHB: + { + if (start) + { + char *val = GetArgData(); + float points = ParseUnitArgument(val); + TwoColWidthB = (int)((points * 100.0) / 72.0); + } + return FALSE; + break; + } /* * Accents * @@ -2522,7 +2649,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) return FALSE; break; } -*/ +*/ case ltTABULAR: case ltSUPERTABULAR: { @@ -2547,6 +2674,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) if (compatibilityMode) { TexOutput("<TR>\n<TD>"); + OutputFont(); /* for (int i = 0; i < noColumns; i++) { @@ -2583,11 +2711,12 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) char titleBuf[150]; if (truncateFilenames) - sprintf(titleBuf, "%s.htm", FileNameFromPath(FileRoot)); + sprintf(titleBuf, "%s.htm", wxFileNameFromPath(FileRoot)); else - sprintf(titleBuf, "%s_contents.html", FileNameFromPath(FileRoot)); + sprintf(titleBuf, "%s_contents.html", wxFileNameFromPath(FileRoot)); - TexOutput("<head><title>"); + HTMLHead(); + TexOutput("<title>"); TexOutput(ReferencesNameString); TexOutput("</title></head>\n"); OutputBodyStart(); @@ -2771,7 +2900,7 @@ bool HTMLGo(void) if (TitlepageName) delete[] TitlepageName; TitlepageName = copystring(buf); Titlepage = fopen(buf, "w"); - + if (truncateFilenames) sprintf(buf, "%s_fc.htm", FileRoot); else @@ -2793,13 +2922,14 @@ bool HTMLGo(void) OnError("Cannot open output file!"); return FALSE; } - AddTexRef("contents", FileNameFromPath(TitlepageName), ContentsNameString); + AddTexRef("contents", wxFileNameFromPath(TitlepageName), ContentsNameString); fprintf(Contents, "<P><P><H2>%s</H2><P><P>\n", ContentsNameString); fprintf(Contents, "<UL>\n"); SetCurrentOutput(Titlepage); + if (htmlWorkshopFiles) HTMLWorkshopStartContents(); OnInform("Converting..."); TraverseDocument(); @@ -2825,25 +2955,25 @@ bool HTMLGo(void) if (Chapters) { - fprintf(Chapters, "\n</BODY></HTML>\n"); + fprintf(Chapters, "\n</FONT></BODY></HTML>\n"); fclose(Chapters); Chapters = NULL; } if (Sections) { - fprintf(Sections, "\n</BODY></HTML>\n"); + fprintf(Sections, "\n</FONT></BODY></HTML>\n"); fclose(Sections); Sections = NULL; } if (Subsections && !combineSubSections) { - fprintf(Subsections, "\n</BODY></HTML>\n"); + fprintf(Subsections, "\n</FONT></BODY></HTML>\n"); fclose(Subsections); Subsections = NULL; } if (Subsubsections && !combineSubSections) { - fprintf(Subsubsections, "\n</BODY></HTML>\n"); + fprintf(Subsubsections, "\n</FONT></BODY></HTML>\n"); fclose(Subsubsections); Subsubsections = NULL; } @@ -2864,19 +2994,21 @@ bool HTMLGo(void) if (DocumentTitle) { SetCurrentOutput(tmpTitle); - TexOutput("\n<HTML>\n<HEAD><TITLE>"); + HTMLHead(); + TexOutput("\n<HEAD><TITLE>"); TraverseChildrenFromChunk(DocumentTitle); TexOutput("</TITLE></HEAD>\n"); } else { SetCurrentOutput(tmpTitle); + HTMLHeadTo(tmpTitle); if (contentsString) - fprintf(tmpTitle, "<HEAD><TITLE>%s</TITLE></HEAD>\n\n", contentsString); + fprintf(tmpTitle, "<TITLE>%s</TITLE></HEAD>\n\n", contentsString); else - fprintf(tmpTitle, "<HEAD><TITLE>%s</TITLE></HEAD>\n\n", FileNameFromPath(FileRoot)); + fprintf(tmpTitle, "<TITLE>%s</TITLE></HEAD>\n\n", wxFileNameFromPath(FileRoot)); } - + // Output frame information if (htmlFrameContents) { @@ -2888,16 +3020,16 @@ bool HTMLGo(void) fprintf(tmpTitle, "<FRAMESET COLS=\"30%%,70%%\">\n"); - fprintf(tmpTitle, "<FRAME SRC=\"%s\">\n", ConvertCase(FileNameFromPath(contentsFrameName))); - fprintf(tmpTitle, "<FRAME SRC=\"%s\" NAME=\"mainwindow\">\n", ConvertCase(FileNameFromPath(firstFileName))); + fprintf(tmpTitle, "<FRAME SRC=\"%s\">\n", ConvertCase(wxFileNameFromPath(contentsFrameName))); + fprintf(tmpTitle, "<FRAME SRC=\"%s\" NAME=\"mainwindow\">\n", ConvertCase(wxFileNameFromPath(firstFileName))); fprintf(tmpTitle, "</FRAMESET>\n"); - + fprintf(tmpTitle, "<NOFRAMES>\n"); } // Output <BODY...> to temporary title page OutputBodyStart(); - + // Concat titlepage FILE *fd = fopen(TitlepageName, "r"); if (fd) @@ -2911,7 +3043,7 @@ bool HTMLGo(void) fclose(fd); } - fprintf(tmpTitle, "\n</BODY>\n"); + fprintf(tmpTitle, "\n</FONT></BODY>\n"); if (htmlFrameContents) { @@ -2920,7 +3052,7 @@ bool HTMLGo(void) fprintf(tmpTitle, "\n</HTML>\n"); fclose(tmpTitle); - if (FileExists(TitlepageName)) wxRemoveFile(TitlepageName); + if (wxFileExists(TitlepageName)) wxRemoveFile(TitlepageName); if (!wxRenameFile("title.tmp", TitlepageName)) { wxCopyFile("title.tmp", TitlepageName); @@ -2933,7 +3065,7 @@ bool HTMLGo(void) if (lastTopic) delete[] lastTopic; lastTopic = NULL; - if (FileExists(ContentsName)) wxRemoveFile(ContentsName); + if (wxFileExists(ContentsName)) wxRemoveFile(ContentsName); if (!wxRenameFile(TmpContentsName, ContentsName)) { @@ -2949,8 +3081,17 @@ bool HTMLGo(void) GenerateHTMLIndexFile(htmlIndexName); } + // Generate HTML Help Workshop files if requested + if (htmlWorkshopFiles) + { + HTMLWorkshopEndContents(); + GenerateHTMLWorkshopFiles(FileRoot); + } + + return TRUE; } + return FALSE; } @@ -2980,3 +3121,175 @@ void GenerateHTMLIndexFile(char *fname) } fclose(fd); } + + + + + + + +// output .hpp, .hhc and .hhk files: + + +void GenerateHTMLWorkshopFiles(char *fname) +{ + FILE *f; + char buf[300]; + + /* Generate project file : */ + + sprintf(buf, "%s.hhp", fname); + f = fopen(buf, "wt"); + fprintf(f, + "[OPTIONS]\n" + "Compatibility=1.1\n" + "Full-text search=Yes\n" + "Contents file=%s.hhc\n" + "Compiled file=%s.chm\n" + "Default Window=%sHelp\n" + "Default topic=%s\n" + "Index file=%s.hhk\n" + "Title=", + wxFileNameFromPath(fname), + wxFileNameFromPath(fname), + wxFileNameFromPath(fname), + wxFileNameFromPath(TitlepageName), + wxFileNameFromPath(fname) + ); + + if (DocumentTitle) { + SetCurrentOutput(f); + TraverseChildrenFromChunk(DocumentTitle); + } + else fprintf(f, "(unknown)"); + + fprintf(f, "\n\n[WINDOWS]\n" + "%sHelp=,\"%s.hhc\",\"%s.hhk\",\"%s\",,,,,,0x2420,,0x380e,,,,,0,,,", + wxFileNameFromPath(fname), + wxFileNameFromPath(fname), + wxFileNameFromPath(fname), + wxFileNameFromPath(TitlepageName)); + + + fprintf(f, "\n\n[FILES]\n"); + fprintf(f, "%s\n", wxFileNameFromPath(TitlepageName)); + for (int i = 1; i <= fileId; i++) { + if (truncateFilenames) + sprintf(buf, "%s%d.htm", wxFileNameFromPath(FileRoot), i); + else + sprintf(buf, "%s%d.html", wxFileNameFromPath(FileRoot), i); + fprintf(f, "%s\n", buf); + } + fclose(f); + + /* Generate index file : */ + + sprintf(buf, "%s.hhk", fname); + f = fopen(buf, "wt"); + + fprintf(f, + "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n" + "<HTML>\n"); + HTMLHeadTo(f); + fprintf(f, + "\n" + "<meta name=\"GENERATOR\" content=\"tex2rtf\">\n" + "<!-- Sitemap 1.0 -->\n" + "</HEAD><BODY>\n" + "<OBJECT type=\"text/site properties\">\n" + " <param name=\"ImageType\" value=\"Folder\">\n" + "</OBJECT>\n" + "<UL>\n"); + + TopicTable.BeginFind(); + wxNode *node = NULL; + while ((node = TopicTable.Next())) + { + TexTopic *texTopic = (TexTopic *)node->Data(); + const char *topicName = node->GetKeyString(); + if (texTopic->filename && texTopic->keywords) + { + wxNode *node1 = texTopic->keywords->First(); + while (node1) + { + char *s = (char *)node1->Data(); + fprintf(f, + " <LI> <OBJECT type=\"text/sitemap\">\n" + " <param name=\"Local\" value=\"%s#%s\">\n" + " <param name=\"Name\" value=\"%s\">\n" + " </OBJECT>\n", + texTopic->filename, topicName, s); + node1 = node1->Next(); + } + } + } + + fprintf(f, "</UL>\n"); + fclose(f); +} + + + +static FILE *HTMLWorkshopContents = NULL; +static int HTMLWorkshopLastLevel = 0; + +void HTMLWorkshopAddToContents(int level, char *s, char *file) +{ + int i; + + if (level > HTMLWorkshopLastLevel) + for (i = HTMLWorkshopLastLevel; i < level; i++) + fprintf(HTMLWorkshopContents, "<UL>"); + if (level < HTMLWorkshopLastLevel) + for (i = level; i < HTMLWorkshopLastLevel; i++) + fprintf(HTMLWorkshopContents, "</UL>"); + + SetCurrentOutput(HTMLWorkshopContents); + fprintf(HTMLWorkshopContents, + " <LI> <OBJECT type=\"text/sitemap\">\n" + " <param name=\"Local\" value=\"%s#%s\">\n" + " <param name=\"Name\" value=\"", + file, s); + OutputCurrentSection(); + fprintf(HTMLWorkshopContents, + "\">\n" + " </OBJECT>\n"); + HTMLWorkshopLastLevel = level; +} + + +void HTMLWorkshopStartContents() +{ + char buf[300]; + sprintf(buf, "%s.hhc", FileRoot); + HTMLWorkshopContents = fopen(buf, "wt"); + HTMLWorkshopLastLevel = 0; + + fprintf(HTMLWorkshopContents, + "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n" + "<HTML>\n"); + HTMLHeadTo(HTMLWorkshopContents); + fprintf(HTMLWorkshopContents, + "\n" + "<meta name=\"GENERATOR\" content=\"tex2rtf\">\n" + "<!-- Sitemap 1.0 -->\n" + "</HEAD><BODY>\n" + "<OBJECT type=\"text/site properties\">\n" + " <param name=\"ImageType\" value=\"Folder\">\n" + "</OBJECT>\n" + "<UL>\n" + "<LI> <OBJECT type=\"text/sitemap\">\n" + "<param name=\"Local\" value=\"%s\">\n" + "<param name=\"Name\" value=\"Contents\">\n</OBJECT>\n", + wxFileNameFromPath(TitlepageName) + ); + +} + + +void HTMLWorkshopEndContents() +{ + for (int i = HTMLWorkshopLastLevel; i >= 0; i--) + fprintf(HTMLWorkshopContents, "</UL>\n"); + fclose(HTMLWorkshopContents); +}