LCOV - code coverage report
Current view: top level - libreoffice/sdext/source/presenter - PresenterCanvasHelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 85 0.0 %
Date: 2012-12-27 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             :         return;
      71             : 
      72           0 :     if ( ! rxCanvas.is() || ! rxCanvas->getDevice().is())
      73             :         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             :         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             :         return;
     140             : 
     141           0 :     if ( ! rxTexture.is())
     142             :         return;
     143             : 
     144           0 :     if ( ! rxPolygon.is())
     145             :         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 :     const sal_Int32 nLeft = (rRepaintBox.X / aBitmapSize.Width) * aBitmapSize.Width;
     157           0 :     const sal_Int32 nTop = (rRepaintBox.Y / aBitmapSize.Height) * aBitmapSize.Height;
     158             :     const sal_Int32 nRight = ((rRepaintBox.X + rRepaintBox.Width - 1 + aBitmapSize.Width - 1)
     159           0 :         / aBitmapSize.Width) * aBitmapSize.Width;
     160             :     const sal_Int32 nBottom = ((rRepaintBox.Y + rRepaintBox.Height - 1 + aBitmapSize.Height - 1)
     161           0 :         / aBitmapSize.Height) * aBitmapSize.Height;
     162             : 
     163           0 :     for (sal_Int32 nY=nTop; nY<=nBottom; nY+=aBitmapSize.Height)
     164           0 :         for (sal_Int32 nX=nLeft; nX<=nRight; nX+=aBitmapSize.Width)
     165             :         {
     166           0 :             if (PresenterGeometryHelper::IsInside(
     167             :                 awt::Rectangle(nX,nY,aBitmapSize.Width,aBitmapSize.Height),
     168           0 :                 rHole))
     169             :             {
     170           0 :                 continue;
     171             :             }
     172           0 :             aRenderState.AffineTransform.m02 = nX;
     173           0 :             aRenderState.AffineTransform.m12 = nY;
     174           0 :             rxCanvas->drawBitmap(
     175             :                 rxTexture,
     176             :                 aViewState,
     177           0 :                 aRenderState);
     178           0 :         }
     179             : }
     180             : 
     181           0 : void PresenterCanvasHelper::PaintBitmap (
     182             :     const css::uno::Reference<css::rendering::XBitmap>& rxBitmap,
     183             :     const awt::Point& rLocation,
     184             :     const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
     185             :     const css::awt::Rectangle& rRepaintBox,
     186             :     const css::uno::Reference<css::rendering::XPolyPolygon2D>& rxPolygon,
     187             :     const css::rendering::ViewState& rDefaultViewState,
     188             :     const css::rendering::RenderState& rDefaultRenderState)
     189             : {
     190           0 :     if ( ! rxCanvas.is() || ! rxCanvas->getDevice().is())
     191             :         return;
     192             : 
     193           0 :     if ( ! rxBitmap.is())
     194             :         return;
     195             : 
     196           0 :     if ( ! rxPolygon.is())
     197             :         return;
     198             : 
     199             :     // Set the repaint box as clip rectangle at the view state.
     200           0 :     rendering::ViewState aViewState (rDefaultViewState);
     201           0 :     aViewState.Clip = PresenterGeometryHelper::CreatePolygon(rRepaintBox, rxCanvas->getDevice());
     202             : 
     203             :     // Setup the rendering state so that the bitmap is painted top left in
     204             :     // the polygon bounding box.
     205           0 :     rendering::RenderState aRenderState (rDefaultRenderState);
     206           0 :     aRenderState.AffineTransform = geometry::AffineMatrix2D(1,0, rLocation.X, 0,1,rLocation.Y);
     207           0 :     aRenderState.Clip = rxPolygon;
     208             : 
     209           0 :     rxCanvas->drawBitmap(
     210             :         rxBitmap,
     211             :         aViewState,
     212           0 :         aRenderState);
     213             : }
     214             : 
     215           0 : void PresenterCanvasHelper::PaintColor (
     216             :     const css::util::Color nColor,
     217             :     const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
     218             :     const css::awt::Rectangle& rRepaintBox,
     219             :     const css::uno::Reference<css::rendering::XPolyPolygon2D>& rxPolygon,
     220             :     const css::rendering::ViewState& rDefaultViewState,
     221             :     const css::rendering::RenderState& rDefaultRenderState)
     222             : {
     223           0 :     if ( ! rxCanvas.is() || ! rxCanvas->getDevice().is())
     224             :         return;
     225             : 
     226           0 :     if ( ! rxPolygon.is())
     227             :         return;
     228             : 
     229             :     // Set the repaint box as clip rectangle at the view state.
     230           0 :     rendering::ViewState aViewState (rDefaultViewState);
     231           0 :     aViewState.Clip = PresenterGeometryHelper::CreatePolygon(rRepaintBox, rxCanvas->getDevice());
     232             : 
     233             :     // Setup the rendering state to use the given color.
     234           0 :     rendering::RenderState aRenderState (rDefaultRenderState);
     235           0 :     SetDeviceColor(aRenderState, nColor);
     236             : 
     237           0 :     rxCanvas->fillPolyPolygon(
     238             :         rxPolygon,
     239             :         aViewState,
     240           0 :         aRenderState);
     241             : }
     242             : 
     243           0 : void PresenterCanvasHelper::SetDeviceColor(
     244             :     rendering::RenderState& rRenderState,
     245             :     const util::Color aColor)
     246             : {
     247             :     // Other component counts then 4 (RGBA) are not accepted (anymore).
     248             : 
     249             :     OSL_ASSERT(rRenderState.DeviceColor.getLength() == 4);
     250           0 :     if (rRenderState.DeviceColor.getLength() == 4)
     251             :     {
     252           0 :         rRenderState.DeviceColor[0] = ((aColor >> 16) & 0x0ff) / 255.0;
     253           0 :         rRenderState.DeviceColor[1] = ((aColor >> 8) & 0x0ff) / 255.0;
     254           0 :         rRenderState.DeviceColor[2] = ((aColor >> 0) & 0x0ff) / 255.0;
     255           0 :         rRenderState.DeviceColor[3] = 1.0 - ((aColor >> 24) & 0x0ff) / 255.0;
     256             :     }
     257           0 : }
     258             : 
     259           0 : css::geometry::RealRectangle2D PresenterCanvasHelper::GetTextBoundingBox (
     260             :     const css::uno::Reference<css::rendering::XCanvasFont>& rxFont,
     261             :     const ::rtl::OUString& rsText,
     262             :     const sal_Int8 nTextDirection)
     263             : {
     264           0 :     if (rxFont.is() && !rsText.isEmpty())
     265             :     {
     266           0 :         rendering::StringContext aContext (rsText, 0, rsText.getLength());
     267             :         Reference<rendering::XTextLayout> xLayout (
     268           0 :             rxFont->createTextLayout(aContext, nTextDirection, 0));
     269           0 :         return xLayout->queryTextBounds();
     270             :     }
     271             :     else
     272             :     {
     273           0 :         return geometry::RealRectangle2D(0,0,0,0);
     274             :     }
     275             : }
     276             : 
     277           0 : css::geometry::RealSize2D PresenterCanvasHelper::GetTextSize (
     278             :     const css::uno::Reference<css::rendering::XCanvasFont>& rxFont,
     279             :     const ::rtl::OUString& rsText,
     280             :     const sal_Int8 nTextDirection)
     281             : {
     282           0 :     const geometry::RealRectangle2D aTextBBox (GetTextBoundingBox(rxFont, rsText, nTextDirection));
     283           0 :     return css::geometry::RealSize2D(aTextBBox.X2 - aTextBBox.X1, aTextBBox.Y2 - aTextBBox.Y1);
     284             : }
     285             : 
     286             : } } // end of namespace sdext::presenter
     287             : 
     288             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10