LCOV - code coverage report
Current view: top level - oox/source/drawingml - texteffectscontext.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 153 173 88.4 %
Date: 2015-06-13 12:38:46 Functions: 10 10 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             :  */
      10             : 
      11             : #include "drawingml/texteffectscontext.hxx"
      12             : 
      13             : #include <map>
      14             : 
      15             : namespace oox { namespace drawingml {
      16             : 
      17             : namespace
      18             : {
      19             : 
      20         126 : OUString lclGetNameForElementId(sal_uInt32 aId)
      21             : {
      22         126 :     static std::map<sal_uInt32, OUString> aIdMap;
      23         126 :     if(aIdMap.empty())
      24             :     {
      25           1 :         aIdMap[OOX_TOKEN(w14, srgbClr)]      = "srgbClr";
      26           1 :         aIdMap[OOX_TOKEN(w14, schemeClr)]    = "schemeClr";
      27           1 :         aIdMap[OOX_TOKEN(w14, tint)]         = "tint";
      28           1 :         aIdMap[OOX_TOKEN(w14, shade)]        = "shade";
      29           1 :         aIdMap[OOX_TOKEN(w14, alpha)]        = "alpha";
      30           1 :         aIdMap[OOX_TOKEN(w14, hueMod)]       = "hueMod";
      31           1 :         aIdMap[OOX_TOKEN(w14, sat)]          = "sat";
      32           1 :         aIdMap[OOX_TOKEN(w14, satOff)]       = "satOff";
      33           1 :         aIdMap[OOX_TOKEN(w14, satMod)]       = "satMod";
      34           1 :         aIdMap[OOX_TOKEN(w14, lum)]          = "lum";
      35           1 :         aIdMap[OOX_TOKEN(w14, lumOff)]       = "lumOff";
      36           1 :         aIdMap[OOX_TOKEN(w14, lumMod)]       = "lumMod";
      37           1 :         aIdMap[OOX_TOKEN(w14, noFill)]       = "noFill";
      38           1 :         aIdMap[OOX_TOKEN(w14, solidFill)]    = "solidFill";
      39           1 :         aIdMap[OOX_TOKEN(w14, gradFill)]     = "gradFill";
      40           1 :         aIdMap[OOX_TOKEN(w14, gsLst)]        = "gsLst";
      41           1 :         aIdMap[OOX_TOKEN(w14, gs)]           = "gs";
      42           1 :         aIdMap[OOX_TOKEN(w14, pos)]          = "pos";
      43           1 :         aIdMap[OOX_TOKEN(w14, lin)]          = "lin";
      44           1 :         aIdMap[OOX_TOKEN(w14, path)]         = "path";
      45           1 :         aIdMap[OOX_TOKEN(w14, fillToRect)]   = "fillToRect";
      46           1 :         aIdMap[OOX_TOKEN(w14, prstDash)]     = "prstDash";
      47           1 :         aIdMap[OOX_TOKEN(w14, round)]        = "round";
      48           1 :         aIdMap[OOX_TOKEN(w14, bevel)]        = "bevel";
      49           1 :         aIdMap[OOX_TOKEN(w14, miter)]        = "miter";
      50           1 :         aIdMap[OOX_TOKEN(w14, camera)]       = "camera";
      51           1 :         aIdMap[OOX_TOKEN(w14, lightRig)]     = "lightRig";
      52           1 :         aIdMap[OOX_TOKEN(w14, rot)]          = "rot";
      53           1 :         aIdMap[OOX_TOKEN(w14, bevelT)]       = "bevelT";
      54           1 :         aIdMap[OOX_TOKEN(w14, bevelB)]       = "bevelB";
      55           1 :         aIdMap[OOX_TOKEN(w14, extrusionClr)] = "extrusionClr";
      56           1 :         aIdMap[OOX_TOKEN(w14, contourClr)]   = "contourClr";
      57           1 :         aIdMap[OOX_TOKEN(w14, styleSet)]     = "styleSet";
      58             : 
      59           1 :         aIdMap[OOX_TOKEN(w14, glow)]         = "glow";
      60           1 :         aIdMap[OOX_TOKEN(w14, shadow)]       = "shadow";
      61           1 :         aIdMap[OOX_TOKEN(w14, reflection)]   = "reflection";
      62           1 :         aIdMap[OOX_TOKEN(w14, textOutline)]  = "textOutline";
      63           1 :         aIdMap[OOX_TOKEN(w14, textFill)]     = "textFill";
      64           1 :         aIdMap[OOX_TOKEN(w14, scene3d)]      = "scene3d";
      65           1 :         aIdMap[OOX_TOKEN(w14, props3d)]      = "props3d";
      66           1 :         aIdMap[OOX_TOKEN(w14, ligatures)]    = "ligatures";
      67           1 :         aIdMap[OOX_TOKEN(w14, numForm)]      = "numForm";
      68           1 :         aIdMap[OOX_TOKEN(w14, numSpacing)]   = "numSpacing";
      69           1 :         aIdMap[OOX_TOKEN(w14, stylisticSets)]= "stylisticSets";
      70           1 :         aIdMap[OOX_TOKEN(w14, cntxtAlts)]    = "cntxtAlts";
      71             :     }
      72             : 
      73         126 :     return aIdMap[aId];
      74             : }
      75             : 
      76          30 : OUString lclGetGrabBagName(sal_uInt32 aId)
      77             : {
      78          30 :     static std::map<sal_uInt32, OUString> aGrabBagNameMap;
      79          30 :     if(aGrabBagNameMap.empty())
      80             :     {
      81           1 :         aGrabBagNameMap[OOX_TOKEN(w14, glow)]         = "CharGlowTextEffect";
      82           1 :         aGrabBagNameMap[OOX_TOKEN(w14, shadow)]       = "CharShadowTextEffect";
      83           1 :         aGrabBagNameMap[OOX_TOKEN(w14, reflection)]   = "CharReflectionTextEffect";
      84           1 :         aGrabBagNameMap[OOX_TOKEN(w14, textOutline)]  = "CharTextOutlineTextEffect";
      85           1 :         aGrabBagNameMap[OOX_TOKEN(w14, textFill)]     = "CharTextFillTextEffect";
      86           1 :         aGrabBagNameMap[OOX_TOKEN(w14, scene3d)]      = "CharScene3DTextEffect";
      87           1 :         aGrabBagNameMap[OOX_TOKEN(w14, props3d)]      = "CharProps3DTextEffect";
      88           1 :         aGrabBagNameMap[OOX_TOKEN(w14, ligatures)]    = "CharLigaturesTextEffect";
      89           1 :         aGrabBagNameMap[OOX_TOKEN(w14, numForm)]      = "CharNumFormTextEffect";
      90           1 :         aGrabBagNameMap[OOX_TOKEN(w14, numSpacing)]   = "CharNumSpacingTextEffect";
      91           1 :         aGrabBagNameMap[OOX_TOKEN(w14, stylisticSets)]= "CharStylisticSetsTextEffect";
      92           1 :         aGrabBagNameMap[OOX_TOKEN(w14, cntxtAlts)]    = "CharCntxtAltsTextEffect";
      93             :     }
      94             : 
      95          30 :     return aGrabBagNameMap[aId];
      96             : }
      97             : 
      98             : const char constAttributesSequenceName[] = "attributes";
      99             : 
     100             : }
     101             : 
     102             : using namespace oox::core;
     103             : using namespace com::sun::star::uno;
     104             : using namespace com::sun::star::beans;
     105             : 
     106          30 : TextEffectsContext::TextEffectsContext(
     107             :                         ContextHandler2Helper& rParent,
     108             :                         sal_Int32 aElementToken,
     109             :                         std::vector<PropertyValue>& rTextEffectsProperties)
     110             :     : ContextHandler2(rParent)
     111             :     , mrTextEffectsProperties(rTextEffectsProperties)
     112             :     , mpGrabBagStack(NULL)
     113          30 :     , mnCurrentElement(aElementToken)
     114             : {
     115          30 : }
     116             : 
     117          60 : TextEffectsContext::~TextEffectsContext()
     118             : {
     119          60 : }
     120             : 
     121         186 : void TextEffectsContext::pushAttributeToGrabBag (const sal_Int32& aAttributeId, const OUString& rElementName, const AttributeList& rAttribs)
     122             : {
     123         186 :     if (!rAttribs.hasAttribute(aAttributeId))
     124         189 :         return;
     125         183 :     OUString aString = rAttribs.getString(aAttributeId).get();
     126         183 :     mpGrabBagStack->addString(rElementName, aString);
     127             : }
     128             : 
     129         126 : void TextEffectsContext::processAttributes(const AttributeList& rAttribs)
     130             : {
     131         126 :     mpGrabBagStack->push(constAttributesSequenceName);
     132         126 :     switch(mnCurrentElement)
     133             :     {
     134             :         case OOX_TOKEN(w14, glow):
     135             :         {
     136           3 :             pushAttributeToGrabBag(OOX_TOKEN(w14, rad),  "rad",  rAttribs);
     137             :         }
     138           3 :         break;
     139             :         case OOX_TOKEN(w14, srgbClr):
     140             :         case OOX_TOKEN(w14, schemeClr):
     141             :         case OOX_TOKEN(w14, tint):
     142             :         case OOX_TOKEN(w14, shade):
     143             :         case OOX_TOKEN(w14, alpha):
     144             :         case OOX_TOKEN(w14, hueMod):
     145             :         case OOX_TOKEN(w14, sat):
     146             :         case OOX_TOKEN(w14, satOff):
     147             :         case OOX_TOKEN(w14, satMod):
     148             :         case OOX_TOKEN(w14, lum):
     149             :         case OOX_TOKEN(w14, lumOff):
     150             :         case OOX_TOKEN(w14, lumMod):
     151             :         {
     152          57 :             pushAttributeToGrabBag(OOX_TOKEN(w14, val),  "val",  rAttribs);
     153             :         }
     154          57 :         break;
     155             :         case OOX_TOKEN(w14, shadow):
     156             :         {
     157           3 :             pushAttributeToGrabBag(OOX_TOKEN(w14, blurRad),  "blurRad",  rAttribs);
     158           3 :             pushAttributeToGrabBag(OOX_TOKEN(w14, dist),     "dist",  rAttribs);
     159           3 :             pushAttributeToGrabBag(OOX_TOKEN(w14, dir),      "dir",  rAttribs);
     160           3 :             pushAttributeToGrabBag(OOX_TOKEN(w14, sx),       "sx",  rAttribs);
     161           3 :             pushAttributeToGrabBag(OOX_TOKEN(w14, sy),       "sy",  rAttribs);
     162           3 :             pushAttributeToGrabBag(OOX_TOKEN(w14, kx),       "kx",  rAttribs);
     163           3 :             pushAttributeToGrabBag(OOX_TOKEN(w14, ky),       "ky",  rAttribs);
     164           3 :             pushAttributeToGrabBag(OOX_TOKEN(w14, algn),     "algn",  rAttribs);
     165             :         }
     166           3 :         break;
     167             :         case OOX_TOKEN(w14, reflection):
     168             :         {
     169           3 :             pushAttributeToGrabBag(OOX_TOKEN(w14, blurRad),  "blurRad",  rAttribs);
     170           3 :             pushAttributeToGrabBag(OOX_TOKEN(w14, stA),      "stA",  rAttribs);
     171           3 :             pushAttributeToGrabBag(OOX_TOKEN(w14, stPos),    "stPos",  rAttribs);
     172           3 :             pushAttributeToGrabBag(OOX_TOKEN(w14, endA),     "endA",  rAttribs);
     173           3 :             pushAttributeToGrabBag(OOX_TOKEN(w14, endPos),   "endPos",  rAttribs);
     174           3 :             pushAttributeToGrabBag(OOX_TOKEN(w14, dist),     "dist",  rAttribs);
     175           3 :             pushAttributeToGrabBag(OOX_TOKEN(w14, dir),      "dir",  rAttribs);
     176           3 :             pushAttributeToGrabBag(OOX_TOKEN(w14, fadeDir),  "fadeDir",  rAttribs);
     177           3 :             pushAttributeToGrabBag(OOX_TOKEN(w14, sx),       "sx",  rAttribs);
     178           3 :             pushAttributeToGrabBag(OOX_TOKEN(w14, sy),       "sy",  rAttribs);
     179           3 :             pushAttributeToGrabBag(OOX_TOKEN(w14, kx),       "kx",  rAttribs);
     180           3 :             pushAttributeToGrabBag(OOX_TOKEN(w14, ky),       "ky",  rAttribs);
     181           3 :             pushAttributeToGrabBag(OOX_TOKEN(w14, algn),     "algn",  rAttribs);
     182             :         }
     183           3 :         break;
     184             :         case OOX_TOKEN(w14, textOutline):
     185             :         {
     186           3 :             pushAttributeToGrabBag(OOX_TOKEN(w14, w),     "w",   rAttribs);
     187           3 :             pushAttributeToGrabBag(OOX_TOKEN(w14, cap),  "cap",  rAttribs);
     188           3 :             pushAttributeToGrabBag(OOX_TOKEN(w14, cmpd), "cmpd", rAttribs);
     189           3 :             pushAttributeToGrabBag(OOX_TOKEN(w14, algn), "algn", rAttribs);
     190             :         }
     191           3 :         break;
     192             :         case OOX_TOKEN(w14, prstDash):
     193             :         {
     194           3 :             pushAttributeToGrabBag(OOX_TOKEN(w14, val),  "val",  rAttribs);
     195             :         }
     196           3 :         break;
     197             :         case OOX_TOKEN(w14, gs):
     198             :         {
     199           9 :             pushAttributeToGrabBag(OOX_TOKEN(w14, pos),  "pos", rAttribs);
     200             :         }
     201           9 :         break;
     202             :         case OOX_TOKEN(w14, lin):
     203             :         {
     204           3 :             pushAttributeToGrabBag(OOX_TOKEN(w14, ang),    "ang", rAttribs);
     205           3 :             pushAttributeToGrabBag(OOX_TOKEN(w14, scaled), "scaled", rAttribs);
     206             :         }
     207           3 :         break;
     208             :         case OOX_TOKEN(w14, path):
     209             :         {
     210           0 :             pushAttributeToGrabBag(OOX_TOKEN(w14, path), "path", rAttribs);
     211             :         }
     212           0 :         break;
     213             :         case OOX_TOKEN(w14, fillToRect):
     214             :         {
     215           0 :             pushAttributeToGrabBag(OOX_TOKEN(w14, l), "l", rAttribs);
     216           0 :             pushAttributeToGrabBag(OOX_TOKEN(w14, t), "t", rAttribs);
     217           0 :             pushAttributeToGrabBag(OOX_TOKEN(w14, r), "r", rAttribs);
     218           0 :             pushAttributeToGrabBag(OOX_TOKEN(w14, b), "b", rAttribs);
     219             :         }
     220           0 :         break;
     221             :         case OOX_TOKEN(w14, miter):
     222             :         {
     223           0 :             pushAttributeToGrabBag(OOX_TOKEN(w14, lim), "lim", rAttribs);
     224             :         }
     225           0 :         break;
     226             :         case OOX_TOKEN(w14, camera):
     227             :         {
     228           0 :             pushAttributeToGrabBag(OOX_TOKEN(w14, prst), "prst", rAttribs);
     229             :         }
     230           0 :         break;
     231             :         case OOX_TOKEN(w14, lightRig):
     232             :         {
     233           0 :             pushAttributeToGrabBag(OOX_TOKEN(w14, rig), "rig", rAttribs);
     234           0 :             pushAttributeToGrabBag(OOX_TOKEN(w14, dir), "dir", rAttribs);
     235             :         }
     236           0 :         break;
     237             :         case OOX_TOKEN(w14, rot):
     238             :         {
     239           0 :             pushAttributeToGrabBag(OOX_TOKEN(w14, lat), "lat", rAttribs);
     240           0 :             pushAttributeToGrabBag(OOX_TOKEN(w14, lon), "lon", rAttribs);
     241           0 :             pushAttributeToGrabBag(OOX_TOKEN(w14, rev), "rev", rAttribs);
     242             :         }
     243           0 :         break;
     244             :         case OOX_TOKEN(w14, props3d):
     245             :         {
     246           3 :             pushAttributeToGrabBag(OOX_TOKEN(w14, extrusionH),   "extrusionH", rAttribs);
     247           3 :             pushAttributeToGrabBag(OOX_TOKEN(w14, contourW),     "contourW", rAttribs);
     248           3 :             pushAttributeToGrabBag(OOX_TOKEN(w14, prstMaterial), "prstMaterial", rAttribs);
     249             :         }
     250           3 :         break;
     251             :         case OOX_TOKEN(w14, bevelT):
     252             :         case OOX_TOKEN(w14, bevelB):
     253             :         {
     254           3 :             pushAttributeToGrabBag(OOX_TOKEN(w14, w),    "w", rAttribs);
     255           3 :             pushAttributeToGrabBag(OOX_TOKEN(w14, h),    "h", rAttribs);
     256           3 :             pushAttributeToGrabBag(OOX_TOKEN(w14, prst), "prst", rAttribs);
     257             :         }
     258           3 :         break;
     259             :         case OOX_TOKEN(w14, ligatures):
     260             :         case OOX_TOKEN(w14, numForm):
     261             :         case OOX_TOKEN(w14, numSpacing):
     262             :         {
     263           9 :             pushAttributeToGrabBag(OOX_TOKEN(w14, val), "val", rAttribs);
     264             :         }
     265           9 :         break;
     266             :         case OOX_TOKEN(w14, styleSet):
     267             :         {
     268           3 :             pushAttributeToGrabBag(OOX_TOKEN(w14, id), "id", rAttribs);
     269           3 :             pushAttributeToGrabBag(OOX_TOKEN(w14, val), "val", rAttribs);
     270             :         }
     271           3 :         break;
     272             :         case OOX_TOKEN(w14, cntxtAlts):
     273             :         {
     274           0 :             pushAttributeToGrabBag(OOX_TOKEN(w14, val), "val", rAttribs);
     275             :         }
     276           0 :         break;
     277             :         default:
     278          24 :             break;
     279             :     }
     280             : 
     281         126 :     mpGrabBagStack->pop();
     282         126 : }
     283             : 
     284         126 : void TextEffectsContext::onStartElement(const oox::AttributeList& rAttribs)
     285             : {
     286         126 :     if(mpGrabBagStack.get() == NULL)
     287             :     {
     288          30 :         OUString aGrabBagName = lclGetGrabBagName(mnCurrentElement);
     289          30 :         mpGrabBagStack.reset(new GrabBagStack(aGrabBagName));
     290             :     }
     291             : 
     292         126 :     OUString aElementName = lclGetNameForElementId(mnCurrentElement);
     293         126 :     mpGrabBagStack->push(aElementName);
     294         126 :     processAttributes(rAttribs);
     295         126 : }
     296             : 
     297         126 : void TextEffectsContext::onEndElement()
     298             : {
     299         126 :     mpGrabBagStack->pop();
     300             : 
     301         126 :     if (mpGrabBagStack->isStackEmpty())
     302             :     {
     303          30 :         Sequence<PropertyValue> aSeq;
     304          60 :         PropertyValue aPropertyValue = mpGrabBagStack->getRootProperty();
     305          30 :         aPropertyValue.Value >>= aSeq;
     306          30 :         aPropertyValue.Value = makeAny(aSeq[0]);
     307             : 
     308          60 :         mrTextEffectsProperties.push_back(aPropertyValue);
     309             :     }
     310             : 
     311         126 : }
     312             : 
     313          96 : ContextHandlerRef TextEffectsContext::onCreateContext(sal_Int32 aElementToken, const AttributeList& /*rAttribs*/)
     314             : {
     315          96 :     mnCurrentElement = aElementToken;
     316          96 :     return this;
     317             : }
     318             : 
     319             : } }
     320             : 
     321             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11