LCOV - code coverage report
Current view: top level - starmath/inc - rect.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 49 49 100.0 %
Date: 2012-08-25 Functions: 35 35 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 7 12 58.3 %

           Branch data     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                 :            : #ifndef RECT_HXX
      21                 :            : #define RECT_HXX
      22                 :            : 
      23                 :            : #include <new>
      24                 :            : 
      25                 :            : #include <rtl/ustring.hxx>
      26                 :            : #include <tools/gen.hxx>
      27                 :            : #include <vcl/outdev.hxx>
      28                 :            : #include <vcl/metric.hxx>
      29                 :            : 
      30                 :            : #include "format.hxx"
      31                 :            : 
      32                 :            : 
      33                 :            : bool SmGetGlyphBoundRect(const OutputDevice &rDev,
      34                 :            :                          const rtl::OUString &rText, Rectangle &rRect);
      35                 :            : 
      36                 :            : bool SmIsMathAlpha(const rtl::OUString &rText);
      37                 :            : 
      38                 :            : 
      39                 :      15336 : inline long SmFromTo(long nFrom, long nTo, double fRelDist)
      40                 :            : {
      41                 :      15336 :     return nFrom + (long) (fRelDist * (nTo - nFrom));
      42                 :            : }
      43                 :            : 
      44                 :            : 
      45                 :            : ////////////////////////////////////////
      46                 :            : // SmRect
      47                 :            : // ... (to be done)
      48                 :            : // This Implementation assumes that the x-axis points to the right and the
      49                 :            : // y-axis to the bottom.
      50                 :            : // Note: however, italic spaces can be negative!
      51                 :            : //
      52                 :            : 
      53                 :            : // possible flags for the 'Draw' function below (just for debugging)
      54                 :            : #define SM_RECT_CORE    0x0001
      55                 :            : #define SM_RECT_ITALIC  0x0002
      56                 :            : #define SM_RECT_LINES   0x0004
      57                 :            : #define SM_RECT_MID     0x0008
      58                 :            : 
      59                 :            : // possible positions and alignments for the 'AlignTo' function
      60                 :            : enum RectPos
      61                 :            :     // (RP_LEFT : align the current object to the left of the argument, ...)
      62                 :            : {   RP_LEFT, RP_RIGHT,
      63                 :            :     RP_TOP, RP_BOTTOM,
      64                 :            :     RP_ATTRIBUT
      65                 :            : };
      66                 :            : enum RectHorAlign
      67                 :            : {   RHA_LEFT, RHA_CENTER, RHA_RIGHT
      68                 :            : };
      69                 :            : enum RectVerAlign
      70                 :            : {   RVA_TOP, RVA_MID, RVA_BOTTOM, RVA_BASELINE, RVA_CENTERY,
      71                 :            :     RVA_ATTRIBUT_HI, RVA_ATTRIBUT_MID, RVA_ATTRIBUT_LO
      72                 :            : };
      73                 :            : 
      74                 :            : // different methods of copying baselines and mid's in 'ExtendBy' function
      75                 :            : enum RectCopyMBL
      76                 :            : {   RCP_THIS,   // keep baseline of current object even if it has none
      77                 :            :     RCP_ARG,    // as above but for the argument
      78                 :            :     RCP_NONE,   // result will have no baseline
      79                 :            :     RCP_XOR     // if current object has a baseline keep it else copy
      80                 :            :                 //   the arguments baseline (even if it has none)
      81                 :            : };
      82                 :            : 
      83                 :            : 
      84                 :            : class SmRect
      85                 :            : {
      86                 :            :     Point   aTopLeft;
      87                 :            :     Size    aSize;
      88                 :            :     long    nBaseline,
      89                 :            :             nAlignT,
      90                 :            :             nAlignM,
      91                 :            :             nAlignB,
      92                 :            :             nGlyphTop,
      93                 :            :             nGlyphBottom,
      94                 :            :             nItalicLeftSpace,
      95                 :            :             nItalicRightSpace,
      96                 :            :             nLoAttrFence,
      97                 :            :             nHiAttrFence;
      98                 :            :     sal_uInt16  nBorderWidth;
      99                 :            :     bool    bHasBaseline,
     100                 :            :             bHasAlignInfo;
     101                 :            : 
     102                 :            : protected:
     103                 :            :             void BuildRect (const OutputDevice &rDev, const SmFormat *pFormat,
     104                 :            :                             const rtl::OUString &rText, sal_uInt16 nBorderWidth);
     105                 :            :             void Init(const OutputDevice &rDev, const SmFormat *pFormat,
     106                 :            :                       const rtl::OUString &rText, sal_uInt16 nBorderWidth);
     107                 :            : 
     108                 :       1386 :             void ClearBaseline()    { bHasBaseline = false; };
     109                 :            :     inline  void CopyMBL(const SmRect& rRect);
     110                 :            :             void CopyAlignInfo(const SmRect& rRect);
     111                 :            : 
     112                 :            :             SmRect & Union(const SmRect &rRect);
     113                 :            : 
     114                 :            : public:
     115                 :            :             SmRect();
     116                 :            :             SmRect(const OutputDevice &rDev, const SmFormat *pFormat,
     117                 :            :                    const rtl::OUString &rText, long nBorderWidth);
     118                 :            :             SmRect(long nWidth, long nHeight);
     119                 :            :             SmRect(const SmRect &rRect);
     120                 :            : 
     121                 :            : 
     122                 :       1152 :             sal_uInt16  GetBorderWidth() const  { return nBorderWidth; }
     123                 :            : 
     124                 :            :             void SetItalicSpaces(long nLeftSpace, long nRightSpace);
     125                 :            : 
     126                 :         84 :             void SetWidth(sal_uLong nWidth)     { aSize.Width()  = nWidth; }
     127                 :            :             void SetHeight(sal_uLong nHeight)   { aSize.Height() = nHeight; }
     128                 :            : 
     129                 :            :             void SetLeft(long nLeft);
     130                 :            :             void SetRight(long nRight);
     131                 :            :             void SetBottom(long nBottom);
     132                 :            :             void SetTop(long nTop);
     133                 :            : 
     134                 :     823519 :             const Point & GetTopLeft() const { return aTopLeft; }
     135                 :            : 
     136                 :     267547 :             long GetTop()     const { return GetTopLeft().Y(); }
     137                 :     242986 :             long GetLeft()    const { return GetTopLeft().X(); }
     138                 :     107096 :             long GetBottom()  const { return GetTop() + GetHeight() - 1; }
     139                 :     123490 :             long GetRight()   const { return GetLeft() + GetWidth() - 1; }
     140                 :            :             long GetCenterX() const { return (GetLeft() + GetRight()) / 2L; }
     141                 :       3924 :             long GetCenterY() const { return (GetTop() + GetBottom()) / 2L; }
     142                 :     223570 :             long GetWidth()   const { return GetSize().Width(); }
     143                 :     142035 :             long GetHeight()  const { return GetSize().Height(); }
     144                 :            : 
     145                 :      55274 :             long GetItalicLeftSpace()  const { return nItalicLeftSpace; }
     146                 :      51935 :             long GetItalicRightSpace() const { return nItalicRightSpace; }
     147                 :            : 
     148                 :            :             void SetHiAttrFence(long nVal)  { nHiAttrFence = nVal; }
     149                 :            :             void SetLoAttrFence(long nVal)  { nLoAttrFence = nVal; }
     150                 :      27256 :             long GetHiAttrFence() const     { return nHiAttrFence; }
     151                 :      26856 :             long GetLoAttrFence() const     { return nLoAttrFence; }
     152                 :            : 
     153                 :      38998 :             long GetItalicLeft() const      { return GetLeft() - GetItalicLeftSpace(); }
     154                 :       7372 :             long GetItalicCenterX() const   { return (GetItalicLeft() + GetItalicRight()) / 2; }
     155                 :      43280 :             long GetItalicRight() const     { return GetRight() + GetItalicRightSpace(); }
     156                 :       7281 :             long GetItalicWidth() const     { return GetWidth() + GetItalicLeftSpace() + GetItalicRightSpace(); }
     157                 :            : 
     158                 :      21182 :             bool HasBaseline() const        { return bHasBaseline; }
     159                 :            :     inline  long GetBaseline() const;
     160                 :      62155 :             long GetBaselineOffset() const  { return GetBaseline() - GetTop(); }
     161                 :            : 
     162                 :            :             void SetAlignTop(long nVal) { nAlignT = nVal; }
     163                 :            : 
     164                 :      31540 :             long GetAlignT() const  { return nAlignT; }
     165                 :       4894 :             long GetAlignM() const  { return nAlignM; }
     166                 :      44878 :             long GetAlignB() const  { return nAlignB; }
     167                 :            : 
     168                 :            :             void SetAlignT(long nVal) { nAlignT = nVal; }
     169                 :            : 
     170                 :            :             const Point  GetCenter() const
     171                 :            :             {   return Point(GetCenterX(), GetCenterY()); }
     172                 :            : 
     173                 :     367510 :             const Size & GetSize() const    { return aSize; }
     174                 :            : 
     175                 :       3087 :             const Size  GetItalicSize() const
     176                 :       3087 :             {   return Size(GetItalicWidth(), GetHeight()); }
     177                 :            : 
     178                 :            :             void Move  (const Point &rPosition);
     179         [ +  - ]:        846 :             void MoveTo(const Point &rPosition) { Move(rPosition - GetTopLeft()); }
     180                 :            : 
     181                 :      26798 :             bool IsEmpty() const
     182                 :            :             {
     183 [ +  + ][ -  + ]:      26798 :                 return GetWidth() == 0  ||  GetHeight() == 0;
     184                 :            :             }
     185                 :            : 
     186                 :      29074 :             bool HasAlignInfo() const { return bHasAlignInfo; }
     187                 :            : 
     188                 :            :             const Point AlignTo(const SmRect &rRect, RectPos ePos,
     189                 :            :                                 RectHorAlign eHor, RectVerAlign eVer) const;
     190                 :            : 
     191                 :            :             SmRect & ExtendBy(const SmRect &rRect, RectCopyMBL eCopyMode);
     192                 :            :             SmRect & ExtendBy(const SmRect &rRect, RectCopyMBL eCopyMode,
     193                 :            :                               long nNewAlignM);
     194                 :            :             SmRect & ExtendBy(const SmRect &rRect, RectCopyMBL eCopyMode,
     195                 :            :                       bool bKeepVerAlignParams);
     196                 :            : 
     197                 :            :             long    OrientedDist(const Point &rPoint) const;
     198                 :            :             bool    IsInsideRect(const Point &rPoint) const;
     199                 :            :             bool    IsInsideItalicRect(const Point &rPoint) const;
     200                 :            : 
     201                 :            :     inline  SmRect & operator = (const SmRect &rRect);
     202                 :            : 
     203                 :            :     inline  Rectangle   AsRectangle() const;
     204                 :            :             SmRect      AsGlyphRect() const;
     205                 :            : };
     206                 :            : 
     207                 :            : 
     208                 :      13692 : inline void SmRect::SetItalicSpaces(long nLeftSpace, long nRightSpace)
     209                 :            :     // set extra spacing to the left and right for (italic)
     210                 :            :     // letters/text
     211                 :            : {
     212                 :      13692 :     nItalicLeftSpace  = nLeftSpace;
     213                 :      13692 :     nItalicRightSpace = nRightSpace;
     214                 :      13692 : }
     215                 :            : 
     216                 :            : 
     217                 :       1706 : inline void SmRect::CopyMBL(const SmRect &rRect)
     218                 :            :     // copy AlignM baseline and value of 'rRect'
     219                 :            : {
     220                 :       1706 :     nBaseline    = rRect.nBaseline;
     221                 :       1706 :     bHasBaseline = rRect.bHasBaseline;
     222                 :       1706 :     nAlignM      = rRect.nAlignM;
     223                 :       1706 : }
     224                 :            : 
     225                 :            : 
     226                 :      75729 : inline long SmRect::GetBaseline() const
     227                 :            : {
     228                 :            :     OSL_ENSURE(HasBaseline(), "Sm: Baseline nicht vorhanden");
     229                 :      75729 :     return nBaseline;
     230                 :            : }
     231                 :            : 
     232                 :            : 
     233                 :      28792 : inline SmRect & SmRect::operator = (const SmRect &rRect)
     234                 :            : {
     235 [ +  - ][ +  - ]:      28792 :     new (this) SmRect(rRect);   // placement new
     236                 :      28792 :     return *this;
     237                 :            : }
     238                 :            : 
     239                 :            : 
     240                 :       3072 : inline Rectangle SmRect::AsRectangle() const
     241                 :            : {
     242         [ +  - ]:       3072 :     return Rectangle(Point(GetItalicLeft(), GetTop()), GetItalicSize());
     243                 :            : }
     244                 :            : 
     245                 :            : #endif
     246                 :            : 
     247                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10