LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/filter/source/svg - units.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 41 0.0 %
Date: 2013-07-09 Functions: 0 4 0.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             :  */
      12             : 
      13             : #include "units.hxx"
      14             : #include <basegfx/range/b2drange.hxx>
      15             : #include "gfxtypes.hxx"
      16             : #include <rtl/ustring.hxx>
      17             : #include <boost/spirit/include/classic.hpp>
      18             : 
      19             : namespace svgi
      20             : {
      21             : 
      22           0 : double convLength( double value, SvgUnit unit, const State& rState, char dir )
      23             : {
      24             :     // convert svg unit to internal coordinates ("pixel"). Since the
      25             :     // OOo drawing layer is still largely integer-based, the initial
      26             :     // viewport transformation includes a certain scale factor
      27           0 :     double fRet(value);
      28           0 :     switch ( unit )
      29             :     {
      30           0 :         case SVG_LENGTH_UNIT_CM: fRet *= 72.0/2.54; break;
      31           0 :         case SVG_LENGTH_UNIT_IN: fRet *= 72.0; break;
      32           0 :         case SVG_LENGTH_UNIT_MM: fRet *= 72.0/25.4; break;
      33           0 :         case SVG_LENGTH_UNIT_PC: fRet *= 72.0/6.0; break;
      34             :         case SVG_LENGTH_UNIT_USER:
      35             :         case SVG_LENGTH_UNIT_PX: // no unit defaults to PX in svg,
      36             :                                  // assume display to have 72DPI
      37           0 :         case SVG_LENGTH_UNIT_PT: break;
      38           0 :         case SVG_LENGTH_UNIT_EM: fRet *= rState.mnFontSize; break;
      39           0 :         case SVG_LENGTH_UNIT_EX: fRet *= rState.mnFontSize / 2.0; break;
      40             :         case SVG_LENGTH_UNIT_PERCENTAGE:
      41             :         {
      42             :             double fBoxLen;
      43           0 :             if (rState.maViewBox.isEmpty())
      44             :             {
      45             :                 basegfx::B2DRange aDefaultBox(0, 0,
      46             :                   convLength(210, SVG_LENGTH_UNIT_MM, rState, 'h'),
      47           0 :                   convLength(297, SVG_LENGTH_UNIT_MM, rState, 'v'));
      48             :                 fBoxLen = (dir=='h' ? aDefaultBox.getWidth() :
      49             :                           (dir=='v' ? aDefaultBox.getHeight() :
      50           0 :                            aDefaultBox.getRange().getLength()));
      51             :             }
      52             :             else
      53             :             {
      54           0 :                 fBoxLen = (dir=='h' ? rState.maViewBox.getWidth() :
      55           0 :                           (dir=='v' ? rState.maViewBox.getHeight() :
      56           0 :                            rState.maViewBox.getRange().getLength()));
      57             :             }
      58             : 
      59           0 :             fRet *= fBoxLen/100.0;
      60             :         }
      61           0 :         break;
      62           0 :         default: OSL_TRACE( "Unknown length type" ); break;
      63             :     }
      64             : 
      65           0 :     return fRet;
      66             : }
      67             : 
      68           0 : double convLength( const OUString& sValue, const State& rState, char dir )
      69             : {
      70             :     //FIXME: convert deprecated spirit::classic to use spirit::qi
      71             :     using namespace ::boost::spirit::classic;
      72             : 
      73             :     OString aUTF8 = OUStringToOString( sValue,
      74           0 :                                                  RTL_TEXTENCODING_UTF8 );
      75             : 
      76           0 :     double  nVal=0.0;
      77           0 :     SvgUnit eUnit=SVG_LENGTH_UNIT_PX;
      78             :     const bool bRes = parse(aUTF8.getStr(),
      79             :         //  Begin grammar
      80             :         (
      81           0 :             real_p[assign_a(nVal)]
      82           0 :             >> (  str_p("cm") [assign_a(eUnit,SVG_LENGTH_UNIT_CM)]
      83           0 :                 | str_p("em") [assign_a(eUnit,SVG_LENGTH_UNIT_EM)]
      84           0 :                 | str_p("ex") [assign_a(eUnit,SVG_LENGTH_UNIT_EX)]
      85           0 :                 | str_p("in") [assign_a(eUnit,SVG_LENGTH_UNIT_IN)]
      86           0 :                 | str_p("mm") [assign_a(eUnit,SVG_LENGTH_UNIT_MM)]
      87           0 :                 | str_p("pc") [assign_a(eUnit,SVG_LENGTH_UNIT_PC)]
      88           0 :                 | str_p("pt") [assign_a(eUnit,SVG_LENGTH_UNIT_PT)]
      89           0 :                 | str_p("px") [assign_a(eUnit,SVG_LENGTH_UNIT_PX)]
      90           0 :                 | str_p("%") [assign_a(eUnit,SVG_LENGTH_UNIT_PERCENTAGE)]
      91           0 :                 | str_p("") [assign_a(eUnit,SVG_LENGTH_UNIT_USER)]
      92           0 :                 | end_p)
      93             :         ),
      94             :         //  End grammar
      95           0 :         space_p).full;
      96             : 
      97           0 :     if( !bRes )
      98           0 :         return 0.0;
      99             : 
     100           0 :     return convLength(nVal,eUnit,rState,dir);
     101             : }
     102             : 
     103           0 : } // namespace svgi
     104             : 
     105             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10