/* -*- 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 .
*/
This is a special version of the FillGradientPrimitive2D which decomposes to a non-overlapping geometry version of the gradient. This needs to be used to support the old XOR paint-'trick'.
It does not need an own identifier since a renderer who wants to interpret it itself may do so. It just overrides the decomposition of the C++ implementation class to do an alternative decomposition.
*/ class NonOverlappingFillGradientPrimitive2D : public FillGradientPrimitive2D
{ protected: /// local decomposition. virtual Primitive2DReference create2DDecomposition( const geometry::ViewInformation2D& rViewInformation) const override;
namespace wmfemfhelper
{ /** helper class for graphic context
This class allows to hold a complete representation of classic VCL OutputDevice state. This data is needed for correct interpretation of the MetaFile action flow.
*/
PropertyHolder::PropertyHolder()
: maMapUnit(MapUnit::Map100thMM),
maTextColor(sal_uInt32(COL_BLACK)),
maRasterOp(RasterOp::OverPaint),
mnLayoutMode(vcl::text::ComplexTextLayoutFlags::Default),
maLanguageType(0),
mnPushFlags(vcl::PushFlags::NONE),
mbLineColor(false),
mbFillColor(false),
mbTextColor(true),
mbTextFillColor(false),
mbTextLineColor(false),
mbOverlineColor(false),
mbClipPolyPolygonActive(false)
{
}
}
namespace wmfemfhelper
{ /** stack for properties
This class builds a stack based on the PropertyHolder class. It encapsulates the pointer/new/delete usage to make it safe and implements the push/pop as needed by a VCL Metafile interpreter. The critical part here are the flag values VCL OutputDevice uses here; not all stuff is pushed and thus needs to be copied at pop.
*/
PropertyHolders::PropertyHolders()
{
maPropertyHolders.push_back(new PropertyHolder());
}
void PropertyHolders::PushDefault()
{
PropertyHolder* pNew = new PropertyHolder();
maPropertyHolders.push_back(pNew);
}
void PropertyHolders::Push(vcl::PushFlags nPushFlags)
{ if (bool(nPushFlags))
{
OSL_ENSURE(maPropertyHolders.size(), "PropertyHolders: PUSH with no property holders (!)"); if (!maPropertyHolders.empty())
{
PropertyHolder* pNew = new PropertyHolder(*maPropertyHolders.back());
pNew->setPushFlags(nPushFlags);
maPropertyHolders.push_back(pNew);
}
}
}
void PropertyHolders::Pop()
{
OSL_ENSURE(maPropertyHolders.size(), "PropertyHolders: POP with no property holders (!)"); const sal_uInt32 nSize(maPropertyHolders.size());
if (nPushFlags != vcl::PushFlags::NONE)
{ if (nSize > 1)
{ // copy back content for all non-set flags
PropertyHolder* pLast = maPropertyHolders[nSize - 2];
if (vcl::PushFlags::ALL != nPushFlags)
{ if (!(nPushFlags & vcl::PushFlags::LINECOLOR))
{
pLast->setLineColor(pTip->getLineColor());
pLast->setLineColorActive(pTip->getLineColorActive());
} if (!(nPushFlags & vcl::PushFlags::FILLCOLOR))
{
pLast->setFillColor(pTip->getFillColor());
pLast->setFillColorActive(pTip->getFillColorActive());
} if (!(nPushFlags & vcl::PushFlags::FONT))
{
pLast->setFont(pTip->getFont());
} if (!(nPushFlags & vcl::PushFlags::TEXTCOLOR))
{
pLast->setTextColor(pTip->getTextColor());
pLast->setTextColorActive(pTip->getTextColorActive());
} if (!(nPushFlags & vcl::PushFlags::MAPMODE))
{
pLast->setTransformation(pTip->getTransformation());
pLast->setMapUnit(pTip->getMapUnit());
} if (!(nPushFlags & vcl::PushFlags::CLIPREGION))
{
pLast->setClipPolyPolygon(pTip->getClipPolyPolygon());
pLast->setClipPolyPolygonActive(pTip->getClipPolyPolygonActive());
} if (!(nPushFlags & vcl::PushFlags::RASTEROP))
{
pLast->setRasterOp(pTip->getRasterOp());
} if (!(nPushFlags & vcl::PushFlags::TEXTFILLCOLOR))
{
pLast->setTextFillColor(pTip->getTextFillColor());
pLast->setTextFillColorActive(pTip->getTextFillColorActive());
} if (!(nPushFlags & vcl::PushFlags::TEXTALIGN))
{ if (pLast->getFont().GetAlignment() != pTip->getFont().GetAlignment())
{
vcl::Font aFont(pLast->getFont());
aFont.SetAlignment(pTip->getFont().GetAlignment());
pLast->setFont(aFont);
}
} if (!(nPushFlags & vcl::PushFlags::REFPOINT))
{ // not supported
} if (!(nPushFlags & vcl::PushFlags::TEXTLINECOLOR))
{
pLast->setTextLineColor(pTip->getTextLineColor());
pLast->setTextLineColorActive(pTip->getTextLineColorActive());
} if (!(nPushFlags & vcl::PushFlags::TEXTLAYOUTMODE))
{
pLast->setLayoutMode(pTip->getLayoutMode());
} if (!(nPushFlags & vcl::PushFlags::TEXTLANGUAGE))
{
pLast->setLanguageType(pTip->getLanguageType());
} if (!(nPushFlags & vcl::PushFlags::OVERLINECOLOR))
{
pLast->setOverlineColor(pTip->getOverlineColor());
pLast->setOverlineColorActive(pTip->getOverlineColorActive());
}
}
}
}
// execute the pop delete maPropertyHolders.back();
maPropertyHolders.pop_back();
}
PropertyHolder& PropertyHolders::Current()
{ static PropertyHolder aDummy;
OSL_ENSURE(maPropertyHolders.size(), "PropertyHolders: CURRENT with no property holders (!)"); return maPropertyHolders.empty() ? aDummy : *maPropertyHolders.back();
}
namespace
{ /** helper to convert a vcl::Region to a B2DPolyPolygon when it does not yet contain one. In the future this may be expanded to merge the polygons created from rectangles or use a special algo to directly turn the spans of regions to a single, already merged PolyPolygon.
*/
basegfx::B2DPolyPolygon getB2DPolyPolygonFromRegion(const vcl::Region& rRegion)
{
basegfx::B2DPolyPolygon aRetval;
if (!rRegion.IsEmpty())
{
aRetval = rRegion.GetAsB2DPolyPolygon();
}
return aRetval;
}
}
namespace wmfemfhelper
{ /** Helper class to buffer and hold a Primitive target vector. It encapsulates the new/delete functionality and allows to work on pointers of the implementation classes. All data will be converted to uno sequences of uno references when accessing the data.
*/
TargetHolder::TargetHolder()
{
}
if (!xRetval.empty() && rPropertyHolder.getClipPolyPolygonActive())
{ const basegfx::B2DPolyPolygon& rClipPolyPolygon = rPropertyHolder.getClipPolyPolygon();
if (rClipPolyPolygon.count())
{
xRetval = drawinglayer::primitive2d::Primitive2DContainer{ new drawinglayer::primitive2d::MaskPrimitive2D(
rClipPolyPolygon,
std::move(xRetval))
};
}
}
return xRetval;
}
}
namespace wmfemfhelper
{ /** Helper class which builds a stack on the TargetHolder class */
TargetHolders::TargetHolders()
{
maTargetHolders.push_back(new TargetHolder());
}
void TargetHolders::Pop()
{
OSL_ENSURE(maTargetHolders.size(), "TargetHolders: POP with no property holders (!)"); if (!maTargetHolders.empty())
{ delete maTargetHolders.back();
maTargetHolders.pop_back();
}
}
TargetHolder& TargetHolders::Current()
{ static TargetHolder aDummy;
OSL_ENSURE(maTargetHolders.size(), "TargetHolders: CURRENT with no property holders (!)"); return maTargetHolders.empty() ? aDummy : *maTargetHolders.back();
}
/** helper to create needed line and fill primitives based on current context */ staticvoid createHairlineAndFillPrimitive( const basegfx::B2DPolygon& rPolygon,
TargetHolder& rTarget,
PropertyHolder const & rProperties)
{ if(rProperties.getFillColorActive())
{
createFillPrimitive(basegfx::B2DPolyPolygon(rPolygon), rTarget, rProperties);
}
/** helper to create needed line and fill primitives based on current context */ staticvoid createHairlineAndFillPrimitive( const basegfx::B2DPolyPolygon& rPolyPolygon,
TargetHolder& rTarget,
PropertyHolder const & rProperties)
{ if(rProperties.getFillColorActive())
{
createFillPrimitive(rPolyPolygon, rTarget, rProperties);
}
/** helper to create DiscreteBitmapPrimitive2D based on current context. The DiscreteBitmapPrimitive2D is especially created for this usage since no other usage defines a bitmap visualisation based on top-left position and size in pixels. At the end it will create a view-dependent transformed embedding of a BitmapPrimitive2D.
*/ staticvoid createBitmapExPrimitive( const BitmapEx& rBitmapEx, const Point& rPoint,
TargetHolder& rTarget,
PropertyHolder const & rProperties)
{ if(!rBitmapEx.IsEmpty())
{
basegfx::B2DPoint aPoint(rPoint.X(), rPoint.Y());
aPoint = rProperties.getTransformation() * aPoint;
rTarget.append( new drawinglayer::primitive2d::DiscreteBitmapPrimitive2D(
rBitmapEx,
aPoint));
}
}
/** helper to create BitmapPrimitive2D based on current context */ staticvoid createBitmapExPrimitive( const BitmapEx& rBitmapEx, const Point& rPoint, const Size& rSize,
TargetHolder& rTarget,
PropertyHolder const & rProperties)
{ if(rBitmapEx.IsEmpty()) return;
rTarget.append( new drawinglayer::primitive2d::BitmapPrimitive2D(
rBitmapEx,
aObjectTransform));
}
/** helper to create a regular BotmapEx from a MaskAction (definitions which use a bitmap without transparence but define one of the colors as transparent)
*/ static BitmapEx createMaskBmpEx(const Bitmap& rBitmap, const Color& rMaskColor)
{ const Color aWhite(COL_WHITE);
BitmapPalette aBiLevelPalette {
aWhite, rMaskColor
};
/** helper to convert from a VCL Gradient definition to the corresponding data for primitive representation
*/ static drawinglayer::attribute::FillGradientAttribute createFillGradientAttribute(const Gradient& rGradient)
{ const Color aStartColor(rGradient.GetStartColor()); const sal_uInt16 nStartIntens(rGradient.GetStartIntensity());
basegfx::BColor aStart(aStartColor.getBColor());
/** helper to convert from a VCL Hatch definition to the corresponding data for primitive representation
*/ static drawinglayer::attribute::FillHatchAttribute createFillHatchAttribute(const Hatch& rHatch)
{
drawinglayer::attribute::HatchStyle aHatchStyle(drawinglayer::attribute::HatchStyle::Single);
return drawinglayer::attribute::FillHatchAttribute(
aHatchStyle, static_cast<double>(rHatch.GetDistance()),
toRadians(rHatch.GetAngle()),
rHatch.GetColor().getBColor(),
3, // same default as VCL, a minimum of three discrete units (pixels) offset false);
}
/** helper to take needed action on ClipRegion change. This method needs to be called on any vcl::Region change, e.g. at the obvious actions doing this, but also at pop-calls which change the vcl::Region of the current context. It takes care of creating the current embedded context, set the new vcl::Region at the context and possibly prepare a new target for including new geometry into the current region
*/ void HandleNewClipRegion( const basegfx::B2DPolyPolygon& rClipPolyPolygon,
TargetHolders& rTargetHolders,
PropertyHolders& rPropertyHolders)
{ constbool bNewActive(rClipPolyPolygon.count());
// #i108636# The handling of new ClipPolyPolygons was not done as good as possible // in the first version of this interpreter; e.g. when a ClipPolyPolygon was set // initially and then using a lot of push/pop actions, the pop always leads // to setting a 'new' ClipPolyPolygon which indeed is the return to the ClipPolyPolygon // of the properties next on the stack.
// This ClipPolyPolygon is identical to the current one, so there is no need to // create a MaskPrimitive2D containing the up-to-now created primitives, but // this was done before. While this does not lead to wrong primitive // representations of the metafile data, it creates unnecessarily expensive // representations. Just detecting when no really 'new' ClipPolyPolygon gets set // solves the problem.
if(!rPropertyHolders.Current().getClipPolyPolygonActive() && !bNewActive)
{ // no active ClipPolyPolygon exchanged by no new one, done return;
}
if(rPropertyHolders.Current().getClipPolyPolygonActive() && bNewActive)
{ // active ClipPolyPolygon and new active ClipPolyPolygon if(rPropertyHolders.Current().getClipPolyPolygon() == rClipPolyPolygon)
{ // new is the same as old, done return;
}
}
// Here the old and the new are definitively different, maybe // old one and/or new one is not active.
// Handle deletion of old ClipPolyPolygon. The process evtl. created primitives which // belong to this active ClipPolyPolygon. These need to be embedded to a // MaskPrimitive2D accordingly. if(rPropertyHolders.Current().getClipPolyPolygonActive() && rTargetHolders.size() > 1)
{
drawinglayer::primitive2d::Primitive2DContainer aSubContent;
// prepare new content holder for new active region
rTargetHolders.Push();
}
}
/** helper to handle the change of RasterOp. It takes care of encapsulating all current geometry to the current RasterOp (if changed) and needs to be called on any RasterOp change. It will also start a new geometry target to embrace to the new RasterOp if a changing RasterOp is used. Currently, RasterOp::Xor and RasterOp::Invert are supported using InvertPrimitive2D, and RasterOp::N0 by using a ModifiedColorPrimitive2D to force to black paint
*/ staticvoid HandleNewRasterOp(
RasterOp aRasterOp,
TargetHolders& rTargetHolders,
PropertyHolders& rPropertyHolders)
{ // check if currently active if(rPropertyHolders.Current().isRasterOpActive() && rTargetHolders.size() > 1)
{
drawinglayer::primitive2d::Primitive2DContainer aSubContent;
if(!aSubContent.empty())
{ if(rPropertyHolders.Current().isRasterOpForceBlack())
{ // force content to black
rTargetHolders.Current().append( new drawinglayer::primitive2d::ModifiedColorPrimitive2D(
std::move(aSubContent),
std::make_shared<basegfx::BColorModifier_replace>(
basegfx::BColor(0.0, 0.0, 0.0))));
} else// if(rPropertyHolders.Current().isRasterOpInvert())
{ // invert content
rTargetHolders.Current().append( new drawinglayer::primitive2d::InvertPrimitive2D(
std::move(aSubContent)));
}
}
}
// apply new settings
rPropertyHolders.Current().setRasterOp(aRasterOp);
// check if now active if(rPropertyHolders.Current().isRasterOpActive())
{ // prepare new content holder for new invert
rTargetHolders.Push();
}
}
/** helper to create needed data to emulate the VCL Wallpaper Metafile action. It is a quite mighty action. This helper is for simple color filled background.
*/ static rtl::Reference<drawinglayer::primitive2d::BasePrimitive2D> CreateColorWallpaper( const basegfx::B2DRange& rRange, const basegfx::BColor& rColor,
PropertyHolder const & rPropertyHolder)
{
basegfx::B2DPolygon aOutline(basegfx::utils::createPolygonFromRect(rRange));
aOutline.transform(rPropertyHolder.getTransformation());
/** helper to create needed data to emulate the VCL Wallpaper Metafile action. It is a quite mighty action. This helper is for gradient filled background.
*/ static rtl::Reference<drawinglayer::primitive2d::BasePrimitive2D> CreateGradientWallpaper( const basegfx::B2DRange& rRange, const Gradient& rGradient,
PropertyHolder const & rPropertyHolder)
{
drawinglayer::attribute::FillGradientAttribute aAttribute(createFillGradientAttribute(rGradient));
basegfx::BColor aSingleColor;
if (aAttribute.getColorStops().isSingleColor(aSingleColor))
{ // not really a gradient. Create filled rectangle return CreateColorWallpaper(rRange, aSingleColor, rPropertyHolder);
} else
{ // really a gradient
rtl::Reference<drawinglayer::primitive2d::BasePrimitive2D> pRetval( new drawinglayer::primitive2d::FillGradientPrimitive2D(
rRange,
std::move(aAttribute)));
pRetval = new drawinglayer::primitive2d::TransformPrimitive2D(
rPropertyHolder.getTransformation(),
std::move(xSeq));
}
return pRetval;
}
}
/** helper to create needed data to emulate the VCL Wallpaper Metafile action. It is a quite mighty action. This helper decides if color and/or gradient background is needed for the wanted bitmap fill and then creates the needed WallpaperBitmapPrimitive2D. This primitive was created for this purpose and takes over all needed logic of orientations and tiling.
*/ staticvoid CreateAndAppendBitmapWallpaper(
basegfx::B2DRange aWallpaperRange, const Wallpaper& rWallpaper,
TargetHolder& rTarget,
PropertyHolder const & rProperty)
{ const BitmapEx& aBitmapEx(rWallpaper.GetBitmap()); const WallpaperStyle eWallpaperStyle(rWallpaper.GetStyle());
// use wallpaper rect if set if(rWallpaper.IsRect() && !rWallpaper.GetRect().IsEmpty())
{
aWallpaperRange = vcl::unotools::b2DRectangleFromRectangle(rWallpaper.GetRect());
}
rtl::Reference<drawinglayer::primitive2d::BasePrimitive2D> pBitmapWallpaperFill = new drawinglayer::primitive2d::WallpaperBitmapPrimitive2D(
aWallpaperRange,
aBitmapEx,
eWallpaperStyle);
if(rProperty.getTransformation().isIdentity())
{ // add directly
rTarget.append(pBitmapWallpaperFill);
} else
{ // when a transformation is set, embed to it
rTarget.append( new drawinglayer::primitive2d::TransformPrimitive2D(
rProperty.getTransformation(),
drawinglayer::primitive2d::Primitive2DContainer { pBitmapWallpaperFill }));
}
}
/** helper to decide UnderlineAbove for text primitives */ staticbool isUnderlineAbove(const vcl::Font& rFont)
{ if(!rFont.IsVertical())
{ returnfalse;
}
// the underline is right for Japanese only return (LANGUAGE_JAPANESE == rFont.GetLanguage()) || (LANGUAGE_JAPANESE == rFont.GetCJKContextLanguage());
}
// take text align into account if(ALIGN_BASELINE != rFont.GetAlignment())
{
drawinglayer::primitive2d::TextLayouterDevice aTextLayouterDevice;
aTextLayouterDevice.setFont(rFont);
if(pResult && rProperty.getTextFillColorActive())
{ // text background is requested, add and encapsulate both to new primitive
drawinglayer::primitive2d::TextLayouterDevice aTextLayouterDevice;
aTextLayouterDevice.setFont(rFont);
aSequence[0] = drawinglayer::primitive2d::Primitive2DReference( new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(
basegfx::B2DPolyPolygon(aOutline),
rProperty.getTextFillColor()));
// set as group at pResult
pResult = new drawinglayer::primitive2d::GroupPrimitive2D(std::move(aSequence));
}
}
if(!pResult) return;
// add created text primitive to target if(rProperty.getTransformation().isIdentity())
{
rTarget.append(pResult);
} else
{ // when a transformation is set, embed to it
rTarget.append( new drawinglayer::primitive2d::TransformPrimitive2D(
rProperty.getTransformation(),
drawinglayer::primitive2d::Primitive2DContainer { pResult }));
}
}
/** helper which takes complete care for creating the needed textLine primitives */ staticvoid processMetaTextLineAction( const MetaTextLineAction& rAction,
TargetHolder& rTarget,
PropertyHolder const & rProperty)
{ constdouble fLineWidth(fabs(static_cast<double>(rAction.GetWidth())));
aTargets.push_back( new drawinglayer::primitive2d::TextCharacterStrikeoutPrimitive2D(
aTextTransform,
fLineWidth,
rProperty.getTextColor(),
aStrikeoutChar,
std::move(aFontAttribute),
std::move(aLocale)));
} else
{ // strikeout with geometry
aTargets.push_back( new drawinglayer::primitive2d::TextGeometryStrikeoutPrimitive2D(
aTextTransform,
fLineWidth,
rProperty.getTextColor(),
aTextLayouter.getUnderlineHeight(),
aTextLayouter.getStrikeoutOffset(),
aTextStrikeout));
}
}
if(aTargets.empty()) return;
// add created text primitive to target if(rProperty.getTransformation().isIdentity())
{
rTarget.append(std::move(aTargets));
} else
{ // when a transformation is set, embed to it
rTarget.append( new drawinglayer::primitive2d::TransformPrimitive2D(
rProperty.getTransformation(),
std::move(aTargets)));
}
}
/** This is the main interpreter method. It is designed to handle the given Metafile completely inside the given context and target. It may use and modify the context and target. This design allows to call itself recursively which adapted contexts and targets as e.g. needed for the MetaActionType::FLOATTRANSPARENT where the content is expressed as a metafile as sub-content.
This interpreter is as free of VCL functionality as possible. It uses VCL data classes (else reading the data would not be possible), but e.g. does NOT use a local OutputDevice as most other MetaFile interpreters/exporters do to hold and work with the current context. This is necessary to be able to get away from the strong internal VCL-binding.
It tries to combine e.g. pixel and/or point actions and to stitch together single line primitives where possible (which is not trivial with the possible line geometry definitions).
It tries to handle clipping no longer as Regions and spans of Rectangles, but as PolyPolygon ClipRegions with (where possible) high precision by using the best possible data quality from the Region. The vcl::Region is unavoidable as data container, but nowadays allows the transport of Polygon-based clip regions. Where this is not used, a Polygon is constructed from the vcl::Region ranges. All primitive clipping uses the MaskPrimitive2D with Polygon-based clipping.
I have marked the single MetaActions with:
SIMPLE, DONE: Simple, e.g nothing to do or value setting in the context
CHECKED, WORKS WELL: Thoroughly tested with extra written test code which created a replacement Metafile just to test this action in various combinations
NEEDS IMPLEMENTATION: Not implemented and asserted, but also no usage found, neither in own Metafile creations, nor in EMF/WMF imports (checked with a whole bunch of critical EMF/WMF bugdocs)
For more comments, see the single action implementations.
*/ staticvoid implInterpretMetafile( const GDIMetaFile& rMetaFile,
TargetHolders& rTargetHolders,
PropertyHolders& rPropertyHolders, const drawinglayer::geometry::ViewInformation2D& rViewInformation)
{ const size_t nCount(rMetaFile.GetActionSize());
std::unique_ptr<emfplushelper::EmfPlusHelper> aEMFPlus;
break;
} case MetaActionType::ROUNDRECT :
{ /** CHECKED, WORKS WELL */ /** The original OutputDevice::DrawRect paints nothing when nHor or nVer is zero; but just because the tools::Polygon operator creating the rounding does produce nonsense. I assume this an error and create an unrounded rectangle in that case (implicit in createPolygonFromRect)
*/ if(rPropertyHolders.Current().getLineOrFillActive())
{ const MetaRoundRectAction* pA = static_cast<const MetaRoundRectAction*>(pAction); const tools::Rectangle& rRectangle = pA->GetRect();
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.