1*ca5ec200SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*ca5ec200SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*ca5ec200SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*ca5ec200SAndrew Rist * distributed with this work for additional information
6*ca5ec200SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*ca5ec200SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*ca5ec200SAndrew Rist * "License"); you may not use this file except in compliance
9*ca5ec200SAndrew Rist * with the License. You may obtain a copy of the License at
10*ca5ec200SAndrew Rist *
11*ca5ec200SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*ca5ec200SAndrew Rist *
13*ca5ec200SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*ca5ec200SAndrew Rist * software distributed under the License is distributed on an
15*ca5ec200SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ca5ec200SAndrew Rist * KIND, either express or implied. See the License for the
17*ca5ec200SAndrew Rist * specific language governing permissions and limitations
18*ca5ec200SAndrew Rist * under the License.
19*ca5ec200SAndrew Rist *
20*ca5ec200SAndrew Rist *************************************************************/
21*ca5ec200SAndrew Rist
22*ca5ec200SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #include "oox/drawingml/textrun.hxx"
25cdf0e10cSrcweir
26cdf0e10cSrcweir #include <com/sun/star/text/ControlCharacter.hpp>
27cdf0e10cSrcweir #include <com/sun/star/beans/XMultiPropertySet.hpp>
28cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
29cdf0e10cSrcweir #include <com/sun/star/text/XTextField.hpp>
30cdf0e10cSrcweir
31cdf0e10cSrcweir #include "oox/helper/helper.hxx"
32cdf0e10cSrcweir #include "oox/helper/propertyset.hxx"
33cdf0e10cSrcweir #include "oox/core/xmlfilterbase.hxx"
34cdf0e10cSrcweir
35cdf0e10cSrcweir using ::rtl::OUString;
36cdf0e10cSrcweir using namespace ::com::sun::star::uno;
37cdf0e10cSrcweir using namespace ::com::sun::star::text;
38cdf0e10cSrcweir using namespace ::com::sun::star::beans;
39cdf0e10cSrcweir using namespace ::com::sun::star::frame;
40cdf0e10cSrcweir using namespace ::com::sun::star::lang;
41cdf0e10cSrcweir
42cdf0e10cSrcweir namespace oox { namespace drawingml {
43cdf0e10cSrcweir
TextRun()44cdf0e10cSrcweir TextRun::TextRun() :
45cdf0e10cSrcweir mbIsLineBreak( false )
46cdf0e10cSrcweir {
47cdf0e10cSrcweir }
48cdf0e10cSrcweir
~TextRun()49cdf0e10cSrcweir TextRun::~TextRun()
50cdf0e10cSrcweir {
51cdf0e10cSrcweir }
52cdf0e10cSrcweir
insertAt(const::oox::core::XmlFilterBase & rFilterBase,const Reference<XText> & xText,const Reference<XTextCursor> & xAt,const TextCharacterProperties & rTextCharacterStyle) const53cdf0e10cSrcweir void TextRun::insertAt(
54cdf0e10cSrcweir const ::oox::core::XmlFilterBase& rFilterBase,
55cdf0e10cSrcweir const Reference < XText > & xText,
56cdf0e10cSrcweir const Reference < XTextCursor > &xAt,
57cdf0e10cSrcweir const TextCharacterProperties& rTextCharacterStyle ) const
58cdf0e10cSrcweir {
59cdf0e10cSrcweir try {
60cdf0e10cSrcweir Reference< XTextRange > xStart( xAt, UNO_QUERY );
61cdf0e10cSrcweir PropertySet aPropSet( xStart );
62cdf0e10cSrcweir
63cdf0e10cSrcweir TextCharacterProperties aTextCharacterProps( rTextCharacterStyle );
64cdf0e10cSrcweir aTextCharacterProps.assignUsed( maTextCharacterProperties );
65cdf0e10cSrcweir aTextCharacterProps.pushToPropSet( aPropSet, rFilterBase );
66cdf0e10cSrcweir
67cdf0e10cSrcweir if( maTextCharacterProperties.maHyperlinkPropertyMap.empty() )
68cdf0e10cSrcweir {
69cdf0e10cSrcweir if( mbIsLineBreak )
70cdf0e10cSrcweir {
71cdf0e10cSrcweir OSL_TRACE( "OOX: TextRun::insertAt() insert line break" );
72cdf0e10cSrcweir xText->insertControlCharacter( xStart, ControlCharacter::LINE_BREAK, sal_False );
73cdf0e10cSrcweir }
74cdf0e10cSrcweir else
75cdf0e10cSrcweir {
76cdf0e10cSrcweir OUString aLatinFontName, aSymbolFontName;
77cdf0e10cSrcweir sal_Int16 nLatinFontPitch = 0, nSymbolFontPitch = 0;
78cdf0e10cSrcweir sal_Int16 nLatinFontFamily = 0, nSymbolFontFamily = 0;
79cdf0e10cSrcweir
80cdf0e10cSrcweir if ( !aTextCharacterProps.maSymbolFont.getFontData( aSymbolFontName, nSymbolFontPitch, nSymbolFontFamily, rFilterBase ) )
81cdf0e10cSrcweir xText->insertString( xStart, getText(), sal_False );
82cdf0e10cSrcweir else if ( getText().getLength() )
83cdf0e10cSrcweir { // !!#i113673<<<
84cdf0e10cSrcweir aTextCharacterProps.maLatinFont.getFontData( aLatinFontName, nLatinFontPitch, nLatinFontFamily, rFilterBase );
85cdf0e10cSrcweir
86cdf0e10cSrcweir sal_Int32 nIndex = 0;
87cdf0e10cSrcweir while ( sal_True )
88cdf0e10cSrcweir {
89cdf0e10cSrcweir sal_Int32 nCount = 0;
90cdf0e10cSrcweir sal_Bool bSymbol = ( getText()[ nIndex ] & 0xff00 ) == 0xf000;
91cdf0e10cSrcweir if ( bSymbol )
92cdf0e10cSrcweir {
93cdf0e10cSrcweir do
94cdf0e10cSrcweir {
95cdf0e10cSrcweir nCount++;
96cdf0e10cSrcweir }
97cdf0e10cSrcweir while( ( ( nCount + nIndex ) < getText().getLength() ) && ( ( getText()[ nCount + nIndex ] & 0xff00 ) == 0xf000 ) );
98cdf0e10cSrcweir aPropSet.setAnyProperty( PROP_CharFontName, Any( aSymbolFontName ) );
99cdf0e10cSrcweir aPropSet.setAnyProperty( PROP_CharFontPitch, Any( nSymbolFontPitch ) );
100cdf0e10cSrcweir aPropSet.setAnyProperty( PROP_CharFontFamily, Any( nSymbolFontFamily ) );
101cdf0e10cSrcweir }
102cdf0e10cSrcweir else
103cdf0e10cSrcweir {
104cdf0e10cSrcweir do
105cdf0e10cSrcweir {
106cdf0e10cSrcweir nCount++;
107cdf0e10cSrcweir }
108cdf0e10cSrcweir while( ( ( nCount + nIndex ) < getText().getLength() ) && ( ( getText()[ nCount + nIndex ] & 0xff00 ) != 0xf000 ) );
109cdf0e10cSrcweir aPropSet.setAnyProperty( PROP_CharFontName, Any( aLatinFontName ) );
110cdf0e10cSrcweir aPropSet.setAnyProperty( PROP_CharFontPitch, Any( nLatinFontPitch ) );
111cdf0e10cSrcweir aPropSet.setAnyProperty( PROP_CharFontFamily, Any( nLatinFontFamily ) );
112cdf0e10cSrcweir }
113cdf0e10cSrcweir rtl::OUString aSubString( getText().copy( nIndex, nCount ) );
114cdf0e10cSrcweir xText->insertString( xStart, aSubString, sal_False );
115cdf0e10cSrcweir nIndex += nCount;
116cdf0e10cSrcweir
117cdf0e10cSrcweir if ( nIndex >= getText().getLength() )
118cdf0e10cSrcweir break;
119cdf0e10cSrcweir
120cdf0e10cSrcweir xStart = Reference< XTextRange >( xAt, UNO_QUERY );
121cdf0e10cSrcweir aPropSet = PropertySet( xStart );
122cdf0e10cSrcweir aTextCharacterProps.pushToPropSet( aPropSet, rFilterBase );
123cdf0e10cSrcweir }
124cdf0e10cSrcweir }
125cdf0e10cSrcweir }
126cdf0e10cSrcweir }
127cdf0e10cSrcweir else
128cdf0e10cSrcweir {
129cdf0e10cSrcweir OSL_TRACE( "OOX: URL field" );
130cdf0e10cSrcweir Reference< XMultiServiceFactory > xFactory( rFilterBase.getModel(), UNO_QUERY );
131cdf0e10cSrcweir Reference< XTextField > xField( xFactory->createInstance( CREATE_OUSTRING( "com.sun.star.text.TextField.URL" ) ), UNO_QUERY );
132cdf0e10cSrcweir if( xField.is() )
133cdf0e10cSrcweir {
134cdf0e10cSrcweir Reference< XTextCursor > xTextFieldCursor = xText->createTextCursor();
135cdf0e10cSrcweir xTextFieldCursor->gotoEnd( sal_False );
136cdf0e10cSrcweir
137cdf0e10cSrcweir PropertySet aFieldProps( xField );
138cdf0e10cSrcweir aFieldProps.setProperties( maTextCharacterProperties.maHyperlinkPropertyMap );
139cdf0e10cSrcweir aFieldProps.setProperty( PROP_Representation, getText() );
140cdf0e10cSrcweir Reference< XTextContent > xContent( xField, UNO_QUERY);
141cdf0e10cSrcweir xText->insertTextContent( xStart, xContent, sal_False );
142cdf0e10cSrcweir
143cdf0e10cSrcweir xTextFieldCursor->gotoEnd( sal_True );
144cdf0e10cSrcweir oox::core::TextField aTextField;
145cdf0e10cSrcweir aTextField.xText = xText;
146cdf0e10cSrcweir aTextField.xTextCursor = xTextFieldCursor;
147cdf0e10cSrcweir aTextField.xTextField = xField;
148cdf0e10cSrcweir rFilterBase.getTextFieldStack().push_back( aTextField );
149cdf0e10cSrcweir }
150cdf0e10cSrcweir else
151cdf0e10cSrcweir {
152cdf0e10cSrcweir OSL_TRACE( "OOX: URL field couldn't be created" );
153cdf0e10cSrcweir xText->insertString( xStart, getText(), sal_False );
154cdf0e10cSrcweir }
155cdf0e10cSrcweir }
156cdf0e10cSrcweir }
157cdf0e10cSrcweir catch( const Exception& )
158cdf0e10cSrcweir {
159cdf0e10cSrcweir OSL_TRACE("OOX: TextRun::insertAt() exception");
160cdf0e10cSrcweir }
161cdf0e10cSrcweir }
162cdf0e10cSrcweir
163cdf0e10cSrcweir
164cdf0e10cSrcweir } }
165