<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: winmtf.cxx,v $
 *
 *  $Revision: 1.44 $
 *
 *  last change: $Author: hr $ $Date: 2005-09-23 13:39:44 $
 *
 *  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
 *
 ************************************************************************/


#include "winmtf.hxx"
#include <vcl/metaact.hxx>
#ifndef _SV_METRIC_HXX
#include <vcl/metric.hxx>
#endif
#ifndef _RTL_TENCINFO_H
#include <rtl/tencinfo.h>
#endif

// ------------------------------------------------------------------------

#define WIN_MTF_MAX_POLYPOLYCOUNT   16

void WinMtfClipPath::ImpUpdateType()
{
    if ( !aPolyPoly.Count() )
        eType = EMPTY;
    else if ( aPolyPoly.IsRect() )
        eType = RECTANGLE;
    else
        eType = COMPLEX;

    bNeedsUpdate = sal_True;
}

void WinMtfClipPath::IntersectClipRect( const Rectangle& rRect )
{
    if ( !aPolyPoly.Count() )
        aPolyPoly = Polygon( rRect );
    else if ( aPolyPoly.Count() < WIN_MTF_MAX_POLYPOLYCOUNT )
    {
        Polygon aPolygon( rRect );
        PolyPolygon aIntersection;
        PolyPolygon aPolyPolyRect( aPolygon );
        aPolyPoly.GetIntersection( aPolyPolyRect, aIntersection );
        aPolyPoly = aIntersection;
    }
    ImpUpdateType();
}

void WinMtfClipPath::ExcludeClipRect( const Rectangle& rRect )
{
    if ( aPolyPoly.Count() && ( aPolyPoly.Count() < WIN_MTF_MAX_POLYPOLYCOUNT ) )
    {
        Polygon aPolygon( rRect );
        PolyPolygon aPolyPolyRect( aPolygon );
        PolyPolygon aDifference;
        aPolyPoly.GetDifference( aPolyPolyRect, aDifference );
        aPolyPoly = aDifference;
    }
    ImpUpdateType();
}

void WinMtfClipPath::SetClipPath( const PolyPolygon& rPolyPolygon, sal_Int32 nClippingMode )
{
    if ( !rPolyPolygon.Count() )
        aPolyPoly = rPolyPolygon;
    else if ( rPolyPolygon.Count() < WIN_MTF_MAX_POLYPOLYCOUNT )
    {
        PolyPolygon aNewClipPath;

        // #115345# Watch out for empty aPolyPoly here - conceptually,
        // an empty clip path is a rectangle of infinite size, but it
        // is represented by an empty aPolyPoly. When intersecting
        // rPolyPolygon with this _empty_ aPolyPoly, set algebra
        // guarantees wrong results.
        switch ( nClippingMode )
        {
            case RGN_OR :
                // #115345# clip stays empty, when ORing an arbitrary
                // rPolyPolygon. Thus, we can save us the unnecessary
                // clipper call.
                if( aPolyPoly.Count() )
                    aPolyPoly.GetUnion( rPolyPolygon, aNewClipPath );
            break;
            case RGN_XOR :
                // TODO:
                // #115345# Cannot handle this case, for the time being
                aPolyPoly.GetXOR( rPolyPolygon, aNewClipPath );
            break;
            case RGN_DIFF :
                // TODO:
                // #115345# Cannot handle this case, for the time being
                aPolyPoly.GetDifference( rPolyPolygon, aNewClipPath );
            break;
            case RGN_AND :
                // #115345# Clip becomes rPolyPolygon, when ANDing
                // with an arbitrary rPolyPolygon
                if( aPolyPoly.Count() )
                    aPolyPoly.GetIntersection( rPolyPolygon, aNewClipPath );
                else
                    aNewClipPath = rPolyPolygon;
            break;
            case RGN_COPY :
                aNewClipPath = rPolyPolygon;
            break;
        }
        aPolyPoly = aNewClipPath;
    }
    ImpUpdateType();
}

void WinMtfClipPath::MoveClipRegion( const Size& rSize )
{
    aPolyPoly.Move( rSize.Width(), rSize.Height() );
    bNeedsUpdate = sal_True;
}

// ------------------------------------------------------------------------

void WinMtfPathObj::AddPoint( const Point& rPoint )
{
    if ( bClosed )
        Insert( Polygon(), POLYPOLY_APPEND );
    Polygon& rPoly = ((PolyPolygon&)*this)[ Count() - 1 ];
    rPoly.Insert( rPoly.GetSize(), rPoint, POLY_NORMAL );
    bClosed = sal_False;
}

void WinMtfPathObj::AddPolyLine( const Polygon& rPolyLine )
{
    if ( bClosed )
        Insert( Polygon(), POLYPOLY_APPEND );
    Polygon& rPoly = ((PolyPolygon&)*this)[ Count() - 1 ];
    rPoly.Insert( rPoly.GetSize(), rPolyLine );
    bClosed = sal_False;
}

void WinMtfPathObj::AddPolygon( const Polygon& rPoly )
{
    Insert( rPoly, POLYPOLY_APPEND );
    bClosed = sal_True;
}

void WinMtfPathObj::AddPolyPolygon( const PolyPolygon& rPolyPoly )
{
    sal_uInt16 i, nCount = rPolyPoly.Count();
    for ( i = 0; i < nCount; i++ )
        Insert( rPolyPoly[ i ], POLYPOLY_APPEND );
    bClosed = sal_True;
}

void WinMtfPathObj::ClosePath()
{
    if ( Count() )
    {
        Polygon& rPoly = ((PolyPolygon&)*this)[ Count() - 1 ];
        if ( rPoly.GetSize() > 2 )
        {
            Point aFirst( rPoly[ 0 ] );
            if ( aFirst != rPoly[ rPoly.GetSize() - 1 ] )
                rPoly.Insert( rPoly.GetSize(), aFirst, POLY_NORMAL );
        }
    }
    bClosed = sal_True;
}

// ------------------------------------------------------------------------

WinMtfFontStyle::WinMtfFontStyle( LOGFONTW& rFont )
{
    CharSet eCharSet;
    if ( ( rFont.lfCharSet == OEM_CHARSET ) || ( rFont.lfCharSet == DEFAULT_CHARSET ) )
        eCharSet = gsl_getSystemTextEncoding();
    else
        eCharSet = rtl_getTextEncodingFromWindowsCharset( rFont.lfCharSet );
    if ( eCharSet == RTL_TEXTENCODING_DONTKNOW )
        eCharSet = gsl_getSystemTextEncoding();
    aFont.SetCharSet( eCharSet );
    aFont.SetName( rFont.alfFaceName );
    FontFamily eFamily;
    switch ( rFont.lfPitchAndFamily & 0xf0 )
    {
        case FF_ROMAN:
            eFamily = FAMILY_ROMAN;
        break;

        case FF_SWISS:
            eFamily = FAMILY_SWISS;
        break;

        case FF_MODERN:
            eFamily = FAMILY_MODERN;
        break;

        case FF_SCRIPT:
            eFamily = FAMILY_SCRIPT;
        break;

        case FF_DECORATIVE:
             eFamily = FAMILY_DECORATIVE;
        break;

        default:
            eFamily = FAMILY_DONTKNOW;
        break;
    }
    aFont.SetFamily( eFamily );

    FontPitch ePitch;
    switch ( rFont.lfPitchAndFamily & 0x0f )
    {
        case FIXED_PITCH:
            ePitch = PITCH_FIXED;
        break;

        case DEFAULT_PITCH:
        case VARIABLE_PITCH:
        default:
            ePitch = PITCH_VARIABLE;
        break;
    }
    aFont.SetPitch( ePitch );

    FontWeight eWeight;
    if( rFont.lfWeight <= FW_THIN )
        eWeight = WEIGHT_THIN;
    else if( rFont.lfWeight <= FW_ULTRALIGHT )
        eWeight = WEIGHT_ULTRALIGHT;
    else if( rFont.lfWeight <= FW_LIGHT )
        eWeight = WEIGHT_LIGHT;
    else if( rFont.lfWeight <  FW_MEDIUM )
        eWeight = WEIGHT_NORMAL;
    else if( rFont.lfWeight == FW_MEDIUM )
        eWeight = WEIGHT_MEDIUM;
    else if( rFont.lfWeight <= FW_SEMIBOLD )
        eWeight = WEIGHT_SEMIBOLD;
    else if( rFont.lfWeight <= FW_BOLD )
        eWeight = WEIGHT_BOLD;
    else if( rFont.lfWeight <= FW_ULTRABOLD )
        eWeight = WEIGHT_ULTRABOLD;
    else
        eWeight = WEIGHT_BLACK;
    aFont.SetWeight( eWeight );

    if( rFont.lfItalic )
        aFont.SetItalic( ITALIC_NORMAL );

    if( rFont.lfUnderline )
        aFont.SetUnderline( UNDERLINE_SINGLE );

    if( rFont.lfStrikeOut )
        aFont.SetStrikeout( STRIKEOUT_SINGLE );

    if ( rFont.lfOrientation )
        aFont.SetOrientation( (short)rFont.lfOrientation );
    else
        aFont.SetOrientation( (short)rFont.lfEscapement );

    Size  aFontSize( Size( rFont.lfWidth, rFont.lfHeight ) );
    if ( rFont.lfHeight > 0 )
    {
        // converting the cell height into a font height
        VirtualDevice aVDev;
        aFont.SetSize( aFontSize );
        aVDev.SetFont( aFont );
        FontMetric aMetric( aVDev.GetFontMetric() );
        long nHeight = aMetric.GetAscent() + aMetric.GetDescent();
        if ( nHeight )
        {
            double fHeight = ((double)aFontSize.Height() * rFont.lfHeight ) / nHeight;
            aFontSize.Height() = (sal_Int32)( fHeight + 0.5 );
        }
    }
    else if ( aFontSize.Height() < 0 )
        aFontSize.Height() *= -1;

    aFont.SetSize( aFontSize );
};
<commit_msg>INTEGRATION: CWS sj23 (1.42.30); FILE MERGED 2005/08/10 13:06:27 sj 172.16.58.3: #i52860# fixed fontwidth aspect ratio problem<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: winmtf.cxx,v $
 *
 *  $Revision: 1.45 $
 *
 *  last change: $Author: hr $ $Date: 2005-09-28 11:28:52 $
 *
 *  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
 *
 ************************************************************************/


#include "winmtf.hxx"
#include <vcl/metaact.hxx>
#ifndef _SV_METRIC_HXX
#include <vcl/metric.hxx>
#endif
#ifndef _RTL_TENCINFO_H
#include <rtl/tencinfo.h>
#endif

// ------------------------------------------------------------------------

#define WIN_MTF_MAX_POLYPOLYCOUNT   16

void WinMtfClipPath::ImpUpdateType()
{
    if ( !aPolyPoly.Count() )
        eType = EMPTY;
    else if ( aPolyPoly.IsRect() )
        eType = RECTANGLE;
    else
        eType = COMPLEX;

    bNeedsUpdate = sal_True;
}

void WinMtfClipPath::IntersectClipRect( const Rectangle& rRect )
{
    if ( !aPolyPoly.Count() )
        aPolyPoly = Polygon( rRect );
    else if ( aPolyPoly.Count() < WIN_MTF_MAX_POLYPOLYCOUNT )
    {
        Polygon aPolygon( rRect );
        PolyPolygon aIntersection;
        PolyPolygon aPolyPolyRect( aPolygon );
        aPolyPoly.GetIntersection( aPolyPolyRect, aIntersection );
        aPolyPoly = aIntersection;
    }
    ImpUpdateType();
}

void WinMtfClipPath::ExcludeClipRect( const Rectangle& rRect )
{
    if ( aPolyPoly.Count() && ( aPolyPoly.Count() < WIN_MTF_MAX_POLYPOLYCOUNT ) )
    {
        Polygon aPolygon( rRect );
        PolyPolygon aPolyPolyRect( aPolygon );
        PolyPolygon aDifference;
        aPolyPoly.GetDifference( aPolyPolyRect, aDifference );
        aPolyPoly = aDifference;
    }
    ImpUpdateType();
}

void WinMtfClipPath::SetClipPath( const PolyPolygon& rPolyPolygon, sal_Int32 nClippingMode )
{
    if ( !rPolyPolygon.Count() )
        aPolyPoly = rPolyPolygon;
    else if ( rPolyPolygon.Count() < WIN_MTF_MAX_POLYPOLYCOUNT )
    {
        PolyPolygon aNewClipPath;

        // #115345# Watch out for empty aPolyPoly here - conceptually,
        // an empty clip path is a rectangle of infinite size, but it
        // is represented by an empty aPolyPoly. When intersecting
        // rPolyPolygon with this _empty_ aPolyPoly, set algebra
        // guarantees wrong results.
        switch ( nClippingMode )
        {
            case RGN_OR :
                // #115345# clip stays empty, when ORing an arbitrary
                // rPolyPolygon. Thus, we can save us the unnecessary
                // clipper call.
                if( aPolyPoly.Count() )
                    aPolyPoly.GetUnion( rPolyPolygon, aNewClipPath );
            break;
            case RGN_XOR :
                // TODO:
                // #115345# Cannot handle this case, for the time being
                aPolyPoly.GetXOR( rPolyPolygon, aNewClipPath );
            break;
            case RGN_DIFF :
                // TODO:
                // #115345# Cannot handle this case, for the time being
                aPolyPoly.GetDifference( rPolyPolygon, aNewClipPath );
            break;
            case RGN_AND :
                // #115345# Clip becomes rPolyPolygon, when ANDing
                // with an arbitrary rPolyPolygon
                if( aPolyPoly.Count() )
                    aPolyPoly.GetIntersection( rPolyPolygon, aNewClipPath );
                else
                    aNewClipPath = rPolyPolygon;
            break;
            case RGN_COPY :
                aNewClipPath = rPolyPolygon;
            break;
        }
        aPolyPoly = aNewClipPath;
    }
    ImpUpdateType();
}

void WinMtfClipPath::MoveClipRegion( const Size& rSize )
{
    aPolyPoly.Move( rSize.Width(), rSize.Height() );
    bNeedsUpdate = sal_True;
}

// ------------------------------------------------------------------------

void WinMtfPathObj::AddPoint( const Point& rPoint )
{
    if ( bClosed )
        Insert( Polygon(), POLYPOLY_APPEND );
    Polygon& rPoly = ((PolyPolygon&)*this)[ Count() - 1 ];
    rPoly.Insert( rPoly.GetSize(), rPoint, POLY_NORMAL );
    bClosed = sal_False;
}

void WinMtfPathObj::AddPolyLine( const Polygon& rPolyLine )
{
    if ( bClosed )
        Insert( Polygon(), POLYPOLY_APPEND );
    Polygon& rPoly = ((PolyPolygon&)*this)[ Count() - 1 ];
    rPoly.Insert( rPoly.GetSize(), rPolyLine );
    bClosed = sal_False;
}

void WinMtfPathObj::AddPolygon( const Polygon& rPoly )
{
    Insert( rPoly, POLYPOLY_APPEND );
    bClosed = sal_True;
}

void WinMtfPathObj::AddPolyPolygon( const PolyPolygon& rPolyPoly )
{
    sal_uInt16 i, nCount = rPolyPoly.Count();
    for ( i = 0; i < nCount; i++ )
        Insert( rPolyPoly[ i ], POLYPOLY_APPEND );
    bClosed = sal_True;
}

void WinMtfPathObj::ClosePath()
{
    if ( Count() )
    {
        Polygon& rPoly = ((PolyPolygon&)*this)[ Count() - 1 ];
        if ( rPoly.GetSize() > 2 )
        {
            Point aFirst( rPoly[ 0 ] );
            if ( aFirst != rPoly[ rPoly.GetSize() - 1 ] )
                rPoly.Insert( rPoly.GetSize(), aFirst, POLY_NORMAL );
        }
    }
    bClosed = sal_True;
}

// ------------------------------------------------------------------------

WinMtfFontStyle::WinMtfFontStyle( LOGFONTW& rFont )
{
    CharSet eCharSet;
    if ( ( rFont.lfCharSet == OEM_CHARSET ) || ( rFont.lfCharSet == DEFAULT_CHARSET ) )
        eCharSet = gsl_getSystemTextEncoding();
    else
        eCharSet = rtl_getTextEncodingFromWindowsCharset( rFont.lfCharSet );
    if ( eCharSet == RTL_TEXTENCODING_DONTKNOW )
        eCharSet = gsl_getSystemTextEncoding();
    aFont.SetCharSet( eCharSet );
    aFont.SetName( rFont.alfFaceName );
    FontFamily eFamily;
    switch ( rFont.lfPitchAndFamily & 0xf0 )
    {
        case FF_ROMAN:
            eFamily = FAMILY_ROMAN;
        break;

        case FF_SWISS:
            eFamily = FAMILY_SWISS;
        break;

        case FF_MODERN:
            eFamily = FAMILY_MODERN;
        break;

        case FF_SCRIPT:
            eFamily = FAMILY_SCRIPT;
        break;

        case FF_DECORATIVE:
             eFamily = FAMILY_DECORATIVE;
        break;

        default:
            eFamily = FAMILY_DONTKNOW;
        break;
    }
    aFont.SetFamily( eFamily );

    FontPitch ePitch;
    switch ( rFont.lfPitchAndFamily & 0x0f )
    {
        case FIXED_PITCH:
            ePitch = PITCH_FIXED;
        break;

        case DEFAULT_PITCH:
        case VARIABLE_PITCH:
        default:
            ePitch = PITCH_VARIABLE;
        break;
    }
    aFont.SetPitch( ePitch );

    FontWeight eWeight;
    if( rFont.lfWeight <= FW_THIN )
        eWeight = WEIGHT_THIN;
    else if( rFont.lfWeight <= FW_ULTRALIGHT )
        eWeight = WEIGHT_ULTRALIGHT;
    else if( rFont.lfWeight <= FW_LIGHT )
        eWeight = WEIGHT_LIGHT;
    else if( rFont.lfWeight <  FW_MEDIUM )
        eWeight = WEIGHT_NORMAL;
    else if( rFont.lfWeight == FW_MEDIUM )
        eWeight = WEIGHT_MEDIUM;
    else if( rFont.lfWeight <= FW_SEMIBOLD )
        eWeight = WEIGHT_SEMIBOLD;
    else if( rFont.lfWeight <= FW_BOLD )
        eWeight = WEIGHT_BOLD;
    else if( rFont.lfWeight <= FW_ULTRABOLD )
        eWeight = WEIGHT_ULTRABOLD;
    else
        eWeight = WEIGHT_BLACK;
    aFont.SetWeight( eWeight );

    if( rFont.lfItalic )
        aFont.SetItalic( ITALIC_NORMAL );

    if( rFont.lfUnderline )
        aFont.SetUnderline( UNDERLINE_SINGLE );

    if( rFont.lfStrikeOut )
        aFont.SetStrikeout( STRIKEOUT_SINGLE );

    if ( rFont.lfOrientation )
        aFont.SetOrientation( (short)rFont.lfOrientation );
    else
        aFont.SetOrientation( (short)rFont.lfEscapement );

    Size  aFontSize( Size( rFont.lfWidth, rFont.lfHeight ) );
    if ( !rFont.lfWidth )
    {
        VirtualDevice aVDev;
        aFont.SetSize( aFontSize );
        aVDev.SetFont( aFont );
        FontMetric aMetric( aVDev.GetFontMetric() );
        aFontSize.Width() = aMetric.GetWidth();
    }
    if ( rFont.lfHeight > 0 )
    {
        // converting the cell height into a font height
        VirtualDevice aVDev;
        aFont.SetSize( aFontSize );
        aVDev.SetFont( aFont );
        FontMetric aMetric( aVDev.GetFontMetric() );
        long nHeight = aMetric.GetAscent() + aMetric.GetDescent();
        if ( nHeight )
        {
            double fHeight = ((double)aFontSize.Height() * rFont.lfHeight ) / nHeight;
            aFontSize.Height() = (sal_Int32)( fHeight + 0.5 );
        }
    }
    else if ( aFontSize.Height() < 0 )
        aFontSize.Height() *= -1;

    aFont.SetSize( aFontSize );
};

{'fraction_non_alphanumeric': 0.13377873638802673, 'fraction_numerical': 0.012625598400757537, 'mean_word_length': 2.1256165734955608, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, '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': '3857067', 'n_tokens_mistral': 6384, 'n_tokens_neox': 5959, 'n_words': 1440}