1 /**
2  *  Yudit Unicode Editor Source File
3  *
4  *  GNU Copyright (C) 1997-2006  Gaspar Sinai <gaspar@yudit.org>
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License, version 2,
8  *  dated June 1991. See file COPYYING for details.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19 
20 #ifndef SParagraph_h
21 #define SParagraph_h
22 
23 #include "stoolkit/SGlyph.h"
24 #include "stoolkit/STypes.h"
25 
26 class SParagraph
27 {
28 public:
29   SParagraph(void);
30   SParagraph(const SParagraph& paragraph);
31 
32   ~SParagraph();
33 
34   SParagraph(const SV_UCS4& buffer, unsigned int *index);
35   SParagraph* subParagraph(unsigned int from, unsigned int to) const;
36 
37   inline unsigned int size() const;
38   inline unsigned int softSize() const;
39   inline SS_UCS4 softCharAt (unsigned int pos) const;
40 
41   inline const SGlyph& operator [] (unsigned int index) const;
42   inline const SGlyph* peek (unsigned int index) const;
43   inline bool isExpanded () const;
44 
45   void append(const SGlyph& glyph);
46   void insert(unsigned int into, const SGlyph& glyph);
47   void remove(unsigned int from, unsigned int to);
48   void remove(unsigned int at);
49   void truncate(unsigned int to);
50   void replace(unsigned int at, const SGlyph& glyph);
51 
52   bool setParagraphSeparator (SS_ParaSep ps);
getParagraphSeparator()53   SS_ParaSep getParagraphSeparator () { return paraSep; };
54   void setEmbedding(SS_Embedding e);
55 
56   void clear();
57 
58   unsigned int toLogical (unsigned int index);
59   const SV_UINT& getLogicalMap() const;
60 
61   void setLineBreaks (const SV_UCS4& breaks);
62 
63   void select (bool is);
64   void select (bool is, unsigned int from, unsigned int to);
65 
66   void underline (bool is);
67   void underline (bool is, unsigned int from, unsigned int to);
68 
69   bool          isLR() const;
70 
71   bool          isProperLine () const;
72 
73   bool          isVisible() const;
74   void          setVisible();
75 
76   bool          isReordered () const;
77   void          setReordered();
78 
79   unsigned int  properSize() const;
80   SV_UCS4       getChars() const;
81 
82   void          clearChange();
83   unsigned int  getChangeStart() const;
84   unsigned int  getChangeEnd() const;
85 
86 private:
87 
88   void           setIniLevel ();
89 
90   void   setChange(unsigned int from, unsigned int to);
91   void   reShape (unsigned int at);
92   void   reShape ();
93   int    getNonTransparentBefore (unsigned int index) const;
94   int    getNonTransparentAfter (unsigned int index) const;
95 
96   bool   isLineBreak(unsigned int index) const;
97   void   resolveLevels();
98 
99   void   expand() const;
100 
101   bool           visible;
102   bool           reordered;
103   bool           selected;
104   bool           underlined;
105   bool           expanded;
106 
107   SS_Embedding   embedding;
108   unsigned int   iniLevel;
109 
110   SVector<SGlyph>          glyphs;
111   SV_UCS4                  ucs4Glyphs;
112   SV_UINT                  logical;
113 
114   SS_ParaSep     paraSep;
115   SV_UCS4        lineBreaks;
116 
117   unsigned int   changeStart;
118   unsigned int   changeRemaining;
119 
120 };
121 
122 
123 unsigned int
size()124 SParagraph::size() const
125 {
126   if (!expanded) expand();
127   return glyphs.size();
128 }
129 
130 unsigned int
softSize()131 SParagraph::softSize() const
132 {
133   if (!expanded) return ucs4Glyphs.size();
134   return glyphs.size();
135 }
136 
137 SS_UCS4
softCharAt(unsigned int pos)138 SParagraph::softCharAt(unsigned int pos) const
139 {
140   if (!expanded) return ucs4Glyphs[pos];
141   return glyphs.peek(pos)->getFirstChar();
142 }
143 
144 /**
145  * Hopefully noone will do this without expending
146  * thus calling size()
147  */
148 const SGlyph&
149 SParagraph::operator [] (unsigned int index) const
150 {
151   if (!expanded) expand();
152   return glyphs[index];
153 }
154 
155 /**
156  * Hopefully noone will do this without expending
157  * thus calling size()
158  */
159 const SGlyph*
peek(unsigned int index)160 SParagraph::peek (unsigned int index) const
161 {
162   if (!expanded) expand();
163   return glyphs.peek(index);
164 }
165 
166 //
167 // Return true if the line has been split into glpyhs
168 // already. getChars () will not touch expanded flag,
169 // you can use that to safely get chars without
170 // forcing expansion for unexpanded lines.
171 //
172 bool
isExpanded()173 SParagraph::isExpanded () const
174 {
175   return expanded;
176 }
177 
178 
179 #endif /* SParagraph_h */
180