LCOV - code coverage report
Current view: top level - starmath/inc - utility.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 16 22 72.7 %
Date: 2014-11-03 Functions: 11 16 68.8 %
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             : #ifndef INCLUDED_STARMATH_INC_UTILITY_HXX
      20             : #define INCLUDED_STARMATH_INC_UTILITY_HXX
      21             : 
      22             : #include <vcl/font.hxx>
      23             : #include <vcl/fixed.hxx>
      24             : #include <vcl/combobox.hxx>
      25             : #include <vcl/lstbox.hxx>
      26             : #include <tools/fract.hxx>
      27             : #include <deque>
      28             : 
      29             : 
      30        1182 : inline long SmPtsTo100th_mm(long nNumPts)
      31             :     // returns the length (in 100th of mm) that corresponds to the length
      32             :     // 'nNumPts' (in units points).
      33             :     // 72.27 [pt] = 1 [inch] = 2,54 [cm] = 2540 [100th of mm].
      34             :     // result is being rounded to the nearest integer.
      35             : {
      36             :     SAL_WARN_IF( nNumPts < 0, "starmath", "Ooops..." );
      37             :     // broken into multiple and fraction of 'nNumPts' to reduce chance
      38             :     // of overflow
      39             :     // (7227 / 2) is added in order to round to the nearest integer
      40        1182 :     return 35 * nNumPts + (nNumPts * 1055L + (7227 / 2)) / 7227L;
      41             : }
      42             : 
      43             : 
      44             : inline long SmPtsTo100th_mm(const Fraction &rNumPts)
      45             :     // as above but with argument 'rNumPts' as 'Fraction'
      46             : {
      47             :     Fraction  aTmp (254000L, 7227L);
      48             :     return aTmp *= rNumPts;
      49             : }
      50             : 
      51             : 
      52           0 : inline Fraction Sm100th_mmToPts(long nNum100th_mm)
      53             :     // returns the length (in points) that corresponds to the length
      54             :     // 'nNum100th_mm' (in 100th of mm).
      55             : {
      56             :     SAL_WARN_IF( nNum100th_mm < 0, "starmath", "Ooops..." );
      57           0 :     Fraction  aTmp (7227L, 254000L);
      58           0 :     return aTmp *= Fraction(nNum100th_mm);
      59             : }
      60             : 
      61             : 
      62           0 : inline long SmRoundFraction(const Fraction &rFrac)
      63             : {
      64             :     SAL_WARN_IF( rFrac <= Fraction(), "starmath", "Ooops..." );
      65           0 :     return (rFrac.GetNumerator() + rFrac.GetDenominator() / 2) / rFrac.GetDenominator();
      66             : }
      67             : 
      68             : 
      69             : class SmViewShell;
      70             : SmViewShell * SmGetActiveView();
      71             : 
      72             : 
      73             : 
      74             : 
      75             : // SmFace
      76             : 
      77             : 
      78             : bool    IsItalic( const vcl::Font &rFont );
      79             : bool    IsBold( const vcl::Font &rFont );
      80             : 
      81       48670 : class SmFace : public vcl::Font
      82             : {
      83             :     long    nBorderWidth;
      84             : 
      85             :     void    Impl_Init();
      86             : 
      87             : public:
      88       45694 :     SmFace() :
      89       45694 :         Font(), nBorderWidth(-1) { Impl_Init(); }
      90        2912 :     SmFace(const Font& rFont) :
      91        2912 :         Font(rFont), nBorderWidth(-1) { Impl_Init(); }
      92        2918 :     SmFace(const OUString& rName, const Size& rSize) :
      93        2918 :         Font(rName, rSize), nBorderWidth(-1) { Impl_Init(); }
      94             :     SmFace( FontFamily eFamily, const Size& rSize) :
      95             :         Font(eFamily, rSize), nBorderWidth(-1) { Impl_Init(); }
      96             : 
      97          14 :     SmFace(const SmFace &rFace) :
      98          14 :         Font(rFace), nBorderWidth(-1) { Impl_Init(); }
      99             : 
     100             :     // overloaded version in order to supply a min value
     101             :     // for font size (height). (Also used in ctor's to do so.)
     102             :     void    SetSize(const Size& rSize);
     103             : 
     104          14 :     void    SetBorderWidth(long nWidth)     { nBorderWidth = nWidth; }
     105             :     long    GetBorderWidth() const;
     106       16600 :     long    GetDefaultBorderWidth() const   { return GetSize().Height() / 20 ; }
     107        2414 :     void    FreezeBorderWidth()     { nBorderWidth = GetDefaultBorderWidth(); }
     108             : 
     109             :     SmFace & operator = (const SmFace &rFace);
     110             : };
     111             : 
     112             : SmFace & operator *= (SmFace &rFace, const Fraction &rFrac);
     113             : 
     114             : 
     115             : 
     116             : 
     117             : // SmFontPickList
     118             : 
     119             : 
     120             : class SmFontDialog;
     121             : 
     122             : class SmFontPickList
     123             : {
     124             : protected:
     125             :     sal_uInt16 nMaxItems;
     126             :     std::deque<vcl::Font> aFontVec;
     127             : 
     128             :     bool     CompareItem(const vcl::Font & rFirstFont, const vcl::Font & rSecondFont) const;
     129             :     OUString GetStringItem(const vcl::Font &rItem);
     130             : 
     131             : public:
     132         168 :     SmFontPickList(sal_uInt16 nMax = 5) : nMaxItems(nMax) {}
     133          28 :     virtual ~SmFontPickList() { Clear(); }
     134             : 
     135             :     virtual void    Insert(const vcl::Font &rFont);
     136             :     virtual void    Update(const vcl::Font &rFont, const vcl::Font &rNewFont);
     137             :     virtual void    Remove(const vcl::Font &rFont);
     138             : 
     139             :     void            Clear();
     140             :     vcl::Font       Get(sal_uInt16 nPos = 0) const;
     141             : 
     142             :     SmFontPickList& operator = (const SmFontPickList& rList);
     143             :     vcl::Font       operator [] (sal_uInt16 nPos) const;
     144             : 
     145             :     void            ReadFrom(const SmFontDialog& rDialog);
     146             :     void            WriteTo(SmFontDialog& rDialog) const;
     147             : };
     148             : 
     149             : 
     150             : 
     151             : //  SmFontPickListBox
     152             : 
     153             : 
     154           0 : class SmFontPickListBox : public SmFontPickList, public ListBox
     155             : {
     156             : protected:
     157             :     DECL_LINK(SelectHdl, ListBox *);
     158             : 
     159             : public:
     160             :     SmFontPickListBox(vcl::Window* pParent, WinBits nBits);
     161             : 
     162             :     SmFontPickListBox& operator = (const SmFontPickList& rList);
     163             : 
     164             :     virtual void    Insert(const vcl::Font &rFont) SAL_OVERRIDE;
     165             :     using   Window::Update;
     166             :     virtual void    Update(const vcl::Font &rFont, const vcl::Font &rNewFont) SAL_OVERRIDE;
     167             :     virtual void    Remove(const vcl::Font &rFont) SAL_OVERRIDE;
     168             : };
     169             : 
     170             : #endif
     171             : 
     172             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10