[Libreoffice-commits] core.git: Branch 'feature/borderline3' - include/svx svx/source
Armin Le Grand
Armin.Le.Grand at cib.de
Thu Aug 17 18:23:25 UTC 2017
include/svx/framelink.hxx | 107 +----------------------------------
include/svx/framelinkarray.hxx | 10 ---
svx/source/dialog/framelink.cxx | 34 ++---------
svx/source/dialog/framelinkarray.cxx | 89 +++++------------------------
svx/source/dialog/frmsel.cxx | 9 +-
5 files changed, 34 insertions(+), 215 deletions(-)
New commits:
commit 3e36255a53db5264eaa212edbc81015f465dbaee
Author: Armin Le Grand <Armin.Le.Grand at cib.de>
Date: Thu Aug 17 20:19:46 2017 +0200
borderline: Cleanup of DiagStyle and others
DiagStyle is not needed anymore due to no longer
using angles calculated, but being based on vectors
defining the geometry. Also cleaned up quite a bit
of no longer needed calculation stuff for the control
Change-Id: I10f2702416eea68b9e1541c6ae153d1f6094970b
diff --git a/include/svx/framelink.hxx b/include/svx/framelink.hxx
index f79b5ed84301..ce4ff50e8524 100644
--- a/include/svx/framelink.hxx
+++ b/include/svx/framelink.hxx
@@ -187,107 +187,8 @@ SVX_DLLPUBLIC bool operator<( const Style& rL, const Style& rR );
inline bool operator>( const Style& rL, const Style& rR ) { return rR < rL; }
inline bool operator<=( const Style& rL, const Style& rR ) { return !(rR < rL); }
-
-/** Extends the Style struct with an angle for diagonal frame borders.
-
- The angle is specified in radian (a full circle is equivalent to 2*PI).
- It is dependent on the context, how the value is interpreted, i.e. it may
- specify the angle to a horizontal or vertical frame border.
- */
-class SAL_WARN_UNUSED DiagStyle : public Style
-{
-public:
- /** Constructs an invisible diagonal frame style. */
- explicit DiagStyle() : mfAngle( 0.0 ) {}
- /** Constructs a diagonal frame style passed style and angle. */
- explicit DiagStyle( const Style& rStyle, double fAngle ) :
- Style( rStyle ), mfAngle( fAngle ) {}
-
- double GetAngle() const { return mfAngle; }
-
- /** Returns this style mirrored, if it is a double frame style, otherwise a simple copy. */
- DiagStyle Mirror() const { return DiagStyle( Style::Mirror(), mfAngle ); }
-
-private:
- double mfAngle; /// Angle between this and hor. or vert. border.
-};
-
-
// Various helper functions
-
-/** Returns the angle between horizontal border of a rectangle and its diagonal.
-
- The returned values represents the inner angle between the diagonals and
- horizontal borders, and is therefore in the range [0,PI/2] (inclusive). The
- passed sizes may be negative, calculation is done with absolute values.
- */
-SVX_DLLPUBLIC double GetHorDiagAngle( long nWidth, long nHeight );
-
-/** Returns the angle between horizontal border of a rectangle and its diagonal.
-
- The returned values represents the inner angle between the diagonals and
- horizontal borders, and is therefore in the range [0,PI/2] (inclusive).
- */
-inline double GetHorDiagAngle( const tools::Rectangle& rRect )
-{ return GetHorDiagAngle( rRect.GetWidth(), rRect.GetHeight() ); }
-
-
-/** Returns the angle between vertical border of a rectangle and its diagonal.
-
- The returned values represents the inner angle between the diagonals and
- vertical borders, and is therefore in the range [0,PI/2] (inclusive). The
- passed sizes may be negative, calculation is done with absolute values.
- */
-inline double GetVerDiagAngle( long nWidth, long nHeight )
-{ return GetHorDiagAngle( nHeight, nWidth ); }
-
-/** Returns the angle between vertical border of a rectangle and its diagonal.
-
- The returned values represents the inner angle between the diagonals and
- vertical borders, and is therefore in the range [0,PI/2] (inclusive).
- */
-inline double GetVerDiagAngle( const tools::Rectangle& rRect )
-{ return GetVerDiagAngle( rRect.GetWidth(), rRect.GetHeight() ); }
-
-
-/** Returns an X coordinate for a diagonal frame border in the specified height.
-
- This function is for usage with the top-left end of a top-left to
- bottom-right diagonal frame border, connected to the left end of a
- horizontal frame border.
-
- The function returns the relative X position (i.e. for a polygon) of the
- diagonal frame border according to the specified relative Y position. The
- mentioned positions are relative to the reference point of both frame
- borders.
-
- +----------------------------------------------------------
- | The horizontal frame border.
- | |
- - - - - - - | --+-- <---- Reference point for horizontal and diagonal frame borders.
- ^ | \ | \
- nVerOffs | \ \ <--- The diagonal frame border.
- v +---\ \------------------------------------------------
- - - - - - - - - -\- - -X <----- The function calculates the X position of i.e.
- \ \ this point (relative from X of reference point).
- \ \
- Primary -->\ \<-- Secondary
-
- @param nVerOffs
- The vertical position of the point to be calculated, relative to the Y
- coordinate of the reference point.
- @param nDiagOffs
- The width offset across the diagonal frame border (0 = middle),
- regardless of the gradient of the diagonal frame border (always
- vertical to the direction of the diagonal frame border). This value is
- not related in any way to the reference point. For details about
- relative width offsets, see description of class Style.
- @param fAngle
- Inner (right) angle between diagonal and horizontal frame border.
- */
-SVX_DLLPUBLIC long GetTLDiagOffset( long nVerOffs, long nDiagOffs, double fAngle );
-
/** Checks whether two horizontal frame borders are "connectable".
Two borders are "connectable" in terms of this function, if both can be
@@ -377,17 +278,17 @@ SVX_DLLPUBLIC void CreateBorderPrimitives(
const Style& rBorder, /// Style of the processed frame border.
- const DiagStyle& rLFromTR, /// Diagonal frame border from top-right to left end of rBorder.
+ const Style& rLFromTR, /// Diagonal frame border from top-right to left end of rBorder.
const Style& rLFromT, /// Vertical frame border from top to left end of rBorder.
const Style& rLFromL, /// Horizontal frame border from left to left end of rBorder.
const Style& rLFromB, /// Vertical frame border from bottom to left end of rBorder.
- const DiagStyle& rLFromBR, /// Diagonal frame border from bottom-right to left end of rBorder.
+ const Style& rLFromBR, /// Diagonal frame border from bottom-right to left end of rBorder.
- const DiagStyle& rRFromTL, /// Diagonal frame border from top-left to right end of rBorder.
+ const Style& rRFromTL, /// Diagonal frame border from top-left to right end of rBorder.
const Style& rRFromT, /// Vertical frame border from top to right end of rBorder.
const Style& rRFromR, /// Horizontal frame border from right to right end of rBorder.
const Style& rRFromB, /// Vertical frame border from bottom to right end of rBorder.
- const DiagStyle& rRFromBL, /// Diagonal frame border from bottom-left to right end of rBorder.
+ const Style& rRFromBL, /// Diagonal frame border from bottom-left to right end of rBorder.
const Color* pForceColor /// If specified, overrides frame border color.
);
diff --git a/include/svx/framelinkarray.hxx b/include/svx/framelinkarray.hxx
index 15d8dcf1d9cf..ade65c111dca 100644
--- a/include/svx/framelinkarray.hxx
+++ b/include/svx/framelinkarray.hxx
@@ -307,16 +307,6 @@ public:
Returns total output rectangle of merged ranges. */
tools::Rectangle GetCellRect( size_t nCol, size_t nRow ) const;
- // diagonal frame borders -------------------------------------------------
-
- /** Returns the angle between horizontal and diagonal border of the cell (nCol,nRow).
- Returns the horizontal angle of merged ranges. */
- double GetHorDiagAngle( size_t nCol, size_t nRow ) const;
-
- /** Returns the angle between vertical and diagonal border of the cell (nCol,nRow).
- Returns the vertical angle of merged ranges. */
- double GetVerDiagAngle( size_t nCol, size_t nRow ) const;
-
// mirroring --------------------------------------------------------------
/** Mirrors the entire array horizontally. */
diff --git a/svx/source/dialog/framelink.cxx b/svx/source/dialog/framelink.cxx
index 4a30caad6b6d..41cc29c7973f 100644
--- a/svx/source/dialog/framelink.cxx
+++ b/svx/source/dialog/framelink.cxx
@@ -44,12 +44,6 @@ namespace frame {
namespace {
-/** Rounds and casts a double value to a long value. */
-inline long lclD2L( double fValue )
-{
- return static_cast< long >( (fValue < 0.0) ? (fValue - 0.5) : (fValue + 0.5) );
-}
-
/** Converts a width in twips to a width in another map unit (specified by fScale). */
double lclScaleValue( double nValue, double fScale, sal_uInt16 nMaxWidth )
{
@@ -241,18 +235,6 @@ bool operator<( const Style& rL, const Style& rR )
#undef SCALEVALUE
-
-// Various helper functions
-double GetHorDiagAngle( long nWidth, long nHeight )
-{
- return atan2( static_cast< double >( std::abs( nHeight ) ), static_cast< double >( std::abs( nWidth ) ) );
-}
-
-long GetTLDiagOffset( long nVerOffs, long nDiagOffs, double fAngle )
-{
- return lclD2L( nVerOffs / tan( fAngle ) + nDiagOffs / sin( fAngle ) );
-}
-
bool CheckFrameBorderConnectable( const Style& rLBorder, const Style& rRBorder,
const Style& rTFromTL, const Style& rTFromT, const Style& rTFromTR,
const Style& rBFromBL, const Style& rBFromB, const Style& rBFromBR )
@@ -511,16 +493,16 @@ void CreateBorderPrimitives(
const basegfx::B2DVector& rX,
const basegfx::B2DVector& rY,
const Style& rBorder,
- const DiagStyle& /*rLFromTR*/,
+ const Style& /*rLFromTR*/,
const Style& rLFromT,
const Style& /*rLFromL*/,
const Style& rLFromB,
- const DiagStyle& /*rLFromBR*/,
- const DiagStyle& /*rRFromTL*/,
+ const Style& /*rLFromBR*/,
+ const Style& /*rRFromTL*/,
const Style& rRFromT,
const Style& /*rRFromR*/,
const Style& rRFromB,
- const DiagStyle& /*rRFromBL*/,
+ const Style& /*rRFromBL*/,
const Color* pForceColor)
{
if (rBorder.Prim())
@@ -670,16 +652,16 @@ void CreateBorderPrimitives(
rX,
rY,
rBorder,
- DiagStyle(),
+ Style(),
rLFromT,
rLFromL,
rLFromB,
- DiagStyle(),
- DiagStyle(),
+ Style(),
+ Style(),
rRFromT,
rRFromR,
rRFromB,
- DiagStyle(),
+ Style(),
pForceColor);
}
}
diff --git a/svx/source/dialog/framelinkarray.cxx b/svx/source/dialog/framelinkarray.cxx
index 5c87cf33943b..011bf304fbda 100644
--- a/svx/source/dialog/framelinkarray.cxx
+++ b/svx/source/dialog/framelinkarray.cxx
@@ -183,9 +183,6 @@ struct ArrayImpl
long GetColWidth( size_t nFirstCol, size_t nLastCol ) const;
long GetRowHeight( size_t nFirstRow, size_t nLastRow ) const;
- double GetHorDiagAngle( size_t nCol, size_t nRow ) const;
- double GetVerDiagAngle( size_t nCol, size_t nRow ) const;
-
bool HasCellRotation() const;
};
@@ -319,35 +316,6 @@ long ArrayImpl::GetRowHeight( size_t nFirstRow, size_t nLastRow ) const
return GetRowPosition( nLastRow + 1 ) - GetRowPosition( nFirstRow );
}
-double ArrayImpl::GetHorDiagAngle( size_t nCol, size_t nRow ) const
-{
- double fAngle = 0.0;
- if( IsValidPos( nCol, nRow ) )
- {
- if( !GetCell( nCol, nRow ).IsMerged() )
- {
- fAngle = frame::GetHorDiagAngle( maWidths[ nCol ] + 1, maHeights[ nRow ] + 1 );
- }
- else
- {
- // return correct angle for each cell in the merged range
- size_t nFirstCol = GetMergedFirstCol( nCol, nRow );
- size_t nFirstRow = GetMergedFirstRow( nCol, nRow );
- const Cell& rCell = GetCell( nFirstCol, nFirstRow );
- long nWidth = GetColWidth( nFirstCol, GetMergedLastCol( nCol, nRow ) ) + rCell.mnAddLeft + rCell.mnAddRight;
- long nHeight = GetRowHeight( nFirstRow, GetMergedLastRow( nCol, nRow ) ) + rCell.mnAddTop + rCell.mnAddBottom;
- fAngle = frame::GetHorDiagAngle( nWidth + 1, nHeight + 1 );
- }
- }
- return fAngle;
-}
-
-double ArrayImpl::GetVerDiagAngle( size_t nCol, size_t nRow ) const
-{
- double fAngle = GetHorDiagAngle( nCol, nRow );
- return (fAngle > 0.0) ? (F_PI2 - fAngle) : 0.0;
-}
-
bool ArrayImpl::HasCellRotation() const
{
// check cell array
@@ -884,19 +852,6 @@ tools::Rectangle Array::GetCellRect( size_t nCol, size_t nRow ) const
return aRect;
}
-// diagonal frame borders
-double Array::GetHorDiagAngle( size_t nCol, size_t nRow ) const
-{
- DBG_FRAME_CHECK_COLROW( nCol, nRow, "GetHorDiagAngle" );
- return mxImpl->GetHorDiagAngle( nCol, nRow );
-}
-
-double Array::GetVerDiagAngle( size_t nCol, size_t nRow ) const
-{
- DBG_FRAME_CHECK_COLROW( nCol, nRow, "GetVerDiagAngle" );
- return mxImpl->GetVerDiagAngle( nCol, nRow );
-}
-
// mirroring
void Array::MirrorSelfX()
{
@@ -1043,43 +998,37 @@ void Array::DrawRange( drawinglayer::processor2d::BaseProcessor2D& rProcessor,
// *** horizontal frame borders ***
for( nRow = nFirstRow; nRow <= nLastRow + 1; ++nRow )
{
- double fAngle = mxImpl->GetHorDiagAngle( nFirstCol, nRow );
- double fTAngle = mxImpl->GetHorDiagAngle( nFirstCol, nRow - 1 );
-
// *Start*** variables store the data of the left end of the cached frame border
basegfx::B2DPoint aStartPos( mxImpl->GetColPosition( nFirstCol ), mxImpl->GetRowPosition( nRow ) );
const Style* pStart = &GetCellStyleTop( nFirstCol, nRow );
- DiagStyle aStartLFromTR( GetCellStyleBL( nFirstCol, nRow - 1 ), fTAngle );
+ Style aStartLFromTR( GetCellStyleBL( nFirstCol, nRow - 1 ));
const Style* pStartLFromT = &GetCellStyleLeft( nFirstCol, nRow - 1 );
const Style* pStartLFromL = &GetCellStyleTop( nFirstCol - 1, nRow );
const Style* pStartLFromB = &GetCellStyleLeft( nFirstCol, nRow );
- DiagStyle aStartLFromBR( GetCellStyleTL( nFirstCol, nRow ), fAngle );
+ Style aStartLFromBR( GetCellStyleTL( nFirstCol, nRow ));
// *End*** variables store the data of the right end of the cached frame border
- DiagStyle aEndRFromTL( GetCellStyleBR( nFirstCol, nRow - 1 ), fTAngle );
+ Style aEndRFromTL( GetCellStyleBR( nFirstCol, nRow - 1 ));
const Style* pEndRFromT = &GetCellStyleRight( nFirstCol, nRow - 1 );
const Style* pEndRFromR = &GetCellStyleTop( nFirstCol + 1, nRow );
const Style* pEndRFromB = &GetCellStyleRight( nFirstCol, nRow );
- DiagStyle aEndRFromBL( GetCellStyleTR( nFirstCol, nRow ), fAngle );
+ Style aEndRFromBL( GetCellStyleTR( nFirstCol, nRow ));
for( nCol = nFirstCol + 1; nCol <= nLastCol; ++nCol )
{
- fAngle = mxImpl->GetHorDiagAngle( nCol, nRow );
- fTAngle = mxImpl->GetHorDiagAngle( nCol, nRow - 1 );
-
const Style& rCurr = *pEndRFromR;
- DiagStyle aLFromTR( GetCellStyleBL( nCol, nRow - 1 ), fTAngle );
+ Style aLFromTR( GetCellStyleBL( nCol, nRow - 1 ));
const Style& rLFromT = *pEndRFromT;
const Style& rLFromL = *pStart;
const Style& rLFromB = *pEndRFromB;
- DiagStyle aLFromBR( GetCellStyleTL( nCol, nRow ), fAngle );
+ Style aLFromBR( GetCellStyleTL( nCol, nRow ));
- DiagStyle aRFromTL( GetCellStyleBR( nCol, nRow - 1 ), fTAngle );
+ Style aRFromTL( GetCellStyleBR( nCol, nRow - 1 ));
const Style& rRFromT = GetCellStyleRight( nCol, nRow - 1 );
const Style& rRFromR = GetCellStyleTop( nCol + 1, nRow );
const Style& rRFromB = GetCellStyleRight( nCol, nRow );
- DiagStyle aRFromBL( GetCellStyleTR( nCol, nRow ), fAngle );
+ Style aRFromBL( GetCellStyleTR( nCol, nRow ));
// check if current frame border can be connected to cached frame border
if( !CheckFrameBorderConnectable( *pStart, rCurr, aEndRFromTL, rLFromT, aLFromTR, aEndRFromBL, rLFromB, aLFromBR ) )
@@ -1211,43 +1160,37 @@ void Array::DrawRange( drawinglayer::processor2d::BaseProcessor2D& rProcessor,
// *** vertical frame borders ***
for( nCol = nFirstCol; nCol <= nLastCol + 1; ++nCol )
{
- double fAngle = mxImpl->GetVerDiagAngle( nCol, nFirstRow );
- double fLAngle = mxImpl->GetVerDiagAngle( nCol - 1, nFirstRow );
-
// *Start*** variables store the data of the top end of the cached frame border
basegfx::B2DPoint aStartPos( mxImpl->GetColPosition( nCol ), mxImpl->GetRowPosition( nFirstRow ) );
const Style* pStart = &GetCellStyleLeft( nCol, nFirstRow );
- DiagStyle aStartTFromBL( GetCellStyleTR( nCol - 1, nFirstRow ), fLAngle );
+ Style aStartTFromBL( GetCellStyleTR( nCol - 1, nFirstRow ));
const Style* pStartTFromL = &GetCellStyleTop( nCol - 1, nFirstRow );
const Style* pStartTFromT = &GetCellStyleLeft( nCol, nFirstRow - 1 );
const Style* pStartTFromR = &GetCellStyleTop( nCol, nFirstRow );
- DiagStyle aStartTFromBR( GetCellStyleTL( nCol, nFirstRow ), fAngle );
+ Style aStartTFromBR( GetCellStyleTL( nCol, nFirstRow ));
// *End*** variables store the data of the bottom end of the cached frame border
- DiagStyle aEndBFromTL( GetCellStyleBR( nCol - 1, nFirstRow ), fLAngle );
+ Style aEndBFromTL( GetCellStyleBR( nCol - 1, nFirstRow ));
const Style* pEndBFromL = &GetCellStyleBottom( nCol - 1, nFirstRow );
const Style* pEndBFromB = &GetCellStyleLeft( nCol, nFirstRow + 1 );
const Style* pEndBFromR = &GetCellStyleBottom( nCol, nFirstRow );
- DiagStyle aEndBFromTR( GetCellStyleBL( nCol, nFirstRow ), fAngle );
+ Style aEndBFromTR( GetCellStyleBL( nCol, nFirstRow ));
for( nRow = nFirstRow + 1; nRow <= nLastRow; ++nRow )
{
- fAngle = mxImpl->GetVerDiagAngle( nCol, nRow );
- fLAngle = mxImpl->GetVerDiagAngle( nCol - 1, nRow );
-
const Style& rCurr = *pEndBFromB;
- DiagStyle aTFromBL( GetCellStyleTR( nCol - 1, nRow ), fLAngle );
+ Style aTFromBL( GetCellStyleTR( nCol - 1, nRow ));
const Style& rTFromL = *pEndBFromL;
const Style& rTFromT = *pStart;
const Style& rTFromR = *pEndBFromR;
- DiagStyle aTFromBR( GetCellStyleTL( nCol, nRow ), fAngle );
+ Style aTFromBR( GetCellStyleTL( nCol, nRow ));
- DiagStyle aBFromTL( GetCellStyleBR( nCol - 1, nRow ), fLAngle );
+ Style aBFromTL( GetCellStyleBR( nCol - 1, nRow ));
const Style& rBFromL = GetCellStyleBottom( nCol - 1, nRow );
const Style& rBFromB = GetCellStyleLeft( nCol, nRow + 1 );
const Style& rBFromR = GetCellStyleBottom( nCol, nRow );
- DiagStyle aBFromTR( GetCellStyleBL( nCol, nRow ), fAngle );
+ Style aBFromTR( GetCellStyleBL( nCol, nRow ));
// check if current frame border can be connected to cached frame border
if( !CheckFrameBorderConnectable( *pStart, rCurr,
diff --git a/svx/source/dialog/frmsel.cxx b/svx/source/dialog/frmsel.cxx
index e3ccf03eebc0..0bb928039b07 100644
--- a/svx/source/dialog/frmsel.cxx
+++ b/svx/source/dialog/frmsel.cxx
@@ -360,8 +360,9 @@ void FrameSelectorImpl::InitGlobalGeometry()
/* nBetwBordersSize contains the size between an outer and inner frame border (made odd). */
long nBetwBordersSize = (((nMinSize - nFixedSize) / 2) - 1) | 1;
- /* The final size of the usable area. */
+ /* The final size of the usable area. At least do not get negative */
mnCtrlSize = 2 * nBetwBordersSize + nFixedSize;
+ mnCtrlSize = std::max(mnCtrlSize, static_cast<long>(0));
mpVirDev->SetOutputSizePixel( Size( mnCtrlSize, mnCtrlSize ) );
/* Center the virtual device in the control. */
@@ -410,8 +411,10 @@ void FrameSelectorImpl::InitBorderGeometry()
for( nRow = 0, nRows = maArray.GetRowCount(); nRow < nRows; ++nRow )
{
tools::Rectangle aRect( maArray.GetCellRect( nCol, nRow ) );
- long nDiagFocusOffsX = frame::GetTLDiagOffset( -mnFocusOffs, mnFocusOffs, maArray.GetHorDiagAngle( nCol, nRow ) );
- long nDiagFocusOffsY = frame::GetTLDiagOffset( -mnFocusOffs, mnFocusOffs, maArray.GetVerDiagAngle( nCol, nRow ) );
+ const double fHorDiagAngle(atan2(static_cast< double >(std::abs(aRect.GetHeight())), static_cast< double >(std::abs(aRect.GetWidth()))));
+ const double fVerDiagAngle(fHorDiagAngle > 0.0 ? F_PI2 - fHorDiagAngle : 0.0);
+ const long nDiagFocusOffsX(basegfx::fround(-mnFocusOffs / tan(fHorDiagAngle) + mnFocusOffs / sin(fHorDiagAngle)));
+ const long nDiagFocusOffsY(basegfx::fround(-mnFocusOffs / tan(fVerDiagAngle) + mnFocusOffs / sin(fVerDiagAngle)));
std::vector< Point > aFocusVec;
aFocusVec.push_back( Point( aRect.Left() - mnFocusOffs, aRect.Top() + nDiagFocusOffsY ) );
More information about the Libreoffice-commits
mailing list