LCOV - code coverage report
Current view: top level - starmath/inc - rect.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 49 49 100.0 %
Date: 2015-06-13 12:38:46 Functions: 35 35 100.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             :  * 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 INCLUDED_STARMATH_INC_RECT_HXX
      21             : #define INCLUDED_STARMATH_INC_RECT_HXX
      22             : 
      23             : #include <new>
      24             : 
      25             : #include <rtl/ustring.hxx>
      26             : #include <sal/log.hxx>
      27             : #include <tools/gen.hxx>
      28             : #include <vcl/outdev.hxx>
      29             : #include <vcl/metric.hxx>
      30             : 
      31             : #include "format.hxx"
      32             : 
      33             : 
      34             : bool SmGetGlyphBoundRect(const OutputDevice &rDev,
      35             :                          const OUString &rText, Rectangle &rRect);
      36             : 
      37             : bool SmIsMathAlpha(const OUString &rText);
      38             : 
      39             : 
      40        9600 : inline long SmFromTo(long nFrom, long nTo, double fRelDist)
      41             : {
      42        9600 :     return nFrom + (long) (fRelDist * (nTo - nFrom));
      43             : }
      44             : 
      45             : 
      46             : 
      47             : // SmRect
      48             : // ... (to be done)
      49             : // This Implementation assumes that the x-axis points to the right and the
      50             : // y-axis to the bottom.
      51             : // Note: however, italic spaces can be negative!
      52             : 
      53             : 
      54             : // possible positions and alignments for the 'AlignTo' function
      55             : enum RectPos
      56             :     // (RP_LEFT : align the current object to the left of the argument, ...)
      57             : {   RP_LEFT, RP_RIGHT,
      58             :     RP_TOP, RP_BOTTOM,
      59             :     RP_ATTRIBUT
      60             : };
      61             : enum RectHorAlign
      62             : {   RHA_LEFT, RHA_CENTER, RHA_RIGHT
      63             : };
      64             : enum RectVerAlign
      65             : {   RVA_TOP, RVA_MID, RVA_BOTTOM, RVA_BASELINE, RVA_CENTERY,
      66             :     RVA_ATTRIBUT_HI, RVA_ATTRIBUT_MID, RVA_ATTRIBUT_LO
      67             : };
      68             : 
      69             : // different methods of copying baselines and mid's in 'ExtendBy' function
      70             : enum RectCopyMBL
      71             : {   RCP_THIS,   // keep baseline of current object even if it has none
      72             :     RCP_ARG,    // as above but for the argument
      73             :     RCP_NONE,   // result will have no baseline
      74             :     RCP_XOR     // if current object has a baseline keep it else copy
      75             :                 //   the arguments baseline (even if it has none)
      76             : };
      77             : 
      78             : 
      79             : class SmRect
      80             : {
      81             :     Point   aTopLeft;
      82             :     Size    aSize;
      83             :     long    nBaseline,
      84             :             nAlignT,
      85             :             nAlignM,
      86             :             nAlignB,
      87             :             nGlyphTop,
      88             :             nGlyphBottom,
      89             :             nItalicLeftSpace,
      90             :             nItalicRightSpace,
      91             :             nLoAttrFence,
      92             :             nHiAttrFence;
      93             :     sal_uInt16  nBorderWidth;
      94             :     bool    bHasBaseline,
      95             :             bHasAlignInfo;
      96             : 
      97             : protected:
      98             :             void BuildRect (const OutputDevice &rDev, const SmFormat *pFormat,
      99             :                             const OUString &rText, sal_uInt16 nBorderWidth);
     100             :             void Init(const OutputDevice &rDev, const SmFormat *pFormat,
     101             :                       const OUString &rText, sal_uInt16 nBorderWidth);
     102             : 
     103         757 :             void ClearBaseline()    { bHasBaseline = false; };
     104             :     inline  void CopyMBL(const SmRect& rRect);
     105             :             void CopyAlignInfo(const SmRect& rRect);
     106             : 
     107             :             SmRect & Union(const SmRect &rRect);
     108             : 
     109             : public:
     110             :             SmRect();
     111             :             SmRect(const OutputDevice &rDev, const SmFormat *pFormat,
     112             :                    const OUString &rText, long nBorderWidth);
     113             :             SmRect(long nWidth, long nHeight);
     114             :             SmRect(const SmRect &rRect);
     115             : 
     116             : 
     117         884 :             sal_uInt16  GetBorderWidth() const  { return nBorderWidth; }
     118             : 
     119             :             void SetItalicSpaces(long nLeftSpace, long nRightSpace);
     120             : 
     121         223 :             void SetWidth(sal_uLong nWidth)     { aSize.Width()  = nWidth; }
     122             :             void SetHeight(sal_uLong nHeight)   { aSize.Height() = nHeight; }
     123             : 
     124             :             void SetLeft(long nLeft);
     125             :             void SetRight(long nRight);
     126             :             void SetBottom(long nBottom);
     127             :             void SetTop(long nTop);
     128             : 
     129      462638 :             const Point & GetTopLeft() const { return aTopLeft; }
     130             : 
     131      166636 :             long GetTop()     const { return GetTopLeft().Y(); }
     132      148801 :             long GetLeft()    const { return GetTopLeft().X(); }
     133       67567 :             long GetBottom()  const { return GetTop() + GetHeight() - 1; }
     134       75688 :             long GetRight()   const { return GetLeft() + GetWidth() - 1; }
     135             :             long GetCenterX() const { return (GetLeft() + GetRight()) / 2L; }
     136        2109 :             long GetCenterY() const { return (GetTop() + GetBottom()) / 2L; }
     137      136742 :             long GetWidth()   const { return GetSize().Width(); }
     138       89361 :             long GetHeight()  const { return GetSize().Height(); }
     139             : 
     140       32627 :             long GetItalicLeftSpace()  const { return nItalicLeftSpace; }
     141       31039 :             long GetItalicRightSpace() const { return nItalicRightSpace; }
     142             : 
     143             :             void SetHiAttrFence(long nVal)  { nHiAttrFence = nVal; }
     144             :             void SetLoAttrFence(long nVal)  { nLoAttrFence = nVal; }
     145       16450 :             long GetHiAttrFence() const     { return nHiAttrFence; }
     146       16250 :             long GetLoAttrFence() const     { return nLoAttrFence; }
     147             : 
     148       23448 :             long GetItalicLeft() const      { return GetLeft() - GetItalicLeftSpace(); }
     149        4566 :             long GetItalicCenterX() const   { return (GetItalicLeft() + GetItalicRight()) / 2; }
     150       26189 :             long GetItalicRight() const     { return GetRight() + GetItalicRightSpace(); }
     151        3942 :             long GetItalicWidth() const     { return GetWidth() + GetItalicLeftSpace() + GetItalicRightSpace(); }
     152             : 
     153       12876 :             bool HasBaseline() const        { return bHasBaseline; }
     154             :     inline  long GetBaseline() const;
     155       37174 :             long GetBaselineOffset() const  { return GetBaseline() - GetTop(); }
     156             : 
     157             :             void SetAlignTop(long nVal) { nAlignT = nVal; }
     158             : 
     159       19149 :             long GetAlignT() const  { return nAlignT; }
     160        2759 :             long GetAlignM() const  { return nAlignM; }
     161       27643 :             long GetAlignB() const  { return nAlignB; }
     162             : 
     163             :             void SetAlignT(long nVal) { nAlignT = nVal; }
     164             : 
     165             :             const Point  GetCenter() const
     166             :             {   return Point(GetCenterX(), GetCenterY()); }
     167             : 
     168      227476 :             const Size & GetSize() const    { return aSize; }
     169             : 
     170        1459 :             const Size  GetItalicSize() const
     171        1459 :             {   return Size(GetItalicWidth(), GetHeight()); }
     172             : 
     173             :             void Move  (const Point &rPosition);
     174         463 :             void MoveTo(const Point &rPosition) { Move(rPosition - GetTopLeft()); }
     175             : 
     176       16383 :             bool IsEmpty() const
     177             :             {
     178       16383 :                 return GetWidth() == 0  ||  GetHeight() == 0;
     179             :             }
     180             : 
     181       17627 :             bool HasAlignInfo() const { return bHasAlignInfo; }
     182             : 
     183             :             const Point AlignTo(const SmRect &rRect, RectPos ePos,
     184             :                                 RectHorAlign eHor, RectVerAlign eVer) const;
     185             : 
     186             :             SmRect & ExtendBy(const SmRect &rRect, RectCopyMBL eCopyMode);
     187             :             SmRect & ExtendBy(const SmRect &rRect, RectCopyMBL eCopyMode,
     188             :                               long nNewAlignM);
     189             :             SmRect & ExtendBy(const SmRect &rRect, RectCopyMBL eCopyMode,
     190             :                       bool bKeepVerAlignParams);
     191             : 
     192             :             long    OrientedDist(const Point &rPoint) const;
     193             :             bool    IsInsideRect(const Point &rPoint) const;
     194             :             bool    IsInsideItalicRect(const Point &rPoint) const;
     195             : 
     196             :     inline  SmRect & operator = (const SmRect &rRect);
     197             : 
     198             :     inline  Rectangle   AsRectangle() const;
     199             :             SmRect      AsGlyphRect() const;
     200             : };
     201             : 
     202             : 
     203        8458 : inline void SmRect::SetItalicSpaces(long nLeftSpace, long nRightSpace)
     204             :     // set extra spacing to the left and right for (italic)
     205             :     // letters/text
     206             : {
     207        8458 :     nItalicLeftSpace  = nLeftSpace;
     208        8458 :     nItalicRightSpace = nRightSpace;
     209        8458 : }
     210             : 
     211             : 
     212        1238 : inline void SmRect::CopyMBL(const SmRect &rRect)
     213             :     // copy AlignM baseline and value of 'rRect'
     214             : {
     215        1238 :     nBaseline    = rRect.nBaseline;
     216        1238 :     bHasBaseline = rRect.bHasBaseline;
     217        1238 :     nAlignM      = rRect.nAlignM;
     218        1238 : }
     219             : 
     220             : 
     221       45633 : inline long SmRect::GetBaseline() const
     222             : {
     223             :     SAL_WARN_IF( !HasBaseline(), "starmath", "Baseline does not exist" );
     224       45633 :     return nBaseline;
     225             : }
     226             : 
     227             : 
     228       14696 : inline SmRect & SmRect::operator = (const SmRect &rRect)
     229             : {
     230       14696 :     new (this) SmRect(rRect);   // placement new
     231       14696 :     return *this;
     232             : }
     233             : 
     234             : 
     235        1451 : inline Rectangle SmRect::AsRectangle() const
     236             : {
     237        1451 :     return Rectangle(Point(GetItalicLeft(), GetTop()), GetItalicSize());
     238             : }
     239             : 
     240             : #endif
     241             : 
     242             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11