1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "oox/drawingml/textrun.hxx"
22 #include <com/sun/star/text/ControlCharacter.hpp>
23 #include <com/sun/star/beans/XMultiPropertySet.hpp>
24 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
25 #include <com/sun/star/text/XTextField.hpp>
27 #include "oox/helper/helper.hxx"
28 #include "oox/helper/propertyset.hxx"
29 #include "oox/core/xmlfilterbase.hxx"
30 #include "oox/token/tokens.hxx"
32 using namespace ::com::sun::star::uno
;
33 using namespace ::com::sun::star::text
;
34 using namespace ::com::sun::star::beans
;
35 using namespace ::com::sun::star::frame
;
36 using namespace ::com::sun::star::lang
;
38 namespace oox
{ namespace drawingml
{
41 mbIsLineBreak( false )
49 sal_Int32
TextRun::insertAt(
50 const ::oox::core::XmlFilterBase
& rFilterBase
,
51 const Reference
< XText
> & xText
,
52 const Reference
< XTextCursor
> &xAt
,
53 const TextCharacterProperties
& rTextCharacterStyle
) const
55 sal_Int32 nCharHeight
= 0;
57 Reference
< XTextRange
> xStart( xAt
, UNO_QUERY
);
58 PropertySet
aPropSet( xStart
);
60 TextCharacterProperties
aTextCharacterProps( rTextCharacterStyle
);
61 aTextCharacterProps
.assignUsed( maTextCharacterProperties
);
62 if ( aTextCharacterProps
.moHeight
.has() )
63 nCharHeight
= aTextCharacterProps
.moHeight
.get();
64 aTextCharacterProps
.pushToPropSet( aPropSet
, rFilterBase
);
66 if( maTextCharacterProperties
.maHyperlinkPropertyMap
.empty() )
70 OSL_TRACE( "OOX: TextRun::insertAt() insert line break" );
71 xText
->insertControlCharacter( xStart
, ControlCharacter::LINE_BREAK
, sal_False
);
75 OUString aLatinFontName
, aSymbolFontName
;
76 sal_Int16 nSymbolFontFamily
= 0, nSymbolFontPitch
= 0;
78 if ( !aTextCharacterProps
.maSymbolFont
.getFontData( aSymbolFontName
, nSymbolFontPitch
, nSymbolFontFamily
, rFilterBase
) )
79 xText
->insertString( xStart
, getText(), sal_False
);
80 else if ( !getText().isEmpty() )
82 sal_Int16 nLatinFontPitch
= 0, nLatinFontFamily
= 0;
83 aTextCharacterProps
.maLatinFont
.getFontData( aLatinFontName
, nLatinFontPitch
, nLatinFontFamily
, rFilterBase
);
89 sal_Bool bSymbol
= ( getText()[ nIndex
] & 0xff00 ) == 0xf000;
96 while( ( ( nCount
+ nIndex
) < getText().getLength() ) && ( ( getText()[ nCount
+ nIndex
] & 0xff00 ) == 0xf000 ) );
97 aPropSet
.setAnyProperty( PROP_CharFontName
, Any( aSymbolFontName
) );
98 aPropSet
.setAnyProperty( PROP_CharFontPitch
, Any( nSymbolFontPitch
) );
99 aPropSet
.setAnyProperty( PROP_CharFontFamily
, Any( nSymbolFontFamily
) );
107 while( ( ( nCount
+ nIndex
) < getText().getLength() ) && ( ( getText()[ nCount
+ nIndex
] & 0xff00 ) != 0xf000 ) );
108 aPropSet
.setAnyProperty( PROP_CharFontName
, Any( aLatinFontName
) );
109 aPropSet
.setAnyProperty( PROP_CharFontPitch
, Any( nLatinFontPitch
) );
110 aPropSet
.setAnyProperty( PROP_CharFontFamily
, Any( nLatinFontFamily
) );
112 OUString
aSubString( getText().copy( nIndex
, nCount
) );
113 xText
->insertString( xStart
, aSubString
, sal_False
);
116 if ( nIndex
>= getText().getLength() )
119 xStart
= Reference
< XTextRange
>( xAt
, UNO_QUERY
);
120 aPropSet
= PropertySet( xStart
);
121 aTextCharacterProps
.pushToPropSet( aPropSet
, rFilterBase
);
128 OSL_TRACE( "OOX: URL field" );
129 Reference
< XMultiServiceFactory
> xFactory( rFilterBase
.getModel(), UNO_QUERY
);
130 Reference
< XTextField
> xField( xFactory
->createInstance( "com.sun.star.text.TextField.URL" ), UNO_QUERY
);
133 Reference
< XTextCursor
> xTextFieldCursor
= xText
->createTextCursor();
134 xTextFieldCursor
->gotoEnd( sal_False
);
136 PropertySet
aFieldProps( xField
);
137 aFieldProps
.setProperties( maTextCharacterProperties
.maHyperlinkPropertyMap
);
138 aFieldProps
.setProperty( PROP_Representation
, getText() );
139 Reference
< XTextContent
> xContent( xField
, UNO_QUERY
);
140 xText
->insertTextContent( xStart
, xContent
, sal_False
);
142 xTextFieldCursor
->gotoEnd( sal_True
);
144 if ( !maTextCharacterProperties
.maCharColor
.isUsed() )
145 aTextCharacterProps
.maCharColor
.setSchemeClr( XML_hlink
);
146 if ( !maTextCharacterProperties
.moUnderline
.has() )
147 aTextCharacterProps
.moUnderline
.set( XML_sng
);
149 Reference
< XTextRange
> xFieldRange( xTextFieldCursor
, UNO_QUERY
);
150 PropertySet
aFieldTextPropSet( xFieldRange
);
151 aTextCharacterProps
.pushToPropSet( aFieldTextPropSet
, rFilterBase
);
153 oox::core::TextField aTextField
;
154 aTextField
.xText
= xText
;
155 aTextField
.xTextCursor
= xTextFieldCursor
;
156 aTextField
.xTextField
= xField
;
157 rFilterBase
.getTextFieldStack().push_back( aTextField
);
161 OSL_TRACE( "OOX: URL field couldn't be created" );
162 xText
->insertString( xStart
, getText(), sal_False
);
166 catch( const Exception
& )
168 OSL_TRACE("OOX: TextRun::insertAt() exception");
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */