[sword-svn] r466 - branches/BCB5
chrislit at www.crosswire.org
chrislit at www.crosswire.org
Fri Oct 19 21:59:28 MST 2007
Author: chrislit
Date: 2007-10-19 21:59:26 -0700 (Fri, 19 Oct 2007)
New Revision: 466
Modified:
branches/BCB5/RxRichEditX.cpp
branches/BCB5/RxRichEditX.h
branches/BCB5/paraldisp.cpp
branches/BCB5/swdisprtf.cpp
branches/BCB5/swdisprtfchap.cpp
Log:
added code to make RTF brackets even, so it won't ever just show the underlying RTF
Modified: branches/BCB5/RxRichEditX.cpp
===================================================================
--- branches/BCB5/RxRichEditX.cpp 2007-09-29 04:09:56 UTC (rev 465)
+++ branches/BCB5/RxRichEditX.cpp 2007-10-20 04:59:26 UTC (rev 466)
@@ -273,6 +273,8 @@
newtext += RTFTrailer;
+ makeBracketsEven(newtext);
+
RTFStream->Clear();
RTFStream->WriteBuffer(newtext.c_str(), newtext.Length());
RTFStream->Position = 0;
@@ -453,6 +455,8 @@
newtext += RTFTrailer;
+ makeBracketsEven(newtext);
+
RTFStream->Clear();
RTFStream->WriteBuffer(newtext.c_str(), newtext.Length());
RTFStream->Position = 0;
@@ -864,7 +868,7 @@
WideString __fastcall TRxRichEditX::GetText() {
long MaxLen = TextLen();
-
+
wchar_t *buf = new wchar_t [ MaxLen + 2 ];
GETTEXTEX params;
params.cb = (MaxLen + 1) * sizeof(wchar_t);
@@ -1149,7 +1153,28 @@
delete ss;
}
+// Count curly brackets and return the open brackets in excess of the number of close brackets
+// Hopefully this will help us hide 90% of the module encoding errors that result in bad display
+void TRxRichEditX::makeBracketsEven(AnsiString &rtfText) {
+ char *rtfcstr = rtfText.c_str();
+ signed char bracketCount = 0;
+ while (*rtfcstr) {
+ if (*rtfcstr == '}') {
+ bracketCount++;
+ }
+ else if (*rtfcstr == '{') {
+ bracketCount--;
+ }
+ rtfcstr++;
+ }
+
+ while (bracketCount > 0) {
+ rtfText += "}";
+ bracketCount--;
+ }
+}
+
/*
// Example to insert image from Image1 into RxRichEdit1
procedure TForm1.Button1Click(Sender: TObject);
Modified: branches/BCB5/RxRichEditX.h
===================================================================
--- branches/BCB5/RxRichEditX.h 2007-09-29 04:09:56 UTC (rev 465)
+++ branches/BCB5/RxRichEditX.h 2007-10-20 04:59:26 UTC (rev 466)
@@ -115,6 +115,7 @@
void recalcAppearance();
void makeLinks();
void makeImages();
+ void makeBracketsEven(AnsiString &rtfText);
void insertImage(const char *filePath);
SWBuf bitmapToRTF(Graphics::TBitmap *pict);
void insertRTF(const char *rtf);
Modified: branches/BCB5/paraldisp.cpp
===================================================================
--- branches/BCB5/paraldisp.cpp 2007-09-29 04:09:56 UTC (rev 465)
+++ branches/BCB5/paraldisp.cpp 2007-10-20 04:59:26 UTC (rev 466)
@@ -26,7 +26,7 @@
helpMessageL1 = "";
helpMessageL2 = "";
helpMessageL3 = "";
- helpTitle = "New Feature - Parallel Display";
+ helpTitle = "Parallel Display";
}
__fastcall ParallelDisp::~ParallelDisp() {
@@ -88,8 +88,6 @@
return 0;
}
-
-
VerseKey *key = (VerseKey *)(SWKey *)(*mods[0]);
UnicodeRTF uToRTF;
testmt = key->Testament();
@@ -111,7 +109,7 @@
/*
- // Dunno if this first line does anything
+ // Dunno if this first line does anything
newtext += "{\\stylesheet{\\s1{\\*\\hyphen2\\hyphlead2\\hyphtrail2\\hyphmax0}\\rtlch\\afs24\\lang255\\ltrch\\dbch\\af2\\afs24\\langfe255\\loch\\f0\\fs24\\lang1033\\snext1 Default;}";
newtext += "{\\s2\\sa120{\\*\\hyphen2\\hyphlead2\\hyphtrail2\\hyphmax0}\\rtlch\\afs24\\lang255\\ltrch\\dbch\\af2\\afs24\\langfe255\\loch\\f0\\fs24\\lang1033\\sbasedon1\\snext2 Text body;}";
newtext += "{\\s3\\sa120{\\*\\hyphen2\\hyphlead2\\hyphtrail2\\hyphmax0}\\rtlch\\afs24\\lang255\\ltrch\\dbch\\af2\\afs24\\langfe255\\loch\\f0\\fs24\\lang1033\\sbasedon2\\snext3 Table Contents;}";
@@ -249,20 +247,21 @@
// else newtext += "\\cell\\row\\pard ";
}
-
+
+ makeBracketsEven(newtext);
+
(*mods[0])++;
}
// ending stuff
// newtext += "\\pard\\plain \\s1";
// newtext += "{\\*\\hyphen2\\hyphlead2\\hyphtrail2\\hyphmax0}";
-// newtext += "\\rtlch\\afs24\\lang255\\ltrch\\dbch\\af2\\afs24\\langfe255\\loch\\f0\\fs24\\lang1033 ";
+// newtext += "\\rtlch\\afs24\\lang255\\ltrch\\dbch\\af2\\afs24\\langfe255\\loch\\f0\\fs24\\lang1033 ";
newtext = newtext + RTFTrailer;
+ makeBracketsEven(newtext);
-
-
key->Verse(1); //{ When setting chapter: if (verse <> new chapter range) don't autonormalize. (we could've just turned the autonormalize option off then back on, but this is cooler) }
key->Chapter(1);
key->Book(1);
@@ -275,7 +274,7 @@
RTFStream->Position = 0;
Lines->LoadFromStream(RTFStream);
- makeLinks();
+ makeLinks();
makeImages();
//{ Position control text at current verse }
Modified: branches/BCB5/swdisprtf.cpp
===================================================================
--- branches/BCB5/swdisprtf.cpp 2007-09-29 04:09:56 UTC (rev 465)
+++ branches/BCB5/swdisprtf.cpp 2007-10-20 04:59:26 UTC (rev 466)
@@ -31,7 +31,7 @@
int __fastcall SWDispRTF::GetMySelStart() {
CHARRANGE cr;
-
+
SendMessage(Handle, EM_EXGETSEL, 0, (long)&cr);
return cr.cpMin;
}
@@ -39,7 +39,7 @@
void __fastcall SWDispRTF::SetMySelStart(int iselstart) {
CHARRANGE cr;
-
+
cr.cpMin = iselstart;
cr.cpMax = iselstart;
SendMessage(Handle, EM_EXSETSEL, 0, (long)&cr);
@@ -55,7 +55,7 @@
type = "Default";
recalcAppearance();
-
+
newtext = RTFHeader;
newtext = newtext + RTFHeadMargin;
Module.Error(); // clear error;
@@ -72,9 +72,12 @@
tmptext = "";
tmptext = (const char *)Module;
-
+
newtext = newtext + RTFVersePre + tmptext + RTFVersePost;
newtext = newtext + RTFTrailer;
+
+ makeBracketsEven(newtext);
+
RTFStream->Clear();
RTFStream->WriteBuffer(newtext.c_str(), newtext.Length());
RTFStream->Position = 0;
@@ -82,7 +85,7 @@
makeLinks();
makeImages();
-
+
SendMessage(Handle, EM_SCROLLCARET, 0, 0);
return 0;
Modified: branches/BCB5/swdisprtfchap.cpp
===================================================================
--- branches/BCB5/swdisprtfchap.cpp 2007-09-29 04:09:56 UTC (rev 465)
+++ branches/BCB5/swdisprtfchap.cpp 2007-10-20 04:59:26 UTC (rev 466)
@@ -57,6 +57,7 @@
int testmt, book, chap, verse, versepos;
char buf[254];
System::AnsiString newtext, tmptext, tmptext2;
+
VerseKey *key = (VerseKey *)(SWKey *)Module;
key->Headings(1);
testmt = key->Testament();
@@ -79,7 +80,6 @@
recalcAppearance();
-
newtext = RTFHeader;
newtext = newtext + RTFChapterMarkPre + IntToStr(chap) + RTFChapterMarkPost;
newtext = newtext + "\\pard\\f0\\nowidctlpar\\cf7 ";
@@ -94,10 +94,10 @@
SWBuf lastEntry = "something the first entry will never be";
while (((!key->Book())||(key->Book() == book)) && ((!key->Chapter())||(key->Chapter() == chap)) && (Module.Error() == 0)) {
SWBuf rawText = Module.getRawEntry();
-
+
// strip off any leading and ending whitespace
rawText.trim();
-
+
if (lastEntry == rawText) {
Module++;
continue;
@@ -144,7 +144,7 @@
}
newtext += tmptext + RTFVersePost;
}
- // check for headings and add a couple new lines, if so.
+ // check for headings and add a couple new lines, if so.
if ((!key->Verse()) || (!key->Chapter()) || (!key->Book()) || (!key->Testament())) {
if (rawText.size())
newtext = newtext + "\\par\\par";
@@ -171,6 +171,8 @@
}
newtext = newtext + RTFTrailer;
+ makeBracketsEven(newtext);
+
key->Verse(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->Chapter(1);
key->Book(1);
@@ -178,6 +180,7 @@
key->Book(book);
key->Chapter(chap);
key->Verse(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);
@@ -185,10 +188,10 @@
// close(fd);
RTFStream->Position = 0;
Lines->LoadFromStream(RTFStream);
-
+
makeLinks();
makeImages();
-
+
//{ Position control text at current verse }
this->SetFocus();
SelStart = 1;
More information about the sword-cvs
mailing list