Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "txtdropi.hxx"
31 : :
32 : : #include <com/sun/star/style/DropCapFormat.hpp>
33 : :
34 : : #include <sax/tools/converter.hxx>
35 : :
36 : : #include <xmloff/xmltkmap.hxx>
37 : : #include <xmloff/xmluconv.hxx>
38 : : #include <xmloff/nmspmap.hxx>
39 : : #include "xmloff/xmlnmspe.hxx"
40 : : #include <xmloff/xmlimp.hxx>
41 : : #include <xmloff/xmltoken.hxx>
42 : :
43 : : using ::rtl::OUString;
44 : : using ::rtl::OUStringBuffer;
45 : :
46 : : using namespace ::com::sun::star;
47 : : using namespace ::com::sun::star::uno;
48 : : using namespace ::com::sun::star::style;
49 : : using namespace ::xmloff::token;
50 : :
51 : :
52 : : enum SvXMLTokenMapDropAttrs
53 : : {
54 : : XML_TOK_DROP_LINES,
55 : : XML_TOK_DROP_LENGTH,
56 : : XML_TOK_DROP_DISTANCE,
57 : : XML_TOK_DROP_STYLE,
58 : : XML_TOK_DROP_END=XML_TOK_UNKNOWN
59 : : };
60 : :
61 : : static SvXMLTokenMapEntry aDropAttrTokenMap[] =
62 : : {
63 : : { XML_NAMESPACE_STYLE, XML_LINES, XML_TOK_DROP_LINES },
64 : : { XML_NAMESPACE_STYLE, XML_LENGTH, XML_TOK_DROP_LENGTH },
65 : : { XML_NAMESPACE_STYLE, XML_DISTANCE, XML_TOK_DROP_DISTANCE },
66 : : { XML_NAMESPACE_STYLE, XML_STYLE_NAME, XML_TOK_DROP_STYLE },
67 : : XML_TOKEN_MAP_END
68 : : };
69 : :
70 [ # # ][ # # ]: 0 : TYPEINIT1( XMLTextDropCapImportContext, XMLElementPropertyContext );
71 : 0 : void XMLTextDropCapImportContext::ProcessAttrs(
72 : : const Reference< xml::sax::XAttributeList >& xAttrList )
73 : : {
74 [ # # ]: 0 : SvXMLTokenMap aTokenMap( aDropAttrTokenMap );
75 : :
76 : 0 : DropCapFormat aFormat;
77 : 0 : sal_Bool bWholeWord = sal_False;
78 : :
79 : : sal_Int32 nTmp;
80 [ # # ][ # # ]: 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
[ # # ]
81 [ # # ]: 0 : for( sal_Int16 i=0; i < nAttrCount; i++ )
82 : : {
83 [ # # ][ # # ]: 0 : const OUString& rAttrName = xAttrList->getNameByIndex( i );
84 : 0 : OUString aLocalName;
85 : : sal_uInt16 nPrefix =
86 : 0 : GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
87 [ # # ]: 0 : &aLocalName );
88 [ # # ][ # # ]: 0 : const OUString& rValue = xAttrList->getValueByIndex( i );
89 : :
90 [ # # ][ # # : 0 : switch( aTokenMap.Get( nPrefix, aLocalName ) )
# # # ]
91 : : {
92 : : case XML_TOK_DROP_LINES:
93 [ # # ][ # # ]: 0 : if (::sax::Converter::convertNumber( nTmp, rValue, 0, 255 ))
94 : : {
95 [ # # ]: 0 : aFormat.Lines = nTmp < 2 ? 0 : (sal_Int8)nTmp;
96 : : }
97 : 0 : break;
98 : :
99 : : case XML_TOK_DROP_LENGTH:
100 [ # # ][ # # ]: 0 : if( IsXMLToken( rValue, XML_WORD ) )
101 : : {
102 : 0 : bWholeWord = sal_True;
103 : : }
104 [ # # ][ # # ]: 0 : else if (::sax::Converter::convertNumber( nTmp, rValue, 1, 255 ))
105 : : {
106 : 0 : bWholeWord = sal_False;
107 : 0 : aFormat.Count = (sal_Int8)nTmp;
108 : : }
109 : 0 : break;
110 : :
111 : : case XML_TOK_DROP_DISTANCE:
112 [ # # ][ # # ]: 0 : if (GetImport().GetMM100UnitConverter().convertMeasureToCore(
113 : : nTmp, rValue, 0 ))
114 : : {
115 : 0 : aFormat.Distance = (sal_uInt16)nTmp;
116 : : }
117 : 0 : break;
118 : :
119 : : case XML_TOK_DROP_STYLE:
120 : 0 : sStyleName = rValue;
121 : 0 : break;
122 : : }
123 : 0 : }
124 : :
125 [ # # ][ # # ]: 0 : if( aFormat.Lines > 1 && aFormat.Count < 1 )
126 : 0 : aFormat.Count = 1;
127 : :
128 [ # # ]: 0 : aProp.maValue <<= aFormat;
129 : :
130 [ # # ][ # # ]: 0 : aWholeWordProp.maValue.setValue( &bWholeWord, ::getBooleanCppuType() );
131 : 0 : }
132 : :
133 : 0 : XMLTextDropCapImportContext::XMLTextDropCapImportContext(
134 : : SvXMLImport& rImport, sal_uInt16 nPrfx,
135 : : const OUString& rLName,
136 : : const Reference< xml::sax::XAttributeList > & xAttrList,
137 : : const XMLPropertyState& rProp,
138 : : sal_Int32 nWholeWordIdx,
139 : : ::std::vector< XMLPropertyState > &rProps ) :
140 : : XMLElementPropertyContext( rImport, nPrfx, rLName, rProp, rProps ),
141 : 0 : aWholeWordProp( nWholeWordIdx )
142 : : {
143 [ # # ]: 0 : ProcessAttrs( xAttrList );
144 : 0 : }
145 : :
146 : 0 : XMLTextDropCapImportContext::~XMLTextDropCapImportContext()
147 : : {
148 [ # # ]: 0 : }
149 : :
150 : 0 : void XMLTextDropCapImportContext::EndElement()
151 : : {
152 : 0 : SetInsert( sal_True );
153 : 0 : XMLElementPropertyContext::EndElement();
154 : :
155 [ # # ]: 0 : if( -1 != aWholeWordProp.mnIndex )
156 : 0 : rProperties.push_back( aWholeWordProp );
157 : 0 : }
158 : :
159 : :
160 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|