Files
libreoffice/drawinglayer/source/primitive3d/hatchtextureprimitive3d.cxx

324 lines
17 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 .
*/
2006-05-12 10:54:47 +00:00
#include <drawinglayer/primitive3d/hatchtextureprimitive3d.hxx>
#include <drawinglayer/primitive3d/polypolygonprimitive3d.hxx>
#include <basegfx/polygon/b2dpolypolygon.hxx>
#include <basegfx/polygon/b3dpolygon.hxx>
#include <basegfx/polygon/b2dpolygon.hxx>
#include <basegfx/polygon/b2dpolypolygontools.hxx>
2006-10-19 09:40:02 +00:00
#include <basegfx/range/b2drange.hxx>
#include <drawinglayer/texture/texture.hxx>
2006-05-12 10:54:47 +00:00
#include <basegfx/polygon/b2dpolygonclipper.hxx>
#include <basegfx/matrix/b3dhommatrix.hxx>
#include <drawinglayer/primitive3d/polygonprimitive3d.hxx>
2007-03-06 11:36:13 +00:00
#include <drawinglayer/primitive3d/drawinglayer_primitivetypes3d.hxx>
2006-10-19 09:40:02 +00:00
using namespace com::sun::star;
2006-05-12 10:54:47 +00:00
namespace drawinglayer
{
2006-08-09 15:51:16 +00:00
namespace primitive3d
2006-05-12 10:54:47 +00:00
{
Primitive3DContainer HatchTexturePrimitive3D::impCreate3DDecomposition() const
2006-05-12 10:54:47 +00:00
{
Primitive3DContainer aRetval;
2006-10-19 09:40:02 +00:00
if(!getChildren().empty())
2006-05-12 10:54:47 +00:00
{
const Primitive3DContainer aSource(getChildren());
const size_t nSourceCount(aSource.size());
2006-10-19 09:40:02 +00:00
std::vector< Primitive3DReference > aDestination;
2006-05-12 10:54:47 +00:00
for(size_t a(0); a < nSourceCount; a++)
2006-05-12 10:54:47 +00:00
{
2006-10-19 09:40:02 +00:00
// get reference
const Primitive3DReference xReference(aSource[a]);
if(xReference.is())
2006-05-12 10:54:47 +00:00
{
2006-10-19 09:40:02 +00:00
// try to cast to BasePrimitive2D implementation
const BasePrimitive3D* pBasePrimitive = dynamic_cast< const BasePrimitive3D* >(xReference.get());
2006-05-12 10:54:47 +00:00
2006-10-19 09:40:02 +00:00
if(pBasePrimitive)
2006-05-12 10:54:47 +00:00
{
// it is a BasePrimitive3D implementation, use getPrimitive3DID() call for switch
2006-10-19 09:40:02 +00:00
// not all content is needed, remove transparencies and ModifiedColorPrimitives
switch(pBasePrimitive->getPrimitive3DID())
2006-05-12 10:54:47 +00:00
{
2007-03-06 11:36:13 +00:00
case PRIMITIVE3D_ID_POLYPOLYGONMATERIALPRIMITIVE3D :
2006-05-12 10:54:47 +00:00
{
2006-10-19 09:40:02 +00:00
// polyPolygonMaterialPrimitive3D, check texturing and hatching
const PolyPolygonMaterialPrimitive3D& rPrimitive = static_cast< const PolyPolygonMaterialPrimitive3D& >(*pBasePrimitive);
const basegfx::B3DPolyPolygon& aFillPolyPolygon(rPrimitive.getB3DPolyPolygon());
2006-05-12 10:54:47 +00:00
2006-10-19 09:40:02 +00:00
if(maHatch.isFillBackground())
2006-05-12 10:54:47 +00:00
{
2006-10-19 09:40:02 +00:00
// add original primitive for background
aDestination.push_back(xReference);
2006-05-12 10:54:47 +00:00
}
2006-10-19 09:40:02 +00:00
if(aFillPolyPolygon.areTextureCoordinatesUsed())
{
const sal_uInt32 nPolyCount(aFillPolyPolygon.count());
basegfx::B2DPolyPolygon aTexPolyPolygon;
basegfx::B2DPoint a2N;
basegfx::B2DVector a2X, a2Y;
basegfx::B3DPoint a3N;
basegfx::B3DVector a3X, a3Y;
bool b2N(false), b2X(false), b2Y(false);
for(sal_uInt32 b(0); b < nPolyCount; b++)
2006-05-12 10:54:47 +00:00
{
2006-12-13 15:57:09 +00:00
const basegfx::B3DPolygon aPartPoly(aFillPolyPolygon.getB3DPolygon(b));
2006-10-19 09:40:02 +00:00
const sal_uInt32 nPointCount(aPartPoly.count());
basegfx::B2DPolygon aTexPolygon;
for(sal_uInt32 c(0); c < nPointCount; c++)
2006-10-19 09:40:02 +00:00
{
2006-12-13 15:57:09 +00:00
const basegfx::B2DPoint a2Candidate(aPartPoly.getTextureCoordinate(c));
2006-10-19 09:40:02 +00:00
if(!b2N)
{
a2N = a2Candidate;
2006-12-13 15:57:09 +00:00
a3N = aPartPoly.getB3DPoint(c);
2006-10-19 09:40:02 +00:00
b2N = true;
}
else if(!b2X && !a2N.equal(a2Candidate))
{
a2X = a2Candidate - a2N;
2006-12-13 15:57:09 +00:00
a3X = aPartPoly.getB3DPoint(c) - a3N;
2006-10-19 09:40:02 +00:00
b2X = true;
}
else if(!b2Y && !a2N.equal(a2Candidate) && !a2X.equal(a2Candidate))
{
a2Y = a2Candidate - a2N;
const double fCross(a2X.cross(a2Y));
if(!basegfx::fTools::equalZero(fCross))
{
2006-12-13 15:57:09 +00:00
a3Y = aPartPoly.getB3DPoint(c) - a3N;
2006-10-19 09:40:02 +00:00
b2Y = true;
}
}
aTexPolygon.append(a2Candidate);
}
aTexPolygon.setClosed(true);
aTexPolyPolygon.append(aTexPolygon);
2006-05-12 10:54:47 +00:00
}
2006-10-19 09:40:02 +00:00
if(b2N && b2X && b2Y)
{
// found two linearly independent 2D vectors
// get 2d range of texture coordinates
const basegfx::B2DRange aOutlineRange(basegfx::tools::getRange(aTexPolyPolygon));
const basegfx::BColor aHatchColor(getHatch().getColor());
const double fAngle(getHatch().getAngle());
2006-10-19 09:40:02 +00:00
::std::vector< basegfx::B2DHomMatrix > aMatrices;
// get hatch transformations
switch(getHatch().getStyle())
{
case attribute::HatchStyle::Triple:
2006-10-19 09:40:02 +00:00
{
// rotated 45 degrees
Merge back branch alg_writerframes to trunk (cherry picked from commit b635b4fa4e42053d30ab639643d2236a20243f62) Conflicts: comphelper/inc/comphelper/TypeGeneration.hxx comphelper/source/property/TypeGeneration.cxx cui/source/factory/dlgfact.hxx cui/source/inc/cuitabarea.hxx cui/source/tabpages/tabarea.cxx cui/source/tabpages/tabarea.hrc cui/source/tabpages/tabarea.src cui/source/tabpages/tparea.cxx drawinglayer/source/primitive2d/polypolygonprimitive2d.cxx drawinglayer/source/processor2d/vclmetafileprocessor2d.cxx drawinglayer/source/texture/texture.cxx editeng/inc/editeng/unotext.hxx editeng/source/items/frmitems.cxx include/drawinglayer/texture/texture.hxx include/editeng/brushitem.hxx include/svx/sdr/primitive2d/sdrdecompositiontools.hxx include/svx/svxids.hrc include/xmloff/xmltypes.hxx reportdesign/source/ui/misc/UITools.cxx sc/source/ui/drawfunc/drawsh.cxx sfx2/source/dialog/tabdlg.cxx svl/source/undo/undo.cxx svx/inc/svx/unoshprp.hxx sw/Library_sw.mk sw/inc/doc.hxx sw/inc/format.hxx sw/inc/frmfmt.hxx sw/inc/swatrset.hxx sw/inc/unomap.hxx sw/inc/unoprnms.hxx sw/source/core/access/accpara.cxx sw/source/core/attr/format.cxx sw/source/core/attr/swatrset.cxx sw/source/core/doc/docdraw.cxx sw/source/core/doc/docfly.cxx sw/source/core/doc/notxtfrm.cxx sw/source/core/inc/frame.hxx sw/source/core/inc/frmtool.hxx sw/source/core/layout/atrfrm.cxx sw/source/core/layout/paintfrm.cxx sw/source/core/text/inftxt.cxx sw/source/core/text/porfld.cxx sw/source/core/text/txtfly.cxx sw/source/core/txtnode/fntcache.cxx sw/source/core/uibase/app/docst.cxx sw/source/core/uibase/app/docstyle.cxx sw/source/core/uibase/shells/drawdlg.cxx sw/source/core/uibase/shells/frmsh.cxx sw/source/core/unocore/unoframe.cxx sw/source/core/unocore/unomap.cxx sw/source/core/unocore/unoprnms.cxx sw/source/core/unocore/unostyle.cxx sw/source/ui/fmtui/tmpdlg.cxx sw/source/ui/fmtui/tmpdlg.src sw/source/ui/frmdlg/frmdlg.cxx sw/source/ui/frmdlg/frmpage.src sw/source/ui/inc/frmsh.hxx xmloff/source/text/txtprhdl.cxx xmloff/source/text/txtprmap.cxx Change-Id: Id3ffaa83bb5594d287f1ac8f2c1c9cf55c70946d
2014-03-19 16:17:02 +00:00
texture::GeoTexSvxHatch aHatch(
aOutlineRange,
aOutlineRange,
getHatch().getDistance(),
fAngle - F_PI4);
2006-10-19 09:40:02 +00:00
aHatch.appendTransformations(aMatrices);
SAL_FALLTHROUGH;
2006-10-19 09:40:02 +00:00
}
case attribute::HatchStyle::Double:
2006-10-19 09:40:02 +00:00
{
// rotated 90 degrees
Merge back branch alg_writerframes to trunk (cherry picked from commit b635b4fa4e42053d30ab639643d2236a20243f62) Conflicts: comphelper/inc/comphelper/TypeGeneration.hxx comphelper/source/property/TypeGeneration.cxx cui/source/factory/dlgfact.hxx cui/source/inc/cuitabarea.hxx cui/source/tabpages/tabarea.cxx cui/source/tabpages/tabarea.hrc cui/source/tabpages/tabarea.src cui/source/tabpages/tparea.cxx drawinglayer/source/primitive2d/polypolygonprimitive2d.cxx drawinglayer/source/processor2d/vclmetafileprocessor2d.cxx drawinglayer/source/texture/texture.cxx editeng/inc/editeng/unotext.hxx editeng/source/items/frmitems.cxx include/drawinglayer/texture/texture.hxx include/editeng/brushitem.hxx include/svx/sdr/primitive2d/sdrdecompositiontools.hxx include/svx/svxids.hrc include/xmloff/xmltypes.hxx reportdesign/source/ui/misc/UITools.cxx sc/source/ui/drawfunc/drawsh.cxx sfx2/source/dialog/tabdlg.cxx svl/source/undo/undo.cxx svx/inc/svx/unoshprp.hxx sw/Library_sw.mk sw/inc/doc.hxx sw/inc/format.hxx sw/inc/frmfmt.hxx sw/inc/swatrset.hxx sw/inc/unomap.hxx sw/inc/unoprnms.hxx sw/source/core/access/accpara.cxx sw/source/core/attr/format.cxx sw/source/core/attr/swatrset.cxx sw/source/core/doc/docdraw.cxx sw/source/core/doc/docfly.cxx sw/source/core/doc/notxtfrm.cxx sw/source/core/inc/frame.hxx sw/source/core/inc/frmtool.hxx sw/source/core/layout/atrfrm.cxx sw/source/core/layout/paintfrm.cxx sw/source/core/text/inftxt.cxx sw/source/core/text/porfld.cxx sw/source/core/text/txtfly.cxx sw/source/core/txtnode/fntcache.cxx sw/source/core/uibase/app/docst.cxx sw/source/core/uibase/app/docstyle.cxx sw/source/core/uibase/shells/drawdlg.cxx sw/source/core/uibase/shells/frmsh.cxx sw/source/core/unocore/unoframe.cxx sw/source/core/unocore/unomap.cxx sw/source/core/unocore/unoprnms.cxx sw/source/core/unocore/unostyle.cxx sw/source/ui/fmtui/tmpdlg.cxx sw/source/ui/fmtui/tmpdlg.src sw/source/ui/frmdlg/frmdlg.cxx sw/source/ui/frmdlg/frmpage.src sw/source/ui/inc/frmsh.hxx xmloff/source/text/txtprhdl.cxx xmloff/source/text/txtprmap.cxx Change-Id: Id3ffaa83bb5594d287f1ac8f2c1c9cf55c70946d
2014-03-19 16:17:02 +00:00
texture::GeoTexSvxHatch aHatch(
aOutlineRange,
aOutlineRange,
getHatch().getDistance(),
fAngle - F_PI2);
2006-10-19 09:40:02 +00:00
aHatch.appendTransformations(aMatrices);
SAL_FALLTHROUGH;
2006-10-19 09:40:02 +00:00
}
case attribute::HatchStyle::Single:
2006-10-19 09:40:02 +00:00
{
// angle as given
Merge back branch alg_writerframes to trunk (cherry picked from commit b635b4fa4e42053d30ab639643d2236a20243f62) Conflicts: comphelper/inc/comphelper/TypeGeneration.hxx comphelper/source/property/TypeGeneration.cxx cui/source/factory/dlgfact.hxx cui/source/inc/cuitabarea.hxx cui/source/tabpages/tabarea.cxx cui/source/tabpages/tabarea.hrc cui/source/tabpages/tabarea.src cui/source/tabpages/tparea.cxx drawinglayer/source/primitive2d/polypolygonprimitive2d.cxx drawinglayer/source/processor2d/vclmetafileprocessor2d.cxx drawinglayer/source/texture/texture.cxx editeng/inc/editeng/unotext.hxx editeng/source/items/frmitems.cxx include/drawinglayer/texture/texture.hxx include/editeng/brushitem.hxx include/svx/sdr/primitive2d/sdrdecompositiontools.hxx include/svx/svxids.hrc include/xmloff/xmltypes.hxx reportdesign/source/ui/misc/UITools.cxx sc/source/ui/drawfunc/drawsh.cxx sfx2/source/dialog/tabdlg.cxx svl/source/undo/undo.cxx svx/inc/svx/unoshprp.hxx sw/Library_sw.mk sw/inc/doc.hxx sw/inc/format.hxx sw/inc/frmfmt.hxx sw/inc/swatrset.hxx sw/inc/unomap.hxx sw/inc/unoprnms.hxx sw/source/core/access/accpara.cxx sw/source/core/attr/format.cxx sw/source/core/attr/swatrset.cxx sw/source/core/doc/docdraw.cxx sw/source/core/doc/docfly.cxx sw/source/core/doc/notxtfrm.cxx sw/source/core/inc/frame.hxx sw/source/core/inc/frmtool.hxx sw/source/core/layout/atrfrm.cxx sw/source/core/layout/paintfrm.cxx sw/source/core/text/inftxt.cxx sw/source/core/text/porfld.cxx sw/source/core/text/txtfly.cxx sw/source/core/txtnode/fntcache.cxx sw/source/core/uibase/app/docst.cxx sw/source/core/uibase/app/docstyle.cxx sw/source/core/uibase/shells/drawdlg.cxx sw/source/core/uibase/shells/frmsh.cxx sw/source/core/unocore/unoframe.cxx sw/source/core/unocore/unomap.cxx sw/source/core/unocore/unoprnms.cxx sw/source/core/unocore/unostyle.cxx sw/source/ui/fmtui/tmpdlg.cxx sw/source/ui/fmtui/tmpdlg.src sw/source/ui/frmdlg/frmdlg.cxx sw/source/ui/frmdlg/frmpage.src sw/source/ui/inc/frmsh.hxx xmloff/source/text/txtprhdl.cxx xmloff/source/text/txtprmap.cxx Change-Id: Id3ffaa83bb5594d287f1ac8f2c1c9cf55c70946d
2014-03-19 16:17:02 +00:00
texture::GeoTexSvxHatch aHatch(
aOutlineRange,
aOutlineRange,
getHatch().getDistance(),
fAngle);
2006-10-19 09:40:02 +00:00
aHatch.appendTransformations(aMatrices);
}
}
// create geometry from unit line
basegfx::B2DPolyPolygon a2DHatchLines;
basegfx::B2DPolygon a2DUnitLine;
a2DUnitLine.append(basegfx::B2DPoint(0.0, 0.0));
a2DUnitLine.append(basegfx::B2DPoint(1.0, 0.0));
for(basegfx::B2DHomMatrix & rMatrix : aMatrices)
2006-10-19 09:40:02 +00:00
{
basegfx::B2DPolygon aNewLine(a2DUnitLine);
aNewLine.transform(rMatrix);
a2DHatchLines.append(aNewLine);
}
if(a2DHatchLines.count())
{
// clip against texture polygon
2008-05-14 08:22:09 +00:00
a2DHatchLines = basegfx::tools::clipPolyPolygonOnPolyPolygon(a2DHatchLines, aTexPolyPolygon, true, true);
2006-10-19 09:40:02 +00:00
}
if(a2DHatchLines.count())
{
// create 2d matrix with 2d vectors as column vectors and 2d point as offset, this represents
// a coordinate system transformation from unit coordinates to the new coordinate system
basegfx::B2DHomMatrix a2D;
a2D.set(0, 0, a2X.getX());
a2D.set(1, 0, a2X.getY());
a2D.set(0, 1, a2Y.getX());
a2D.set(1, 1, a2Y.getY());
a2D.set(0, 2, a2N.getX());
a2D.set(1, 2, a2N.getY());
// invert that transformation, so we have a back-transformation from texture coordinates
// to unit coordinates
a2D.invert();
a2DHatchLines.transform(a2D);
// expand back-transformated geometry tpo 3D
basegfx::B3DPolyPolygon a3DHatchLines(basegfx::tools::createB3DPolyPolygonFromB2DPolyPolygon(a2DHatchLines, 0.0));
// create 3d matrix with 3d vectors as column vectors (0,0,1 as Z) and 3d point as offset, this represents
// a coordinate system transformation from unit coordinates to the object's 3d coordinate system
basegfx::B3DHomMatrix a3D;
a3D.set(0, 0, a3X.getX());
a3D.set(1, 0, a3X.getY());
a3D.set(2, 0, a3X.getZ());
a3D.set(0, 1, a3Y.getX());
a3D.set(1, 1, a3Y.getY());
a3D.set(2, 1, a3Y.getZ());
a3D.set(0, 3, a3N.getX());
a3D.set(1, 3, a3N.getY());
a3D.set(2, 3, a3N.getZ());
// transform hatch lines to 3D object coordinates
a3DHatchLines.transform(a3D);
// build primitives from this geometry
const sal_uInt32 nHatchLines(a3DHatchLines.count());
for(sal_uInt32 d(0); d < nHatchLines; d++)
2006-10-19 09:40:02 +00:00
{
const Primitive3DReference xRef(new PolygonHairlinePrimitive3D(a3DHatchLines.getB3DPolygon(d), aHatchColor));
2006-10-19 09:40:02 +00:00
aDestination.push_back(xRef);
}
}
}
2006-05-12 10:54:47 +00:00
}
2006-10-19 09:40:02 +00:00
break;
2006-05-12 10:54:47 +00:00
}
2006-10-19 09:40:02 +00:00
default :
2006-05-12 10:54:47 +00:00
{
2006-10-19 09:40:02 +00:00
// add reference to result
aDestination.push_back(xReference);
break;
2006-05-12 10:54:47 +00:00
}
}
}
2006-10-19 09:40:02 +00:00
else
2006-05-12 10:54:47 +00:00
{
2006-10-19 09:40:02 +00:00
// unknown implementation, add to result
aDestination.push_back(xReference);
2006-05-12 10:54:47 +00:00
}
}
2006-10-19 09:40:02 +00:00
}
2006-05-12 10:54:47 +00:00
2006-10-19 09:40:02 +00:00
// prepare return value
const sal_uInt32 nDestSize(aDestination.size());
aRetval.resize(nDestSize);
2006-10-19 09:40:02 +00:00
for(sal_uInt32 b(0); b < nDestSize; b++)
2006-10-19 09:40:02 +00:00
{
aRetval[b] = aDestination[b];
2006-05-12 10:54:47 +00:00
}
}
2006-10-19 09:40:02 +00:00
return aRetval;
2006-05-12 10:54:47 +00:00
}
2006-10-19 09:40:02 +00:00
HatchTexturePrimitive3D::HatchTexturePrimitive3D(
const attribute::FillHatchAttribute& rHatch,
const Primitive3DContainer& rChildren,
2006-08-09 15:51:16 +00:00
const basegfx::B2DVector& rTextureSize,
2006-05-12 10:54:47 +00:00
bool bModulate,
bool bFilter)
2006-10-19 09:40:02 +00:00
: TexturePrimitive3D(rChildren, rTextureSize, bModulate, bFilter),
maHatch(rHatch),
maBuffered3DDecomposition()
2006-05-12 10:54:47 +00:00
{
}
2006-10-19 09:40:02 +00:00
bool HatchTexturePrimitive3D::operator==(const BasePrimitive3D& rPrimitive) const
2006-05-12 10:54:47 +00:00
{
2006-10-19 09:40:02 +00:00
if(TexturePrimitive3D::operator==(rPrimitive))
2006-05-12 10:54:47 +00:00
{
const HatchTexturePrimitive3D& rCompare = static_cast<const HatchTexturePrimitive3D&>(rPrimitive);
2006-10-19 09:40:02 +00:00
return (getHatch() == rCompare.getHatch());
2006-05-12 10:54:47 +00:00
}
return false;
}
Primitive3DContainer HatchTexturePrimitive3D::get3DDecomposition(const geometry::ViewInformation3D& /*rViewInformation*/) const
{
::osl::MutexGuard aGuard( m_aMutex );
if(getBuffered3DDecomposition().empty())
{
const Primitive3DContainer aNewSequence(impCreate3DDecomposition());
const_cast< HatchTexturePrimitive3D* >(this)->maBuffered3DDecomposition = aNewSequence;
}
return getBuffered3DDecomposition();
}
// provide unique ID
ImplPrimitive3DIDBlock(HatchTexturePrimitive3D, PRIMITIVE3D_ID_HATCHTEXTUREPRIMITIVE3D)
2006-08-09 15:51:16 +00:00
} // end of namespace primitive3d
2006-05-12 10:54:47 +00:00
} // end of namespace drawinglayer
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */