LCOV - code coverage report
Current view: top level - writerfilter/source/dmapper - CellColorHandler.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 89 120 74.2 %
Date: 2014-04-11 Functions: 11 12 91.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             : #include <CellColorHandler.hxx>
      20             : #include <PropertyMap.hxx>
      21             : #include <ConversionHelper.hxx>
      22             : #include <TDefTableHandler.hxx>
      23             : #include <ooxml/resourceids.hxx>
      24             : #include <com/sun/star/drawing/ShadingPattern.hpp>
      25             : #include <sal/macros.h>
      26             : #include <filter/msfilter/util.hxx>
      27             : #include "dmapperLoggers.hxx"
      28             : 
      29             : namespace writerfilter {
      30             : namespace dmapper {
      31             : 
      32             : using namespace ::com::sun::star::drawing;
      33             : using namespace ::writerfilter;
      34             : 
      35             : 
      36        3165 : CellColorHandler::CellColorHandler() :
      37             : LoggedProperties(dmapper_logger, "CellColorHandler"),
      38             : m_nShadingPattern( ShadingPattern::CLEAR ),
      39             : m_nColor( 0xffffffff ),
      40             : m_nFillColor( 0xffffffff ),
      41        3165 :     m_OutputFormat( Form )
      42             : {
      43        3165 : }
      44             : 
      45        6330 : CellColorHandler::~CellColorHandler()
      46             : {
      47        6330 : }
      48             : 
      49             : // ST_Shd strings are converted to integers by the tokenizer, store strings in
      50             : // the InteropGrabBag
      51        3157 : uno::Any lcl_ConvertShd(sal_Int32 nIntValue)
      52             : {
      53        3157 :     OUString aRet;
      54             :     // This should be in sync with the ST_Shd list in ooxml's model.xml.
      55        3157 :     switch (nIntValue)
      56             :     {
      57        2957 :         case 0: aRet = "clear"; break;
      58          96 :         case 1: aRet = "solid"; break;
      59           3 :         case 2: aRet = "pct5"; break;
      60           7 :         case 3: aRet = "pct10"; break;
      61          23 :         case 4: aRet = "pct20"; break;
      62          33 :         case 5: aRet = "pct25"; break;
      63          12 :         case 6: aRet = "pct30"; break;
      64           0 :         case 7: aRet = "pct40"; break;
      65          18 :         case 8: aRet = "pct50"; break;
      66           0 :         case 9: aRet = "pct60"; break;
      67           0 :         case 10: aRet = "pct70"; break;
      68           3 :         case 11: aRet = "pct75"; break;
      69           0 :         case 12: aRet = "pct80"; break;
      70           0 :         case 13: aRet = "pct90"; break;
      71           0 :         case 14: aRet = "horzStripe"; break;
      72           0 :         case 15: aRet = "vertStripe"; break;
      73           0 :         case 17: aRet = "reverseDiagStripe"; break;
      74           0 :         case 16: aRet = "diagStripe"; break;
      75           0 :         case 18: aRet = "horzCross"; break;
      76           0 :         case 19: aRet = "diagCross"; break;
      77           0 :         case 20: aRet = "thinHorzStripe"; break;
      78           0 :         case 21: aRet = "thinVertStripe"; break;
      79           0 :         case 23: aRet = "thinReverseDiagStripe"; break;
      80           0 :         case 22: aRet = "thinDiagStripe"; break;
      81           0 :         case 24: aRet = "thinHorzCross"; break;
      82           0 :         case 25: aRet = "thinDiagCross"; break;
      83           0 :         case 37: aRet = "pct12"; break;
      84           5 :         case 38: aRet = "pct15"; break;
      85           0 :         case 43: aRet = "pct35"; break;
      86           0 :         case 44: aRet = "pct37"; break;
      87           0 :         case 46: aRet = "pct45"; break;
      88           0 :         case 49: aRet = "pct55"; break;
      89           0 :         case 51: aRet = "pct62"; break;
      90           0 :         case 52: aRet = "pct65"; break;
      91           0 :         case 57: aRet = "pct85"; break;
      92           0 :         case 58: aRet = "pct87"; break;
      93           0 :         case 60: aRet = "pct95"; break;
      94           0 :         case 65535: aRet = "nil"; break;
      95             :     }
      96        3157 :     return uno::makeAny(aRet);
      97             : }
      98             : 
      99        8586 : void CellColorHandler::lcl_attribute(Id rName, Value & rVal)
     100             : {
     101        8586 :     sal_Int32 nIntValue = rVal.getInt();
     102        8586 :     switch( rName )
     103             :     {
     104             :         case NS_ooxml::LN_CT_Shd_val:
     105             :         {
     106        3157 :             createGrabBag("val", lcl_ConvertShd(nIntValue));
     107             :             //might be clear, pct5...90, some hatch types
     108             :             //TODO: The values need symbolic names!
     109        3157 :             m_nShadingPattern = nIntValue; //clear == 0, solid: 1, pct5: 2, pct50:8, pct95: x3c, horzStripe:0x0e, thinVertStripe: 0x15
     110             :         }
     111        3157 :         break;
     112             :         case NS_ooxml::LN_CT_Shd_fill:
     113        3165 :             createGrabBag("fill", uno::makeAny(OStringToOUString(msfilter::util::ConvertColor(nIntValue, /*bAutoColor=*/true), RTL_TEXTENCODING_UTF8)));
     114        3165 :             if( nIntValue == OOXML_COLOR_AUTO )
     115        1494 :                 nIntValue = 0xffffff; //fill color auto means white
     116        3165 :             m_nFillColor = nIntValue;
     117        3165 :         break;
     118             :         case NS_ooxml::LN_CT_Shd_color:
     119        1830 :             createGrabBag("color", uno::makeAny(OStringToOUString(msfilter::util::ConvertColor(nIntValue, /*bAutoColor=*/true), RTL_TEXTENCODING_UTF8)));
     120        1830 :             if( nIntValue == OOXML_COLOR_AUTO )
     121        1614 :                 nIntValue = 0; //shading color auto means black
     122             :             //color of the shading
     123        1830 :             m_nColor = nIntValue;
     124        1830 :         break;
     125             :         case NS_ooxml::LN_CT_Shd_themeFill:
     126         251 :             createGrabBag("themeFill", uno::makeAny(TDefTableHandler::getThemeColorTypeString(nIntValue)));
     127         251 :         break;
     128             :         case NS_ooxml::LN_CT_Shd_themeFillShade:
     129          90 :             createGrabBag("themeFillShade", uno::makeAny(OUString::number(nIntValue, 16)));
     130          90 :         break;
     131             :         case NS_ooxml::LN_CT_Shd_themeFillTint:
     132          93 :             createGrabBag("themeFillTint", uno::makeAny(OUString::number(nIntValue, 16)));
     133          93 :             break;
     134             :         default:
     135             :             OSL_FAIL( "unknown attribute");
     136             :     }
     137        8586 : }
     138             : 
     139           0 : void CellColorHandler::lcl_sprm(Sprm & rSprm)
     140             : {
     141             :     (void)rSprm;
     142           0 : }
     143             : 
     144        3165 : TablePropertyMapPtr  CellColorHandler::getProperties()
     145             : {
     146        3165 :     TablePropertyMapPtr pPropertyMap(new TablePropertyMap);
     147             : 
     148             :     // Code from binary word filter (the values are out of 1000)
     149             :     static const sal_Int32 eMSGrayScale[] =
     150             :     {
     151             :         // Clear-Brush
     152             :            0,   // 0    clear
     153             :         // Solid-Brush
     154             :         1000,   // 1    solid
     155             :         // Percent values
     156             :           50,   // 2    pct5
     157             :          100,   // 3    pct10
     158             :          200,   // 4    pct20
     159             :          250,   // 5    pct25
     160             :          300,   // 6    pct30
     161             :          400,   // 7    pct40
     162             :          500,   // 8    pct50
     163             :          600,   // 9    pct60
     164             :          700,   // 10   pct70
     165             :          750,   // 11   pct75
     166             :          800,   // 12   pct80
     167             :          900,   // 13   pct90
     168             :         // Special cases
     169             :          333,   // 14   Dark Horizontal
     170             :          333,   // 15   Dark Vertical
     171             :          333,   // 16   Dark Forward Diagonal
     172             :          333,   // 17   Dark Backward Diagonal
     173             :          333,   // 18   Dark Cross
     174             :          333,   // 19   Dark Diagonal Cross
     175             :          333,   // 20   Horizontal
     176             :          333,   // 21   Vertical
     177             :          333,   // 22   Forward Diagonal
     178             :          333,   // 23   Backward Diagonal
     179             :          333,   // 24   Cross
     180             :          333,   // 25   Diagonal Cross
     181             :         // Undefined values in DOC spec-sheet
     182             :          500,   // 26
     183             :          500,   // 27
     184             :          500,   // 28
     185             :          500,   // 29
     186             :          500,   // 30
     187             :          500,   // 31
     188             :          500,   // 32
     189             :          500,   // 33
     190             :          500,   // 34
     191             :         // Different shading types
     192             :           25,   // 35   [available in DOC, not available in DOCX]
     193             :           75,   // 36   [available in DOC, not available in DOCX]
     194             :          125,   // 37   pct12
     195             :          150,   // 38   pct15
     196             :          175,   // 39   [available in DOC, not available in DOCX]
     197             :          225,   // 40   [available in DOC, not available in DOCX]
     198             :          275,   // 41   [available in DOC, not available in DOCX]
     199             :          325,   // 42   [available in DOC, not available in DOCX]
     200             :          350,   // 43   pct35
     201             :          375,   // 44   pct37
     202             :          425,   // 45   [available in DOC, not available in DOCX]
     203             :          450,   // 46   pct45
     204             :          475,   // 47   [available in DOC, not available in DOCX]
     205             :          525,   // 48   [available in DOC, not available in DOCX]
     206             :          550,   // 49   pct55
     207             :          575,   // 50   [available in DOC, not available in DOCX]
     208             :          625,   // 51   pct62
     209             :          650,   // 52   pct65
     210             :          675,   // 53   [available in DOC, not available in DOCX]
     211             :          725,   // 54   [available in DOC, not available in DOCX]
     212             :          775,   // 55   [available in DOC, not available in DOCX]
     213             :          825,   // 56   [available in DOC, not available in DOCX]
     214             :          850,   // 57   pct85
     215             :          875,   // 58   pct87
     216             :          925,   // 59   [available in DOC, not available in DOCX]
     217             :          950,   // 60   pct95
     218             :          975    // 61   [available in DOC, not available in DOCX]
     219             :     };// 62
     220             : 
     221        3165 :     if( m_nShadingPattern >= (sal_Int32)SAL_N_ELEMENTS( eMSGrayScale ) )
     222           0 :         m_nShadingPattern = 0;
     223             : 
     224        3165 :     sal_Int32 nWW8BrushStyle = eMSGrayScale[m_nShadingPattern];
     225        3165 :     sal_Int32 nApplyColor = 0;
     226        3165 :     if( !nWW8BrushStyle )
     227             :     {
     228             :         // Clear-Brush
     229        2965 :         nApplyColor = m_nFillColor;
     230             :     }
     231             :     else
     232             :     {
     233         200 :         sal_Int32 nFore = m_nColor;
     234         200 :         sal_Int32 nBack = m_nFillColor;
     235             : 
     236         200 :         sal_uInt32 nRed = ((nFore & 0xff0000)>>0x10) * nWW8BrushStyle;
     237         200 :         sal_uInt32 nGreen = ((nFore & 0xff00)>>0x8) * nWW8BrushStyle;
     238         200 :         sal_uInt32 nBlue = (nFore & 0xff) * nWW8BrushStyle;
     239         200 :         nRed += ((nBack & 0xff0000)>>0x10)  * (1000L - nWW8BrushStyle);
     240         200 :         nGreen += ((nBack & 0xff00)>>0x8)* (1000L - nWW8BrushStyle);
     241         200 :         nBlue += (nBack & 0xff) * (1000L - nWW8BrushStyle);
     242             : 
     243         200 :         nApplyColor = ( (nRed/1000) << 0x10 ) + ((nGreen/1000) << 8) + nBlue/1000;
     244             :     }
     245             : 
     246             :     // Check if it is a 'Character'
     247        3165 :     if (m_OutputFormat == Character)
     248             :     {
     249             :         static sal_Int32 aWWShadingPatterns[ ] =
     250             :         {
     251             :             ShadingPattern::CLEAR,
     252             :             ShadingPattern::SOLID,
     253             :             ShadingPattern::PCT5,
     254             :             ShadingPattern::PCT10,
     255             :             ShadingPattern::PCT20,
     256             :             ShadingPattern::PCT25,
     257             :             ShadingPattern::PCT30,
     258             :             ShadingPattern::PCT40,
     259             :             ShadingPattern::PCT50,
     260             :             ShadingPattern::PCT60,
     261             :             ShadingPattern::PCT70,
     262             :             ShadingPattern::PCT75,
     263             :             ShadingPattern::PCT80,
     264             :             ShadingPattern::PCT90,
     265             :             ShadingPattern::HORZ_STRIPE,
     266             :             ShadingPattern::VERT_STRIPE,
     267             :             ShadingPattern::REVERSE_DIAG_STRIPE,
     268             :             ShadingPattern::DIAG_STRIPE,
     269             :             ShadingPattern::HORZ_CROSS,
     270             :             ShadingPattern::DIAG_CROSS,
     271             :             ShadingPattern::THIN_HORZ_STRIPE,
     272             :             ShadingPattern::THIN_VERT_STRIPE,
     273             :             ShadingPattern::THIN_REVERSE_DIAG_STRIPE,
     274             :             ShadingPattern::THIN_DIAG_STRIPE,
     275             :             ShadingPattern::THIN_HORZ_CROSS,
     276             :             ShadingPattern::THIN_DIAG_CROSS,
     277             :             ShadingPattern::UNUSED_1,
     278             :             ShadingPattern::UNUSED_2,
     279             :             ShadingPattern::UNUSED_3,
     280             :             ShadingPattern::UNUSED_4,
     281             :             ShadingPattern::UNUSED_5,
     282             :             ShadingPattern::UNUSED_6,
     283             :             ShadingPattern::UNUSED_7,
     284             :             ShadingPattern::UNUSED_8,
     285             :             ShadingPattern::UNUSED_9,
     286             :             ShadingPattern::PCT2,
     287             :             ShadingPattern::PCT7,
     288             :             ShadingPattern::PCT12,
     289             :             ShadingPattern::PCT15,
     290             :             ShadingPattern::PCT17,
     291             :             ShadingPattern::PCT22,
     292             :             ShadingPattern::PCT27,
     293             :             ShadingPattern::PCT32,
     294             :             ShadingPattern::PCT35,
     295             :             ShadingPattern::PCT37,
     296             :             ShadingPattern::PCT42,
     297             :             ShadingPattern::PCT45,
     298             :             ShadingPattern::PCT47,
     299             :             ShadingPattern::PCT52,
     300             :             ShadingPattern::PCT55,
     301             :             ShadingPattern::PCT57,
     302             :             ShadingPattern::PCT62,
     303             :             ShadingPattern::PCT65,
     304             :             ShadingPattern::PCT67,
     305             :             ShadingPattern::PCT72,
     306             :             ShadingPattern::PCT77,
     307             :             ShadingPattern::PCT82,
     308             :             ShadingPattern::PCT85,
     309             :             ShadingPattern::PCT87,
     310             :             ShadingPattern::PCT92,
     311             :             ShadingPattern::PCT95,
     312             :             ShadingPattern::PCT97
     313             :         };
     314             : 
     315             :         // Write the shading pattern property
     316         141 :         pPropertyMap->Insert(PROP_CHAR_SHADING_VALUE, uno::makeAny( aWWShadingPatterns[m_nShadingPattern] ));
     317             :     }
     318             : 
     319        6330 :     pPropertyMap->Insert( m_OutputFormat == Form ? PROP_BACK_COLOR
     320         213 :                         : m_OutputFormat == Paragraph ? PROP_PARA_BACK_COLOR
     321        9708 :                         : PROP_CHAR_BACK_COLOR, uno::makeAny( nApplyColor ));
     322        3165 :     return pPropertyMap;
     323             : }
     324             : 
     325        8586 : void CellColorHandler::createGrabBag(const OUString& aName, uno::Any aAny)
     326             : {
     327        8586 :     if (m_aInteropGrabBagName.isEmpty())
     328        9203 :         return;
     329             : 
     330        7969 :     beans::PropertyValue aValue;
     331        7969 :     aValue.Name = aName;
     332        7969 :     aValue.Value = aAny;
     333        7969 :     m_aInteropGrabBag.push_back(aValue);
     334             : }
     335             : 
     336        2934 : void CellColorHandler::enableInteropGrabBag(const OUString& aName)
     337             : {
     338        2934 :     m_aInteropGrabBagName = aName;
     339        2934 : }
     340             : 
     341        2934 : beans::PropertyValue CellColorHandler::getInteropGrabBag()
     342             : {
     343        2934 :     beans::PropertyValue aRet;
     344        2934 :     aRet.Name = m_aInteropGrabBagName;
     345             : 
     346        5868 :     uno::Sequence<beans::PropertyValue> aSeq(m_aInteropGrabBag.size());
     347        2934 :     beans::PropertyValue* pSeq = aSeq.getArray();
     348       10903 :     for (std::vector<beans::PropertyValue>::iterator i = m_aInteropGrabBag.begin(); i != m_aInteropGrabBag.end(); ++i)
     349        7969 :         *pSeq++ = *i;
     350             : 
     351        2934 :     aRet.Value = uno::makeAny(aSeq);
     352        5868 :     return aRet;
     353             : }
     354             : 
     355          72 : void CellColorHandler::disableInteropGrabBag()
     356             : {
     357          72 :     m_aInteropGrabBagName = "";
     358          72 :     m_aInteropGrabBag.clear();
     359          72 : }
     360             : 
     361          72 : sal_Bool CellColorHandler::isInteropGrabBagEnabled()
     362             : {
     363          72 :     return !(m_aInteropGrabBagName.isEmpty());
     364             : }
     365             : 
     366             : } //namespace dmapper
     367             : } //namespace writerfilter
     368             : 
     369             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10