1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
6 * Jan Holesovsky <kendy@suse.cz>
7 * Fridrich Strba <fridrich.strba@bluewin.ch>
8 * Thorsten Behrens <tbehrens@novell.com>
10 * Copyright (C) 2008, Novell Inc.
12 * The Contents of this file are made available subject to
13 * the terms of GNU Lesser General Public License Version 2.1.
15 ************************************************************************/
17 // MARKER(update_precomp.py): autogen include statement, do not remove
18 #include "precompiled_filter.hxx"
21 #include "gfxtypes.hxx"
22 #include "spirit_supplements.hxx"
25 #include <rtl/ustring.hxx>
27 #include <boost/bind.hpp>
28 // workaround. spirit uses INT_MAX.
30 #include <boost/spirit.hpp>
36 double convLength( double value
, SvgUnit unit
, const State
& rState
, char dir
)
38 // convert svg unit to internal coordinates ("pixel"). Since the
39 // OOo drawing layer is still largely integer-based, the initial
40 // viewport transformation includes a certain scale factor
44 case SVG_LENGTH_UNIT_CM
: fRet
*= 72.0/2.54; break;
45 case SVG_LENGTH_UNIT_IN
: fRet
*= 72.0; break;
46 case SVG_LENGTH_UNIT_MM
: fRet
*= 72.0/25.4; break;
47 case SVG_LENGTH_UNIT_PC
: fRet
*= 72.0/6.0; break;
48 case SVG_LENGTH_UNIT_USER
:
49 case SVG_LENGTH_UNIT_PX
: // no unit defaults to PX in svg,
50 // assume display to have 72DPI
51 case SVG_LENGTH_UNIT_PT
: break;
52 case SVG_LENGTH_UNIT_EM
: fRet
*= rState
.mnFontSize
; break;
53 case SVG_LENGTH_UNIT_EX
: fRet
*= rState
.mnFontSize
/ 2.0; break;
54 case SVG_LENGTH_UNIT_PERCENTAGE
:
57 if (rState
.maViewBox
.isEmpty())
59 basegfx::B2DRange
aDefaultBox(0, 0,
60 convLength(210, SVG_LENGTH_UNIT_MM
, rState
, 'h'),
61 convLength(297, SVG_LENGTH_UNIT_MM
, rState
, 'v'));
62 fBoxLen
= (dir
=='h' ? aDefaultBox
.getWidth() :
63 (dir
=='v' ? aDefaultBox
.getHeight() :
64 aDefaultBox
.getRange().getLength()));
68 fBoxLen
= (dir
=='h' ? rState
.maViewBox
.getWidth() :
69 (dir
=='v' ? rState
.maViewBox
.getHeight() :
70 rState
.maViewBox
.getRange().getLength()));
73 fRet
*= fBoxLen
/100.0;
76 default: OSL_TRACE( "Unknown length type" ); break;
82 double convLength( const rtl::OUString
& sValue
, const State
& rState
, char dir
)
84 using namespace ::boost::spirit
;
86 rtl::OString aUTF8
= rtl::OUStringToOString( sValue
,
87 RTL_TEXTENCODING_UTF8
);
90 SvgUnit eUnit
=SVG_LENGTH_UNIT_PX
;
91 const bool bRes
= parse(aUTF8
.getStr(),
94 real_p
[assign_a(nVal
)]
95 >> ( str_p("cm") [assign_a(eUnit
,SVG_LENGTH_UNIT_CM
)]
96 | str_p("em") [assign_a(eUnit
,SVG_LENGTH_UNIT_EM
)]
97 | str_p("ex") [assign_a(eUnit
,SVG_LENGTH_UNIT_EX
)]
98 | str_p("in") [assign_a(eUnit
,SVG_LENGTH_UNIT_IN
)]
99 | str_p("mm") [assign_a(eUnit
,SVG_LENGTH_UNIT_MM
)]
100 | str_p("pc") [assign_a(eUnit
,SVG_LENGTH_UNIT_PC
)]
101 | str_p("pt") [assign_a(eUnit
,SVG_LENGTH_UNIT_PT
)]
102 | str_p("px") [assign_a(eUnit
,SVG_LENGTH_UNIT_PX
)]
103 | str_p("%") [assign_a(eUnit
,SVG_LENGTH_UNIT_PERCENTAGE
)]
104 | str_p("") [assign_a(eUnit
,SVG_LENGTH_UNIT_USER
)]
113 return convLength(nVal
,eUnit
,rState
,dir
);