[Libreoffice-commits] core.git: Branch 'libreoffice-4-0' - sw/inc sw/source

Jian Hong Cheng chengjh at apache.org
Thu Mar 14 02:47:38 PDT 2013


 sw/inc/IDocumentContentOperations.hxx |    2 
 sw/inc/doc.hxx                        |    3 -
 sw/inc/ndtxt.hxx                      |    1 
 sw/source/core/doc/docfmt.cxx         |   54 ++++++++++++++++++--
 sw/source/core/txtnode/thints.cxx     |   70 ++++++++++++++++++++++++++
 sw/source/filter/inc/fltshell.hxx     |   25 ++++++++-
 sw/source/filter/ww1/fltshell.cxx     |   91 +++++++++++++++++++++++++++++++---
 sw/source/filter/ww8/ww8par.cxx       |   64 +++++++++++++++++++++++
 sw/source/filter/ww8/ww8par.hxx       |   16 +++++
 sw/source/filter/ww8/ww8par3.cxx      |   15 +++++
 10 files changed, 324 insertions(+), 17 deletions(-)

New commits:
commit 8675c8de07255bb77d2191fa62285904aa536c4f
Author: Jian Hong Cheng <chengjh at apache.org>
Date:   Fri Aug 24 02:28:19 2012 +0000

    Fix issue #i119405: Numbering text style changed after importing the *.doc
    
    * main/sw/inc/doc.hxx
    * main/sw/inc/IDocumentContentOperations.hxx
    * main/sw/inc/ndtxt.hxx
    * main/sw/source/core/doc/docfmt.cxx
    * main/sw/source/core/txtnode/thints.cxx
    * main/sw/source/filter/inc/fltshell.hxx
    * main/sw/source/filter/ww1/fltshell.cxx
    * main/sw/source/filter/ww8/ww8par.cxx
    * main/sw/source/filter/ww8/ww8par.hxx
    * main/sw/source/filter/ww8/ww8par3.cxx
    MS Word Binary compatibility
    
    Patch by: Fan Zheng,<zheng.easyfan at gmail.com>
    Found by: Jian Hong Cheng,<chengjh at apache.org>
    Review by: Jian Hong Cheng,<chengjh at apache.org>
    Signed-off-by: Fridrich Å trba <fridrich.strba at bluewin.ch>
    
    Conflicts:
    	sw/source/filter/inc/fltshell.hxx
    	sw/source/filter/ww1/fltshell.cxx
    	sw/source/filter/ww8/ww8par.cxx
    	sw/source/filter/ww8/ww8par.hxx
    
    (cherry picked from commit ee3b12ab1d62faedcd2d62fcb8011b7454ea0474)
    
    Change-Id: I2f72969a54db53e6a51edcf3a3216647cec9424c
    (cherry picked from commit 1c22545edf9085b9f2656ca92781158b6b123db3)
    
    Signed-off-by: Fridrich Å trba <fridrich.strba at bluewin.ch>

diff --git a/sw/inc/IDocumentContentOperations.hxx b/sw/inc/IDocumentContentOperations.hxx
index e236102..998bf6f 100644
--- a/sw/inc/IDocumentContentOperations.hxx
+++ b/sw/inc/IDocumentContentOperations.hxx
@@ -165,7 +165,7 @@
         sal_False.
     */
     virtual bool InsertPoolItem(const SwPaM &rRg, const SfxPoolItem&,
-                                const sal_uInt16 nFlags) = 0;
+                                const sal_uInt16 nFlags,bool bExpandCharToPara=false) = 0;
 
     virtual bool InsertItemSet (const SwPaM &rRg, const SfxItemSet&,
                                 const sal_uInt16 nFlags) = 0;
diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index d71ce52..ed16869 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -874,8 +874,9 @@ public:
     virtual SwDrawFrmFmt* Insert(const SwPaM &rRg, SdrObject& rDrawObj, const SfxItemSet* pFlyAttrSet, SwFrmFmt*);
     virtual SwFlyFrmFmt* Insert(const SwPaM &rRg, const svt::EmbeddedObjectRef& xObj, const SfxItemSet* pFlyAttrSet,
                         const SfxItemSet* pGrfAttrSet, SwFrmFmt*);
+    //Add a para for the char attribute exp...
     virtual bool InsertPoolItem(const SwPaM &rRg, const SfxPoolItem&,
-                                const SetAttrMode nFlags);
+                                const SetAttrMode nFlags,bool bExpandCharToPara=false);
     virtual bool InsertItemSet (const SwPaM &rRg, const SfxItemSet&,
                                 const SetAttrMode nFlags);
     virtual void ReRead(SwPaM&, const String& rGrfName, const String& rFltName, const Graphic* pGraphic, const GraphicObject* pGrfObj);
diff --git a/sw/inc/ndtxt.hxx b/sw/inc/ndtxt.hxx
index 985e6e8..e3cc9d0 100644
--- a/sw/inc/ndtxt.hxx
+++ b/sw/inc/ndtxt.hxx
@@ -206,6 +206,7 @@ public:
     /// SMARTTAGS
     void SetSmartTags( SwWrongList* pNew, bool bDelete = true );
     SwWrongList* GetSmartTags();
+    bool TryCharSetExpandToNum(const SfxItemSet& pCharSet);
 
 
     /// End: Data collected during idle time
diff --git a/sw/source/core/doc/docfmt.cxx b/sw/source/core/doc/docfmt.cxx
index 484c93c..352a451 100644
--- a/sw/source/core/doc/docfmt.cxx
+++ b/sw/source/core/doc/docfmt.cxx
@@ -495,7 +495,7 @@ void SwDoc::ResetAttrs( const SwPaM &rRg,
 
 static bool
 lcl_InsAttr(SwDoc *const pDoc, const SwPaM &rRg, const SfxItemSet& rChgSet,
-            const SetAttrMode nFlags, SwUndoAttr *const pUndo)
+            const SetAttrMode nFlags, SwUndoAttr *const pUndo,bool bExpandCharToPara=false)
 {
     // Divide the Sets (for selections in Nodes)
     const SfxItemSet* pCharSet = 0;
@@ -899,6 +899,24 @@ lcl_InsAttr(SwDoc *const pDoc, const SwPaM &rRg, const SfxItemSet& rChgSet,
             // Only selection in a Node.
             if( pStt->nNode == pEnd->nNode )
             {
+            //The data parameter flag: bExpandCharToPara, comes from the data member of SwDoc,
+            //Which is set in SW MS word Binary filter WW8ImplRreader. With this flag on, means that
+            //current setting attribute set is a character range properties set and comes from a MS word
+            //binary file, And the setting range include a paragraph end position (0X0D);
+            //More specifications, as such property inside the character range properties set recorded in
+            //MS word binary file are dealed and inserted into data model (SwDoc) one by one, so we
+            //only dealing the scenario that the char properties set with 1 item inside;
+
+                if (bExpandCharToPara && pCharSet && pCharSet->Count() ==1 )
+                {
+                    SwTxtNode* pCurrentNd = pStt->nNode.GetNode().GetTxtNode();
+
+                    if (pCurrentNd)
+                    {
+                         pCurrentNd->TryCharSetExpandToNum(*pCharSet);
+
+                    }
+                }
                 DELETECHARSETS
                 return bRet;
             }
@@ -1002,13 +1020,41 @@ lcl_InsAttr(SwDoc *const pDoc, const SwPaM &rRg, const SfxItemSet& rChgSet,
         ++nNodes;
     }
 
+    //The data parameter flag: bExpandCharToPara, comes from the data member of SwDoc,
+    //Which is set in SW MS word Binary filter WW8ImplRreader. With this flag on, means that
+    //current setting attribute set is a character range properties set and comes from a MS word
+    //binary file, And the setting range include a paragraph end position (0X0D);
+    //More specifications, as such property inside the character range properties set recorded in
+    //MS word binary file are dealed and inserted into data model (SwDoc) one by one, so we
+    //only dealing the scenario that the char properties set with 1 item inside;
+    if (bExpandCharToPara && pCharSet && pCharSet->Count() ==1)
+    {
+        SwPosition aStartPos (*rRg.Start());
+        SwPosition aEndPos (*rRg.End());
+
+        if (aEndPos.nNode.GetNode().GetTxtNode() && aEndPos.nContent != aEndPos.nNode.GetNode().GetTxtNode()->Len())
+            aEndPos.nNode--;
+
+        for (;aStartPos<=aEndPos;aStartPos.nNode++)
+        {
+            SwTxtNode* pCurrentNd = aStartPos.nNode.GetNode().GetTxtNode();
+
+            if (pCurrentNd)
+            {
+                 pCurrentNd->TryCharSetExpandToNum(*pCharSet);
+
+            }
+
+        }
+    }
+
     DELETECHARSETS
     return (nNodes != 0) || bRet;
 }
 
-
+//Add a para for the char attribute exp...
 bool SwDoc::InsertPoolItem( const SwPaM &rRg, const SfxPoolItem &rHt,
-                            const SetAttrMode nFlags )
+                            const SetAttrMode nFlags, bool bExpandCharToPara)
 {
     SwDataChanged aTmp( rRg );
     SwUndoAttr* pUndoAttr = 0;
@@ -1020,7 +1066,7 @@ bool SwDoc::InsertPoolItem( const SwPaM &rRg, const SfxPoolItem &rHt,
 
     SfxItemSet aSet( GetAttrPool(), rHt.Which(), rHt.Which() );
     aSet.Put( rHt );
-    bool bRet = lcl_InsAttr( this, rRg, aSet, nFlags, pUndoAttr );
+    bool bRet = lcl_InsAttr( this, rRg, aSet, nFlags, pUndoAttr,bExpandCharToPara );
 
     if (GetIDocumentUndoRedo().DoesUndo())
     {
diff --git a/sw/source/core/txtnode/thints.cxx b/sw/source/core/txtnode/thints.cxx
index cf549e3..a2be20b 100644
--- a/sw/source/core/txtnode/thints.cxx
+++ b/sw/source/core/txtnode/thints.cxx
@@ -1607,6 +1607,76 @@ void SwTxtNode::DelSoftHyph( const xub_StrLen nStt, const xub_StrLen nEnd )
     }
 }
 
+//In MS Word, the font underline setting of the paragraph end position wont affect the formatting of numbering, so we ignore it
+bool lcl_IsIgnoredCharFmtForNumbering(const sal_uInt16 nWhich)
+{
+    return (nWhich ==  RES_CHRATR_UNDERLINE);
+}
+
+//In MS Word, following properties of the paragraph end position wont affect the formatting of bullets, so we ignore them:
+//Font underline;
+//Font Italic of Western, CJK and CTL;
+//Font Bold of Wertern, CJK and CTL;
+bool lcl_IsIgnoredCharFmtForBullets(const sal_uInt16 nWhich)
+{
+    return (nWhich ==  RES_CHRATR_UNDERLINE || nWhich ==  RES_CHRATR_POSTURE || nWhich ==  RES_CHRATR_WEIGHT
+        || nWhich == RES_CHRATR_CJK_POSTURE || nWhich == RES_CHRATR_CJK_WEIGHT
+        || nWhich == RES_CHRATR_CTL_POSTURE || nWhich == RES_CHRATR_CTL_WEIGHT);
+}
+
+//Condition for expanding char set to character style of specified number rule level:
+//The item inside the set should not conflict to any exist and non-default item inside paragraph properties set (SwCntntNode::SwPAttrSet);
+//The node should have applied a number rule;
+//The node should be counted in a list, if not, make it to be;
+//The item should not conflict to any exist and non-default item inside the character of specified number rule level;
+//The item should not be ignored depend on the exact number rule type;
+bool SwTxtNode::TryCharSetExpandToNum(const SfxItemSet& aCharSet)
+{
+    bool bRet = false;
+    SfxItemIter aIter( aCharSet );
+        const SfxPoolItem* pItem = aIter.FirstItem();
+        const sal_uInt16 nWhich = pItem->Which();
+
+    const SfxPoolItem& rInnerItem = GetAttr(nWhich,false);
+
+    if (!IsDefaultItem(&rInnerItem) &&  !IsInvalidItem(&rInnerItem))
+        return bRet;
+
+    if ( !IsInList() && GetNumRule() && GetListId().Len() > 0 )
+    {
+        return bRet;
+    }
+
+    SwNumRule* pCurrNum = GetNumRule(false);
+
+    int nLevel = GetActualListLevel();
+
+    if (nLevel != -1 && pCurrNum)
+    {
+        const SwNumFmt* pCurrNumFmt = pCurrNum->GetNumFmt(static_cast<sal_uInt16>(nLevel));
+        if (pCurrNumFmt)
+        {
+            if (pCurrNumFmt->IsItemize() && lcl_IsIgnoredCharFmtForBullets(nWhich))
+                return bRet;
+            if (pCurrNumFmt->IsEnumeration() && lcl_IsIgnoredCharFmtForNumbering(nWhich))
+                return bRet;
+            SwCharFmt* pCurrCharFmt =pCurrNumFmt->GetCharFmt();
+
+            if (pCurrCharFmt && pCurrCharFmt->GetItemState(nWhich,false) != SFX_ITEM_SET)
+            {
+                pCurrCharFmt->SetFmtAttr(*pItem);
+                SwNumFmt aNewNumFmt(*pCurrNumFmt);
+                aNewNumFmt.SetCharFmt(pCurrCharFmt);
+                pCurrNum->Set(nLevel,aNewNumFmt);
+                bRet = true;
+            }
+        }
+    }
+
+
+    return bRet;
+}
+
 // setze diese Attribute am TextNode. Wird der gesamte Bereich umspannt,
 // dann setze sie nur im AutoAttrSet (SwCntntNode:: SetAttr)
 sal_Bool SwTxtNode::SetAttr( const SfxItemSet& rSet, xub_StrLen nStt,
diff --git a/sw/source/filter/inc/fltshell.hxx b/sw/source/filter/inc/fltshell.hxx
index 55ea8e4..e0a64b3 100644
--- a/sw/source/filter/inc/fltshell.hxx
+++ b/sw/source/filter/inc/fltshell.hxx
@@ -111,6 +111,10 @@ public:
     sal_Bool bOpen;     //Entry open, awaiting being closed
     sal_Bool bConsumedByField;
 
+    sal_Int32 mnStartCP;
+    sal_Int32 mnEndCP;
+    bool bIsParaEnd;
+
     SW_DLLPUBLIC SwFltStackEntry(const SwPosition & rStartPos, SfxPoolItem* pHt );
     SW_DLLPUBLIC ~SwFltStackEntry();
 
@@ -118,8 +122,16 @@ public:
     SW_DLLPUBLIC void SetEndPos(  const SwPosition & rEndPos);
     SW_DLLPUBLIC bool MakeRegion(SwDoc* pDoc, SwPaM& rRegion, bool bCheck) const;
     SW_DLLPUBLIC static bool MakeRegion(SwDoc* pDoc, SwPaM& rRegion,
-        bool bCheck, const SwFltPosition &rMkPos, const SwFltPosition &rPtPos,
+        bool bCheck, const SwFltPosition &rMkPos, const SwFltPosition &rPtPos, bool bIsParaEnd=false,
         sal_uInt16 nWhich=0);
+
+    void SetStartCP(sal_Int32 nCP) {mnStartCP = nCP;}
+    void SetEndCP(sal_Int32 nCP) {mnEndCP = nCP;}
+    sal_Int32 GetStartCP() const {return mnStartCP;}
+    sal_Int32 GetEndCP() const {return mnEndCP;}
+    bool IsAbleMakeRegion();
+    bool IsParaEnd(){ return bIsParaEnd;}
+    void SetIsParaEnd(bool bArg){ bIsParaEnd = bArg;}
 };
 
 class SW_DLLPUBLIC SwFltControlStack : private ::boost::noncopyable
@@ -132,12 +144,23 @@ class SW_DLLPUBLIC SwFltControlStack : private ::boost::noncopyable
     sal_uLong nFieldFlags;
     KeyCode aEmptyKeyCode; // fuer Bookmarks
 
+private:
+    bool bHasSdOD;
+    bool bSdODChecked;
+
 protected:
     SwDoc* pDoc;
     sal_Bool bIsEndStack;
 
     void MoveAttrs( const SwPosition&  rPos );
     virtual void SetAttrInDoc(const SwPosition& rTmpPos, SwFltStackEntry& rEntry);
+    virtual sal_Int32 GetCurrAttrCP() const {return -1;}
+    virtual bool IsParaEndInCPs(sal_Int32 nStart,sal_Int32 nEnd,bool bSdOD=true) const;
+
+    //Clear the para end position recorded in reader intermittently for the least impact on loading performance
+    virtual void ClearParaEndPosition(){};
+    virtual bool CheckSdOD(sal_Int32 nStart,sal_Int32 nEnd);
+    bool HasSdOD();
 
 public:
     enum Flags
diff --git a/sw/source/filter/ww1/fltshell.cxx b/sw/source/filter/ww1/fltshell.cxx
index 2608e62..9eb9364 100644
--- a/sw/source/filter/ww1/fltshell.cxx
+++ b/sw/source/filter/ww1/fltshell.cxx
@@ -81,6 +81,9 @@ static SwCntntNode* GetCntntNode(SwDoc* pDoc, SwNodeIndex& rIdx, sal_Bool bNext)
 SwFltStackEntry::SwFltStackEntry(const SwPosition& rStartPos, SfxPoolItem* pHt)
     : m_aMkPos(rStartPos)
     , m_aPtPos(rStartPos)
+    , mnStartCP(-1)
+    , mnEndCP(-1)
+    , bIsParaEnd(false)
 {
     pAttr = pHt;        // speicher eine Kopie vom Attribut
     bOld    = sal_False;    // used for marking Attributes *before* skipping field results
@@ -105,22 +108,26 @@ void SwFltStackEntry::SetEndPos(const SwPosition& rEndPos)
     m_aPtPos.SetPos(rEndPos);
 }
 
+
 bool SwFltStackEntry::MakeRegion(SwDoc* pDoc, SwPaM& rRegion, bool bCheck,
-    const SwFltPosition &rMkPos, const SwFltPosition &rPtPos,
+    const SwFltPosition &rMkPos, const SwFltPosition &rPtPos, bool bIsParaEnd,
     sal_uInt16 nWhich)
 {
     // does this range actually contain something?
     // empty range is allowed if at start of empty paragraph
     // fields are special: never have range, so leave them
+    //
+    // The only position of 0x0D will not be able to make region in the old logic
+    // because it is beyond the length of para...need special consideration here.
     SwCntntNode *const pCntntNode(
         SwNodeIndex(rMkPos.m_nNode, +1).GetNode().GetCntntNode());
     if (rMkPos == rPtPos &&
         ((0 != rPtPos.m_nCntnt) || (pCntntNode && (0 != pCntntNode->Len())))
-        && (RES_TXTATR_FIELD != nWhich))
+        && (RES_TXTATR_FIELD != nWhich)
+        && !(bIsParaEnd && pCntntNode && pCntntNode->IsTxtNode() && 0 != pCntntNode->Len() ))
     {
         return false;
     }
-
     // !!! Die Content-Indizies beziehen sich immer auf den Node !!!
     rRegion.GetPoint()->nNode = rMkPos.m_nNode.GetIndex() + 1;
     SwCntntNode* pCNd = GetCntntNode(pDoc, rRegion.GetPoint()->nNode, sal_True);
@@ -144,12 +151,12 @@ bool SwFltStackEntry::MakeRegion(SwDoc* pDoc, SwPaM& rRegion, bool bCheck,
 
 bool SwFltStackEntry::MakeRegion(SwDoc* pDoc, SwPaM& rRegion, bool bCheck) const
 {
-    return MakeRegion(pDoc, rRegion, bCheck, m_aMkPos, m_aPtPos,
+    return MakeRegion(pDoc, rRegion, bCheck, m_aMkPos, m_aPtPos, bIsParaEnd,
         pAttr->Which());
 }
 
 SwFltControlStack::SwFltControlStack(SwDoc* pDo, sal_uLong nFieldFl)
-    : nFieldFlags(nFieldFl), pDoc(pDo), bIsEndStack(false)
+    : nFieldFlags(nFieldFl),bHasSdOD(true), bSdODChecked(false), pDoc(pDo), bIsEndStack(false)
 {
 }
 
@@ -238,7 +245,11 @@ void SwFltControlStack::NewAttr(const SwPosition& rPos, const SfxPoolItem& rAttr
         pExtendCandidate->bOpen=true;
     }
     else
-        maEntries.push_back(new SwFltStackEntry(rPos, rAttr.Clone()));
+    {
+        SwFltStackEntry *pTmp = new SwFltStackEntry(rPos, rAttr.Clone() );
+        pTmp->SetStartCP(GetCurrAttrCP());
+        maEntries.push_back(pTmp);
+    }
 }
 
 void SwFltControlStack::DeleteAndDestroy(Entries::size_type nCnt)
@@ -249,6 +260,14 @@ void SwFltControlStack::DeleteAndDestroy(Entries::size_type nCnt)
         myEIter aElement = maEntries.begin() + nCnt;
         maEntries.erase(aElement);
     }
+    //Clear the para end position recorded in reader intermittently for the least impact on loading performance
+    //Because the attributes handled based on the unit of para
+    if ( empty() )
+    {
+        ClearParaEndPosition();
+        bHasSdOD = true;
+        bSdODChecked = false;
+    }
 }
 
 // SwFltControlStack::StealAttr() loescht Attribute des angegebenen Typs vom Stack.
@@ -343,6 +362,7 @@ SwFltStackEntry* SwFltControlStack::SetAttr(const SwPosition& rPos,
             {
                 rEntry.bConsumedByField = consumedByField;
                 rEntry.SetEndPos(rPos);
+                rEntry.SetEndCP(GetCurrAttrCP());
                 if (bLastEntry && nAttrId == rEntry.pAttr->Which())
                 {
                     //potential candidate for merging with an identical
@@ -446,6 +466,28 @@ static sal_Bool IterateNumrulePiece( const SwNodeIndex& rEnd,
     return rTmpStart <= rTmpEnd;                    // gueltig ?
 }
 
+//***This function will check whether there is existing individual attribute positon for 0x0D***/
+//The check will happen only once for a paragraph during loading
+bool SwFltControlStack::HasSdOD()
+{
+    bool bRet = false;
+
+    for (Entries::iterator it = maEntries.begin(); it != maEntries.end(); ++it)
+    {
+        SwFltStackEntry& rEntry = *it;
+        if ( rEntry.mnStartCP == rEntry.mnEndCP )
+        {
+            if ( CheckSdOD(rEntry.mnStartCP,rEntry.mnEndCP) )
+            {
+                bRet = true;
+                break;
+            }
+        }
+    }
+
+    return bRet;
+}
+
 void SwFltControlStack::SetAttrInDoc(const SwPosition& rTmpPos,
     SwFltStackEntry& rEntry)
 {
@@ -628,14 +670,47 @@ void SwFltControlStack::SetAttrInDoc(const SwPosition& rTmpPos,
         }
         break;
     default:
-        if (rEntry.MakeRegion(pDoc, aRegion, sal_False))
         {
-            pDoc->InsertPoolItem(aRegion, *rEntry.pAttr, 0);
+            //Revised for more complex situations should be considered
+            if ( !bSdODChecked )
+            {
+                bHasSdOD = HasSdOD();
+                bSdODChecked = true;
+            }
+            sal_Int32 nStart = rEntry.GetStartCP();
+            sal_Int32 nEnd = rEntry.GetEndCP();
+            if (nStart != -1 && nEnd != -1 && nEnd >= nStart )
+            {
+                rEntry.SetIsParaEnd( IsParaEndInCPs(nStart,nEnd,bHasSdOD) );
+            }
+            if (rEntry.MakeRegion(pDoc, aRegion, sal_False))
+            {
+                nStart = rEntry.GetStartCP();
+                nEnd = rEntry.GetEndCP();
+                if (rEntry.IsParaEnd())
+                {
+                    pDoc->InsertPoolItem(aRegion, *rEntry.pAttr, 0, true);
+                }
+                else
+                {
+                    pDoc->InsertPoolItem(aRegion, *rEntry.pAttr, 0);
+                }
+            }
         }
         break;
     }
 }
 
+bool SwFltControlStack::IsParaEndInCPs(sal_Int32 /*nStart*/, sal_Int32 /*nEnd*/,bool /*bSdOD*/) const
+{
+    return false;
+}
+
+bool SwFltControlStack::CheckSdOD(sal_Int32 /*nStart*/, sal_Int32 /*nEnd*/)
+{
+    return false;
+}
+
 SfxPoolItem* SwFltControlStack::GetFmtStackAttr(sal_uInt16 nWhich, sal_uInt16 * pPos)
 {
     size_t nSize = maEntries.size();
diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx
index d18106e..095e6ea 100644
--- a/sw/source/filter/ww8/ww8par.cxx
+++ b/sw/source/filter/ww8/ww8par.cxx
@@ -1015,6 +1015,30 @@ const SwNumFmt* SwWW8FltControlStack::GetNumFmtFromStack(const SwPosition &rPos,
     return pRet;
 }
 
+sal_Int32 SwWW8FltControlStack::GetCurrAttrCP() const
+{
+    return rReader.GetCurrAttrCP();
+}
+
+bool SwWW8FltControlStack::IsParaEndInCPs(sal_Int32 nStart,sal_Int32 nEnd,bool bSdOD) const
+{
+    return rReader.IsParaEndInCPs(nStart,nEnd,bSdOD);
+}
+
+//Clear the para end position recorded in reader intermittently for the least impact on loading performance
+void SwWW8FltControlStack::ClearParaEndPosition()
+{
+    if ( !empty() )
+        return;
+
+    rReader.ClearParaEndPosition();
+}
+
+bool SwWW8FltControlStack::CheckSdOD(sal_Int32 nStart,sal_Int32 nEnd)
+{
+    return rReader.IsParaEndInCPs(nStart,nEnd);
+}
+
 void SwWW8FltControlStack::SetAttrInDoc(const SwPosition& rTmpPos,
     SwFltStackEntry& rEntry)
 {
@@ -3344,6 +3368,34 @@ long SwWW8ImplReader::ReadTextAttr(WW8_CP& rTxtPos, bool& rbStartLine)
     return nNext;
 }
 
+//Revised 2012.8.16 for the complex attribute presentation of 0x0D in MS
+bool SwWW8ImplReader::IsParaEndInCPs(sal_Int32 nStart, sal_Int32 nEnd,bool bSdOD) const
+{
+    //Revised for performance consideration
+    if (nStart == -1 || nEnd == -1 || nEnd < nStart )
+        return false;
+
+    for (cp_vector::const_reverse_iterator aItr = maEndParaPos.rbegin(); aItr!= maEndParaPos.rend(); aItr++)
+    {
+        //Revised 2012.8.16,to the 0x0D,the attribute will have two situations
+        //*********within***********exact******//
+        //*********but also sample with only left and the position of 0x0d is the edge of the right side***********//
+        if ( bSdOD && ( (nStart < *aItr && nEnd > *aItr) || ( nStart == nEnd && *aItr == nStart)) )
+            return true;
+        else if ( !bSdOD &&  (nStart < *aItr && nEnd >= *aItr) )
+            return true;
+    }
+
+    return false;
+}
+
+//Clear the para end position recorded in reader intermittently for the least impact on loading performance
+void SwWW8ImplReader::ClearParaEndPosition()
+{
+    if ( maEndParaPos.size() > 0 )
+        maEndParaPos.clear();
+}
+
 void SwWW8ImplReader::ReadAttrs(WW8_CP& rNext, WW8_CP& rTxtPos, bool& rbStartLine)
 {
     if( rTxtPos >= rNext )
@@ -3351,6 +3403,7 @@ void SwWW8ImplReader::ReadAttrs(WW8_CP& rNext, WW8_CP& rTxtPos, bool& rbStartLin
 
         do
         {
+            maCurrAttrCP = rTxtPos;
             rNext = ReadTextAttr( rTxtPos, rbStartLine );
         }
         while( rTxtPos >= rNext );
@@ -3434,7 +3487,12 @@ bool SwWW8ImplReader::ReadText(long nStartCp, long nTextLen, ManTypes nType)
         // create a new txtnode and join the two paragraphs together
 
         if (bStartLine && !pPreviousNode) // Zeilenende
+        {
+            //We will record the CP of a paragraph end ('0x0D'), if current loading contents is from main stream;
+            if (mbOnLoadingMain)
+                maEndParaPos.push_back(l-1);
             AppendTxtNode(*pPaM->GetPoint());
+        }
 
         if (pPreviousNode && bStartLine)
         {
@@ -3593,7 +3651,9 @@ SwWW8ImplReader::SwWW8ImplReader(sal_uInt8 nVersionPara, SvStorage* pStorage,
     nDropCap(0),
     nIdctHint(0),
     bBidi(false),
-    bReadTable(false)
+    bReadTable(false),
+    maCurrAttrCP(-1),
+    mbOnLoadingMain(false)
 {
     pStrm->SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN );
     nWantedVersion = nVersionPara;
@@ -4599,7 +4659,9 @@ sal_uLong SwWW8ImplReader::CoreLoad(WW8Glossary *pGloss, const SwPosition &rPos)
 
             StoreMacroCmds();
         }
+        mbOnLoadingMain = true;
         ReadText(0, pWwFib->ccpText, MAN_MAINTEXT);
+        mbOnLoadingMain = false;
 
     }
 
diff --git a/sw/source/filter/ww8/ww8par.hxx b/sw/source/filter/ww8/ww8par.hxx
index 31321f7..18d4e3c 100644
--- a/sw/source/filter/ww8/ww8par.hxx
+++ b/sw/source/filter/ww8/ww8par.hxx
@@ -330,6 +330,12 @@ protected:
     virtual void SetAttrInDoc(const SwPosition& rTmpPos,
         SwFltStackEntry& rEntry);
 
+    virtual sal_Int32 GetCurrAttrCP() const;
+    virtual bool IsParaEndInCPs(sal_Int32 nStart,sal_Int32 nEnd,bool bSdOD=true) const;
+    //Clear the para end position recorded in reader intermittently for the least impact on loading performance
+    virtual void ClearParaEndPosition();
+    virtual bool CheckSdOD(sal_Int32 nStart,sal_Int32 nEnd);
+
 public:
     SwWW8FltControlStack(SwDoc* pDo, sal_uLong nFieldFl, SwWW8ImplReader& rReader_ )
         : SwFltControlStack( pDo, nFieldFl ), rReader( rReader_ ),
@@ -910,6 +916,8 @@ struct WW8PostProcessAttrsInfo
 //-----------------------------------------
 //            Storage-Reader
 //-----------------------------------------
+typedef std::vector<WW8_CP> cp_vector;
+
 class SwWW8ImplReader
 {
 private:
@@ -1208,6 +1216,9 @@ private:
     bool bReadTable;
     boost::shared_ptr<SwPaM> mpTableEndPaM;
 
+    cp_vector maEndParaPos;
+    WW8_CP maCurrAttrCP;
+    bool mbOnLoadingMain:1;
 //---------------------------------------------
 
     const SprmReadInfo& GetSprmReadInfo(sal_uInt16 nId) const;
@@ -1534,7 +1545,10 @@ public:     // eigentlich private, geht aber leider nur public
     sal_uInt16 GetToggleBiDiAttrFlags() const;
     void SetToggleAttrFlags(sal_uInt16 nFlags);
     void SetToggleBiDiAttrFlags(sal_uInt16 nFlags);
-
+    WW8_CP GetCurrAttrCP() const {return maCurrAttrCP;}
+    bool IsParaEndInCPs(sal_Int32 , sal_Int32,bool bSdOD=true) const;
+    //Clear the para end position recorded in reader intermittently for the least impact on loading performance
+    void ClearParaEndPosition();
 
     long Read_Ftn(WW8PLCFManResult* pRes);
     sal_uInt16 End_Ftn();
diff --git a/sw/source/filter/ww8/ww8par3.cxx b/sw/source/filter/ww8/ww8par3.cxx
index 9017061..6bf6b70 100644
--- a/sw/source/filter/ww8/ww8par3.cxx
+++ b/sw/source/filter/ww8/ww8par3.cxx
@@ -995,6 +995,21 @@ void WW8ListManager::AdjustLVL( sal_uInt8 nLevel, SwNumRule& rNumRule,
         //
         aNumFmt.SetCharFmt( pFmt );
     }
+    //Ensure the default char fmt is initialized for any level of num ruler if no customized attr
+    else
+    {
+        SwCharFmt* pFmt = aNumFmt.GetCharFmt();
+        if ( !pFmt)
+        {
+            OUString aName = ( sPrefix.Len() ? sPrefix : rNumRule.GetName() );
+                     aName += "z" + OUString::valueOf( nLevel );
+
+                    pFmt = rDoc.MakeCharFmt(aName, (SwCharFmt*)rDoc.GetDfltCharFmt());
+                    bNewCharFmtCreated = true;
+            rCharFmt[ nLevel ] = pFmt;
+            aNumFmt.SetCharFmt( pFmt );
+        }
+    }
     //
     // ggfs. Bullet Font an das NumFormat haengen
     //


More information about the Libreoffice-commits mailing list