LCOV - code coverage report
Current view: top level - libreoffice/xmloff/source/draw - EnhancedCustomShapeToken.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 32 32 100.0 %
Date: 2012-12-27 Functions: 5 5 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 "EnhancedCustomShapeToken.hxx"
      21             : #include <osl/mutex.hxx>
      22             : #include <boost/unordered_map.hpp>
      23             : #include <string.h>
      24             : 
      25             : namespace xmloff { namespace EnhancedCustomShapeToken {
      26             : 
      27             : struct THash
      28             : {
      29        3138 :     size_t operator()( const char* s ) const
      30             :     {
      31        3138 :         return rtl_str_hashCode(s);
      32             :     }
      33             : };
      34             : struct TCheck
      35             : {
      36        2898 :     bool operator()( const char* s1, const char* s2 ) const
      37             :     {
      38        2898 :         return strcmp( s1, s2 ) == 0;
      39             :     }
      40             : };
      41             : typedef boost::unordered_map< const char*, EnhancedCustomShapeTokenEnum, THash, TCheck> TypeNameHashMap;
      42             : static TypeNameHashMap* pHashMap = NULL;
      43           2 : static ::osl::Mutex& getHashMapMutex()
      44             : {
      45           2 :     static osl::Mutex s_aHashMapProtection;
      46           2 :     return s_aHashMapProtection;
      47             : }
      48             : 
      49             : struct TokenTable
      50             : {
      51             :     const char*                         pS;
      52             :     EnhancedCustomShapeTokenEnum        pE;
      53             : };
      54             : 
      55             : static const TokenTable pTokenTableArray[] =
      56             : {
      57             :     { "type",                               EAS_type },
      58             :     { "name",                               EAS_name },
      59             :     { "mirror-horizontal",                  EAS_mirror_horizontal },
      60             :     { "mirror-vertical",                    EAS_mirror_vertical },
      61             :     { "viewBox",                            EAS_viewBox },
      62             :     { "text-rotate-angle",                  EAS_text_rotate_angle },
      63             :     { "extrusion-allowed",                  EAS_extrusion_allowed },
      64             :     { "extrusion-text-path-allowed",        EAS_text_path_allowed },
      65             :     { "extrusion-concentric-gradient-fill", EAS_concentric_gradient_fill_allowed },
      66             :     { "extrusion",                          EAS_extrusion },
      67             :     { "extrusion-brightness",               EAS_extrusion_brightness },
      68             :     { "extrusion-depth",                    EAS_extrusion_depth },
      69             :     { "extrusion-diffusion",                EAS_extrusion_diffusion },
      70             :     { "extrusion-number-of-line-segments",  EAS_extrusion_number_of_line_segments },
      71             :     { "extrusion-light-face",               EAS_extrusion_light_face },
      72             :     { "extrusion-first-light-harsh",        EAS_extrusion_first_light_harsh },
      73             :     { "extrusion-second-light-harsh",       EAS_extrusion_second_light_harsh },
      74             :     { "extrusion-first-light-livel",        EAS_extrusion_first_light_level },
      75             :     { "extrusion-second-light-level",       EAS_extrusion_second_light_level },
      76             :     { "extrusion-first-light-direction",    EAS_extrusion_first_light_direction },
      77             :     { "extrusion-second-light-direction",   EAS_extrusion_second_light_direction },
      78             :     { "extrusion-metal",                    EAS_extrusion_metal },
      79             :     { "shade-mode",                         EAS_shade_mode },
      80             :     { "extrusion-rotation-angle",           EAS_extrusion_rotation_angle },
      81             :     { "extrusion-rotation-center",          EAS_extrusion_rotation_center },
      82             :     { "extrusion-shininess",                EAS_extrusion_shininess },
      83             :     { "extrusion-skew",                     EAS_extrusion_skew },
      84             :     { "extrusion-specularity",              EAS_extrusion_specularity },
      85             :     { "projection",                         EAS_projection },
      86             :     { "extrusion-viewpoint",                EAS_extrusion_viewpoint },
      87             :     { "extrusion-origin",                   EAS_extrusion_origin },
      88             :     { "extrusion-color",                    EAS_extrusion_color },
      89             :     { "enhanced-path",                      EAS_enhanced_path },
      90             :     { "path-stretchpoint-x",                EAS_path_stretchpoint_x },
      91             :     { "path-stretchpoint-y",                EAS_path_stretchpoint_y },
      92             :     { "text-areas",                         EAS_text_areas },
      93             :     { "glue-points",                        EAS_glue_points },
      94             :     { "glue-point-type",                    EAS_glue_point_type },
      95             :     { "glue-point-leaving-directions",      EAS_glue_point_leaving_directions },
      96             :     { "text-path",                          EAS_text_path },
      97             :     { "text-path-mode",                     EAS_text_path_mode },
      98             :     { "text-path-scale",                    EAS_text_path_scale },
      99             :     { "text-path-same-letter-heights",      EAS_text_path_same_letter_heights },
     100             :     { "modifiers",                          EAS_modifiers },
     101             :     { "equation",                           EAS_equation },
     102             :     { "formula",                            EAS_formula },
     103             :     { "handle",                             EAS_handle },
     104             :     { "handle-mirror-horizontal",           EAS_handle_mirror_horizontal },
     105             :     { "handle-mirror-vertical",             EAS_handle_mirror_vertical },
     106             :     { "handle-switched",                    EAS_handle_switched },
     107             :     { "handle-position",                    EAS_handle_position },
     108             :     { "handle-range-x-minimum",             EAS_handle_range_x_minimum },
     109             :     { "handle-range-x-maximum",             EAS_handle_range_x_maximum },
     110             :     { "handle-range-y-minimum",             EAS_handle_range_y_minimum },
     111             :     { "handle-range-y-maximum",             EAS_handle_range_y_maximum },
     112             :     { "handle-polar",                       EAS_handle_polar },
     113             :     { "handle-radius-range-minimum",        EAS_handle_radius_range_minimum },
     114             :     { "handle-radius-range-maximum",        EAS_handle_radius_range_maximum },
     115             : 
     116             :     { "CustomShapeEngine",                  EAS_CustomShapeEngine },
     117             :     { "CustomShapeData",                    EAS_CustomShapeData },
     118             :     { "Type",                               EAS_Type },
     119             :     { "MirroredX",                          EAS_MirroredX },
     120             :     { "MirroredY",                          EAS_MirroredY },
     121             :     { "ViewBox",                            EAS_ViewBox },
     122             :     { "TextRotateAngle",                    EAS_TextRotateAngle },
     123             :     { "ExtrusionAllowed",                   EAS_ExtrusionAllowed },
     124             :     { "TextPathAllowed",                    EAS_TextPathAllowed },
     125             :     { "ConcentricGradientFillAllowed",      EAS_ConcentricGradientFillAllowed },
     126             :     { "Extrusion",                          EAS_Extrusion },
     127             :     { "Equations",                          EAS_Equations },
     128             :     { "Equation",                           EAS_Equation },
     129             :     { "Path",                               EAS_Path },
     130             :     { "TextPath",                           EAS_TextPath },
     131             :     { "Handles",                            EAS_Handles },
     132             :     { "Handle",                             EAS_Handle },
     133             :     { "Brightness",                         EAS_Brightness },
     134             :     { "Depth",                              EAS_Depth },
     135             :     { "Diffusion",                          EAS_Diffusion },
     136             :     { "NumberOfLineSegments",               EAS_NumberOfLineSegments },
     137             :     { "LightFace",                          EAS_LightFace },
     138             :     { "FirstLightHarsh",                    EAS_FirstLightHarsh },
     139             :     { "SecondLightHarsh",                   EAS_SecondLightHarsh },
     140             :     { "FirstLightLevel",                    EAS_FirstLightLevel },
     141             :     { "SecondLightLevel",                   EAS_SecondLightLevel },
     142             :     { "FirstLightDirection",                EAS_FirstLightDirection },
     143             :     { "SecondLightDirection",               EAS_SecondLightDirection },
     144             :     { "Metal",                              EAS_Metal },
     145             :     { "ShadeMode",                          EAS_ShadeMode },
     146             :     { "RotateAngle",                        EAS_RotateAngle },
     147             :     { "RotationCenter",                     EAS_RotationCenter },
     148             :     { "Shininess",                          EAS_Shininess },
     149             :     { "Skew",                               EAS_Skew },
     150             :     { "Specularity",                        EAS_Specularity },
     151             :     { "ProjectionMode",                     EAS_ProjectionMode },
     152             :     { "ViewPoint",                          EAS_ViewPoint },
     153             :     { "Origin",                             EAS_Origin },
     154             :     { "Color",                              EAS_Color },
     155             :     { "Switched",                           EAS_Switched },
     156             :      { "Polar",                             EAS_Polar },
     157             :     { "RangeXMinimum",                      EAS_RangeXMinimum },
     158             :     { "RangeXMaximum",                      EAS_RangeXMaximum },
     159             :     { "RangeYMinimum",                      EAS_RangeYMinimum },
     160             :     { "RangeYMaximum",                      EAS_RangeYMaximum },
     161             :     { "RadiusRangeMinimum",                 EAS_RadiusRangeMinimum },
     162             :     { "RadiusRangeMaximum",                 EAS_RadiusRangeMaximum },
     163             :     { "Coordinates",                        EAS_Coordinates },
     164             :     { "Segments",                           EAS_Segments },
     165             :     { "StretchX",                           EAS_StretchX },
     166             :     { "StretchY",                           EAS_StretchY },
     167             :     { "TextFrames",                         EAS_TextFrames },
     168             :     { "GluePoints",                         EAS_GluePoints },
     169             :     { "GluePointLeavingDirections",         EAS_GluePointLeavingDirections },
     170             :     { "GluePointType",                      EAS_GluePointType },
     171             :     { "TextPathMode",                       EAS_TextPathMode },
     172             :     { "ScaleX",                             EAS_ScaleX },
     173             :     { "SameLetterHeights",                  EAS_SameLetterHeights },
     174             :     { "Position",                           EAS_Position },
     175             :     { "AdjustmentValues",                   EAS_AdjustmentValues },
     176             : 
     177             :     { "Last",                               EAS_Last },
     178             :     { "NotFound",                           EAS_NotFound }
     179             : };
     180             : 
     181        2898 : EnhancedCustomShapeTokenEnum EASGet( const rtl::OUString& rShapeType )
     182             : {
     183        2898 :     if ( !pHashMap )
     184             :     {   // init hash map
     185           2 :         ::osl::MutexGuard aGuard( getHashMapMutex() );
     186           2 :         if ( !pHashMap )
     187             :         {
     188           2 :             TypeNameHashMap* pH = new TypeNameHashMap;
     189           2 :             const TokenTable* pPtr = pTokenTableArray;
     190           2 :             const TokenTable* pEnd = pPtr + ( sizeof( pTokenTableArray ) / sizeof( TokenTable ) );
     191         242 :             for ( ; pPtr < pEnd; pPtr++ )
     192         240 :                 (*pH)[ pPtr->pS ] = pPtr->pE;
     193           2 :             pHashMap = pH;
     194           2 :         }
     195             :     }
     196        2898 :     EnhancedCustomShapeTokenEnum eRetValue = EAS_NotFound;
     197        2898 :     int i, nLen = rShapeType.getLength();
     198        2898 :     char* pBuf = new char[ nLen + 1 ];
     199       25915 :     for ( i = 0; i < nLen; i++ )
     200       23017 :         pBuf[ i ] = (char)rShapeType[ i ];
     201        2898 :     pBuf[ i ] = 0;
     202        2898 :     TypeNameHashMap::iterator aHashIter( pHashMap->find( pBuf ) );
     203        2898 :     delete[] pBuf;
     204        2898 :     if ( aHashIter != pHashMap->end() )
     205        2898 :         eRetValue = (*aHashIter).second;
     206        2898 :     return eRetValue;
     207             : }
     208             : 
     209         868 : rtl::OUString EASGet( const EnhancedCustomShapeTokenEnum eToken )
     210             : {
     211             :     sal_uInt32 i = eToken >= EAS_Last
     212             :         ? (sal_uInt32)EAS_NotFound
     213         868 :         : (sal_uInt32)eToken;
     214         868 :     return rtl::OUString::createFromAscii( pTokenTableArray[ i ].pS );
     215             : }
     216             : 
     217             : }
     218             : }
     219             : 
     220             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10