LCOV - code coverage report
Current view: top level - libreoffice/oox/source/drawingml - drawingmltypes.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 42 100 42.0 %
Date: 2012-12-27 Functions: 11 17 64.7 %
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             : #include "oox/drawingml/drawingmltypes.hxx"
      21             : #include <com/sun/star/awt/FontUnderline.hpp>
      22             : #include <com/sun/star/awt/FontStrikeout.hpp>
      23             : #include <com/sun/star/style/CaseMap.hpp>
      24             : #include <com/sun/star/style/ParagraphAdjust.hpp>
      25             : #include <sax/tools/converter.hxx>
      26             : #include "oox/token/tokens.hxx"
      27             : 
      28             : using ::com::sun::star::uno::Reference;
      29             : using ::com::sun::star::xml::sax::XFastAttributeList;
      30             : using namespace ::com::sun::star;
      31             : using namespace ::com::sun::star::drawing;
      32             : using namespace ::com::sun::star::geometry;
      33             : using namespace ::com::sun::star::style;
      34             : 
      35             : namespace oox {
      36             : namespace drawingml {
      37             : 
      38             : // ============================================================================
      39             : 
      40             : /** converts EMUs into 1/100th mmm */
      41         281 : sal_Int32 GetCoordinate( sal_Int32 nValue )
      42             : {
      43         281 :     return (nValue + 180) / 360;
      44             : }
      45             : 
      46             : /** converts an emu string into 1/100th mmm */
      47         281 : sal_Int32 GetCoordinate( const OUString& sValue )
      48             : {
      49         281 :     sal_Int32 nRet = 0;
      50         281 :     if( !::sax::Converter::convertNumber( nRet, sValue ) )
      51           0 :         nRet = 0;
      52         281 :     return GetCoordinate( nRet );
      53             : }
      54             : 
      55             : /** converts a ST_Percentage % string into 1/1000th of % */
      56         110 : sal_Int32 GetPercent( const OUString& sValue )
      57             : {
      58         110 :     sal_Int32 nRet = 0;
      59         110 :     if( !::sax::Converter::convertNumber( nRet, sValue ) )
      60           0 :         nRet = 0;
      61             : 
      62         110 :     return nRet;
      63             : }
      64             : 
      65           0 : double GetPositiveFixedPercentage( const OUString& sValue )
      66             : {
      67           0 :     double fPercent = sValue.toFloat() / 100000.;
      68           0 :     return fPercent;
      69             : }
      70             : 
      71             : // --------------------------------------------------------------------
      72             : 
      73             : /** converts the attributes from an CT_TLPoint into an awt Point with 1/1000% */
      74           0 : awt::Point GetPointPercent( const Reference< XFastAttributeList >& xAttribs )
      75             : {
      76           0 :     return awt::Point( GetPercent( xAttribs->getOptionalValue( XML_x ) ), GetCoordinate( xAttribs->getOptionalValue( XML_y ) ) );
      77             : }
      78             : 
      79             : // --------------------------------------------------------------------
      80             : 
      81             : /** converts the ST_TextFontSize to point */
      82           0 : float GetTextSize( const OUString& sValue )
      83             : {
      84           0 :     float fRet = 0;
      85             :     sal_Int32 nRet;
      86           0 :     if( ::sax::Converter::convertNumber( nRet, sValue ) )
      87           0 :         fRet = static_cast< float >( static_cast< double >( nRet ) / 100.0 );
      88           0 :     return fRet;
      89             : }
      90             : 
      91             : 
      92             : /** converts the ST_TextSpacingPoint to 1/100mm */
      93           0 : sal_Int32 GetTextSpacingPoint( const OUString& sValue )
      94             : {
      95             :     sal_Int32 nRet;
      96           0 :     if( ::sax::Converter::convertNumber( nRet, sValue ) )
      97           0 :         nRet = GetTextSpacingPoint( nRet );
      98           0 :     return nRet;
      99             : }
     100             : 
     101         108 : sal_Int32 GetTextSpacingPoint( const sal_Int32 nValue )
     102             : {
     103         108 :     return ( nValue * 254 + 360 ) / 720;
     104             : }
     105             : 
     106         141 : float GetFontHeight( sal_Int32 nHeight )
     107             : {
     108             :     // convert 1/100 points to points
     109         141 :     return static_cast< float >( nHeight / 100.0 );
     110             : }
     111             : 
     112         108 : sal_Int16 GetFontUnderline( sal_Int32 nToken )
     113             : {
     114             :     OSL_ASSERT((nToken & sal_Int32(0xFFFF0000))==0);
     115         108 :     switch( nToken )
     116             :     {
     117         105 :         case XML_none:              return awt::FontUnderline::NONE;
     118           0 :         case XML_dash:              return awt::FontUnderline::DASH;
     119           0 :         case XML_dashHeavy:         return awt::FontUnderline::BOLDDASH;
     120           0 :         case XML_dashLong:          return awt::FontUnderline::LONGDASH;
     121           0 :         case XML_dashLongHeavy:     return awt::FontUnderline::BOLDLONGDASH;
     122           0 :         case XML_dbl:               return awt::FontUnderline::DOUBLE;
     123           0 :         case XML_dotDash:           return awt::FontUnderline::DASHDOT;
     124           0 :         case XML_dotDashHeavy:      return awt::FontUnderline::BOLDDASHDOT;
     125           0 :         case XML_dotDotDash:        return awt::FontUnderline::DASHDOTDOT;
     126           0 :         case XML_dotDotDashHeavy:   return awt::FontUnderline::BOLDDASHDOTDOT;
     127           0 :         case XML_dotted:            return awt::FontUnderline::DOTTED;
     128           0 :         case XML_dottedHeavy:       return awt::FontUnderline::BOLDDOTTED;
     129           0 :         case XML_heavy:             return awt::FontUnderline::BOLD;
     130           3 :         case XML_sng:               return awt::FontUnderline::SINGLE;
     131           0 :         case XML_wavy:              return awt::FontUnderline::WAVE;
     132           0 :         case XML_wavyDbl:           return awt::FontUnderline::DOUBLEWAVE;
     133           0 :         case XML_wavyHeavy:         return awt::FontUnderline::BOLDWAVE;
     134             : //        case XML_words:             // TODO
     135             :     }
     136           0 :     return awt::FontUnderline::DONTKNOW;
     137             : }
     138             : 
     139         108 : sal_Int16 GetFontStrikeout( sal_Int32 nToken )
     140             : {
     141             :     OSL_ASSERT((nToken & sal_Int32(0xFFFF0000))==0);
     142         108 :     switch( nToken )
     143             :     {
     144           0 :         case XML_dblStrike: return awt::FontStrikeout::DOUBLE;
     145         108 :         case XML_noStrike:  return awt::FontStrikeout::NONE;
     146           0 :         case XML_sngStrike: return awt::FontStrikeout::SINGLE;
     147             :     }
     148           0 :     return awt::FontStrikeout::DONTKNOW;
     149             : }
     150             : 
     151         108 : sal_Int16 GetCaseMap( sal_Int32 nToken )
     152             : {
     153         108 :     switch( nToken )
     154             :     {
     155           0 :         case XML_all:   return CaseMap::UPPERCASE;
     156           0 :         case XML_small: return CaseMap::SMALLCAPS;
     157             :     }
     158         108 :     return CaseMap::NONE;
     159             : }
     160             : 
     161             : /** converts a paragraph align to a ParaAdjust */
     162         191 : sal_Int16 GetParaAdjust( sal_Int32 nAlign )
     163             : {
     164             :     OSL_ASSERT((nAlign & sal_Int32(0xFFFF0000))==0);
     165             :     sal_Int16 nEnum;
     166         191 :     switch( nAlign )
     167             :     {
     168             :     case XML_ctr:
     169          32 :         nEnum = ParagraphAdjust_CENTER;
     170          32 :         break;
     171             :     case XML_just:
     172             :     case XML_justLow:
     173           0 :         nEnum = ParagraphAdjust_BLOCK;
     174           0 :         break;
     175             :     case XML_r:
     176           5 :         nEnum = ParagraphAdjust_RIGHT;
     177           5 :         break;
     178             :     case XML_thaiDist:
     179             :     case XML_dist:
     180           0 :         nEnum = ParagraphAdjust_STRETCH;
     181           0 :         break;
     182             :     case XML_l:
     183             :     default:
     184         154 :         nEnum = ParagraphAdjust_LEFT;
     185         154 :         break;
     186             :     }
     187         191 :     return nEnum;
     188             : }
     189             : 
     190             : 
     191           0 : TabAlign GetTabAlign( sal_Int32 aToken )
     192             : {
     193             :     OSL_ASSERT((aToken & sal_Int32(0xFFFF0000))==0);
     194             :     TabAlign nEnum;
     195           0 :     switch( aToken )
     196             :     {
     197             :     case XML_ctr:
     198           0 :         nEnum = TabAlign_CENTER;
     199           0 :         break;
     200             :     case XML_dec:
     201           0 :         nEnum = TabAlign_DECIMAL;
     202           0 :         break;
     203             :     case XML_l:
     204           0 :         nEnum = TabAlign_LEFT;
     205           0 :         break;
     206             :     case XML_r:
     207           0 :         nEnum = TabAlign_RIGHT;
     208           0 :         break;
     209             :     default:
     210           0 :         nEnum = TabAlign_DEFAULT;
     211           0 :         break;
     212             :     }
     213           0 :     return nEnum;
     214             : }
     215             : 
     216             : // --------------------------------------------------------------------
     217             : 
     218             : /** converts the attributes from a CT_RelativeRect to an IntegerRectangle2D */
     219          28 : IntegerRectangle2D GetRelativeRect( const Reference< XFastAttributeList >& xAttribs )
     220             : {
     221          28 :     IntegerRectangle2D r;
     222             : 
     223          28 :     r.X1 = xAttribs->getOptionalValue( XML_l ).toInt32();
     224          28 :     r.Y1 = xAttribs->getOptionalValue( XML_t ).toInt32();
     225          28 :     r.X2 = xAttribs->getOptionalValue( XML_r ).toInt32();
     226          28 :     r.Y2 = xAttribs->getOptionalValue( XML_b ).toInt32();
     227             : 
     228          28 :     return r;
     229             : }
     230             : 
     231             : // ============================================================================
     232             : 
     233             : /** converts the attributes from an CT_Size2D into an awt Size with 1/100thmm */
     234           8 : awt::Size GetSize2D( const Reference< XFastAttributeList >& xAttribs )
     235             : {
     236           8 :     return awt::Size( GetCoordinate( xAttribs->getOptionalValue( XML_cx ) ), GetCoordinate( xAttribs->getOptionalValue( XML_cy ) ) );
     237             : }
     238             : 
     239           0 : IndexRange GetIndexRange( const Reference< XFastAttributeList >& xAttributes )
     240             : {
     241             :     IndexRange range;
     242           0 :     range.start = xAttributes->getOptionalValue( XML_st ).toInt32();
     243           0 :     range.end = xAttributes->getOptionalValue( XML_end ).toInt32();
     244           0 :     return range;
     245             : }
     246             : 
     247             : // ============================================================================
     248             : 
     249             : } // namespace drawingml
     250             : } // namespace oox
     251             : 
     252             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10