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