1 /* AbiWord
2  * Copyright (C) 1998,1999 AbiSource, Inc.
3  * BIDI Copyright (c) 2001,2002 Tomas Frydrych
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18  * 02110-1301 USA.
19  */
20 
21 #ifndef FB_ALIGNMENT_H
22 #define FB_ALIGNMENT_H
23 
24 #include "ut_types.h"
25 
26 class fp_Line;
27 class fp_Run;
28 
29 /*
30 	fb_Alignment is an abstract worker class that encapsulates the
31 	alignment policy in effect for the current fp_Line of an individual
32 	fl_Block during formatting.
33 
34 	Each policy is implemented in its own subclass:
35 
36 		fb_Alignment_left
37 		fb_Alignment_center
38 		fb_Alignment_right
39 		fb_Alignment_justify
40 */
41 enum FB_AlignmentType { FB_ALIGNMENT_LEFT,
42                         FB_ALIGNMENT_RIGHT,
43                         FB_ALIGNMENT_CENTER,
44                         FB_ALIGNMENT_JUSTIFY
45                         };
46 
47 
48 class ABI_EXPORT fb_Alignment
49 {
50 
51 public:
~fb_Alignment()52 	virtual ~fb_Alignment() {}
53 
54 	virtual void		initialize(fp_Line *pLine) = 0;
55 	virtual UT_sint32	getStartPosition() = 0;
56 	virtual void		eraseLineFromRun(fp_Line *pLine, UT_uint32 runIndex) = 0;
57     virtual FB_AlignmentType getType() = 0;
58 
59 };
60 
61 class ABI_EXPORT fb_Alignment_left : public fb_Alignment
62 {
63 public:
64 
65 	void		initialize(fp_Line *pLine);
66 	UT_sint32	getStartPosition();
67 	void		eraseLineFromRun(fp_Line *pLine, UT_uint32 runIndex);
getType()68     FB_AlignmentType getType(){return FB_ALIGNMENT_LEFT;};
69 
70 private:
71 
72 	UT_sint32	m_iStartPosition;
73 };
74 
75 class ABI_EXPORT fb_Alignment_center : public fb_Alignment
76 {
77 public:
78 
79 	void		initialize(fp_Line *pLine);
80 	UT_sint32	getStartPosition();
81 	void		eraseLineFromRun(fp_Line *pLine, UT_uint32 runIndex);
getType()82     FB_AlignmentType getType(){return FB_ALIGNMENT_CENTER;};
83 
84 private:
85 
86 	UT_sint32	m_startPosition;
87 };
88 
89 class ABI_EXPORT fb_Alignment_right : public fb_Alignment
90 {
91 public:
92 
93 	void		initialize(fp_Line *pLine);
94 	UT_sint32	getStartPosition();
95 	void		eraseLineFromRun(fp_Line *pLine, UT_uint32 runIndex);
getType()96     FB_AlignmentType getType(){return FB_ALIGNMENT_RIGHT;};
97 
98 private:
99 
100 	UT_sint32	m_startPosition;
101 };
102 
103 class ABI_EXPORT fb_Alignment_justify : public fb_Alignment
104 {
105 public:
106 
107 	void		initialize(fp_Line *pLine);
108 	UT_sint32	getStartPosition();
109 	void		eraseLineFromRun(fp_Line *pLine, UT_uint32 runIndex);
getType()110     FB_AlignmentType getType(){return FB_ALIGNMENT_JUSTIFY;};
111 
112 private:
113 
114 	int			m_iSpaceCountLeft;
115 	int			m_iSpaceCount;
116 	int			m_iExtraWidth;
117 	UT_sint32	m_iStartPosition;
118 
119 
120 };
121 
122 #endif /* FB_ALIGNMENT_H */
123