[Libreoffice] [PATCH][PUSHED]Fix 33898 - import/export xrefs to numbered paras

Cedric Bosdonnat cedric.bosdonnat.ooo at free.fr
Wed Aug 10 01:22:36 PDT 2011


Hi Troy,

Your patch looks good to me, but it seems the bug number is wrong in the
title: isn't it fdo#33960? I pushed your patch to master, but I'm
wondering if you have some sample documents to help us test it more
intensively...

Thanks for your patch!

On Mon, 2011-07-18 at 00:54 +1000, Troy Rollo wrote:
> ---
>  sw/source/filter/rtf/rtffld.cxx  |   50 ++++++++++++-----------------
>  sw/source/filter/ww8/ww8atr.cxx  |   12 +++++++
>  sw/source/filter/ww8/ww8par5.cxx |   63 +++++++++++++++++++------------------
>  3 files changed, 65 insertions(+), 60 deletions(-)
> 
> diff --git a/sw/source/filter/rtf/rtffld.cxx b/sw/source/filter/rtf/rtffld.cxx
> index f5d9058..ccac5f1 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 0ea9201..1464e42 100644
> --- a/sw/source/filter/ww8/ww8atr.cxx
> +++ b/sw/source/filter/ww8/ww8atr.cxx
> @@ -2831,6 +2831,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 759293d..62d73b6 100644
> --- a/sw/source/filter/ww8/ww8par5.cxx
> +++ b/sw/source/filter/ww8/ww8par5.cxx
> @@ -2089,8 +2089,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 );
> @@ -2102,14 +2101,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;
> @@ -2121,36 +2135,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;

-- 
Cédric Bosdonnat
LibreOffice hacker
http://documentfoundation.org
OOo Eclipse Integration developer
http://cedric.bosdonnat.free.fr



More information about the LibreOffice mailing list