ooo-build r11636 - in trunk: . patches/ooxml patches/src680



Author: pflin
Date: Wed Feb 20 08:24:06 2008
New Revision: 11636
URL: http://svn.gnome.org/viewvc/ooo-build?rev=11636&view=rev

Log:
	* patches/src680/cws-cjksp1-officecfg.diff,  
	* patches/src680/cws-cjksp1-sw.diff,  
	* patches/src680/cws-cjksp1-xmloff.diff: updated the patch for text grid 
   	  from the CWS cjksp1

	* patches/src680/text_grid_enhancement_filter.diff,  
	* patches/src680/text_grid_enhancement_officecfg.diff,  
	* patches/src680/text_grid_enhancement_layout.diff,  
	* patches/src680/text_grid_enhancement_ww8_filter.diff: removed the
  	  old patch

	* patches/src680/cjk-character-units-imp.diff,  
	* patches/src680/cjk-character-units-rulers-sync-with-pggrid-fix.diff,  
	* patches/ooxml/cws-xmlfilter02-sw.diff: fixed some conflicts.  

	* patches/src680/apply. 	



Added:
   trunk/patches/src680/cws-cjksp1-officecfg.diff
   trunk/patches/src680/cws-cjksp1-sw.diff
   trunk/patches/src680/cws-cjksp1-xmloff.diff
Removed:
   trunk/patches/src680/text_grid_enhancement_filter.diff
   trunk/patches/src680/text_grid_enhancement_layout.diff
   trunk/patches/src680/text_grid_enhancement_officecfg.diff
   trunk/patches/src680/text_grid_enhancement_ww8_filter.diff
Modified:
   trunk/ChangeLog
   trunk/patches/ooxml/cws-xmlfilter02-sw.diff
   trunk/patches/src680/apply
   trunk/patches/src680/cjk-character-units-imp.diff
   trunk/patches/src680/cjk-character-units-rulers-sync-with-pggrid-fix.diff

Modified: trunk/patches/ooxml/cws-xmlfilter02-sw.diff
==============================================================================
--- trunk/patches/ooxml/cws-xmlfilter02-sw.diff	(original)
+++ trunk/patches/ooxml/cws-xmlfilter02-sw.diff	Wed Feb 20 08:24:06 2008
@@ -40,10 +40,10 @@
  	sal_uInt32  n32DummyCompatabilityOptions1;
 --- sw/inc/unoprnms.hxx	18 Jul 2007 12:55:53 -0000	1.121
 +++ sw/inc/unoprnms.hxx	12 Oct 2007 07:49:09 -0000	1.121.108.1
-@@ -789,7 +789,8 @@ enum SwPropNameIds
+@@ -793,7 +793,8 @@ enum SwPropNameIds
  /* 0717 */  UNO_NAME_GRID_BASE_WIDTH,
  /* 0718 */  UNO_NAME_GRID_SNAP_TO_CHARS,
- /* 0719 */  UNO_NAME_GRID_SQUARE_PAGE_MODE,
+ /* 0719 */  UNO_NAME_GRID_STANDARD_PAGE_MODE,
 -/* 0720 */  SW_PROPNAME_END
 +/* 0720 */  UNO_NAME_ROW_SPAN,
 +/* 0721 */  SW_PROPNAME_END
@@ -296,13 +296,13 @@
  				};
 --- sw/source/core/unocore/unoprnms.cxx	18 Jul 2007 12:58:06 -0000	1.130
 +++ sw/source/core/unocore/unoprnms.cxx	12 Oct 2007 07:49:09 -0000	1.130.108.1
-@@ -771,7 +771,8 @@ const SwPropNameTab aPropNameTab = {
+@@ -774,7 +774,8 @@ const SwPropNameTab aPropNameTab = {
  /* 0716 UNO_NAME_INPUT */                {MAP_CHAR_LEN("Input")},
- /* 0717 UNO_NAME_GRID_BASE_WIDTH*/      {MAP_CHAR_LEN("GridBaseWidth")},
- /* 0718 UNO_NAME_GRID_SNAP_TO_CHARS*/   {MAP_CHAR_LEN("GridSnapToChars")},
--/* 0719 UNO_NAME_SQUARE_PAGE_MODE*/     {MAP_CHAR_LEN("SquarePageMode")}
-+/* 0719 UNO_NAME_SQUARE_PAGE_MODE*/     {MAP_CHAR_LEN("SquarePageMode")},
-+/* 0717 UNO_NAME_ROW_SPAN */            {MAP_CHAR_LEN("RowSpan")}
+ /* 0717 UNO_NAME_GRID_BASE_WIDTH*/ {MAP_CHAR_LEN("GridBaseWidth")},
+ /* 0718 UNO_NAME_GRID_SNAP_TO_CHARS*/ {MAP_CHAR_LEN("GridSnapToChars")},
+-/* 0719 UNO_NAME_GRID_STANDARD_PAGE_MODE*/ {MAP_CHAR_LEN("StandardPageMode")}
++/* 0719 UNO_NAME_GRID_STANDARD_PAGE_MODE*/ {MAP_CHAR_LEN("StandardPageMode")},
++/* 0720 UNO_NAME_ROW_SPAN */            {MAP_CHAR_LEN("RowSpan")}
  };
  
  const SwPropNameLen& SwGetPropName( USHORT nId )

Modified: trunk/patches/src680/apply
==============================================================================
--- trunk/patches/src680/apply	(original)
+++ trunk/patches/src680/apply	Wed Feb 20 08:24:06 2008
@@ -229,10 +229,9 @@
 sw-default-cjk-fontsize.diff i#72010, jianhua
 
 # Text grid enhancement for better CJK support
-text_grid_enhancement_ww8_filter.diff, Fong Lin
-text_grid_enhancement_officecfg.diff, Fong Lin
-text_grid_enhancement_layout.diff, Fong Lin
-text_grid_enhancement_filter.diff, Fong Lin
+cws-cjksp1-officecfg.diff, Fong Lin
+cws-cjksp1-sw.diff, Fong Lin
+cws-cjksp1-xmloff.diff, Fong Lin
 
 # add a new unit 'character unit'
 cjk-character-units-ui.diff, Amelia Wang

Modified: trunk/patches/src680/cjk-character-units-imp.diff
==============================================================================
--- trunk/patches/src680/cjk-character-units-imp.diff	(original)
+++ trunk/patches/src680/cjk-character-units-imp.diff	Wed Feb 20 08:24:06 2008
@@ -436,7 +436,7 @@
      sal_Int32   GetDefTab() const { return nDefTab;}
      void        SetDefTab( sal_Int32  nSet, sal_Bool bNoModify = sal_False )
                  {
-diff -uNr sw/source/ui/misc/pggrid.cxx sw/source/ui/misc/pggrid.cxx
++diff -uNr sw/source/ui/misc/pggrid.cxx sw/source/ui/misc/pggrid.cxx
 --- sw/source/ui/misc/pggrid.cxx	2007-12-17 01:41:49.000000000 +0800
 +++ sw/source/ui/misc/pggrid.cxx	2007-12-17 11:13:59.000000000 +0800
 @@ -149,7 +149,9 @@
@@ -450,7 +450,7 @@
  
      Link aLink = LINK(this, SwTextGridPage, CharorLineChangedHdl);
      aCharsPerLineNF.SetUpHdl(aLink);
-@@ -346,6 +348,11 @@
+@@ -346,6 +348,10 @@
          aGridItem.SetPrintGrid(aPrintCB.IsChecked());
          aGridItem.SetColor(aColorLB.GetSelectEntryColor());
          rSet.Put(aGridItem);
@@ -458,12 +458,11 @@
 +        SwView * pView = ::GetActiveView();
 +        pView->GetHLineal().SetCharWidth((long)(aCharWidthMF.GetValue(FUNIT_TWIP)/56.7));
 +        pView->GetVLineal().SetLineHeight((long)(aTextSizeMF.GetValue(FUNIT_TWIP)/56.7));
-+
  }
  /* -----------------------------08.02.2002 10:54------------------------------
  
-@@ -450,6 +457,10 @@
-             long nHeight = m_aPageSize.Height() / aLinesPerPageNF.GetValue();
+@@ -450,6 +456,10 @@
+             long nHeight = static_cast< sal_Int32 >(m_aPageSize.Height() / aLinesPerPageNF.GetValue());
              aTextSizeMF.SetValue(aTextSizeMF.Normalize(nHeight), FUNIT_TWIP);
              aRubySizeMF.SetValue(0, FUNIT_TWIP);
 +            String aMaxLinesFTStr = String::CreateFromAscii("( 1 - ");
@@ -473,9 +472,9 @@
              
              m_nRubyUserValue = nHeight;
              m_bRubyUserValue = sal_True;
-@@ -458,6 +469,10 @@
+@@ -458,6 +468,10 @@
          {
-             long nWidth = m_aPageSize.Width() / aCharsPerLineNF.GetValue();
+             long nWidth = static_cast< sal_Int32 >(m_aPageSize.Width() / aCharsPerLineNF.GetValue());
              aCharWidthMF.SetValue(aCharWidthMF.Normalize(nWidth), FUNIT_TWIP);
 +            String aMaxCharsFTStr = String::CreateFromAscii("( 1 - ");
 +            aMaxCharsFTStr += String::CreateFromInt32(aCharsPerLineNF.GetValue());
@@ -484,23 +483,16 @@
          }
      }
      GridModifyHdl(0);
-@@ -473,13 +488,12 @@
+@@ -473,7 +487,6 @@
          if (&aTextSizeMF == pField)
-         {
-             sal_Int32 nTextSize = aTextSizeMF.Denormalize(aTextSizeMF.GetValue(FUNIT_TWIP));
--            aCharsPerLineNF.SetValue(m_aPageSize.Width() / nTextSize);
-             m_bRubyUserValue = sal_False;
-         }
+     {
+         sal_Int32 nTextSize = static_cast< sal_Int32 >(aTextSizeMF.Denormalize(aTextSizeMF.GetValue(FUNIT_TWIP)));
+-        aCharsPerLineNF.SetValue(m_aPageSize.Width() / nTextSize);
+         m_bRubyUserValue = sal_False;
+     }
  		//set maximum line per page
-         {
-             sal_Int32 nMaxLines = m_aPageSize.Height() /
--                (   aTextSizeMF.Denormalize(aTextSizeMF.GetValue(FUNIT_TWIP)) +
-+               (   aTextSizeMF.Denormalize(aTextSizeMF.GetValue(FUNIT_TWIP)) +
-                     aRubySizeMF.Denormalize(aRubySizeMF.GetValue(FUNIT_TWIP)));
-             aLinesPerPageNF.SetMax(nMaxLines);
-         }
-@@ -491,14 +505,22 @@
-             sal_Int32 nTextSize = static_cast< sal_Int32 >(aTextSizeMF.Denormalize(aTextSizeMF.GetValue(FUNIT_TWIP)));
+@@ -491,14 +504,22 @@
+             sal_Int32 nTextSize = static_cast< sal_Int32 >(aTextSizeMF.Denormalize(aTextSizeMF.GetValue(FUNIT_TWIP)));
              aLinesPerPageNF.SetValue(m_aPageSize.Height() / nTextSize);
              m_bRubyUserValue = sal_False;
 +            String aRangesStr = String::CreateFromAscii("( 1 - ");
@@ -510,7 +502,7 @@
          }
          else if (&aCharWidthMF == pField)
          {
-             sal_Int32 nTextWidth = static_cast< sal_Int32 >(aCharWidthMF.Denormalize(aCharWidthMF.GetValue(FUNIT_TWIP)));
+             sal_Int32 nTextWidth = static_cast< sal_Int32 >(aCharWidthMF.Denormalize(aCharWidthMF.GetValue(FUNIT_TWIP)));
 +            sal_Int32 nMaxChar = 45 ;
              if (nTextWidth)
 -                aCharsPerLineNF.SetValue(m_aPageSize.Width() / nTextWidth); 
@@ -525,7 +517,7 @@
          }
          //rubySize is disabled
      }
-@@ -526,6 +548,7 @@
+@@ -526,6 +547,7 @@
  	{
  		aCharsPerLineFT.Enable(sal_False);
  		aCharsPerLineNF.Enable(sal_False);

Modified: trunk/patches/src680/cjk-character-units-rulers-sync-with-pggrid-fix.diff
==============================================================================
--- trunk/patches/src680/cjk-character-units-rulers-sync-with-pggrid-fix.diff	(original)
+++ trunk/patches/src680/cjk-character-units-rulers-sync-with-pggrid-fix.diff	Wed Feb 20 08:24:06 2008
@@ -62,18 +62,17 @@
      m_bRubyUserValue(sal_False),
      m_aPageSize(MM50, MM50),
      m_bVertical(sal_False),
--    m_bSquaredMode(sal_False)
-+    m_bSquaredMode(sal_False),
+-	m_bSquaredMode(sal_False)
++	m_bSquaredMode(sal_False),
 +    m_bHRulerChanged( sal_False ),
 +    m_bVRulerChanged( sal_False )
  {
      FreeResource();
  
-@@ -261,7 +263,12 @@
-         PutGridItem(rSet);
+@@ -262,6 +264,12 @@
          bRet = TRUE;
      }
--
+ 
 +    // draw ticks of ruler
 +    SwView * pView = ::GetActiveView();
 +    if ( m_bHRulerChanged )
@@ -83,14 +82,13 @@
      return bRet;
  }
  /*-- 06.02.2002 15:25:40---------------------------------------------------
-@@ -349,10 +356,17 @@
+@@ -349,9 +357,17 @@
          aGridItem.SetColor(aColorLB.GetSelectEntryColor());
          rSet.Put(aGridItem);
  /// Amelia
 -        SwView * pView = ::GetActiveView();
 -        pView->GetHLineal().SetCharWidth((long)(aCharWidthMF.GetValue(FUNIT_TWIP)/56.7));
 -        pView->GetVLineal().SetLineHeight((long)(aTextSizeMF.GetValue(FUNIT_TWIP)/56.7));
--
 +        if ( aGridItem.GetGridType() != GRID_NONE )
 +        {
 +            SwView * pView = ::GetActiveView();

Added: trunk/patches/src680/cws-cjksp1-officecfg.diff
==============================================================================
--- (empty file)
+++ trunk/patches/src680/cws-cjksp1-officecfg.diff	Wed Feb 20 08:24:06 2008
@@ -0,0 +1,17 @@
+diff -uNpr officecfg.bk/registry/schema/org/openoffice/Office/Writer.xcs officecfg/registry/schema/org/openoffice/Office/Writer.xcs
+--- officecfg.bk/registry/schema/org/openoffice/Office/Writer.xcs	2008-02-19 15:21:03.000000000 +0800
++++ officecfg/registry/schema/org/openoffice/Office/Writer.xcs	2008-02-19 15:21:31.000000000 +0800
+@@ -1589,6 +1589,13 @@
+ 					</info>
+ 					<value>1250</value>
+ 				</prop>
++				<prop oor:name="IsSquaredPageMode" oor:type="xs:boolean">
++					<info>
++						<desc>Specified which kind of paper mode is used in the whole document </desc>
++						<label>Use squared paper mode</label>
++					</info>
++					<value>true</value>
++				</prop>	
+ 			</group>
+ 			<group oor:name="Zoom">
+ 				<info>

Added: trunk/patches/src680/cws-cjksp1-sw.diff
==============================================================================
--- (empty file)
+++ trunk/patches/src680/cws-cjksp1-sw.diff	Wed Feb 20 08:24:06 2008
@@ -0,0 +1,1836 @@
+diff -uNpr sw.bak/inc/doc.hxx sw/inc/doc.hxx
+--- sw.bak/inc/doc.hxx	2008-02-19 15:12:39.000000000 +0800
++++ sw/inc/doc.hxx	2008-02-19 15:20:17.000000000 +0800
+@@ -1999,6 +1999,10 @@ public:
+     }
+     void SetApplyWorkaroundForB6375613( bool p_bApplyWorkaroundForB6375613 );
+     // <--
++     
++     //Update all the page masters
++     SW_DLLPUBLIC void SetDefaultPageMode(bool bSquaredPageMode);
++     SW_DLLPUBLIC sal_Bool IsSquaredPageMode() const;    
+ 
+ 	// i#78591#
+ 	void Setn32DummyCompatabilityOptions1( sal_uInt32 CompatabilityOptions1 )
+diff -uNpr sw.bak/inc/swmodule.hxx sw/inc/swmodule.hxx
+--- sw.bak/inc/swmodule.hxx	2008-02-19 15:12:39.000000000 +0800
++++ sw/inc/swmodule.hxx	2008-02-19 15:12:51.000000000 +0800
+@@ -194,6 +194,9 @@ public:
+     SW_DLLPUBLIC void ApplyFldUpdateFlags(SwFldUpdateFlags eFldFlags);
+ 	SW_DLLPUBLIC void ApplyLinkMode(sal_Int32 nNewLinkMode);
+ 
++    //default page mode for text grid 
++    SW_DLLPUBLIC void ApplyDefaultPageMode(sal_Bool bIsSquaredPageMode);
++
+ 	// ConfigItems erzeugen
+ 	SwModuleOptions*    GetModuleConfig()		{ return pModuleConfig;}
+ 	SW_DLLPUBLIC SwPrintOptions* 	GetPrtOptions(sal_Bool bWeb);
+diff -uNpr sw.bak/inc/tgrditem.hxx sw/inc/tgrditem.hxx
+--- sw.bak/inc/tgrditem.hxx	2008-02-19 15:12:39.000000000 +0800
++++ sw/inc/tgrditem.hxx	2008-02-19 15:12:51.000000000 +0800
+@@ -65,6 +65,10 @@ class SW_DLLPUBLIC SwTextGridItem : publ
+ 	BOOL bPrintGrid;
+ 	BOOL bDisplayGrid;
+ 
++	//for textgrid enhancement
++    sal_uInt16 nBaseWidth;
++    BOOL bSnapToChars;
++    BOOL bSquaredMode;
+ public:
+ 	SwTextGridItem();
+ 	virtual ~SwTextGridItem();
+@@ -108,6 +112,21 @@ public:
+     BOOL IsDisplayGrid() const { return bDisplayGrid; }
+     BOOL GetDisplayGrid() const { return bDisplayGrid; }
+     void SetDisplayGrid( BOOL bNew ) { bDisplayGrid = bNew; }
++    
++    //for textgrid enhancement
++    sal_uInt16 GetBaseWidth() const { return nBaseWidth;}
++    void SetBaseWidth( sal_uInt16 nNew ) { nBaseWidth = nNew; }
++    
++    BOOL IsSnapToChars() const { return bSnapToChars; }
++    BOOL GetSnapToChars() const { return bSnapToChars; }
++    void SetSnapToChars( BOOL bNew ) { bSnapToChars = bNew; }
++    
++    BOOL IsSquaredMode() const { return bSquaredMode; }
++    BOOL GetSquaredMode() const { return bSquaredMode; }
++    void SetSquaredMode( BOOL bNew ) { bSquaredMode = bNew; }
++	void SwitchPaperMode(BOOL bNew );
++	
++	void Init();
+ };
+ 
+ inline const SwTextGridItem &SwAttrSet::GetTextGrid(BOOL bInP) const
+diff -uNpr sw.bak/inc/unomid.h sw/inc/unomid.h
+--- sw.bak/inc/unomid.h	2008-02-19 15:12:39.000000000 +0800
++++ sw/inc/unomid.h	2008-02-19 15:12:51.000000000 +0800
+@@ -140,6 +140,9 @@
+ #define MID_GRID_RUBY_BELOW     5
+ #define MID_GRID_PRINT          6
+ #define MID_GRID_DISPLAY        7
++#define MID_GRID_BASEWIDTH      8
++#define MID_GRID_SNAPTOCHARS    9
++#define MID_GRID_STANDARD_MODE    10
+ 
+ //SwEnvItem
+ #define MID_ENV_ADDR_TEXT       1
+diff -uNpr sw.bak/inc/unoprnms.hxx sw/inc/unoprnms.hxx
+--- sw.bak/inc/unoprnms.hxx	2008-02-19 15:12:39.000000000 +0800
++++ sw/inc/unoprnms.hxx	2008-02-19 15:12:51.000000000 +0800
+@@ -789,7 +789,11 @@ enum SwPropNameIds
+ /* 0714 */  UNO_NAME_DIALOG_LIBRARIES,
+ /* 0715 */  UNO_NAME_HEADER_ROW_COUNT,
+ /* 0716 */  UNO_NAME_INPUT,
+-/* 0716 */  SW_PROPNAME_END
++// --> 2007-03-27 text grid enhancement for better CJK support
++/* 0717 */  UNO_NAME_GRID_BASE_WIDTH,
++/* 0718 */  UNO_NAME_GRID_SNAP_TO_CHARS,
++/* 0719 */  UNO_NAME_GRID_STANDARD_PAGE_MODE,
++/* 0720 */  SW_PROPNAME_END
+ };
+ 
+ 
+diff -uNpr sw.bak/source/core/doc/docdesc.cxx sw/source/core/doc/docdesc.cxx
+--- sw.bak/source/core/doc/docdesc.cxx	2008-02-19 15:12:40.000000000 +0800
++++ sw/source/core/doc/docdesc.cxx	2008-02-19 15:12:51.000000000 +0800
+@@ -157,6 +157,8 @@
+ #include <SwUndoPageDesc.hxx>
+ #include <headerfooterhelper.hxx>
+ 
++#include <tgrditem.hxx>
++
+ using namespace com::sun::star;
+ 
+ static void lcl_DefaultPageFmt( sal_uInt16 nPoolFmtId,
+@@ -1069,3 +1071,36 @@ void SwDoc::CheckDefaultPageFmt()
+             lcl_DefaultPageFmt( rDesc.GetPoolFmtId(), rDesc.GetMaster(), rDesc.GetLeft() );
+     }
+ }
++
++void SwDoc::SetDefaultPageMode(bool bSquaredPageMode)
++{
++    if( !bSquaredPageMode == !IsSquaredPageMode() )
++		return;
++
++	const SwTextGridItem& rGrid =
++					(const SwTextGridItem&)GetDefault( RES_TEXTGRID );
++	SwTextGridItem aNewGrid = rGrid;
++	aNewGrid.SetSquaredMode(bSquaredPageMode);
++	aNewGrid.Init();
++	SetDefault(aNewGrid);
++	
++    for ( USHORT i = 0; i < GetPageDescCnt(); ++i )
++    {
++        SwPageDesc& rDesc = _GetPageDesc( i );
++
++        SwFrmFmt& rMaster = rDesc.GetMaster();
++		SwFrmFmt& rLeft = rDesc.GetLeft();
++        
++        SwTextGridItem aGrid((SwTextGridItem&)rMaster.GetAttr(RES_TEXTGRID));
++        aGrid.SwitchPaperMode( bSquaredPageMode );
++		rMaster.SetAttr(aGrid);
++		rLeft.SetAttr(aGrid);
++    }
++}
++
++sal_Bool SwDoc::IsSquaredPageMode() const
++{
++	const SwTextGridItem& rGrid =
++						(const SwTextGridItem&)GetDefault( RES_TEXTGRID );
++	return rGrid.IsSquaredMode();					
++}
+diff -uNpr sw.bak/source/core/inc/pagefrm.hxx sw/source/core/inc/pagefrm.hxx
+--- sw.bak/source/core/inc/pagefrm.hxx	2008-02-19 15:12:40.000000000 +0800
++++ sw/source/core/inc/pagefrm.hxx	2008-02-19 15:12:51.000000000 +0800
+@@ -506,4 +506,9 @@ inline BOOL SwPageFrm::IsInvalidFly() co
+      GetPageDesc()->GetMaster().GetAttr(RES_TEXTGRID))->GetGridType() ) \
+     pGrid = NULL;}
+ 
++#define GETGRIDWIDTH( pGrid , pDoc )  pDoc->IsSquaredPageMode() ? \
++	pGrid->GetBaseHeight(): pGrid->GetBaseWidth()
++
++			
++
+ #endif	//_PAGEFRM_HXX
+diff -uNpr sw.bak/source/core/layout/atrfrm.cxx sw/source/core/layout/atrfrm.cxx
+--- sw.bak/source/core/layout/atrfrm.cxx	2008-02-19 15:12:42.000000000 +0800
++++ sw/source/core/layout/atrfrm.cxx	2008-02-19 15:12:51.000000000 +0800
+@@ -274,6 +274,10 @@
+ #endif
+ // <--
+ 
++#ifndef _SVTOOLS_CJKOPTIONS_HXX
++#include <svtools/cjkoptions.hxx>
++#endif
++
+ using namespace ::com::sun::star;
+ using namespace ::rtl;
+ 
+@@ -2286,7 +2290,8 @@ BOOL SwFmtLineNumber::PutValue( const un
+ SwTextGridItem::SwTextGridItem()
+     : SfxPoolItem( RES_TEXTGRID ), aColor( COL_LIGHTGRAY ), nLines( 20 ),
+       nBaseHeight( 400 ), nRubyHeight( 200 ), eGridType( GRID_NONE ),
+-      bRubyTextBelow( 0 ), bPrintGrid( 1 ), bDisplayGrid( 1 )
++      bRubyTextBelow( 0 ), bPrintGrid( 1 ), bDisplayGrid( 1 ),
++      nBaseWidth(400), bSnapToChars( 1 ), bSquaredMode(1)
+ {
+ }
+ 
+@@ -2304,7 +2309,10 @@ int SwTextGridItem::operator==( const Sf
+            bRubyTextBelow == ((SwTextGridItem&)rAttr).GetRubyTextBelow() &&
+            bDisplayGrid == ((SwTextGridItem&)rAttr).GetDisplayGrid() &&
+            bPrintGrid == ((SwTextGridItem&)rAttr).GetPrintGrid() &&
+-           aColor == ((SwTextGridItem&)rAttr).GetColor();
++           aColor == ((SwTextGridItem&)rAttr).GetColor() && 
++           nBaseWidth == ((SwTextGridItem&)rAttr).GetBaseWidth() && 
++           bSnapToChars == ((SwTextGridItem&)rAttr).GetSnapToChars() &&
++           bSquaredMode == ((SwTextGridItem&)rAttr).GetSquaredMode();
+ }
+ 
+ SfxPoolItem* SwTextGridItem::Clone( SfxItemPool* ) const
+@@ -2322,6 +2330,9 @@ SwTextGridItem& SwTextGridItem::operator
+     bRubyTextBelow = rCpy.GetRubyTextBelow();
+     bPrintGrid = rCpy.GetPrintGrid();
+     bDisplayGrid = rCpy.GetDisplayGrid();
++    nBaseWidth = rCpy.GetBaseWidth();
++    bSnapToChars = rCpy.GetSnapToChars();
++    bSquaredMode = rCpy.GetSquaredMode();
+ 
+ 	return *this;
+ }
+@@ -2352,6 +2363,11 @@ BOOL SwTextGridItem::QueryValue( uno::An
+                         "This value needs TWIPS-MM100 conversion" );
+             rVal <<= (sal_Int32) TWIP_TO_MM100_UNSIGNED(nBaseHeight);
+             break;
++        case MID_GRID_BASEWIDTH:
++            DBG_ASSERT( (nMemberId & CONVERT_TWIPS) != 0,
++                        "This value needs TWIPS-MM100 conversion" );
++            rVal <<= (sal_Int32) TWIP_TO_MM100_UNSIGNED(nBaseWidth);
++            break;
+         case MID_GRID_RUBYHEIGHT:
+             DBG_ASSERT( (nMemberId & CONVERT_TWIPS) != 0,
+                         "This value needs TWIPS-MM100 conversion" );
+@@ -2375,6 +2391,15 @@ BOOL SwTextGridItem::QueryValue( uno::An
+                     break;
+             }
+             break;
++        case MID_GRID_SNAPTOCHARS:
++            rVal.setValue( &bSnapToChars, ::getBooleanCppuType() );
++            break;
++        case MID_GRID_STANDARD_MODE:
++			{
++				sal_Bool bStandardMode = !bSquaredMode;
++    	        rVal.setValue( &bStandardMode, ::getBooleanCppuType() );
++			}
++            break;
+         default:
+             DBG_ERROR("Unknown SwTextGridItem member");
+             bRet = FALSE;
+@@ -2417,6 +2442,7 @@ BOOL SwTextGridItem::PutValue( const uno
+             SetDisplayGrid( *(sal_Bool*)rVal.getValue() );
+             break;
+         case MID_GRID_BASEHEIGHT:
++        case MID_GRID_BASEWIDTH:
+         case MID_GRID_RUBYHEIGHT:
+         {
+             DBG_ASSERT( (nMemberId & CONVERT_TWIPS) != 0,
+@@ -2427,6 +2453,8 @@ BOOL SwTextGridItem::PutValue( const uno
+             if( bRet && (nTmp >= 0) && ( nTmp <= USHRT_MAX) )
+                 if( (nMemberId & ~CONVERT_TWIPS) == MID_GRID_BASEHEIGHT )
+                     SetBaseHeight( (USHORT)nTmp );
++                else if( (nMemberId & ~CONVERT_TWIPS) == MID_GRID_BASEWIDTH )
++                    SetBaseWidth( (USHORT)nTmp );
+                 else
+                     SetRubyHeight( (USHORT)nTmp );
+             else
+@@ -2457,7 +2485,15 @@ BOOL SwTextGridItem::PutValue( const uno
+             }
+             break;
+         }
+-
++        case MID_GRID_SNAPTOCHARS:
++            SetSnapToChars( *(sal_Bool*)rVal.getValue() );
++            break;
++        case MID_GRID_STANDARD_MODE:
++		{
++			sal_Bool bStandard = *(sal_Bool*)rVal.getValue();
++           	SetSquaredMode( !bStandard );
++        	break;
++		}
+         default:
+             DBG_ERROR("Unknown SwTextGridItem member");
+             bRet = FALSE;
+@@ -2466,6 +2502,75 @@ BOOL SwTextGridItem::PutValue( const uno
+     return bRet;
+ }
+ 
++void SwTextGridItem::SwitchPaperMode(BOOL bNew)
++{
++	if( bNew == bSquaredMode )
++	{
++		//same paper mode, not switch
++		return;
++	}
++	
++	// use default value when grid is disable
++	if( eGridType == GRID_NONE )
++	{
++		bSquaredMode = bNew;
++		Init();
++		return;
++	}
++	
++	if( bSquaredMode )
++	{
++		//switch from "squared mode" to "standard mode"
++		nBaseWidth = nBaseHeight;
++		nBaseHeight = nBaseHeight + nRubyHeight;
++		nRubyHeight = 0;
++	}
++	else
++	{
++		//switch from "standard mode" to "squared mode"
++		nRubyHeight = nBaseHeight/3;
++		nBaseHeight = nBaseHeight - nRubyHeight;
++		nBaseWidth = nBaseHeight;
++	}
++	bSquaredMode = !bSquaredMode;
++}
++
++void SwTextGridItem::Init()
++{
++	if( bSquaredMode )
++	{
++		nLines = 20;
++		nBaseHeight = 400;
++		nRubyHeight = 200;
++		eGridType = GRID_NONE;
++		bRubyTextBelow = 0;
++		bPrintGrid = 1;
++		bDisplayGrid = 1;
++		bSnapToChars = 1;
++		nBaseWidth = 400;
++	}
++	else
++	{
++		nLines = 44;
++		nBaseHeight = 312;
++		nRubyHeight = 0;
++		eGridType = GRID_NONE;
++		bRubyTextBelow = 0;
++		bPrintGrid = 1;
++		bDisplayGrid = 1;
++		nBaseWidth = 210;
++		bSnapToChars = 1;
++
++		//default grid type is line only in CJK env
++		//disable this function due to type area change 
++		//if grid type change.
++		//if(SvtCJKOptions().IsAsianTypographyEnabled())
++		//{
++		//	bDisplayGrid = 0;
++		//	eGridType = GRID_LINES_ONLY;
++		//}
++	}
++}
+ // class SwHeaderAndFooterEatSpacingItem
+ 
+ SfxPoolItem* SwHeaderAndFooterEatSpacingItem::Clone( SfxItemPool* ) const
+diff -uNpr sw.bak/source/core/layout/flowfrm.cxx sw/source/core/layout/flowfrm.cxx
+--- sw.bak/source/core/layout/flowfrm.cxx	2008-02-19 15:12:42.000000000 +0800
++++ sw/source/core/layout/flowfrm.cxx	2008-02-19 15:12:51.000000000 +0800
+@@ -1604,7 +1604,9 @@ SwTwips SwFlowFrm::CalcUpperSpace( const
+ 
+     // OD 2004-03-12 #i11860# - consider value of new parameter <_bConsiderGrid>
+     // and use new method <GetUpperSpaceAmountConsideredForPageGrid(..)>
+-    if ( _bConsiderGrid )
++
++	//consider grid in square page mode
++    if ( _bConsiderGrid && rThis.GetUpper()->GetFmt()->GetDoc()->IsSquaredPageMode() )
+     {
+         nUpper += _GetUpperSpaceAmountConsideredForPageGrid( nUpper );
+     }
+diff -uNpr sw.bak/source/core/layout/pagechg.cxx sw/source/core/layout/pagechg.cxx
+--- sw.bak/source/core/layout/pagechg.cxx	2008-02-19 15:12:42.000000000 +0800
++++ sw/source/core/layout/pagechg.cxx	2008-02-19 15:12:51.000000000 +0800
+@@ -178,7 +178,9 @@ void SwBodyFrm::Format( const SwBorderAt
+             long nBorder = 0;
+             if( GRID_LINES_CHARS == pGrid->GetGridType() )
+             {
+-                nBorder = nSize % pGrid->GetBaseHeight();
++                //for textgrid refactor
++				SwDoc *pDoc = GetFmt()->GetDoc();	
++                nBorder = nSize % (GETGRIDWIDTH(pGrid, pDoc));
+                 nSize -= nBorder;
+                 nBorder /= 2;
+             }
+diff -uNpr sw.bak/source/core/layout/paintfrm.cxx sw/source/core/layout/paintfrm.cxx
+--- sw.bak/source/core/layout/paintfrm.cxx	2008-02-19 15:12:42.000000000 +0800
++++ sw/source/core/layout/paintfrm.cxx	2008-02-19 15:12:51.000000000 +0800
+@@ -4903,6 +4903,8 @@ void SwPageFrm::PaintGrid( OutputDevice*
+                 BOOL bGrid = pGrid->GetRubyTextBelow();
+                 BOOL bCell = GRID_LINES_CHARS == pGrid->GetGridType();
+                 long nGrid = pGrid->GetBaseHeight();
++				const SwDoc* pDoc = GetFmt()->GetDoc();
++                long nGridWidth = GETGRIDWIDTH(pGrid,pDoc); //for textgrid refactor
+                 long nRuby = pGrid->GetRubyHeight();
+                 long nSum = nGrid + nRuby;
+                 const Color *pCol = &pGrid->GetColor();
+@@ -5046,10 +5048,11 @@ void SwPageFrm::PaintGrid( OutputDevice*
+                     SwTwips nY = nOrig + nSum *( (aInter.Top()-nOrig)/nSum );
+                     SwRect aTmp( Point( aInter.Left(), nY ),
+                                 Size( aInter.Width(), 1 ) );
+-                    SwTwips nX = aGrid.Left() + nGrid *
+-                                ( ( aInter.Left() - aGrid.Left() )/ nGrid );
++                    //for textgrid refactor
++                    SwTwips nX = aGrid.Left() + nGridWidth *
++                        ( ( aInter.Left() - aGrid.Left() )/ nGridWidth );
+                     if( nX < aInter.Left() )
+-                        nX += nGrid;
++                        nX += nGridWidth;
+                     SwTwips nGridRight = aGrid.Left() + aGrid.Width();
+                     BOOL bLeft = aGrid.Left() >= aInter.Left();
+                     BOOL bRight = nGridRight <= nRight;
+@@ -5071,7 +5074,7 @@ void SwPageFrm::PaintGrid( OutputDevice*
+                                     while( aVert.Left() <= nRight )
+                                     {
+                                         PaintBorderLine(rRect,aVert,this,pCol);
+-                                        aVert.Pos().X() += nGrid;
++                                        aVert.Pos().X() += nGridWidth;	//for textgrid refactor
+                                     }
+                                 }
+                                 else if ( bBorder )
+@@ -5128,7 +5131,7 @@ void SwPageFrm::PaintGrid( OutputDevice*
+                                     while( aVert.Left() <= nRight )
+                                     {
+                                         PaintBorderLine( rRect, aVert, this, pCol);
+-                                        aVert.Pos().X() += nGrid;
++                                        aVert.Pos().X() += nGridWidth;	//for textgrid refactor
+                                     }
+                                 }
+                                 else if( bBorder )
+diff -uNpr sw.bak/source/core/text/itrform2.cxx sw/source/core/text/itrform2.cxx
+--- sw.bak/source/core/text/itrform2.cxx	2008-02-19 15:12:41.000000000 +0800
++++ sw/source/core/text/itrform2.cxx	2008-02-19 15:12:51.000000000 +0800
+@@ -473,8 +473,9 @@ void SwTxtFormatter::BuildPortions( SwTx
+     const sal_Bool bHasGrid = pGrid && rInf.SnapToGrid() &&
+                               GRID_LINES_CHARS == pGrid->GetGridType();
+ 
++	const SwDoc *pDoc = rInf.GetTxtFrm()->GetNode()->GetDoc();
+     const USHORT nGridWidth = bHasGrid ?
+-                              pGrid->GetBaseHeight() : 0;
++                                GETGRIDWIDTH(pGrid,pDoc) : 0;	//for textgrid refactor
+ 
+     // used for grid mode only:
+     // the pointer is stored, because after formatting of non-asian text,
+diff -uNpr sw.bak/source/core/text/itrtxt.cxx sw/source/core/text/itrtxt.cxx
+--- sw.bak/source/core/text/itrtxt.cxx	2008-02-19 15:12:41.000000000 +0800
++++ sw/source/core/text/itrtxt.cxx	2008-02-19 15:12:51.000000000 +0800
+@@ -340,7 +340,6 @@ USHORT SwTxtCursor::AdjustBaseLine( cons
+ 
+     if ( bHasGrid )
+     {
+-        const USHORT nGridWidth = pGrid->GetBaseHeight();
+         const USHORT nRubyHeight = pGrid->GetRubyHeight();
+         const sal_Bool bRubyTop = ! pGrid->GetRubyTextBelow();
+ 
+@@ -359,9 +358,12 @@ USHORT SwTxtCursor::AdjustBaseLine( cons
+             {
+                 // Portions which are bigger than on grid distance are
+                 // centered inside the whole line.
+-                const USHORT nLineNetto = ( nPorHeight > nGridWidth ) ?
+-                                            rLine.Height() - nRubyHeight :
+-                                            nGridWidth;
++                
++                //for text refactor
++                const USHORT nLineNetto =  rLine.Height() - nRubyHeight;
++                //const USHORT nLineNetto = ( nPorHeight > nGridWidth ) ?
++                 //                           rLine.Height() - nRubyHeight :
++                 //                           nGridWidth;
+                 nOfst += ( nLineNetto - nPorHeight ) / 2;
+                 if ( bRubyTop )
+                     nOfst = nOfst + nRubyHeight;
+diff -uNpr sw.bak/source/core/text/txtfly.cxx sw/source/core/text/txtfly.cxx
+--- sw.bak/source/core/text/txtfly.cxx	2008-02-19 15:12:41.000000000 +0800
++++ sw/source/core/text/txtfly.cxx	2008-02-19 15:12:51.000000000 +0800
+@@ -153,6 +153,9 @@
+ #ifndef PRODUCT
+ #include "viewopt.hxx"	// SwViewOptions, nur zum Testen (Test2)
+ #endif
++#ifndef _DOC_HXX 
++#include "doc.hxx"
++#endif
+ 
+ using namespace ::com::sun::star;
+ 
+@@ -682,7 +685,8 @@ void SwTxtFormatter::CalcFlyWidth( SwTxt
+                                     (pBody->*fnRect->fnGetPrtLeft)() :
+                                     (pPageFrm->*fnRect->fnGetPrtLeft)();
+ 
+-            const USHORT nGridWidth = pGrid->GetBaseHeight();
++			const SwDoc *pDoc = rInf.GetTxtFrm()->GetNode()->GetDoc();
++            const USHORT nGridWidth = GETGRIDWIDTH( pGrid, pDoc);	//for textgrid refactor
+ 
+             SwTwips nStartX = GetLeftMargin();
+             if ( bVert )
+diff -uNpr sw.bak/source/core/txtnode/fntcache.cxx sw/source/core/txtnode/fntcache.cxx
+--- sw.bak/source/core/txtnode/fntcache.cxx	2008-02-19 15:12:42.000000000 +0800
++++ sw/source/core/txtnode/fntcache.cxx	2008-02-19 15:12:51.000000000 +0800
+@@ -114,6 +114,18 @@
+ #include <svtools/accessibilityoptions.hxx>
+ #endif
+ 
++#ifndef _DOC_HXX
++#include <doc.hxx>
++#endif
++#ifndef _SVX_FHGTITEM_HXX
++#include <svx/fhgtitem.hxx>
++#endif
++#ifndef _SWDOCSH_HXX
++#include <docsh.hxx>
++#endif
++#ifndef _POOLFMT_HRC
++#include <poolfmt.hrc>
++#endif
+ // Enable this to use the helpclass SwRVPMark
+ #if OSL_DEBUG_LEVEL > 1
+ #ifndef _RVP_MARK_HXX
+@@ -138,6 +150,18 @@ MapMode* SwFntObj::pPixMap = NULL;
+ OutputDevice* SwFntObj::pPixOut = NULL;
+ 
+ extern USHORT UnMapDirection( USHORT nDir, const BOOL bVertFormat );
++USHORT GetDefaultFontHeight( SwDrawTextInfo &rInf )
++{
++    SwDocShell* pDocShell = rInf.GetShell()->GetDoc()->GetDocShell();
++    SfxStyleSheetBasePool* pBasePool = pDocShell->GetStyleSheetPool();
++    
++    String aString(SW_RES(STR_POOLCOLL_STANDARD));
++    
++    SfxStyleSheetBase* pStyle = pBasePool->Find( aString, (SfxStyleFamily)SFX_STYLE_FAMILY_PARA );
++    SfxItemSet& aTmpSet = pStyle->GetItemSet();
++    SvxFontHeightItem &aDefaultFontItem = (SvxFontHeightItem&)aTmpSet.Get(RES_CHRATR_CJK_FONTSIZE); 
++    return (USHORT)aDefaultFontItem.GetHeight();
++}
+ 
+ #ifdef _RVP_MARK_HXX
+ 
+@@ -1056,16 +1080,19 @@ void SwFntObj::DrawText( SwDrawTextInfo 
+ 
+ 
+     //
+-    // ASIAN LINE AND CHARACTER GRID MODE START
++    // ASIAN LINE AND CHARACTER GRID MODE START: snap to characters
+     //
+ 
+     if ( rInf.GetFrm() && rInf.SnapToGrid() && rInf.GetFont() &&
+          SW_CJK == rInf.GetFont()->GetActual() )
+     {
+         GETGRID( rInf.GetFrm()->FindPageFrm() )
+-        if ( pGrid && GRID_LINES_CHARS == pGrid->GetGridType() )
++        if ( pGrid && GRID_LINES_CHARS == pGrid->GetGridType() && pGrid->IsSnapToChars())
+         {
+-            const USHORT nGridWidth = pGrid->GetBaseHeight();
++            //for textgrid refactor
++            //const USHORT nGridWidth = pGrid->GetBaseHeight();
++			const SwDoc* pDoc = rInf.GetShell()->GetDoc();	
++            const USHORT nGridWidth = GETGRIDWIDTH(pGrid, pDoc);
+             sal_Int32* pKernArray = new sal_Int32[rInf.GetLen()];
+ 
+             if ( pPrinter )
+@@ -1143,6 +1170,148 @@ void SwFntObj::DrawText( SwDrawTextInfo 
+         }
+     }
+ 
++    // For text grid refactor
++    // ASIAN LINE AND CHARACTER GRID MODE START: not snap to characters
++    //
++    if ( rInf.GetFrm() && rInf.SnapToGrid() && rInf.GetFont() )
++    {
++        GETGRID( rInf.GetFrm()->FindPageFrm() )
++        
++        if ( pGrid && GRID_LINES_CHARS == pGrid->GetGridType() && !pGrid->IsSnapToChars() )
++        {
++            const USHORT  nDefaultFontHeight = GetDefaultFontHeight( rInf );
++            
++			const SwDoc* pDoc = rInf.GetShell()->GetDoc();	
++            long nGridWidthAdd = GETGRIDWIDTH(pGrid, pDoc);
++            if( SW_LATIN == rInf.GetFont()->GetActual() )
++                nGridWidthAdd = ( nGridWidthAdd - nDefaultFontHeight ) / 2;
++            else
++                nGridWidthAdd = nGridWidthAdd - nDefaultFontHeight;
++
++            sal_Int32*  pKernArray = new sal_Int32[rInf.GetLen()];
++
++            if ( pPrinter )
++                pPrinter->GetTextArray( rInf.GetText(), pKernArray,
++                rInf.GetIdx(), rInf.GetLen() );
++            else
++                rInf.GetOut().GetTextArray( rInf.GetText(), pKernArray,
++                rInf.GetIdx(), rInf.GetLen() );
++            if ( bSwitchH2V )
++                rInf.GetFrm()->SwitchHorizontalToVertical( aPos );
++            if ( rInf.GetSpace() || rInf.GetKanaComp())
++            {
++                long nSpaceAdd = rInf.GetSpace() / SPACING_PRECISION_FACTOR;
++                sal_Bool bSpecialJust = sal_False;
++                if ( rInf.GetFont() && rInf.GetLen() )
++                {
++                    const SwScriptInfo* pSI = rInf.GetScriptInfo();
++                    const BYTE nActual = rInf.GetFont()->GetActual();
++                    ///Kana Compression
++                    if( SW_CJK == nActual && rInf.GetKanaComp() &&
++                        pSI && pSI->CountCompChg() &&
++                        lcl_IsMonoSpaceFont( *(rInf.GetpOut()) ) )
++                    {
++                        pSI->Compress( pKernArray,rInf.GetIdx(), rInf.GetLen(),
++                            rInf.GetKanaComp(), (USHORT)aFont.GetSize().Height(),&aPos );
++                        bSpecialJust = sal_True;
++                    }
++                    ///Asian Justification
++                    if ( ( SW_CJK == nActual || SW_LATIN == nActual ) && nSpaceAdd )
++                    {
++                        LanguageType aLang = rInf.GetFont()->GetLanguage( SW_CJK );
++                        if ( LANGUAGE_KOREAN != aLang && LANGUAGE_KOREAN_JOHAB != aLang)
++                        {
++                            long nSpaceSum = nSpaceAdd;
++                            for ( USHORT nI = 0; nI < rInf.GetLen(); ++nI )
++                            {
++                                pKernArray[ nI ] += nSpaceSum;
++                                nSpaceSum += nSpaceAdd;
++                            }
++                            bSpecialJust = sal_True;
++                            nSpaceAdd = 0;
++                        }
++                    }
++                    long nGridAddSum = nGridWidthAdd;
++                    for(xub_StrLen i = 0; i < rInf.GetLen(); i++,nGridAddSum += nGridWidthAdd )
++                    {
++                        pKernArray[i] += nGridAddSum;
++                    }
++                    long nKernSum = rInf.GetKern();
++                    if ( bSpecialJust || rInf.GetKern() )
++                    {
++                        for( xub_StrLen i = 0; i < rInf.GetLen(); i++, nKernSum += rInf.GetKern() )
++                        {
++                            if ( CH_BLANK == rInf.GetText().GetChar(rInf.GetIdx()+i) )
++                                nKernSum += nSpaceAdd;
++                            pKernArray[i] += nKernSum;
++                        }
++                        ///With through/uderstr. Grouped style requires a blank at the end
++                        ///of a text edition special measures:
++                        if( bPaintBlank && rInf.GetLen() && (CH_BLANK ==
++                            rInf.GetText().GetChar( rInf.GetIdx() + rInf.GetLen() - 1) ) )
++                        {
++                            ///If it concerns a singular, underlined space acts,
++                            ///we must spend two:
++                            if( 1 == rInf.GetLen() )
++                            {
++                                pKernArray[0] = rInf.GetWidth() + nSpaceAdd;
++                                rInf.GetOut().DrawTextArray( aPos, rInf.GetText(),
++                                    pKernArray, rInf.GetIdx(), 1 );
++                            }
++                            else
++                            {
++                                pKernArray[ rInf.GetLen() - 2] += nSpaceAdd;
++                                rInf.GetOut().DrawTextArray( aPos, rInf.GetText(),
++                                    pKernArray, rInf.GetIdx(), rInf.GetLen() );
++                            }
++                        }
++                        else
++                        {
++                            rInf.GetOut().DrawTextArray( aPos, rInf.GetText(),
++                                pKernArray, rInf.GetIdx(), rInf.GetLen() );
++                        }
++                    }
++                    else
++                    {
++                        Point aTmpPos( aPos );
++                        xub_StrLen i;
++                        xub_StrLen j = 0;
++                        long nSpaceSum = 0;
++                        for( i = 0; i < rInf.GetLen(); i++ )
++                        {
++                            if( CH_BLANK == rInf.GetText().GetChar( rInf.GetIdx() + i) )
++                            {
++                                nSpaceSum += nSpaceAdd;
++                                if( j < i)
++                                    rInf.GetOut().DrawText( aTmpPos, rInf.GetText(),
++                                    rInf.GetIdx() + j, i - j );
++                                j = i + 1;
++                                pKernArray[i] = pKernArray[i] + nSpaceSum;
++                                aTmpPos.X() = aPos.X() + pKernArray[ i ] + nKernSum;
++                            }
++                        }
++                        if( j < i )
++                            rInf.GetOut().DrawText( aTmpPos, rInf.GetText(),
++                            rInf.GetIdx() +j , i - j );
++                    }
++                }
++            }
++            else
++            {
++                //long nKernAdd = rInf.GetKern();
++		long nKernAdd = 0;
++                long nGridAddSum = nGridWidthAdd + nKernAdd;
++                for(xub_StrLen i = 0; i < rInf.GetLen(); i++,nGridAddSum += nGridWidthAdd + nKernAdd )
++                {
++                    pKernArray[i] += nGridAddSum;
++                }
++                rInf.GetOut().DrawTextArray( aPos, rInf.GetText(),
++                    pKernArray, rInf.GetIdx(), rInf.GetLen() );
++            }
++            delete[] pKernArray;
++            return;
++        }
++    }
+ 
+     //
+     // DIRECT PAINTING WITHOUT SCREEN ADJUSTMENT
+@@ -1905,9 +2074,10 @@ Size SwFntObj::GetTextSize( SwDrawTextIn
+          SW_CJK == rInf.GetFont()->GetActual() )
+     {
+         GETGRID( rInf.GetFrm()->FindPageFrm() )
+-        if ( pGrid && GRID_LINES_CHARS == pGrid->GetGridType() )
++        if ( pGrid && GRID_LINES_CHARS == pGrid->GetGridType() && pGrid->IsSnapToChars() )
+         {
+-            const USHORT nGridWidth = pGrid->GetBaseHeight();
++			const SwDoc* pDoc = rInf.GetShell()->GetDoc();	
++            const USHORT nGridWidth = GETGRIDWIDTH(pGrid, pDoc);
+ 
+             OutputDevice* pOutDev;
+ 
+@@ -1936,6 +2106,40 @@ Size SwFntObj::GetTextSize( SwDrawTextIn
+                             1;
+ 
+             aTxtSize.Width() = i * nGridWidth * nLn;
++            rInf.SetKanaDiff( 0 );
++            return aTxtSize;
++        }
++    }
++    
++    //for textgrid refactor
++    if ( rInf.GetFrm() && nLn && rInf.SnapToGrid() && rInf.GetFont())
++    {
++        GETGRID( rInf.GetFrm()->FindPageFrm() )
++        if ( pGrid && GRID_LINES_CHARS == pGrid->GetGridType() && !pGrid->IsSnapToChars() )
++        {
++            const USHORT nDefaultFontHeight = GetDefaultFontHeight( rInf );
++
++			const SwDoc* pDoc = rInf.GetShell()->GetDoc();	
++            long nGridWidthAdd = GETGRIDWIDTH(pGrid, pDoc);
++            if( SW_LATIN == rInf.GetFont()->GetActual() )
++                nGridWidthAdd = ( nGridWidthAdd - nDefaultFontHeight ) / 2;
++            else
++                nGridWidthAdd = nGridWidthAdd - nDefaultFontHeight;
++            OutputDevice* pOutDev;
++            if ( pPrinter )
++            {
++                if( !pPrtFont->IsSameInstance( pPrinter->GetFont() ) )
++                    pPrinter->SetFont(*pPrtFont);
++                pOutDev = pPrinter;
++            }
++            else
++                pOutDev = rInf.GetpOut();
++            aTxtSize.Width() = pOutDev->GetTextWidth( rInf.GetText(), rInf.GetIdx(), nLn );
++            aTxtSize.Height() = pOutDev->GetTextHeight() +
++                                GetFontLeading( rInf.GetShell(), rInf.GetOut() );
++            aTxtSize.Width() += (nLn) * long( nGridWidthAdd ); 
++            //if ( rInf.GetKern() && nLn )
++            //    aTxtSize.Width() += ( nLn ) * long( rInf.GetKern() );
+ 
+             rInf.SetKanaDiff( 0 );
+             return aTxtSize;
+@@ -2158,9 +2362,10 @@ xub_StrLen SwFntObj::GetCrsrOfst( SwDraw
+          rInf.GetFont() && SW_CJK == rInf.GetFont()->GetActual() )
+     {
+         GETGRID( rInf.GetFrm()->FindPageFrm() )
+-        if ( pGrid && GRID_LINES_CHARS == pGrid->GetGridType() )
++        if ( pGrid && GRID_LINES_CHARS == pGrid->GetGridType() && pGrid->IsSnapToChars() )
+         {
+-            const USHORT nGridWidth = pGrid->GetBaseHeight();
++			const SwDoc* pDoc = rInf.GetShell()->GetDoc();	
++            const USHORT nGridWidth = GETGRIDWIDTH(pGrid, pDoc);
+ 
+             long nWidthPerChar = pKernArray[ rInf.GetLen() - 1 ] / rInf.GetLen();
+ 
+@@ -2179,6 +2384,37 @@ xub_StrLen SwFntObj::GetCrsrOfst( SwDraw
+         }
+     }
+ 
++    //for textgrid refactor
++    if ( rInf.GetFrm() && rInf.GetLen() && rInf.SnapToGrid() &&
++        rInf.GetFont() )
++    {
++        GETGRID( rInf.GetFrm()->FindPageFrm() )
++        if ( pGrid && GRID_LINES_CHARS == pGrid->GetGridType() && !pGrid->IsSnapToChars() )
++        {
++
++            const USHORT nDefaultFontHeight = GetDefaultFontHeight( rInf );
++
++			const SwDoc* pDoc = rInf.GetShell()->GetDoc();	
++            long nGridWidthAdd = GETGRIDWIDTH(pGrid, pDoc);
++            if( SW_LATIN == rInf.GetFont()->GetActual() )   
++                nGridWidthAdd = ( nGridWidthAdd - nDefaultFontHeight ) / 2;
++            else
++                nGridWidthAdd = nGridWidthAdd - nDefaultFontHeight;
++            
++            for(xub_StrLen j = 0; j < rInf.GetLen(); j++)
++            {
++                long nScr = pKernArray[ j ] + ( nSpaceAdd + nGridWidthAdd  ) * ( j + 1 );
++                if( nScr >= rInf.GetOfst())
++                {
++                    nCnt = j;
++                    break;
++                }
++            }
++            delete[] pKernArray;
++            return nCnt;
++        }
++    }
++
+     sal_uInt16 nItrMode = i18n::CharacterIteratorMode::SKIPCELL;
+     sal_Int32 nDone = 0;
+     LanguageType aLang = LANGUAGE_NONE;
+@@ -2385,9 +2621,10 @@ xub_StrLen SwFont::GetTxtBreak( SwDrawTe
+          rInf.GetFont() && SW_CJK == rInf.GetFont()->GetActual() )
+     {
+         GETGRID( rInf.GetFrm()->FindPageFrm() )
+-        if ( pGrid && GRID_LINES_CHARS == pGrid->GetGridType() )
++        if ( pGrid && GRID_LINES_CHARS == pGrid->GetGridType() && pGrid->IsSnapToChars() )
+         {
+-            const USHORT nGridWidth = pGrid->GetBaseHeight();
++			const SwDoc* pDoc = rInf.GetShell()->GetDoc();	
++            const USHORT nGridWidth = GETGRIDWIDTH(pGrid, pDoc);
+ 
+             sal_Int32* pKernArray = new sal_Int32[rInf.GetLen()];
+             rInf.GetOut().GetTextArray( rInf.GetText(), pKernArray,
+@@ -2413,6 +2650,35 @@ xub_StrLen SwFont::GetTxtBreak( SwDrawTe
+         }
+     }
+ 
++    //for text grid enhancement
++    if ( rInf.GetFrm() && nLn && rInf.SnapToGrid() && rInf.GetFont() )
++    {
++        GETGRID( rInf.GetFrm()->FindPageFrm() )
++        if ( pGrid && GRID_LINES_CHARS == pGrid->GetGridType() && !pGrid->IsSnapToChars() )
++        {
++            const USHORT nDefaultFontHeight = GetDefaultFontHeight( rInf );
++
++			const SwDoc* pDoc = rInf.GetShell()->GetDoc();	
++            long nGridWidthAdd = GETGRIDWIDTH(pGrid, pDoc);
++            if( SW_LATIN == rInf.GetFont()->GetActual() )
++                nGridWidthAdd = ( nGridWidthAdd - nDefaultFontHeight ) / 2 ;
++            else
++                nGridWidthAdd = nGridWidthAdd - nDefaultFontHeight;
++
++            sal_Int32* pKernArray = new sal_Int32[rInf.GetLen()];
++            rInf.GetOut().GetTextArray( rInf.GetText(), pKernArray,
++                                            rInf.GetIdx(), rInf.GetLen() );
++            long nCurrPos = pKernArray[nTxtBreak] + nGridWidthAdd;
++            while( nTxtBreak < rInf.GetLen() && nTextWidth >= nCurrPos)
++            {
++                nTxtBreak++;
++                nCurrPos = pKernArray[nTxtBreak] + nGridWidthAdd * ( nTxtBreak + 1 );
++            }
++            delete[] pKernArray;
++            return nTxtBreak + rInf.GetIdx();
++        }
++    }
++
+     if( aSub[nActual].IsCapital() && nLn )
+ 		nTxtBreak = GetCapitalBreak( rInf.GetShell(), rInf.GetpOut(),
+ 		rInf.GetScriptInfo(), rInf.GetText(), nTextWidth,0, rInf.GetIdx(),nLn );
+diff -uNpr sw.bak/source/core/unocore/unomap.cxx sw/source/core/unocore/unomap.cxx
+--- sw.bak/source/core/unocore/unomap.cxx	2008-02-19 15:12:42.000000000 +0800
++++ sw/source/core/unocore/unomap.cxx	2008-02-19 15:12:51.000000000 +0800
+@@ -986,7 +986,9 @@ const SfxItemPropertyMap* SwUnoPropertyM
+                     { SW_PROP_NMID(UNO_NAME_GRID_RUBY_BELOW), RES_TEXTGRID, CPPU_E2T(CPPUTYPE_BOOLEAN), PROPERTY_NONE, MID_GRID_RUBY_BELOW},
+                     { SW_PROP_NMID(UNO_NAME_GRID_PRINT), RES_TEXTGRID, CPPU_E2T(CPPUTYPE_BOOLEAN), PROPERTY_NONE, MID_GRID_PRINT},
+                     { SW_PROP_NMID(UNO_NAME_GRID_DISPLAY), RES_TEXTGRID, CPPU_E2T(CPPUTYPE_BOOLEAN), PROPERTY_NONE, MID_GRID_DISPLAY},
+-
++                    { SW_PROP_NMID(UNO_NAME_GRID_BASE_WIDTH), RES_TEXTGRID, CPPU_E2T(CPPUTYPE_INT32), PROPERTY_NONE, MID_GRID_BASEWIDTH|CONVERT_TWIPS},
++                    { SW_PROP_NMID(UNO_NAME_GRID_SNAP_TO_CHARS), RES_TEXTGRID, CPPU_E2T(CPPUTYPE_BOOLEAN), PROPERTY_NONE, MID_GRID_SNAPTOCHARS},
++                    { SW_PROP_NMID(UNO_NAME_GRID_STANDARD_PAGE_MODE), RES_TEXTGRID, CPPU_E2T(CPPUTYPE_BOOLEAN), PROPERTY_NONE, MID_GRID_STANDARD_MODE},
+                     {0,0,0,0,0,0}
+ 				};
+ 				aMapArr[nPropertyId] = aPageStyleMap;
+@@ -1808,6 +1810,10 @@ const SfxItemPropertyMap* SwUnoPropertyM
+                     // --> collapsing borders DVO, FME 2005-05-27 #i29550#
+                     { SW_PROP_NMID(UNO_NAME_COLLAPSING_BORDERS), RES_COLLAPSING_BORDERS, CPPU_E2T(CPPUTYPE_BOOLEAN), PROPERTY_NONE, 0},
+                     // <-- collapsing
++
++			//text grid enhancement for better CJK support.  2007-04-01
++			//just export the default page mode property, other properties are not handled in this version
++                    { SW_PROP_NMID(UNO_NAME_GRID_STANDARD_PAGE_MODE), RES_TEXTGRID, CPPU_E2T(CPPUTYPE_BOOLEAN), PROPERTY_NONE, MID_GRID_STANDARD_MODE},
+                     {0,0,0,0,0,0}
+ 				};
+ 				aMapArr[nPropertyId] = aTextDefaultMap_Impl;
+diff -uNpr sw.bak/source/core/unocore/unoprnms.cxx sw/source/core/unocore/unoprnms.cxx
+--- sw.bak/source/core/unocore/unoprnms.cxx	2008-02-19 15:12:42.000000000 +0800
++++ sw/source/core/unocore/unoprnms.cxx	2008-02-19 15:12:51.000000000 +0800
+@@ -771,7 +771,10 @@ const SwPropNameTab aPropNameTab = {
+ /* 0713 UNO_NAME_TOOLTIP */ {MAP_CHAR_LEN("Tooltip")},
+ /* 0714 UNO_NAME_DIALOG_LIBRARIES*/     {MAP_CHAR_LEN("DialogLibraries")},
+ /* 0715 UNO_NAME_HEADER_ROW_COUNT*/     {MAP_CHAR_LEN("HeaderRowCount")},
+-/* 0716 UNO_NAME_INPUT */                {MAP_CHAR_LEN("Input")}
++/* 0716 UNO_NAME_INPUT */                {MAP_CHAR_LEN("Input")},
++/* 0717 UNO_NAME_GRID_BASE_WIDTH*/ {MAP_CHAR_LEN("GridBaseWidth")},
++/* 0718 UNO_NAME_GRID_SNAP_TO_CHARS*/ {MAP_CHAR_LEN("GridSnapToChars")},
++/* 0719 UNO_NAME_GRID_STANDARD_PAGE_MODE*/ {MAP_CHAR_LEN("StandardPageMode")}
+ };
+ 
+ const SwPropNameLen& SwGetPropName( USHORT nId )
+diff -uNpr sw.bak/source/filter/ww8/wrtww8.hxx sw/source/filter/ww8/wrtww8.hxx
+--- sw.bak/source/filter/ww8/wrtww8.hxx	2008-02-19 15:12:42.000000000 +0800
++++ sw/source/filter/ww8/wrtww8.hxx	2008-02-19 15:12:51.000000000 +0800
+@@ -990,6 +990,7 @@ public:
+ 
+     void OutStyleTab();
+     USHORT Sty_GetWWSlot( const SwFmt& rFmt ) const;
++	SwFmt* GetSwFmt(){return (*pFmtA);}
+ };
+ 
+ class WW8SaveData
+diff -uNpr sw.bak/source/filter/ww8/ww8atr.cxx sw/source/filter/ww8/ww8atr.cxx
+--- sw.bak/source/filter/ww8/ww8atr.cxx	2008-02-19 15:12:42.000000000 +0800
++++ sw/source/filter/ww8/ww8atr.cxx	2008-02-19 15:12:51.000000000 +0800
+@@ -3778,7 +3778,16 @@ static Writer& OutWW8_SwTextGrid( Writer
+                 nGridType = 2;
+                 break;
+             case GRID_LINES_CHARS:
++				{
++					if(rItem.IsSnapToChars())
++					{
++						nGridType = 3;
++					}
++					else
++					{
+                 nGridType = 1;
++					}
++				}
+                 break;
+         }
+         rWrtWW8.InsUInt16(0x5032);
+@@ -3787,6 +3796,27 @@ static Writer& OutWW8_SwTextGrid( Writer
+         UINT16 nHeight = rItem.GetBaseHeight() + rItem.GetRubyHeight();
+         rWrtWW8.InsUInt16(0x9031);
+         rWrtWW8.InsUInt16(nHeight);
++	   	sal_uInt32 nPageCharSize = ItemGet<SvxFontHeightItem>(*(rWrtWW8.pStyles->GetSwFmt()),
++                RES_CHRATR_CJK_FONTSIZE).GetHeight();
++
++		INT32 nCharWidth = rItem.GetBaseWidth() - nPageCharSize;	   
++	   	INT32 nFraction = 0;
++	   	nFraction = nCharWidth%20;
++	   	if( nCharWidth < 0 )
++			nFraction = 20 + nFraction;
++	  	nFraction = ((nFraction)*0xFFF)/20;
++	   	nFraction = (nFraction & 0x00000FFF);
++   
++	   	INT32 nMain = 0;
++	   	nMain = nCharWidth/20;
++	   	if( nCharWidth < 0 )
++			nMain -= 1;
++	   	nMain = nMain * 0x1000;
++	   	nMain = (nMain & 0xFFFFF000);
++   
++	   	UINT32 nCharSpace = nFraction + nMain;
++	   	rWrtWW8.InsUInt16(0x7030);
++	   	rWrtWW8.InsUInt32(nCharSpace);
+     }
+     return rWrt;
+ }
+diff -uNpr sw.bak/source/filter/ww8/ww8par6.cxx sw/source/filter/ww8/ww8par6.cxx
+--- sw.bak/source/filter/ww8/ww8par6.cxx	2008-02-19 15:12:42.000000000 +0800
++++ sw/source/filter/ww8/ww8par6.cxx	2008-02-19 15:12:51.000000000 +0800
+@@ -420,12 +420,12 @@ void SwWW8ImplReader::SetDocumentGrid(Sw
+         default:
+             ASSERT(!this, "Unknown grid type");
+         case 3:
+-            //Text snaps to char grid, this doesn't make a lot of sense to
+-            //me. This is closer than LINES_CHARS
+-            eType = GRID_LINES_ONLY;
++            eType = GRID_LINES_CHARS;
++			aGrid.SetSnapToChars(sal_True);
+             break;
+         case 1:
+             eType = GRID_LINES_CHARS;
++			aGrid.SetSnapToChars(sal_False);
+             break;
+         case 2:
+             eType = GRID_LINES_ONLY;
+@@ -438,6 +438,11 @@ void SwWW8ImplReader::SetDocumentGrid(Sw
+     if (eType != GRID_NONE)
+         rDoc.set(IDocumentSettingAccess::ADD_EXT_LEADING, true);
+ 
++	//force to set document as standard page mode
++	sal_Bool bSquaredMode = sal_False;
++	rDoc.SetDefaultPageMode( bSquaredMode );
++	aGrid.SetSquaredMode( bSquaredMode );
++
+     //sep.dyaLinePitch
+     sal_Int32 nLinePitch = rSection.maSep.dyaLinePitch;
+ 
+@@ -468,11 +473,15 @@ void SwWW8ImplReader::SetDocumentGrid(Sw
+         nCharWidth += nFraction;
+     }
+ 
++    aGrid.SetBaseWidth( writer_cast<sal_uInt16>(nCharWidth));
+     aGrid.SetLines(writer_cast<sal_uInt16>(nTextareaHeight/nLinePitch));
+-    aGrid.SetBaseHeight(writer_cast<sal_uInt16>(nCharWidth));
+-    sal_Int32 nRubyHeight = nLinePitch - nCharWidth;
+-    if (nRubyHeight < 0)
+-        nRubyHeight = 0;
++	aGrid.SetBaseHeight(writer_cast<sal_uInt16>(nLinePitch));
++
++	// ruby height is not supported in ww8
++    //sal_Int32 nRubyHeight = nLinePitch - nCharWidth;
++    //if (nRubyHeight < 0)
++    //    nRubyHeight = 0;
++	sal_Int32 nRubyHeight = 0;
+     aGrid.SetRubyHeight(writer_cast<sal_uInt16>(nRubyHeight));
+ 
+     rFmt.SetAttr(aGrid);
+diff -uNpr sw.bak/source/filter/xml/xmlfmte.cxx sw/source/filter/xml/xmlfmte.cxx
+--- sw.bak/source/filter/xml/xmlfmte.cxx	2008-02-19 15:12:42.000000000 +0800
++++ sw/source/filter/xml/xmlfmte.cxx	2008-02-19 15:12:51.000000000 +0800
+@@ -244,6 +244,9 @@ void SwXMLExport::_ExportStyles( sal_Boo
+ #if SUPD <628 && !defined(TEST_MIB)
+ 	GetTextParagraphExport()->SetProgress( 0 );
+ #endif
++
++	//page defaults
++	GetPageExport()->exportDefaultStyle();
+ }
+ 
+ void SwXMLExport::_ExportAutoStyles()
+diff -uNpr sw.bak/source/ui/app/docshini.cxx sw/source/ui/app/docshini.cxx
+--- sw.bak/source/ui/app/docshini.cxx	2008-02-19 15:12:39.000000000 +0800
++++ sw/source/ui/app/docshini.cxx	2008-02-19 15:12:51.000000000 +0800
+@@ -228,6 +228,8 @@
+ 
+ #include <unochart.hxx>
+ 
++// text grid
++#include <tgrditem.hxx>
+ 
+ using namespace ::com::sun::star::i18n;
+ using namespace ::com::sun::star::lang;
+@@ -918,6 +920,14 @@ void SwDocShell::SubInitNew()
+     aDfltSet.Put( SvxColorItem( Color( COL_AUTO ), RES_CHRATR_COLOR ) );
+ 
+ 	pDoc->SetDefault( aDfltSet );
++
++	//default page mode for text grid
++	if(!bWeb)
++	{
++		sal_Bool bSquaredPageMode = SW_MOD()->GetUsrPref(FALSE)->IsSquaredPageMode();
++		pDoc->SetDefaultPageMode( bSquaredPageMode );
++	}
++	
+ 	pDoc->ResetModified();
+ }
+ 
+diff -uNpr sw.bak/source/ui/app/swmodul1.cxx sw/source/ui/app/swmodul1.cxx
+--- sw.bak/source/ui/app/swmodul1.cxx	2008-02-19 15:12:39.000000000 +0800
++++ sw/source/ui/app/swmodul1.cxx	2008-02-19 15:12:51.000000000 +0800
+@@ -700,3 +700,10 @@ void SwModule::CheckSpellChanges( sal_Bo
+ //		pSpell->SetSpellAllAgain( sal_False );
+ 	}
+ }
++
++void SwModule::ApplyDefaultPageMode(sal_Bool bIsSquaredPageMode)
++{
++    if(!pUsrPref)
++        GetUsrPref(sal_False);
++    pUsrPref->SetDefaultPageMode(bIsSquaredPageMode);
++}
+diff -uNpr sw.bak/source/ui/config/optload.cxx sw/source/ui/config/optload.cxx
+--- sw.bak/source/ui/config/optload.cxx	2008-02-19 15:12:40.000000000 +0800
++++ sw/source/ui/config/optload.cxx	2008-02-19 15:12:51.000000000 +0800
+@@ -106,6 +106,11 @@
+ #include <SwStyleNameMapper.hxx>
+ #endif
+ 
++#include <doc.hxx>
++#ifndef _SVTOOLS_CJKOPTIONS_HXX
++#include <svtools/cjkoptions.hxx>
++#endif
++
+ using namespace ::com::sun::star;
+ 
+ /* -----------------22.10.98 15:12-------------------
+@@ -130,6 +135,7 @@ SwLoadOptPage::SwLoadOptPage( Window* pP
+     aMetricLB           ( this, SW_RES( LB_METRIC ) ),
+     aTabFT              ( this, SW_RES( FT_TAB ) ),
+     aTabMF              ( this, SW_RES( MF_TAB ) ),
++	aUseSquaredPageMode ( this, SW_RES( CB_USE_SQUARE_PAGE_MODE ) ),
+ 
+ 	pWrtShell	( NULL ),
+     bHTMLMode   ( FALSE ),
+@@ -169,6 +175,10 @@ SwLoadOptPage::SwLoadOptPage( Window* pP
+         aTabFT.Hide();
+ 		aTabMF.Hide();
+ 	}
++	
++	SvtCJKOptions aCJKOptions;
++	if(!aCJKOptions.IsAsianTypographyEnabled())
++		aUseSquaredPageMode.Hide();
+ }
+ 
+ /*-----------------18.01.97 12.43-------------------
+@@ -246,6 +256,19 @@ BOOL __EXPORT SwLoadOptPage::FillItemSet
+         bRet = TRUE;
+     }
+ 
++    sal_Bool bIsSquaredPageModeFlag = aUseSquaredPageMode.IsChecked();
++    if ( bIsSquaredPageModeFlag != aUseSquaredPageMode.GetSavedValue() )
++    {
++        pMod->ApplyDefaultPageMode( bIsSquaredPageModeFlag );
++        if ( pWrtShell )
++        {
++            SwDoc* pDoc = pWrtShell->GetDoc();
++            pDoc->SetDefaultPageMode( bIsSquaredPageModeFlag );
++            pWrtShell->SetModified();
++        }
++        bRet = TRUE;
++    }
++
+     return bRet;
+ }
+ /*-----------------18.01.97 12.42-------------------
+@@ -311,6 +334,14 @@ void __EXPORT SwLoadOptPage::Reset( cons
+ 	{
+ 		bHTMLMode = 0 != (((const SfxUInt16Item*)pItem)->GetValue() & HTMLMODE_ON);
+ 	}
++    
++	//default page mode loading
++	if(pWrtShell)
++	{
++    	sal_Bool bSquaredPageMode = pWrtShell->GetDoc()->IsSquaredPageMode();
++		aUseSquaredPageMode.Check( bSquaredPageMode );
++   	 	aUseSquaredPageMode.SaveValue();
++	}
+ }
+ /*-----------------13.01.97 14.44-------------------
+ 	Metric des Deftabstops umschalten
+diff -uNpr sw.bak/source/ui/config/optload.hrc sw/source/ui/config/optload.hrc
+--- sw.bak/source/ui/config/optload.hrc	2008-02-19 15:12:40.000000000 +0800
++++ sw/source/ui/config/optload.hrc	2008-02-19 15:12:51.000000000 +0800
+@@ -48,6 +48,7 @@
+ #define FT_METRIC				20
+ #define FT_TAB					21
+ #define MF_TAB					22
++#define CB_USE_SQUARE_PAGE_MODE 23
+ 
+ // SwCaptionOptPage -----------------------------
+ 
+diff -uNpr sw.bak/source/ui/config/optload.src sw/source/ui/config/optload.src
+--- sw.bak/source/ui/config/optload.src	2008-02-19 15:12:40.000000000 +0800
++++ sw/source/ui/config/optload.src	2008-02-19 15:12:51.000000000 +0800
+@@ -140,6 +140,13 @@ TabPage TP_OPTLOAD_PAGE
+ 		First = 50 ;
+ 		Last = 9999 ;
+ 	};
++    CheckBox CB_USE_SQUARE_PAGE_MODE
++    {
++        Pos = MAP_APPFONT ( 12 , 111) ;
++        Size = MAP_APPFONT ( 248 , 10 ) ;
++        Text [ en-US ] = "Use square page mode for text grid";
++        Text [ zh-CN ] = "äçççæå";
++    };
+ };
+ /**************************************************************************/
+ /*                                                                        */
+diff -uNpr sw.bak/source/ui/config/usrpref.cxx sw/source/ui/config/usrpref.cxx
+--- sw.bak/source/ui/config/usrpref.cxx	2008-02-19 15:12:40.000000000 +0800
++++ sw/source/ui/config/usrpref.cxx	2008-02-19 15:12:51.000000000 +0800
+@@ -84,6 +84,7 @@ SwMasterUsrPref::SwMasterUsrPref(BOOL bW
+     bIsHScrollMetricSet(sal_False),
+     bIsVScrollMetricSet(sal_False),
+     nDefTab( MM50 * 4 ),
++    bIsSquaredPageMode(sal_False),
+     aContentConfig(bWeb, *this),
+     aLayoutConfig(bWeb, *this),
+     aGridConfig(bWeb, *this),
+@@ -281,9 +282,10 @@ Sequence<OUString> SwLayoutViewConfig::G
+         "Zoom/Type",                        //12
+         "Other/MeasureUnit",                //13
+         "Other/TabStop",                    //14
+-        "Window/IsVerticalRulerRight"       //15
++        "Window/IsVerticalRulerRight",      //15
++        "Other/IsSquaredPageMode"        //16
+     };
+-    const int nCount = bWeb ? 14 : 16;
++    const int nCount = bWeb ? 14 : 17;
+     Sequence<OUString> aNames(nCount);
+ 	OUString* pNames = aNames.getArray();
+ 	for(int i = 0; i < nCount; i++)
+@@ -347,8 +349,9 @@ void SwLayoutViewConfig::Commit()
+             case 13: pValues[nProp] <<= (sal_Int32)rParent.GetMetric(); break;// "Other/MeasureUnit",
+             case 14: pValues[nProp] <<= static_cast<sal_Int32>(TWIP_TO_MM100(rParent.GetDefTab())); break;// "Other/TabStop",
+             case 15: bSet = rParent.IsVRulerRight(); break;// "Window/IsVerticalRulerRight",
++            case 16: bSet = rParent.IsSquaredPageMode(); break;// "Other/IsSquaredPageMode",
+         }
+-        if(nProp < 8 || nProp == 10)
++        if(nProp < 8 || nProp == 10 || nProp == 16)
+ 			pValues[nProp].setValue(&bSet, ::getBooleanCppuType());
+ 	}
+ 	PutProperties(aNames, aValues);
+@@ -368,7 +371,7 @@ void SwLayoutViewConfig::Load()
+ 		{
+ 			if(pValues[nProp].hasValue())
+ 			{
+-                sal_Bool bSet = nProp < 8 || nProp == 10 ? *(sal_Bool*)pValues[nProp].getValue() : sal_False;
++                sal_Bool bSet = nProp < 8 || nProp == 10 || nProp == 16? *(sal_Bool*)pValues[nProp].getValue() : sal_False;
+                 switch(nProp)
+ 				{
+                     case  0: rParent.SetCrossHair(bSet); break;// "Line/Guide",
+@@ -425,6 +428,7 @@ void SwLayoutViewConfig::Load()
+ 					}
+ 					break;// "Other/TabStop",
+                     case 15: rParent.SetVRulerRight(bSet); break;// "Window/IsVerticalRulerRight",
++                    case 16: rParent.SetDefaultPageMode(bSet); break;// "Other/IsSquaredPageMode",
+                 }
+ 			}
+ 		}
+diff -uNpr sw.bak/source/ui/inc/optload.hxx sw/source/ui/inc/optload.hxx
+--- sw.bak/source/ui/inc/optload.hxx	2008-02-19 15:12:40.000000000 +0800
++++ sw/source/ui/inc/optload.hxx	2008-02-19 15:12:51.000000000 +0800
+@@ -93,6 +93,7 @@ private:
+     ListBox     aMetricLB;
+     FixedText   aTabFT;
+ 	MetricField aTabMF;
++    CheckBox    aUseSquaredPageMode;
+ 
+ 	SwWrtShell*	pWrtShell;
+     sal_Bool    bHTMLMode;
+diff -uNpr sw.bak/source/ui/inc/pggrid.hxx sw/source/ui/inc/pggrid.hxx
+--- sw.bak/source/ui/inc/pggrid.hxx	2008-02-19 15:12:40.000000000 +0800
++++ sw/source/ui/inc/pggrid.hxx	2008-02-19 15:12:51.000000000 +0800
+@@ -60,6 +60,7 @@ class SwTextGridPage: public SfxTabPage
+     RadioButton     aNoGridRB;
+     RadioButton     aLinesGridRB;
+     RadioButton     aCharsGridRB;
++    CheckBox        aSnapToCharsCB;
+ 
+     SwPageGridExample   aExampleWN;
+ 
+@@ -74,6 +75,9 @@ class SwTextGridPage: public SfxTabPage
+     FixedText       aCharsPerLineFT;
+     NumericField    aCharsPerLineNF;
+ 
++    FixedText       aCharWidthFT;
++    MetricField     aCharWidthMF;    
++    
+     FixedText       aRubySizeFT;
+     MetricField     aRubySizeMF;
+ 
+@@ -86,12 +90,13 @@ class SwTextGridPage: public SfxTabPage
+     FixedText       aColorFT;
+     ColorListBox    aColorLB;
+ 
+-    Window*         aControls[16];
++    Window*         aControls[18];
+ 
+     sal_Int32       m_nRubyUserValue;
+     sal_Bool        m_bRubyUserValue;
+     Size            m_aPageSize;
+     sal_Bool        m_bVertical;
++	sal_Bool		m_bSquaredMode;
+ 
+     SwTextGridPage(Window *pParent, const SfxItemSet &rSet);
+     ~SwTextGridPage();
+@@ -100,7 +105,8 @@ class SwTextGridPage: public SfxTabPage
+     void PutGridItem(SfxItemSet& rSet);
+ 
+     DECL_LINK(GridTypeHdl, RadioButton*);
+-    DECL_LINK(CharSizeChangedHdl, SpinField*);
++    DECL_LINK(CharorLineChangedHdl, SpinField*);
++    DECL_LINK(TextSizeChangedHdl, SpinField*);
+     DECL_LINK(GridModifyHdl, void*);
+     DECL_LINK(DisplayGridHdl, CheckBox*);
+ 
+diff -uNpr sw.bak/source/ui/inc/usrpref.hxx sw/source/ui/inc/usrpref.hxx
+--- sw.bak/source/ui/inc/usrpref.hxx	2008-02-19 15:12:40.000000000 +0800
++++ sw/source/ui/inc/usrpref.hxx	2008-02-19 15:12:51.000000000 +0800
+@@ -157,6 +157,7 @@ class SwMasterUsrPref : public SwViewOpt
+ 
+ 	sal_Int32	nDefTab;			//default tab stop distance
+ 
++    sal_Bool    bIsSquaredPageMode; //default page mode for text grid
+     SwContentViewConfig aContentConfig;
+     SwLayoutViewConfig  aLayoutConfig;
+     SwGridConfig        aGridConfig;
+@@ -272,6 +273,15 @@ public:
+                         aLayoutConfig.SetModified();
+                 }
+ 
++    //default page mode for text grid
++    sal_Bool    IsSquaredPageMode() const {return bIsSquaredPageMode;}
++    void        SetDefaultPageMode( sal_Bool bVal, sal_Bool bNoModify = sal_False ) 
++                { 
++                    bIsSquaredPageMode = bVal;
++                    if(!bNoModify)
++                        aLayoutConfig.SetModified(); 
++                }
++
+ };
+ 
+ #endif
+diff -uNpr sw.bak/source/ui/misc/pggrid.cxx sw/source/ui/misc/pggrid.cxx
+--- sw.bak/source/ui/misc/pggrid.cxx	2008-02-19 15:12:40.000000000 +0800
++++ sw/source/ui/misc/pggrid.cxx	2008-02-19 15:12:51.000000000 +0800
+@@ -69,6 +69,9 @@
+ #ifndef _SVX_LRSPITEM_HXX
+ #include <svx/lrspitem.hxx>
+ #endif
++#ifndef _SVX_ULSPITEM_HXX
++#include <svx/ulspitem.hxx>
++#endif
+ #ifndef _SVX_BOXITEM_HXX
+ #include <svx/boxitem.hxx>
+ #endif
+@@ -83,6 +86,11 @@
+ #endif
+ #include <pggrid.hrc>
+ 
++#include "wrtsh.hxx"
++#include "doc.hxx"
++#include "uiitems.hxx"
++#include "swmodule.hxx"
++#include "view.hxx"
+ /*-- 06.02.2002 15:25:39---------------------------------------------------
+ 
+   -----------------------------------------------------------------------*/
+@@ -92,6 +100,7 @@ SwTextGridPage::SwTextGridPage(Window *p
+     aNoGridRB               (this, SW_RES(RB_NOGRID          )),
+     aLinesGridRB            (this, SW_RES(RB_LINESGRID       )),
+     aCharsGridRB            (this, SW_RES(RB_CHARSGRID       )),
++	aSnapToCharsCB          (this, SW_RES(CB_SNAPTOCHARS      )),
+     aExampleWN              (this, SW_RES(WN_EXAMPLE         )),
+     aLayoutFL               (this, SW_RES(FL_LAYOUT          )),
+     aLinesPerPageFT         (this, SW_RES(FT_LINESPERPAGE    )),
+@@ -100,6 +109,8 @@ SwTextGridPage::SwTextGridPage(Window *p
+     aTextSizeMF             (this, SW_RES(MF_TEXTSIZE        )),
+     aCharsPerLineFT         (this, SW_RES(FT_CHARSPERLINE    )),
+     aCharsPerLineNF         (this, SW_RES(NF_CHARSPERLINE    )),
++	aCharWidthFT            (this, SW_RES(FT_CHARWIDTH        )),
++	aCharWidthMF            (this, SW_RES(MF_CHARWIDTH        )),
+     aRubySizeFT             (this, SW_RES(FT_RUBYSIZE        )),
+     aRubySizeMF             (this, SW_RES(MF_RUBYSIZE        )),
+     aRubyBelowCB            (this, SW_RES(CB_RUBYBELOW       )),
+@@ -111,7 +122,8 @@ SwTextGridPage::SwTextGridPage(Window *p
+     m_nRubyUserValue(0),
+     m_bRubyUserValue(sal_False),
+     m_aPageSize(MM50, MM50),
+-    m_bVertical(sal_False)
++    m_bVertical(sal_False),
++	m_bSquaredMode(sal_False)
+ {
+     FreeResource();
+ 
+@@ -122,23 +134,36 @@ SwTextGridPage::SwTextGridPage(Window *p
+     aControls[4] =&aTextSizeMF;
+     aControls[5] =&aCharsPerLineFT;
+     aControls[6] =&aCharsPerLineNF;
+-    aControls[7] =&aRubySizeFT;
+-    aControls[8] =&aRubySizeMF;
+-    aControls[9] =&aRubyBelowCB;
+-    aControls[10] =&aDisplayFL;
+-    aControls[11] =&aDisplayCB;
+-    aControls[12] =&aPrintCB;
+-    aControls[13] =&aColorFT;
+-    aControls[14] =&aColorLB;
+-    aControls[15] =0;
++    aControls[7] =&aCharWidthFT;
++    aControls[8] =&aCharWidthMF;
++    aControls[9] =&aRubySizeFT;
++    aControls[10] =&aRubySizeMF;    
++    aControls[11] =&aRubyBelowCB;
++    aControls[12] =&aDisplayFL;
++    aControls[13] =&aDisplayCB;
++    aControls[14] =&aPrintCB;
++    aControls[15] =&aColorFT;
++    aControls[16] =&aColorLB;
++    aControls[17] =0;
+ 
+-    Link aLink = LINK(this, SwTextGridPage, CharSizeChangedHdl);
++    Link aLink = LINK(this, SwTextGridPage, CharorLineChangedHdl);
+     aCharsPerLineNF.SetUpHdl(aLink);
+-    aTextSizeMF.SetUpHdl(aLink);
+     aCharsPerLineNF.SetDownHdl(aLink);
+-    aTextSizeMF.SetDownHdl(aLink);
+     aCharsPerLineNF.SetLoseFocusHdl(aLink);
+-    aTextSizeMF.SetLoseFocusHdl(aLink);
++    aLinesPerPageNF.SetUpHdl(aLink);
++    aLinesPerPageNF.SetDownHdl(aLink);
++    aLinesPerPageNF.SetLoseFocusHdl(aLink);
++    
++    Link aSizeLink = LINK(this, SwTextGridPage, TextSizeChangedHdl);
++    aTextSizeMF.SetUpHdl(aSizeLink);
++    aTextSizeMF.SetDownHdl(aSizeLink);
++    aTextSizeMF.SetLoseFocusHdl(aSizeLink);
++    aRubySizeMF.SetUpHdl(aSizeLink);
++    aRubySizeMF.SetDownHdl(aSizeLink);
++    aRubySizeMF.SetLoseFocusHdl(aSizeLink); 
++    aCharWidthMF.SetUpHdl(aSizeLink);
++    aCharWidthMF.SetDownHdl(aSizeLink);
++    aCharWidthMF.SetLoseFocusHdl(aSizeLink);
+ 
+     Link aGridTypeHdl = LINK(this, SwTextGridPage, GridTypeHdl);
+     aNoGridRB   .SetClickHdl(aGridTypeHdl);
+@@ -150,12 +175,6 @@ SwTextGridPage::SwTextGridPage(Window *p
+     aPrintCB.SetClickHdl(aModifyLk);
+     aRubyBelowCB.SetClickHdl(aModifyLk);
+ 
+-    aLinesPerPageNF.SetUpHdl(aModifyLk);
+-    aRubySizeMF.SetUpHdl(aModifyLk);
+-    aLinesPerPageNF.SetDownHdl(aModifyLk);
+-    aRubySizeMF.SetDownHdl(aModifyLk);
+-    aLinesPerPageNF.SetLoseFocusHdl(aModifyLk);
+-    aRubySizeMF.SetLoseFocusHdl(aModifyLk);
+ 
+     aDisplayCB.SetClickHdl(LINK(this, SwTextGridPage, DisplayGridHdl));
+ 
+@@ -169,6 +188,34 @@ SwTextGridPage::SwTextGridPage(Window *p
+ 		aColorLB.InsertEntry( aColor, sName );
+ 	}
+ 	aColorLB.SetUpdateMode( TRUE );
++	//Get the default paper mode
++	SwView *pView   = ::GetActiveView();
++	if( pView )
++	{
++		SwWrtShell* pSh = pView->GetWrtShellPtr();
++		if( pSh )
++		{
++			m_bSquaredMode = pSh->GetDoc()->IsSquaredPageMode();
++		}
++	}
++	if( m_bSquaredMode )
++	{
++		aRubySizeFT.Show();
++		aRubySizeMF.Show();
++		aRubyBelowCB.Show();
++		aSnapToCharsCB.Hide();
++		aCharWidthFT.Hide();
++		aCharWidthMF.Hide();
++	}
++	else
++	{
++		aRubySizeFT.Hide();
++		aRubySizeMF.Hide();
++		aRubyBelowCB.Hide();
++		aSnapToCharsCB.Show();
++		aCharWidthFT.Show();
++		aCharWidthMF.Show();
++	}
+ }
+ /*-- 06.02.2002 15:25:40---------------------------------------------------
+ 
+@@ -196,7 +243,9 @@ BOOL    SwTextGridPage::FillItemSet(SfxI
+         aTextSizeMF.GetSavedValue().ToInt32() != aTextSizeMF.GetValue()||
+         aCharsPerLineNF.GetSavedValue().ToInt32()
+            != aCharsPerLineNF.GetValue()||
++        aSnapToCharsCB.GetSavedValue() != aSnapToCharsCB.IsChecked() ||
+         aRubySizeMF.GetSavedValue().ToInt32() != aRubySizeMF.GetValue()||
++        aCharWidthMF.GetSavedValue().ToInt32() != aCharWidthMF.GetValue()||
+         aRubyBelowCB.GetSavedValue() != aRubyBelowCB.IsChecked()||
+         aDisplayCB.GetSavedValue() != aDisplayCB.IsChecked()||
+         aPrintCB.GetSavedValue() != aPrintCB.IsChecked()||
+@@ -225,11 +274,13 @@ void    SwTextGridPage::Reset(const SfxI
+         }
+         pButton->Check();
+         GridTypeHdl(pButton);
++        aSnapToCharsCB.Check(rGridItem.IsSnapToChars());
+         aLinesPerPageNF.SetValue(rGridItem.GetLines());
+         m_nRubyUserValue = rGridItem.GetBaseHeight();
+         m_bRubyUserValue = sal_True;
+         aTextSizeMF.SetValue(aTextSizeMF.Normalize(m_nRubyUserValue), FUNIT_TWIP);
+         aRubySizeMF.SetValue(aRubySizeMF.Normalize(rGridItem.GetRubyHeight()), FUNIT_TWIP);
++        aCharWidthMF.SetValue(aCharWidthMF.Normalize(rGridItem.GetBaseWidth()), FUNIT_TWIP);
+         aRubyBelowCB.Check(rGridItem.IsRubyTextBelow());
+         aDisplayCB.Check(rGridItem.IsDisplayGrid());
+         aPrintCB.Check(rGridItem.IsPrintGrid());
+@@ -239,10 +290,12 @@ void    SwTextGridPage::Reset(const SfxI
+ 
+     aNoGridRB.SaveValue();
+     aLinesGridRB.SaveValue();
++    aSnapToCharsCB.SaveValue();
+     aLinesPerPageNF.SaveValue();
+     aTextSizeMF.SaveValue();
+     aCharsPerLineNF.SaveValue();
+     aRubySizeMF.SaveValue();
++    aCharWidthMF.SaveValue();
+     aRubyBelowCB.SaveValue();
+     aDisplayCB.SaveValue();
+     aPrintCB.SaveValue();
+@@ -275,12 +328,15 @@ void SwTextGridPage::PutGridItem(SfxItem
+         SwTextGridItem aGridItem;
+         aGridItem.SetGridType(aNoGridRB.IsChecked() ? GRID_NONE :
+             aLinesGridRB.IsChecked() ? GRID_LINES_ONLY : GRID_LINES_CHARS );
++        aGridItem.SetSnapToChars(aSnapToCharsCB.IsChecked());
+         aGridItem.SetLines( static_cast< sal_uInt16 >(aLinesPerPageNF.GetValue()) );
+         aGridItem.SetBaseHeight( static_cast< sal_uInt16 >(
+             m_bRubyUserValue ? m_nRubyUserValue :
+                 aTextSizeMF.Denormalize(aTextSizeMF.GetValue(FUNIT_TWIP))) );
+         aGridItem.SetRubyHeight( static_cast< sal_uInt16 >(aRubySizeMF.Denormalize(aRubySizeMF.GetValue(FUNIT_TWIP))) );
++        aGridItem.SetBaseWidth( static_cast< sal_uInt16 >(aCharWidthMF.Denormalize(aCharWidthMF.GetValue(FUNIT_TWIP))) );
+         aGridItem.SetRubyTextBelow(aRubyBelowCB.IsChecked());
++        aGridItem.SetSquaredMode(m_bSquaredMode);
+         aGridItem.SetDisplayGrid(aDisplayCB.IsChecked());
+         aGridItem.SetPrintGrid(aPrintCB.IsChecked());
+         aGridItem.SetColor(aColorLB.GetSelectEntryColor());
+@@ -305,13 +361,16 @@ void SwTextGridPage::UpdatePageSize(cons
+                                             SID_ATTR_PAGE_SIZE);
+         const SvxLRSpaceItem& rLRSpace = (const SvxLRSpaceItem&)rSet.Get(
+                                                             RES_LR_SPACE );
++        const SvxULSpaceItem& rULSpace = (const SvxULSpaceItem&)rSet.Get(
++                                                            RES_UL_SPACE );                                                    
+         const SvxBoxItem& rBox = (const SvxBoxItem&) rSet.Get(RES_BOX);
+-        sal_Int32 nDistance = rLRSpace.GetLeft() + rLRSpace.GetRight();
++        sal_Int32 nDistanceLR = rLRSpace.GetLeft() + rLRSpace.GetRight();
++        sal_Int32 nDistanceUL = rULSpace.GetUpper() + rULSpace.GetLower();
+ 
+-        sal_Int32 nValue1 = rSize.GetSize().Height() - nDistance -
++        sal_Int32 nValue1 = rSize.GetSize().Height() - nDistanceUL -
+                 rBox.GetDistance(BOX_LINE_TOP) -
+                                     rBox.GetDistance(BOX_LINE_BOTTOM);
+-        sal_Int32 nValue2 = rSize.GetSize().Width() - nDistance -
++        sal_Int32 nValue2 = rSize.GetSize().Width() - nDistanceLR -
+                 rBox.GetDistance(BOX_LINE_LEFT) -
+                                     rBox.GetDistance(BOX_LINE_RIGHT);
+         if(m_bVertical)
+@@ -328,8 +387,21 @@ void SwTextGridPage::UpdatePageSize(cons
+         sal_Int32 nTextSize = static_cast< sal_Int32 >(m_bRubyUserValue ?
+                     m_nRubyUserValue :
+                         aTextSizeMF.Denormalize(aTextSizeMF.GetValue(FUNIT_TWIP)) );
++        
++        if ( m_bSquaredMode )
++        {
+         aCharsPerLineNF.SetValue(m_aPageSize.Width() / nTextSize);
+     }
++        else
++        {
++            sal_Int32 nTextWidth = static_cast< sal_Int32 >(aCharWidthMF.Denormalize(aCharWidthMF.GetValue(FUNIT_TWIP)));
++            aLinesPerPageNF.SetValue(m_aPageSize.Height() / nTextSize);
++            if (nTextWidth)
++                aCharsPerLineNF.SetValue(m_aPageSize.Width() / nTextWidth); 
++            else
++                aCharsPerLineNF.SetValue( 45 );
++        }
++    }
+ }
+ /* -----------------------------06.02.2002 15:24------------------------------
+ 
+@@ -344,22 +416,87 @@ USHORT* SwTextGridPage::GetRanges()
+ /* -----------------------------08.02.2002 10:56------------------------------
+ 
+  ---------------------------------------------------------------------------*/
+-IMPL_LINK(SwTextGridPage, CharSizeChangedHdl, SpinField*, pField)
++IMPL_LINK(SwTextGridPage, CharorLineChangedHdl, SpinField*, pField)
++{
++    //if in squared mode
++    if ( m_bSquaredMode )
+ {
+     if(&aCharsPerLineNF == pField)
+     {
+-        long nWidth = m_aPageSize.Width() / static_cast< long >(aCharsPerLineNF.GetValue());
++            long nWidth = (long)(m_aPageSize.Width() / aCharsPerLineNF.GetValue());
+         aTextSizeMF.SetValue(aTextSizeMF.Normalize(nWidth), FUNIT_TWIP);
+         //prevent rounding errors in the MetricField by saving the used value
+         m_nRubyUserValue = nWidth;
+         m_bRubyUserValue = sal_True;
++            
+     }
+-    else
++		//set maximum line per page
++        {
++            sal_Int32 nMaxLines = static_cast< sal_Int32 >(m_aPageSize.Height() /
++                (   aTextSizeMF.Denormalize(aTextSizeMF.GetValue(FUNIT_TWIP)) +
++                    aRubySizeMF.Denormalize(aRubySizeMF.GetValue(FUNIT_TWIP))));
++            aLinesPerPageNF.SetMax(nMaxLines);
++        }
++	}
++    else//in normal mode
++    {
++        if(&aLinesPerPageNF == pField)
++        {
++            long nHeight = static_cast< sal_Int32 >(m_aPageSize.Height() / aLinesPerPageNF.GetValue());
++            aTextSizeMF.SetValue(aTextSizeMF.Normalize(nHeight), FUNIT_TWIP);
++            aRubySizeMF.SetValue(0, FUNIT_TWIP);
++            
++            m_nRubyUserValue = nHeight;
++            m_bRubyUserValue = sal_True;
++        }
++        else if (&aCharsPerLineNF == pField)
++        {
++            long nWidth = static_cast< sal_Int32 >(m_aPageSize.Width() / aCharsPerLineNF.GetValue());
++            aCharWidthMF.SetValue(aCharWidthMF.Normalize(nWidth), FUNIT_TWIP);
++        }
++    }
++    GridModifyHdl(0);
++    return 0;
++}
++/* -----------------------------04.09.2006 15:46------------------------------
++ ---------------------------------------------------------------------------*/
++IMPL_LINK(SwTextGridPage, TextSizeChangedHdl, SpinField*, pField)
++{
++    //if in squared mode
++    if( m_bSquaredMode )
++    {
++        if (&aTextSizeMF == pField)
+     {
+         sal_Int32 nTextSize = static_cast< sal_Int32 >(aTextSizeMF.Denormalize(aTextSizeMF.GetValue(FUNIT_TWIP)));
+         aCharsPerLineNF.SetValue(m_aPageSize.Width() / nTextSize);
+         m_bRubyUserValue = sal_False;
+     }
++		//set maximum line per page
++        {
++            sal_Int32 nMaxLines = static_cast< sal_Int32 >(m_aPageSize.Height() /
++                (   aTextSizeMF.Denormalize(aTextSizeMF.GetValue(FUNIT_TWIP)) +
++                    aRubySizeMF.Denormalize(aRubySizeMF.GetValue(FUNIT_TWIP))));
++            aLinesPerPageNF.SetMax(nMaxLines);
++        }
++    }
++    else
++    {
++        if (&aTextSizeMF == pField)
++        {
++            sal_Int32 nTextSize = static_cast< sal_Int32 >(aTextSizeMF.Denormalize(aTextSizeMF.GetValue(FUNIT_TWIP)));
++            aLinesPerPageNF.SetValue(m_aPageSize.Height() / nTextSize);
++            m_bRubyUserValue = sal_False;
++        }
++        else if (&aCharWidthMF == pField)
++        {
++            sal_Int32 nTextWidth = static_cast< sal_Int32 >(aCharWidthMF.Denormalize(aCharWidthMF.GetValue(FUNIT_TWIP)));
++            if (nTextWidth)
++                aCharsPerLineNF.SetValue(m_aPageSize.Width() / nTextWidth); 
++            else
++                aCharsPerLineNF.SetValue( 45 );
++        }
++        //rubySize is disabled
++    }
+     GridModifyHdl(0);
+     return 0;
+ }
+@@ -376,6 +513,18 @@ IMPL_LINK(SwTextGridPage, GridTypeHdl, R
+     if(bEnable)
+         DisplayGridHdl(&aDisplayCB);
+ 
++	bEnable = &aCharsGridRB == pButton;
++	aSnapToCharsCB.Enable(bEnable);
++	
++	bEnable = &aLinesGridRB == pButton;
++	if(bEnable && !m_bSquaredMode )
++	{
++		aCharsPerLineFT.Enable(sal_False);
++		aCharsPerLineNF.Enable(sal_False);
++		aCharWidthFT.Enable(sal_False);
++		aCharWidthMF.Enable(sal_False);
++	}
++	
+     GridModifyHdl(0);
+     return 0;
+ }
+@@ -392,11 +541,6 @@ IMPL_LINK(SwTextGridPage, DisplayGridHdl
+  ---------------------------------------------------------------------------*/
+ IMPL_LINK(SwTextGridPage, GridModifyHdl, void*, EMPTYARG)
+ {
+-    //set maximum for Lines per page
+-    sal_Int32 nMaxLines = static_cast< sal_Int32 >(m_aPageSize.Height() /
+-                (   aTextSizeMF.Denormalize(aTextSizeMF.GetValue(FUNIT_TWIP)) +
+-                    aRubySizeMF.Denormalize(aRubySizeMF.GetValue(FUNIT_TWIP))) );
+-    aLinesPerPageNF.SetMax(nMaxLines);
+     const SfxItemSet& rOldSet = GetItemSet();
+     SfxItemSet aSet(rOldSet);
+     const SfxItemSet* pExSet = GetTabDialog()->GetExampleSet();
+diff -uNpr sw.bak/source/ui/misc/pggrid.hrc sw/source/ui/misc/pggrid.hrc
+--- sw.bak/source/ui/misc/pggrid.hrc	2008-02-19 15:12:40.000000000 +0800
++++ sw/source/ui/misc/pggrid.hrc	2008-02-19 15:12:51.000000000 +0800
+@@ -55,3 +55,6 @@
+ #define CB_PRINT            20
+ #define FT_COLOR            21
+ #define LB_COLOR            22
++#define CB_SNAPTOCHARS      23
++#define FT_CHARWIDTH        24
++#define MF_CHARWIDTH        25
+diff -uNpr sw.bak/source/ui/misc/pggrid.src sw/source/ui/misc/pggrid.src
+--- sw.bak/source/ui/misc/pggrid.src	2008-02-19 15:12:40.000000000 +0800
++++ sw/source/ui/misc/pggrid.src	2008-02-19 15:12:51.000000000 +0800
+@@ -65,6 +65,13 @@ TabPage TP_TEXTGRID_PAGE
+         Size = MAP_APPFONT ( 158 , 10 ) ;
+         Text [ en-US ] = "Grid (lines and characters)" ;
+ 	};
++    CheckBox        CB_SNAPTOCHARS
++    {
++        Pos = MAP_APPFONT ( 14 , 53 ) ;
++        Size = MAP_APPFONT ( 158 , 10 ) ;
++        Text [ en-US ] = "~Snap to characters" ;
++        Text [ zh-CN ] = "æååéåççæ" ;
++    };
+     Window          WN_EXAMPLE
+     {
+         Pos = MAP_APPFONT ( 176 , 6 ) ;
+@@ -72,19 +79,19 @@ TabPage TP_TEXTGRID_PAGE
+     };
+     FixedLine       FL_LAYOUT
+     {
+-        Pos = MAP_APPFONT ( 6 , 56 ) ;
++        Pos = MAP_APPFONT ( 6 , 69 ) ;
+         Size = MAP_APPFONT ( 248 , 8 ) ;
+         Text [ en-US ] = "Grid layout" ;
+ 	};
+     FixedText       FT_LINESPERPAGE
+     {
+-        Pos = MAP_APPFONT ( 12 , 69 ) ;
++        Pos = MAP_APPFONT ( 12 , 82 ) ;
+         Size = MAP_APPFONT ( 59 , 8 ) ;
+         Text [ en-US ] = "Lines per page" ;
+ 	};
+     NumericField    NF_LINESPERPAGE
+     {
+-        Pos = MAP_APPFONT ( 74 , 67 ) ;
++        Pos = MAP_APPFONT ( 74 , 80 ) ;
+         Size = MAP_APPFONT ( 25 , 12 ) ;
+         Border = TRUE ;
+         TabStop = TRUE ;
+@@ -100,13 +107,13 @@ TabPage TP_TEXTGRID_PAGE
+     };
+     FixedText       FT_TEXTSIZE
+     {
+-        Pos = MAP_APPFONT ( 133 , 69 ) ;
++        Pos = MAP_APPFONT ( 133 , 82 ) ;
+         Size = MAP_APPFONT ( 80 , 8 ) ;
+         Text [ en-US ] = "Max. base text size" ;
+ 	};
+     MetricField     MF_TEXTSIZE
+     {
+-        Pos = MAP_APPFONT ( 216 , 67 ) ;
++        Pos = MAP_APPFONT ( 216 , 80 ) ;
+         Size = MAP_APPFONT ( 35 , 12 ) ;
+         Border = TRUE ;
+         TabStop = TRUE ;
+@@ -115,7 +122,7 @@ TabPage TP_TEXTGRID_PAGE
+ 		Spin = TRUE ;
+ 		Minimum = 1 ;
+ 		Maximum = 5600 ;
+-        DecimalDigits = 1 ;
++        DecimalDigits = 2 ;
+         Unit = FUNIT_POINT ;
+ 		First = 10 ;
+ 		Last = 5600 ;
+@@ -123,13 +130,13 @@ TabPage TP_TEXTGRID_PAGE
+     };
+     FixedText       FT_CHARSPERLINE
+     {
+-        Pos = MAP_APPFONT ( 12 , 85 ) ;
++        Pos = MAP_APPFONT ( 12 , 98 ) ;
+         Size = MAP_APPFONT ( 59 , 8 ) ;
+         Text [ en-US ] = "Characters per line" ;
+ 	};
+     NumericField    NF_CHARSPERLINE
+     {
+-        Pos = MAP_APPFONT ( 74 , 83 ) ;
++        Pos = MAP_APPFONT ( 74 , 96 ) ;
+         Size = MAP_APPFONT ( 25 , 12 ) ;
+         Border = TRUE ;
+         TabStop = TRUE ;
+@@ -143,62 +150,86 @@ TabPage TP_TEXTGRID_PAGE
+         Last = 233 ;
+ 		SpinSize = 1 ;
+     };
++    FixedText       FT_CHARWIDTH
++    {
++        Pos = MAP_APPFONT ( 133 , 98 ) ;
++        Size = MAP_APPFONT ( 80 , 8 ) ;
++        Text [ en-US ] = "Character ~width" ;
++        Text [ zh-CN ] = "åçèå" ;
++	};
++    MetricField     MF_CHARWIDTH
++    {
++        Pos = MAP_APPFONT ( 216 , 96 ) ;
++        Size = MAP_APPFONT ( 35 , 12 ) ;
++        Border = TRUE ;
++        TabStop = TRUE ;
++		Left = TRUE ;
++		Repeat = TRUE ;
++		Spin = TRUE ;
++		Minimum = 0 ;
++		Maximum = 5600 ;
++        DecimalDigits = 2 ;
++        Unit = FUNIT_POINT;
++		First = 0 ;
++		Last = 5600 ;
++        SpinSize = 5 ;
++    };
+     FixedText       FT_RUBYSIZE
+     {
+-        Pos = MAP_APPFONT ( 133 , 85 ) ;
++        Pos = MAP_APPFONT ( 133 , 98 ) ;
+         Size = MAP_APPFONT ( 80 , 8 ) ;
+         Text [ en-US ] = "Max. Ruby text size" ;
+ 	};
+     MetricField     MF_RUBYSIZE
+     {
+-        Pos = MAP_APPFONT ( 216 , 83 ) ;
++        Pos = MAP_APPFONT ( 216 , 96 ) ;
+         Size = MAP_APPFONT ( 35 , 12 ) ;
+         Border = TRUE ;
+         TabStop = TRUE ;
+ 		Left = TRUE ;
+ 		Repeat = TRUE ;
+ 		Spin = TRUE ;
+-		Minimum = 1 ;
++        Minimum = 0 ;
+ 		Maximum = 5600 ;
+-        DecimalDigits = 1 ;
++        DecimalDigits = 2 ;
+         Unit = FUNIT_POINT;
+-		First = 10 ;
++        First = 0 ;
+ 		Last = 5600 ;
+         SpinSize = 5 ;
+     };
+     CheckBox        CB_RUBYBELOW
+     {
+-        Pos = MAP_APPFONT ( 14 , 99 ) ;
+-        Size = MAP_APPFONT ( 242 , 10 ) ;
++        Pos = MAP_APPFONT ( 14 , 112 ) ;
++        Size = MAP_APPFONT ( 110 , 10 ) ;
+         Text [ en-US ] = "Ruby text below/left from base text" ;
+ 	};
+     FixedLine       FL_DISPLAY
+     {
+-        Pos = MAP_APPFONT ( 6 , 115 ) ;
++        Pos = MAP_APPFONT ( 6 , 128 ) ;
+         Size = MAP_APPFONT ( 248 , 8 ) ;
+         Text [ en-US ] = "Grid display" ;
+ 	};
+     CheckBox        CB_DISPLAY
+     {
+-        Pos = MAP_APPFONT ( 12 , 126 ) ;
++        Pos = MAP_APPFONT ( 12 , 139 ) ;
+         Size = MAP_APPFONT ( 112 , 10 ) ;
+         Text [ en-US ] = "Display grid" ;
+ 	};
+     CheckBox        CB_PRINT
+     {
+-        Pos = MAP_APPFONT ( 18 , 141 ) ;
++        Pos = MAP_APPFONT ( 18 , 154 ) ;
+         Size = MAP_APPFONT ( 106 , 10 ) ;
+         Text [ en-US ] = "Print grid" ;
+ 	};
+     FixedText       FT_COLOR
+     {
+-        Pos = MAP_APPFONT ( 133 , 126 ) ;
++        Pos = MAP_APPFONT ( 133 , 139 ) ;
+         Size = MAP_APPFONT ( 55 , 8 ) ;
+         Text [ en-US ] = "Grid color" ;
+ 	};
+     ListBox         LB_COLOR
+     {
+-        Pos = MAP_APPFONT ( 191 , 124 ) ;
++        Pos = MAP_APPFONT ( 191 , 137 ) ;
+         Size = MAP_APPFONT ( 60 , 50 ) ;
+         TabStop = TRUE;
+         Border = TRUE;

Added: trunk/patches/src680/cws-cjksp1-xmloff.diff
==============================================================================
--- (empty file)
+++ trunk/patches/src680/cws-cjksp1-xmloff.diff	Wed Feb 20 08:24:06 2008
@@ -0,0 +1,276 @@
+diff -uNpr xmloff.bk/inc/PageMasterImportContext.hxx xmloff/inc/PageMasterImportContext.hxx
+--- xmloff.bk/inc/PageMasterImportContext.hxx	2008-02-19 15:20:40.000000000 +0800
++++ xmloff/inc/PageMasterImportContext.hxx	2008-02-19 15:20:49.000000000 +0800
+@@ -60,7 +60,8 @@ public:
+ 	PageStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
+ 			const ::rtl::OUString& rLName,
+ 			const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList,
+-			SvXMLStylesContext& rStyles);
++			SvXMLStylesContext& rStyles,
++			sal_Bool bDefaultStyle=sal_False);
+ 	virtual ~PageStyleContext();
+ 
+ 	virtual SvXMLImportContext *CreateChildContext(
+@@ -71,6 +72,9 @@ public:
+ 	virtual void FillPropertySet(
+ 			const ::com::sun::star::uno::Reference<
+ 				::com::sun::star::beans::XPropertySet > & rPropSet );
++
++	//text grid enhancement
++	virtual void SetDefaults();
+ };
+ 
+ #endif
+diff -uNpr xmloff.bk/inc/xmloff/PageMasterStyleMap.hxx xmloff/inc/xmloff/PageMasterStyleMap.hxx
+--- xmloff.bk/inc/xmloff/PageMasterStyleMap.hxx	2008-02-19 15:20:40.000000000 +0800
++++ xmloff/inc/xmloff/PageMasterStyleMap.hxx	2008-02-19 15:20:49.000000000 +0800
+@@ -107,6 +107,9 @@
+ #define CTF_PM_SCALETOPAGES				(XML_PM_CTF_START + 0x0052)
+ #define CTF_PM_SCALETOX                 (XML_PM_CTF_START + 0x0053)
+ #define CTF_PM_SCALETOY                 (XML_PM_CTF_START + 0x0054)
++#define CTF_PM_STANDARD_MODE            (XML_PM_CTF_START + 0x0055)
++#define CTP_PM_GRID_BASE_WIDTH          (XML_PM_CTF_START + 0x0056)
++#define CTP_PM_GRID_SNAP_TO_CHARS       (XML_PM_CTF_START + 0x0057)
+ // header
+ #define CTF_PM_HEADERBORDERALL			(CTF_PM_HEADERFLAG|CTF_PM_BORDERALL)
+ #define CTF_PM_HEADERBORDERTOP			(CTF_PM_HEADERFLAG|CTF_PM_BORDERTOP)
+diff -uNpr xmloff.bk/inc/xmloff/XMLPageExport.hxx xmloff/inc/xmloff/XMLPageExport.hxx
+--- xmloff.bk/inc/xmloff/XMLPageExport.hxx	2008-02-19 15:20:40.000000000 +0800
++++ xmloff/inc/xmloff/XMLPageExport.hxx	2008-02-19 15:20:49.000000000 +0800
+@@ -130,6 +130,9 @@ public:
+ 	void	collectAutoStyles( sal_Bool bUsed )		{ exportStyles( bUsed, sal_True ); }
+ 	void	exportAutoStyles();
+ 	void	exportMasterStyles( sal_Bool bUsed )	{ exportStyles( bUsed, sal_False ); }
++
++	//text grid enhancement for better CJK support
++	void exportDefaultStyle();
+ };
+ 
+ #endif	//  _XMLOFF_XMLTEXTMASTERPAGEEXPORT_HXX
+diff -uNpr xmloff.bk/inc/xmloff/xmlstyle.hxx xmloff/inc/xmloff/xmlstyle.hxx
+--- xmloff.bk/inc/xmloff/xmlstyle.hxx	2008-02-19 15:20:40.000000000 +0800
++++ xmloff/inc/xmloff/xmlstyle.hxx	2008-02-19 15:20:49.000000000 +0800
+@@ -91,6 +91,7 @@ enum XMLStyleStylesElemTokens
+ 	XML_TOK_TEXT_BIBLIOGRAPHY_CONFIG,
+ 	XML_TOK_TEXT_LINENUMBERING_CONFIG,
+ 	XML_TOK_STYLE_DEFAULT_STYLE,
++	XML_TOK_STYLE_DEFAULT_PAGE_LAYOUT,	//text grid enhancement
+ 	XML_TOK_STYLE_STYLES_ELEM_END=XML_TOK_UNKNOWN
+ };
+ 
+diff -uNpr xmloff.bk/inc/xmloff/xmltoken.hxx xmloff/inc/xmloff/xmltoken.hxx
+--- xmloff.bk/inc/xmloff/xmltoken.hxx	2008-02-19 15:20:40.000000000 +0800
++++ xmloff/inc/xmloff/xmltoken.hxx	2008-02-19 15:20:49.000000000 +0800
+@@ -2081,6 +2081,12 @@ namespace xmloff { namespace token {
+         XML_LAYOUT_GRID_PRINT,
+         XML_LAYOUT_GRID_DISPLAY,
+ 
++		//text grid enhancement for better CJK support
++		XML_DEFAULT_PAGE_LAYOUT,
++		XML_LAYOUT_GRID_STANDARD_MODE,
++		XML_LAYOUT_GRID_BASE_WIDTH,
++		XML_LAYOUT_GRID_SNAP_TO_CHARS,
++
+         XML_SNAP_TO_LAYOUT_GRID,
+         XML_DONT_BALANCE_TEXT_COLUMNS,
+ 
+diff -uNpr xmloff.bk/source/core/xmltoken.cxx xmloff/source/core/xmltoken.cxx
+--- xmloff.bk/source/core/xmltoken.cxx	2008-02-19 15:20:40.000000000 +0800
++++ xmloff/source/core/xmltoken.cxx	2008-02-19 15:20:49.000000000 +0800
+@@ -2091,6 +2091,12 @@ namespace xmloff { namespace token {
+         TOKEN( "layout-grid-print",               XML_LAYOUT_GRID_PRINT ),
+         TOKEN( "layout-grid-display",             XML_LAYOUT_GRID_DISPLAY ),
+ 
++		//text grid enhancement for better CJK support
++        TOKEN( "default-page-layout",             XML_DEFAULT_PAGE_LAYOUT ),
++        TOKEN( "layout-grid-standard-mode",       XML_LAYOUT_GRID_STANDARD_MODE ),
++        TOKEN( "layout-grid-base-width",          XML_LAYOUT_GRID_BASE_WIDTH ),
++        TOKEN( "layout-grid-snap-to-characters",       XML_LAYOUT_GRID_SNAP_TO_CHARS ),
++
+         TOKEN( "snap-to-layout-grid",             XML_SNAP_TO_LAYOUT_GRID ),
+ 
+         TOKEN( "dont-balance-text-columns",       XML_DONT_BALANCE_TEXT_COLUMNS ),
+diff -uNpr xmloff.bk/source/style/PageMasterExportPropMapper.cxx xmloff/source/style/PageMasterExportPropMapper.cxx
+--- xmloff.bk/source/style/PageMasterExportPropMapper.cxx	2008-02-19 15:20:40.000000000 +0800
++++ xmloff/source/style/PageMasterExportPropMapper.cxx	2008-02-19 15:20:49.000000000 +0800
+@@ -348,6 +348,9 @@ void XMLPageMasterExportPropMapper::Cont
+ 	XMLPropertyState*		pPMScaleToPages		= NULL;
+ 	XMLPropertyState*		pPMScaleToX 		= NULL;
+ 	XMLPropertyState*		pPMScaleToY	    	= NULL;
++	XMLPropertyState*		pPMStandardMode    	= NULL;
++	XMLPropertyState*		pPMGridBaseWidth   	= NULL;
++	XMLPropertyState*		pPMGridSnapToChars 	= NULL;
+ 
+     XMLPropertyState*       pPrint              = NULL;
+ 
+@@ -400,6 +403,9 @@ void XMLPageMasterExportPropMapper::Cont
+ 			case CTF_PM_SCALETOPAGES:		pPMScaleToPages		= pProp;	break;
+             case CTF_PM_SCALETOX:   		pPMScaleToX 		= pProp;	break;
+             case CTF_PM_SCALETOY:   		pPMScaleToY 		= pProp;	break;
++            case CTF_PM_STANDARD_MODE:		pPMStandardMode		= pProp;	break;
++            case CTP_PM_GRID_BASE_WIDTH:		pPMGridBaseWidth	= pProp;	break;
++            case CTP_PM_GRID_SNAP_TO_CHARS:		pPMGridSnapToChars	= pProp;	break;
+ 		}
+         if (nPrintId == CTF_PM_PRINTMASK)
+         {
+@@ -408,6 +414,18 @@ void XMLPageMasterExportPropMapper::Cont
+         }
+ 	}
+ 
++	if( pPMStandardMode && !getBOOL(pPMStandardMode->maValue) )
++	{
++		lcl_RemoveState(pPMStandardMode);
++		if( pPMGridBaseWidth )
++			lcl_RemoveState(pPMGridBaseWidth);
++		if( pPMGridSnapToChars )
++			lcl_RemoveState(pPMGridSnapToChars);
++	}
++
++	if( pPMGridBaseWidth && pPMStandardMode )
++		lcl_RemoveState(pPMStandardMode);	
++	
+ 	aPageBuffer.ContextFilter( rPropState );
+ 	aHeaderBuffer.ContextFilter( rPropState );
+ 	aFooterBuffer.ContextFilter( rPropState );
+diff -uNpr xmloff.bk/source/style/PageMasterImportContext.cxx xmloff/source/style/PageMasterImportContext.cxx
+--- xmloff.bk/source/style/PageMasterImportContext.cxx	2008-02-19 15:20:40.000000000 +0800
++++ xmloff/source/style/PageMasterImportContext.cxx	2008-02-19 15:20:49.000000000 +0800
+@@ -67,8 +67,14 @@
+ #include <xmloff/PageMasterStyleMap.hxx>
+ #endif
+ 
++#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
++#include <com/sun/star/lang/XMultiServiceFactory.hpp>
++#endif
++
+ using namespace ::com::sun::star;
+ using namespace ::xmloff::token;
++using namespace ::com::sun::star::uno;
++using namespace ::com::sun::star::lang;
+ 
+ void PageStyleContext::SetAttribute( sal_uInt16 nPrefixKey,
+                                         const rtl::OUString& rLocalName,
+@@ -90,8 +96,9 @@ TYPEINIT1( PageStyleContext, XMLPropStyl
+ PageStyleContext::PageStyleContext( SvXMLImport& rImport,
+         sal_uInt16 nPrfx, const rtl::OUString& rLName,
+         const uno::Reference< xml::sax::XAttributeList > & xAttrList,
+-        SvXMLStylesContext& rStyles) :
+-    XMLPropStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles, XML_STYLE_FAMILY_PAGE_MASTER ),
++        SvXMLStylesContext& rStyles,
++        sal_Bool bDefaultStyle) :
++    XMLPropStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles, XML_STYLE_FAMILY_PAGE_MASTER, bDefaultStyle),
+     sPageUsage()
+ {
+ }
+@@ -202,3 +209,18 @@ void PageStyleContext::FillPropertySet(
+     }
+ }
+ 
++// text grid enhancement for better CJK support
++//set default page layout style
++void PageStyleContext::SetDefaults( )
++{
++	Reference < XMultiServiceFactory > xFactory ( GetImport().GetModel(), UNO_QUERY);
++	if (xFactory.is())
++	{
++		Reference < XInterface > xInt = xFactory->createInstance (
++	    rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.text.Defaults" ) ) );
++	    Reference < beans::XPropertySet > xProperties ( xInt, UNO_QUERY );
++	    if ( xProperties.is() )
++	    	FillPropertySet ( xProperties );
++	}
++}
++
+diff -uNpr xmloff.bk/source/style/PageMasterStyleMap.cxx xmloff/source/style/PageMasterStyleMap.cxx
+--- xmloff.bk/source/style/PageMasterStyleMap.cxx	2008-02-19 15:20:40.000000000 +0800
++++ xmloff/source/style/PageMasterStyleMap.cxx	2008-02-19 15:20:49.000000000 +0800
+@@ -122,6 +122,12 @@ const XMLPropertyMapEntry aXMLPageMaster
+     PLMAP( "GridPrint", XML_NAMESPACE_STYLE, XML_LAYOUT_GRID_PRINT, XML_TYPE_BOOL, 0 ),
+     PLMAP( "GridDisplay", XML_NAMESPACE_STYLE, XML_LAYOUT_GRID_DISPLAY, XML_TYPE_BOOL, 0 ),
+ 
++	//text grid enhancement for better CJK support
++    PLMAP( "GridBaseWidth", XML_NAMESPACE_STYLE, XML_LAYOUT_GRID_BASE_WIDTH, XML_TYPE_MEASURE, CTP_PM_GRID_BASE_WIDTH ),
++    PLMAP( "GridSnapToChars", XML_NAMESPACE_STYLE, XML_LAYOUT_GRID_SNAP_TO_CHARS, XML_TYPE_BOOL, CTP_PM_GRID_SNAP_TO_CHARS ),
++  	//export as a default attribute
++    PLMAP( "StandardPageMode", XML_NAMESPACE_STYLE, XML_LAYOUT_GRID_STANDARD_MODE, XML_TYPE_BOOL|MID_FLAG_DEFAULT_ITEM_EXPORT, CTF_PM_STANDARD_MODE ),
++	
+ 	PLMAP( "UserDefinedAttributes",	XML_NAMESPACE_TEXT,		XML_XMLNS,						XML_TYPE_ATTRIBUTE_CONTAINER | MID_FLAG_SPECIAL_ITEM, 0 ),
+ 
+ // footnote
+diff -uNpr xmloff.bk/source/style/XMLPageExport.cxx xmloff/source/style/XMLPageExport.cxx
+--- xmloff.bk/source/style/XMLPageExport.cxx	2008-02-19 15:20:40.000000000 +0800
++++ xmloff/source/style/XMLPageExport.cxx	2008-02-19 15:20:49.000000000 +0800
+@@ -277,3 +277,47 @@ void XMLPageExport::exportAutoStyles()
+ 		rExport.GetNamespaceMap()
+         );
+ }
++
++void XMLPageExport::exportDefaultStyle()
++{
++	Reference < lang::XMultiServiceFactory > xFactory (GetExport().GetModel(), UNO_QUERY);
++	if (xFactory.is())
++	{
++		OUString sTextDefaults ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.text.Defaults" ) );
++		Reference < XPropertySet > xPropSet (xFactory->createInstance ( sTextDefaults ), UNO_QUERY);
++		if (xPropSet.is())
++		{
++			// <style:default-style ...>
++			GetExport().CheckAttrList();
++
++			::std::vector< XMLPropertyState > xPropStates =
++				xPageMasterExportPropMapper->FilterDefaults( xPropSet );
++			
++			sal_Bool bExport = sal_False;
++			UniReference < XMLPropertySetMapper > aPropMapper(xPageMasterExportPropMapper->getPropertySetMapper());
++			for( ::std::vector< XMLPropertyState >::iterator aIter = xPropStates.begin(); aIter != xPropStates.end(); ++aIter )
++			{
++        		XMLPropertyState *pProp = &(*aIter);
++				sal_Int16 nContextId	= aPropMapper->GetEntryContextId( pProp->mnIndex );
++				if( nContextId == CTF_PM_STANDARD_MODE )
++				{
++					bExport = sal_True;
++					break;
++				}
++			}
++
++		//	if ( xPropStates.size() != 0 &&
++          //          ( xPropStates.size() != 1 || xPropStates[0].mnIndex != -1 ) )
++			if( bExport )	
++			{
++				//<style:default-page-layout>
++				SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE,
++										  XML_DEFAULT_PAGE_LAYOUT,
++										  sal_True, sal_True );
++
++				xPageMasterExportPropMapper->exportXML( GetExport(), xPropStates,
++									   	  XML_EXPORT_FLAG_IGN_WS );
++			}
++		}
++	}
++}
+diff -uNpr xmloff.bk/source/style/xmlstyle.cxx xmloff/source/style/xmlstyle.cxx
+--- xmloff.bk/source/style/xmlstyle.cxx	2008-02-19 15:20:40.000000000 +0800
++++ xmloff/source/style/xmlstyle.cxx	2008-02-19 15:20:49.000000000 +0800
+@@ -175,6 +175,7 @@ static __FAR_DATA SvXMLTokenMapEntry aSt
+ 	{ XML_NAMESPACE_TEXT,	XML_NOTES_CONFIGURATION,    XML_TOK_TEXT_NOTE_CONFIG },
+ 	{ XML_NAMESPACE_TEXT,	XML_BIBLIOGRAPHY_CONFIGURATION, XML_TOK_TEXT_BIBLIOGRAPHY_CONFIG },
+ 	{ XML_NAMESPACE_TEXT,   XML_LINENUMBERING_CONFIGURATION,XML_TOK_TEXT_LINENUMBERING_CONFIG },
++	{ XML_NAMESPACE_STYLE,	XML_DEFAULT_PAGE_LAYOUT,	XML_TOK_STYLE_DEFAULT_PAGE_LAYOUT        },
+ 	XML_TOKEN_MAP_END
+ };
+ 
+@@ -546,9 +547,13 @@ SvXMLStyleContext *SvXMLStylesContext::C
+ 			}
+ 			break;
+ 			case XML_TOK_STYLE_PAGE_MASTER:
++			case XML_TOK_STYLE_DEFAULT_PAGE_LAYOUT:
+ 			{
++				//there is not page family in odf now, so I specify one for it
++				sal_Bool bDefaultStyle  = XML_TOK_STYLE_DEFAULT_PAGE_LAYOUT == nToken
++					? sal_True: sal_False;
+ 				pStyle = new PageStyleContext( GetImport(), p_nPrefix,
+-													rLocalName, xAttrList, *this );
++													rLocalName, xAttrList, *this, bDefaultStyle );
+ 			}
+ 			break;
+ 			case XML_TOK_TEXT_LIST_STYLE:



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]