[Libreoffice-commits] .: 2 commits - sw/inc sw/source

Cédric Bosdonnat cbosdo at kemper.freedesktop.org
Wed Aug 10 01:18:26 PDT 2011


 sw/inc/numrule.hxx               |   10 +++++-
 sw/source/core/doc/number.cxx    |   56 ++++++++++++++++++++++++++++++++--
 sw/source/filter/rtf/rtffld.cxx  |   50 +++++++++++++-----------------
 sw/source/filter/ww8/ww8atr.cxx  |   12 +++++++
 sw/source/filter/ww8/ww8par5.cxx |   63 +++++++++++++++++++--------------------
 5 files changed, 126 insertions(+), 65 deletions(-)

New commits:
commit 234642040086ee91bdb026e10a7c92ec71ac24d3
Author: Troy Rollo <libreoffice at troy.rollo.name>
Date:   Mon Jul 18 00:54:26 2011 +1000

    fdo#33960 - import/export xrefs to numbered paras

diff --git a/sw/source/filter/rtf/rtffld.cxx b/sw/source/filter/rtf/rtffld.cxx
index eb0b465..7bb6210 100644
--- a/sw/source/filter/rtf/rtffld.cxx
+++ b/sw/source/filter/rtf/rtffld.cxx
@@ -813,8 +813,7 @@ int SwRTFParser::MakeFieldInst( String& rFieldStr )
     case RTFFLD_REF:
         {
             String sOrigBkmName;
-            bool bChapterNr = false;
-            bool bAboveBelow = false;
+            REFERENCEMARK eFormat = REF_CONTENT;
 
             RtfFieldSwitch aRFS( aSaveStr );
             while( !aRFS.IsAtEnd() )
@@ -828,42 +827,35 @@ int SwRTFParser::MakeFieldInst( String& rFieldStr )
                             sOrigBkmName = sParam;
                         break;
 
+                    /* References to numbers in Word could be either to a numbered
+                    paragraph or to a chapter number. However Word does not seem to
+                    have the capability we do, of refering to the chapter number some
+                    other bookmark is in. As a result, cross-references to chapter
+                    numbers in a word document will be cross-references to a numbered
+                    paragraph, being the chapter heading paragraph. As it happens, our
+                    cross-references to numbered paragraphs will do the right thing
+                    when the target is a numbered chapter heading, so there is no need
+                    for us to use the REF_CHAPTER bookmark format on import.
+                    */
                     case 'n':
+                        eFormat = REF_NUMBER_NO_CONTEXT;
+                        break;
                     case 'r':
+                        eFormat = REF_NUMBER;
+                        break;
                     case 'w':
-                        bChapterNr = true; // activate flag 'Chapter Number'
+                        eFormat = REF_NUMBER_FULL_CONTEXT;
                         break;
 
                     case 'p':
-                        bAboveBelow = true;
+                        eFormat = REF_UPDOWN;
                         break;
                 }
             }
-            if (!bAboveBelow || bChapterNr)
-            {
-                if (bChapterNr)
-                {
-                    SwGetRefField aFld(
-                        (SwGetRefFieldType*)pDoc->GetSysFldType( RES_GETREFFLD ),
-                        sOrigBkmName,REF_BOOKMARK,0,REF_CHAPTER);
-                    pDoc->InsertPoolItem( *pPam, SwFmtFld( aFld ), 0 );
-                }
-                else
-                {
-                    SwGetRefField aFld(
-                        (SwGetRefFieldType*)pDoc->GetSysFldType( RES_GETREFFLD ),
-                        sOrigBkmName,REF_BOOKMARK,0,REF_CONTENT);
-                    pDoc->InsertPoolItem( *pPam, SwFmtFld( aFld ), 0 );
-                }
-            }
-
-            if( bAboveBelow )
-            {
-                SwGetRefField aFld( (SwGetRefFieldType*)
-                    pDoc->GetSysFldType( RES_GETREFFLD ), sOrigBkmName, REF_BOOKMARK, 0,
-                    REF_UPDOWN );
-                pDoc->InsertPoolItem(*pPam, SwFmtFld(aFld), 0);
-            }
+            SwGetRefField aFld(
+                (SwGetRefFieldType*)pDoc->GetSysFldType( RES_GETREFFLD ),
+                sOrigBkmName,REF_BOOKMARK,0,eFormat);
+            pDoc->InsertPoolItem( *pPam, SwFmtFld( aFld ), 0 );
         }
         break;
 
diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx
index 08241b2..8841a07 100644
--- a/sw/source/filter/ww8/ww8atr.cxx
+++ b/sw/source/filter/ww8/ww8atr.cxx
@@ -2830,6 +2830,18 @@ void AttributeOutputBase::TextField( const SwFmtFld& rField )
                     sStr = FieldString(eFld);
                     sStr += GetExport().GetBookmarkName(nSubType,
                         &rRFld.GetSetRefName(), 0);
+                    switch (pFld->GetFormat())
+                    {
+                        case REF_NUMBER:
+                            sStr.APPEND_CONST_ASC(" \\r");
+                            break;
+                        case REF_NUMBER_NO_CONTEXT:
+                            sStr.APPEND_CONST_ASC(" \\n");
+                            break;
+                        case REF_NUMBER_FULL_CONTEXT:
+                            sStr.APPEND_CONST_ASC(" \\w");
+                            break;
+                    }
                     break;
                 case REF_FOOTNOTE:
                 case REF_ENDNOTE:
diff --git a/sw/source/filter/ww8/ww8par5.cxx b/sw/source/filter/ww8/ww8par5.cxx
index 0d99332..0b654ae 100644
--- a/sw/source/filter/ww8/ww8par5.cxx
+++ b/sw/source/filter/ww8/ww8par5.cxx
@@ -2064,8 +2064,7 @@ eF_ResT SwWW8ImplReader::Read_F_Set( WW8FieldDesc* pF, String& rStr )
 eF_ResT SwWW8ImplReader::Read_F_Ref( WW8FieldDesc*, String& rStr )
 {                                                       // Reference - Field
     String sOrigBkmName;
-    bool bChapterNr = false;
-    bool bAboveBelow = false;
+    REFERENCEMARK eFormat = REF_CONTENT;
 
     long nRet;
     _ReadFieldParams aReadParam( rStr );
@@ -2077,14 +2076,29 @@ eF_ResT SwWW8ImplReader::Read_F_Ref( WW8FieldDesc*, String& rStr )
             if( !sOrigBkmName.Len() ) // get name of bookmark
                 sOrigBkmName = aReadParam.GetResult();
             break;
+
+        /* References to numbers in Word could be either to a numbered
+        paragraph or to a chapter number. However Word does not seem to
+        have the capability we do, of refering to the chapter number some
+        other bookmark is in. As a result, cross-references to chapter
+        numbers in a word document will be cross-references to a numbered
+        paragraph, being the chapter heading paragraph. As it happens, our
+        cross-references to numbered paragraphs will do the right thing
+        when the target is a numbered chapter heading, so there is no need
+        for us to use the REF_CHAPTER bookmark format on import.
+        */
         case 'n':
+            eFormat = REF_NUMBER_NO_CONTEXT;
+            break;
         case 'r':
+            eFormat = REF_NUMBER;
+            break;
         case 'w':
-            bChapterNr = true; // activate flag 'Chapter Number'
+            eFormat = REF_NUMBER_FULL_CONTEXT;
             break;
 
         case 'p':
-            bAboveBelow = true;
+            eFormat = REF_UPDOWN;
             break;
         case 'h':
             break;
@@ -2096,36 +2110,23 @@ eF_ResT SwWW8ImplReader::Read_F_Ref( WW8FieldDesc*, String& rStr )
 
     String sBkmName(GetMappedBookmark(sOrigBkmName));
 
-    if (!bAboveBelow || bChapterNr)
+    SwGetRefField aFld(
+        (SwGetRefFieldType*)rDoc.GetSysFldType( RES_GETREFFLD ),
+        sBkmName,REF_BOOKMARK,0,eFormat);
+
+    if (eFormat == REF_CONTENT)
     {
-        if (bChapterNr)
-        {
-            SwGetRefField aFld(
-                (SwGetRefFieldType*)rDoc.GetSysFldType( RES_GETREFFLD ),
-                sBkmName,REF_BOOKMARK,0,REF_CHAPTER);
-            rDoc.InsertPoolItem( *pPaM, SwFmtFld( aFld ), 0 );
-        }
-        else
-        {
-            /*
-            If we are just inserting the contents of the bookmark, then it
-            is possible that the bookmark is actually a variable, so we
-            must store it until the end of the document to see if it was,
-            in which case we'll turn it into a show variable
-            */
-            SwGetRefField aFld(
-                (SwGetRefFieldType*)rDoc.GetSysFldType( RES_GETREFFLD ),
-                sBkmName,REF_BOOKMARK,0,REF_CONTENT);
-            pReffingStck->NewAttr( *pPaM->GetPoint(), SwFmtFld(aFld) );
-            pReffingStck->SetAttr( *pPaM->GetPoint(), RES_TXTATR_FIELD);
-        }
+        /*
+        If we are just inserting the contents of the bookmark, then it
+        is possible that the bookmark is actually a variable, so we
+        must store it until the end of the document to see if it was,
+        in which case we'll turn it into a show variable
+        */
+        pReffingStck->NewAttr( *pPaM->GetPoint(), SwFmtFld(aFld) );
+        pReffingStck->SetAttr( *pPaM->GetPoint(), RES_TXTATR_FIELD);
     }
-
-    if( bAboveBelow )
+    else
     {
-        SwGetRefField aFld( (SwGetRefFieldType*)
-            rDoc.GetSysFldType( RES_GETREFFLD ), sBkmName, REF_BOOKMARK, 0,
-            REF_UPDOWN );
         rDoc.InsertPoolItem(*pPaM, SwFmtFld(aFld), 0);
     }
     return FLD_OK;
commit 7e631b61607ddd821d9b3a688ff769bde45a4b2c
Author: Troy Rollo <libreoffice at troy.rollo.name>
Date:   Mon Jul 11 23:02:20 2011 +1000

    fdo#33960, Implement new rule for xref to numbered paragraphs

diff --git a/sw/inc/numrule.hxx b/sw/inc/numrule.hxx
index 35bc168..4401df3 100644
--- a/sw/inc/numrule.hxx
+++ b/sw/inc/numrule.hxx
@@ -105,6 +105,13 @@ class SW_DLLPUBLIC SwNumRule
 public:
     typedef std::vector< SwTxtNode* > tTxtNodeList;
     typedef std::vector< SwTxtFmtColl* > tParagraphStyleList;
+
+    struct Extremities
+    {
+        sal_uInt16 nPrefixChars;
+        sal_uInt16 nSuffixChars;
+    };
+
 private:
     friend void _FinitCore();
 
@@ -171,7 +178,8 @@ public:
     String MakeNumString( const SwNumberTree::tNumberVector & rNumVector,
                           const sal_Bool bInclStrings = sal_True,
                           const sal_Bool bOnlyArabic = sal_False,
-                          const unsigned int _nRestrictToThisLevel = MAXLEVEL ) const;
+                          const unsigned int _nRestrictToThisLevel = MAXLEVEL,
+                          Extremities* pExtremities = 0 ) const;
     String MakeRefNumString( const SwNodeNum& rNodeNum,
                              const bool bInclSuperiorNumLabels = false,
                              const sal_uInt8 nRestrictInclToThisLevel = 0 ) const;
diff --git a/sw/source/core/doc/number.cxx b/sw/source/core/doc/number.cxx
index b9f0818..112ffd5 100644
--- a/sw/source/core/doc/number.cxx
+++ b/sw/source/core/doc/number.cxx
@@ -671,12 +671,16 @@ String SwNumRule::MakeNumString( const SwNodeNum& rNum, sal_Bool bInclStrings,
 String SwNumRule::MakeNumString( const SwNumberTree::tNumberVector & rNumVector,
                                  const sal_Bool bInclStrings,
                                  const sal_Bool bOnlyArabic,
-                                 const unsigned int _nRestrictToThisLevel ) const
+                                 const unsigned int _nRestrictToThisLevel,
+                                 SwNumRule::Extremities* pExtremities ) const
 {
     String aStr;
 
     unsigned int nLevel = rNumVector.size() - 1;
 
+    if ( pExtremities )
+        pExtremities->nPrefixChars = pExtremities->nSuffixChars = 0;
+
     if ( nLevel > _nRestrictToThisLevel )
     {
         nLevel = _nRestrictToThisLevel;
@@ -734,8 +738,16 @@ String SwNumRule::MakeNumString( const SwNumberTree::tNumberVector & rNumVector,
                 SVX_NUM_CHAR_SPECIAL != rMyNFmt.GetNumberingType() &&
                 SVX_NUM_BITMAP != rMyNFmt.GetNumberingType() )
             {
-                aStr.Insert( rMyNFmt.GetPrefix(), 0 );
-                aStr += rMyNFmt.GetSuffix();
+                String const &rPrefix = rMyNFmt.GetPrefix();
+                String const &rSuffix = rMyNFmt.GetSuffix();
+
+                aStr.Insert( rPrefix, 0 );
+                aStr += rSuffix;
+                if ( pExtremities )
+                {
+                    pExtremities->nPrefixChars = rPrefix.Len();
+                    pExtremities->nSuffixChars = rSuffix.Len();
+                }
             }
         }
     }
@@ -752,6 +764,8 @@ String SwNumRule::MakeRefNumString( const SwNodeNum& rNodeNum,
 
     if ( rNodeNum.GetLevelInListTree() >= 0 )
     {
+        sal_Bool bOldHadPrefix = sal_True;
+
         const SwNodeNum* pWorkingNodeNum( &rNodeNum );
         do
         {
@@ -768,11 +782,45 @@ String SwNumRule::MakeRefNumString( const SwNodeNum& rNodeNum,
                    pWorkingNodeNum->GetTxtNode() &&
                    pWorkingNodeNum->GetTxtNode()->HasNumber() ) )
             {
-                aRefNumStr.Insert( MakeNumString( pWorkingNodeNum->GetNumberVector() ), 0 );
+                Extremities aExtremities;
+                String aPrevStr = MakeNumString( pWorkingNodeNum->GetNumberVector(),
+                                                 sal_True, sal_False, MAXLEVEL,
+                                                 &aExtremities);
+                int        nLen = aPrevStr.Len();
+                int        nStrip = 0;
+                sal_Unicode        c;
+
+
+                while ( nStrip < aExtremities.nPrefixChars &&
+                       ( '\t' == ( c = aPrevStr.GetChar( nStrip ) ) ||
+                         ' ' == c) )
+                {
+                        ++nStrip;
+                }
+
+                if (nStrip)
+                {
+                        aPrevStr.Erase( 0, nStrip );
+                        aExtremities.nPrefixChars -= nStrip;
+                        nLen -= nStrip;
+                }
+
+                if ( bOldHadPrefix &&
+                     aExtremities.nSuffixChars &&
+                     !aExtremities.nPrefixChars
+                   )
+                {
+                        aPrevStr.Erase( nLen - aExtremities.nSuffixChars, aExtremities.nSuffixChars );
+                }
+                bOldHadPrefix = ( aExtremities.nPrefixChars >  0);
+
+                aRefNumStr.Insert( aPrevStr, 0 );
+
             }
             else if ( aRefNumStr.Len() > 0 )
             {
                 aRefNumStr.Insert( String::CreateFromAscii(" "), 0 );
+                bOldHadPrefix = true;
             }
 
             if ( bInclSuperiorNumLabels && pWorkingNodeNum->GetLevelInListTree() > 0 )


More information about the Libreoffice-commits mailing list