LCOV - code coverage report
Current view: top level - libreoffice/filter/source/svg - units.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 41 0.0 %
Date: 2012-12-27 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             :  * Version: MPL 1.1 / GPLv3+ / LGPLv3+
       4             :  *
       5             :  * The contents of this file are subject to the Mozilla Public License Version
       6             :  * 1.1 (the "License"); you may not use this file except in compliance with
       7             :  * the License. You may obtain a copy of the License at
       8             :  * http://www.mozilla.org/MPL/
       9             :  *
      10             :  * Software distributed under the License is distributed on an "AS IS" basis,
      11             :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12             :  * for the specific language governing rights and limitations under the
      13             :  * License.
      14             :  *
      15             :  * The Initial Developer of the Original Code is
      16             :  *       Jan Holesovsky   <kendy@suse.cz>
      17             :  *       Fridrich Strba   <fridrich.strba@bluewin.ch>
      18             :  *       Thorsten Behrens <tbehrens@novell.com>
      19             :  *
      20             :  * Contributor(s):
      21             :  *
      22             :  * Alternatively, the contents of this file may be used under the terms of
      23             :  * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
      24             :  * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
      25             :  * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
      26             :  * instead of those above.
      27             :  */
      28             : 
      29             : #include "units.hxx"
      30             : #include <basegfx/range/b2drange.hxx>
      31             : #include "gfxtypes.hxx"
      32             : #include <rtl/ustring.hxx>
      33             : #include <boost/spirit/include/classic.hpp>
      34             : 
      35             : namespace svgi
      36             : {
      37             : 
      38           0 : double convLength( double value, SvgUnit unit, const State& rState, char dir )
      39             : {
      40             :     // convert svg unit to internal coordinates ("pixel"). Since the
      41             :     // OOo drawing layer is still largely integer-based, the initial
      42             :     // viewport transformation includes a certain scale factor
      43           0 :     double fRet(value);
      44           0 :     switch ( unit )
      45             :     {
      46           0 :         case SVG_LENGTH_UNIT_CM: fRet *= 72.0/2.54; break;
      47           0 :         case SVG_LENGTH_UNIT_IN: fRet *= 72.0; break;
      48           0 :         case SVG_LENGTH_UNIT_MM: fRet *= 72.0/25.4; break;
      49           0 :         case SVG_LENGTH_UNIT_PC: fRet *= 72.0/6.0; break;
      50             :         case SVG_LENGTH_UNIT_USER:
      51             :         case SVG_LENGTH_UNIT_PX: // no unit defaults to PX in svg,
      52             :                                  // assume display to have 72DPI
      53           0 :         case SVG_LENGTH_UNIT_PT: break;
      54           0 :         case SVG_LENGTH_UNIT_EM: fRet *= rState.mnFontSize; break;
      55           0 :         case SVG_LENGTH_UNIT_EX: fRet *= rState.mnFontSize / 2.0; break;
      56             :         case SVG_LENGTH_UNIT_PERCENTAGE:
      57             :         {
      58             :             double fBoxLen;
      59           0 :             if (rState.maViewBox.isEmpty())
      60             :             {
      61             :                 basegfx::B2DRange aDefaultBox(0, 0,
      62             :                   convLength(210, SVG_LENGTH_UNIT_MM, rState, 'h'),
      63           0 :                   convLength(297, SVG_LENGTH_UNIT_MM, rState, 'v'));
      64             :                 fBoxLen = (dir=='h' ? aDefaultBox.getWidth() :
      65             :                           (dir=='v' ? aDefaultBox.getHeight() :
      66           0 :                            aDefaultBox.getRange().getLength()));
      67             :             }
      68             :             else
      69             :             {
      70           0 :                 fBoxLen = (dir=='h' ? rState.maViewBox.getWidth() :
      71           0 :                           (dir=='v' ? rState.maViewBox.getHeight() :
      72           0 :                            rState.maViewBox.getRange().getLength()));
      73             :             }
      74             : 
      75           0 :             fRet *= fBoxLen/100.0;
      76             :         }
      77           0 :         break;
      78           0 :         default: OSL_TRACE( "Unknown length type" ); break;
      79             :     }
      80             : 
      81           0 :     return fRet;
      82             : }
      83             : 
      84           0 : double convLength( const rtl::OUString& sValue, const State& rState, char dir )
      85             : {
      86             :     //FIXME: convert deprecated spirit::classic to use spirit::qi
      87             :     using namespace ::boost::spirit::classic;
      88             : 
      89             :     rtl::OString aUTF8 = rtl::OUStringToOString( sValue,
      90           0 :                                                  RTL_TEXTENCODING_UTF8 );
      91             : 
      92           0 :     double  nVal=0.0;
      93           0 :     SvgUnit eUnit=SVG_LENGTH_UNIT_PX;
      94             :     const bool bRes = parse(aUTF8.getStr(),
      95             :         //  Begin grammar
      96             :         (
      97           0 :             real_p[assign_a(nVal)]
      98           0 :             >> (  str_p("cm") [assign_a(eUnit,SVG_LENGTH_UNIT_CM)]
      99           0 :                 | str_p("em") [assign_a(eUnit,SVG_LENGTH_UNIT_EM)]
     100           0 :                 | str_p("ex") [assign_a(eUnit,SVG_LENGTH_UNIT_EX)]
     101           0 :                 | str_p("in") [assign_a(eUnit,SVG_LENGTH_UNIT_IN)]
     102           0 :                 | str_p("mm") [assign_a(eUnit,SVG_LENGTH_UNIT_MM)]
     103           0 :                 | str_p("pc") [assign_a(eUnit,SVG_LENGTH_UNIT_PC)]
     104           0 :                 | str_p("pt") [assign_a(eUnit,SVG_LENGTH_UNIT_PT)]
     105           0 :                 | str_p("px") [assign_a(eUnit,SVG_LENGTH_UNIT_PX)]
     106           0 :                 | str_p("%") [assign_a(eUnit,SVG_LENGTH_UNIT_PERCENTAGE)]
     107           0 :                 | str_p("") [assign_a(eUnit,SVG_LENGTH_UNIT_USER)]
     108           0 :                 | end_p)
     109             :         ),
     110             :         //  End grammar
     111           0 :         space_p).full;
     112             : 
     113           0 :     if( !bRes )
     114           0 :         return 0.0;
     115             : 
     116           0 :     return convLength(nVal,eUnit,rState,dir);
     117             : }
     118             : 
     119           0 : } // namespace svgi
     120             : 
     121             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10