xref: /trunk/main/oox/source/drawingml/textrun.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include "oox/drawingml/textrun.hxx"
29 
30 #include <com/sun/star/text/ControlCharacter.hpp>
31 #include <com/sun/star/beans/XMultiPropertySet.hpp>
32 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
33 #include <com/sun/star/text/XTextField.hpp>
34 
35 #include "oox/helper/helper.hxx"
36 #include "oox/helper/propertyset.hxx"
37 #include "oox/core/xmlfilterbase.hxx"
38 
39 using ::rtl::OUString;
40 using namespace ::com::sun::star::uno;
41 using namespace ::com::sun::star::text;
42 using namespace ::com::sun::star::beans;
43 using namespace ::com::sun::star::frame;
44 using namespace ::com::sun::star::lang;
45 
46 namespace oox { namespace drawingml {
47 
48 TextRun::TextRun() :
49     mbIsLineBreak( false )
50 {
51 }
52 
53 TextRun::~TextRun()
54 {
55 }
56 
57 void TextRun::insertAt(
58         const ::oox::core::XmlFilterBase& rFilterBase,
59         const Reference < XText > & xText,
60         const Reference < XTextCursor > &xAt,
61         const TextCharacterProperties& rTextCharacterStyle ) const
62 {
63     try {
64         Reference< XTextRange > xStart( xAt, UNO_QUERY );
65         PropertySet aPropSet( xStart );
66 
67         TextCharacterProperties aTextCharacterProps( rTextCharacterStyle );
68 		aTextCharacterProps.assignUsed( maTextCharacterProperties );
69 		aTextCharacterProps.pushToPropSet( aPropSet, rFilterBase );
70 
71         if( maTextCharacterProperties.maHyperlinkPropertyMap.empty() )
72         {
73             if( mbIsLineBreak )
74             {
75                 OSL_TRACE( "OOX: TextRun::insertAt() insert line break" );
76                 xText->insertControlCharacter( xStart, ControlCharacter::LINE_BREAK, sal_False );
77             }
78             else
79             {
80 				OUString aLatinFontName, aSymbolFontName;
81 				sal_Int16 nLatinFontPitch = 0, nSymbolFontPitch = 0;
82 				sal_Int16 nLatinFontFamily = 0, nSymbolFontFamily = 0;
83 
84 				if ( !aTextCharacterProps.maSymbolFont.getFontData( aSymbolFontName, nSymbolFontPitch, nSymbolFontFamily, rFilterBase ) )
85 					xText->insertString( xStart, getText(), sal_False );
86 				else if ( getText().getLength() )
87 				{	// !!#i113673<<<
88 					aTextCharacterProps.maLatinFont.getFontData( aLatinFontName, nLatinFontPitch, nLatinFontFamily, rFilterBase );
89 
90 					sal_Int32 nIndex = 0;
91 					while ( sal_True )
92 					{
93 						sal_Int32 nCount = 0;
94 						sal_Bool bSymbol = ( getText()[ nIndex ] & 0xff00 ) == 0xf000;
95 						if ( bSymbol )
96 						{
97 							do
98 							{
99 								nCount++;
100 							}
101 							while( ( ( nCount + nIndex ) < getText().getLength() ) && ( ( getText()[ nCount + nIndex ] & 0xff00 ) == 0xf000 ) );
102 							aPropSet.setAnyProperty( PROP_CharFontName, Any( aSymbolFontName ) );
103 							aPropSet.setAnyProperty( PROP_CharFontPitch, Any( nSymbolFontPitch ) );
104 							aPropSet.setAnyProperty( PROP_CharFontFamily, Any( nSymbolFontFamily ) );
105 						}
106 						else
107 						{
108 							do
109 							{
110 								nCount++;
111 							}
112 							while( ( ( nCount + nIndex ) < getText().getLength() ) && ( ( getText()[ nCount + nIndex ] & 0xff00 ) != 0xf000 ) );
113 							aPropSet.setAnyProperty( PROP_CharFontName, Any( aLatinFontName ) );
114 							aPropSet.setAnyProperty( PROP_CharFontPitch, Any( nLatinFontPitch ) );
115 							aPropSet.setAnyProperty( PROP_CharFontFamily, Any( nLatinFontFamily ) );
116 						}
117 						rtl::OUString aSubString( getText().copy( nIndex, nCount ) );
118 						xText->insertString( xStart, aSubString, sal_False );
119 						nIndex += nCount;
120 
121 						if ( nIndex >= getText().getLength() )
122 							break;
123 
124 						xStart = Reference< XTextRange >( xAt, UNO_QUERY );
125 						aPropSet = PropertySet( xStart );
126 						aTextCharacterProps.pushToPropSet( aPropSet, rFilterBase );
127 					}
128 				}
129             }
130         }
131         else
132         {
133             OSL_TRACE( "OOX: URL field" );
134             Reference< XMultiServiceFactory > xFactory( rFilterBase.getModel(), UNO_QUERY );
135             Reference< XTextField > xField( xFactory->createInstance( CREATE_OUSTRING( "com.sun.star.text.TextField.URL" ) ), UNO_QUERY );
136             if( xField.is() )
137             {
138 				Reference< XTextCursor > xTextFieldCursor = xText->createTextCursor();
139 				xTextFieldCursor->gotoEnd( sal_False );
140 
141 				PropertySet aFieldProps( xField );
142                 aFieldProps.setProperties( maTextCharacterProperties.maHyperlinkPropertyMap );
143                 aFieldProps.setProperty( PROP_Representation, getText() );
144                 Reference< XTextContent > xContent( xField, UNO_QUERY);
145                 xText->insertTextContent( xStart, xContent, sal_False );
146 
147 				xTextFieldCursor->gotoEnd( sal_True );
148 				oox::core::TextField aTextField;
149 				aTextField.xText = xText;
150 				aTextField.xTextCursor = xTextFieldCursor;
151 				aTextField.xTextField = xField;
152 				rFilterBase.getTextFieldStack().push_back( aTextField );
153             }
154             else
155             {
156                 OSL_TRACE( "OOX: URL field couldn't be created" );
157                 xText->insertString( xStart, getText(), sal_False );
158             }
159         }
160     }
161     catch( const Exception&  )
162     {
163         OSL_TRACE("OOX:  TextRun::insertAt() exception");
164     }
165 }
166 
167 
168 } }
169