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