API  1.0.0
CPParagraphStyle.j
Go to the documentation of this file.
1 /*
2  * CPParagraphStyle.j
3  * AppKit
4  *
5  * FIXME
6  * This is basically a stub.
7  * We need to store all the spacing informations as well as writing direction (among others)
8  *
9  * Created by Daniel Boehringer on 11/01/2014
10  * Copyright Daniel Boehringer 2014.
11  *
12  * This library is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public
14  * License as published by the Free Software Foundation; either
15  * version 2.1 of the License, or (at your option) any later version.
16  *
17  * This library is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  * Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public
23  * License along with this library; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25  */
26 
27 
28 
30 
31 CPParagraphStyleAttributeName = @"CPParagraphStyleAttributeName";
32 
33 var _sharedDefaultParagraphStyle,
34  _defaultTabStopArray;
35 
36 @implementation CPParagraphStyle : CPObject
37 {
38  CPArray _tabStops;
39  CPTextAlignment _alignment;
40  unsigned _firstLineHeadIndent;
41  unsigned _headIndent;
42  unsigned _tailIndent;
43  unsigned _paragraphSpacing;
44  unsigned _minimumLineHeight;
45  unsigned _maximumLineHeight;
46  unsigned _lineSpacing;
47 }
48 
49 
50 #pragma mark -
51 #pragma mark Class methods
52 
53 + (CPParagraphStyle)defaultParagraphStyle
54 {
55  if (!_sharedDefaultParagraphStyle)
56  _sharedDefaultParagraphStyle = [self new];
57 
58  return _sharedDefaultParagraphStyle;
59 }
60 
61 + (CPArray)_defaultTabStops
62 {
63  if (!_defaultTabStopArray)
64  {
65  var i;
66  _defaultTabStopArray = [];
67 
68  // <!> FIXME: Define constants for these magic numbers: 13, 28
69  for (i = 1; i < 16 ; i++)
70  {
71  _defaultTabStopArray.push([[CPTextTab alloc] initWithType:CPLeftTabStopType location:i * 28]);
72  }
73  }
74 
75  return _defaultTabStopArray;
76 }
77 
78 
79 #pragma mark -
80 #pragma mark Init methods
81 
82 - (id)init
83 {
84  [self _initWithDefaults];
85 
86  return self;
87 }
88 
89 - (CPParagraphStyle)initWithParagraphStyle:(CPParagraphStyle)other
90 {
91  self = [super init];
92 
93  _tabStops = [other._tabStops copy];
94  _alignment = other._alignment;
95  _firstLineHeadIndent = other._firstLineHeadIndent;
96  _headIndent = other._headIndent;
97  _tailIndent = other._tailIndent;
98  _paragraphSpacing = other._paragraphSpacing;
99  _minimumLineHeight = other._minimumLineHeight;
100  _maximumLineHeight = other._maximumLineHeight;
101  _lineSpacing = other._lineSpacing;
102 
103  return self;
104 }
105 
106 - (void)_initWithDefaults
107 {
108  _alignment = CPLeftTextAlignment;
109  _tabStops = [[[self class] _defaultTabStops] copy];
110 }
111 
112 - (void)addTabStop:(CPTextTab)aStop
113 {
114  _tabStops.push(aStop);
115 }
116 
117 - (id)copy
118 {
119  var other = [[self class] alloc];
120 
121  return [other initWithParagraphStyle:self];
122 }
123 
124 @end
125 
126 
127 var CPParagraphStyleTabStopsKey = @"CPParagraphStyleTabStopsKey",
128  CPParagraphStyleAlignmentKey = @"CPParagraphStyleAlignmentKey",
129  CPParagraphStyleFirstLineHeadIndentKey = @"CPParagraphStyleFirstLineHeadIndentKey",
130  CPParagraphStyleHeadIndentKey = @"CPParagraphStyleHeadIndentKey",
131  CPParagraphStyleTailIndentKey = @"CPParagraphStyleTailIndentKey",
132  CPParagraphStyleParagraphSpacingKey = @"CPParagraphStyleParagraphSpacingKey",
133  CPParagraphStyleMinimumLineHeightKey = @"CPParagraphStyleMinimumLineHeightKey",
134  CPParagraphStyleMaximumLineHeightKey = @"CPParagraphStyleMaximumLineHeightKey",
135  CPParagraphStyleLineSpacingKey = @"CPParagraphStyleLineSpacingKey";
136 
138 
139 - (id)initWithCoder:(id)aCoder
140 {
141  self = [self init];
142 
143  if (self)
144  {
145  _tabStops = [aCoder decodeObjectForKey:"CPParagraphStyleTabStopsKey"];
146  _alignment = [aCoder decodeIntForKey:"CPParagraphStyleAlignmentKey"];
147  _firstLineHeadIndent = [aCoder decodeIntForKey:"CPParagraphStyleFirstLineHeadIndentKey"];
148  _headIndent = [aCoder decodeIntForKey:"CPParagraphStyleHeadIndentKey"];
149  _tailIndent = [aCoder decodeIntForKey:"CPParagraphStyleTailIndentKey"];
150  _paragraphSpacing = [aCoder decodeIntForKey:"CPParagraphStyleParagraphSpacingKey"];
151  _minimumLineHeight = [aCoder decodeIntForKey:"CPParagraphStyleMinimumLineHeightKey"];
152  _maximumLineHeight = [aCoder decodeIntForKey:"CPParagraphStyleMaximumLineHeightKey"];
153  _lineSpacing = [aCoder decodeIntForKey:"CPParagraphStyleLineSpacingKey"];
154  }
155 
156  return self;
157 }
158 
159 - (void)encodeWithCoder:(id)aCoder
160 {
161  [aCoder encodeInt:_alignment forKey:"CPParagraphStyleAlignmentKey"];
162  [aCoder encodeObject:_tabStops forKey:"CPParagraphStyleTabStopsKey"];
163  [aCoder encodeInt:_firstLineHeadIndent forKey:"CPParagraphStyleFirstLineHeadIndentKey"];
164  [aCoder encodeInt:_headIndent forKey:"CPParagraphStyleHeadIndentKey"];
165  [aCoder encodeInt:_tailIndent forKey:"CPParagraphStyleTailIndentKey"];
166  [aCoder encodeInt:_paragraphSpacing forKey:"CPParagraphStyleParagraphSpacingKey"];
167  [aCoder encodeInt:_minimumLineHeight forKey:"CPParagraphStyleMinimumLineHeightKey"];
168  [aCoder encodeInt:_maximumLineHeight forKey:"CPParagraphStyleMaximumLineHeightKey"];
169  [aCoder encodeInt:_lineSpacing forKey:"CPParagraphStyleLineSpacingKey"];
170 }
171 
172 
173 @end
174 
175 
176 @implementation CPTextTab : CPObject
177 {
178  int _type;
179  double _location;
180 }
181 
182 - (id)initWithType:(CPTabStopType) aType location:(double) aLocation
183 {
184  if ([self = [super init]])
185  {
186  _type = aType;
187  _location = aLocation;
188  }
189 
190  return self;
191 }
192 
193 @end
194 
195 
196 var CPTextTabTypeKey = @"CPTextTabTypeKey",
197  CPTextTabLocationKey = @"CPTextTabLocationKey";
198 
199 @implementation CPTextTab (CPCoding)
200 
201 - (id)initWithCoder:(id)aCoder
202 {
203  self = [self init];
204 
205  if (self)
206  {
207  _type = [aCoder decodeIntForKey:"CPTextTabTypeKey"];
208  _location = [aCoder decodeDoubleForKey:"CPTextTabLocationKey"];
209  }
210 
211  return self;
212 }
213 
214 - (void)encodeWithCoder:(id)aCoder
215 {
216  [aCoder encodeInt:_type forKey:"CPTextTabTypeKey"];
217  [aCoder encodeDouble:_location forKey:"CPTextTabLocationKey"];
218 }
219 
220 @end
221 
223 
227 - (CPArray)tabStops
228 {
229  return _tabStops;
230 }
231 
235 - (void)setTabStops:(CPArray)aValue
236 {
237  _tabStops = aValue;
238 }
239 
243 - (CPTextAlignment)alignment
244 {
245  return _alignment;
246 }
247 
251 - (void)setAlignment:(CPTextAlignment)aValue
252 {
253  _alignment = aValue;
254 }
255 
259 - (unsigned)firstLineHeadIndent
260 {
261  return _firstLineHeadIndent;
262 }
263 
267 - (void)setFirstLineHeadIndent:(unsigned)aValue
268 {
269  _firstLineHeadIndent = aValue;
270 }
271 
275 - (unsigned)headIndent
276 {
277  return _headIndent;
278 }
279 
283 - (void)setHeadIndent:(unsigned)aValue
284 {
285  _headIndent = aValue;
286 }
287 
291 - (unsigned)tailIndent
292 {
293  return _tailIndent;
294 }
295 
299 - (void)setTailIndent:(unsigned)aValue
300 {
301  _tailIndent = aValue;
302 }
303 
307 - (unsigned)paragraphSpacing
308 {
309  return _paragraphSpacing;
310 }
311 
315 - (void)setParagraphSpacing:(unsigned)aValue
316 {
317  _paragraphSpacing = aValue;
318 }
319 
323 - (unsigned)minimumLineHeight
324 {
325  return _minimumLineHeight;
326 }
327 
331 - (void)setMinimumLineHeight:(unsigned)aValue
332 {
333  _minimumLineHeight = aValue;
334 }
335 
339 - (unsigned)maximumLineHeight
340 {
341  return _maximumLineHeight;
342 }
343 
347 - (void)setMaximumLineHeight:(unsigned)aValue
348 {
349  _maximumLineHeight = aValue;
350 }
351 
355 - (unsigned)lineSpacing
356 {
357  return _lineSpacing;
358 }
359 
363 - (void)setLineSpacing:(unsigned)aValue
364 {
365  _lineSpacing = aValue;
366 }
367 
368 @end
369 
371 
375 - (int)tabStopType
376 {
377  return _type;
378 }
379 
383 - (void)setTabStopType:(int)aValue
384 {
385  _type = aValue;
386 }
387 
391 - (double)location
392 {
393  return _location;
394 }
395 
399 - (void)setLocation:(double)aValue
400 {
401  _location = aValue;
402 }
403 
404 @end
id init()
Definition: CALayer.j:126
var CPParagraphStyleTabStopsKey
var CPParagraphStyleFirstLineHeadIndentKey
CPParagraphStyleAttributeName
var CPTextTabTypeKey
var CPParagraphStyleAlignmentKey
CPLeftTabStopType
var CPParagraphStyleTailIndentKey
var CPTextTabLocationKey
var CPParagraphStyleMinimumLineHeightKey
id init()
Definition: CPObject.j:145
CPParagraphStyle initWithParagraphStyle:(CPParagraphStyle other)
id new()
Definition: CPObject.j:122
var CPParagraphStyleMaximumLineHeightKey
CPTextAlignment CPLeftTextAlignment
Definition: CPText.j:76
var CPParagraphStyleLineSpacingKey
Class class()
Definition: CPObject.j:179
var CPParagraphStyleHeadIndentKey
var CPParagraphStyleParagraphSpacingKey