LCOV - code coverage report
Current view: top level - oox/source/drawingml - clrscheme.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 34 35 97.1 %
Date: 2015-06-13 12:38:46 Functions: 7 7 100.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 <osl/diagnose.h>
      21             : #include "oox/drawingml/clrscheme.hxx"
      22             : #include "oox/token/tokens.hxx"
      23             : 
      24             : namespace oox { namespace drawingml {
      25             : 
      26        4275 : bool ClrMap::getColorMap( sal_Int32& nClrToken )
      27             : {
      28        4275 :     sal_Int32 nMapped = 0;
      29        4275 :     std::map < sal_Int32, sal_Int32 >::const_iterator aIter( maClrMap.find( nClrToken ) );
      30        4275 :     if ( aIter != maClrMap.end() )
      31        3260 :         nMapped = (*aIter).second;
      32        4275 :     if ( nMapped )
      33             :     {
      34        3260 :         nClrToken = nMapped;
      35        3260 :         return true;
      36             :     }
      37             :     else
      38        1015 :         return false;
      39             : }
      40             : 
      41        1236 : void ClrMap::setColorMap( sal_Int32 nClrToken, sal_Int32 nMappedClrToken )
      42             : {
      43        1236 :     maClrMap[ nClrToken ] = nMappedClrToken;
      44        1236 : }
      45             : 
      46             : struct find_by_token
      47             : {
      48       13338 :     explicit find_by_token(sal_Int32 token):
      49       13338 :         m_token(token)
      50             :     {
      51       13338 :     }
      52             : 
      53       35847 :     bool operator()(const std::pair<sal_Int32, sal_Int32>& r)
      54             :     {
      55       35847 :         return r.first == m_token;
      56             :     }
      57             : 
      58             : private:
      59             :     sal_Int32 m_token;
      60             : };
      61             : 
      62       13338 : bool ClrScheme::getColor( sal_Int32 nSchemeClrToken, sal_Int32& rColor ) const
      63             : {
      64             :     OSL_ASSERT((nSchemeClrToken & sal_Int32(0xFFFF0000))==0);
      65       13338 :     switch( nSchemeClrToken )
      66             :     {
      67         455 :         case XML_bg1 : nSchemeClrToken = XML_lt1; break;
      68           3 :         case XML_bg2 : nSchemeClrToken = XML_lt2; break;
      69        3850 :         case XML_tx1 : nSchemeClrToken = XML_dk1; break;
      70         149 :         case XML_tx2 : nSchemeClrToken = XML_dk2; break;
      71             :     }
      72             : 
      73       13338 :     auto aIter = std::find_if(maClrScheme.begin(), maClrScheme.end(), find_by_token(nSchemeClrToken) );
      74             : 
      75       13338 :     if ( aIter != maClrScheme.end() )
      76       12188 :         rColor = aIter->second;
      77             : 
      78       13338 :     return aIter != maClrScheme.end();
      79             : }
      80             : 
      81       16932 : void ClrScheme::setColor( sal_Int32 nSchemeClrToken, sal_Int32 nColor )
      82             : {
      83       16932 :     maClrScheme.push_back(std::pair<sal_Int32, sal_Int32>(nSchemeClrToken, nColor));
      84       16932 : }
      85             : 
      86           5 : bool ClrScheme::getColorByIndex(size_t nIndex, sal_Int32& rColor) const
      87             : {
      88           5 :     if (nIndex >= maClrScheme.size())
      89           0 :         return false;
      90             : 
      91           5 :     rColor = maClrScheme[nIndex].second;
      92           5 :     return true;
      93             : }
      94             : 
      95             : } }
      96             : 
      97             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11