summaryrefslogtreecommitdiff
path: root/writerfilter/source/dmapper/PageBordersHandler.cxx
blob: ae607199f588a298de9cfc35f3e79d45494939dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
#include "PageBordersHandler.hxx"

#include <ooxml/resourceids.hxx>

namespace writerfilter {
namespace dmapper {

_PgBorder::_PgBorder( ) :
    m_nDistance( 0 ),
    m_ePos( BORDER_RIGHT )
{
}

_PgBorder::~_PgBorder( )
{
}

PageBordersHandler::PageBordersHandler( ) :
    m_nDisplay( 0 ),
    m_nOffset( 0 )
{
}

PageBordersHandler::~PageBordersHandler( )
{
}

void PageBordersHandler::attribute( Id eName, Value& rVal )
{
    int nIntValue = rVal.getInt( );
    switch ( eName )
    {
        case NS_ooxml::LN_CT_PageBorders_display:
        {
            switch ( nIntValue )
            {
                default:
                case NS_ooxml::LN_Value_wordprocessingml_ST_PageBorderDisplay_allPages:
                    m_nDisplay = 0;
                    break;
                case NS_ooxml::LN_Value_wordprocessingml_ST_PageBorderDisplay_firstPage:
                    m_nDisplay = 1;
                    break;
                case NS_ooxml::LN_Value_wordprocessingml_ST_PageBorderDisplay_notFirstPage:
                    m_nDisplay = 2;
                    break;
            }
        }
        break;
        case NS_ooxml::LN_CT_PageBorders_offsetFrom:
        {
            switch ( nIntValue )
            {
                default:
                case NS_ooxml::LN_Value_wordprocessingml_ST_PageBorderOffset_page:
                    m_nOffset = 1;
                    break;
                case NS_ooxml::LN_Value_wordprocessingml_ST_PageBorderOffset_text:
                    m_nOffset = 0;
                    break;
            }
        }
        break;
        default:;
    }
}

void PageBordersHandler::sprm( Sprm& rSprm )
{
    switch ( rSprm.getId( ) )
    {
        case NS_ooxml::LN_CT_PageBorders_top:
        case NS_ooxml::LN_CT_PageBorders_left:
        case NS_ooxml::LN_CT_PageBorders_bottom:
        case NS_ooxml::LN_CT_PageBorders_right:
        {
            writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
            if( pProperties.get())
            {
                BorderHandlerPtr pBorderHandler( new BorderHandler( true ) );
                pProperties->resolve(*pBorderHandler);
                BorderPosition ePos = BorderPosition( 0 );
                switch( rSprm.getId( ) )
                {
                    case NS_ooxml::LN_CT_PageBorders_top:
                        ePos = BORDER_TOP;
                    break;
                    case NS_ooxml::LN_CT_PageBorders_left:
                        ePos = BORDER_LEFT;
                    break;
                    case NS_ooxml::LN_CT_PageBorders_bottom:
                        ePos = BORDER_BOTTOM;
                    break;
                    case NS_ooxml::LN_CT_PageBorders_right:
                        ePos = BORDER_RIGHT;
                    break;
                    default:;
                }

                _PgBorder aPgBorder;
                aPgBorder.m_rLine = pBorderHandler->getBorderLine( );
                aPgBorder.m_nDistance = pBorderHandler->getLineDistance( );
                aPgBorder.m_ePos = ePos;
                m_aBorders.push_back( aPgBorder );
            }
        }
        break;
        default:;
    }
}

void PageBordersHandler::SetBorders( SectionPropertyMap* pSectContext )
{
    for ( int i = 0, length = m_aBorders.size( ); i < length; i++ )
    {
        _PgBorder aBorder = m_aBorders[i];
        pSectContext->SetBorder( aBorder.m_ePos, aBorder.m_nDistance, aBorder.m_rLine );
    }
}

} }

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */