LCOV - code coverage report
Current view: top level - sdext/source/presenter - PresenterCanvasHelper.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 100 0.0 %
Date: 2014-11-03 Functions: 0 10 0.0 %
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 "PresenterCanvasHelper.hxx"
      21             : 
      22             : #include "PresenterController.hxx"
      23             : #include "PresenterGeometryHelper.hxx"
      24             : #include <com/sun/star/rendering/CompositeOperation.hpp>
      25             : #include <com/sun/star/rendering/TextDirection.hpp>
      26             : #include <com/sun/star/rendering/TexturingMode.hpp>
      27             : 
      28             : using namespace ::com::sun::star;
      29             : using namespace ::com::sun::star::uno;
      30             : 
      31             : namespace sdext { namespace presenter {
      32             : 
      33           0 : PresenterCanvasHelper::PresenterCanvasHelper (void)
      34             :     : maDefaultViewState(
      35             :         geometry::AffineMatrix2D(1,0,0, 0,1,0),
      36             :         NULL),
      37             :       maDefaultRenderState(
      38             :           geometry::AffineMatrix2D(1,0,0, 0,1,0),
      39             :           NULL,
      40             :           Sequence<double>(4),
      41           0 :           rendering::CompositeOperation::SOURCE)
      42             : {
      43           0 : }
      44             : 
      45           0 : PresenterCanvasHelper::~PresenterCanvasHelper (void)
      46             : {
      47           0 : }
      48             : 
      49           0 : void PresenterCanvasHelper::Paint (
      50             :     const SharedBitmapDescriptor& rpBitmap,
      51             :     const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
      52             :     const css::awt::Rectangle& rRepaintBox,
      53             :     const css::awt::Rectangle& rOuterBoundingBox,
      54             :     const css::awt::Rectangle& rContentBoundingBox) const
      55             : {
      56             :     PaintRectangle(rpBitmap,rxCanvas,rRepaintBox,rOuterBoundingBox,rContentBoundingBox,
      57           0 :         maDefaultViewState, maDefaultRenderState);
      58           0 : }
      59             : 
      60           0 : void PresenterCanvasHelper::PaintRectangle (
      61             :     const SharedBitmapDescriptor& rpBitmap,
      62             :     const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
      63             :     const css::awt::Rectangle& rRepaintBox,
      64             :     const css::awt::Rectangle& rOuterBoundingBox,
      65             :     const css::awt::Rectangle& rContentBoundingBox,
      66             :     const css::rendering::ViewState& rDefaultViewState,
      67             :     const css::rendering::RenderState& rDefaultRenderState)
      68             : {
      69           0 :     if (rpBitmap.get() == NULL)
      70           0 :         return;
      71             : 
      72           0 :     if ( ! rxCanvas.is() || ! rxCanvas->getDevice().is())
      73           0 :         return;
      74             : 
      75             :     // Create a clip polypolygon that has the content box as hole.
      76           0 :     ::std::vector<awt::Rectangle> aRectangles;
      77           0 :     aRectangles.reserve(2);
      78             :     aRectangles.push_back(
      79           0 :         PresenterGeometryHelper::Intersection(rRepaintBox, rOuterBoundingBox));
      80           0 :     if (rContentBoundingBox.Width > 0 && rContentBoundingBox.Height > 0)
      81             :         aRectangles.push_back(
      82           0 :             PresenterGeometryHelper::Intersection(rRepaintBox, rContentBoundingBox));
      83             :     Reference<rendering::XPolyPolygon2D> xPolyPolygon (
      84             :         PresenterGeometryHelper::CreatePolygon(
      85             :             aRectangles,
      86           0 :             rxCanvas->getDevice()));
      87           0 :     if ( ! xPolyPolygon.is())
      88           0 :         return;
      89           0 :     xPolyPolygon->setFillRule(rendering::FillRule_EVEN_ODD);
      90             : 
      91           0 :     if (rpBitmap->GetNormalBitmap().is())
      92             :     {
      93           0 :         if (rpBitmap->meHorizontalTexturingMode == PresenterBitmapDescriptor::Repeat
      94           0 :             || rpBitmap->meVerticalTexturingMode == PresenterBitmapDescriptor::Repeat)
      95             :         {
      96             :             PaintTiledBitmap(
      97             :                 Reference<rendering::XBitmap>(rpBitmap->GetNormalBitmap(), UNO_QUERY),
      98             :                 rxCanvas,
      99             :                 rRepaintBox,
     100             :                 xPolyPolygon,
     101             :                 rContentBoundingBox,
     102             :                 rDefaultViewState,
     103           0 :                 rDefaultRenderState);
     104             :         }
     105             :         else
     106             :         {
     107             :             PaintBitmap(
     108             :                 Reference<rendering::XBitmap>(rpBitmap->GetNormalBitmap(), UNO_QUERY),
     109             :                 awt::Point(rOuterBoundingBox.X, rOuterBoundingBox.Y),
     110             :                 rxCanvas,
     111             :                 rRepaintBox,
     112             :                 xPolyPolygon,
     113             :                 rDefaultViewState,
     114           0 :                 rDefaultRenderState);
     115             :         }
     116             :     }
     117             :     else
     118             :     {
     119             :         PaintColor(
     120           0 :             rpBitmap->maReplacementColor,
     121             :             rxCanvas,
     122             :             rRepaintBox,
     123             :             xPolyPolygon,
     124             :             rDefaultViewState,
     125           0 :             rDefaultRenderState);
     126           0 :     }
     127             : }
     128             : 
     129           0 : void PresenterCanvasHelper::PaintTiledBitmap (
     130             :     const css::uno::Reference<css::rendering::XBitmap>& rxTexture,
     131             :     const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
     132             :     const css::awt::Rectangle& rRepaintBox,
     133             :     const css::uno::Reference<css::rendering::XPolyPolygon2D>& rxPolygon,
     134             :     const css::awt::Rectangle& rHole,
     135             :     const css::rendering::ViewState& rDefaultViewState,
     136             :     const css::rendering::RenderState& rDefaultRenderState)
     137             : {
     138           0 :     if ( ! rxCanvas.is() || ! rxCanvas->getDevice().is())
     139           0 :         return;
     140             : 
     141           0 :     if ( ! rxTexture.is())
     142           0 :         return;
     143             : 
     144           0 :     if ( ! rxPolygon.is())
     145           0 :         return;
     146             : 
     147           0 :     rendering::ViewState aViewState (rDefaultViewState);
     148           0 :     aViewState.Clip = rxPolygon;
     149             : 
     150             :     // Create a local render state at which the location of the bitmap is
     151             :     // set.
     152           0 :     rendering::RenderState aRenderState (rDefaultRenderState);
     153             : 
     154             :     // Tile the bitmap over the repaint box.
     155           0 :     const geometry::IntegerSize2D aBitmapSize (rxTexture->getSize());
     156           0 :     if( aBitmapSize.Width < 1 || aBitmapSize.Height < 1)
     157           0 :         return;
     158             : 
     159           0 :     const sal_Int32 nLeft = (rRepaintBox.X / aBitmapSize.Width) * aBitmapSize.Width;
     160           0 :     const sal_Int32 nTop = (rRepaintBox.Y / aBitmapSize.Height) * aBitmapSize.Height;
     161           0 :     const sal_Int32 nRight = ((rRepaintBox.X + rRepaintBox.Width - 1 + aBitmapSize.Width - 1)
     162           0 :         / aBitmapSize.Width) * aBitmapSize.Width;
     163           0 :     const sal_Int32 nBottom = ((rRepaintBox.Y + rRepaintBox.Height - 1 + aBitmapSize.Height - 1)
     164           0 :         / aBitmapSize.Height) * aBitmapSize.Height;
     165             : 
     166           0 :     for (sal_Int32 nY=nTop; nY<=nBottom; nY+=aBitmapSize.Height)
     167           0 :         for (sal_Int32 nX=nLeft; nX<=nRight; nX+=aBitmapSize.Width)
     168             :         {
     169           0 :             if (PresenterGeometryHelper::IsInside(
     170             :                 awt::Rectangle(nX,nY,aBitmapSize.Width,aBitmapSize.Height),
     171           0 :                 rHole))
     172             :             {
     173           0 :                 continue;
     174             :             }
     175           0 :             aRenderState.AffineTransform.m02 = nX;
     176           0 :             aRenderState.AffineTransform.m12 = nY;
     177           0 :             rxCanvas->drawBitmap(
     178             :                 rxTexture,
     179             :                 aViewState,
     180           0 :                 aRenderState);
     181           0 :         }
     182             : }
     183             : 
     184           0 : void PresenterCanvasHelper::PaintBitmap (
     185             :     const css::uno::Reference<css::rendering::XBitmap>& rxBitmap,
     186             :     const awt::Point& rLocation,
     187             :     const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
     188             :     const css::awt::Rectangle& rRepaintBox,
     189             :     const css::uno::Reference<css::rendering::XPolyPolygon2D>& rxPolygon,
     190             :     const css::rendering::ViewState& rDefaultViewState,
     191             :     const css::rendering::RenderState& rDefaultRenderState)
     192             : {
     193           0 :     if ( ! rxCanvas.is() || ! rxCanvas->getDevice().is())
     194           0 :         return;
     195             : 
     196           0 :     if ( ! rxBitmap.is())
     197           0 :         return;
     198             : 
     199           0 :     if ( ! rxPolygon.is())
     200           0 :         return;
     201             : 
     202             :     // Set the repaint box as clip rectangle at the view state.
     203           0 :     rendering::ViewState aViewState (rDefaultViewState);
     204           0 :     aViewState.Clip = PresenterGeometryHelper::CreatePolygon(rRepaintBox, rxCanvas->getDevice());
     205             : 
     206             :     // Setup the rendering state so that the bitmap is painted top left in
     207             :     // the polygon bounding box.
     208           0 :     rendering::RenderState aRenderState (rDefaultRenderState);
     209           0 :     aRenderState.AffineTransform = geometry::AffineMatrix2D(1,0, rLocation.X, 0,1,rLocation.Y);
     210           0 :     aRenderState.Clip = rxPolygon;
     211             : 
     212           0 :     rxCanvas->drawBitmap(
     213             :         rxBitmap,
     214             :         aViewState,
     215           0 :         aRenderState);
     216             : }
     217             : 
     218           0 : void PresenterCanvasHelper::PaintColor (
     219             :     const css::util::Color nColor,
     220             :     const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
     221             :     const css::awt::Rectangle& rRepaintBox,
     222             :     const css::uno::Reference<css::rendering::XPolyPolygon2D>& rxPolygon,
     223             :     const css::rendering::ViewState& rDefaultViewState,
     224             :     const css::rendering::RenderState& rDefaultRenderState)
     225             : {
     226           0 :     if ( ! rxCanvas.is() || ! rxCanvas->getDevice().is())
     227           0 :         return;
     228             : 
     229           0 :     if ( ! rxPolygon.is())
     230           0 :         return;
     231             : 
     232             :     // Set the repaint box as clip rectangle at the view state.
     233           0 :     rendering::ViewState aViewState (rDefaultViewState);
     234           0 :     aViewState.Clip = PresenterGeometryHelper::CreatePolygon(rRepaintBox, rxCanvas->getDevice());
     235             : 
     236             :     // Setup the rendering state to use the given color.
     237           0 :     rendering::RenderState aRenderState (rDefaultRenderState);
     238           0 :     SetDeviceColor(aRenderState, nColor);
     239             : 
     240           0 :     rxCanvas->fillPolyPolygon(
     241             :         rxPolygon,
     242             :         aViewState,
     243           0 :         aRenderState);
     244             : }
     245             : 
     246           0 : void PresenterCanvasHelper::SetDeviceColor(
     247             :     rendering::RenderState& rRenderState,
     248             :     const util::Color aColor)
     249             : {
     250             :     // Other component counts then 4 (RGBA) are not accepted (anymore).
     251             : 
     252             :     OSL_ASSERT(rRenderState.DeviceColor.getLength() == 4);
     253           0 :     if (rRenderState.DeviceColor.getLength() == 4)
     254             :     {
     255           0 :         rRenderState.DeviceColor[0] = ((aColor >> 16) & 0x0ff) / 255.0;
     256           0 :         rRenderState.DeviceColor[1] = ((aColor >> 8) & 0x0ff) / 255.0;
     257           0 :         rRenderState.DeviceColor[2] = ((aColor >> 0) & 0x0ff) / 255.0;
     258           0 :         rRenderState.DeviceColor[3] = 1.0 - ((aColor >> 24) & 0x0ff) / 255.0;
     259             :     }
     260           0 : }
     261             : 
     262           0 : css::geometry::RealRectangle2D PresenterCanvasHelper::GetTextBoundingBox (
     263             :     const css::uno::Reference<css::rendering::XCanvasFont>& rxFont,
     264             :     const OUString& rsText,
     265             :     const sal_Int8 nTextDirection)
     266             : {
     267           0 :     if (rxFont.is() && !rsText.isEmpty())
     268             :     {
     269           0 :         rendering::StringContext aContext (rsText, 0, rsText.getLength());
     270             :         Reference<rendering::XTextLayout> xLayout (
     271           0 :             rxFont->createTextLayout(aContext, nTextDirection, 0));
     272           0 :         return xLayout->queryTextBounds();
     273             :     }
     274             :     else
     275             :     {
     276           0 :         return geometry::RealRectangle2D(0,0,0,0);
     277             :     }
     278             : }
     279             : 
     280           0 : css::geometry::RealSize2D PresenterCanvasHelper::GetTextSize (
     281             :     const css::uno::Reference<css::rendering::XCanvasFont>& rxFont,
     282             :     const OUString& rsText,
     283             :     const sal_Int8 nTextDirection)
     284             : {
     285           0 :     const geometry::RealRectangle2D aTextBBox (GetTextBoundingBox(rxFont, rsText, nTextDirection));
     286           0 :     return css::geometry::RealSize2D(aTextBBox.X2 - aTextBBox.X1, aTextBBox.Y2 - aTextBBox.Y1);
     287             : }
     288             : 
     289             : } } // end of namespace sdext::presenter
     290             : 
     291             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10