<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: wrtw8num.cxx,v $
 *
 *  $Revision: 1.38 $
 *
 *  last change: $Author: obo $ $Date: 2006-09-16 22:21:43 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sw.hxx"

/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil -*- */


#ifndef _HINTIDS_HXX
#include <hintids.hxx>
#endif

#ifndef _SV_FONT_HXX //autogen
#include <vcl/font.hxx>
#endif
#ifndef _SVX_FONTITEM_HXX //autogen
#include <svx/fontitem.hxx>
#endif
#ifndef _SVX_LRSPITEM_HXX //autogen wg. SvxLRSpaceItem
#include <svx/lrspitem.hxx>
#endif

#ifndef _DOC_HXX //autogen
#include <doc.hxx>
#endif
#ifndef _DOCARY_HXX //autogen
#include <docary.hxx>
#endif
#ifndef _NUMRULE_HXX //autogen
#include <numrule.hxx>
#endif
#ifndef _PARATR_HXX //autogen
#include <paratr.hxx>
#endif
#ifndef _CHARFMT_HXX //autogen
#include <charfmt.hxx>
#endif
#ifndef _NDTXT_HXX //autogen wg. SwTxtNode
#include <ndtxt.hxx>
#endif
#ifndef _COM_SUN_STAR_I18N_SCRIPTTYPE_HDL_
#include <com/sun/star/i18n/ScriptType.hdl>
#endif

#ifndef SW_WRITERHELPER
#include "writerhelper.hxx"
#endif
#ifndef SW_WRITERWORDGLUE
#include "writerwordglue.hxx"
#endif

#ifndef _WRTWW8_HXX
#include "wrtww8.hxx"
#endif
#ifndef _WW8PAR_HXX
#include "ww8par.hxx"
#endif

//#define DUMPSYMBOLS
#ifdef DUMPSYMBOLS
#include <fstream>
#endif

using namespace ::com::sun::star::i18n;
using namespace sw::types;
using namespace sw::util;

USHORT SwWW8Writer::DupNumRuleWithLvlStart(const SwNumRule *pRule,BYTE nLvl,
    USHORT nVal)
{
    //List is set to restart at a particular value so for export make a
    //completely new list based on this one and export that instead,
    //which duplicates words behaviour in this respect.
    USHORT nNumId = USHRT_MAX;
    String sPrefix(CREATE_CONST_ASC("WW8TempExport"));
    sPrefix += String::CreateFromInt32( nUniqueList++ );
    SwNumRule* pMyNumRule = new SwNumRule(pDoc->GetUniqueNumRuleName(&sPrefix));
    pUsedNumTbl->Insert( pMyNumRule, pUsedNumTbl->Count() );

    for (int i=0;i<MAXLEVEL;i++)
    {
        const SwNumFmt& rSubRule = pRule->Get(i);
        pMyNumRule->Set( i, rSubRule );
    }

    SwNumFmt aNumFmt(pMyNumRule->Get(nLvl));
    aNumFmt.SetStart(nVal);
    pMyNumRule->Set(nLvl,aNumFmt);

    nNumId = GetId( *pMyNumRule );

    //Map the old list to our new list
    aRuleDuplicates[GetId(*pRule)] = nNumId;

    return nNumId;
}

USHORT SwWW8Writer::GetId( const SwNumRule& rNumRule ) const
{
    if( !pUsedNumTbl )
    {
        SwWW8Writer* pThis = (SwWW8Writer*)this;
        pThis->pUsedNumTbl = new SwNumRuleTbl;
        pThis->pUsedNumTbl->Insert( &pDoc->GetNumRuleTbl(), 0 );
        // --> OD 2005-10-17 #126238# - Check, if the outline rule is
        // already inserted into <pUsedNumTbl>. If yes, do not insert it again.
        bool bOutlineRuleAdded( false );
        for( USHORT n = pUsedNumTbl->Count(); n; )
        {
            const SwNumRule& rRule = *pUsedNumTbl->GetObject( --n );
            if ( !pDoc->IsUsed( rRule ) )
            {
                pThis->pUsedNumTbl->Remove( n );
            }
            else if ( &rRule == pDoc->GetOutlineNumRule() )
            {
                bOutlineRuleAdded = true;
            }
        }

        if ( !bOutlineRuleAdded )
        {
            // jetzt noch die OutlineRule einfuegen
            SwNumRule* pR = (SwNumRule*)pDoc->GetOutlineNumRule();
            pThis->pUsedNumTbl->Insert( pR, pUsedNumTbl->Count() );
        }
        // <--
    }
    SwNumRule* p = (SwNumRule*)&rNumRule;
    USHORT nRet = pUsedNumTbl->GetPos(p);

    //Is this list now duplicated into a new list which we should use
    ::std::map<USHORT,USHORT>::const_iterator aResult =
        aRuleDuplicates.find(nRet);
    if (aResult != aRuleDuplicates.end())
        nRet = (*aResult).second;

    return nRet;
}

//GetFirstLineOffset should problem never appear unadorned apart from
//here in the ww export filter
sal_Int16 GetWordFirstLineOffset(const SwNumFmt &rFmt)
{
    short nFirstLineOffset;
    if (rFmt.GetNumAdjust() == SVX_ADJUST_RIGHT)
        nFirstLineOffset = -rFmt.GetCharTextDistance();
    else
        nFirstLineOffset = rFmt.GetFirstLineOffset();
    return nFirstLineOffset;
}

void SwWW8Writer::OutListTab()
{
    if( !pUsedNumTbl )
        return ;            // no numbering is used

    USHORT nCount = pUsedNumTbl->Count();
    USHORT n;

    pFib->fcPlcfLst = pTableStrm->Tell();
    SwWW8Writer::WriteShort( *pTableStrm, nCount );<commit_msg>INTEGRATION: CWS ww8export02_SRC680 (1.38.330); FILE MERGED 2007/05/30 07:31:57 od 1.38.330.1: #i77812# method SwWW8Writer::GetId(..)> 	 - perform 'deep' search in list style duplication map in order to 	   consider the case that a certain list is restarted more than once.<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: wrtw8num.cxx,v $
 *
 *  $Revision: 1.39 $
 *
 *  last change: $Author: ihi $ $Date: 2007-06-04 14:02:49 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sw.hxx"

/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil -*- */


#ifndef _HINTIDS_HXX
#include <hintids.hxx>
#endif

#ifndef _SV_FONT_HXX //autogen
#include <vcl/font.hxx>
#endif
#ifndef _SVX_FONTITEM_HXX //autogen
#include <svx/fontitem.hxx>
#endif
#ifndef _SVX_LRSPITEM_HXX //autogen wg. SvxLRSpaceItem
#include <svx/lrspitem.hxx>
#endif

#ifndef _DOC_HXX //autogen
#include <doc.hxx>
#endif
#ifndef _DOCARY_HXX //autogen
#include <docary.hxx>
#endif
#ifndef _NUMRULE_HXX //autogen
#include <numrule.hxx>
#endif
#ifndef _PARATR_HXX //autogen
#include <paratr.hxx>
#endif
#ifndef _CHARFMT_HXX //autogen
#include <charfmt.hxx>
#endif
#ifndef _NDTXT_HXX //autogen wg. SwTxtNode
#include <ndtxt.hxx>
#endif
#ifndef _COM_SUN_STAR_I18N_SCRIPTTYPE_HDL_
#include <com/sun/star/i18n/ScriptType.hdl>
#endif

#ifndef SW_WRITERHELPER
#include "writerhelper.hxx"
#endif
#ifndef SW_WRITERWORDGLUE
#include "writerwordglue.hxx"
#endif

#ifndef _WRTWW8_HXX
#include "wrtww8.hxx"
#endif
#ifndef _WW8PAR_HXX
#include "ww8par.hxx"
#endif

//#define DUMPSYMBOLS
#ifdef DUMPSYMBOLS
#include <fstream>
#endif

using namespace ::com::sun::star::i18n;
using namespace sw::types;
using namespace sw::util;

USHORT SwWW8Writer::DupNumRuleWithLvlStart(const SwNumRule *pRule,BYTE nLvl,
    USHORT nVal)
{
    //List is set to restart at a particular value so for export make a
    //completely new list based on this one and export that instead,
    //which duplicates words behaviour in this respect.
    USHORT nNumId = USHRT_MAX;
    String sPrefix(CREATE_CONST_ASC("WW8TempExport"));
    sPrefix += String::CreateFromInt32( nUniqueList++ );
    SwNumRule* pMyNumRule = new SwNumRule(pDoc->GetUniqueNumRuleName(&sPrefix));
    pUsedNumTbl->Insert( pMyNumRule, pUsedNumTbl->Count() );

    for (int i=0;i<MAXLEVEL;i++)
    {
        const SwNumFmt& rSubRule = pRule->Get(i);
        pMyNumRule->Set( i, rSubRule );
    }

    SwNumFmt aNumFmt(pMyNumRule->Get(nLvl));
    aNumFmt.SetStart(nVal);
    pMyNumRule->Set(nLvl,aNumFmt);

    nNumId = GetId( *pMyNumRule );

    //Map the old list to our new list
    aRuleDuplicates[GetId(*pRule)] = nNumId;

    return nNumId;
}

USHORT SwWW8Writer::GetId( const SwNumRule& rNumRule ) const
{
    if( !pUsedNumTbl )
    {
        SwWW8Writer* pThis = (SwWW8Writer*)this;
        pThis->pUsedNumTbl = new SwNumRuleTbl;
        pThis->pUsedNumTbl->Insert( &pDoc->GetNumRuleTbl(), 0 );
        // --> OD 2005-10-17 #126238# - Check, if the outline rule is
        // already inserted into <pUsedNumTbl>. If yes, do not insert it again.
        bool bOutlineRuleAdded( false );
        for( USHORT n = pUsedNumTbl->Count(); n; )
        {
            const SwNumRule& rRule = *pUsedNumTbl->GetObject( --n );
            if ( !pDoc->IsUsed( rRule ) )
            {
                pThis->pUsedNumTbl->Remove( n );
            }
            else if ( &rRule == pDoc->GetOutlineNumRule() )
            {
                bOutlineRuleAdded = true;
            }
        }

        if ( !bOutlineRuleAdded )
        {
            // jetzt noch die OutlineRule einfuegen
            SwNumRule* pR = (SwNumRule*)pDoc->GetOutlineNumRule();
            pThis->pUsedNumTbl->Insert( pR, pUsedNumTbl->Count() );
        }
        // <--
    }
    SwNumRule* p = (SwNumRule*)&rNumRule;
    USHORT nRet = pUsedNumTbl->GetPos(p);

    //Is this list now duplicated into a new list which we should use
    // --> OD 2007-05-30 #i77812#
    // perform 'deep' search in duplication map
    ::std::map<USHORT,USHORT>::const_iterator aResult = aRuleDuplicates.end();
    do {
        aResult = aRuleDuplicates.find(nRet);
        if ( aResult != aRuleDuplicates.end() )
        {
            nRet = (*aResult).second;
        }
    } while ( aResult != aRuleDuplicates.end() );
    // <--

    return nRet;
}

//GetFirstLineOffset should problem never appear unadorned apart from
//here in the ww export filter
sal_Int16 GetWordFirstLineOffset(const SwNumFmt &rFmt)
{
    short nFirstLineOffset;
    if (rFmt.GetNumAdjust() == SVX_ADJUST_RIGHT)
        nFirstLineOffset = -rFmt.GetCharTextDistance();
    else
        nFirstLineOffset = rFmt.GetFirstLineOffset();
    return nFirstLineOffset;
}

void SwWW8Writer::OutListTab()
{
    if( !pUsedNumTbl )
        return ;            // no numbering is used

    USHORT nCount = pUsedNumTbl->Count();
    USHORT n;

    pFib->fcPlcfLst = pTableStrm->Tell();
    SwWW8Writer::WriteShort( *pTableStrm, nCount );
{'fraction_non_alphanumeric': 0.13871963942909607, 'fraction_numerical': 0.019030131040814625, 'mean_word_length': 3.180739706908583, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 85, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '952795', 'n_tokens_mistral': 4262, 'n_tokens_neox': 4032, 'n_words': 1088}