LCOV - code coverage report
Current view: top level - svgio/inc/svgio/svgreader - svgtools.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 23 23 100.0 %
Date: 2014-11-03 Functions: 12 13 92.3 %
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_SVGTOOLS_HXX
      21             : #define INCLUDED_SVGIO_INC_SVGIO_SVGREADER_SVGTOOLS_HXX
      22             : 
      23             : #include <drawinglayer/primitive2d/baseprimitive2d.hxx>
      24             : #include <basegfx/color/bcolor.hxx>
      25             : #include <basegfx/polygon/b2dpolypolygon.hxx>
      26             : #include <svgio/svgreader/svgpaint.hxx>
      27             : #include <vector>
      28             : 
      29             : namespace svgio
      30             : {
      31             :     namespace svgreader
      32             :     {
      33             : #ifdef DBG_UTIL
      34             :         // error helper
      35             :         void myAssert(const OUString& rMessage);
      36             : #endif
      37             : 
      38             : // recommended value for this devise dependent unit, see CSS2 section 4.3.2 Lengths
      39             : #define F_SVG_PIXEL_PER_INCH  90.0
      40             : 
      41             :         // common non-token strings
      42             :         struct commonStrings
      43             :         {
      44             :             static const OUString aStrUserSpaceOnUse;
      45             :             static const OUString aStrObjectBoundingBox;
      46             :             static const OUString aStrNonzero;
      47             :             static const OUString aStrEvenOdd;
      48             :         };
      49             : 
      50             :         enum SvgUnits
      51             :         {
      52             :             userSpaceOnUse,
      53             :             objectBoundingBox
      54             :         };
      55             : 
      56             :         enum NumberType
      57             :         {
      58             :             xcoordinate,
      59             :             ycoordinate,
      60             :             length
      61             :         };
      62             : 
      63       10783 :         class InfoProvider
      64             :         {
      65             :         public:
      66       10783 :             virtual ~InfoProvider() {}
      67             :             virtual const basegfx::B2DRange getCurrentViewPort() const = 0;
      68             :             /// return font size of node inherited from parents
      69             :             virtual double getCurrentFontSizeInherited() const = 0;
      70             :             /// return xheight of node inherited from parents
      71             :             virtual double getCurrentXHeightInherited() const = 0;
      72             :         };
      73             : 
      74             :         enum SvgUnit
      75             :         {
      76             :             Unit_em = 0,    // relative to current font size
      77             :             Unit_ex,        // relative to current x-height
      78             : 
      79             :             Unit_px,        // 'user unit'
      80             :             Unit_pt,        // points, 1.25 px
      81             :             Unit_pc,        // 15.0 px
      82             :             Unit_cm,        // 35.43307 px
      83             :             Unit_mm,        // 3.543307 px
      84             :             Unit_in,        // 90 px
      85             : 
      86             :             Unit_percent    // relative to range
      87             :         };
      88             : 
      89             :         class SvgNumber
      90             :         {
      91             :         private:
      92             :             double      mfNumber;
      93             :             SvgUnit     meUnit;
      94             : 
      95             :             /// bitfield
      96             :             bool        mbSet : 1;
      97             : 
      98             :         public:
      99      134252 :             SvgNumber()
     100             :             :   mfNumber(0.0),
     101             :                 meUnit(Unit_px),
     102      134252 :                 mbSet(false)
     103             :             {
     104      134252 :             }
     105             : 
     106       56808 :             SvgNumber(double fNum, SvgUnit aSvgUnit = Unit_px, bool bSet = true)
     107             :             :   mfNumber(fNum),
     108             :                 meUnit(aSvgUnit),
     109       56808 :                 mbSet(bSet)
     110             :             {
     111       56808 :             }
     112             : 
     113       11151 :             double getNumber() const
     114             :             {
     115       11151 :                 return mfNumber;
     116             :             }
     117             : 
     118        4633 :             SvgUnit getUnit() const
     119             :             {
     120        4633 :                 return meUnit;
     121             :             }
     122             : 
     123       51370 :             bool isSet() const
     124             :             {
     125       51370 :                 return mbSet;
     126             :             }
     127             : 
     128             :             bool isPositive() const;
     129             : 
     130             :             // Only usable in cases, when the unit is not Unit_percent, otherwise use method solve
     131             :             double solveNonPercentage(const InfoProvider& rInfoProvider) const;
     132             : 
     133             :             double solve(const InfoProvider& rInfoProvider, NumberType aNumberType = length) const;
     134             : 
     135             : 
     136             :         };
     137             : 
     138             :         typedef ::std::vector< SvgNumber > SvgNumberVector;
     139             : 
     140             :         enum SvgAlign
     141             :         {
     142             :             Align_none,
     143             :             Align_xMinYMin,
     144             :             Align_xMidYMin,
     145             :             Align_xMaxYMin,
     146             :             Align_xMinYMid,
     147             :             Align_xMidYMid, // default
     148             :             Align_xMaxYMid,
     149             :             Align_xMinYMax,
     150             :             Align_xMidYMax,
     151             :             Align_xMaxYMax
     152             :         };
     153             : 
     154             :         class SvgAspectRatio
     155             :         {
     156             :         private:
     157             :             SvgAlign    maSvgAlign;
     158             : 
     159             :             /// bitfield
     160             :             bool        mbDefer : 1; // default is false
     161             :             bool        mbMeetOrSlice : 1; // true = meet (default), false = slice
     162             :             bool        mbSet : 1;
     163             : 
     164             :         public:
     165         538 :             SvgAspectRatio()
     166             :             :   maSvgAlign(Align_xMidYMid),
     167             :                 mbDefer(false),
     168             :                 mbMeetOrSlice(true),
     169         538 :                 mbSet(false)
     170             :             {
     171         538 :             }
     172             : 
     173         292 :             SvgAspectRatio(SvgAlign aSvgAlign, bool bDefer, bool bMeetOrSlice)
     174             :             :   maSvgAlign(aSvgAlign),
     175             :                 mbDefer(bDefer),
     176             :                 mbMeetOrSlice(bMeetOrSlice),
     177         292 :                 mbSet(true)
     178             :             {
     179         292 :             }
     180             : 
     181             :             /// data read access
     182         876 :             SvgAlign getSvgAlign() const { return maSvgAlign; }
     183             :             bool isDefer() const { return mbDefer; }
     184         292 :             bool isMeetOrSlice() const { return mbMeetOrSlice; }
     185         821 :             bool isSet() const { return mbSet; }
     186             : 
     187             :             /// tooling
     188             :             static basegfx::B2DHomMatrix createLinearMapping(const basegfx::B2DRange& rTarget, const basegfx::B2DRange& rSource);
     189             :             basegfx::B2DHomMatrix createMapping(const basegfx::B2DRange& rTarget, const basegfx::B2DRange& rSource) const;
     190             :         };
     191             : 
     192             :         void skip_char(const OUString& rCandidate, const sal_Unicode& rChar, sal_Int32& nPos, const sal_Int32 nLen);
     193             :         void skip_char(const OUString& rCandidate, const sal_Unicode& rCharA, const sal_Unicode& rCharB, sal_Int32& nPos, const sal_Int32 nLen);
     194             :         void copySign(const OUString& rCandidate, sal_Int32& nPos, OUStringBuffer& rTarget, const sal_Int32 nLen);
     195             :         void copyNumber(const OUString& rCandidate, sal_Int32& nPos, OUStringBuffer& rTarget, const sal_Int32 nLen);
     196             :         void copyHex(const OUString& rCandidate, sal_Int32& nPos, OUStringBuffer& rTarget, const sal_Int32 nLen);
     197             :         void copyString(const OUString& rCandidate, sal_Int32& nPos, OUStringBuffer& rTarget, const sal_Int32 nLen);
     198             :         void copyToLimiter(const OUString& rCandidate, const sal_Unicode& rLimiter, sal_Int32& nPos, OUStringBuffer& rTarget, const sal_Int32 nLen);
     199             :         bool readNumber(const OUString& rCandidate, sal_Int32& nPos, double& fNum, const sal_Int32 nLen);
     200             :         SvgUnit readUnit(const OUString& rCandidate, sal_Int32& nPos, const sal_Int32 nLen);
     201             :         bool readNumberAndUnit(const OUString& rCandidate, sal_Int32& nPos, SvgNumber& aNum, const sal_Int32 nLen);
     202             :         bool readAngle(const OUString& rCandidate, sal_Int32& nPos, double& fAngle, const sal_Int32 nLen);
     203             :         sal_Int32 read_hex(const sal_Unicode& rChar);
     204             :         bool match_colorKeyword(basegfx::BColor& rColor, const OUString& rName, bool bCaseIndependent);
     205             :         bool read_color(const OUString& rCandidate, basegfx::BColor& rColor, bool bCaseIndependent);
     206             :         basegfx::B2DRange readViewBox(const OUString& rCandidate, InfoProvider& rInfoProvider);
     207             :         basegfx::B2DHomMatrix readTransform(const OUString& rCandidate, InfoProvider& rInfoProvider);
     208             :         bool readSingleNumber(const OUString& rCandidate, SvgNumber& aNum);
     209             :         bool readLocalUrl(const OUString& rCandidate, OUString& rURL);
     210             :         bool readSvgPaint(const OUString& rCandidate, SvgPaint& rSvgPaint, OUString& rURL, bool bCaseIndependent);
     211             : 
     212             :         bool readSvgNumberVector(const OUString& rCandidate, SvgNumberVector& rSvgNumberVector);
     213             :         ::std::vector< double > solveSvgNumberVector(const SvgNumberVector& rInput, const InfoProvider& rInfoProvider, NumberType aNumberType = length);
     214             : 
     215             :         SvgAspectRatio readSvgAspectRatio(const OUString& rCandidate);
     216             : 
     217             :         typedef ::std::vector< OUString > SvgStringVector;
     218             :         bool readSvgStringVector(const OUString& rCandidate, SvgStringVector& rSvgStringVector);
     219             : 
     220             :         void readImageLink(const OUString& rCandidate, OUString& rXLink, OUString& rUrl, OUString& rMimeType, OUString& rData);
     221             : 
     222             :         OUString convert(const OUString& rCandidate, const sal_Unicode& rPattern, const sal_Unicode& rNew, bool bRemove);
     223             :         OUString consolidateContiguosSpace(const OUString& rCandidate);
     224             :         OUString whiteSpaceHandlingDefault(const OUString& rCandidate);
     225             :         OUString whiteSpaceHandlingPreserve(const OUString& rCandidate);
     226             : 
     227             :         // #125325# removes block comment of the general form '/* ... */', returns
     228             :         // an adapted string or the original if no comments included
     229             :         OUString removeBlockComments(const OUString& rCandidate);
     230             : 
     231             :     } // end of namespace svgreader
     232             : } // end of namespace svgio
     233             : 
     234             : #endif // INCLUDED_SVGIO_INC_SVGIO_SVGREADER_SVGTOOLS_HXX
     235             : 
     236             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10