Kaydet (Commit) 2c91cb08 authored tarafından Markus Mohrhard's avatar Markus Mohrhard

better drawing support for borders of different width, fdo#33634

üst 71da75ab
...@@ -85,17 +85,17 @@ namespace drawinglayer ...@@ -85,17 +85,17 @@ namespace drawinglayer
/// local helpers /// local helpers
double getCorrectedLeftWidth() const double getCorrectedLeftWidth() const
{ {
return basegfx::fTools::equal(1.0, mfLeftWidth) ? 0.0 : mfLeftWidth; return mfLeftWidth <= 0.1 ? 0.0 : mfLeftWidth;
} }
double getCorrectedDistance() const double getCorrectedDistance() const
{ {
return basegfx::fTools::equal(1.0, mfDistance) ? 0.0 : mfDistance; return mfDistance <= 0.1 ? 0.0 : mfDistance;
} }
double getCorrectedRightWidth() const double getCorrectedRightWidth() const
{ {
return basegfx::fTools::equal(1.0, mfRightWidth) ? 0.0 : mfRightWidth; return mfRightWidth <= 0.1 ? 0.0 : mfRightWidth;
} }
double getWidth() const double getWidth() const
...@@ -105,12 +105,12 @@ namespace drawinglayer ...@@ -105,12 +105,12 @@ namespace drawinglayer
bool leftIsHairline() const bool leftIsHairline() const
{ {
return basegfx::fTools::equal(1.0, mfLeftWidth); return 0 < mfLeftWidth && mfLeftWidth <= 0.1;
} }
bool rightIsHairline() const bool rightIsHairline() const
{ {
return basegfx::fTools::equal(1.0, mfRightWidth); return 0 < mfRightWidth && mfRightWidth <= 0.1;
} }
bool isSolidLine() const bool isSolidLine() const
......
...@@ -118,12 +118,12 @@ public: ...@@ -118,12 +118,12 @@ public:
/** Constructs an invisible frame style. */ /** Constructs an invisible frame style. */
inline explicit Style() : meRefMode( REFMODE_CENTERED ), mnType( editeng::SOLID ) { Clear(); } inline explicit Style() : meRefMode( REFMODE_CENTERED ), mnType( editeng::SOLID ) { Clear(); }
/** Constructs a frame style with passed line widths. */ /** Constructs a frame style with passed line widths. */
inline explicit Style( sal_uInt16 nP, sal_uInt16 nD, sal_uInt16 nS, editeng::SvxBorderStyle nType ) : inline explicit Style( double nP, double nD, double nS, editeng::SvxBorderStyle nType ) :
meRefMode( REFMODE_CENTERED ), mnType( nType ) meRefMode( REFMODE_CENTERED ), mnType( nType )
{ Clear(); Set( nP, nD, nS ); } { Clear(); Set( nP, nD, nS ); }
/** Constructs a frame style with passed color and line widths. */ /** Constructs a frame style with passed color and line widths. */
inline explicit Style( const Color& rColorPrim, const Color& rColorSecn, const Color& rColorGap, bool bUseGapColor, inline explicit Style( const Color& rColorPrim, const Color& rColorSecn, const Color& rColorGap, bool bUseGapColor,
sal_uInt16 nP, sal_uInt16 nD, sal_uInt16 nS, editeng::SvxBorderStyle nType ) : double nP, double nD, double nS, editeng::SvxBorderStyle nType ) :
meRefMode( REFMODE_CENTERED ), mnType( nType ) meRefMode( REFMODE_CENTERED ), mnType( nType )
{ Set( rColorPrim, rColorSecn, rColorGap, bUseGapColor, nP, nD, nS ); } { Set( rColorPrim, rColorSecn, rColorGap, bUseGapColor, nP, nD, nS ); }
/** Constructs a frame style from the passed SvxBorderLine struct. */ /** Constructs a frame style from the passed SvxBorderLine struct. */
...@@ -138,21 +138,21 @@ public: ...@@ -138,21 +138,21 @@ public:
inline const Color& GetColorSecn() const { return maColorSecn; } inline const Color& GetColorSecn() const { return maColorSecn; }
inline const Color& GetColorGap() const { return maColorGap; } inline const Color& GetColorGap() const { return maColorGap; }
inline bool UseGapColor() const { return mbUseGapColor; } inline bool UseGapColor() const { return mbUseGapColor; }
inline sal_uInt16 Prim() const { return mnPrim; } inline double Prim() const { return mnPrim; }
inline sal_uInt16 Dist() const { return mnDist; } inline double Dist() const { return mnDist; }
inline sal_uInt16 Secn() const { return mnSecn; } inline double Secn() const { return mnSecn; }
inline editeng::SvxBorderStyle Type() const { return mnType; } inline editeng::SvxBorderStyle Type() const { return mnType; }
/** Returns the total width of this frame style. */ /** Returns the total width of this frame style. */
inline sal_uInt16 GetWidth() const { return mnPrim + mnDist + mnSecn; } inline double GetWidth() const { return mnPrim + mnDist + mnSecn; }
/** Sets the frame style to invisible state. */ /** Sets the frame style to invisible state. */
void Clear(); void Clear();
/** Sets the frame style to the passed line widths. */ /** Sets the frame style to the passed line widths. */
void Set( sal_uInt16 nP, sal_uInt16 nD, sal_uInt16 nS ); void Set( double nP, double nD, double nS );
/** Sets the frame style to the passed line widths. */ /** Sets the frame style to the passed line widths. */
void Set( const Color& rColorPrim, const Color& rColorSecn, const Color& rColorGap, bool bUseGapColor, void Set( const Color& rColorPrim, const Color& rColorSecn, const Color& rColorGap, bool bUseGapColor,
sal_uInt16 nP, sal_uInt16 nD, sal_uInt16 nS ); double nP, double nD, double nS );
/** Sets the frame style to the passed SvxBorderLine struct. */ /** Sets the frame style to the passed SvxBorderLine struct. */
void Set( const editeng::SvxBorderLine& rBorder, double fScale = 1.0, sal_uInt16 nMaxWidth = SAL_MAX_UINT16 ); void Set( const editeng::SvxBorderLine& rBorder, double fScale = 1.0, sal_uInt16 nMaxWidth = SAL_MAX_UINT16 );
/** Sets the frame style to the passed SvxBorderLine struct. Clears the style, if pBorder is 0. */ /** Sets the frame style to the passed SvxBorderLine struct. Clears the style, if pBorder is 0. */
...@@ -178,9 +178,9 @@ private: ...@@ -178,9 +178,9 @@ private:
Color maColorGap; Color maColorGap;
bool mbUseGapColor; bool mbUseGapColor;
RefMode meRefMode; /// Reference point handling for this frame border. RefMode meRefMode; /// Reference point handling for this frame border.
sal_uInt16 mnPrim; /// Width of primary (single, left, or top) line. double mnPrim; /// Width of primary (single, left, or top) line.
sal_uInt16 mnDist; /// Distance between primary and secondary line. double mnDist; /// Distance between primary and secondary line.
sal_uInt16 mnSecn; /// Width of secondary (right or bottom) line. double mnSecn; /// Width of secondary (right or bottom) line.
editeng::SvxBorderStyle mnType; editeng::SvxBorderStyle mnType;
}; };
......
...@@ -215,12 +215,9 @@ inline long lclD2L( double fValue ) ...@@ -215,12 +215,9 @@ inline long lclD2L( double fValue )
} }
/** Converts a width in twips to a width in another map unit (specified by fScale). */ /** Converts a width in twips to a width in another map unit (specified by fScale). */
sal_uInt16 lclScaleValue( long nValue, double fScale, sal_uInt16 nMaxWidth ) double lclScaleValue( double nValue, double fScale, sal_uInt16 nMaxWidth )
{ {
// convert any width except 0 to at least 1 unit return std::min<double>(nValue * fScale, nMaxWidth);
// #i61324# 1 twip must scale to 1/100mm
return nValue ? static_cast< sal_uInt16 >( std::min< long >( std::max(
static_cast< long >( nValue * fScale ), 1L ), nMaxWidth ) ) : 0;
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
...@@ -1154,7 +1151,7 @@ void Style::Clear() ...@@ -1154,7 +1151,7 @@ void Style::Clear()
Set( Color(), Color(), Color(), false, 0, 0, 0 ); Set( Color(), Color(), Color(), false, 0, 0, 0 );
} }
void Style::Set( sal_uInt16 nP, sal_uInt16 nD, sal_uInt16 nS ) void Style::Set( double nP, double nD, double nS )
{ {
/* nP nD nS -> mnPrim mnDist mnSecn /* nP nD nS -> mnPrim mnDist mnSecn
-------------------------------------- --------------------------------------
...@@ -1163,12 +1160,12 @@ void Style::Set( sal_uInt16 nP, sal_uInt16 nD, sal_uInt16 nS ) ...@@ -1163,12 +1160,12 @@ void Style::Set( sal_uInt16 nP, sal_uInt16 nD, sal_uInt16 nS )
>0 0 >0 nP 0 0 >0 0 >0 nP 0 0
>0 >0 >0 nP nD nS >0 >0 >0 nP nD nS
*/ */
mnPrim = nP ? nP : nS; mnPrim = rtl::math::round(nP ? nP : nS, 2);
mnDist = (nP && nS) ? nD : 0; mnDist = rtl::math::round((nP && nS) ? nD : 0, 2);
mnSecn = (nP && nD) ? nS : 0; mnSecn = rtl::math::round((nP && nD) ? nS : 0, 2);
} }
void Style::Set( const Color& rColorPrim, const Color& rColorSecn, const Color& rColorGap, bool bUseGapColor, sal_uInt16 nP, sal_uInt16 nD, sal_uInt16 nS ) void Style::Set( const Color& rColorPrim, const Color& rColorSecn, const Color& rColorGap, bool bUseGapColor, double nP, double nD, double nS )
{ {
maColorPrim = rColorPrim; maColorPrim = rColorPrim;
maColorSecn = rColorSecn; maColorSecn = rColorSecn;
...@@ -1197,7 +1194,7 @@ void Style::Set( const SvxBorderLine& rBorder, double fScale, sal_uInt16 nMaxWid ...@@ -1197,7 +1194,7 @@ void Style::Set( const SvxBorderLine& rBorder, double fScale, sal_uInt16 nMaxWid
{ {
Set( SCALEVALUE( nPrim ), SCALEVALUE( nDist ), SCALEVALUE( nSecn ) ); Set( SCALEVALUE( nPrim ), SCALEVALUE( nDist ), SCALEVALUE( nSecn ) );
// Enlarge the style if distance is too small due to rounding losses. // Enlarge the style if distance is too small due to rounding losses.
sal_uInt16 nPixWidth = SCALEVALUE( nPrim + nDist + nSecn ); double nPixWidth = SCALEVALUE( nPrim + nDist + nSecn );
if( nPixWidth > GetWidth() ) if( nPixWidth > GetWidth() )
mnDist = nPixWidth - mnPrim - mnSecn; mnDist = nPixWidth - mnPrim - mnSecn;
// Shrink the style if it is too thick for the control. // Shrink the style if it is too thick for the control.
...@@ -1209,7 +1206,7 @@ void Style::Set( const SvxBorderLine& rBorder, double fScale, sal_uInt16 nMaxWid ...@@ -1209,7 +1206,7 @@ void Style::Set( const SvxBorderLine& rBorder, double fScale, sal_uInt16 nMaxWid
// Still too thick? Decrease the line widths. // Still too thick? Decrease the line widths.
if( GetWidth() > nMaxWidth ) if( GetWidth() > nMaxWidth )
{ {
if( mnPrim && (mnPrim == mnSecn) ) if( rtl::math::approxEqual(mnPrim, 0.0) && rtl::math::approxEqual(mnPrim, mnSecn) )
{ {
// Both lines equal - decrease both to keep symmetry. // Both lines equal - decrease both to keep symmetry.
--mnPrim; --mnPrim;
...@@ -1220,7 +1217,7 @@ void Style::Set( const SvxBorderLine& rBorder, double fScale, sal_uInt16 nMaxWid ...@@ -1220,7 +1217,7 @@ void Style::Set( const SvxBorderLine& rBorder, double fScale, sal_uInt16 nMaxWid
// Decrease each line for itself // Decrease each line for itself
if( mnPrim ) if( mnPrim )
--mnPrim; --mnPrim;
if( (GetWidth() > nMaxWidth) && mnSecn ) if( (GetWidth() > nMaxWidth) && !rtl::math::approxEqual(mnSecn, 0.0) )
--mnSecn; --mnSecn;
} }
} }
...@@ -1264,8 +1261,8 @@ bool operator==( const Style& rL, const Style& rR ) ...@@ -1264,8 +1261,8 @@ bool operator==( const Style& rL, const Style& rR )
bool operator<( const Style& rL, const Style& rR ) bool operator<( const Style& rL, const Style& rR )
{ {
// different total widths -> rL<rR, if rL is thinner // different total widths -> rL<rR, if rL is thinner
sal_uInt16 nLW = rL.GetWidth(); double nLW = rL.GetWidth();
sal_uInt16 nRW = rR.GetWidth(); double nRW = rR.GetWidth();
if( nLW != nRW ) return nLW < nRW; if( nLW != nRW ) return nLW < nRW;
// one line double, the other single -> rL<rR, if rL is single // one line double, the other single -> rL<rR, if rL is single
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment