1
0
Эх сурвалжийг харах

adjust rtf text before drawing, fix for drawing ms word copied text

sabrogden 8 жил өмнө
parent
commit
3e2970c08a
4 өөрчлөгдсөн 59 нэмэгдсэн , 3 устгасан
  1. 23 1
      Misc.cpp
  2. 14 1
      Options.cpp
  3. 4 0
      Options.h
  4. 18 1
      QListCtrl.cpp

+ 23 - 1
Misc.cpp

@@ -1334,9 +1334,31 @@ bool RemoveRTFSection(CStringA &str, CStringA section)
 	bool removedSection = false;
 
 	int start2 = str.Find(section, 0);
+	int end2 = 0;
 	if (start2 >= 0)
 	{
-		int end2 = str.Find("}", start2);
+		int in = 0;
+		for (int pos = start2+1; pos < str.GetLength(); pos++)
+		{
+			if (str[pos] == '{')
+			{
+				in++;
+			}
+
+			if (str[pos] == '}')
+			{
+				if (in > 0)
+				{
+					in--;
+				}
+				else
+				{
+					end2 = pos;
+					break;
+				}
+			}
+		}
+
 		if (end2 > start2)
 		{
 			str.Delete(start2, (end2 - start2) + 1);

+ 14 - 1
Options.cpp

@@ -71,6 +71,7 @@ BOOL CGetSetOptions::m_excludeCF_DIBInExcel = TRUE;
 CChaiScriptXml CGetSetOptions::m_copyScripts;
 CChaiScriptXml CGetSetOptions::m_pasteScripts;
 long CGetSetOptions::m_tooltipTimeout;
+BOOL CGetSetOptions::m_cleanRTFBeforeDrawing = TRUE;
 
 CGetSetOptions::CGetSetOptions()
 {
@@ -1946,7 +1947,7 @@ DWORD CGetSetOptions::SendKeysDelay()
 
 DWORD CGetSetOptions::WaitForActiveWndTimeout()
 {
-	return (DWORD)GetProfileLong(_T("WaitForActiveWndTimeout"), 100);
+	return (DWORD)GetProfileLong(_T("WaitForActiveWndTimeout"), 500);
 }
 
 DWORD CGetSetOptions::FocusChangedDelay()
@@ -2665,4 +2666,16 @@ BOOL CGetSetOptions::GetShowMsgWhenReceivingManualSentClip()
 void CGetSetOptions::SetShowMsgWhenReceivingManualSentClip(BOOL val)
 {
 	SetProfileLong("ShowMsgWhenReceivingManualSentClip", val);
+}
+
+
+BOOL CGetSetOptions::GetCleanRTFBeforeDrawing()
+{
+	return GetProfileLong("CleanRTFBeforeDrawing", TRUE);
+}
+
+void CGetSetOptions::SetCleanRTFBeforeDrawing(BOOL val)
+{
+	m_cleanRTFBeforeDrawing = true;
+	SetProfileLong("CleanRTFBeforeDrawing", val);
 }

+ 4 - 0
Options.h

@@ -595,6 +595,10 @@ public:
 	static BOOL GetShowMsgWhenReceivingManualSentClip();
 	static void SetShowMsgWhenReceivingManualSentClip(BOOL val);
 
+	static BOOL m_cleanRTFBeforeDrawing;
+	static BOOL GetCleanRTFBeforeDrawing();
+	static void SetCleanRTFBeforeDrawing(BOOL val);
+
 };
 
 // global for easy access and for initialization of fast access variables

+ 18 - 1
QListCtrl.cpp

@@ -555,7 +555,24 @@ BOOL CQListCtrl::DrawRtfText(int nItem, CRect &crRect, CDC *pDC)
 	   char *pData = (char*)GlobalLock(pThumbnail->m_hgData);
 	   if(pData)
 	   {
-		   CComBSTR bStr(pData);
+		   CStringA CStringData((char*)pData);		   
+
+		   /*CFile file;
+		   if (file.Open(_T("c:\\temp\\rtf.txt"), CFile::modeRead))
+		   {
+			   int len = file.GetLength();
+			   file.Read(CStringData.GetBuffer(len), len);
+			   CStringData.ReleaseBuffer();
+		   }*/
+
+		   //newer version of word adds these to the rtf, i tracked these sections down, remove them and it draws correcty, might find more later
+		   if (g_Opt.m_cleanRTFBeforeDrawing)
+		   {
+			   RemoveRTFSection(CStringData, "{\\fonttbl");
+			   RemoveRTFSection(CStringData, "{\\stylesheet");
+		   }
+
+		   CComBSTR bStr(CStringData);
 		   
 		   m_pFormatter->put_RTFText(bStr);