📄 texutils.cpp
字号:
else if (wxStrcmp(settingValue, _T("bitmap")) == 0) htmlBrowseButtons = HTML_BUTTONS_BITMAP; else if (wxStrcmp(settingValue, _T("text")) == 0) htmlBrowseButtons = HTML_BUTTONS_TEXT; else { if (interactive) OnInform(_T("Initialisation file error: htmlBrowseButtons must be one of none, bitmap, or text.")); wxStrcpy(errorCode, _T("Initialisation file error: htmlBrowseButtons must be one of none, bitmap, or text.")); } } else if (StringMatch(settingName, _T("backgroundImage"), false, true)) { backgroundImageString = copystring(settingValue); } else if (StringMatch(settingName, _T("backgroundColour"), false, true)) { delete[] backgroundColourString; backgroundColourString = copystring(settingValue); } else if (StringMatch(settingName, _T("textColour"), false, true)) { textColourString = copystring(settingValue); } else if (StringMatch(settingName, _T("linkColour"), false, true)) { linkColourString = copystring(settingValue); } else if (StringMatch(settingName, _T("followedLinkColour"), false, true)) { followedLinkColourString = copystring(settingValue); } else if (StringMatch(settingName, _T("conversionMode"), false, true)) { if (StringMatch(settingValue, _T("RTF"), false, true)) { winHelp = false; convertMode = TEX_RTF; } else if (StringMatch(settingValue, _T("WinHelp"), false, true)) { winHelp = true; convertMode = TEX_RTF; } else if (StringMatch(settingValue, _T("XLP"), false, true) || StringMatch(settingValue, _T("wxHelp"), false, true)) { convertMode = TEX_XLP; } else if (StringMatch(settingValue, _T("HTML"), false, true)) { convertMode = TEX_HTML; } else { if (interactive) OnInform(_T("Initialisation file error: conversionMode must be one of\nRTF, WinHelp, XLP (or wxHelp), HTML.")); wxStrcpy(errorCode, _T("Initialisation file error: conversionMode must be one of\nRTF, WinHelp, XLP (or wxHelp), HTML.")); } } else if (StringMatch(settingName, _T("documentFontSize"), false, true)) { int n; RegisterIntSetting(settingValueStr, &n); if (n == 10 || n == 11 || n == 12) SetFontSizes(n); else { wxChar buf[200]; wxSnprintf(buf, sizeof(buf), _T("Initialisation file error: nonstandard document font size %d."), n); if (interactive) OnInform(buf); wxStrcpy(errorCode, buf); } } else { wxChar buf[200]; wxSnprintf(buf, sizeof(buf), _T("Initialisation file error: unrecognised setting %s."), settingName.c_str()); if (interactive) OnInform(buf); wxStrcpy(errorCode, buf); } return errorCode;}bool ReadCustomMacros(const wxString& filename){ if (!wxFileExists(filename)) return false; wxFileInputStream input( filename ); if(!input.Ok()) return false; wxTextInputStream ini( input ); CustomMacroList.Clear(); while (!input.Eof()) { wxString line = ini.ReadLine(); BibEatWhiteSpace(line); if (line.empty()) continue; if (line[0] != _T('\\')) // Not a macro definition, so must be NAME=VALUE { wxString settingName = BibReadWord(line); BibEatWhiteSpace(line); if (line.empty() || line[0] != _T('=')) { OnError(_T("Expected = following name: malformed tex2rtf.ini file.")); return false; } else { line = line.substr(1); BibEatWhiteSpace(line); wxString settingValue = BibReadToEOL(line); RegisterSetting(settingName, settingValue); } } else { line = line.substr(1); wxString macroName = BibReadWord(line); BibEatWhiteSpace(line); if (line[0] != _T('[')) { OnError(_T("Expected [ followed by number of arguments: malformed tex2rtf.ini file.")); return false; } line = line.substr(1); wxString noAargStr = line.BeforeFirst(_T(']')); line = line.AfterFirst(_T(']')); long noArgs; if (!noAargStr.ToLong(&noArgs) || line.empty()) { OnError(_T("Expected ] following number of arguments: malformed tex2rtf.ini file.")); return false; } BibEatWhiteSpace(line); if (line[0] != _T('{')) { OnError(_T("Expected { followed by macro body: malformed tex2rtf.ini file.")); return false; } CustomMacro *macro = new CustomMacro(macroName.c_str(), noArgs, NULL); wxString macroBody = BibReadValue(line, false, false); // Don't ignore extra braces if (!macroBody.empty()) macro->macroBody = copystring(macroBody.c_str()); BibEatWhiteSpace(line); CustomMacroList.Append(macroName.c_str(), macro); AddMacroDef(ltCUSTOM_MACRO, macroName.c_str(), noArgs); } } wxChar mbuf[200]; wxSnprintf(mbuf, sizeof(mbuf), _T("Read initialization file %s."), filename.c_str()); OnInform(mbuf); return true;}CustomMacro *FindCustomMacro(wxChar *name){ wxNode *node = CustomMacroList.Find(name); if (node) { CustomMacro *macro = (CustomMacro *)node->GetData(); return macro; } return NULL;}// Display custom macrosvoid ShowCustomMacros(void){ wxNode *node = CustomMacroList.GetFirst(); if (!node) { OnInform(_T("No custom macros loaded.\n")); return; } wxChar buf[400]; while (node) { CustomMacro *macro = (CustomMacro *)node->GetData(); wxSnprintf(buf, sizeof(buf), _T("\\%s[%d]\n {%s}"), macro->macroName, macro->noArgs, macro->macroBody ? macro->macroBody : _T("")); OnInform(buf); node = node->GetNext(); }}// Parse a string into several comma-separated fieldswxChar *ParseMultifieldString(wxChar *allFields, int *pos){ static wxChar buffer[300]; int i = 0; int fieldIndex = *pos; int len = wxStrlen(allFields); int oldPos = *pos; bool keepGoing = true; while ((fieldIndex <= len) && keepGoing) { if (allFields[fieldIndex] == _T(' ')) { // Skip fieldIndex ++; } else if (allFields[fieldIndex] == _T(',')) { *pos = fieldIndex + 1; keepGoing = false; } else if (allFields[fieldIndex] == 0) { *pos = fieldIndex + 1; keepGoing = false; } else { buffer[i] = allFields[fieldIndex]; fieldIndex ++; i++; } } buffer[i] = 0; if (oldPos == (*pos)) *pos = len + 1; if (i == 0) return NULL; else return buffer;}/* * Colour tables * */ColourTableEntry::ColourTableEntry(const wxChar *theName, unsigned int r, unsigned int g, unsigned int b){ name = copystring(theName); red = r; green = g; blue = b;}ColourTableEntry::~ColourTableEntry(void){ delete[] name;}void AddColour(const wxChar *theName, unsigned int r, unsigned int g, unsigned int b){ wxNode *node = ColourTable.Find(theName); if (node) { ColourTableEntry *entry = (ColourTableEntry *)node->GetData(); if (entry->red == r || entry->green == g || entry->blue == b) return; else { delete entry; delete node; } } ColourTableEntry *entry = new ColourTableEntry(theName, r, g, b); ColourTable.Append(theName, entry);}int FindColourPosition(wxChar *theName){ int i = 0; wxNode *node = ColourTable.GetFirst(); while (node) { ColourTableEntry *entry = (ColourTableEntry *)node->GetData(); if (wxStrcmp(theName, entry->name) == 0) return i; i ++; node = node->GetNext(); } return -1;}// Converts e.g. "red" -> "#FF0000"extern void DecToHex(int, wxChar *);bool FindColourHTMLString(wxChar *theName, wxChar *buf){ wxNode *node = ColourTable.GetFirst(); while (node) { ColourTableEntry *entry = (ColourTableEntry *)node->GetData(); if (wxStrcmp(theName, entry->name) == 0) { wxStrcpy(buf, _T("#")); wxChar buf2[3]; DecToHex(entry->red, buf2); wxStrcat(buf, buf2); DecToHex(entry->green, buf2); wxStrcat(buf, buf2); DecToHex(entry->blue, buf2); wxStrcat(buf, buf2); return true; } node = node->GetNext(); } return false;}void InitialiseColourTable(void){ // \\red0\\green0\\blue0; AddColour(_T("black"), 0,0,0); // \\red0\\green0\\blue255;\\red0\\green255\\blue255;\n"); AddColour(_T("cyan"), 0,255,255); // \\red0\\green255\\blue0; AddColour(_T("green"), 0,255,0); // \\red255\\green0\\blue255; AddColour(_T("magenta"), 255,0,255); // \\red255\\green0\\blue0; AddColour(_T("red"), 255,0,0); // \\red255\\green255\\blue0; AddColour(_T("yellow"), 255,255,0); // \\red255\\green255\\blue255;}"); AddColour(_T("white"), 255,255,255);}/* * The purpose of this is to reduce the number of times wxYield is * called, since under Windows this can slow things down. */void Tex2RTFYield(bool force){#ifdef __WINDOWS__ static int yieldCount = 0; if (isSync) return; if (force) yieldCount = 0; if (yieldCount == 0) { if (wxTheApp) wxYield(); yieldCount = 10; } yieldCount --;#else wxUnusedVar(force);#endif}// In both RTF generation and HTML generation for wxHelp version 2,// we need to associate \indexed keywords with the current filename/topics.// Hash table for lists of keywords for topics (WinHelp).wxHashTable TopicTable(wxKEY_STRING);void AddKeyWordForTopic(wxChar *topic, wxChar *entry, wxChar *filename){ TexTopic *texTopic = (TexTopic *)TopicTable.Get(topic); if (!texTopic) { texTopic = new TexTopic(filename); texTopic->keywords = new wxStringList; TopicTable.Put(topic, texTopic); } if (!texTopic->keywords->Member(entry)) texTopic->keywords->Add(entry);}void ClearKeyWordTable(void){ TopicTable.BeginFind(); wxHashTable::Node *node = TopicTable.Next(); while (node) { TexTopic *texTopic = (TexTopic *)node->GetData(); delete texTopic; node = TopicTable.Next(); } TopicTable.Clear();}/* * TexTopic structure */TexTopic::TexTopic(wxChar *f){ if (f) filename = copystring(f); else filename = NULL; hasChildren = false; keywords = NULL;}TexTopic::~TexTopic(void){ if (keywords) delete keywords; if (filename) delete[] filename;}// Convert case, according to upperCaseNames setting.wxChar *ConvertCase(wxChar *s){ static wxChar buf[256]; int len = wxStrlen(s); int i; if (upperCaseNames) for (i = 0; i < len; i ++) buf[i] = (wxChar)wxToupper(s[i]); else for (i = 0; i < len; i ++) buf[i] = (wxChar)wxTolower(s[i]); buf[i] = 0; return buf;}// if substring is true, search for str1 in str2bool StringMatch(const wxChar *str1, const wxChar *str2, bool subString, bool exact){ if (subString) { wxString Sstr1(str1); wxString Sstr2(str2); if (!exact) { Sstr1.MakeUpper(); Sstr2.MakeUpper(); } return Sstr2.Index(Sstr1) != (size_t)wxNOT_FOUND; } else return exact ? wxString(str2).Cmp(str1) == 0 : wxString(str2).CmpNoCase(str1) == 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -