LCOV - code coverage report
Current view: top level - starmath/inc - rect.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 49 49 100.0 %
Date: 2014-11-03 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 <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 OUString &rText, Rectangle &rRect);
      35             : 
      36             : bool SmIsMathAlpha(const OUString &rText);
      37             : 
      38             : 
      39       18878 : inline long SmFromTo(long nFrom, long nTo, double fRelDist)
      40             : {
      41       18878 :     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 OUString &rText, sal_uInt16 nBorderWidth);
     105             :             void Init(const OutputDevice &rDev, const SmFormat *pFormat,
     106             :                       const OUString &rText, sal_uInt16 nBorderWidth);
     107             : 
     108        1468 :             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 OUString &rText, long nBorderWidth);
     118             :             SmRect(long nWidth, long nHeight);
     119             :             SmRect(const SmRect &rRect);
     120             : 
     121             : 
     122        1768 :             sal_uInt16  GetBorderWidth() const  { return nBorderWidth; }
     123             : 
     124             :             void SetItalicSpaces(long nLeftSpace, long nRightSpace);
     125             : 
     126         422 :             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      906377 :             const Point & GetTopLeft() const { return aTopLeft; }
     135             : 
     136      326195 :             long GetTop()     const { return GetTopLeft().Y(); }
     137      292177 :             long GetLeft()    const { return GetTopLeft().X(); }
     138      132736 :             long GetBottom()  const { return GetTop() + GetHeight() - 1; }
     139      148620 :             long GetRight()   const { return GetLeft() + GetWidth() - 1; }
     140             :             long GetCenterX() const { return (GetLeft() + GetRight()) / 2L; }
     141        4170 :             long GetCenterY() const { return (GetTop() + GetBottom()) / 2L; }
     142      266539 :             long GetWidth()   const { return GetSize().Width(); }
     143      174669 :             long GetHeight()  const { return GetSize().Height(); }
     144             : 
     145       64008 :             long GetItalicLeftSpace()  const { return nItalicLeftSpace; }
     146       60903 :             long GetItalicRightSpace() const { return nItalicRightSpace; }
     147             : 
     148             :             void SetHiAttrFence(long nVal)  { nHiAttrFence = nVal; }
     149             :             void SetLoAttrFence(long nVal)  { nLoAttrFence = nVal; }
     150       32340 :             long GetHiAttrFence() const     { return nHiAttrFence; }
     151       31940 :             long GetLoAttrFence() const     { return nLoAttrFence; }
     152             : 
     153       46017 :             long GetItalicLeft() const      { return GetLeft() - GetItalicLeftSpace(); }
     154        8916 :             long GetItalicCenterX() const   { return (GetItalicLeft() + GetItalicRight()) / 2; }
     155       51384 :             long GetItalicRight() const     { return GetRight() + GetItalicRightSpace(); }
     156        7711 :             long GetItalicWidth() const     { return GetWidth() + GetItalicLeftSpace() + GetItalicRightSpace(); }
     157             : 
     158       25212 :             bool HasBaseline() const        { return bHasBaseline; }
     159             :     inline  long GetBaseline() const;
     160       71920 :             long GetBaselineOffset() const  { return GetBaseline() - GetTop(); }
     161             : 
     162             :             void SetAlignTop(long nVal) { nAlignT = nVal; }
     163             : 
     164       37706 :             long GetAlignT() const  { return nAlignT; }
     165        5446 :             long GetAlignM() const  { return nAlignM; }
     166       54396 :             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      443902 :             const Size & GetSize() const    { return aSize; }
     174             : 
     175        2847 :             const Size  GetItalicSize() const
     176        2847 :             {   return Size(GetItalicWidth(), GetHeight()); }
     177             : 
     178             :             void Move  (const Point &rPosition);
     179         918 :             void MoveTo(const Point &rPosition) { Move(rPosition - GetTopLeft()); }
     180             : 
     181       32174 :             bool IsEmpty() const
     182             :             {
     183       32174 :                 return GetWidth() == 0  ||  GetHeight() == 0;
     184             :             }
     185             : 
     186       34670 :             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       16596 : inline void SmRect::SetItalicSpaces(long nLeftSpace, long nRightSpace)
     209             :     // set extra spacing to the left and right for (italic)
     210             :     // letters/text
     211             : {
     212       16596 :     nItalicLeftSpace  = nLeftSpace;
     213       16596 :     nItalicRightSpace = nRightSpace;
     214       16596 : }
     215             : 
     216             : 
     217        2424 : inline void SmRect::CopyMBL(const SmRect &rRect)
     218             :     // copy AlignM baseline and value of 'rRect'
     219             : {
     220        2424 :     nBaseline    = rRect.nBaseline;
     221        2424 :     bHasBaseline = rRect.bHasBaseline;
     222        2424 :     nAlignM      = rRect.nAlignM;
     223        2424 : }
     224             : 
     225             : 
     226       88492 : inline long SmRect::GetBaseline() const
     227             : {
     228             :     SAL_WARN_IF( !HasBaseline(), "starmath", "Baseline does not exist" );
     229       88492 :     return nBaseline;
     230             : }
     231             : 
     232             : 
     233       28772 : inline SmRect & SmRect::operator = (const SmRect &rRect)
     234             : {
     235       28772 :     new (this) SmRect(rRect);   // placement new
     236       28772 :     return *this;
     237             : }
     238             : 
     239             : 
     240        2839 : inline Rectangle SmRect::AsRectangle() const
     241             : {
     242        2839 :     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