1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SVX_FRAMELINK_HXX
21 #define INCLUDED_SVX_FRAMELINK_HXX
24 #include <sal/types.h>
25 #include <tools/color.hxx>
26 #include <svx/svxdllapi.h>
27 #include <vcl/outdev.hxx>
28 #include <editeng/borderline.hxx>
30 #include <drawinglayer/primitive2d/baseprimitive2d.hxx>
33 namespace tools
{ class Rectangle
; }
43 /** Specifies how the reference points for frame borders are used.
47 /** Frame borders are drawn centered to the reference points. */
50 /** The reference points specify the begin of the frame border width.
52 The result is that horizontal lines are drawn below, and vertical lines
53 are drawn right of the reference points.
57 /** The reference points specify the end of the frame border width.
59 The result is that horizontal lines are drawn above, and vertical lines
60 are drawn left of the reference points.
69 /** Contains the widths of primary and secondary line of a frame style.
71 In the following, "frame style" is a complete style of one frame border,
72 i.e. the double line at the left side of the frame. A "line" is always a
73 trivial single line, i.e. the first line of a double frame style.
75 The following states of the members of this struct are valid:
77 mnPrim mnDist mnSecn frame style
78 -------------------------------------------------
83 The behaviour of the member functions for other states is not defined.
85 Per definition the primary line in double frame styles is:
86 - The top line for horizontal frame borders.
87 - The left line for vertical frame borders.
88 - The bottom-left line for top-left to bottom-right diagonal frame borders.
89 - The top-left line for bottom-left to top-right diagonal frame borders.
91 The following picture shows the upper end of a vertical double frame
94 |<---------------- GetWidth() ----------------->|
96 |<----- mnPrim ----->||<- mnDist ->||<- mnSecn >|
98 ###################### #############
99 ###################### #############
100 ###################### #############
101 ###################### #############
102 ###################### | #############
103 ###################### | #############
105 |<- middle of the frame border
107 class SAL_WARN_UNUSED SVX_DLLPUBLIC Style
110 /** Constructs an invisible frame style. */
112 /** Constructs a frame style with passed line widths. */
113 explicit Style( double nP
, double nD
, double nS
, SvxBorderLineStyle nType
);
114 /** Constructs a frame style with passed color and line widths. */
115 explicit Style( const Color
& rColorPrim
, const Color
& rColorSecn
, const Color
& rColorGap
, bool bUseGapColor
,
116 double nP
, double nD
, double nS
, SvxBorderLineStyle nType
);
117 /** Constructs a frame style from the passed SvxBorderLine struct. Clears the style, if pBorder is 0. */
118 explicit Style( const editeng::SvxBorderLine
* pBorder
, double fScale
= 1.0 );
120 RefMode
GetRefMode() const { return meRefMode
; }
121 const Color
& GetColorPrim() const { return maColorPrim
; }
122 const Color
& GetColorSecn() const { return maColorSecn
; }
123 const Color
& GetColorGap() const { return maColorGap
; }
124 bool UseGapColor() const { return mbUseGapColor
; }
125 double Prim() const { return mfPrim
; }
126 double Dist() const { return mfDist
; }
127 double Secn() const { return mfSecn
; }
128 double PatternScale() const { return mfPatternScale
;}
129 void SetPatternScale( double fScale
);
130 SvxBorderLineStyle
Type() const { return mnType
; }
132 /** Returns the total width of this frame style. */
133 double GetWidth() const { return mfPrim
+ mfDist
+ mfSecn
; }
135 /** Sets the frame style to invisible state. */
137 /** Sets the frame style to the passed line widths. */
138 void Set( double nP
, double nD
, double nS
);
139 /** Sets the frame style to the passed line widths. */
140 void Set( const Color
& rColorPrim
, const Color
& rColorSecn
, const Color
& rColorGap
, bool bUseGapColor
,
141 double nP
, double nD
, double nS
);
142 /** Sets the frame style to the passed SvxBorderLine struct. */
143 void Set( const editeng::SvxBorderLine
& rBorder
, double fScale
, sal_uInt16 nMaxWidth
= SAL_MAX_UINT16
);
144 /** Sets the frame style to the passed SvxBorderLine struct. Clears the style, if pBorder is 0. */
145 void Set( const editeng::SvxBorderLine
* pBorder
, double fScale
, sal_uInt16 nMaxWidth
= SAL_MAX_UINT16
);
147 /** Sets a new reference point handling mode, does not modify other settings. */
148 void SetRefMode( RefMode eRefMode
) { meRefMode
= eRefMode
; }
149 /** Sets a new color, does not modify other settings. */
150 void SetColorPrim( const Color
& rColor
) { maColorPrim
= rColor
; }
151 void SetColorSecn( const Color
& rColor
) { maColorSecn
= rColor
; }
152 /** Sets whether to use dotted style for single hair lines. */
153 void SetType( SvxBorderLineStyle nType
) { mnType
= nType
; }
155 /** Mirrors this style (exchanges primary and secondary), if it is a double frame style. */
157 /** Returns this style mirrored, if it is a double frame style, otherwise a simple copy. */
158 Style
Mirror() const;
165 RefMode meRefMode
; /// Reference point handling for this frame border.
166 double mfPrim
; /// Width of primary (single, left, or top) line.
167 double mfDist
; /// Distance between primary and secondary line.
168 double mfSecn
; /// Width of secondary (right or bottom) line.
169 double mfPatternScale
; /// Scale used for line pattern spacing.
170 SvxBorderLineStyle mnType
;
173 bool operator==( const Style
& rL
, const Style
& rR
);
174 SVX_DLLPUBLIC
bool operator<( const Style
& rL
, const Style
& rR
);
176 inline bool operator>( const Style
& rL
, const Style
& rR
) { return rR
< rL
; }
177 inline bool operator<=( const Style
& rL
, const Style
& rR
) { return !(rR
< rL
); }
180 /** Extends the Style struct with an angle for diagonal frame borders.
182 The angle is specified in radian (a full circle is equivalent to 2*PI).
183 It is dependent on the context, how the value is interpreted, i.e. it may
184 specify the angle to a horizontal or vertical frame border.
186 class SAL_WARN_UNUSED DiagStyle
: public Style
189 /** Constructs an invisible diagonal frame style. */
190 explicit DiagStyle() : mfAngle( 0.0 ) {}
191 /** Constructs a diagonal frame style passed style and angle. */
192 explicit DiagStyle( const Style
& rStyle
, double fAngle
) :
193 Style( rStyle
), mfAngle( fAngle
) {}
195 double GetAngle() const { return mfAngle
; }
197 /** Returns this style mirrored, if it is a double frame style, otherwise a simple copy. */
198 DiagStyle
Mirror() const { return DiagStyle( Style::Mirror(), mfAngle
); }
201 double mfAngle
; /// Angle between this and hor. or vert. border.
205 // Various helper functions
208 /** Returns the angle between horizontal border of a rectangle and its diagonal.
210 The returned values represents the inner angle between the diagonals and
211 horizontal borders, and is therefore in the range [0,PI/2] (inclusive). The
212 passed sizes may be negative, calculation is done with absolute values.
214 SVX_DLLPUBLIC
double GetHorDiagAngle( long nWidth
, long nHeight
);
216 /** Returns the angle between horizontal border of a rectangle and its diagonal.
218 The returned values represents the inner angle between the diagonals and
219 horizontal borders, and is therefore in the range [0,PI/2] (inclusive).
221 inline double GetHorDiagAngle( const tools::Rectangle
& rRect
)
222 { return GetHorDiagAngle( rRect
.GetWidth(), rRect
.GetHeight() ); }
225 /** Returns the angle between vertical border of a rectangle and its diagonal.
227 The returned values represents the inner angle between the diagonals and
228 vertical borders, and is therefore in the range [0,PI/2] (inclusive). The
229 passed sizes may be negative, calculation is done with absolute values.
231 inline double GetVerDiagAngle( long nWidth
, long nHeight
)
232 { return GetHorDiagAngle( nHeight
, nWidth
); }
234 /** Returns the angle between vertical border of a rectangle and its diagonal.
236 The returned values represents the inner angle between the diagonals and
237 vertical borders, and is therefore in the range [0,PI/2] (inclusive).
239 inline double GetVerDiagAngle( const tools::Rectangle
& rRect
)
240 { return GetVerDiagAngle( rRect
.GetWidth(), rRect
.GetHeight() ); }
243 /** Returns an X coordinate for a diagonal frame border in the specified height.
245 This function is for usage with the top-left end of a top-left to
246 bottom-right diagonal frame border, connected to the left end of a
247 horizontal frame border.
249 The function returns the relative X position (i.e. for a polygon) of the
250 diagonal frame border according to the specified relative Y position. The
251 mentioned positions are relative to the reference point of both frame
254 +----------------------------------------------------------
255 | The horizontal frame border.
257 - - - - - - | --+-- <---- Reference point for horizontal and diagonal frame borders.
259 nVerOffs | \ \ <--- The diagonal frame border.
260 v +---\ \------------------------------------------------
261 - - - - - - - - -\- - -X <----- The function calculates the X position of i.e.
262 \ \ this point (relative from X of reference point).
264 Primary -->\ \<-- Secondary
267 The vertical position of the point to be calculated, relative to the Y
268 coordinate of the reference point.
270 The width offset across the diagonal frame border (0 = middle),
271 regardless of the gradient of the diagonal frame border (always
272 vertical to the direction of the diagonal frame border). This value is
273 not related in any way to the reference point. For details about
274 relative width offsets, see description of class Style.
276 Inner (right) angle between diagonal and horizontal frame border.
278 SVX_DLLPUBLIC
long GetTLDiagOffset( long nVerOffs
, long nDiagOffs
, double fAngle
);
280 /** Returns an X coordinate for a diagonal frame border in the specified height.
282 This function is for usage with the bottom-left end of a bottom-left to
283 top-right diagonal frame border, connected to the left end of a horizontal
286 The function returns the relative X position (i.e. for a polygon) of the
287 diagonal frame border according to the specified relative Y position. The
288 mentioned positions are relative to the reference point of both frame
291 Primary -->/ /<--- Secondary
293 / / The function calculates the X position of i.e.
294 - - - - - - - - -/- - -X <----- this point (relative from X of reference point).
295 ^ +---/ /------------------------------------------------
296 nVerOffs | / / <--- The diagonal frame border.
298 - - - - - - | --+-- <---- Reference point for horizontal and diagonal frame borders.
300 | The horizontal frame border.
301 +----------------------------------------------------------
304 The vertical position of the point to be calculated, relative to the Y
305 coordinate of the reference point.
307 The width offset across the diagonal frame border (0 = middle),
308 regardless of the gradient of the diagonal frame border (always
309 vertical to the direction of the diagonal frame border). This value is
310 not related in any way to the reference point. For details about
311 relative width offsets, see description of class Style.
313 Inner (right) angle between diagonal and horizontal frame border.
315 long GetBLDiagOffset( long nVerOffs
, long nDiagOffs
, double fAngle
);
317 /** Returns an X coordinate for a diagonal frame border in the specified height.
319 This function is for usage with the bottom-right end of a top-left to
320 bottom-right diagonal frame border, connected to the right end of a
321 horizontal frame border.
324 The width offset across the diagonal frame border (0 = middle),
325 regardless of the gradient of the diagonal frame border (always
326 vertical to the direction of the diagonal frame border). This value is
327 not related in any way to the reference point. For details about
328 relative width offsets, see description of class Style.
330 Inner (left) angle between diagonal and horizontal frame border.
332 long GetBRDiagOffset( long nDiagOffs
, double fAngle
);
334 /** Returns an X coordinate for a diagonal frame border in the specified height.
336 This function is for usage with the top-right end of a bottom-left to
337 top-right diagonal frame border, connected to the right end of a horizontal
341 The width offset across the diagonal frame border (0 = middle),
342 regardless of the gradient of the diagonal frame border (always
343 vertical to the direction of the diagonal frame border). This value is
344 not related in any way to the reference point. For details about
345 relative width offsets, see description of class Style.
347 Inner (left) angle between diagonal and horizontal frame border.
349 long GetTRDiagOffset( long nDiagOffs
, double fAngle
);
352 /** Checks whether two horizontal frame borders are "connectable".
354 Two borders are "connectable" in terms of this function, if both can be
355 drawn with only one call of a border drawing function. This means, the two
356 frame borders must have equal style and color, and none of the other
357 vertical and diagonal frame borders break the lines of the two borders in
358 any way (i.e. two vertical double frame borders would break the horizonal
359 frame borders). Of course this function can be used for vertical frame
362 The follong picture shows the meaning of all passed parameters:
369 ======== rLBorder ========= ========== rRBorder =======
377 True, if rLBorder and rRBorder can be drawn in one step without
378 interruption at their connection point.
380 SVX_DLLPUBLIC
bool CheckFrameBorderConnectable(
381 const Style
& rLBorder
, /// Style of the left frame border to connect.
382 const Style
& rRBorder
, /// Style of the right frame border to connect.
384 const Style
& rTFromTL
, /// Diagonal frame border from top-left to connection point.
385 const Style
& rTFromT
, /// Vertical frame border from top to connection point.
386 const Style
& rTFromTR
, /// Horizontal frame border from top-right to connection point.
388 const Style
& rBFromBL
, /// Diagonal frame border from bottom-left to connection point.
389 const Style
& rBFromB
, /// Vertical frame border from bottom to connection point.
390 const Style
& rBFromBR
/// Horizontal frame border from bottom-right to connection point.
397 /** Draws a horizontal frame border, regards all connected frame styles.
399 The frame style to draw is passed as parameter rBorder. The function
400 calculates the adjustment in X direction for left and right end of primary
401 and secondary line of the frame border (the style may present a double
402 line). The line ends may differ according to the connected frame styles
403 coming from top, bottom, left, right, and/or diagonal.
405 Thick frame styles are always drawn centered (in width) to the passed
406 reference points. The Y coordinates of both reference points must be equal
407 (the line cannot be drawn slanted).
409 The function preserves all settings of the passed output device.
411 All parameters starting with "rL" refer to the left end of the processed
412 frame border, all parameters starting with "rR" refer to the right end.
413 The following part of the parameter name starting with "From" specifies
414 where the frame border comes from. Example: "rLFromTR" means the frame
415 border coming from top-right, connected to the left end of rBorder (and
416 therefore a diagonal frame border).
418 The follong picture shows the meaning of all passed parameters:
422 | rLFromTR rRFromTL |
425 --- rLFromL --- ============== rBorder ============== --- rRFromR ---
428 | rLFromBR rRFromBL |
432 SVX_DLLPUBLIC
drawinglayer::primitive2d::Primitive2DContainer
CreateBorderPrimitives(
433 const Point
& rLPos
, /// Reference point for left end of the processed frame border.
434 const Point
& rRPos
, /// Reference point for right end of the processed frame border.
435 const Style
& rBorder
, /// Style of the processed frame border.
437 const DiagStyle
& rLFromTR
, /// Diagonal frame border from top-right to left end of rBorder.
438 const Style
& rLFromT
, /// Vertical frame border from top to left end of rBorder.
439 const Style
& rLFromL
, /// Horizontal frame border from left to left end of rBorder.
440 const Style
& rLFromB
, /// Vertical frame border from bottom to left end of rBorder.
441 const DiagStyle
& rLFromBR
, /// Diagonal frame border from bottom-right to left end of rBorder.
443 const DiagStyle
& rRFromTL
, /// Diagonal frame border from top-left to right end of rBorder.
444 const Style
& rRFromT
, /// Vertical frame border from top to right end of rBorder.
445 const Style
& rRFromR
, /// Horizontal frame border from right to right end of rBorder.
446 const Style
& rRFromB
, /// Vertical frame border from bottom to right end of rBorder.
447 const DiagStyle
& rRFromBL
, /// Diagonal frame border from bottom-left to right end of rBorder.
449 const Color
* pForceColor
, /// If specified, overrides frame border color.
450 const long rRotationT
= 9000, /// Angle of the top slanted frames in 100th of degree
451 const long rRotationB
= 9000 /// Angle of the bottom slanted frames in 100th of degree
454 SVX_DLLPUBLIC
drawinglayer::primitive2d::Primitive2DContainer
CreateBorderPrimitives(
455 const Point
& rLPos
, /// Reference point for left end of the processed frame border.
456 const Point
& rRPos
, /// Reference point for right end of the processed frame border.
457 const Style
& rBorder
, /// Style of the processed frame border.
459 const Style
& rLFromT
, /// Vertical frame border from top to left end of rBorder.
460 const Style
& rLFromL
, /// Horizontal frame border from left to left end of rBorder.
461 const Style
& rLFromB
, /// Vertical frame border from bottom to left end of rBorder.
463 const Style
& rRFromT
, /// Vertical frame border from top to right end of rBorder.
464 const Style
& rRFromR
, /// Horizontal frame border from right to right end of rBorder.
465 const Style
& rRFromB
, /// Vertical frame border from bottom to right end of rBorder.
467 const Color
* pForceColor
, /// If specified, overrides frame border color.
468 const long rRotationT
= 9000, /// Angle of the top slanted frame in 100th of degrees
469 const long rRotationB
= 9000 /// Angle of the bottom slanted frame in 100th of degrees
472 SVX_DLLPUBLIC
drawinglayer::primitive2d::Primitive2DContainer
CreateClippedBorderPrimitives (
473 const Point
& rStart
, const Point
& rEnd
, const Style
& rBorder
,
474 const tools::Rectangle
& rClipRect
);
476 /** Draws a horizontal frame border, regards all connected frame styles.
478 The frame style to draw is passed as parameter rBorder. The function
479 calculates the adjustment in X direction for left and right end of primary
480 and secondary line of the frame border (the style may present a double
481 line). The line ends may differ according to the connected frame styles
482 coming from top, bottom, left, right, and/or diagonal.
484 Thick frame styles are always drawn centered (in width) to the passed
485 reference points. The Y coordinates of both reference points must be equal
486 (the line cannot be drawn slanted).
488 The function preserves all settings of the passed output device.
490 All parameters starting with "rL" refer to the left end of the processed
491 frame border, all parameters starting with "rR" refer to the right end.
492 The following part of the parameter name starting with "From" specifies
493 where the frame border comes from. Example: "rLFromTR" means the frame
494 border coming from top-right, connected to the left end of rBorder (and
495 therefore a diagonal frame border).
497 The follong picture shows the meaning of all passed parameters:
501 | rLFromTR rRFromTL |
504 --- rLFromL --- ============== rBorder ============== --- rRFromR ---
507 | rLFromBR rRFromBL |
511 SVX_DLLPUBLIC
void DrawHorFrameBorder(
512 OutputDevice
& rDev
, /// The output device used to draw the frame border.
514 const Point
& rLPos
, /// Reference point for left end of the processed frame border.
515 const Point
& rRPos
, /// Reference point for right end of the processed frame border.
516 const Style
& rBorder
, /// Style of the processed frame border.
518 const DiagStyle
& rLFromTR
, /// Diagonal frame border from top-right to left end of rBorder.
519 const Style
& rLFromT
, /// Vertical frame border from top to left end of rBorder.
520 const Style
& rLFromL
, /// Horizontal frame border from left to left end of rBorder.
521 const Style
& rLFromB
, /// Vertical frame border from bottom to left end of rBorder.
522 const DiagStyle
& rLFromBR
, /// Diagonal frame border from bottom-right to left end of rBorder.
524 const DiagStyle
& rRFromTL
, /// Diagonal frame border from top-left to right end of rBorder.
525 const Style
& rRFromT
, /// Vertical frame border from top to right end of rBorder.
526 const Style
& rRFromR
, /// Horizontal frame border from right to right end of rBorder.
527 const Style
& rRFromB
, /// Vertical frame border from bottom to right end of rBorder.
528 const DiagStyle
& rRFromBL
, /// Diagonal frame border from bottom-left to right end of rBorder.
530 const Color
* pForceColor
= nullptr /// If specified, overrides frame border color.
534 /** Draws a vertical frame border, regards all connected frame styles.
536 The frame style to draw is passed as parameter rBorder. The function
537 calculates the adjustment in Y direction for top and bottom end of primary
538 and secondary line of the frame border (the style may present a double
539 line). The line ends may differ according to the connected frame styles
540 coming from left, right, top, bottom, and/or diagonal.
542 Thick frame styles are always drawn centered (in width) to the passed
543 reference points. The X coordinates of both reference points must be equal
544 (the line cannot be drawn slanted).
546 The function preserves all settings of the passed output device.
548 All parameters starting with "rT" refer to the top end of the processed
549 frame border, all parameters starting with "rB" refer to the bottom end.
550 The following part of the parameter name starting with "From" specifies
551 where the frame border comes from. Example: "rTFromBL" means the frame
552 border coming from bottom-left, connected to the top end of rBorder (and
553 therefore a diagonal frame border).
555 The follong picture shows the meaning of all passed parameters:
561 --- rTFromL --- --- rTFromR ---
575 --- rBFromL --- --- rBFromR ---
581 SVX_DLLPUBLIC
void DrawVerFrameBorder(
582 OutputDevice
& rDev
, /// The output device used to draw the frame border.
584 const Point
& rTPos
, /// Reference point for top end of the processed frame border.
585 const Point
& rBPos
, /// Reference point for bottom end of the processed frame border.
586 const Style
& rBorder
, /// Style of the processed frame border.
588 const DiagStyle
& rTFromBL
, /// Diagonal frame border from bottom-right to top end of rBorder.
589 const Style
& rTFromL
, /// Horizontal frame border from left to top end of rBorder.
590 const Style
& rTFromT
, /// Vertical frame border from top to top end of rBorder.
591 const Style
& rTFromR
, /// Horizontal frame border from right to top end of rBorder.
592 const DiagStyle
& rTFromBR
, /// Diagonal frame border from bottom-right to top end of rBorder.
594 const DiagStyle
& rBFromTL
, /// Diagonal frame border from top-left to bottom end of rBorder.
595 const Style
& rBFromL
, /// Horizontal frame border from left to bottom end of rBorder.
596 const Style
& rBFromB
, /// Vertical frame border from bottom to bottom end of rBorder.
597 const Style
& rBFromR
, /// Horizontal frame border from right to bottom end of rBorder.
598 const DiagStyle
& rBFromTR
, /// Diagonal frame border from top-right to bottom end of rBorder.
600 const Color
* pForceColor
= nullptr /// If specified, overrides frame border color.
604 /** Draws both diagonal frame borders, regards all connected frame styles.
606 One or both passed diagonal frame styles may be invisible.
608 The function preserves all settings of the passed output device.
610 SVX_DLLPUBLIC
void DrawDiagFrameBorders(
611 OutputDevice
& rDev
, /// The output device used to draw the frame border.
613 const tools::Rectangle
& rRect
, /// Rectangle for both diagonal frame borders.
614 const Style
& rTLBR
, /// Style of the processed top-left to bottom-right diagonal frame border.
615 const Style
& rBLTR
, /// Style of the processed bottom-left to top-right diagonal frame border.
617 const Style
& rTLFromB
, /// Vertical frame border from bottom to top-left end of rTLBR.
618 const Style
& rTLFromR
, /// Horizontal frame border from right to top-left end of rTLBR.
619 const Style
& rBRFromT
, /// Vertical frame border from top to bottom-right end of rTLBR.
620 const Style
& rBRFromL
, /// Horizontal frame border from left to bottom-right end of rTLBR.
622 const Style
& rBLFromT
, /// Vertical frame border from top to bottom-left end of rBLTR.
623 const Style
& rBLFromR
, /// Horizontal frame border from right to bottom-left end of rBLTR.
624 const Style
& rTRFromB
, /// Vertical frame border from bottom to top-right end of rBLTR.
625 const Style
& rTRFromL
, /// Horizontal frame border from left to top-right end of rBLTR.
627 const Color
* pForceColor
, /// If specified, overrides frame border color.
628 bool bDiagDblClip
/// true = Use clipping for crossing double frame borders.
635 /* Yes, I love ASCII art. :-) -DR- */
639 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */