📄 htmlutil.cpp
字号:
wxChar *nextLabel = NULL; wxChar *nextFilename = NULL; // Get the next page, and record the previous page's 'next' page // (i.e. this page) TexNextPage *nextPage = (TexNextPage *)TexNextPages.Get(thisLabel); if (nextPage) { nextLabel = nextPage->label; nextFilename = nextPage->filename; } if (previousLabel && previousFilename) { TexNextPage *oldNextPage = (TexNextPage *)TexNextPages.Get(previousLabel); if (oldNextPage) { delete oldNextPage; TexNextPages.Delete(previousLabel); } TexNextPage *newNextPage = new TexNextPage(thisLabel, thisFilename); TexNextPages.Put(previousLabel, newNextPage); } /* * >> button * */ if (nextLabel && nextFilename) { if (PrimaryAnchorOfTheFile(nextFilename, nextLabel)) wxSnprintf(buf, sizeof(buf), _T("<A HREF=\"%s\">%s</A> "), ConvertCase(nextFilename), forwardReference); else wxSnprintf(buf, sizeof(buf), _T("<A HREF=\"%s#%s\">%s</A> "), ConvertCase(nextFilename), nextLabel, forwardReference); TexOutput(buf); } else { // A placeholder so the buttons don't keep moving position wxSnprintf(buf, sizeof(buf), _T("%s "), forwardReference); TexOutput(buf); } /* * Horizontal rule to finish it off nicely. * */ TexOutput(_T("</CENTER>")); TexOutput(_T("<HR>\n")); // Update last topic/filename if (lastFileName) delete[] lastFileName; lastFileName = copystring(thisFilename); if (lastTopic) delete[] lastTopic; lastTopic = copystring(thisLabel);}// A colour string is either 3 numbers separated by semicolons (RGB),// or a reference to a GIF. Return the filename or a hex string like #934CE8wxChar *ParseColourString(wxChar *bkStr, bool *isPicture){ static wxChar resStr[300]; wxStrcpy(resStr, bkStr); wxStringTokenizer tok(resStr, _T(";"), wxTOKEN_STRTOK); if (tok.HasMoreTokens()) { wxString token1 = tok.GetNextToken(); if (!tok.HasMoreTokens()) { *isPicture = true; return resStr; } else { wxString token2 = tok.GetNextToken(); *isPicture = false; if (tok.HasMoreTokens()) { wxString token3 = tok.GetNextToken(); // Now convert 3 strings into decimal numbers, and then hex numbers. int red = wxAtoi(token1.c_str()); int green = wxAtoi(token2.c_str()); int blue = wxAtoi(token3.c_str()); wxStrcpy(resStr, _T("#")); wxChar buf[3]; DecToHex(red, buf); wxStrcat(resStr, buf); DecToHex(green, buf); wxStrcat(resStr, buf); DecToHex(blue, buf); wxStrcat(resStr, buf); return resStr; } else return NULL; } } 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(_T("<FONT FACE=\"")); TexOutput(htmlFaceName); TexOutput(_T("\">\n")); }}// Output start of <BODY> blockvoid OutputBodyStart(void){ TexOutput(_T("\n<BODY")); if (backgroundImageString) { bool isPicture = false; wxChar *s = ParseColourString(backgroundImageString, &isPicture); if (s) { TexOutput(_T(" BACKGROUND=\"")); TexOutput(s); TexOutput(_T("\"")); } } if (backgroundColourString) { bool isPicture = false; wxChar *s = ParseColourString(backgroundColourString, &isPicture); if (s) { TexOutput(_T(" BGCOLOR=")); TexOutput(s); } } // Set foreground text colour, if one is specified if (textColourString) { bool isPicture = false; wxChar *s = ParseColourString(textColourString, &isPicture); if (s) { TexOutput(_T(" TEXT=")); TexOutput(s); } } // Set link text colour, if one is specified if (linkColourString) { bool isPicture = false; wxChar *s = ParseColourString(linkColourString, &isPicture); if (s) { TexOutput(_T(" LINK=")); TexOutput(s); } } // Set followed link text colour, if one is specified if (followedLinkColourString) { bool isPicture = false; wxChar *s = ParseColourString(followedLinkColourString, &isPicture); if (s) { TexOutput(_T(" VLINK=")); TexOutput(s); } } TexOutput(_T(">\n")); OutputFont();}void HTMLHead(){ TexOutput(_T("<head>")); if (htmlStylesheet) { TexOutput(_T("<link rel=stylesheet type=\"text/css\" href=\"")); TexOutput(htmlStylesheet); TexOutput(_T("\">")); }};void HTMLHeadTo(FILE* f){ if (htmlStylesheet) wxFprintf(f,_T("<head><link rel=stylesheet type=\"text/css\" href=\"%s\">"),htmlStylesheet); else wxFprintf(f,_T("<head>"));}// Called on start/end of macro examinationvoid HTMLOnMacro(int macroId, int no_args, bool start){ switch (macroId) { case ltCHAPTER: case ltCHAPTERSTAR: case ltCHAPTERHEADING: { if (!start) { sectionNo = 0; figureNo = 0; subsectionNo = 0; subsubsectionNo = 0; if (macroId != ltCHAPTERSTAR) chapterNo ++; SetCurrentOutput(NULL); startedSections = true; wxChar *topicName = FindTopicName(GetNextChunk()); ReopenFile(&Chapters, &ChaptersName, topicName); AddTexRef(topicName, ChaptersName, ChapterNameString); SetCurrentChapterName(topicName, ChaptersName); if (htmlWorkshopFiles) HTMLWorkshopAddToContents(0, topicName, ChaptersName); SetCurrentOutput(Chapters); HTMLHead(); TexOutput(_T("<title>")); OutputCurrentSection(); // Repeat section header TexOutput(_T("</title></head>\n")); OutputBodyStart(); wxChar titleBuf[200]; if (truncateFilenames) wxSnprintf(titleBuf, sizeof(titleBuf), _T("%s.htm"), wxFileNameFromPath(FileRoot)); else wxSnprintf(titleBuf, sizeof(titleBuf), _T("%s_contents.html"), wxFileNameFromPath(FileRoot)); wxFprintf(Chapters, _T("<A NAME=\"%s\"></A>"), topicName); AddBrowseButtons(_T(""), titleBuf, // Up lastTopic, lastFileName, // Last topic topicName, ChaptersName); // This topic if(PrimaryAnchorOfTheFile(ChaptersName, topicName)) wxFprintf(Contents, _T("\n<LI><A HREF=\"%s\">"), ConvertCase(ChaptersName)); else wxFprintf(Contents, _T("\n<LI><A HREF=\"%s#%s\">"), ConvertCase(ChaptersName), topicName); if (htmlFrameContents && FrameContents) { SetCurrentOutput(FrameContents); if(PrimaryAnchorOfTheFile(ChaptersName, topicName)) wxFprintf(FrameContents, _T("\n<LI><A HREF=\"%s\" TARGET=\"mainwindow\">"), ConvertCase(ChaptersName)); else wxFprintf(FrameContents, _T("\n<LI><A HREF=\"%s#%s\" TARGET=\"mainwindow\">"), ConvertCase(ChaptersName), topicName); OutputCurrentSection(); wxFprintf(FrameContents, _T("</A>\n")); } SetCurrentOutputs(Contents, Chapters); wxFprintf(Chapters, _T("\n<H2>")); OutputCurrentSection(); wxFprintf(Contents, _T("</A>\n")); wxFprintf(Chapters, _T("</H2>\n")); SetCurrentOutput(Chapters); // Add this section title to the list of keywords if (htmlIndex) { OutputCurrentSectionToString(wxTex2RTFBuffer); AddKeyWordForTopic(topicName, wxTex2RTFBuffer, ConvertCase(currentFileName)); } } break; } case ltSECTION: case ltSECTIONSTAR: case ltSECTIONHEADING: case ltGLOSS: { if (!start) { subsectionNo = 0; subsubsectionNo = 0; subsectionStarted = false; if (macroId != ltSECTIONSTAR) sectionNo ++; SetCurrentOutput(NULL); startedSections = true; wxChar *topicName = FindTopicName(GetNextChunk()); ReopenFile(&Sections, &SectionsName, topicName); AddTexRef(topicName, SectionsName, SectionNameString); SetCurrentSectionName(topicName, SectionsName); if (htmlWorkshopFiles) HTMLWorkshopAddToContents(1, topicName, SectionsName); SetCurrentOutput(Sections); HTMLHead(); TexOutput(_T("<title>")); OutputCurrentSection(); TexOutput(_T("</title></head>\n")); OutputBodyStart(); wxFprintf(Sections, _T("<A NAME=\"%s\"></A>"), topicName); AddBrowseButtons(CurrentChapterName, CurrentChapterFile, // Up lastTopic, lastFileName, // Last topic topicName, SectionsName); // This topic FILE *jumpFrom = ((DocumentStyle == LATEX_ARTICLE) ? Contents : Chapters); SetCurrentOutputs(jumpFrom, Sections); if (DocumentStyle == LATEX_ARTICLE) { if(PrimaryAnchorOfTheFile(SectionsName, topicName)) wxFprintf(jumpFrom, _T("\n<LI><A HREF=\"%s\">"), ConvertCase(SectionsName)); else wxFprintf(jumpFrom, _T("\n<LI><A HREF=\"%s#%s\">"), ConvertCase(SectionsName), topicName); } else { if(PrimaryAnchorOfTheFile(SectionsName, topicName)) wxFprintf(jumpFrom, _T("\n<A HREF=\"%s\"><B>"), ConvertCase(SectionsName)); else wxFprintf(jumpFrom, _T("\n<A HREF=\"%s#%s\"><B>"), ConvertCase(SectionsName), topicName); } wxFprintf(Sections, _T("\n<H2>")); OutputCurrentSection(); if (DocumentStyle == LATEX_ARTICLE) wxFprintf(jumpFrom, _T("</A>\n")); else wxFprintf(jumpFrom, _T("</B></A><BR>\n")); wxFprintf(Sections, _T("</H2>\n")); SetCurrentOutput(Sections); // Add this section title to the list of keywords if (htmlIndex) { OutputCurrentSectionToString(wxTex2RTFBuffer); AddKeyWordForTopic(topicName, wxTex2RTFBuffer, currentFileName); } } break; } case ltSUBSECTION: case ltSUBSECTIONSTAR: case ltMEMBERSECTION: case ltFUNCTIONSECTION: { if (!start) { if (!Sections) { OnError(_T("You cannot have a subsection before a section!")); } else { subsubsectionNo = 0; if (macroId != ltSUBSECTIONSTAR) subsectionNo ++; if ( combineSubSections && !subsectionStarted ) { fflush(Sections); // Read old .con file in at this point wxChar buf[256]; wxStrcpy(buf, CurrentSectionFile); wxStripExtension(buf); wxStrcat(buf, _T(".con")); FILE *fd = wxFopen(buf, _T("r")); if ( fd ) { int ch = getc(fd); while (ch != EOF) { wxPutc(ch, Sections); ch = getc(fd); } fclose(fd); } wxFprintf(Sections, _T("<P>\n")); // Close old file, create a new file for the sub(sub)section contents entries ReopenSectionContentsFile(); } startedSections = true; subsectionStarted = true; wxChar *topicName = FindTopicName(GetNextChunk()); if ( !combineSubSections ) { SetCurrentOutput(NULL); ReopenFile(&Subsections, &SubsectionsName, topicName); AddTexRef(topicName, SubsectionsName, SubsectionNameString); SetCurrentSubsectionName(topicName, SubsectionsName); if (htmlWorkshopFiles) HTMLWorkshopAddToContents(2, topicName, SubsectionsName); SetCurrentOutput(Subsections); HTMLHead(); TexOutput(_T("<title>")); OutputCurrentSection(); TexOutput(_T("</title></head>\n")); OutputBodyStart(); wxFprintf(Subsections, _T("<A NAME=\"%s\"></A>"), topicName); AddBrowseButtons(CurrentSectionName, CurrentSectionFile, // Up lastTopic, lastFileName, // Last topic topicName, SubsectionsName); // This topic SetCurrentOutputs(Sections, Subsections); if(PrimaryAnchorOfTheFile(SubsectionsName, topicName)) wxFprintf(Sections, _T("\n<A HREF=\"%s\"><B>"), ConvertCase(SubsectionsName)); else wxFprintf(Sections, _T("\n<A HREF=\"%s#%s\"><B>"), ConvertCase(SubsectionsName), topicName); wxFprintf(Subsections, _T("\n<H3>")); OutputCurrentSection(); wxFprintf(Sections, _T("</B></A><BR>\n")); wxFprintf(Subsections, _T("</H3>\n")); SetCurrentOutput(Subsections); } else { AddTexRef(topicName, SectionsName, SubsectionNameString); SetCurrentSubsectionName(topicName, SectionsName);// if ( subsectionNo != 0 ) wxFprintf(Sections, _T("\n<HR>\n")); // We're putting everything into the section file wxFprintf(Sections, _T("<A NAME=\"%s\"></A>"), topicName); wxFprintf(Sections, _T("\n<H3>")); OutputCurrentSection(); wxFprintf(Sections, _T("</H3>\n")); SetCurrentOutput(SectionContentsFD); wxFprintf(SectionContentsFD, _T("<A HREF=\"#%s\">"), topicName); OutputCurrentSection(); TexOutput(_T("</A><BR>\n")); if (htmlWorkshopFiles) HTMLWorkshopAddToContents(2, topicName, SectionsName); SetCurrentOutput(Sections); } // Add this section title to the list of keywords if (htmlIndex) { OutputCurrentSectionToString(wxTex2RTFBuffer); AddKeyWordForTopic(topicName, wxTex2RTFBuffer, currentFileName); } } } break; } case ltSUBSUBSECTION: case ltSUBSUBSECTIONSTAR: { if (!start) { if (!Subsections && !combineSubSections) { OnError(_T("You cannot have a subsubsection before a subsection!")); } else { if (macroId != ltSUBSUBSECTIONSTAR) subsubsectionNo ++; startedSections = true; wxChar *topicName = FindTopicName(GetNextChunk()); if ( !combineSubSections ) { SetCurrentOutput(NULL); ReopenFile(&Subsubsections, &SubsubsectionsName, topicName); AddTexRef(topicName, SubsubsectionsName, SubsubsectionNameString); SetCurrentSubsubsectionName(topicName, SubsubsectionsName); if (htmlWorkshopFiles) HTMLWorkshopAddToContents(3, topicName, SubsubsectionsName); SetCurrentOutput(Subsubsections); HTMLHead(); TexOutput(_T("<title>")); OutputCurrentSection(); TexOutput(_T("</title></head>\n")); OutputBodyStart(); wxFprintf(Subsubsections, _T("<A NAME=\"%s\"></A>"), topicName); AddBrowseButtons(CurrentSubsectionName, CurrentSubsectionFile, // Up lastTopic, lastFileName, // Last topic topicName, SubsubsectionsName); // This topic SetCurrentOutputs(Subsections, Subsubsections); if(PrimaryAnchorOfTheFile(SubsubsectionsName, topicName)) wxFprintf(Subsections, _T("\n<A HREF=\"%s\"><B>"), ConvertCase(SubsubsectionsName)); else wxFprintf(Subsections, _T("\n<A HREF=\"%s#%s\"><B>"), ConvertCase(SubsubsectionsName), topicName); wxFprintf(Subsubsections, _T("\n<H3>")); OutputCurrentSection(); wxFprintf(Subsections, _T("</B></A><BR>\n")); wxFprintf(Subsubsections, _T("</H3>\n")); } else { AddTexRef(topicName, SectionsName, SubsubsectionNameString); SetCurrentSubsectionName(topicName, SectionsName); wxFprintf(Sections, _T("\n<HR>\n"));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -