X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/14204c7acc3f89b59b07580da7da3448fb49f23b..5d35dca95fed224817455e65e70f9f52ca3e293c:/utils/tex2rtf/src/htmlutil.cpp diff --git a/utils/tex2rtf/src/htmlutil.cpp b/utils/tex2rtf/src/htmlutil.cpp index 654b1d7a14..2ba1279576 100644 --- a/utils/tex2rtf/src/htmlutil.cpp +++ b/utils/tex2rtf/src/htmlutil.cpp @@ -28,6 +28,10 @@ #include "tex2rtf.h" #include "table.h" + +extern wxHashTable TexReferences; + + extern void DecToHex(int, char *); void GenerateHTMLIndexFile(char *fname); @@ -76,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: @@ -131,7 +140,7 @@ void SetCurrentChapterName(char *s, char *file) CurrentChapterFile = copystring(file); currentFileName = CurrentChapterFile; - + SetCurrentTopic(s); } void SetCurrentSectionName(char *s, char *file) @@ -172,7 +181,7 @@ void ReopenFile(FILE **fd, char **fileName) { if (*fd) { - fprintf(*fd, "\n\n"); + fprintf(*fd, "\n\n"); fclose(*fd); } fileId ++; @@ -225,7 +234,7 @@ void ReopenSectionContentsFile(void) * converting Latex-isms into HTML-isms, such as 2 newlines ->

. * */ - + void ProcessText2HTML(TexChunk *chunk) { bool changed = FALSE; @@ -297,7 +306,7 @@ void ProcessText2HTML(TexChunk *chunk) * and before TraverseDocument is called. * */ - + void Text2HTML(TexChunk *chunk) { Tex2RTFYield(); @@ -374,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; @@ -384,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 = "<<"; @@ -394,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 = ">>"; @@ -404,9 +413,9 @@ void AddBrowseButtons(char *upLabel, char *upFilename, forwardReference = forwardReferenceBuf; sprintf(forwardReference, "\"Next\"", ConvertCase("forward.gif")); } - + TexOutput("

"); - + char buf[200]; /* @@ -556,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); @@ -574,6 +583,17 @@ char *ParseColourString(char *bkStr, bool *isPicture) else return NULL; } +void OutputFont(void) +{ + // Output + TexOutput("\n"); +} + // Output start of block void OutputBodyStart(void) { @@ -596,7 +616,7 @@ void OutputBodyStart(void) TexOutput(" BGCOLOR="); TexOutput(s); } } - + // Set foreground text colour, if one is specified if (textColourString) { @@ -628,6 +648,8 @@ void OutputBodyStart(void) } } TexOutput(">\n"); + + OutputFont(); } // Called on start/end of macro examination @@ -672,7 +694,7 @@ void HTMLOnMacro(int macroId, int no_args, bool start) sprintf(titleBuf, "%s_contents.html", FileNameFromPath(FileRoot)); fprintf(Chapters, "", topicName); - + AddBrowseButtons("", titleBuf, // Up lastTopic, lastFileName, // Last topic topicName, ChaptersName); // This topic @@ -717,7 +739,7 @@ void HTMLOnMacro(int macroId, int no_args, bool start) if (macroId != ltSECTIONSTAR) sectionNo ++; - + SetCurrentOutput(NULL); startedSections = TRUE; @@ -938,7 +960,7 @@ void HTMLOnMacro(int macroId, int no_args, bool start) OutputCurrentSection(); TexOutput("
"); */ - if (htmlWorkshopFiles) HTMLWorkshopAddToContents(2, topicName, SectionsName); + if (htmlWorkshopFiles) HTMLWorkshopAddToContents(2, topicName, SectionsName); SetCurrentOutput(Sections); } @@ -1018,8 +1040,9 @@ void HTMLOnMacro(int macroId, int no_args, bool start) if (inTabular) { // End cell, start cell - TexOutput(""); - + + TexOutput("
"); + // Start new row and cell, setting alignment for the first cell. if (currentColumn < noColumns) currentColumn ++; @@ -1033,7 +1056,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); @@ -1042,6 +1065,7 @@ void HTMLOnMacro(int macroId, int no_args, bool start) else sprintf(buf, "\n"); TexOutput(buf); + OutputFont(); } else TexOutput("&"); @@ -1070,7 +1094,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') @@ -1081,7 +1105,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); @@ -1090,12 +1114,13 @@ void HTMLOnMacro(int macroId, int no_args, bool start) else sprintf(buf, "\n"); TexOutput(buf); + OutputFont(); } else { // End cell and row // Start new row and cell - TexOutput("\n\n"); + TexOutput("
\n\n"); } break; } @@ -1189,8 +1214,12 @@ void HTMLOnMacro(int macroId, int no_args, bool start) { if ( start ) TexOutput("\n\n"); - else + else { TexOutput("\n
\n"); + // DHS + TwoColWidthA = -1; + TwoColWidthB = -1; + } break; } case ltPAR: @@ -1479,7 +1508,7 @@ void HTMLOnMacro(int macroId, int no_args, bool start) if (htmlFrameContents && FrameContents) { SetCurrentOutput(FrameContents); - + // Add a special label for the contents page. TexOutput("
\n"); TexOutput("

\n"); @@ -1499,7 +1528,7 @@ void HTMLOnMacro(int macroId, int no_args, bool start) } TexOutput("\n

\n"); TexOutput("


\n"); - + SetCurrentOutput(Titlepage); } */ @@ -1701,7 +1730,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) { if (!suppressNameDecoration) TexOutput(""); } - + if (start && (arg_no == 3)) TexOutput("("); if (!start && (arg_no == 3)) @@ -1793,7 +1822,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) if (start) { char *sec = NULL; - + char *refName = GetArgData(); if (refName) { @@ -1893,7 +1922,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("??"); @@ -1916,11 +1949,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"); @@ -1998,7 +2031,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"); @@ -2021,7 +2054,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) if (imageFile) delete[] imageFile; imageFile = NULL; - if (f) + if (!f.IsEmpty()) { imageFile = copystring(f); } @@ -2077,6 +2110,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) descriptionItemArg = GetArgChunk(); return FALSE; } + return TRUE; } case ltTWOCOLITEM: case ltTWOCOLITEMRULED: @@ -2089,17 +2123,31 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) */ if (arg_no == 1) { - if ( start ) - TexOutput("\n\n"); - else - TexOutput("\n\n"); + if ( start ) { + // DHS + if (TwoColWidthA > -1) { + char buf[100]; + sprintf(buf,"\n\n",TwoColWidthA); + TexOutput(buf); + } else + TexOutput("\n\n"); + OutputFont(); + } else + TexOutput("\n\n"); } if (arg_no == 2) { - if ( start ) - TexOutput("\n\n"); - else - TexOutput("\n\n"); + // DHS + if ( start ) { + if (TwoColWidthB > -1) { + char buf[100]; + sprintf(buf,"\n\n",TwoColWidthB); + TexOutput(buf); + } else + TexOutput("\n\n"); + OutputFont(); + } else + TexOutput("\n\n"); } return TRUE; break; @@ -2153,6 +2201,30 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) TexOutput("


\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 * @@ -2552,7 +2624,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) return FALSE; break; } -*/ +*/ case ltTABULAR: case ltSUPERTABULAR: { @@ -2577,6 +2649,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) if (compatibilityMode) { TexOutput("\n"); + OutputFont(); /* for (int i = 0; i < noColumns; i++) { @@ -2801,7 +2874,7 @@ bool HTMLGo(void) if (TitlepageName) delete[] TitlepageName; TitlepageName = copystring(buf); Titlepage = fopen(buf, "w"); - + if (truncateFilenames) sprintf(buf, "%s_fc.htm", FileRoot); else @@ -2856,25 +2929,25 @@ bool HTMLGo(void) if (Chapters) { - fprintf(Chapters, "\n\n"); + fprintf(Chapters, "\n\n"); fclose(Chapters); Chapters = NULL; } if (Sections) { - fprintf(Sections, "\n\n"); + fprintf(Sections, "\n\n"); fclose(Sections); Sections = NULL; } if (Subsections && !combineSubSections) { - fprintf(Subsections, "\n\n"); + fprintf(Subsections, "\n\n"); fclose(Subsections); Subsections = NULL; } if (Subsubsections && !combineSubSections) { - fprintf(Subsubsections, "\n\n"); + fprintf(Subsubsections, "\n\n"); fclose(Subsubsections); Subsubsections = NULL; } @@ -2907,7 +2980,7 @@ bool HTMLGo(void) else fprintf(tmpTitle, "%s\n\n", FileNameFromPath(FileRoot)); } - + // Output frame information if (htmlFrameContents) { @@ -2922,13 +2995,13 @@ bool HTMLGo(void) fprintf(tmpTitle, "\n", ConvertCase(FileNameFromPath(contentsFrameName))); fprintf(tmpTitle, "\n", ConvertCase(FileNameFromPath(firstFileName))); fprintf(tmpTitle, "\n"); - + fprintf(tmpTitle, "\n"); } // Output <BODY...> to temporary title page OutputBodyStart(); - + // Concat titlepage FILE *fd = fopen(TitlepageName, "r"); if (fd) @@ -2942,7 +3015,7 @@ bool HTMLGo(void) fclose(fd); } - fprintf(tmpTitle, "\n</BODY>\n"); + fprintf(tmpTitle, "\n</FONT></BODY>\n"); if (htmlFrameContents) { @@ -3039,27 +3112,40 @@ void GenerateHTMLWorkshopFiles(char *fname) sprintf(buf, "%s.hhp", fname); f = fopen(buf, "wt"); - fprintf(f, + fprintf(f, "[OPTIONS]\n" - "Compatibility=1.1 or later\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=", FileNameFromPath(fname), + FileNameFromPath(fname), + FileNameFromPath(fname), FileNameFromPath(TitlepageName), FileNameFromPath(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,,,", + FileNameFromPath(fname), + FileNameFromPath(fname), + FileNameFromPath(fname), + FileNameFromPath(TitlepageName)); + + fprintf(f, "\n\n[FILES]\n"); fprintf(f, "%s\n", FileNameFromPath(TitlepageName)); - for (int i = 1; i <= fileId; i++) { + for (int i = 1; i <= fileId; i++) { if (truncateFilenames) sprintf(buf, "%s%d.htm", FileNameFromPath(FileRoot), i); else @@ -3097,7 +3183,7 @@ void GenerateHTMLWorkshopFiles(char *fname) while (node1) { char *s = (char *)node1->Data(); - fprintf(f, + fprintf(f, " <LI> <OBJECT type=\"text/sitemap\">\n" " <param name=\"Local\" value=\"%s#%s\">\n" " <param name=\"Name\" value=\"%s\">\n" @@ -3107,7 +3193,7 @@ void GenerateHTMLWorkshopFiles(char *fname) } } } - + fprintf(f, "</UL>\n"); fclose(f); } @@ -3123,19 +3209,19 @@ void HTMLWorkshopAddToContents(int level, char *s, char *file) if (level > HTMLWorkshopLastLevel) for (i = HTMLWorkshopLastLevel; i < level; i++) - fprintf(HTMLWorkshopContents, "<UL>"); + fprintf(HTMLWorkshopContents, "<UL>"); if (level < HTMLWorkshopLastLevel) for (i = level; i < HTMLWorkshopLastLevel; i++) - fprintf(HTMLWorkshopContents, "</UL>"); - + fprintf(HTMLWorkshopContents, "</UL>"); + SetCurrentOutput(HTMLWorkshopContents); - fprintf(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, + fprintf(HTMLWorkshopContents, "\">\n" " </OBJECT>\n"); HTMLWorkshopLastLevel = level; @@ -3146,10 +3232,10 @@ void HTMLWorkshopStartContents() { char buf[300]; sprintf(buf, "%s.hhc", FileRoot); - HTMLWorkshopContents = fopen(buf, "wt"); + HTMLWorkshopContents = fopen(buf, "wt"); HTMLWorkshopLastLevel = 0; - fprintf(HTMLWorkshopContents, + fprintf(HTMLWorkshopContents, "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n" "<HTML>\n" "<HEAD>\n" @@ -3159,7 +3245,13 @@ void HTMLWorkshopStartContents() "<OBJECT type=\"text/site properties\">\n" " <param name=\"ImageType\" value=\"Folder\">\n" "</OBJECT>\n" - "<UL>\n"); + "<UL>\n" + "<LI> <OBJECT type=\"text/sitemap\">\n" + "<param name=\"Local\" value=\"%s\">\n" + "<param name=\"Name\" value=\"Contents\">\n</OBJECT>\n", + FileNameFromPath(TitlepageName) + ); + }