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 <drawingml/textrun.hxx>
22 #include <com/sun/star/text/ControlCharacter.hpp>
23 #include <com/sun/star/beans/XMultiPropertySet.hpp>
24 #include <com/sun/star/beans/XPropertySet.hpp>
25 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
26 #include <com/sun/star/text/XTextField.hpp>
28 #include <sal/log.hxx>
30 #include <oox/helper/helper.hxx>
31 #include <oox/helper/propertyset.hxx>
32 #include <oox/core/xmlfilterbase.hxx>
33 #include <oox/token/properties.hxx>
34 #include <oox/token/tokens.hxx>
35 #include <tools/diagnose_ex.h>
37 using namespace ::com::sun::star::uno
;
38 using namespace ::com::sun::star::text
;
39 using namespace ::com::sun::star::beans
;
40 using namespace ::com::sun::star::lang
;
42 namespace oox
{ namespace drawingml
{
45 mbIsLineBreak( false )
53 sal_Int32
TextRun::insertAt(
54 const ::oox::core::XmlFilterBase
& rFilterBase
,
55 const Reference
< XText
> & xText
,
56 const Reference
< XTextCursor
> &xAt
,
57 const TextCharacterProperties
& rTextCharacterStyle
,
58 float nDefaultCharHeight
) const
60 sal_Int32 nCharHeight
= 0;
62 Reference
< XTextRange
> xStart( xAt
, UNO_QUERY
);
63 PropertySet
aPropSet( xStart
);
65 TextCharacterProperties
aTextCharacterProps( rTextCharacterStyle
);
66 aTextCharacterProps
.assignUsed( maTextCharacterProperties
);
67 if ( aTextCharacterProps
.moHeight
.has() )
68 nCharHeight
= aTextCharacterProps
.moHeight
.get();
70 // UNO API has the character height as float, DML has it as int, but in hundreds.
71 aTextCharacterProps
.moHeight
= static_cast<sal_Int32
>(nDefaultCharHeight
* 100);
72 aTextCharacterProps
.pushToPropSet( aPropSet
, rFilterBase
);
74 if( maTextCharacterProperties
.maHyperlinkPropertyMap
.empty() )
78 SAL_WARN("oox", "OOX: TextRun::insertAt() insert line break" );
79 xText
->insertControlCharacter( xStart
, ControlCharacter::LINE_BREAK
, false );
83 OUString aSymbolFontName
;
84 sal_Int16 nSymbolFontFamily
= 0, nSymbolFontPitch
= 0;
86 if ( !aTextCharacterProps
.maSymbolFont
.getFontData( aSymbolFontName
, nSymbolFontPitch
, nSymbolFontFamily
, rFilterBase
) )
87 xText
->insertString( xStart
, getText(), false );
88 else if ( !getText().isEmpty() )
91 OUString aLatinFontName
;
92 sal_Int16 nLatinFontPitch
= 0, nLatinFontFamily
= 0;
93 bool bLatinOk
= aTextCharacterProps
.maLatinFont
.getFontData( aLatinFontName
, nLatinFontPitch
, nLatinFontFamily
, rFilterBase
);
99 bool bSymbol
= ( getText()[ nIndex
] & 0xff00 ) == 0xf000;
106 while( ( ( nCount
+ nIndex
) < getText().getLength() ) && ( ( getText()[ nCount
+ nIndex
] & 0xff00 ) == 0xf000 ) );
107 aPropSet
.setAnyProperty( PROP_CharFontName
, Any( aSymbolFontName
) );
108 aPropSet
.setAnyProperty( PROP_CharFontPitch
, Any( nSymbolFontPitch
) );
109 aPropSet
.setAnyProperty( PROP_CharFontFamily
, Any( nSymbolFontFamily
) );
117 while( ( ( nCount
+ nIndex
) < getText().getLength() ) && ( ( getText()[ nCount
+ nIndex
] & 0xff00 ) != 0xf000 ) );
120 aPropSet
.setAnyProperty( PROP_CharFontName
, Any( aLatinFontName
) );
121 aPropSet
.setAnyProperty( PROP_CharFontPitch
, Any( nLatinFontPitch
) );
122 aPropSet
.setAnyProperty( PROP_CharFontFamily
, Any( nLatinFontFamily
) );
125 OUString
aSubString( getText().copy( nIndex
, nCount
) );
126 xText
->insertString( xStart
, aSubString
, false );
129 if ( nIndex
>= getText().getLength() )
133 aPropSet
= PropertySet( xStart
);
134 aTextCharacterProps
.pushToPropSet( aPropSet
, rFilterBase
);
141 SAL_WARN("oox", "OOX: URL field" );
142 Reference
< XMultiServiceFactory
> xFactory( rFilterBase
.getModel(), UNO_QUERY
);
143 Reference
< XTextField
> xField( xFactory
->createInstance( "com.sun.star.text.TextField.URL" ), UNO_QUERY
);
146 Reference
< XTextCursor
> xTextFieldCursor
= xText
->createTextCursor();
147 xTextFieldCursor
->gotoEnd( false );
149 PropertySet
aFieldProps( xField
);
150 aFieldProps
.setProperties( maTextCharacterProperties
.maHyperlinkPropertyMap
);
151 aFieldProps
.setProperty( PROP_Representation
, getText() );
152 xText
->insertTextContent( xStart
, xField
, false );
154 xTextFieldCursor
->gotoEnd( true );
156 aTextCharacterProps
.maFillProperties
.maFillColor
.setSchemeClr( XML_hlink
);
157 aTextCharacterProps
.maFillProperties
.moFillType
.set(XML_solidFill
);
158 if ( !maTextCharacterProperties
.moUnderline
.has() )
159 aTextCharacterProps
.moUnderline
.set( XML_sng
);
161 PropertySet
aFieldTextPropSet( xTextFieldCursor
);
162 aTextCharacterProps
.pushToPropSet( aFieldTextPropSet
, rFilterBase
);
164 oox::core::TextField aTextField
;
165 aTextField
.xText
= xText
;
166 aTextField
.xTextCursor
= xTextFieldCursor
;
167 aTextField
.xTextField
= xField
;
168 rFilterBase
.getTextFieldStack().push_back( aTextField
);
172 SAL_WARN("oox", "OOX: URL field couldn't be created" );
173 xText
->insertString( xStart
, getText(), false );
177 catch( const Exception
& )
179 css::uno::Any
ex( cppu::getCaughtException() );
180 SAL_WARN("oox", "OOX: TextRun::insertAt() exception " << exceptionToString(ex
));
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */