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

Generated by: LCOV version 1.10