LCOV - code coverage report
Current view: top level - svgio/inc/svgio/svgreader - svgnode.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 9 10 90.0 %
Date: 2014-11-03 Functions: 9 10 90.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             : #ifndef INCLUDED_SVGIO_INC_SVGIO_SVGREADER_SVGNODE_HXX
      21             : #define INCLUDED_SVGIO_INC_SVGIO_SVGREADER_SVGNODE_HXX
      22             : 
      23             : #include <svgio/svgreader/svgtools.hxx>
      24             : #include <svgio/svgreader/svgtoken.hxx>
      25             : #include <svgio/svgreader/svgpaint.hxx>
      26             : #include <basegfx/matrix/b2dhommatrix.hxx>
      27             : #include <com/sun/star/xml/sax/XAttributeList.hpp>
      28             : #include <vector>
      29             : #include <boost/unordered_map.hpp>
      30             : 
      31             : 
      32             : // predefines
      33             : namespace svgio
      34             : {
      35             :     namespace svgreader
      36             :     {
      37             :         class SvgNode;
      38             :         class SvgDocument;
      39             :         class SvgStyleAttributes;
      40             :     }
      41             : }
      42             : 
      43             : 
      44             : 
      45             : namespace svgio
      46             : {
      47             :     namespace svgreader
      48             :     {
      49             :         typedef ::std::vector< SvgNode* > SvgNodeVector;
      50             :         typedef ::std::vector< const SvgStyleAttributes* > SvgStyleAttributeVector;
      51             : 
      52             :         enum XmlSpace
      53             :         {
      54             :             XmlSpace_notset,
      55             :             XmlSpace_default,
      56             :             XmlSpace_preserve
      57             :         };
      58             : 
      59             :         // display property (see SVG 1.1. 11.5), not inheritable
      60             :         enum Display // #i121656#
      61             :         {
      62             :             Display_inline, // the default
      63             :             Display_block,
      64             :             Display_list_item,
      65             :             Display_run_in,
      66             :             Display_compact,
      67             :             Display_marker,
      68             :             Display_table,
      69             :             Display_inline_table,
      70             :             Display_table_row_group,
      71             :             Display_table_header_group,
      72             :             Display_table_footer_group,
      73             :             Display_table_row,
      74             :             Display_table_column_group,
      75             :             Display_table_column,
      76             :             Display_table_cell,
      77             :             Display_table_caption,
      78             :             Display_none,
      79             :             Display_inherit
      80             :         };
      81             : 
      82             :         // helper to convert a string associated with a token of type SVGTokenDisplay
      83             :         // to the enum Display. Empty trings return the default 'Display_inline' with
      84             :         // which members should be initialized
      85             :         Display getDisplayFromContent(const OUString& aContent);
      86             : 
      87             :         class SvgNode : private boost::noncopyable, public InfoProvider
      88             :         {
      89             :         private:
      90             :             /// basic data, Type, document we belong to and parent (if not root)
      91             :             SVGToken                    maType;
      92             :             SvgDocument&                mrDocument;
      93             :             const SvgNode*              mpParent;
      94             :             const SvgNode*              mpAlternativeParent;
      95             : 
      96             :             /// sub hierarchy
      97             :             SvgNodeVector               maChildren;
      98             : 
      99             :             /// Id svan value
     100             :             OUString*              mpId;
     101             : 
     102             :             /// Class svan value
     103             :             OUString*              mpClass;
     104             : 
     105             :             /// XmlSpace value
     106             :             XmlSpace                    maXmlSpace;
     107             : 
     108             :             /// Display value #i121656#
     109             :             Display                     maDisplay;
     110             : 
     111             :             // CSS style vector chain, used in decompose phase and built up once per node.
     112             :             // It contains the StyleHierarchy for the local node. INdependent from the
     113             :             // node hierarchy itself which also needs to be used in style entry solving
     114             :             SvgStyleAttributeVector     maCssStyleVector;
     115             : 
     116             :             /// possibbe local CssStyle, e.g. style="fill:red; stroke:red;"
     117             :             SvgStyleAttributes*         mpLocalCssStyle;
     118             : 
     119             :             /// bitfield
     120             :             // flag if maCssStyleVector is already computed (done only once)
     121             :             bool                        mbCssStyleVectorBuilt : 1;
     122             : 
     123             :         protected:
     124             :             /// helper to evtl. link to css style
     125             :             const SvgStyleAttributes* checkForCssStyle(const OUString& rClassStr, const SvgStyleAttributes& rOriginal) const;
     126             : 
     127             :             /// helper for filling the CssStyle vector once dependent on mbCssStyleVectorBuilt
     128             :             void fillCssStyleVector(const OUString& rClassStr);
     129             :             void fillCssStyleVectorUsingHierarchyAndSelectors(
     130             :                 const OUString& rClassStr,
     131             :                 const SvgNode& rCurrent,
     132             :                 const OUString& aConcatenated);
     133             : 
     134             :         public:
     135             :             SvgNode(
     136             :                 SVGToken aType,
     137             :                 SvgDocument& rDocument,
     138             :                 SvgNode* pParent);
     139             :             virtual ~SvgNode();
     140             : 
     141             :             /// scan helper to read and interpret a local CssStyle to mpLocalCssStyle
     142             :             void readLocalCssStyle(const OUString& aContent);
     143             : 
     144             :             /// style helpers
     145             :             void parseAttributes(const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttribs);
     146             :             virtual const SvgStyleAttributes* getSvgStyleAttributes() const;
     147             :             virtual void parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent);
     148             :             virtual void decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence& rTarget, bool bReferenced) const;
     149             : 
     150             :             /// #i125258# tell if this node is allowed to have a parent style (e.g. defs do not)
     151             :             virtual bool supportsParentStyle() const;
     152             : 
     153             :             /// basic data read access
     154      177658 :             SVGToken getType() const { return maType; }
     155       21915 :             const SvgDocument& getDocument() const { return mrDocument; }
     156      258689 :             const SvgNode* getParent() const { if(mpAlternativeParent) return mpAlternativeParent; return mpParent; }
     157       12863 :             const SvgNodeVector& getChildren() const { return maChildren; }
     158             : 
     159             :             /// InfoProvider support for %, em and ex values
     160             :             virtual const basegfx::B2DRange getCurrentViewPort() const SAL_OVERRIDE;
     161             :             virtual double getCurrentFontSizeInherited() const SAL_OVERRIDE;
     162             :             virtual double getCurrentXHeightInherited() const SAL_OVERRIDE;
     163             : 
     164             :             double getCurrentFontSize() const;
     165             :             double getCurrentXHeight() const;
     166             : 
     167             :             /// Id access
     168          32 :             const OUString* getId() const { return mpId; }
     169             :             void setId(const OUString* pfId = 0);
     170             : 
     171             :             /// Class access
     172          32 :             const OUString* getClass() const { return mpClass; }
     173             :             void setClass(const OUString* pfClass = 0);
     174             : 
     175             :             /// XmlSpace access
     176             :             XmlSpace getXmlSpace() const;
     177         292 :             void setXmlSpace(XmlSpace eXmlSpace = XmlSpace_notset) { maXmlSpace = eXmlSpace; }
     178             : 
     179             :             /// Display access #i121656#
     180       20241 :             Display getDisplay() const { return maDisplay; }
     181           0 :             void setDisplay(Display eDisplay = Display_inherit) { maDisplay = eDisplay; }
     182             : 
     183             :             /// alternative parent
     184         386 :             void setAlternativeParent(const SvgNode* pAlternativeParent = 0) { mpAlternativeParent = pAlternativeParent; }
     185             :         };
     186             :     } // end of namespace svgreader
     187             : } // end of namespace svgio
     188             : 
     189             : #endif // INCLUDED_SVGIO_INC_SVGIO_SVGREADER_SVGNODE_HXX
     190             : 
     191             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10