From: Jordi Mas (jmas@softcatala.org)
Date: Mon Sep 15 2003 - 09:24:22 EDT
Hello there,
This is a proposed patch to make the win32 usable again. It fixes bug 5748. I 
REVERTS some changes made my Martin.
If nobody has a better solution, I think that we should commit this patch and 
Martin and me or a win32 developer should look very close to what modification 
need to be done to the win32 graphics class in the future.
Thanks,
--Jordi Mas i Hernāndez (homepage http://www.softcatala.org/~jmas) http://www.softcatala.org
Index: src/af/gr/win/gr_Win32CharWidths.cpp
===================================================================
RCS file: /cvsroot/abi/src/af/gr/win/gr_Win32CharWidths.cpp,v
retrieving revision 1.23
diff -u -r1.23 gr_Win32CharWidths.cpp
--- src/af/gr/win/gr_Win32CharWidths.cpp	11 Sep 2003 03:03:31 -0000	1.23
+++ src/af/gr/win/gr_Win32CharWidths.cpp	15 Sep 2003 13:24:35 -0000
@@ -27,17 +27,10 @@
 #include "ut_endian.h"
 
 //////////////////////////////////////////////////////////////////
-#if 1
-
-#define _UL(x) (x)
-#define _UUL(x)(x) = (x)
-
-#else
 
 #define _UL(x) pGr->tlu((x))
 #define _UUL(x) (x) = pGr->tlu((x))
 
-#endif
 void GR_Win32CharWidths::setCharWidthsOfRange(HDC hdc, UT_UCSChar c0, UT_UCSChar c1, GR_Graphics * pGr)
 {
         if(m_vRanges.getItemCount() == 0)
Index: src/af/gr/win/gr_Win32CharWidths.h
===================================================================
RCS file: /cvsroot/abi/src/af/gr/win/gr_Win32CharWidths.h,v
retrieving revision 1.3
diff -u -r1.3 gr_Win32CharWidths.h
--- src/af/gr/win/gr_Win32CharWidths.h	21 Jun 2003 23:26:53 -0000	1.3
+++ src/af/gr/win/gr_Win32CharWidths.h	15 Sep 2003 13:24:35 -0000
@@ -25,6 +25,11 @@
 class UT_NumberVector;
 class GR_Graphics;
 
+#define _UL(x) (x)                                                              
+#define _UUL(x)(x) = (x)                                                        
+
+
+
 //////////////////////////////////////////////////////////////////
 // the only reason that we subclass is because Win32 provides a
 // routine to fetch the widths of a whole font in one call.
Index: src/af/gr/win/gr_Win32Graphics.cpp
===================================================================
RCS file: /cvsroot/abi/src/af/gr/win/gr_Win32Graphics.cpp,v
retrieving revision 1.152
diff -u -r1.152 gr_Win32Graphics.cpp
--- src/af/gr/win/gr_Win32Graphics.cpp	11 Sep 2003 03:03:32 -0000	1.152
+++ src/af/gr/win/gr_Win32Graphics.cpp	15 Sep 2003 13:24:35 -0000
@@ -36,8 +36,12 @@
 #include "ut_string.h"
 #include "ut_Win32OS.h"
 
-#define WIN_SCALE_RATIO 1440.0/72.
-#define NEW_SCALE 1
+                                                                                
+
+	
+
+#define WIN_SCALE_RATIO 1440.0/72.                                              
+#define NEW_SCALE 0                                                             
 
 //#define GR_GRAPHICS_DEBUG	1
 
@@ -197,10 +201,10 @@
         {
                 // lazily grab this (once)
                 HFONT f = (HFONT) GetStockObject(DEFAULT_GUI_FONT);
-		LOGFONT lf;
-		int iRes = GetObject(f, sizeof(LOGFONT), &lf);
-		UT_sint32 iHeight = static_cast<UT_sint32>(lf.lfHeight);
-		m_pFontGUI = new GR_Win32Font(f, this,iHeight);
+		LOGFONT lf;                                                     
+		int iRes = GetObject(f, sizeof(LOGFONT), &lf);                  
+		UT_sint32 iHeight = static_cast<UT_sint32>(lf.lfHeight);                                                                                     
+		m_pFontGUI = new GR_Win32Font(f, this,iHeight);                 
                 UT_ASSERT(m_pFontGUI);
         }
 
@@ -285,7 +289,7 @@
         if (!hFont)
                 return 0;
 
-	return new GR_Win32Font(hFont, this,iHeight);
+	return new GR_Win32Font(hFont, this, iHeight);
 }
 
 void GR_Win32Graphics::drawGlyph(UT_uint32 Char, UT_sint32 xoff, UT_sint32 yoff)
@@ -342,41 +346,6 @@
         }
 }
 
-
-UT_uint16*	GR_Win32Graphics::_remapGlyphs(const UT_UCSChar* pChars, int iCharOffset, int &iLength)
-{
-	// TODO -- make this handle 32-bit chars properly
-	if (iLength > (int)m_remapBufferSize)
-	{
-		delete [] m_remapBuffer;
-
-		if(XAP_App::getApp()->theOSHasBidiSupport() != XAP_App::BIDI_SUPPORT_NONE)
-		{
-			delete [] m_remapIndices;
-			m_remapIndices = new UT_UCS2Char[iLength];
-		}
-
-		m_remapBuffer = new UT_UCS2Char[iLength];
-		m_remapBufferSize = iLength;
-	}
-
-    // Need to handle zero-width spaces correctly
-	int i, j;
-	for (i = 0, j = 0; i < iLength; ++i, ++j)
-	{
-		m_remapBuffer[j] = (UT_UCS2Char)pChars[iCharOffset + i];
-		
-		if(m_remapBuffer[j] == 0x200B || m_remapBuffer[j] == 0xFEFF
-		   /*|| m_remapBuffer[j] == UCS_LIGATURE_PLACEHOLDER*/)
-			j--;
-	}
-
-	iLength -= (i - j);
-
-	return m_remapBuffer;
-}
-
-
 void GR_Win32Graphics::drawChars(const UT_UCSChar* pChars,
                                                                  int iCharOffset, int iLengthOrig,
                                                                  UT_sint32 xoff, UT_sint32 yoff,
@@ -390,7 +359,6 @@
         
         xoff = tdu(xoff);
         yoff = tdu(yoff);
-	int *pCharAdvances = NULL;
         
 
         // iLength can be modified by _remapGlyphs
@@ -420,13 +388,13 @@
                 int iConverted = WideCharToMultiByte(CP_ACP, NULL,
                         (LPCWSTR) currentChars, iLength,
                         str, iLength * sizeof(UT_UCSChar), NULL, NULL);
-
                 ExtTextOutA(m_hdc, xoff, yoff, 0, NULL, str, iConverted, NULL);
                 delete [] str;
         }
         else
         {
                 int duCharWidths [256];
+		int *pCharAdvances;
 
                 if (pCharWidths)
                 {
@@ -440,26 +408,19 @@
                         // all 0x200B and 0xFEFF characters, we also have to
                         // remove their entires from the advances
                         UT_sint32 i,j;
-			UT_sint32 iwidth = 0;
-			UT_sint32 iadvance = 0;
-			UT_sint32 inextAdvance = 0;
+			
                         for (i = 0, j = 0; i < iLengthOrig; i++)
                         {
                                 if(! (pChars[iCharOffset+i] == 0x200B || pChars[iCharOffset+i] == 0xFEFF
                                    /*|| pChars[iCharOffset+i] == UCS_LIGATURE_PLACEHOLDER*/ ) )
                                 {
-					iwidth += pCharWidths[i];
-					inextAdvance = tdu(iwidth);
-					pCharAdvances[j] = inextAdvance - iadvance;
-					iadvance = inextAdvance;
-					j++;
+					pCharAdvances[j] = tdu (pCharWidths[i]);					
+                    j++;
                                 }
                         }
                 }
                 else
-		  {
                         pCharAdvances=NULL;
-		  }
 
                 // Unicode font and default character set handling for WinNT and Win9x
 
@@ -521,6 +482,39 @@
 
 }
 
+UT_uint16*	GR_Win32Graphics::_remapGlyphs(const UT_UCSChar* pChars, int iCharOffset, int &iLength)
+{
+	// TODO -- make this handle 32-bit chars properly
+	if (iLength > (int)m_remapBufferSize)
+	{
+		delete [] m_remapBuffer;
+
+		if(XAP_App::getApp()->theOSHasBidiSupport() != XAP_App::BIDI_SUPPORT_NONE)
+		{
+			delete [] m_remapIndices;
+			m_remapIndices = new UT_UCS2Char[iLength];
+		}
+
+		m_remapBuffer = new UT_UCS2Char[iLength];
+		m_remapBufferSize = iLength;
+	}
+
+    // Need to handle zero-width spaces correctly
+	int i, j;
+	for (i = 0, j = 0; i < iLength; ++i, ++j)
+	{
+		m_remapBuffer[j] = (UT_UCS2Char)pChars[iCharOffset + i];
+		
+		if(m_remapBuffer[j] == 0x200B || m_remapBuffer[j] == 0xFEFF
+		   /*|| m_remapBuffer[j] == UCS_LIGATURE_PLACEHOLDER*/)
+			j--;
+	}
+
+	iLength -= (i - j);
+
+	return m_remapBuffer;
+}
+
 void GR_Win32Graphics::setFont(GR_Font* pFont)
 {
         UT_ASSERT(pFont);	// TODO should we allow pFont == NULL?
@@ -1291,7 +1285,7 @@
         m_defaultCharWidth(0),
         m_tm(TEXTMETRIC()),
         m_pG(pG),
-	m_iUnScaled(iHeight)
+	m_iUnScaled(iHeight)  
 {
         UT_ASSERT(m_hFont);
 
@@ -1375,20 +1369,21 @@
         // calculate the limits of the 256-char page
         UT_UCS4Char base = (cChar & 0xffffff00);
         UT_UCS4Char limit = (cChar | 0x000000ff);
-#if NEW_SCALE
-	LOGFONT lf;
-	int iRes = GetObject(m_hFont, sizeof(LOGFONT), &lf);
-	lf.lfHeight= static_cast<LONG>(static_cast<double>(m_iUnScaled)*  WIN_SCALE_RATIO);
-	HFONT hFont = CreateFontIndirect(&lf);
-	HDC hdc = CreateDC("DISPLAY",NULL,NULL,NULL);
-	SelectObject(hdc,hFont);
-	_getCharWidths()->setCharWidthsOfRange(hdc, base, limit, m_pG);
-	DeleteObject(hFont);
-	DeleteDC(hdc);
-#else
+	
+	
+	#if NEW_SCALE                                                                               
+        LOGFONT lf;                                                             
+        int iRes = GetObject(m_hFont, sizeof(LOGFONT), &lf);                    
+        lf.lfHeight= static_cast<LONG>(static_cast<double>(m_iUnScaled)*  WIN_SCALE_RATIO);
+        HFONT hFont = CreateFontIndirect(&lf);                                  
+        HDC hdc = CreateDC("DISPLAY",NULL,NULL,NULL);                           
+        SelectObject(hdc,hFont);                                                
+        _getCharWidths()->setCharWidthsOfRange(hdc, base, limit, m_pG);         
+        DeleteObject(hFont);                                                    
+        DeleteDC(hdc);                                                          
+	#else  	
         _getCharWidths()->setCharWidthsOfRange(m_oldHDC, base, limit, m_pG);
-
-#endif	
+	#endif
         return _getCharWidths()->getWidth(cChar);
 }
 
@@ -1413,19 +1408,7 @@
         UINT d = m_tm.tmDefaultChar;
 
         UT_return_if_fail(_getCharWidths());
-#if NEW_SCALE
-	LOGFONT lf;
-	int iRes = GetObject(m_hFont, sizeof(LOGFONT), &lf);
-	lf.lfHeight = static_cast<LONG>(static_cast<double>(m_iUnScaled)*  WIN_SCALE_RATIO);
-	HFONT hFont = CreateFontIndirect(&lf);
-	HDC hdc = CreateDC("DISPLAY",NULL,NULL,NULL);
-	SelectObject(hdc,hFont);
-	_getCharWidths()->setCharWidthsOfRange(hdc, d, d, m_pG);
-	DeleteObject(hFont);
-	DeleteDC(hdc);
-#else
         _getCharWidths()->setCharWidthsOfRange(m_oldHDC, d, d, m_pG);
-#endif
         m_defaultCharWidth = getCharWidthFromCache(d);
 }
 
Index: src/af/gr/win/gr_Win32Graphics.h
===================================================================
RCS file: /cvsroot/abi/src/af/gr/win/gr_Win32Graphics.h,v
retrieving revision 1.69
diff -u -r1.69 gr_Win32Graphics.h
--- src/af/gr/win/gr_Win32Graphics.h	11 Sep 2003 03:03:33 -0000	1.69
+++ src/af/gr/win/gr_Win32Graphics.h	15 Sep 2003 13:24:35 -0000
@@ -35,7 +35,7 @@
 class GR_Win32Font : public GR_Font
 {
 public:
-	GR_Win32Font(HFONT hFont, GR_Graphics * pGr, UT_sint32 iUnscaled);
+	GR_Win32Font(HFONT hFont, GR_Graphics * pGr, UT_sint32 iUnscaled); 
         ~GR_Win32Font();
 
 
@@ -80,7 +80,7 @@
         UT_uint32				m_defaultCharWidth;
         TEXTMETRIC				m_tm;
         GR_Graphics            *m_pG;
-	UT_sint32               m_iUnScaled;
+	UT_sint32               m_iUnScaled; 
 };
 
 //////////////////////////////////////////////////////////////////
This archive was generated by hypermail 2.1.4 : Mon Sep 15 2003 - 09:38:16 EDT