1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* 3 * This file is part of the LibreOffice project. 4 * 5 * This Source Code Form is subject to the terms of the Mozilla Public 6 * License, v. 2.0. If a copy of the MPL was not distributed with this 7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 8 * 9 * This file incorporates work covered by the following license notice: 10 * 11 * Licensed to the Apache Software Foundation (ASF) under one or more 12 * contributor license agreements. See the NOTICE file distributed 13 * with this work for additional information regarding copyright 14 * ownership. The ASF licenses this file to you under the Apache 15 * License, Version 2.0 (the "License"); you may not use this file 16 * except in compliance with the License. You may obtain a copy of 17 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 18 */ 19 20 #include <sdr/primitive2d/sdrcaptionprimitive2d.hxx> 21 #include <basegfx/polygon/b2dpolypolygon.hxx> 22 #include <basegfx/polygon/b2dpolygontools.hxx> 23 #include <sdr/primitive2d/sdrdecompositiontools.hxx> 24 #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx> 25 #include <drawinglayer/primitive2d/sdrdecompositiontools2d.hxx> 26 27 28 using namespace com::sun::star; 29 30 31 namespace drawinglayer::primitive2d 32 { create2DDecomposition(Primitive2DContainer & rContainer,const geometry::ViewInformation2D &) const33 void SdrCaptionPrimitive2D::create2DDecomposition(Primitive2DContainer& rContainer, const geometry::ViewInformation2D& /*aViewInformation*/) const 34 { 35 Primitive2DContainer aRetval; 36 37 // create unit outline polygon 38 const basegfx::B2DPolygon aUnitOutline(basegfx::utils::createPolygonFromRect( 39 basegfx::B2DRange(0.0, 0.0, 1.0, 1.0), 40 getCornerRadiusX(), 41 getCornerRadiusY())); 42 43 // add fill 44 if(getSdrLFSTAttribute().getFill().isDefault()) 45 { 46 // create invisible fill for HitTest 47 aRetval.push_back( 48 createHiddenGeometryPrimitives2D( 49 true, 50 basegfx::B2DPolyPolygon(aUnitOutline), 51 getTransform())); 52 } 53 else 54 { 55 basegfx::B2DPolyPolygon aTransformed(aUnitOutline); 56 57 aTransformed.transform(getTransform()); 58 aRetval.push_back( 59 createPolyPolygonFillPrimitive( 60 aTransformed, 61 getSdrLFSTAttribute().getFill(), 62 getSdrLFSTAttribute().getFillFloatTransGradient())); 63 } 64 65 // add line 66 if(getSdrLFSTAttribute().getLine().isDefault()) 67 { 68 // create invisible line for HitTest/BoundRect 69 aRetval.push_back( 70 createHiddenGeometryPrimitives2D( 71 false, 72 basegfx::B2DPolyPolygon(aUnitOutline), 73 getTransform())); 74 75 aRetval.push_back( 76 createHiddenGeometryPrimitives2D( 77 false, 78 basegfx::B2DPolyPolygon(getTail()), 79 getTransform())); 80 } 81 else 82 { 83 basegfx::B2DPolygon aTransformed(aUnitOutline); 84 85 aTransformed.transform(getTransform()); 86 aRetval.push_back( 87 createPolygonLinePrimitive( 88 aTransformed, 89 getSdrLFSTAttribute().getLine(), 90 attribute::SdrLineStartEndAttribute())); 91 92 aTransformed = getTail(); 93 aTransformed.transform(getTransform()); 94 aRetval.push_back( 95 createPolygonLinePrimitive( 96 aTransformed, 97 getSdrLFSTAttribute().getLine(), 98 getSdrLFSTAttribute().getLineStartEnd())); 99 } 100 101 // add text 102 if(!getSdrLFSTAttribute().getText().isDefault()) 103 { 104 aRetval.push_back( 105 createTextPrimitive( 106 basegfx::B2DPolyPolygon(aUnitOutline), 107 getTransform(), 108 getSdrLFSTAttribute().getText(), 109 getSdrLFSTAttribute().getLine(), 110 false, 111 false)); 112 } 113 114 // add shadow 115 if(!getSdrLFSTAttribute().getShadow().isDefault()) 116 { 117 aRetval = createEmbeddedShadowPrimitive(aRetval, getSdrLFSTAttribute().getShadow()); 118 } 119 120 rContainer.insert(rContainer.end(), aRetval.begin(), aRetval.end()); 121 } 122 SdrCaptionPrimitive2D(const basegfx::B2DHomMatrix & rTransform,const attribute::SdrLineFillEffectsTextAttribute & rSdrLFSTAttribute,const basegfx::B2DPolygon & rTail,double fCornerRadiusX,double fCornerRadiusY)123 SdrCaptionPrimitive2D::SdrCaptionPrimitive2D( 124 const basegfx::B2DHomMatrix& rTransform, 125 const attribute::SdrLineFillEffectsTextAttribute& rSdrLFSTAttribute, 126 const basegfx::B2DPolygon& rTail, 127 double fCornerRadiusX, 128 double fCornerRadiusY) 129 : BufferedDecompositionPrimitive2D(), 130 maTransform(rTransform), 131 maSdrLFSTAttribute(rSdrLFSTAttribute), 132 maTail(rTail), 133 mfCornerRadiusX(fCornerRadiusX), 134 mfCornerRadiusY(fCornerRadiusY) 135 { 136 // transform maTail to unit polygon 137 if(getTail().count()) 138 { 139 basegfx::B2DHomMatrix aInverse(getTransform()); 140 aInverse.invert(); 141 maTail.transform(aInverse); 142 } 143 } 144 operator ==(const BasePrimitive2D & rPrimitive) const145 bool SdrCaptionPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const 146 { 147 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive)) 148 { 149 const SdrCaptionPrimitive2D& rCompare = static_cast<const SdrCaptionPrimitive2D&>(rPrimitive); 150 151 return (getCornerRadiusX() == rCompare.getCornerRadiusX() 152 && getCornerRadiusY() == rCompare.getCornerRadiusY() 153 && getTail() == rCompare.getTail() 154 && getTransform() == rCompare.getTransform() 155 && getSdrLFSTAttribute() == rCompare.getSdrLFSTAttribute()); 156 } 157 158 return false; 159 } 160 161 // provide unique ID 162 ImplPrimitive2DIDBlock(SdrCaptionPrimitive2D, PRIMITIVE2D_ID_SDRCAPTIONPRIMITIVE2D) 163 164 } // end of namespace 165 166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 167