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

Generated by: LCOV version 1.10