fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / oox / source / drawingml / textrun.cxx
blobca744e8dfe4a287ad3758563823c511f5e43334b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/lang/XMultiServiceFactory.hpp>
25 #include <com/sun/star/text/XTextField.hpp>
27 #include <osl/diagnose.h>
29 #include "oox/helper/helper.hxx"
30 #include "oox/helper/propertyset.hxx"
31 #include "oox/core/xmlfilterbase.hxx"
32 #include "oox/token/tokens.hxx"
34 using namespace ::com::sun::star::uno;
35 using namespace ::com::sun::star::text;
36 using namespace ::com::sun::star::beans;
37 using namespace ::com::sun::star::frame;
38 using namespace ::com::sun::star::lang;
40 namespace oox { namespace drawingml {
42 TextRun::TextRun() :
43 mbIsLineBreak( false )
47 TextRun::~TextRun()
51 sal_Int32 TextRun::insertAt(
52 const ::oox::core::XmlFilterBase& rFilterBase,
53 const Reference < XText > & xText,
54 const Reference < XTextCursor > &xAt,
55 const TextCharacterProperties& rTextCharacterStyle,
56 float nDefaultCharHeight) const
58 sal_Int32 nCharHeight = 0;
59 try {
60 Reference< XTextRange > xStart( xAt, UNO_QUERY );
61 PropertySet aPropSet( xStart );
63 TextCharacterProperties aTextCharacterProps( rTextCharacterStyle );
64 aTextCharacterProps.assignUsed( maTextCharacterProperties );
65 if ( aTextCharacterProps.moHeight.has() )
66 nCharHeight = aTextCharacterProps.moHeight.get();
67 else
68 // UNO API has the character height as float, DML has it as int, but in hundreds.
69 aTextCharacterProps.moHeight = static_cast<sal_Int32>(nDefaultCharHeight * 100);
70 aTextCharacterProps.pushToPropSet( aPropSet, rFilterBase );
72 if( maTextCharacterProperties.maHyperlinkPropertyMap.empty() )
74 if( mbIsLineBreak )
76 OSL_TRACE( "OOX: TextRun::insertAt() insert line break" );
77 xText->insertControlCharacter( xStart, ControlCharacter::LINE_BREAK, sal_False );
79 else
81 OUString aSymbolFontName;
82 sal_Int16 nSymbolFontFamily = 0, nSymbolFontPitch = 0;
84 if ( !aTextCharacterProps.maSymbolFont.getFontData( aSymbolFontName, nSymbolFontPitch, nSymbolFontFamily, rFilterBase ) )
85 xText->insertString( xStart, getText(), sal_False );
86 else if ( !getText().isEmpty() )
88 // #i113673
89 OUString aLatinFontName;
90 sal_Int16 nLatinFontPitch = 0, nLatinFontFamily = 0;
91 bool bLatinOk = aTextCharacterProps.maLatinFont.getFontData( aLatinFontName, nLatinFontPitch, nLatinFontFamily, rFilterBase );
93 sal_Int32 nIndex = 0;
94 while ( true )
96 sal_Int32 nCount = 0;
97 bool bSymbol = ( getText()[ nIndex ] & 0xff00 ) == 0xf000;
98 if ( bSymbol )
102 nCount++;
104 while( ( ( nCount + nIndex ) < getText().getLength() ) && ( ( getText()[ nCount + nIndex ] & 0xff00 ) == 0xf000 ) );
105 aPropSet.setAnyProperty( PROP_CharFontName, Any( aSymbolFontName ) );
106 aPropSet.setAnyProperty( PROP_CharFontPitch, Any( nSymbolFontPitch ) );
107 aPropSet.setAnyProperty( PROP_CharFontFamily, Any( nSymbolFontFamily ) );
109 else
113 nCount++;
115 while( ( ( nCount + nIndex ) < getText().getLength() ) && ( ( getText()[ nCount + nIndex ] & 0xff00 ) != 0xf000 ) );
116 if (bLatinOk)
118 aPropSet.setAnyProperty( PROP_CharFontName, Any( aLatinFontName ) );
119 aPropSet.setAnyProperty( PROP_CharFontPitch, Any( nLatinFontPitch ) );
120 aPropSet.setAnyProperty( PROP_CharFontFamily, Any( nLatinFontFamily ) );
123 OUString aSubString( getText().copy( nIndex, nCount ) );
124 xText->insertString( xStart, aSubString, sal_False );
125 nIndex += nCount;
127 if ( nIndex >= getText().getLength() )
128 break;
130 xStart = xAt;
131 aPropSet = PropertySet( xStart );
132 aTextCharacterProps.pushToPropSet( aPropSet, rFilterBase );
137 else
139 OSL_TRACE( "OOX: URL field" );
140 Reference< XMultiServiceFactory > xFactory( rFilterBase.getModel(), UNO_QUERY );
141 Reference< XTextField > xField( xFactory->createInstance( "com.sun.star.text.TextField.URL" ), UNO_QUERY );
142 if( xField.is() )
144 Reference< XTextCursor > xTextFieldCursor = xText->createTextCursor();
145 xTextFieldCursor->gotoEnd( sal_False );
147 PropertySet aFieldProps( xField );
148 aFieldProps.setProperties( maTextCharacterProperties.maHyperlinkPropertyMap );
149 aFieldProps.setProperty( PROP_Representation, getText() );
150 xText->insertTextContent( xStart, xField, sal_False );
152 xTextFieldCursor->gotoEnd( sal_True );
154 aTextCharacterProps.maCharColor.setSchemeClr( XML_hlink );
155 if ( !maTextCharacterProperties.moUnderline.has() )
156 aTextCharacterProps.moUnderline.set( XML_sng );
158 PropertySet aFieldTextPropSet( xTextFieldCursor );
159 aTextCharacterProps.pushToPropSet( aFieldTextPropSet, rFilterBase );
161 oox::core::TextField aTextField;
162 aTextField.xText = xText;
163 aTextField.xTextCursor = xTextFieldCursor;
164 aTextField.xTextField = xField;
165 rFilterBase.getTextFieldStack().push_back( aTextField );
167 else
169 OSL_TRACE( "OOX: URL field couldn't be created" );
170 xText->insertString( xStart, getText(), sal_False );
174 catch( const Exception& )
176 OSL_TRACE("OOX: TextRun::insertAt() exception");
179 return nCharHeight;
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */