Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "oox/drawingml/textrun.hxx"
21 :
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>
26 :
27 : #include "oox/helper/helper.hxx"
28 : #include "oox/helper/propertyset.hxx"
29 : #include "oox/core/xmlfilterbase.hxx"
30 : #include "oox/token/tokens.hxx"
31 :
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;
37 :
38 : namespace oox { namespace drawingml {
39 :
40 89 : TextRun::TextRun() :
41 89 : mbIsLineBreak( false )
42 : {
43 89 : }
44 :
45 166 : TextRun::~TextRun()
46 : {
47 166 : }
48 :
49 38 : 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
54 : {
55 38 : sal_Int32 nCharHeight = 0;
56 : try {
57 38 : Reference< XTextRange > xStart( xAt, UNO_QUERY );
58 38 : PropertySet aPropSet( xStart );
59 :
60 38 : TextCharacterProperties aTextCharacterProps( rTextCharacterStyle );
61 38 : aTextCharacterProps.assignUsed( maTextCharacterProperties );
62 38 : if ( aTextCharacterProps.moHeight.has() )
63 36 : nCharHeight = aTextCharacterProps.moHeight.get();
64 38 : aTextCharacterProps.pushToPropSet( aPropSet, rFilterBase );
65 :
66 38 : if( maTextCharacterProperties.maHyperlinkPropertyMap.empty() )
67 : {
68 38 : if( mbIsLineBreak )
69 : {
70 : OSL_TRACE( "OOX: TextRun::insertAt() insert line break" );
71 2 : xText->insertControlCharacter( xStart, ControlCharacter::LINE_BREAK, sal_False );
72 : }
73 : else
74 : {
75 36 : OUString aLatinFontName, aSymbolFontName;
76 36 : sal_Int16 nSymbolFontFamily = 0, nSymbolFontPitch = 0;
77 :
78 36 : if ( !aTextCharacterProps.maSymbolFont.getFontData( aSymbolFontName, nSymbolFontPitch, nSymbolFontFamily, rFilterBase ) )
79 36 : xText->insertString( xStart, getText(), sal_False );
80 0 : else if ( !getText().isEmpty() )
81 : { // !!#i113673<<<
82 0 : sal_Int16 nLatinFontPitch = 0, nLatinFontFamily = 0;
83 0 : aTextCharacterProps.maLatinFont.getFontData( aLatinFontName, nLatinFontPitch, nLatinFontFamily, rFilterBase );
84 :
85 0 : sal_Int32 nIndex = 0;
86 0 : while ( sal_True )
87 : {
88 0 : sal_Int32 nCount = 0;
89 0 : sal_Bool bSymbol = ( getText()[ nIndex ] & 0xff00 ) == 0xf000;
90 0 : if ( bSymbol )
91 : {
92 0 : do
93 : {
94 0 : nCount++;
95 : }
96 0 : while( ( ( nCount + nIndex ) < getText().getLength() ) && ( ( getText()[ nCount + nIndex ] & 0xff00 ) == 0xf000 ) );
97 0 : aPropSet.setAnyProperty( PROP_CharFontName, Any( aSymbolFontName ) );
98 0 : aPropSet.setAnyProperty( PROP_CharFontPitch, Any( nSymbolFontPitch ) );
99 0 : aPropSet.setAnyProperty( PROP_CharFontFamily, Any( nSymbolFontFamily ) );
100 : }
101 : else
102 : {
103 0 : do
104 : {
105 0 : nCount++;
106 : }
107 0 : while( ( ( nCount + nIndex ) < getText().getLength() ) && ( ( getText()[ nCount + nIndex ] & 0xff00 ) != 0xf000 ) );
108 0 : aPropSet.setAnyProperty( PROP_CharFontName, Any( aLatinFontName ) );
109 0 : aPropSet.setAnyProperty( PROP_CharFontPitch, Any( nLatinFontPitch ) );
110 0 : aPropSet.setAnyProperty( PROP_CharFontFamily, Any( nLatinFontFamily ) );
111 : }
112 0 : OUString aSubString( getText().copy( nIndex, nCount ) );
113 0 : xText->insertString( xStart, aSubString, sal_False );
114 0 : nIndex += nCount;
115 :
116 0 : if ( nIndex >= getText().getLength() )
117 : break;
118 :
119 0 : xStart = Reference< XTextRange >( xAt, UNO_QUERY );
120 0 : aPropSet = PropertySet( xStart );
121 0 : aTextCharacterProps.pushToPropSet( aPropSet, rFilterBase );
122 0 : }
123 36 : }
124 : }
125 : }
126 : else
127 : {
128 : OSL_TRACE( "OOX: URL field" );
129 0 : Reference< XMultiServiceFactory > xFactory( rFilterBase.getModel(), UNO_QUERY );
130 0 : Reference< XTextField > xField( xFactory->createInstance( CREATE_OUSTRING( "com.sun.star.text.TextField.URL" ) ), UNO_QUERY );
131 0 : if( xField.is() )
132 : {
133 0 : Reference< XTextCursor > xTextFieldCursor = xText->createTextCursor();
134 0 : xTextFieldCursor->gotoEnd( sal_False );
135 :
136 0 : PropertySet aFieldProps( xField );
137 0 : aFieldProps.setProperties( maTextCharacterProperties.maHyperlinkPropertyMap );
138 0 : aFieldProps.setProperty( PROP_Representation, getText() );
139 0 : Reference< XTextContent > xContent( xField, UNO_QUERY);
140 0 : xText->insertTextContent( xStart, xContent, sal_False );
141 :
142 0 : xTextFieldCursor->gotoEnd( sal_True );
143 :
144 0 : if ( !maTextCharacterProperties.maCharColor.isUsed() )
145 0 : aTextCharacterProps.maCharColor.setSchemeClr( XML_hlink );
146 0 : if ( !maTextCharacterProperties.moUnderline.has() )
147 0 : aTextCharacterProps.moUnderline.set( XML_sng );
148 :
149 0 : Reference< XTextRange > xFieldRange( xTextFieldCursor, UNO_QUERY );
150 0 : PropertySet aFieldTextPropSet( xFieldRange );
151 0 : aTextCharacterProps.pushToPropSet( aFieldTextPropSet, rFilterBase );
152 :
153 0 : oox::core::TextField aTextField;
154 0 : aTextField.xText = xText;
155 0 : aTextField.xTextCursor = xTextFieldCursor;
156 0 : aTextField.xTextField = xField;
157 0 : rFilterBase.getTextFieldStack().push_back( aTextField );
158 : }
159 : else
160 : {
161 : OSL_TRACE( "OOX: URL field couldn't be created" );
162 0 : xText->insertString( xStart, getText(), sal_False );
163 0 : }
164 38 : }
165 : }
166 0 : catch( const Exception& )
167 : {
168 : OSL_TRACE("OOX: TextRun::insertAt() exception");
169 : }
170 :
171 38 : return nCharHeight;
172 : }
173 :
174 :
175 51 : } }
176 :
177 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|