//--------------------------------------------------------------------------- #include #pragma hdrstop #include "biblecsmgr.h" #include "swdisprtfchap.h" #include #include #include #include #include #include #include #include //using namespace std; //--------------------------------------------------------------------------- static inline SWDispRTFChap *ValidCtrCheck() { return new SWDispRTFChap(NULL); } char SWDispRTFChap::platformID = 0; class SWDispRTFChap_init { public: SWDispRTFChap_init() { OSVERSIONINFO osvi; memset(&osvi, 0, sizeof(OSVERSIONINFO)); osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); GetVersionEx(&osvi); SWDispRTFChap::platformID = osvi.dwPlatformId; } } SWDispRTFChap::_init; //--------------------------------------------------------------------------- __fastcall SWDispRTFChap::SWDispRTFChap(TWinControl *Owner) : SWDispRTF(Owner) { } __fastcall SWDispRTFChap::~SWDispRTFChap() { } void __fastcall SWDispRTFChap::Loaded(void) { SWDispRTF::Loaded(); } // Display for biblical text char SWDispRTFChap::Display(SWModule &Module) { int testmt, book, chap, verse, versepos; char buf[254]; System::AnsiString newtext, tmptext, tmptext2; static bool hebarLang; static char* hebarLanguages[] = {"he", "ar", "fa", "ug", "ur", 0}; VerseKey *key = (VerseKey *)Module.getKey(); key->setIntros(true); testmt = key->getTestament(); book = key->getBook(); chap = key->getChapter(); verse = key->getVerse(); key->setAutoNormalize(false); key->setVerse(0); if (chap == 1) { key->setChapter(0); if (book == 1) { key->setBook(0); if (testmt == 1) key->setTestament(0); } } key->setAutoNormalize(false); module = &Module; type = "Default"; //Windows of various flavors has odd behavior with Hebrew & Arabic, which are only partially supported as RTL scripts. //This snippet determines whether the module is set up to use one of these languages and is tagged as RTL. hebarLang = false; if (Module.getDirection() == DIRECTION_RTL && Module.getLanguage()) { for (unsigned char l = 0; hebarLanguages[l]; l++) { if (!strnicmp(Module.getLanguage(), hebarLanguages[l], 2)) { //change the length variable if we ever get any 3-char language codes hebarLang = true; } } } recalcAppearance(); newtext = RTFHeader; newtext = newtext + RTFChapterMarkPre + IntToStr(chap) + RTFChapterMarkPost; newtext = newtext + "\\pard\\f0\\nowidctlpar\\cf7 "; if (Module.getDirection() == DIRECTION_RTL) { newtext = newtext + "\\qr "; } if (platformID == VER_PLATFORM_WIN32_NT && hebarLang) { newtext = newtext + "\\rtlpar "; } Module.popError(); // clear error; SWBuf lastEntry = "something the first entry will never be"; while (((!key->getBook())||(key->getBook() == book)) && ((!key->getChapter())||(key->getChapter() == chap)) && (Module.popError() == 0)) { SWBuf rawText = Module.getRawEntry(); // strip off any leading and ending whitespace rawText.trim(); if (lastEntry == rawText) { Module++; continue; } newtext = newtext + "{"; tmptext = ""; lastEntry = rawText; SWBuf renderedText = Module.renderText(); for (const char *loop = renderedText.c_str(); *loop; loop++) { if (*loop == '\n') { tmptext += "\\par "; } else tmptext += *loop; } if (tmptext.Length() > 3) { // make sure we have an entry int pvHeading = 0; do { sprintf(buf, "%i", pvHeading++); SWBuf preverseHeading = module->getEntryAttributes()["Heading"]["Preverse"][buf].c_str(); preverseHeading = Module.renderText(preverseHeading); if (preverseHeading.length()) { newtext += ((AnsiString)"\\par\\par {\\i1\\b1 ") + preverseHeading.c_str() + "\\par}"; } else break; } while (true); if (Module.getDirection() == DIRECTION_RTL && (platformID == VER_PLATFORM_WIN32_WINDOWS || !hebarLang)) { newtext = newtext + RTFVersePre; if ((key->getVerse() == verse) && (dispAttribs.markCurrentVerse)) { newtext = newtext + "\\cf2 "; // \cf2 = second color in color table } newtext += tmptext + RTFVersePost; if (key->getVerse()) newtext = newtext + RTFVerseMarkPre + /*"" +*/ IntToStr(key->getVerse()) /*+ ""*/ + RTFVerseMarkPost; if (!dispAttribs.verseNewLine) newtext = newtext + "\\par "; } else { if (key->getVerse()) newtext = newtext + RTFVerseMarkPre + /*"" +*/ IntToStr(key->getVerse()) /*+ ""*/ + RTFVerseMarkPost; newtext = newtext + RTFVersePre; if ((key->getVerse() == verse) && (dispAttribs.markCurrentVerse)) { newtext = newtext + "\\cf2 "; // \cf2 = second color in color table } newtext += tmptext + RTFVersePost; } // check for headings and add a couple new lines, if so. if ((!key->getVerse()) || (!key->getChapter()) || (!key->getBook()) || (!key->getTestament())) { if (rawText.size()) newtext = newtext + "\\par\\par"; } // we don't want to add too many newlines if this display option is turned on, so this is in an else. else { if (dispAttribs.verseNewLine) { newtext += "\\par "; } } } if (key->getVerse() == verse) { tmptext = newtext + RTFTrailer + "}"; RTFStream->Clear(); RTFStream->WriteBuffer(tmptext.c_str(), tmptext.Length()); RTFStream->Position = 0; Lines->LoadFromStream(RTFStream); makeLinks(); makeImages(); versepos = GetTextLen() - 3; } newtext = newtext + "}"; Module++; } newtext = newtext + RTFTrailer; makeBracketsEven(newtext); key->setVerse(1); //{ When setting chapter: if (verse !in new chapter range) don't autonormalize. (we could've just turned the autonormalize option off then back on, but this is cooler) } key->setChapter(1); key->setBook(1); key->setTestament(testmt); key->setBook(book); key->setChapter(chap); key->setVerse(verse); RTFStream->Clear(); RTFStream->WriteBuffer(newtext.c_str(), newtext.Length()); // int fd = open("rtfout.txt", O_CREAT|O_RDWR|O_TRUNC, S_IREAD|S_IWRITE); // write(fd, newtext.c_str(), newtext.Length()); // close(fd); RTFStream->Position = 0; Lines->LoadFromStream(RTFStream); makeLinks(); makeImages(); //{ Position control text at current verse } this->SetFocus(); SelStart = 1; SendMessage(Handle, EM_SCROLLCARET, 0, 0); SelStart = versepos; SendMessage(Handle, EM_SCROLLCARET, 0, 0); return 0; } //--------------------------------------------------------------------------- namespace Swdisprtfchap { void __fastcall Register() { TComponentClass classes[1] = {__classid(SWDispRTFChap)}; RegisterComponents("SWORD", classes, 0); } } //---------------------------------------------------------------------------