/* -*- 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 "backhdl.hxx" #include #include #include #include #include #include #include using namespace ::com::sun::star; using namespace ::xmloff::token; SvXMLEnumMapEntry const pXML_BrushHorizontalPos[] = { { XML_LEFT, style::GraphicLocation_LEFT_MIDDLE }, { XML_RIGHT, style::GraphicLocation_RIGHT_MIDDLE }, { XML_TOKEN_INVALID, style::GraphicLocation(0) } }; SvXMLEnumMapEntry const pXML_BrushVerticalPos[] = { { XML_TOP, style::GraphicLocation_MIDDLE_TOP }, { XML_BOTTOM, style::GraphicLocation_MIDDLE_BOTTOM }, { XML_TOKEN_INVALID, style::GraphicLocation(0) } }; XMLBackGraphicPositionPropHdl::~XMLBackGraphicPositionPropHdl() { // Nothing to do } bool XMLBackGraphicPositionPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const { bool bRet = true; style::GraphicLocation ePos = style::GraphicLocation_NONE, eTmp; style::GraphicLocation nTmpGraphicLocation; SvXMLTokenEnumerator aTokenEnum( rStrImpValue ); std::u16string_view aToken; bool bHori = false, bVert = false; while( bRet && aTokenEnum.getNextToken( aToken ) ) { if( bHori && bVert ) { bRet = false; } else if( std::u16string_view::npos != aToken.find( '%' ) ) { sal_Int32 nPrc = 50; if (::sax::Converter::convertPercent( nPrc, aToken )) { if( !bHori ) { ePos = nPrc < 25 ? style::GraphicLocation_LEFT_TOP : (nPrc < 75 ? style::GraphicLocation_MIDDLE_MIDDLE : style::GraphicLocation_RIGHT_BOTTOM); bHori = true; } else { eTmp = nPrc < 25 ? style::GraphicLocation_LEFT_TOP: (nPrc < 75 ? style::GraphicLocation_LEFT_MIDDLE : style::GraphicLocation_LEFT_BOTTOM); MergeXMLVertPos( ePos, eTmp ); bVert = true; } } else { // wrong percentage bRet = false; } } else if( IsXMLToken( aToken, XML_CENTER ) ) { if( bHori ) MergeXMLVertPos( ePos, style::GraphicLocation_MIDDLE_MIDDLE ); else if ( bVert ) MergeXMLHoriPos( ePos, style::GraphicLocation_MIDDLE_MIDDLE ); else ePos = style::GraphicLocation_MIDDLE_MIDDLE; } else if( SvXMLUnitConverter::convertEnum( nTmpGraphicLocation, aToken, pXML_BrushHorizontalPos ) ) { if( bVert ) MergeXMLHoriPos( ePos, nTmpGraphicLocation ); else if( !bHori ) ePos = nTmpGraphicLocation; else bRet = false; bHori = true; } else if( SvXMLUnitConverter::convertEnum( nTmpGraphicLocation, aToken, pXML_BrushVerticalPos ) ) { if( bHori ) MergeXMLVertPos( ePos, nTmpGraphicLocation ); else if( !bVert ) ePos = nTmpGraphicLocation; else bRet = false; bVert = true; } else { bRet = false; } } bRet &= style::GraphicLocation_NONE != ePos; if( bRet ) rValue <<= static_cast(static_cast(ePos)); return bRet; } bool XMLBackGraphicPositionPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const { bool bRet = true; OUStringBuffer aOut; style::GraphicLocation eLocation; if( !( rValue >>= eLocation ) ) { sal_Int32 nValue = 0; if( rValue >>= nValue ) eLocation = static_cast(nValue); else bRet = false; } if( bRet ) { bRet = false; switch( eLocation ) { case style::GraphicLocation_LEFT_TOP: case style::GraphicLocation_MIDDLE_TOP: case style::GraphicLocation_RIGHT_TOP: aOut.append( GetXMLToken(XML_TOP) ); bRet = true; break; case style::GraphicLocation_LEFT_MIDDLE: case style::GraphicLocation_MIDDLE_MIDDLE: case style::GraphicLocation_RIGHT_MIDDLE: aOut.append( GetXMLToken(XML_CENTER) ); bRet = true; break; case style::GraphicLocation_LEFT_BOTTOM: case style::GraphicLocation_MIDDLE_BOTTOM: case style::GraphicLocation_RIGHT_BOTTOM: aOut.append( GetXMLToken(XML_BOTTOM) ); bRet = true; break; default: break; } if( bRet ) { aOut.append( ' ' ); switch( eLocation ) { case style::GraphicLocation_LEFT_TOP: case style::GraphicLocation_LEFT_BOTTOM: case style::GraphicLocation_LEFT_MIDDLE: aOut.append( GetXMLToken(XML_LEFT) ); break; case style::GraphicLocation_MIDDLE_TOP: case style::GraphicLocation_MIDDLE_MIDDLE: case style::GraphicLocation_MIDDLE_BOTTOM: aOut.append( GetXMLToken(XML_CENTER) ); break; case style::GraphicLocation_RIGHT_MIDDLE: case style::GraphicLocation_RIGHT_TOP: case style::GraphicLocation_RIGHT_BOTTOM: aOut.append( GetXMLToken(XML_RIGHT) ); break; default: break; } } } rStrExpValue = aOut.makeStringAndClear(); return bRet; } void XMLBackGraphicPositionPropHdl::MergeXMLVertPos( style::GraphicLocation& ePos, style::GraphicLocation eVert ) { switch( ePos ) { case style::GraphicLocation_LEFT_TOP: case style::GraphicLocation_LEFT_MIDDLE: case style::GraphicLocation_LEFT_BOTTOM: ePos = style::GraphicLocation_MIDDLE_TOP==eVert ? style::GraphicLocation_LEFT_TOP : (style::GraphicLocation_MIDDLE_MIDDLE==eVert ? style::GraphicLocation_LEFT_MIDDLE : style::GraphicLocation_LEFT_BOTTOM); break; case style::GraphicLocation_MIDDLE_TOP: case style::GraphicLocation_MIDDLE_MIDDLE: case style::GraphicLocation_MIDDLE_BOTTOM: ePos = eVert; break; case style::GraphicLocation_RIGHT_TOP: case style::GraphicLocation_RIGHT_MIDDLE: case style::GraphicLocation_RIGHT_BOTTOM: ePos = style::GraphicLocation_MIDDLE_TOP==eVert ? style::GraphicLocation_RIGHT_TOP : (style::GraphicLocation_MIDDLE_MIDDLE==eVert ? style::GraphicLocation_RIGHT_MIDDLE : style::GraphicLocation_RIGHT_BOTTOM); break; default: break; } } void XMLBackGraphicPositionPropHdl::MergeXMLHoriPos( style::GraphicLocation& ePos, style::GraphicLocation eHori ) { SAL_WARN_IF( !(style::GraphicLocation_LEFT_MIDDLE==eHori || style::GraphicLocation_MIDDLE_MIDDLE==eHori || style::GraphicLocation_RIGHT_MIDDLE==eHori), "xmloff", "lcl_frmitems_MergeXMLHoriPos: vertical pos must be middle" ); switch( ePos ) { case style::GraphicLocation_LEFT_TOP: case style::GraphicLocation_MIDDLE_TOP: case style::GraphicLocation_RIGHT_TOP: ePos = style::GraphicLocation_LEFT_MIDDLE==eHori ? style::GraphicLocation_LEFT_TOP : (style::GraphicLocation_MIDDLE_MIDDLE==eHori ? style::GraphicLocation_MIDDLE_TOP : style::GraphicLocation_RIGHT_TOP); break; case style::GraphicLocation_LEFT_MIDDLE: case style::GraphicLocation_MIDDLE_MIDDLE: case style::GraphicLocation_RIGHT_MIDDLE: ePos = eHori; break; case style::GraphicLocation_LEFT_BOTTOM: case style::GraphicLocation_MIDDLE_BOTTOM: case style::GraphicLocation_RIGHT_BOTTOM: ePos = style::GraphicLocation_LEFT_MIDDLE==eHori ? style::GraphicLocation_LEFT_BOTTOM : (style::GraphicLocation_MIDDLE_MIDDLE==eHori ? style::GraphicLocation_MIDDLE_BOTTOM : style::GraphicLocation_RIGHT_BOTTOM); break; default: break; } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ re/OperationSmiley LibreOffice 核心代码仓库文档基金会
summaryrefslogtreecommitdiff
AgeCommit message (Expand)Author
2024-11-27PVS: V560 A part of conditional expression is always true: bRotate90Xisco Fauli
2024-11-19improve loplugin passparamsbyrefNoel Grandin
2024-07-30tdf#161846 remove one layout operations (iii)Noel Grandin
2024-07-23cid#1555167 COPY_INSTEAD_OF_MOVECaolán McNamara
2023-12-30move IsFuzzing to comphelperCaolán McNamara
2023-07-10svx: prefix members of GeoStatMiklos Vajna
2023-03-05svx: remove unneeded rectangle initsTomaž Vajngerl
2023-03-04svx: change Poly2Rect to return a rectangle, also clean-up the codeTomaž Vajngerl
2023-03-04svx: SdrTextObj maRect - use getter and add funcs. for manipulationTomaž Vajngerl
2023-01-26ofz#54906 TimeoutCaolán McNamara
2022-09-03crashtesting: fix use-after-freeCaolán McNamara
2022-08-29ref-count SdrObjectNoel Grandin
2022-08-24tools: rename Rectangle::Justify() to Rectangle::Normalize()Chris Sherlock
2022-07-29svx: manipulate SdrObject::m_aOutRect indirectlyTomaž Vajngerl
2022-07-25loplugin:moveitNoel Grandin
2022-01-07remove E3D_INVENTOR_FLAG and convert SdrObjKind to scoped enumNoel Grandin
2021-12-05improve ImpConvertContainedTextToSdrPathObjsNoel Grandin
2021-12-04use visitor in getViewIndependentPrimitive2DContainerNoel Grandin
2021-08-20Revert "ofz#37370 Null-dereference"Caolán McNamara
2021-08-19ofz#37370 Null-dereferenceCaolán McNamara
2021-08-17rename SetRectsDirty->SetBoundAndSnapRectsDirtyNoel Grandin
2021-06-19svx: prefix member variables for SdrTextObj and othersTomaž Vajngerl
2021-04-12svx: prefix members of SdrObjectMiklos Vajna
2021-01-02introduce Degree100 strong_int typeNoel
2020-12-22rename members of GeoStat classNoel
2020-10-26switching long to a 64-bit type on 64-bit windowsNoel