txtparae.cxx (dec99bbd) txtparae.cxx (c45df7c4)
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 3133 unchanged lines hidden (view full) ---

3142
3143void XMLTextParagraphExport::setTextEmbeddedGraphicURL(
3144 const Reference < XPropertySet >&,
3145 OUString& /*rStreamName*/ ) const
3146{
3147}
3148
3149sal_Bool XMLTextParagraphExport::addHyperlinkAttributes(
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 3133 unchanged lines hidden (view full) ---

3142
3143void XMLTextParagraphExport::setTextEmbeddedGraphicURL(
3144 const Reference < XPropertySet >&,
3145 OUString& /*rStreamName*/ ) const
3146{
3147}
3148
3149sal_Bool XMLTextParagraphExport::addHyperlinkAttributes(
3150 const Reference < XPropertySet > & rPropSet,
3151 const Reference < XPropertyState > & rPropState,
3152 const Reference < XPropertySetInfo > & rPropSetInfo )
3150 const Reference< XPropertySet > & rPropSet,
3151 const Reference< XPropertyState > & rPropState,
3152 const Reference< XPropertySetInfo > & rPropSetInfo )
3153{
3153{
3154 sal_Bool bExport = sal_False;
3155 OUString sHRef, sName, sTargetFrame, sUStyleName, sVStyleName;
3156 sal_Bool bServerMap = sal_False;
3154 sal_Bool bExport = sal_False;
3155 OUString sHRef, sName, sTargetFrame, sUStyleName, sVStyleName;
3156 sal_Bool bServerMap = sal_False;
3157
3157
3158/* bool bHyperLinkURL = false;
3159 bool bHyperLinkName = false;
3160 bool bHyperLinkTarget = false;
3161 bool bServer = false;
3162 bool bUnvisitedCharStyleName = false;
3163 bool bVisitedCharStyleName = false;
3164
3165 const Reference< XMultiPropertySet > xMultiPropertySet( rPropSet, UNO_QUERY );
3166 if ( xMultiPropertySet.is() )
3158 if ( rPropSetInfo->hasPropertyByName( sHyperLinkURL )
3159 && ( !rPropState.is()
3160 || PropertyState_DIRECT_VALUE == rPropState->getPropertyState( sHyperLinkURL ) ) )
3167 {
3161 {
3168 sal_uInt32 nCount = 0;
3169 Sequence< OUString > aPropertyNames( 6 );
3170 OUString* pArray = aPropertyNames.getArray();
3171
3172 if ( rPropSetInfo->hasPropertyByName( sServerMap ) )
3173 {
3174 bServer = true;
3175 pArray[ nCount++ ] = sServerMap;
3162 rPropSet->getPropertyValue( sHyperLinkURL ) >>= sHRef;
3163 if ( !sHRef.isEmpty() )
3164 bExport = sal_True;
3176 }
3165 }
3177 if ( rPropSetInfo->hasPropertyByName( sHyperLinkName ) )
3166 if ( sHRef.isEmpty() )
3178 {
3167 {
3179 bHyperLinkName = true;
3180 pArray[ nCount++ ] = sHyperLinkName;
3168 // hyperlink without an URL does not make sense
3169 OSL_ENSURE( false, "hyperlink without an URL --> no export to ODF" );
3170 return sal_False;
3181 }
3171 }
3182 if ( rPropSetInfo->hasPropertyByName( sHyperLinkTarget ) )
3172
3173
3174 if ( rPropSetInfo->hasPropertyByName( sHyperLinkName )
3175 && ( !rPropState.is()
3176 || PropertyState_DIRECT_VALUE == rPropState->getPropertyState( sHyperLinkName ) ) )
3183 {
3177 {
3184 bHyperLinkTarget = true;
3185 pArray[ nCount++ ] = sHyperLinkTarget;
3178 rPropSet->getPropertyValue( sHyperLinkName ) >>= sName;
3179 if ( !sName.isEmpty() )
3180 bExport = sal_True;
3186 }
3181 }
3187 if ( rPropSetInfo->hasPropertyByName( sHyperLinkURL ) )
3182
3183 if ( rPropSetInfo->hasPropertyByName( sHyperLinkTarget )
3184 && ( !rPropState.is()
3185 || PropertyState_DIRECT_VALUE == rPropState->getPropertyState( sHyperLinkTarget ) ) )
3188 {
3186 {
3189 bHyperLinkURL = true;
3190 pArray[ nCount++ ] = sHyperLinkURL;
3187 rPropSet->getPropertyValue( sHyperLinkTarget ) >>= sTargetFrame;
3188 if ( !sTargetFrame.isEmpty() )
3189 bExport = sal_True;
3191 }
3190 }
3192 if ( rPropSetInfo->hasPropertyByName( sUnvisitedCharStyleName ) )
3191
3192 if ( rPropSetInfo->hasPropertyByName( sServerMap )
3193 && ( !rPropState.is()
3194 || PropertyState_DIRECT_VALUE == rPropState->getPropertyState( sServerMap ) ) )
3193 {
3195 {
3194 bUnvisitedCharStyleName = true;
3195 pArray[ nCount++ ] = sUnvisitedCharStyleName;
3196 bServerMap = *(sal_Bool *) rPropSet->getPropertyValue( sServerMap ).getValue();
3197 if ( bServerMap )
3198 bExport = sal_True;
3196 }
3199 }
3197 if ( rPropSetInfo->hasPropertyByName( sVisitedCharStyleName ) )
3200
3201 if ( rPropSetInfo->hasPropertyByName( sUnvisitedCharStyleName )
3202 && ( !rPropState.is()
3203 || PropertyState_DIRECT_VALUE == rPropState->getPropertyState( sUnvisitedCharStyleName ) ) )
3198 {
3204 {
3199 bVisitedCharStyleName = true;
3200 pArray[ nCount++ ] = sVisitedCharStyleName;
3205 rPropSet->getPropertyValue( sUnvisitedCharStyleName ) >>= sUStyleName;
3206 if ( !sUStyleName.isEmpty() )
3207 bExport = sal_True;
3201 }
3202
3208 }
3209
3203 aPropertyNames.realloc( nCount );
3204
3205 if ( nCount )
3210 if ( rPropSetInfo->hasPropertyByName( sVisitedCharStyleName )
3211 && ( !rPropState.is()
3212 || PropertyState_DIRECT_VALUE == rPropState->getPropertyState( sVisitedCharStyleName ) ) )
3206 {
3213 {
3207 Sequence< PropertyState > aPropertyStates( nCount );
3208 PropertyState* pStateArray = aPropertyStates.getArray();
3209
3210 if ( rPropState.is() )
3211 aPropertyStates = rPropState->getPropertyStates( aPropertyNames );
3212
3213 Sequence< Any > aPropertyValues ( xMultiPropertySet->getPropertyValues( aPropertyNames ) );
3214 Any* pValueArray = aPropertyValues.getArray();
3215
3216 sal_uInt32 nIdx = 0;
3217
3218 if ( bServer )
3219 {
3220 if ( !rPropState.is() || PropertyState_DIRECT_VALUE == pStateArray[ nIdx ] )
3221 {
3222 bServerMap = *(sal_Bool *)pValueArray[ nIdx ].getValue();
3223 if( bServerMap )
3224 bExport = sal_True;
3225 }
3226 ++nIdx;
3227 }
3228 if ( bHyperLinkName )
3229 {
3230 if ( !rPropState.is() || PropertyState_DIRECT_VALUE == pStateArray[ nIdx ] )
3231 {
3232 pValueArray[ nIdx ] >>= sName;
3233 if( sName.getLength() > 0 )
3234 bExport = sal_True;
3235 }
3236 ++nIdx;
3237 }
3238 if ( bHyperLinkTarget )
3239 {
3240 if ( !rPropState.is() || PropertyState_DIRECT_VALUE == pStateArray[ nIdx ] )
3241 {
3242 pValueArray[ nIdx ] >>= sTargetFrame;
3243 if( sTargetFrame.getLength() )
3244 bExport = sal_True;
3245 }
3246 ++nIdx;
3247 }
3248 if ( bHyperLinkURL )
3249 {
3250 if ( !rPropState.is() || PropertyState_DIRECT_VALUE == pStateArray[ nIdx ] )
3251 {
3252 pValueArray[ nIdx ] >>= sHRef;
3253 if( sHRef.getLength() > 0 )
3254 bExport = sal_True;
3255 }
3256 ++nIdx;
3257 }
3258 if ( bUnvisitedCharStyleName )
3259 {
3260 if ( !rPropState.is() || PropertyState_DIRECT_VALUE == pStateArray[ nIdx ] )
3261 {
3262 pValueArray[ nIdx ] >>= sUStyleName;
3263 if( sUStyleName.getLength() )
3264 bExport = sal_True;
3265 }
3266 ++nIdx;
3267 }
3268 if ( bVisitedCharStyleName )
3269 {
3270 if ( !rPropState.is() || PropertyState_DIRECT_VALUE == pStateArray[ nIdx ] )
3271 {
3272 pValueArray[ nIdx ] >>= sVStyleName;
3273 if( sVStyleName.getLength() )
3274 bExport = sal_True;
3275 }
3276 ++nIdx;
3277 }
3214 rPropSet->getPropertyValue( sVisitedCharStyleName ) >>= sVStyleName;
3215 if ( !sVStyleName.isEmpty() )
3216 bExport = sal_True;
3278 }
3217 }
3279 }
3280 else
3281 {*/
3282 if( rPropSetInfo->hasPropertyByName( sHyperLinkURL ) &&
3283 ( !rPropState.is() || PropertyState_DIRECT_VALUE ==
3284 rPropState->getPropertyState( sHyperLinkURL ) ) )
3285 {
3286 rPropSet->getPropertyValue( sHyperLinkURL ) >>= sHRef;
3287
3218
3288 if( sHRef.getLength() > 0 )
3289 bExport = sal_True;
3290 }
3291
3292 if( rPropSetInfo->hasPropertyByName( sHyperLinkName ) &&
3293 ( !rPropState.is() || PropertyState_DIRECT_VALUE ==
3294 rPropState->getPropertyState( sHyperLinkName ) ) )
3219 if ( bExport )
3295 {
3220 {
3296 rPropSet->getPropertyValue( sHyperLinkName ) >>= sName;
3297 if( sName.getLength() > 0 )
3298 bExport = sal_True;
3299 }
3300
3301 if( rPropSetInfo->hasPropertyByName( sHyperLinkTarget ) &&
3302 ( !rPropState.is() || PropertyState_DIRECT_VALUE ==
3303 rPropState->getPropertyState( sHyperLinkTarget ) ) )
3304 {
3305 rPropSet->getPropertyValue( sHyperLinkTarget ) >>= sTargetFrame;
3306 if( sTargetFrame.getLength() )
3307 bExport = sal_True;
3308 }
3309
3310 if( rPropSetInfo->hasPropertyByName( sServerMap ) &&
3311 ( !rPropState.is() || PropertyState_DIRECT_VALUE ==
3312 rPropState->getPropertyState( sServerMap ) ) )
3313 {
3314 bServerMap = *(sal_Bool *)rPropSet->getPropertyValue( sServerMap ).getValue();
3315 if( bServerMap )
3316 bExport = sal_True;
3317 }
3318
3319 if( rPropSetInfo->hasPropertyByName( sUnvisitedCharStyleName ) &&
3320 ( !rPropState.is() || PropertyState_DIRECT_VALUE ==
3321 rPropState->getPropertyState( sUnvisitedCharStyleName ) ) )
3322 {
3323 rPropSet->getPropertyValue( sUnvisitedCharStyleName ) >>= sUStyleName;
3324 if( sUStyleName.getLength() )
3325 bExport = sal_True;
3326 }
3327
3328 if( rPropSetInfo->hasPropertyByName( sVisitedCharStyleName ) &&
3329 ( !rPropState.is() || PropertyState_DIRECT_VALUE ==
3330 rPropState->getPropertyState( sVisitedCharStyleName ) ) )
3331 {
3332 rPropSet->getPropertyValue( sVisitedCharStyleName ) >>= sVStyleName;
3333 if( sVStyleName.getLength() )
3334 bExport = sal_True;
3335 }
3336
3337 if( bExport )
3338 {
3339 GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE );
3340 GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, GetExport().GetRelativeReference( sHRef ) );
3341
3221 GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE );
3222 GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, GetExport().GetRelativeReference( sHRef ) );
3223
3342 if( sName.getLength() > 0 )
3224 if( !sName.isEmpty() )
3343 GetExport().AddAttribute( XML_NAMESPACE_OFFICE, XML_NAME, sName );
3344
3225 GetExport().AddAttribute( XML_NAMESPACE_OFFICE, XML_NAME, sName );
3226
3345 if( sTargetFrame.getLength() )
3227 if( !sTargetFrame.isEmpty() )
3346 {
3347 GetExport().AddAttribute( XML_NAMESPACE_OFFICE,
3348 XML_TARGET_FRAME_NAME, sTargetFrame );
3349 enum XMLTokenEnum eTok =
3350 sTargetFrame.equalsAsciiL( "_blank", sizeof("_blank")-1 )
3351 ? XML_NEW : XML_REPLACE;
3352 GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_SHOW, eTok );
3353 }
3354
3355 if( bServerMap )
3356 GetExport().AddAttribute( XML_NAMESPACE_OFFICE,
3357 XML_SERVER_MAP, XML_TRUE );
3358
3228 {
3229 GetExport().AddAttribute( XML_NAMESPACE_OFFICE,
3230 XML_TARGET_FRAME_NAME, sTargetFrame );
3231 enum XMLTokenEnum eTok =
3232 sTargetFrame.equalsAsciiL( "_blank", sizeof("_blank")-1 )
3233 ? XML_NEW : XML_REPLACE;
3234 GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_SHOW, eTok );
3235 }
3236
3237 if( bServerMap )
3238 GetExport().AddAttribute( XML_NAMESPACE_OFFICE,
3239 XML_SERVER_MAP, XML_TRUE );
3240
3359 if( sUStyleName.getLength() )
3241 if( !sUStyleName.isEmpty() )
3360 GetExport().AddAttribute( XML_NAMESPACE_TEXT,
3361 XML_STYLE_NAME, GetExport().EncodeStyleName( sUStyleName ) );
3362
3242 GetExport().AddAttribute( XML_NAMESPACE_TEXT,
3243 XML_STYLE_NAME, GetExport().EncodeStyleName( sUStyleName ) );
3244
3363 if( sVStyleName.getLength() )
3245 if( !sVStyleName.isEmpty() )
3364 GetExport().AddAttribute( XML_NAMESPACE_TEXT,
3365 XML_VISITED_STYLE_NAME, GetExport().EncodeStyleName( sVStyleName ) );
3366 }
3367
3368 return bExport;
3369}
3370
3246 GetExport().AddAttribute( XML_NAMESPACE_TEXT,
3247 XML_VISITED_STYLE_NAME, GetExport().EncodeStyleName( sVStyleName ) );
3248 }
3249
3250 return bExport;
3251}
3252
3253void XMLTextParagraphExport::exportTextRangeSpan(
3254 const com::sun::star::uno::Reference< com::sun::star::text::XTextRange > & rTextRange,
3255 Reference< XPropertySet > & xPropSet,
3256 Reference < XPropertySetInfo > & xPropSetInfo,
3257 const sal_Bool bIsUICharStyle,
3258 const sal_Bool bHasAutoStyle,
3259 const OUString& sStyle,
3260 sal_Bool& rPrevCharIsSpace )
3261{
3262 XMLTextCharStyleNamesElementExport aCharStylesExport(
3263 GetExport(),
3264 bIsUICharStyle && aCharStyleNamesPropInfoCache.hasProperty( xPropSet, xPropSetInfo ),
3265 bHasAutoStyle,
3266 xPropSet,
3267 sCharStyleNames );
3268
3269 if ( !sStyle.isEmpty() )
3270 {
3271 GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME, GetExport().EncodeStyleName( sStyle ) );
3272 }
3273 {
3274 SvXMLElementExport aElement( GetExport(), !sStyle.isEmpty(), XML_NAMESPACE_TEXT, XML_SPAN, sal_False, sal_False );
3275 const OUString aText( rTextRange->getString() );
3276 exportText( aText, rPrevCharIsSpace );
3277 }
3278}
3279
3371void XMLTextParagraphExport::exportTextRange(
3280void XMLTextParagraphExport::exportTextRange(
3372 const Reference < XTextRange > & rTextRange,
3373 sal_Bool bAutoStyles,
3374 sal_Bool& rPrevCharIsSpace )
3281 const Reference< XTextRange > & rTextRange,
3282 sal_Bool bAutoStyles,
3283 sal_Bool& rPrevCharIsSpace )
3375{
3284{
3376 Reference < XPropertySet > xPropSet( rTextRange, UNO_QUERY );
3377 if( bAutoStyles )
3378 {
3379 Add( XML_STYLE_FAMILY_TEXT_TEXT, xPropSet );
3380 }
3381 else
3382 {
3383 sal_Bool bHyperlink = sal_False;
3285 Reference< XPropertySet > xPropSet( rTextRange, UNO_QUERY );
3286 if ( bAutoStyles )
3287 {
3288 Add( XML_STYLE_FAMILY_TEXT_TEXT, xPropSet );
3289 }
3290 else
3291 {
3292 sal_Bool bHyperlink = sal_False;
3384 sal_Bool bIsUICharStyle = sal_False;
3385 sal_Bool bHasAutoStyle = sal_False;
3293 sal_Bool bIsUICharStyle = sal_False;
3294 sal_Bool bHasAutoStyle = sal_False;
3295 const OUString sStyle(
3296 FindTextStyleAndHyperlink( xPropSet, bHyperlink, bIsUICharStyle, bHasAutoStyle ) );
3386
3297
3387 OUString sStyle(FindTextStyleAndHyperlink( xPropSet, bHyperlink,
3388 bIsUICharStyle, bHasAutoStyle ));
3389
3390 Reference < XPropertySetInfo > xPropSetInfo;
3298 Reference < XPropertySetInfo > xPropSetInfo;
3391 if( bHyperlink )
3392 {
3393 Reference< XPropertyState > xPropState( xPropSet, UNO_QUERY );
3394 xPropSetInfo.set(xPropSet->getPropertySetInfo());
3395 bHyperlink = addHyperlinkAttributes( xPropSet, xPropState, xPropSetInfo );
3396 }
3397 SvXMLElementExport aElem( GetExport(), bHyperlink, XML_NAMESPACE_TEXT,
3398 XML_A, sal_False, sal_False );
3399 if( bHyperlink )
3400 {
3401 // export events (if supported)
3402 OUString sHyperLinkEvents(RTL_CONSTASCII_USTRINGPARAM(
3403 "HyperLinkEvents"));
3404 if (xPropSetInfo->hasPropertyByName(sHyperLinkEvents))
3405 {
3406 Reference<XNameReplace> xName(xPropSet->getPropertyValue(sHyperLinkEvents), uno::UNO_QUERY);
3407 GetExport().GetEventExport().Export(xName, sal_False);
3408 }
3409 }
3299 sal_Bool bHyperlinkAttrsAdded = sal_False;
3300 if ( bHyperlink )
3301 {
3302 Reference< XPropertyState > xPropState( xPropSet, UNO_QUERY );
3303 xPropSetInfo.set( xPropSet->getPropertySetInfo() );
3304 bHyperlinkAttrsAdded = addHyperlinkAttributes( xPropSet, xPropState, xPropSetInfo );
3305 }
3410
3306
3411 {
3412 XMLTextCharStyleNamesElementExport aCharStylesExport(
3413 GetExport(), bIsUICharStyle &&
3414 aCharStyleNamesPropInfoCache.hasProperty(
3415 xPropSet, xPropSetInfo ), bHasAutoStyle,
3416 xPropSet, sCharStyleNames );
3307 if ( bHyperlink && bHyperlinkAttrsAdded )
3308 {
3309 SvXMLElementExport aElem( GetExport(), sal_True, XML_NAMESPACE_TEXT, XML_A, sal_False, sal_False );
3417
3310
3418 OUString aText(rTextRange->getString());
3419 if( sStyle.getLength() )
3420 GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME,
3421 GetExport().EncodeStyleName( sStyle ) );
3422 {
3423 // in a block to make sure it is destroyed before the text:a element
3424 SvXMLElementExport aElement( GetExport(), sStyle.getLength() > 0,
3425 XML_NAMESPACE_TEXT, XML_SPAN, sal_False,
3426 sal_False );
3427 exportText( aText, rPrevCharIsSpace );
3428 }
3429 }
3430 }
3311 // export events (if supported)
3312 static const OUString sHyperLinkEvents( RTL_CONSTASCII_USTRINGPARAM( "HyperLinkEvents" ) );
3313 if ( xPropSetInfo->hasPropertyByName( sHyperLinkEvents ) )
3314 {
3315 Reference< XNameReplace > xName( xPropSet->getPropertyValue( sHyperLinkEvents ), uno::UNO_QUERY );
3316 GetExport().GetEventExport().Export( xName, sal_False );
3317 }
3318
3319 exportTextRangeSpan( rTextRange, xPropSet, xPropSetInfo, bIsUICharStyle, bHasAutoStyle, sStyle, rPrevCharIsSpace );
3320 }
3321 else
3322 {
3323 exportTextRangeSpan( rTextRange, xPropSet, xPropSetInfo, bIsUICharStyle, bHasAutoStyle, sStyle, rPrevCharIsSpace );
3324 }
3325 }
3431}
3432
3433void XMLTextParagraphExport::exportText( const OUString& rText,
3434 sal_Bool& rPrevCharIsSpace )
3435{
3436 sal_Int32 nExpStartPos = 0;
3437 sal_Int32 nEndPos = rText.getLength();
3438 sal_Int32 nSpaceChars = 0;

--- 445 unchanged lines hidden ---
3326}
3327
3328void XMLTextParagraphExport::exportText( const OUString& rText,
3329 sal_Bool& rPrevCharIsSpace )
3330{
3331 sal_Int32 nExpStartPos = 0;
3332 sal_Int32 nEndPos = rText.getLength();
3333 sal_Int32 nSpaceChars = 0;

--- 445 unchanged lines hidden ---