xref: /AOO41X/main/xmloff/source/text/txtdropi.cxx (revision 63bba73cc51e0afb45f8a8d578158724bb5afee8)
1*63bba73cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*63bba73cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*63bba73cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*63bba73cSAndrew Rist  * distributed with this work for additional information
6*63bba73cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*63bba73cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*63bba73cSAndrew Rist  * "License"); you may not use this file except in compliance
9*63bba73cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*63bba73cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*63bba73cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*63bba73cSAndrew Rist  * software distributed under the License is distributed on an
15*63bba73cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*63bba73cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*63bba73cSAndrew Rist  * specific language governing permissions and limitations
18*63bba73cSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*63bba73cSAndrew Rist  *************************************************************/
21*63bba73cSAndrew Rist 
22*63bba73cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
26cdf0e10cSrcweir #include <com/sun/star/style/DropCapFormat.hpp>
27cdf0e10cSrcweir #include "txtdropi.hxx"
28cdf0e10cSrcweir #include <xmloff/xmltkmap.hxx>
29cdf0e10cSrcweir #include <xmloff/xmluconv.hxx>
30cdf0e10cSrcweir #include <xmloff/nmspmap.hxx>
31cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
32cdf0e10cSrcweir #include <xmloff/xmlimp.hxx>
33cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir using ::rtl::OUString;
36cdf0e10cSrcweir using ::rtl::OUStringBuffer;
37cdf0e10cSrcweir 
38cdf0e10cSrcweir using namespace ::com::sun::star;
39cdf0e10cSrcweir using namespace ::com::sun::star::uno;
40cdf0e10cSrcweir using namespace ::com::sun::star::style;
41cdf0e10cSrcweir using namespace ::xmloff::token;
42cdf0e10cSrcweir 
43cdf0e10cSrcweir 
44cdf0e10cSrcweir enum SvXMLTokenMapDropAttrs
45cdf0e10cSrcweir {
46cdf0e10cSrcweir     XML_TOK_DROP_LINES,
47cdf0e10cSrcweir     XML_TOK_DROP_LENGTH,
48cdf0e10cSrcweir     XML_TOK_DROP_DISTANCE,
49cdf0e10cSrcweir     XML_TOK_DROP_STYLE,
50cdf0e10cSrcweir     XML_TOK_DROP_END=XML_TOK_UNKNOWN
51cdf0e10cSrcweir };
52cdf0e10cSrcweir 
53cdf0e10cSrcweir static __FAR_DATA SvXMLTokenMapEntry aDropAttrTokenMap[] =
54cdf0e10cSrcweir {
55cdf0e10cSrcweir     { XML_NAMESPACE_STYLE, XML_LINES,       XML_TOK_DROP_LINES  },
56cdf0e10cSrcweir     { XML_NAMESPACE_STYLE, XML_LENGTH,      XML_TOK_DROP_LENGTH },
57cdf0e10cSrcweir     { XML_NAMESPACE_STYLE, XML_DISTANCE,    XML_TOK_DROP_DISTANCE   },
58cdf0e10cSrcweir     { XML_NAMESPACE_STYLE, XML_STYLE_NAME,  XML_TOK_DROP_STYLE  },
59cdf0e10cSrcweir     XML_TOKEN_MAP_END
60cdf0e10cSrcweir };
61cdf0e10cSrcweir 
62cdf0e10cSrcweir TYPEINIT1( XMLTextDropCapImportContext, XMLElementPropertyContext );
ProcessAttrs(const Reference<xml::sax::XAttributeList> & xAttrList)63cdf0e10cSrcweir void XMLTextDropCapImportContext::ProcessAttrs(
64cdf0e10cSrcweir         const Reference< xml::sax::XAttributeList >& xAttrList )
65cdf0e10cSrcweir {
66cdf0e10cSrcweir     SvXMLTokenMap aTokenMap( aDropAttrTokenMap );
67cdf0e10cSrcweir 
68cdf0e10cSrcweir     DropCapFormat aFormat;
69cdf0e10cSrcweir     sal_Bool bWholeWord = sal_False;
70cdf0e10cSrcweir 
71cdf0e10cSrcweir     sal_Int32 nTmp;
72cdf0e10cSrcweir     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
73cdf0e10cSrcweir     for( sal_Int16 i=0; i < nAttrCount; i++ )
74cdf0e10cSrcweir     {
75cdf0e10cSrcweir         const OUString& rAttrName = xAttrList->getNameByIndex( i );
76cdf0e10cSrcweir         OUString aLocalName;
77cdf0e10cSrcweir         sal_uInt16 nPrefix =
78cdf0e10cSrcweir             GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
79cdf0e10cSrcweir                                                             &aLocalName );
80cdf0e10cSrcweir         const OUString& rValue = xAttrList->getValueByIndex( i );
81cdf0e10cSrcweir 
82cdf0e10cSrcweir         switch( aTokenMap.Get( nPrefix, aLocalName ) )
83cdf0e10cSrcweir         {
84cdf0e10cSrcweir         case XML_TOK_DROP_LINES:
85cdf0e10cSrcweir             if( GetImport().GetMM100UnitConverter().convertNumber( nTmp, rValue, 0, 255 ) )
86cdf0e10cSrcweir             {
87cdf0e10cSrcweir                 aFormat.Lines = nTmp < 2 ? 0 : (sal_Int8)nTmp;
88cdf0e10cSrcweir             }
89cdf0e10cSrcweir             break;
90cdf0e10cSrcweir 
91cdf0e10cSrcweir         case XML_TOK_DROP_LENGTH:
92cdf0e10cSrcweir             if( IsXMLToken( rValue, XML_WORD ) )
93cdf0e10cSrcweir             {
94cdf0e10cSrcweir                 bWholeWord = sal_True;
95cdf0e10cSrcweir             }
96cdf0e10cSrcweir             else if( GetImport().GetMM100UnitConverter().convertNumber( nTmp, rValue, 1, 255 ) )
97cdf0e10cSrcweir             {
98cdf0e10cSrcweir                 bWholeWord = sal_False;
99cdf0e10cSrcweir                 aFormat.Count = (sal_Int8)nTmp;
100cdf0e10cSrcweir             }
101cdf0e10cSrcweir             break;
102cdf0e10cSrcweir 
103cdf0e10cSrcweir         case XML_TOK_DROP_DISTANCE:
104cdf0e10cSrcweir             if( GetImport().GetMM100UnitConverter().convertMeasure( nTmp, rValue, 0 ) )
105cdf0e10cSrcweir             {
106cdf0e10cSrcweir                 aFormat.Distance = (sal_uInt16)nTmp;
107cdf0e10cSrcweir             }
108cdf0e10cSrcweir             break;
109cdf0e10cSrcweir 
110cdf0e10cSrcweir         case XML_TOK_DROP_STYLE:
111cdf0e10cSrcweir             sStyleName = rValue;
112cdf0e10cSrcweir             break;
113cdf0e10cSrcweir         }
114cdf0e10cSrcweir     }
115cdf0e10cSrcweir 
116cdf0e10cSrcweir     if( aFormat.Lines > 1 && aFormat.Count < 1 )
117cdf0e10cSrcweir         aFormat.Count = 1;
118cdf0e10cSrcweir 
119cdf0e10cSrcweir     aProp.maValue <<= aFormat;
120cdf0e10cSrcweir 
121cdf0e10cSrcweir     aWholeWordProp.maValue.setValue( &bWholeWord, ::getBooleanCppuType() );
122cdf0e10cSrcweir }
123cdf0e10cSrcweir 
XMLTextDropCapImportContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLName,const Reference<xml::sax::XAttributeList> & xAttrList,const XMLPropertyState & rProp,sal_Int32 nWholeWordIdx,::std::vector<XMLPropertyState> & rProps)124cdf0e10cSrcweir XMLTextDropCapImportContext::XMLTextDropCapImportContext(
125cdf0e10cSrcweir         SvXMLImport& rImport, sal_uInt16 nPrfx,
126cdf0e10cSrcweir         const OUString& rLName,
127cdf0e10cSrcweir         const Reference< xml::sax::XAttributeList > & xAttrList,
128cdf0e10cSrcweir         const XMLPropertyState& rProp,
129cdf0e10cSrcweir         sal_Int32 nWholeWordIdx,
130cdf0e10cSrcweir         ::std::vector< XMLPropertyState > &rProps ) :
131cdf0e10cSrcweir     XMLElementPropertyContext( rImport, nPrfx, rLName, rProp, rProps ),
132cdf0e10cSrcweir     aWholeWordProp( nWholeWordIdx )
133cdf0e10cSrcweir {
134cdf0e10cSrcweir     ProcessAttrs( xAttrList );
135cdf0e10cSrcweir }
136cdf0e10cSrcweir 
~XMLTextDropCapImportContext()137cdf0e10cSrcweir XMLTextDropCapImportContext::~XMLTextDropCapImportContext()
138cdf0e10cSrcweir {
139cdf0e10cSrcweir }
140cdf0e10cSrcweir 
EndElement()141cdf0e10cSrcweir void XMLTextDropCapImportContext::EndElement()
142cdf0e10cSrcweir {
143cdf0e10cSrcweir     SetInsert( sal_True );
144cdf0e10cSrcweir     XMLElementPropertyContext::EndElement();
145cdf0e10cSrcweir 
146cdf0e10cSrcweir     if( -1 != aWholeWordProp.mnIndex )
147cdf0e10cSrcweir         rProperties.push_back( aWholeWordProp );
148cdf0e10cSrcweir }
149cdf0e10cSrcweir 
150cdf0e10cSrcweir 
151