1/*
2 Project: Graphos
3 GRPathObject.m
4
5 Copyright (C) 2008-2018 GNUstep Application Project
6
7 Author: Ing. Riccardo Mottola
8
9 Created: 2008-03-14
10
11 This application is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public
13 License as published by the Free Software Foundation; either
14 version 2 of the License, or (at your option) any later version.
15
16 This application is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 Library General Public License for more details.
20
21 You should have received a copy of the GNU General Public
22 License along with this library; if not, write to the Free
23 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
24 */
25
26#import "GRPathObject.h"
27
28
29@implementation GRPathObject
30
31- (id)copyWithZone:(NSZone *)zone
32{
33  GRPathObject *objCopy;
34
35  objCopy = [super copyWithZone:zone];
36  objCopy->displayPath = [displayPath copy];
37  objCopy->path = [path copy];
38  objCopy->linewidth = linewidth;
39  objCopy->flatness = flatness;
40  objCopy->miterlimit = miterlimit;
41  objCopy->linejoin = linejoin;
42  objCopy->linecap = linecap;
43  [objCopy setCurrentPoint:[self currentPoint]];
44
45  return objCopy;
46}
47
48- (void)dealloc
49{
50  [path release];
51  [displayPath release];
52  [super dealloc];
53}
54
55- (id)initInView:(GRDocView *)aView
56      zoomFactor:(CGFloat)zf
57      withProperties:(NSDictionary *)properties
58{
59  self = [super initInView:aView zoomFactor:zf withProperties:properties];
60  if(self)
61    {
62      id val;
63
64      path = [[NSBezierPath bezierPath] retain];
65      [path setCachesBezierPath: NO];
66      displayPath = [[NSBezierPath bezierPath] retain];
67      [displayPath setCachesBezierPath: NO];
68
69      flatness = 0.6;
70      miterlimit = 10.0;
71      linewidth = 1.5;
72      linejoin = 0;
73      linecap = 0;
74
75      val = [properties objectForKey: @"flatness"];
76      if (val != nil)
77	[self setFlat: [val floatValue]];
78
79      val = [properties objectForKey: @"linejoin"];
80      if (val != nil)
81	[self setLineJoin: [val intValue]];
82
83      val = [properties objectForKey: @"linecap"];
84      if (val != nil)
85	[self setLineCap: [val intValue]];
86
87      val = [properties objectForKey: @"miterlimit"];
88      if (val != nil)
89	[self setMiterLimit: [val floatValue]];
90
91      val = [properties objectForKey: @"linewidth"];
92      if (val != nil)
93        [self setLineWidth: [val floatValue]];
94    }
95  return self;
96}
97
98- (id)initFromData:(NSDictionary *)description
99            inView:(GRDocView *)aView
100        zoomFactor:(CGFloat)zf
101{
102  self = [super initFromData:description inView:aView zoomFactor:zf];
103  if(self)
104    {
105      path = [[NSBezierPath bezierPath] retain];
106      [path setCachesBezierPath: NO];
107      displayPath = [[NSBezierPath bezierPath] retain];
108      [displayPath setCachesBezierPath: NO];
109
110      flatness = [[description objectForKey: @"flatness"] floatValue];
111      linejoin = [[description objectForKey: @"linejoin"] intValue];
112      linecap = [[description objectForKey: @"linecap"] intValue];
113      miterlimit = [[description objectForKey: @"miterlimit"] floatValue];
114      linewidth = [[description objectForKey: @"linewidth"] floatValue];
115    }
116  return self;
117}
118
119- (void)setCurrentPoint:(GRObjectControlPoint *)aPoint
120{
121    currentPoint = aPoint;
122}
123
124- (GRObjectControlPoint *)currentPoint
125{
126    return currentPoint;
127}
128
129- (void)setLineWidth:(CGFloat)width
130{
131  linewidth = width;
132}
133
134- (CGFloat)lineWidth
135{
136  return linewidth;
137}
138
139- (void)setFlat:(CGFloat)flat
140{
141  flatness = flat;
142}
143
144- (CGFloat)flatness
145{
146  return flatness;
147}
148
149- (void)setLineJoin:(NSLineJoinStyle)join
150{
151  linejoin = join;
152}
153
154- (NSLineJoinStyle)lineJoin
155{
156  return linejoin;
157}
158
159- (void)setLineCap:(NSLineCapStyle)cap
160{
161  linecap = cap;
162}
163
164- (NSLineCapStyle)lineCap
165{
166  return linecap;
167}
168
169- (void)setMiterLimit:(CGFloat)limit
170{
171  miterlimit = limit;
172}
173
174- (CGFloat)miterLimit
175{
176  return miterlimit;
177}
178
179- (void)remakePath
180{
181}
182
183@end
184