Date: prev next · Thread: first prev next last
2011 Archives by date, by thread · List index


Hi Cedric, all,

https://bugs.freedesktop.org/show_bug.cgi?id=37516

So this one was a particularly nasty one; the only thing I had was a
black box (in the form of MSO 2010) answering yes/no about the document
validity :-)  Long story short, it was SPRM SDxtCharSpace that had wrong
value.

The attached patch reverts the simplified computation of its value that
produces wrong results when nPitch is smaller than nPageCharSize.  Maybe
it could be simplified in another way, but I think the safest ATM is to
return to the algorithm that was there before (see commit
e5693d5e14f8a53070b86ea1682201f5f2149b82).

Review appreciated, targeting libreoffice-3-4 branch.

Thank you,
Kendy
From 7941d9a4716c1579e81857abab0922701b319c9a Mon Sep 17 00:00:00 2001
From: Jan Holesovsky <kendy@suse.cz>
Date: Fri, 1 Jul 2011 10:04:37 +0200
Subject: [PATCH] Fix the computation of grid character pitch, fdo#37516.

---
 sw/source/filter/ww8/attributeoutputbase.hxx |    3 ++
 sw/source/filter/ww8/docxattributeoutput.cxx |   17 +---------
 sw/source/filter/ww8/ww8atr.cxx              |   47 +++++++++++++++++--------
 3 files changed, 36 insertions(+), 31 deletions(-)

diff --git a/sw/source/filter/ww8/attributeoutputbase.hxx 
b/sw/source/filter/ww8/attributeoutputbase.hxx
index 25fc965..84e58f7 100644
--- a/sw/source/filter/ww8/attributeoutputbase.hxx
+++ b/sw/source/filter/ww8/attributeoutputbase.hxx
@@ -539,6 +539,9 @@ protected:
     /// Sfx item RES_KEEP
     virtual void FormatKeep( const SvxFmtKeepItem& ) = 0;
 
+    /// Compute the grid character pitch
+    sal_uInt32 GridCharacterPitch( const SwTextGridItem& rGrid ) const;
+
     /// Sfx item RES_TEXTGRID
     virtual void FormatTextGrid( const SwTextGridItem& ) = 0;
 
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index 9fd3150..693549c 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -4041,23 +4041,8 @@ void DocxAttributeOutput::FormatTextGrid( const SwTextGridItem& rGrid )
     pGridAttrList->add( FSNS( XML_w, XML_linePitch ),
             OString::valueOf( sal_Int32( nHeight ) ).getStr( ) );
 
-    MSWordStyles * pStyles = m_rExport.pStyles;
-    SwFmt * pSwFmt = pStyles->GetSwFmt();
-
-    sal_uInt32 nPageCharSize = 0;
-
-    if (pSwFmt != NULL)
-    {
-        nPageCharSize = ItemGet<SvxFontHeightItem>
-        (*pSwFmt, RES_CHRATR_FONTSIZE).GetHeight();
-    }
-
-    sal_uInt16 nPitch = rGrid.IsSquaredMode() ? rGrid.GetBaseHeight() :
-        rGrid.GetBaseWidth( );
-    sal_Int32 nCharSpace = ( nPitch - nPageCharSize ) * 4096 / 20;
-
     pGridAttrList->add( FSNS( XML_w, XML_charSpace ),
-            OString::valueOf( sal_Int32( nCharSpace ) ).getStr( ) );
+            OString::valueOf( sal_Int32( GridCharacterPitch( rGrid ) ) ).getStr( ) );
 
     m_pSerializer->singleElementNS( XML_w, XML_docGrid, pGridAttrList );
 }
diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx
index 63ee393..6e61641 100644
--- a/sw/source/filter/ww8/ww8atr.cxx
+++ b/sw/source/filter/ww8/ww8atr.cxx
@@ -3641,6 +3641,37 @@ void WW8AttributeOutput::SectionBreak( sal_uInt8 nC, const WW8_SepInfo* 
/*pSecti
     m_rWW8Export.ReplaceCr( nC );
 }
 
+sal_uInt32 AttributeOutputBase::GridCharacterPitch( const SwTextGridItem& rGrid ) const
+{
+    MSWordStyles * pStyles = GetExport().pStyles;
+    SwFmt * pSwFmt = pStyles->GetSwFmt();
+
+    sal_uInt32 nPageCharSize = 0;
+
+    if (pSwFmt != NULL)
+    {
+        nPageCharSize = ItemGet<SvxFontHeightItem>
+            (*pSwFmt, RES_CHRATR_FONTSIZE).GetHeight();
+    }
+    sal_uInt16 nPitch = rGrid.IsSquaredMode() ? rGrid.GetBaseHeight() :
+        rGrid.GetBaseWidth( );
+
+    sal_Int32 nCharWidth = nPitch - nPageCharSize;
+    sal_Int32 nFraction = nCharWidth % 20;
+    if ( nCharWidth < 0 )
+        nFraction = 20 + nFraction;
+    nFraction = ( nFraction * 0xFFF ) / 20;
+    nFraction = ( nFraction & 0x00000FFF );
+
+    sal_Int32 nMain = nCharWidth / 20;
+    if ( nCharWidth < 0 )
+        nMain -= 1;
+    nMain = nMain * 0x1000;
+    nMain = ( nMain & 0xFFFFF000 );
+
+    return sal_uInt32( nFraction + nMain );
+}
+
 void WW8AttributeOutput::FormatTextGrid( const SwTextGridItem& rGrid )
 {
     if ( m_rWW8Export.bOutPageDescs && m_rWW8Export.bWrtWW8 )
@@ -3670,22 +3701,8 @@ void WW8AttributeOutput::FormatTextGrid( const SwTextGridItem& rGrid )
         m_rWW8Export.InsUInt16( NS_sprm::LN_SDyaLinePitch );
         m_rWW8Export.InsUInt16( nHeight );
 
-        MSWordStyles * pStyles = m_rWW8Export.pStyles;
-        SwFmt * pSwFmt = pStyles->GetSwFmt();
-
-        sal_uInt32 nPageCharSize = 0;
-
-        if (pSwFmt != NULL)
-        {
-            nPageCharSize = ItemGet<SvxFontHeightItem>
-            (*pSwFmt, RES_CHRATR_FONTSIZE).GetHeight();
-        }
-        sal_uInt16 nPitch = rGrid.IsSquaredMode() ? rGrid.GetBaseHeight() :
-            rGrid.GetBaseWidth( );
-        sal_Int32 nCharSpace = ( nPitch - nPageCharSize ) * 4096 / 20;
-
         m_rWW8Export.InsUInt16( NS_sprm::LN_SDxtCharSpace );
-        m_rWW8Export.InsUInt32( nCharSpace );
+        m_rWW8Export.InsUInt32( GridCharacterPitch( rGrid ) );
     }
 }
 
-- 
1.7.5.4


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.