LCOV - code coverage report
Current view: top level - drawinglayer/source/primitive2d - graphicprimitive2d.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 46 75 61.3 %
Date: 2015-06-13 12:38:46 Functions: 4 6 66.7 %
Legend: Lines: hit not hit

          Line data    Source code
       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 <drawinglayer/primitive2d/graphicprimitive2d.hxx>
      21             : #include <drawinglayer/primitive2d/cropprimitive2d.hxx>
      22             : #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
      23             : #include <drawinglayer/primitive2d/maskprimitive2d.hxx>
      24             : #include <drawinglayer/primitive2d/graphicprimitivehelper2d.hxx>
      25             : #include <drawinglayer/primitive2d/unifiedtransparenceprimitive2d.hxx>
      26             : #include <drawinglayer/primitive2d/modifiedcolorprimitive2d.hxx>
      27             : #include <basegfx/matrix/b2dhommatrixtools.hxx>
      28             : #include <vcl/svapp.hxx>
      29             : #include <vcl/outdev.hxx>
      30             : 
      31             : namespace drawinglayer
      32             : {
      33             :     namespace primitive2d
      34             :     {
      35         304 :         Primitive2DSequence GraphicPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D&
      36             :             ) const
      37             :         {
      38         304 :             Primitive2DSequence aRetval;
      39             : 
      40         304 :             if(255L == getGraphicAttr().GetTransparency())
      41             :             {
      42             :                 // content is invisible, done
      43           0 :                 return aRetval;
      44             :             }
      45             : 
      46             :             // do not apply mirroring from GraphicAttr to the Metafile by calling
      47             :             // GetTransformedGraphic, this will try to mirror the Metafile using Scale()
      48             :             // at the Metafile. This again calls Scale at the single MetaFile actions,
      49             :             // but this implementation never worked. I reworked that implementations,
      50             :             // but for security reasons i will try not to use it.
      51         608 :             basegfx::B2DHomMatrix aTransform(getTransform());
      52             : 
      53         304 :             if(getGraphicAttr().IsMirrored())
      54             :             {
      55             :                 // content needs mirroring
      56           0 :                 const bool bHMirr(getGraphicAttr().GetMirrorFlags() & BmpMirrorFlags::Horizontal);
      57           0 :                 const bool bVMirr(getGraphicAttr().GetMirrorFlags() & BmpMirrorFlags::Vertical);
      58             : 
      59             :                 // mirror by applying negative scale to the unit primitive and
      60             :                 // applying the object transformation on it.
      61           0 :                 aTransform = basegfx::tools::createScaleB2DHomMatrix(
      62             :                     bHMirr ? -1.0 : 1.0,
      63           0 :                     bVMirr ? -1.0 : 1.0);
      64             :                 aTransform.translate(
      65             :                     bHMirr ? 1.0 : 0.0,
      66           0 :                     bVMirr ? 1.0 : 0.0);
      67           0 :                 aTransform = getTransform() * aTransform;
      68             :             }
      69             : 
      70             :             // Get transformed graphic. Suppress rotation and cropping, only filtering is needed
      71             :             // here (and may be replaced later on). Cropping is handled below as mask primitive (if set).
      72             :             // Also need to suppress mirroring, it is part of the transformation now (see above).
      73             :             // Also move transparency handling to embedding to a UnifiedTransparencePrimitive2D; do
      74             :             // that by remembering original transparency and applying that later if needed
      75         608 :             GraphicAttr aSuppressGraphicAttr(getGraphicAttr());
      76             : 
      77         304 :             aSuppressGraphicAttr.SetCrop(0, 0, 0, 0);
      78         304 :             aSuppressGraphicAttr.SetRotation(0);
      79         304 :             aSuppressGraphicAttr.SetMirrorFlags(BmpMirrorFlags::NONE);
      80         304 :             aSuppressGraphicAttr.SetTransparency(0);
      81             : 
      82         304 :             const GraphicObject& rGraphicObject = getGraphicObject();
      83         608 :             Graphic aTransformedGraphic(rGraphicObject.GetGraphic());
      84         304 :             const bool isBitmap(GRAPHIC_BITMAP == aTransformedGraphic.GetType() && !aTransformedGraphic.getSvgData().get());
      85         304 :             const bool isAdjusted(getGraphicAttr().IsAdjusted());
      86         304 :             const bool isDrawMode(GRAPHICDRAWMODE_STANDARD != getGraphicAttr().GetDrawMode());
      87             : 
      88         304 :             if(isBitmap && (isAdjusted || isDrawMode))
      89             :             {
      90             :                 // the pure primitive solution with the color modifiers works well, too, but when
      91             :                 // it is a bitmap graphic the old modification currently is faster; so use it here
      92             :                 // instead of creating all as in create2DColorModifierEmbeddingsAsNeeded (see below).
      93             :                 // Still, crop, rotation, mirroring and transparency is handled by primitives already
      94             :                 // (see above).
      95             :                 // This could even be done when vector graphic, but we explicitely want to have the
      96             :                 // pure primitive solution for this; this will allow vector graphics to stay vector
      97             :                 // geraphics, independent from the color filtering stuff. This will enhance e.g.
      98             :                 // SVG and print quality while reducing data size at the same time.
      99             :                 // The other way around the old modifications when only used on already bitmap objects
     100             :                 // will not lose any quality.
     101           0 :                 aTransformedGraphic = rGraphicObject.GetTransformedGraphic(&aSuppressGraphicAttr);
     102             : 
     103             :                 // reset GraphicAttr after use to not apply double
     104           0 :                 aSuppressGraphicAttr = GraphicAttr();
     105             :             }
     106             : 
     107             :             // create sub-content; helper takes care of correct handling of
     108             :             // bitmap, svg or metafile content
     109         608 :             aRetval = create2DDecompositionOfGraphic(
     110             :                 aTransformedGraphic,
     111         304 :                 aTransform);
     112             : 
     113         304 :             if(!aRetval.getLength())
     114             :             {
     115             :                 // content is invisible, done
     116          30 :                 return aRetval;
     117             :             }
     118             : 
     119         274 :             if(isAdjusted || isDrawMode)
     120             :             {
     121             :                 // embed to needed ModifiedColorPrimitive2D's if necessary. Do this for
     122             :                 // adjustments and draw mode specials
     123           0 :                 aRetval = create2DColorModifierEmbeddingsAsNeeded(
     124             :                     aRetval,
     125             :                     aSuppressGraphicAttr.GetDrawMode(),
     126           0 :                     basegfx::clamp(aSuppressGraphicAttr.GetLuminance() * 0.01, -1.0, 1.0),
     127           0 :                     basegfx::clamp(aSuppressGraphicAttr.GetContrast() * 0.01, -1.0, 1.0),
     128           0 :                     basegfx::clamp(aSuppressGraphicAttr.GetChannelR() * 0.01, -1.0, 1.0),
     129           0 :                     basegfx::clamp(aSuppressGraphicAttr.GetChannelG() * 0.01, -1.0, 1.0),
     130           0 :                     basegfx::clamp(aSuppressGraphicAttr.GetChannelB() * 0.01, -1.0, 1.0),
     131           0 :                     basegfx::clamp(aSuppressGraphicAttr.GetGamma(), 0.0, 10.0),
     132           0 :                     aSuppressGraphicAttr.IsInvert());
     133             : 
     134           0 :                 if(!aRetval.getLength())
     135             :                 {
     136             :                     // content is invisible, done
     137           0 :                     return aRetval;
     138             :                 }
     139             :             }
     140             : 
     141         274 :             if(getGraphicAttr().IsTransparent())
     142             :             {
     143             :                 // check for transparency
     144           1 :                 const double fTransparency(basegfx::clamp(getGraphicAttr().GetTransparency() * (1.0 / 255.0), 0.0, 1.0));
     145             : 
     146           1 :                 if(!basegfx::fTools::equalZero(fTransparency))
     147             :                 {
     148             :                     const Primitive2DReference aUnifiedTransparence(
     149             :                         new UnifiedTransparencePrimitive2D(
     150             :                             aRetval,
     151           1 :                             fTransparency));
     152             : 
     153           1 :                     aRetval = Primitive2DSequence(&aUnifiedTransparence, 1);
     154             :                 }
     155             :             }
     156             : 
     157         274 :             if(getGraphicAttr().IsCropped())
     158             :             {
     159             :                 // check for cropping
     160             :                 // calculate scalings between real image size and logic object size. This
     161             :                 // is necessary since the crop values are relative to original bitmap size
     162           3 :                 const basegfx::B2DVector aObjectScale(aTransform * basegfx::B2DVector(1.0, 1.0));
     163             :                 const basegfx::B2DVector aCropScaleFactor(
     164             :                     rGraphicObject.calculateCropScaling(
     165             :                         aObjectScale.getX(),
     166             :                         aObjectScale.getY(),
     167           3 :                         getGraphicAttr().GetLeftCrop(),
     168           3 :                         getGraphicAttr().GetTopCrop(),
     169           3 :                         getGraphicAttr().GetRightCrop(),
     170          15 :                         getGraphicAttr().GetBottomCrop()));
     171             : 
     172             :                 // embed content in cropPrimitive
     173             :                 Primitive2DReference xPrimitive(
     174             :                     new CropPrimitive2D(
     175             :                         aRetval,
     176             :                         aTransform,
     177           3 :                         getGraphicAttr().GetLeftCrop() * aCropScaleFactor.getX(),
     178           3 :                         getGraphicAttr().GetTopCrop() * aCropScaleFactor.getY(),
     179           3 :                         getGraphicAttr().GetRightCrop() * aCropScaleFactor.getX(),
     180          12 :                         getGraphicAttr().GetBottomCrop() * aCropScaleFactor.getY()));
     181             : 
     182           6 :                 aRetval = Primitive2DSequence(&xPrimitive, 1);
     183             :             }
     184             : 
     185         274 :             return aRetval;
     186             :         }
     187             : 
     188         766 :         GraphicPrimitive2D::GraphicPrimitive2D(
     189             :             const basegfx::B2DHomMatrix& rTransform,
     190             :             const GraphicObject& rGraphicObject,
     191             :             const GraphicAttr& rGraphicAttr)
     192             :         :   BufferedDecompositionPrimitive2D(),
     193             :             maTransform(rTransform),
     194             :             maGraphicObject(rGraphicObject),
     195         766 :             maGraphicAttr(rGraphicAttr)
     196             :         {
     197         766 :         }
     198             : 
     199           0 :         GraphicPrimitive2D::GraphicPrimitive2D(
     200             :             const basegfx::B2DHomMatrix& rTransform,
     201             :             const GraphicObject& rGraphicObject)
     202             :         :   BufferedDecompositionPrimitive2D(),
     203             :             maTransform(rTransform),
     204             :             maGraphicObject(rGraphicObject),
     205           0 :             maGraphicAttr()
     206             :         {
     207           0 :         }
     208             : 
     209           0 :         bool GraphicPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
     210             :         {
     211           0 :             if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
     212             :             {
     213           0 :                 const GraphicPrimitive2D& rCompare = static_cast<const GraphicPrimitive2D&>(rPrimitive);
     214             : 
     215           0 :                 return (getTransform() == rCompare.getTransform()
     216           0 :                     && getGraphicObject() == rCompare.getGraphicObject()
     217           0 :                     && getGraphicAttr() == rCompare.getGraphicAttr());
     218             :             }
     219             : 
     220           0 :             return false;
     221             :         }
     222             : 
     223        1687 :         basegfx::B2DRange GraphicPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const
     224             :         {
     225        1687 :             basegfx::B2DRange aRetval(0.0, 0.0, 1.0, 1.0);
     226        1687 :             aRetval.transform(getTransform());
     227        1687 :             return aRetval;
     228             :         }
     229             : 
     230             :         // provide unique ID
     231         501 :         ImplPrimitive2DIDBlock(GraphicPrimitive2D, PRIMITIVE2D_ID_GRAPHICPRIMITIVE2D)
     232             : 
     233             :     } // end of namespace primitive2d
     234             : } // end of namespace drawinglayer
     235             : 
     236             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11