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 "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 <osl/diagnose.h>
28 :
29 : #include "oox/helper/helper.hxx"
30 : #include "oox/helper/propertyset.hxx"
31 : #include "oox/core/xmlfilterbase.hxx"
32 : #include "oox/token/tokens.hxx"
33 :
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;
39 :
40 : namespace oox { namespace drawingml {
41 :
42 2555 : TextRun::TextRun() :
43 2555 : mbIsLineBreak( false )
44 : {
45 2555 : }
46 :
47 4891 : TextRun::~TextRun()
48 : {
49 4891 : }
50 :
51 1394 : 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
57 : {
58 1394 : sal_Int32 nCharHeight = 0;
59 : try {
60 1394 : Reference< XTextRange > xStart( xAt, UNO_QUERY );
61 2788 : PropertySet aPropSet( xStart );
62 :
63 2788 : TextCharacterProperties aTextCharacterProps( rTextCharacterStyle );
64 1394 : aTextCharacterProps.assignUsed( maTextCharacterProperties );
65 1394 : if ( aTextCharacterProps.moHeight.has() )
66 1307 : nCharHeight = aTextCharacterProps.moHeight.get();
67 : else
68 : // UNO API has the character height as float, DML has it as int, but in hundreds.
69 87 : aTextCharacterProps.moHeight = static_cast<sal_Int32>(nDefaultCharHeight * 100);
70 1394 : aTextCharacterProps.pushToPropSet( aPropSet, rFilterBase );
71 :
72 1394 : if( maTextCharacterProperties.maHyperlinkPropertyMap.empty() )
73 : {
74 1394 : if( mbIsLineBreak )
75 : {
76 : OSL_TRACE( "OOX: TextRun::insertAt() insert line break" );
77 11 : xText->insertControlCharacter( xStart, ControlCharacter::LINE_BREAK, sal_False );
78 : }
79 : else
80 : {
81 1383 : OUString aSymbolFontName;
82 1383 : sal_Int16 nSymbolFontFamily = 0, nSymbolFontPitch = 0;
83 :
84 1383 : if ( !aTextCharacterProps.maSymbolFont.getFontData( aSymbolFontName, nSymbolFontPitch, nSymbolFontFamily, rFilterBase ) )
85 1383 : xText->insertString( xStart, getText(), sal_False );
86 0 : else if ( !getText().isEmpty() )
87 : {
88 : // #i113673
89 0 : OUString aLatinFontName;
90 0 : sal_Int16 nLatinFontPitch = 0, nLatinFontFamily = 0;
91 0 : bool bLatinOk = aTextCharacterProps.maLatinFont.getFontData( aLatinFontName, nLatinFontPitch, nLatinFontFamily, rFilterBase );
92 :
93 0 : sal_Int32 nIndex = 0;
94 : while ( true )
95 : {
96 0 : sal_Int32 nCount = 0;
97 0 : bool bSymbol = ( getText()[ nIndex ] & 0xff00 ) == 0xf000;
98 0 : if ( bSymbol )
99 : {
100 0 : do
101 : {
102 0 : nCount++;
103 : }
104 0 : while( ( ( nCount + nIndex ) < getText().getLength() ) && ( ( getText()[ nCount + nIndex ] & 0xff00 ) == 0xf000 ) );
105 0 : aPropSet.setAnyProperty( PROP_CharFontName, Any( aSymbolFontName ) );
106 0 : aPropSet.setAnyProperty( PROP_CharFontPitch, Any( nSymbolFontPitch ) );
107 0 : aPropSet.setAnyProperty( PROP_CharFontFamily, Any( nSymbolFontFamily ) );
108 : }
109 : else
110 : {
111 0 : do
112 : {
113 0 : nCount++;
114 : }
115 0 : while( ( ( nCount + nIndex ) < getText().getLength() ) && ( ( getText()[ nCount + nIndex ] & 0xff00 ) != 0xf000 ) );
116 0 : if (bLatinOk)
117 : {
118 0 : aPropSet.setAnyProperty( PROP_CharFontName, Any( aLatinFontName ) );
119 0 : aPropSet.setAnyProperty( PROP_CharFontPitch, Any( nLatinFontPitch ) );
120 0 : aPropSet.setAnyProperty( PROP_CharFontFamily, Any( nLatinFontFamily ) );
121 : }
122 : }
123 0 : OUString aSubString( getText().copy( nIndex, nCount ) );
124 0 : xText->insertString( xStart, aSubString, sal_False );
125 0 : nIndex += nCount;
126 :
127 0 : if ( nIndex >= getText().getLength() )
128 0 : break;
129 :
130 0 : xStart = xAt;
131 0 : aPropSet = PropertySet( xStart );
132 0 : aTextCharacterProps.pushToPropSet( aPropSet, rFilterBase );
133 0 : }
134 1383 : }
135 : }
136 : }
137 : else
138 : {
139 : OSL_TRACE( "OOX: URL field" );
140 0 : Reference< XMultiServiceFactory > xFactory( rFilterBase.getModel(), UNO_QUERY );
141 0 : Reference< XTextField > xField( xFactory->createInstance( "com.sun.star.text.TextField.URL" ), UNO_QUERY );
142 0 : if( xField.is() )
143 : {
144 0 : Reference< XTextCursor > xTextFieldCursor = xText->createTextCursor();
145 0 : xTextFieldCursor->gotoEnd( sal_False );
146 :
147 0 : PropertySet aFieldProps( xField );
148 0 : aFieldProps.setProperties( maTextCharacterProperties.maHyperlinkPropertyMap );
149 0 : aFieldProps.setProperty( PROP_Representation, getText() );
150 0 : xText->insertTextContent( xStart, xField, sal_False );
151 :
152 0 : xTextFieldCursor->gotoEnd( sal_True );
153 :
154 0 : aTextCharacterProps.maCharColor.setSchemeClr( XML_hlink );
155 0 : if ( !maTextCharacterProperties.moUnderline.has() )
156 0 : aTextCharacterProps.moUnderline.set( XML_sng );
157 :
158 0 : PropertySet aFieldTextPropSet( xTextFieldCursor );
159 0 : aTextCharacterProps.pushToPropSet( aFieldTextPropSet, rFilterBase );
160 :
161 0 : oox::core::TextField aTextField;
162 0 : aTextField.xText = xText;
163 0 : aTextField.xTextCursor = xTextFieldCursor;
164 0 : aTextField.xTextField = xField;
165 0 : rFilterBase.getTextFieldStack().push_back( aTextField );
166 : }
167 : else
168 : {
169 : OSL_TRACE( "OOX: URL field couldn't be created" );
170 0 : xText->insertString( xStart, getText(), sal_False );
171 0 : }
172 1394 : }
173 : }
174 0 : catch( const Exception& )
175 : {
176 : OSL_TRACE("OOX: TextRun::insertAt() exception");
177 : }
178 :
179 1394 : return nCharHeight;
180 : }
181 :
182 246 : } }
183 :
184 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|