Kaydet (Commit) cb628728 authored tarafından Armin Le Grand's avatar Armin Le Grand

RotateFlyFrameFix: im/export rotation in deg

Unified im/export of rotation at FlyFrame Graphics to
not write their internal old 10th degree format, but to
use deg notation and the correct orientation. Extended
the mechanism to use tooling (SdXMLImExTransform2D) to
completely read/write 'draw:transform' statements. Added
quite some comments due to stuff in the old mechanism(s)

Change-Id: I7d265c1a05532a0dd9b921e383c10b477b4c8846
Reviewed-on: https://gerrit.libreoffice.org/47335Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarArmin Le Grand <Armin.Le.Grand@cib.de>
üst 63a10765
......@@ -55,6 +55,7 @@
#include <basegfx/polygon/b2dpolygontools.hxx>
#include <basegfx/matrix/b2dhommatrixtools.hxx>
#include <basegfx/polygon/b2dpolypolygontools.hxx>
#include <basegfx/numeric/ftools.hxx>
#include <map>
using namespace ::com::sun::star;
......@@ -982,23 +983,41 @@ XMLTextFrameContext_Impl::XMLTextFrameContext_Impl(
break;
case XML_TOK_TEXT_FRAME_TRANSFORM:
{
OUString sValue( rValue );
sValue = sValue.trim();
const OUString& aRotate(GetXMLToken(XML_ROTATE));
const sal_Int32 nRotateLen(aRotate.getLength());
sal_Int32 nLen = sValue.getLength();
if( nLen >= nRotateLen+3 &&
sValue.startsWith(aRotate) &&
'(' == sValue[nRotateLen] &&
')' == sValue[nLen-1] )
// RotateFlyFrameFix: im/export full 'draw:transform' using existing tooling
// Currently only rotation is used, but combinations with 'draw:transform'
// may be necessary in the future, so that svg:x/svg:y/svg:width/svg:height
// may be extended/replaced with 'draw:transform' (see draw objects)
SdXMLImExTransform2D aSdXMLImExTransform2D;
basegfx::B2DHomMatrix aFullTransform;
// use SdXMLImExTransform2D to conert to transformation
// Note: using GetTwipUnitConverter instead of GetMM100UnitConverter may be needed,
// but is not generally available (as it should be, a 'current' UnitConverter should
// be available at GetExport() - and maybe was once). May have to be adressed as soon
// as translate transformations are used here.
aSdXMLImExTransform2D.SetString(rValue, GetImport().GetMM100UnitConverter());
aSdXMLImExTransform2D.GetFullTransform(aFullTransform);
if(!aFullTransform.isIdentity())
{
sValue = sValue.copy( nRotateLen+1, nLen-(nRotateLen+2) );
sValue = sValue.trim();
sal_Int32 nVal;
if (::sax::Converter::convertNumber( nVal, sValue ))
const basegfx::utils::B2DHomMatrixBufferedDecompose aDecomposedTransform(aFullTransform);
// currently we *only* use rotation, so warn if *any* of the other transform parts is used
SAL_WARN_IF(!basegfx::fTools::equal(1.0, aDecomposedTransform.getScale().getX()), "xmloff.text", "draw:transform uses scaleX" );
SAL_WARN_IF(!basegfx::fTools::equal(1.0, aDecomposedTransform.getScale().getY()), "xmloff.text", "draw:transform uses scaleY" );
SAL_WARN_IF(!basegfx::fTools::equalZero(aDecomposedTransform.getTranslate().getX()), "xmloff.text", "draw:transform uses translateX" );
SAL_WARN_IF(!basegfx::fTools::equalZero(aDecomposedTransform.getTranslate().getY()), "xmloff.text", "draw:transform uses translateY" );
SAL_WARN_IF(!basegfx::fTools::equalZero(aDecomposedTransform.getShearX()), "xmloff.text", "draw:transform uses shearX" );
if(!basegfx::fTools::equalZero(aDecomposedTransform.getRotate()))
{
// RotGrfFlyFrame: is in 10th degrees
nRotation = (sal_Int16)(nVal % 3600 );
// rotation is used, set it. Convert from deg to 10th degree integer
// CAUTION: due to #i78696# (rotation mirrored using API) the rotate
// value is already mirrored, so do not do it again here (to be in sync
// with XMLTextParagraphExport::_exportTextGraphic normally it would need
// to me mirrored using * -1.0, see converion there)
const double fRotate(aDecomposedTransform.getRotate() * (1800.0/M_PI));
nRotation = static_cast< sal_Int16 >(fRotate) % 3600;
}
}
}
......
......@@ -3036,13 +3036,29 @@ void XMLTextParagraphExport::_exportTextGraphic(
rPropSet->getPropertyValue( sGraphicRotation ) >>= nVal;
if( nVal != 0 )
{
OUStringBuffer sRet( GetXMLToken(XML_ROTATE).getLength()+4 );
sRet.append( GetXMLToken(XML_ROTATE));
sRet.append( '(' );
sRet.append( (sal_Int32)nVal );
sRet.append( ')' );
GetExport().AddAttribute( XML_NAMESPACE_DRAW, XML_TRANSFORM,
sRet.makeStringAndClear() );
// RotateFlyFrameFix: im/export full 'draw:transform' using existing tooling.
// Currently only rotation is used, but combinations with 'draw:transform'
// may be necessary in the future, so that svg:x/svg:y/svg:width/svg:height
// may be extended/replaced with 'draw:transform' (see draw objects)
SdXMLImExTransform2D aSdXMLImExTransform2D;
// Convert from 10th degree integer to deg.
// CAUTION: Internal rotation is classically mathematically 'wrong' defined by ignoring that
// we have a right-handed coordinate system, so need to correct this by mirroring
// the rotation to get the correct transformation. See also case XML_TOK_TEXT_FRAME_TRANSFORM
// in XMLTextFrameContext_Impl::XMLTextFrameContext_Impl and #i78696#
const double fRotate(static_cast< double >(-nVal) * (M_PI/1800.0));
aSdXMLImExTransform2D.AddRotate(fRotate);
// Note: using GetTwipUnitConverter instead of GetMM100UnitConverter may be needed,
// but is not generally available (as it should be, a 'current' UnitConverter should
// be available at GetExport() - and maybe was once). May have to be adressed as soon
// as translate transformations are used here.
GetExport().AddAttribute(
XML_NAMESPACE_DRAW,
XML_TRANSFORM,
aSdXMLImExTransform2D.GetExportString(GetExport().GetMM100UnitConverter()));
}
// original content
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment