LCOV - code coverage report
Current view: top level - svgio/inc/svgio/svgreader - svgstyleattributes.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 19 43 44.2 %
Date: 2014-11-03 Functions: 19 43 44.2 %
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_SVGSTYLEATTRIBUTES_HXX
      21             : #define INCLUDED_SVGIO_INC_SVGIO_SVGREADER_SVGSTYLEATTRIBUTES_HXX
      22             : 
      23             : #include <svgio/svgreader/svgpaint.hxx>
      24             : #include <svgio/svgreader/svgnode.hxx>
      25             : #include <vcl/vclenum.hxx>
      26             : #include <basegfx/polygon/b2dpolypolygontools.hxx>
      27             : 
      28             : 
      29             : // predefines
      30             : 
      31             : namespace svgio { namespace svgreader {
      32             :     class SvgGradientNode;
      33             :     class SvgPatternNode;
      34             :     class SvgMarkerNode;
      35             : }}
      36             : 
      37             : 
      38             : 
      39             : namespace svgio
      40             : {
      41             :     namespace svgreader
      42             :     {
      43             :         enum StrokeLinecap
      44             :         {
      45             :             StrokeLinecap_notset,
      46             :             StrokeLinecap_butt,
      47             :             StrokeLinecap_round,
      48             :             StrokeLinecap_square
      49             :         };
      50             : 
      51             :         enum StrokeLinejoin
      52             :         {
      53             :             StrokeLinejoin_notset,
      54             :             StrokeLinejoin_miter,
      55             :             StrokeLinejoin_round,
      56             :             StrokeLinejoin_bevel
      57             :         };
      58             : 
      59             :         enum FontStretch
      60             :         {
      61             :             FontStretch_notset,
      62             :             FontStretch_normal,
      63             :             FontStretch_wider,
      64             :             FontStretch_narrower,
      65             :             FontStretch_ultra_condensed,
      66             :             FontStretch_extra_condensed,
      67             :             FontStretch_condensed,
      68             :             FontStretch_semi_condensed,
      69             :             FontStretch_semi_expanded,
      70             :             FontStretch_expanded,
      71             :             FontStretch_extra_expanded,
      72             :             FontStretch_ultra_expanded
      73             :         };
      74             : 
      75             :         FontStretch getWider(FontStretch aSource);
      76             :         FontStretch getNarrower(FontStretch aSource);
      77             : 
      78             :         enum FontStyle
      79             :         {
      80             :             FontStyle_notset,
      81             :             FontStyle_normal,
      82             :             FontStyle_italic,
      83             :             FontStyle_oblique
      84             :         };
      85             : 
      86             :         enum FontVariant
      87             :         {
      88             :             FontVariant_notset,
      89             :             FontVariant_normal,
      90             :             FontVariant_small_caps
      91             :         };
      92             : 
      93             :         enum FontWeight
      94             :         {
      95             :             FontWeight_notset,
      96             :             FontWeight_100,
      97             :             FontWeight_200,
      98             :             FontWeight_300,
      99             :             FontWeight_400, // same as FontWeight_normal
     100             :             FontWeight_500,
     101             :             FontWeight_600,
     102             :             FontWeight_700, // same as FontWeight_bold
     103             :             FontWeight_800,
     104             :             FontWeight_900,
     105             :             FontWeight_bolder,
     106             :             FontWeight_lighter,
     107             :         };
     108             : 
     109             :         FontWeight getBolder(FontWeight aSource);
     110             :         FontWeight getLighter(FontWeight aSource);
     111             :         ::FontWeight getVclFontWeight(FontWeight aSource);
     112             : 
     113             :         enum TextAlign
     114             :         {
     115             :             TextAlign_notset,
     116             :             TextAlign_left,
     117             :             TextAlign_right,
     118             :             TextAlign_center,
     119             :             TextAlign_justify
     120             :         };
     121             : 
     122             :         enum TextDecoration
     123             :         {
     124             :             TextDecoration_notset,
     125             :             TextDecoration_none,
     126             :             TextDecoration_underline,
     127             :             TextDecoration_overline,
     128             :             TextDecoration_line_through,
     129             :             TextDecoration_blink
     130             :         };
     131             : 
     132             :         enum TextAnchor
     133             :         {
     134             :             TextAnchor_notset,
     135             :             TextAnchor_start,
     136             :             TextAnchor_middle,
     137             :             TextAnchor_end
     138             :         };
     139             : 
     140             :         enum FillRule
     141             :         {
     142             :             FillRule_notset,
     143             :             FillRule_nonzero,
     144             :             FillRule_evenodd
     145             :         };
     146             : 
     147             :         enum BaselineShift
     148             :         {
     149             :             BaselineShift_Baseline,
     150             :             BaselineShift_Sub,
     151             :             BaselineShift_Super,
     152             :             BaselineShift_Percentage,
     153             :             BaselineShift_Length
     154             :         };
     155             : 
     156             :         enum Visibility
     157             :         {
     158             :             Visibility_visible,
     159             :             Visibility_hidden,
     160             :             Visibility_collapse,
     161             :             Visibility_inherit
     162             :         };
     163             : 
     164             :         class SvgStyleAttributes
     165             :         {
     166             :         private:
     167             :             SvgNode&                    mrOwner;
     168             :             const SvgStyleAttributes*   mpCssStyleParent;
     169             :             SvgPaint                    maFill;
     170             :             SvgPaint                    maStroke;
     171             :             SvgPaint                    maStopColor;
     172             :             SvgNumber                   maStrokeWidth;
     173             :             SvgNumber                   maStopOpacity;
     174             :             const SvgGradientNode*      mpSvgGradientNodeFill;
     175             :             const SvgGradientNode*      mpSvgGradientNodeStroke;
     176             :             const SvgPatternNode*       mpSvgPatternNodeFill;
     177             :             const SvgPatternNode*       mpSvgPatternNodeStroke;
     178             :             SvgNumber                   maFillOpacity;
     179             :             SvgNumberVector             maStrokeDasharray;
     180             :             SvgNumber                   maStrokeDashOffset;
     181             :             StrokeLinecap               maStrokeLinecap;
     182             :             StrokeLinejoin              maStrokeLinejoin;
     183             :             SvgNumber                   maStrokeMiterLimit;
     184             :             SvgNumber                   maStrokeOpacity;
     185             :             SvgStringVector             maFontFamily;
     186             :             SvgNumber                   maFontSize;
     187             :             FontStretch                 maFontStretch;
     188             :             FontStyle                   maFontStyle;
     189             :             FontVariant                 maFontVariant;
     190             :             FontWeight                  maFontWeight;
     191             :             TextAlign                   maTextAlign;
     192             :             TextDecoration              maTextDecoration;
     193             :             TextAnchor                  maTextAnchor;
     194             :             SvgPaint                    maColor;
     195             :             SvgNumber                   maOpacity;
     196             :             Visibility                  maVisibility;
     197             :             OUString               maTitle;
     198             :             OUString               maDesc;
     199             : 
     200             :             /// link to content. If set, the node can be fetched on demand
     201             :             OUString               maClipPathXLink;
     202             :             OUString               maMaskXLink;
     203             : 
     204             :             /// link to markers. If set, the node can be fetched on demand
     205             :             OUString               maMarkerStartXLink;
     206             :             const SvgMarkerNode*        mpMarkerStartXLink;
     207             :             OUString               maMarkerMidXLink;
     208             :             const SvgMarkerNode*        mpMarkerMidXLink;
     209             :             OUString               maMarkerEndXLink;
     210             :             const SvgMarkerNode*        mpMarkerEndXLink;
     211             : 
     212             :             /// fill rule
     213             :             FillRule                    maFillRule;
     214             : 
     215             :             // ClipRule setting (only valid wne mbIsClipPathContent == true, default is FillRule_nonzero)
     216             :             FillRule                    maClipRule;
     217             : 
     218             :             // BaselineShift: Type and number (in case of BaselineShift_Percentage or BaselineShift_Length)
     219             :             BaselineShift               maBaselineShift;
     220             :             SvgNumber                   maBaselineShiftNumber;
     221             : 
     222             :             /// bitfield
     223             : 
     224             :             // defines if this attributes are part of a ClipPath. If yes,
     225             :             // rough geometry will be created on decomposition by patching
     226             :             // vaules for fill, stroke, strokeWidth and others
     227             :             bool                        mbIsClipPathContent : 1;
     228             : 
     229             :             // #121221# Defines if evtl. an empty array *is* set
     230             :             bool                        mbStrokeDasharraySet : 1;
     231             : 
     232             :             /// internal helpers
     233             :             void add_fillGradient(
     234             :                 const basegfx::B2DPolyPolygon& rPath,
     235             :                 drawinglayer::primitive2d::Primitive2DSequence& rTarget,
     236             :                 const SvgGradientNode& rFillGradient,
     237             :                 const basegfx::B2DRange& rGeoRange) const;
     238             :             void add_fillPatternTransform(
     239             :                 const basegfx::B2DPolyPolygon& rPath,
     240             :                 drawinglayer::primitive2d::Primitive2DSequence& rTarget,
     241             :                 const SvgPatternNode& rFillGradient,
     242             :                 const basegfx::B2DRange& rGeoRange) const;
     243             :             void add_fillPattern(
     244             :                 const basegfx::B2DPolyPolygon& rPath,
     245             :                 drawinglayer::primitive2d::Primitive2DSequence& rTarget,
     246             :                 const SvgPatternNode& rFillGradient,
     247             :                 const basegfx::B2DRange& rGeoRange) const;
     248             :             void add_fill(
     249             :                 const basegfx::B2DPolyPolygon& rPath,
     250             :                 drawinglayer::primitive2d::Primitive2DSequence& rTarget,
     251             :                 const basegfx::B2DRange& rGeoRange) const;
     252             :             void add_stroke(
     253             :                 const basegfx::B2DPolyPolygon& rPath,
     254             :                 drawinglayer::primitive2d::Primitive2DSequence& rTarget,
     255             :                 const basegfx::B2DRange& rGeoRange) const;
     256             :             bool prepare_singleMarker(
     257             :                 drawinglayer::primitive2d::Primitive2DSequence& rMarkerPrimitives,
     258             :                 basegfx::B2DHomMatrix& rMarkerTransform,
     259             :                 basegfx::B2DRange& rClipRange,
     260             :                 const SvgMarkerNode& rMarker) const;
     261             :             void add_markers(
     262             :                 const basegfx::B2DPolyPolygon& rPath,
     263             :                 drawinglayer::primitive2d::Primitive2DSequence& rTarget,
     264             :                 const basegfx::tools::PointIndexSet* pHelpPointIndices) const;
     265             : 
     266             :         public:
     267             :             /// local attribute scanner
     268             :             void parseStyleAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& rContent,
     269             :                                      bool bCaseIndependent);
     270             : 
     271             :             /// helper which does the necessary with a given path
     272             :             void add_text(
     273             :                 drawinglayer::primitive2d::Primitive2DSequence& rTarget,
     274             :                 drawinglayer::primitive2d::Primitive2DSequence& rSource) const;
     275             :             void add_path(
     276             :                 const basegfx::B2DPolyPolygon& rPath,
     277             :                 drawinglayer::primitive2d::Primitive2DSequence& rTarget,
     278             :                 const basegfx::tools::PointIndexSet* pHelpPointIndices) const;
     279             :             void add_postProcess(
     280             :                 drawinglayer::primitive2d::Primitive2DSequence& rTarget,
     281             :                 const drawinglayer::primitive2d::Primitive2DSequence& rSource,
     282             :                 const basegfx::B2DHomMatrix* pTransform) const;
     283             : 
     284             :             /// helper to set mpCssStyleParent temporarily for CSS style hierarchies
     285       22830 :             void setCssStyleParent(const SvgStyleAttributes* pNew) { mpCssStyleParent = pNew; }
     286      135943 :             const SvgStyleAttributes* getCssStyleParent() const { return mpCssStyleParent; }
     287             : 
     288             :             /// scan helpers
     289             :             void readCssStyle(const OUString& rCandidate);
     290             :             const SvgStyleAttributes* getParentStyle() const;
     291             : 
     292             :             SvgStyleAttributes(SvgNode& rOwner);
     293             :             ~SvgStyleAttributes();
     294             : 
     295             :             /// fill content
     296             :             bool isFillSet() const; // #i125258# ask if fill is a direct hard attribute (no hierarchy)
     297             :             const basegfx::BColor* getFill() const;
     298        1886 :             void setFill(const SvgPaint& rFill) { maFill = rFill; }
     299             : 
     300             :             /// stroke content
     301             :             const basegfx::BColor* getStroke() const;
     302         234 :             void setStroke(const SvgPaint& rStroke) { maStroke = rStroke; }
     303             : 
     304             :             /// stop color content
     305             :             const basegfx::BColor& getStopColor() const;
     306        3433 :             void setStopColor(const SvgPaint& rStopColor) { maStopColor = rStopColor; }
     307             : 
     308             :             /// stroke-width content
     309             :             SvgNumber getStrokeWidth() const;
     310         220 :             void setStrokeWidth(const SvgNumber& rStrokeWidth = SvgNumber()) { maStrokeWidth = rStrokeWidth; }
     311             : 
     312             :             /// stop opacity content
     313             :             SvgNumber getStopOpacity() const;
     314           0 :             void setStopOpacity(const SvgNumber& rStopOpacity = SvgNumber()) { maStopOpacity = rStopOpacity; }
     315             : 
     316             :             /// access to evtl. set fill gradient
     317             :             const SvgGradientNode* getSvgGradientNodeFill() const;
     318        1283 :             void setSvgGradientNodeFill(const SvgGradientNode* pNew) { mpSvgGradientNodeFill = pNew; }
     319             : 
     320             :             /// access to evtl. set fill pattern
     321             :             const SvgPatternNode* getSvgPatternNodeFill() const;
     322           0 :             void setSvgPatternNodeFill(const SvgPatternNode* pNew) { mpSvgPatternNodeFill = pNew; }
     323             : 
     324             :             /// access to evtl. set stroke gradient
     325             :             const SvgGradientNode* getSvgGradientNodeStroke() const;
     326           0 :             void setSvgGradientNodeStroke(const SvgGradientNode* pNew) { mpSvgGradientNodeStroke = pNew; }
     327             : 
     328             :             /// access to evtl. set stroke pattern
     329             :             const SvgPatternNode* getSvgPatternNodeStroke() const;
     330           0 :             void setSvgPatternNodeStroke(const SvgPatternNode* pNew) { mpSvgPatternNodeStroke = pNew; }
     331             : 
     332             :             /// fill opacity content
     333             :             SvgNumber getFillOpacity() const;
     334           1 :             void setFillOpacity(const SvgNumber& rFillOpacity = SvgNumber()) { maFillOpacity = rFillOpacity; }
     335             : 
     336             :             /// fill rule content
     337             :             FillRule getFillRule() const;
     338             :             void setFillRule(const FillRule aFillRule = FillRule_notset) { maFillRule = aFillRule; }
     339             : 
     340             :             /// fill StrokeDasharray content
     341             :             const SvgNumberVector& getStrokeDasharray() const;
     342          15 :             void setStrokeDasharray(const SvgNumberVector& rStrokeDasharray = SvgNumberVector()) { maStrokeDasharray = rStrokeDasharray; }
     343             : 
     344             :             /// #121221# StrokeDasharray needs a set state, it *may* be set to empty by purpose
     345         846 :             bool getStrokeDasharraySet() const { return mbStrokeDasharraySet; }
     346           0 :             void setStrokeDasharraySet(bool bNew) { mbStrokeDasharraySet = bNew; }
     347             : 
     348             :             /// StrokeDashOffset content
     349             :             SvgNumber getStrokeDashOffset() const;
     350           0 :             void setStrokeDashOffset(const SvgNumber& rStrokeDashOffset = SvgNumber()) { maStrokeDashOffset = rStrokeDashOffset; }
     351             : 
     352             :             /// StrokeLinecap content
     353             :             StrokeLinecap getStrokeLinecap() const;
     354          38 :             void setStrokeLinecap(const StrokeLinecap aStrokeLinecap = StrokeLinecap_notset) { maStrokeLinecap = aStrokeLinecap; }
     355             : 
     356             :             /// StrokeLinejoin content
     357             :             StrokeLinejoin getStrokeLinejoin() const;
     358          30 :             void setStrokeLinejoin(const StrokeLinejoin aStrokeLinejoin = StrokeLinejoin_notset) { maStrokeLinejoin = aStrokeLinejoin; }
     359             : 
     360             :             /// StrokeMiterLimit content
     361             :             SvgNumber getStrokeMiterLimit() const;
     362           0 :             void setStrokeMiterLimit(const SvgNumber& rStrokeMiterLimit = SvgNumber()) { maStrokeMiterLimit = rStrokeMiterLimit; }
     363             : 
     364             :             /// StrokeOpacity content
     365             :             SvgNumber getStrokeOpacity() const;
     366           0 :             void setStrokeOpacity(const SvgNumber& rStrokeOpacity = SvgNumber()) { maStrokeOpacity = rStrokeOpacity; }
     367             : 
     368             :             /// Font content
     369             :             const SvgStringVector& getFontFamily() const;
     370           0 :             void setFontFamily(const SvgStringVector& rSvgStringVector = SvgStringVector()) { maFontFamily = rSvgStringVector; }
     371             : 
     372             :             /// FontSize content
     373             :             SvgNumber getFontSize() const;
     374           0 :             void setFontSize(const SvgNumber& rFontSize = SvgNumber()) { maFontSize = rFontSize; }
     375             : 
     376             :             /// FontStretch content
     377             :             FontStretch getFontStretch() const;
     378           0 :             void setFontStretch(const FontStretch aFontStretch = FontStretch_notset) { maFontStretch = aFontStretch; }
     379             : 
     380             :             /// FontStyle content
     381             :             FontStyle getFontStyle() const;
     382           0 :             void setFontStyle(const FontStyle aFontStyle = FontStyle_notset) { maFontStyle = aFontStyle; }
     383             : 
     384             :             /// FontVariant content
     385             :             FontVariant getFontVariant() const;
     386           0 :             void setFontVariant(const FontVariant aFontVariant = FontVariant_notset) { maFontVariant = aFontVariant; }
     387             : 
     388             :             /// FontWeight content
     389             :             FontWeight getFontWeight() const;
     390           0 :             void setFontWeight(const FontWeight aFontWeight = FontWeight_notset) { maFontWeight = aFontWeight; }
     391             : 
     392             :             /// TextAlign content
     393             :             TextAlign getTextAlign() const;
     394           0 :             void setTextAlign(const TextAlign aTextAlign = TextAlign_notset) { maTextAlign = aTextAlign; }
     395             : 
     396             :             /// TextDecoration content
     397             :             const SvgStyleAttributes* getTextDecorationDefiningSvgStyleAttributes() const;
     398             :             TextDecoration getTextDecoration() const;
     399           0 :             void setTextDecoration(const TextDecoration aTextDecoration = TextDecoration_notset) { maTextDecoration = aTextDecoration; }
     400             : 
     401             :             /// TextAnchor content
     402             :             TextAnchor getTextAnchor() const;
     403           0 :             void setTextAnchor(const TextAnchor aTextAnchor = TextAnchor_notset) { maTextAnchor = aTextAnchor; }
     404             : 
     405             :             /// Color content
     406             :             const basegfx::BColor* getColor() const;
     407           0 :             void setColor(const SvgPaint& rColor) { maColor = rColor; }
     408             : 
     409             :             /// Opacity content
     410        9831 :             SvgNumber getOpacity() const { return maOpacity; }
     411         719 :             void setOpacity(const SvgNumber& rOpacity = SvgNumber()) { maOpacity = rOpacity; }
     412             : 
     413             :             /// Visibility
     414       24658 :             Visibility getVisibility() const { return maVisibility; }
     415           0 :             void setVisibility(Visibility eVisibility) { maVisibility = eVisibility; }
     416             : 
     417             :             // Title content
     418        2401 :             const OUString& getTitle() const { return maTitle; }
     419           0 :             void setTitle(const OUString& rNew) { maTitle = rNew; }
     420             : 
     421             :             // Desc content
     422        2401 :             const OUString& getDesc() const { return maDesc; }
     423           0 :             void setDesc(const OUString& rNew) { maDesc = rNew; }
     424             : 
     425             :             // ClipPathXLink content
     426        5164 :             const OUString getClipPathXLink() const { return maClipPathXLink; }
     427             :             void setClipPathXLink(const OUString& rNew) { maClipPathXLink = rNew; }
     428             : 
     429             :             // MaskXLink content
     430        5161 :             const OUString getMaskXLink() const { return maMaskXLink; }
     431             :             void setMaskXLink(const OUString& rNew) { maMaskXLink = rNew; }
     432             : 
     433             :             // MarkerStartXLink content
     434             :             OUString getMarkerStartXLink() const;
     435             :             const SvgMarkerNode* accessMarkerStartXLink() const;
     436             :             void setMarkerStartXLink(const OUString& rNew) { maMarkerStartXLink = rNew; }
     437             : 
     438             :             // MarkerMidXLink content
     439             :             OUString getMarkerMidXLink() const;
     440             :             const SvgMarkerNode* accessMarkerMidXLink() const;
     441             :             void setMarkerMidXLink(const OUString& rNew) { maMarkerMidXLink = rNew; }
     442             : 
     443             :             // MarkerEndXLink content
     444             :             OUString getMarkerEndXLink() const;
     445             :             const SvgMarkerNode* accessMarkerEndXLink() const;
     446             :             void setMarkerEndXLink(const OUString& rNew) { maMarkerEndXLink = rNew; }
     447             : 
     448             :             // BaselineShift
     449           0 :             void setBaselineShift(const BaselineShift aBaselineShift = BaselineShift_Baseline) { maBaselineShift = aBaselineShift; }
     450           0 :             BaselineShift getBaselineShift() const { return maBaselineShift; }
     451           0 :             void setBaselineShiftNumber(const SvgNumber& rBaselineShift = SvgNumber()) { maBaselineShiftNumber = rBaselineShift; }
     452             :             SvgNumber getBaselineShiftNumber() const;
     453             :         };
     454             :     } // end of namespace svgreader
     455             : } // end of namespace svgio
     456             : 
     457             : #endif // INCLUDED_SVGIO_INC_SVGIO_SVGREADER_SVGSTYLEATTRIBUTES_HXX
     458             : 
     459             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10