Files
libreoffice/xmloff/source/draw/XMLGraphicsDefaultStyle.cxx

120 lines
4.5 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <xmloff/xmlimp.hxx>
#include <xmloff/nmspmap.hxx>
#include <xmloff/xmlnmspe.hxx>
#include <xmloff/xmltoken.hxx>
#include <xmloff/families.hxx>
#include "XMLShapePropertySetContext.hxx"
#include <xmloff/XMLGraphicsDefaultStyle.hxx>
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::xml::sax;
using ::xmloff::token::IsXMLToken;
using ::xmloff::token::XML_TEXT_PROPERTIES;
using ::xmloff::token::XML_GRAPHIC_PROPERTIES;
using ::xmloff::token::XML_PARAGRAPH_PROPERTIES;
TYPEINIT1( XMLGraphicsDefaultStyle, XMLPropStyleContext );
XMLGraphicsDefaultStyle::XMLGraphicsDefaultStyle( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName, const Reference< XAttributeList >& xAttrList, SvXMLStylesContext& rStyles )
: XMLPropStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles, XML_STYLE_FAMILY_SD_GRAPHICS_ID, sal_True )
{
}
XMLGraphicsDefaultStyle::~XMLGraphicsDefaultStyle()
{
}
SvXMLImportContext *XMLGraphicsDefaultStyle::CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const Reference< XAttributeList > & xAttrList )
{
SvXMLImportContext *pContext = 0;
if( XML_NAMESPACE_STYLE == nPrefix )
{
sal_uInt32 nFamily = 0;
if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) )
nFamily = XML_TYPE_PROP_TEXT;
else if( IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES ) )
nFamily = XML_TYPE_PROP_PARAGRAPH;
else if( IsXMLToken( rLocalName, XML_GRAPHIC_PROPERTIES ) )
nFamily = XML_TYPE_PROP_GRAPHIC;
if( nFamily )
{
UniReference < SvXMLImportPropertyMapper > xImpPrMap = GetStyles()->GetImportPropertyMapper( GetFamily() );
if( xImpPrMap.is() )
pContext = new XMLShapePropertySetContext( GetImport(), nPrefix, rLocalName, xAttrList, nFamily, GetProperties(), xImpPrMap );
}
}
if( !pContext )
pContext = XMLPropStyleContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
return pContext;
}
// This method is called for every default style
void XMLGraphicsDefaultStyle::SetDefaults()
{
Reference< XMultiServiceFactory > xFact( GetImport().GetModel(), UNO_QUERY );
if( !xFact.is() )
return;
Reference< XPropertySet > xDefaults( xFact->createInstance( "com.sun.star.drawing.Defaults" ), UNO_QUERY );
if( !xDefaults.is() )
return;
// SJ: #i114750#
sal_Bool bWordWrapDefault = sal_True; // initializing with correct ODF fo:wrap-option default
sal_Int32 nUPD( 0 );
sal_Int32 nBuild( 0 );
const bool bBuildIdFound = GetImport().getBuildIds( nUPD, nBuild );
if ( bBuildIdFound && (
((nUPD >= 600) && (nUPD < 700))
||
((nUPD == 300) && (nBuild <= 9535))
||
((nUPD > 300) && (nUPD <= 330))
2010-10-29 13:23:16 +02:00
) )
bWordWrapDefault = sal_False;
const OUString sTextWordWrap( "TextWordWrap" );
Reference< XPropertySetInfo > xInfo( xDefaults->getPropertySetInfo() );
if ( xInfo->hasPropertyByName( sTextWordWrap ) )
xDefaults->setPropertyValue( sTextWordWrap, Any( bWordWrapDefault ) );
if (GetImport().IsOOoXML()
i#119922: reverse engineer 9a37613b5e8f08fae585d54a5745e887eb08f8ce It is not quite obvious what that commit attempts to do... especially since the bugdoc attachment does not actually exercise the code that was added in the commit, which changes the handling of the "IsFollowingTextFlow" property. The corresponding ODF attribute is style:flow-with-text, which has been added in OOo 2.0. Investigation revels that MSO's ODF filter does not support this attribute and acts as if it always had value "false". The code in FillBaseProperties effectively acts as a default if the value is not set; the ODF spec does not specify what the default should be. But when an ODF document was written by MSO, "false" makes more sense than the previous "true" default. Except when the document is not ODF but OOoXML format, which indicates it's likely written by OOo 1.x which did not support the attribute and acts as if it always had value "true". The Writer UNO API implementation is however not the right place for format specific handling, so replace that with an addition to the function reading the default graphic style that sets the "IsFollowingTextFlow" property to false as a default, which should have the same effect because all styles inherit from it. Note: MSO 2010 Word always writes a default graphic style into ODF docs. This has a side effect for loaded ODF documents: various newly inserted objects have the property turned off then. But it turns out this is actually an advantage, since the same behavior already exists for _new_ documents (see SwDocShell::InitNew) so it is more consistent now. Change-Id: Iba6444a0515fd583398ff052fc5018254da31c30
2013-05-15 17:10:00 +02:00
&& xInfo->hasPropertyByName("IsFollowingTextFlow"))
{
// OOo 1.x only supported "true" so that is the more appropriate
// default for OOoXML format documents.
xDefaults->setPropertyValue("IsFollowingTextFlow", uno::makeAny(true));
i#119922: reverse engineer 9a37613b5e8f08fae585d54a5745e887eb08f8ce It is not quite obvious what that commit attempts to do... especially since the bugdoc attachment does not actually exercise the code that was added in the commit, which changes the handling of the "IsFollowingTextFlow" property. The corresponding ODF attribute is style:flow-with-text, which has been added in OOo 2.0. Investigation revels that MSO's ODF filter does not support this attribute and acts as if it always had value "false". The code in FillBaseProperties effectively acts as a default if the value is not set; the ODF spec does not specify what the default should be. But when an ODF document was written by MSO, "false" makes more sense than the previous "true" default. Except when the document is not ODF but OOoXML format, which indicates it's likely written by OOo 1.x which did not support the attribute and acts as if it always had value "true". The Writer UNO API implementation is however not the right place for format specific handling, so replace that with an addition to the function reading the default graphic style that sets the "IsFollowingTextFlow" property to false as a default, which should have the same effect because all styles inherit from it. Note: MSO 2010 Word always writes a default graphic style into ODF docs. This has a side effect for loaded ODF documents: various newly inserted objects have the property turned off then. But it turns out this is actually an advantage, since the same behavior already exists for _new_ documents (see SwDocShell::InitNew) so it is more consistent now. Change-Id: Iba6444a0515fd583398ff052fc5018254da31c30
2013-05-15 17:10:00 +02:00
}
FillPropertySet( xDefaults );
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */