LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/writerfilter/source/dmapper - CellColorHandler.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 43 47 91.5 %
Date: 2013-07-09 Functions: 7 8 87.5 %
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             : #include <CellColorHandler.hxx>
      20             : #include <PropertyMap.hxx>
      21             : #include <doctok/resourceids.hxx>
      22             : #include <ConversionHelper.hxx>
      23             : #include <ooxml/resourceids.hxx>
      24             : #include <com/sun/star/drawing/ShadingPattern.hpp>
      25             : #include <sal/macros.h>
      26             : #include "dmapperLoggers.hxx"
      27             : 
      28             : #define OOXML_COLOR_AUTO 0x0a //todo: AutoColor needs symbol
      29             : 
      30             : namespace writerfilter {
      31             : namespace dmapper {
      32             : 
      33             : using namespace ::com::sun::star::drawing;
      34             : using namespace ::writerfilter;
      35             : 
      36             : 
      37         414 : CellColorHandler::CellColorHandler() :
      38             : LoggedProperties(dmapper_logger, "CellColorHandler"),
      39             : m_nShadingPattern( ShadingPattern::CLEAR ),
      40             : m_nColor( 0xffffffff ),
      41             : m_nFillColor( 0xffffffff ),
      42         414 :     m_OutputFormat( Form )
      43             : {
      44         414 : }
      45             : 
      46         828 : CellColorHandler::~CellColorHandler()
      47             : {
      48         828 : }
      49             : 
      50        1220 : void CellColorHandler::lcl_attribute(Id rName, Value & rVal)
      51             : {
      52        1220 :     sal_Int32 nIntValue = rVal.getInt();
      53        1220 :     switch( rName )
      54             :     {
      55             :         case NS_rtf::LN_cellTopColor:
      56             :         case NS_rtf::LN_cellLeftColor:
      57             :         case NS_rtf::LN_cellBottomColor:
      58             :         case NS_rtf::LN_cellRightColor:
      59             :             // nIntValue contains the color, directly
      60           0 :         break;
      61             :         case NS_ooxml::LN_CT_Shd_val:
      62             :         {
      63             :             //might be clear, pct5...90, some hatch types
      64             :             //TODO: The values need symbolic names!
      65         408 :             m_nShadingPattern = nIntValue; //clear == 0, solid: 1, pct5: 2, pct50:8, pct95: x3c, horzStripe:0x0e, thinVertStripe: 0x15
      66             :         }
      67         408 :         break;
      68             :         case NS_ooxml::LN_CT_Shd_fill:
      69         414 :             if( nIntValue == OOXML_COLOR_AUTO )
      70          48 :                 nIntValue = 0xffffff; //fill color auto means white
      71         414 :             m_nFillColor = nIntValue;
      72         414 :         break;
      73             :         case NS_ooxml::LN_CT_Shd_color:
      74         355 :             if( nIntValue == OOXML_COLOR_AUTO )
      75         354 :                 nIntValue = 0; //shading color auto means black
      76             :             //color of the shading
      77         355 :             m_nColor = nIntValue;
      78         355 :         break;
      79             :         case NS_ooxml::LN_CT_Shd_themeFill:
      80             :         case NS_ooxml::LN_CT_Shd_themeFillTint:
      81             :         case NS_ooxml::LN_CT_Shd_themeFillShade:
      82             :             // ignored
      83          43 :             break;
      84             :         default:
      85             :             OSL_FAIL( "unknown attribute");
      86             :     }
      87        1220 : }
      88             : 
      89           0 : void CellColorHandler::lcl_sprm(Sprm & rSprm)
      90             : {
      91             :     (void)rSprm;
      92           0 : }
      93             : 
      94         414 : TablePropertyMapPtr  CellColorHandler::getProperties()
      95             : {
      96         414 :     TablePropertyMapPtr pPropertyMap(new TablePropertyMap);
      97             : 
      98             :     // Code from binary word filter (the values are out of 1000)
      99             :     static const sal_Int32 eMSGrayScale[] =
     100             :     {
     101             :         // Clear-Brush
     102             :            0,   // 0    clear
     103             :         // Solid-Brush
     104             :         1000,   // 1    solid
     105             :         // Percent values
     106             :           50,   // 2    pct5
     107             :          100,   // 3    pct10
     108             :          200,   // 4    pct20
     109             :          250,   // 5    pct25
     110             :          300,   // 6    pct30
     111             :          400,   // 7    pct40
     112             :          500,   // 8    pct50
     113             :          600,   // 9    pct60
     114             :          700,   // 10   pct70
     115             :          750,   // 11   pct75
     116             :          800,   // 12   pct80
     117             :          900,   // 13   pct90
     118             :         // Special cases
     119             :          333,   // 14   Dark Horizontal
     120             :          333,   // 15   Dark Vertical
     121             :          333,   // 16   Dark Forward Diagonal
     122             :          333,   // 17   Dark Backward Diagonal
     123             :          333,   // 18   Dark Cross
     124             :          333,   // 19   Dark Diagonal Cross
     125             :          333,   // 20   Horizontal
     126             :          333,   // 21   Vertical
     127             :          333,   // 22   Forward Diagonal
     128             :          333,   // 23   Backward Diagonal
     129             :          333,   // 24   Cross
     130             :          333,   // 25   Diagonal Cross
     131             :         // Undefined values in DOC spec-sheet
     132             :          500,   // 26
     133             :          500,   // 27
     134             :          500,   // 28
     135             :          500,   // 29
     136             :          500,   // 30
     137             :          500,   // 31
     138             :          500,   // 32
     139             :          500,   // 33
     140             :          500,   // 34
     141             :         // Different shading types
     142             :           25,   // 35   [available in DOC, not available in DOCX]
     143             :           75,   // 36   [available in DOC, not available in DOCX]
     144             :          125,   // 37   pct12
     145             :          150,   // 38   pct15
     146             :          175,   // 39   [available in DOC, not available in DOCX]
     147             :          225,   // 40   [available in DOC, not available in DOCX]
     148             :          275,   // 41   [available in DOC, not available in DOCX]
     149             :          325,   // 42   [available in DOC, not available in DOCX]
     150             :          350,   // 43   pct35
     151             :          375,   // 44   pct37
     152             :          425,   // 45   [available in DOC, not available in DOCX]
     153             :          450,   // 46   pct45
     154             :          475,   // 47   [available in DOC, not available in DOCX]
     155             :          525,   // 48   [available in DOC, not available in DOCX]
     156             :          550,   // 49   pct55
     157             :          575,   // 50   [available in DOC, not available in DOCX]
     158             :          625,   // 51   pct62
     159             :          650,   // 52   pct65
     160             :          675,   // 53   [available in DOC, not available in DOCX]
     161             :          725,   // 54   [available in DOC, not available in DOCX]
     162             :          775,   // 55   [available in DOC, not available in DOCX]
     163             :          825,   // 56   [available in DOC, not available in DOCX]
     164             :          850,   // 57   pct85
     165             :          875,   // 58   pct87
     166             :          925,   // 59   [available in DOC, not available in DOCX]
     167             :          950,   // 60   pct95
     168             :          975    // 61   [available in DOC, not available in DOCX]
     169             :     };// 62
     170             : 
     171         414 :     if( m_nShadingPattern >= (sal_Int32)SAL_N_ELEMENTS( eMSGrayScale ) )
     172           0 :         m_nShadingPattern = 0;
     173             : 
     174         414 :     sal_Int32 nWW8BrushStyle = eMSGrayScale[m_nShadingPattern];
     175         414 :     sal_Int32 nApplyColor = 0;
     176         414 :     if( !nWW8BrushStyle )
     177             :     {
     178             :         // Clear-Brush
     179         411 :         nApplyColor = m_nFillColor;
     180             :     }
     181             :     else
     182             :     {
     183           3 :         sal_Int32 nFore = m_nColor;
     184           3 :         sal_Int32 nBack = m_nFillColor;
     185             : 
     186           3 :         sal_uInt32 nRed = ((nFore & 0xff0000)>>0x10) * nWW8BrushStyle;
     187           3 :         sal_uInt32 nGreen = ((nFore & 0xff00)>>0x8) * nWW8BrushStyle;
     188           3 :         sal_uInt32 nBlue = (nFore & 0xff) * nWW8BrushStyle;
     189           3 :         nRed += ((nBack & 0xff0000)>>0x10)  * (1000L - nWW8BrushStyle);
     190           3 :         nGreen += ((nBack & 0xff00)>>0x8)* (1000L - nWW8BrushStyle);
     191           3 :         nBlue += (nBack & 0xff) * (1000L - nWW8BrushStyle);
     192             : 
     193           3 :         nApplyColor = ( (nRed/1000) << 0x10 ) + ((nGreen/1000) << 8) + nBlue/1000;
     194             :     }
     195             : 
     196             :     // Check if it is a 'Character'
     197         414 :     if (m_OutputFormat == Character)
     198             :     {
     199             :         static sal_Int32 aWWShadingPatterns[ ] =
     200             :         {
     201             :             ShadingPattern::CLEAR,
     202             :             ShadingPattern::SOLID,
     203             :             ShadingPattern::PCT5,
     204             :             ShadingPattern::PCT10,
     205             :             ShadingPattern::PCT20,
     206             :             ShadingPattern::PCT25,
     207             :             ShadingPattern::PCT30,
     208             :             ShadingPattern::PCT40,
     209             :             ShadingPattern::PCT50,
     210             :             ShadingPattern::PCT60,
     211             :             ShadingPattern::PCT70,
     212             :             ShadingPattern::PCT75,
     213             :             ShadingPattern::PCT80,
     214             :             ShadingPattern::PCT90,
     215             :             ShadingPattern::HORZ_STRIPE,
     216             :             ShadingPattern::VERT_STRIPE,
     217             :             ShadingPattern::REVERSE_DIAG_STRIPE,
     218             :             ShadingPattern::DIAG_STRIPE,
     219             :             ShadingPattern::HORZ_CROSS,
     220             :             ShadingPattern::DIAG_CROSS,
     221             :             ShadingPattern::THIN_HORZ_STRIPE,
     222             :             ShadingPattern::THIN_VERT_STRIPE,
     223             :             ShadingPattern::THIN_REVERSE_DIAG_STRIPE,
     224             :             ShadingPattern::THIN_DIAG_STRIPE,
     225             :             ShadingPattern::THIN_HORZ_CROSS,
     226             :             ShadingPattern::THIN_DIAG_CROSS,
     227             :             ShadingPattern::UNUSED_1,
     228             :             ShadingPattern::UNUSED_2,
     229             :             ShadingPattern::UNUSED_3,
     230             :             ShadingPattern::UNUSED_4,
     231             :             ShadingPattern::UNUSED_5,
     232             :             ShadingPattern::UNUSED_6,
     233             :             ShadingPattern::UNUSED_7,
     234             :             ShadingPattern::UNUSED_8,
     235             :             ShadingPattern::UNUSED_9,
     236             :             ShadingPattern::PCT2,
     237             :             ShadingPattern::PCT7,
     238             :             ShadingPattern::PCT12,
     239             :             ShadingPattern::PCT15,
     240             :             ShadingPattern::PCT17,
     241             :             ShadingPattern::PCT22,
     242             :             ShadingPattern::PCT27,
     243             :             ShadingPattern::PCT32,
     244             :             ShadingPattern::PCT35,
     245             :             ShadingPattern::PCT37,
     246             :             ShadingPattern::PCT42,
     247             :             ShadingPattern::PCT45,
     248             :             ShadingPattern::PCT47,
     249             :             ShadingPattern::PCT52,
     250             :             ShadingPattern::PCT55,
     251             :             ShadingPattern::PCT57,
     252             :             ShadingPattern::PCT62,
     253             :             ShadingPattern::PCT65,
     254             :             ShadingPattern::PCT67,
     255             :             ShadingPattern::PCT72,
     256             :             ShadingPattern::PCT77,
     257             :             ShadingPattern::PCT82,
     258             :             ShadingPattern::PCT85,
     259             :             ShadingPattern::PCT87,
     260             :             ShadingPattern::PCT92,
     261             :             ShadingPattern::PCT95,
     262             :             ShadingPattern::PCT97
     263             :         };
     264             : 
     265             :         // Write the shading pattern property
     266           8 :         pPropertyMap->Insert(PROP_CHAR_SHADING_VALUE, uno::makeAny( aWWShadingPatterns[m_nShadingPattern] ));
     267             :     }
     268             : 
     269         828 :     pPropertyMap->Insert( m_OutputFormat == Form ? PROP_BACK_COLOR
     270          11 :                         : m_OutputFormat == Paragraph ? PROP_PARA_BACK_COLOR
     271        1253 :                         : PROP_CHAR_BACK_COLOR, uno::makeAny( nApplyColor ));
     272         414 :     return pPropertyMap;
     273             : }
     274             : } //namespace dmapper
     275          24 : } //namespace writerfilter
     276             : 
     277             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10