프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / MarkupToPDF / Controls / Text / TextControl.cs @ 8898253f

이력 | 보기 | 이력해설 | 다운로드 (44.3 KB)

1
using MarkupToPDF.Common;
2
using MarkupToPDF.Controls.Common;
3
using MarkupToPDF.Serialize.Core;
4
using MarkupToPDF.Serialize.S_Control;
5
using System;
6
using System.Collections.Generic;
7
using System.ComponentModel;
8
using System.Linq;
9
using System.Text;
10
using System.Threading.Tasks;
11
using System.Windows;
12
using System.Windows.Controls;
13
using System.Windows.Media;
14
using System.Windows.Shapes;
15

    
16
namespace MarkupToPDF.Controls.Text
17
{    
18
    public class TextControl : CommentUserInfo, IDisposable, INotifyPropertyChanged, IPath, ITextControl, IMarkupControlData
19
    {
20
        public event PropertyChangedEventHandler PropertyChanged;
21

    
22
        private const string PART_Grid = "PART_Grid";
23
        private const string PART_Border = "PART_Border";
24
        private const string PART_TextBox = "PART_TextBox";
25
        private const string PART_TextPath = "PART_TextPath";
26
        private const string PART_TextBlock = "PART_TextBlock";
27
        private const string PART_Canvas = "PART_TextControlCanvas";
28
        private const string PART_BaseTextbox_Caret = "Caret";
29
        
30
        //private const string PART_TextPrefix = "PART_TextPrefix";
31
      
32
        public Path Base_TextPath = null;
33
        public Grid Base_Grid = null;
34
        public Border Base_Border = null;
35
        public Canvas Base_Canvas = null;
36
        //public TextBlock Base_TextPrefixBlock = null;
37
        public TextBlock Base_TextBlock = null;
38
        public TextBox Base_TextBox = null;
39
        public Border BaseTextbox_Caret = null;
40

    
41
        public RotateTransform _rotation = null;
42
        public TranslateTransform _translation = null;
43
        public ScaleTransform _scale = null;
44

    
45
        private const double _CloudArcDepth = 0.8;  /// 2018.05.14 added by humkyung
46

    
47
        public override bool IsSelected
48
        {
49
            get
50
            {
51
                return (bool)GetValue(IsSelectedProperty);
52
            }
53
            set
54
            {
55
                SetValue(IsSelectedProperty, value);
56
                OnPropertyChanged("IsSelected");
57
            }
58
        }
59

    
60
        #region Internal Method
61

    
62
        public TextControl()
63
        {
64
            this.DefaultStyleKey = typeof(TextControl);
65
        }
66

    
67
        static TextControl()
68
        {
69
            DefaultStyleKeyProperty.OverrideMetadata(typeof(TextControl), new FrameworkPropertyMetadata(typeof(TextControl)));
70
            ResourceDictionary dictionary = new ResourceDictionary();
71
            dictionary.Source = new Uri("/MarkupToPDF;component/Themes/generic.xaml", UriKind.RelativeOrAbsolute);
72
            Application.Current.Resources.MergedDictionaries.Add(dictionary);
73

    
74
        }
75

    
76

    
77
        public override void OnApplyTemplate()
78
        {
79
            base.OnApplyTemplate();
80

    
81
            Base_TextPath = GetTemplateChild(PART_TextPath) as Path;
82
            Base_TextBox = GetTemplateChild(PART_TextBox) as TextBox;
83
            Base_TextBlock = GetTemplateChild(PART_TextBlock) as TextBlock;
84
            Base_Grid = GetTemplateChild(PART_Grid) as Grid;
85
            Base_Border = GetTemplateChild(PART_Border) as Border;
86
            Base_Canvas = GetTemplateChild(PART_Canvas) as Canvas;
87
            BaseTextbox_Caret = GetTemplateChild(PART_BaseTextbox_Caret) as Border;
88
            this.Base_TextBox.Text = this.Text;
89
            this.Base_TextBox.CaretIndex = this.Base_TextBox.Text.Length;
90
            this.Base_TextBox.CaretBrush = new SolidColorBrush(Colors.Transparent);
91
            this.Base_TextBox.ApplyTemplate();
92
            MoveCustomCaret();
93

    
94
            this.Base_TextBox.SizeChanged += new SizeChangedEventHandler(Base_TextBox_SizeChanged);
95
            this.Base_TextBox.TextChanged += new TextChangedEventHandler(Base_TextBox_TextChanged);
96
            this.Base_TextBlock.SizeChanged += new SizeChangedEventHandler(Base_TextBlock_SizeChanged);
97
            this.Base_TextBox.GotFocus += new RoutedEventHandler(Base_TextBox_GotFocus);
98
            this.Base_TextBox.LostFocus += new RoutedEventHandler(Base_TextBox_LostFocus);            
99
            this.Base_TextBox.SelectionChanged += (sender, e) => MoveCustomCaret();
100
            
101
            
102
            SetText();
103
            DrawingCloud();
104

    
105

    
106

    
107
        }
108

    
109
        
110

    
111

    
112

    
113
        /// <summary>
114
        /// Moves the custom caret on the canvas.
115
        /// </summary>
116
        public void MoveCustomCaret()
117
        {
118

    
119
            var caretLocation = this.Base_TextBox.GetRectFromCharacterIndex(this.Base_TextBox.CaretIndex).Location;
120

    
121
            if (!double.IsInfinity(caretLocation.X)) {
122
                Canvas.SetLeft(this.BaseTextbox_Caret, caretLocation.X);
123
            }
124

    
125
            if (!double.IsInfinity(caretLocation.Y)) {
126
                Canvas.SetTop(this.BaseTextbox_Caret, caretLocation.Y);
127
            }
128
        }
129

    
130
        
131

    
132
        public override void ApplyOverViewData()
133
        {
134
            this.OverViewPathData = this.PathData;
135
            if (Text == "")
136
                this.Text = this.OverViewText;
137
            else
138
                this.OverViewText = this.Text;
139
            
140
            this.OverViewPaint = this.Paint;
141

    
142
        }        
143

    
144
        void Base_TextBox_SizeChanged(object sender, SizeChangedEventArgs e)
145
        {
146
            BoxWidth = e.NewSize.Width;
147
            BoxHeight = e.NewSize.Height;
148

    
149
            DrawingCloud();
150
        }
151
        private void Base_TextBlock_SizeChanged(object sender, SizeChangedEventArgs e)
152
        {
153
            BoxWidth = e.NewSize.Width;
154
            BoxHeight = e.NewSize.Height;
155

    
156
            DrawingCloud();
157
        }
158
        private void Base_TextBox_TextChanged(object sender, TextChangedEventArgs e)
159
        {
160
            if (IsEditingMode)
161
            {
162
                if (Base_TextBox.Text.Contains("|OR||DZ|"))
163
                {
164
                    Base_TextBox.Text = this.Text;
165
                }
166

    
167
                this.Text = Base_TextBox.Text;
168

    
169
            }            
170
            DrawingCloud();
171
        }
172
        void Base_TextBox_GotFocus(object sender, RoutedEventArgs e)
173
        {
174
            this.BaseTextbox_Caret.Visibility = Visibility.Visible;
175
            this.IsEditingMode = true;
176
        }
177

    
178
        void Base_TextBox_LostFocus(object sender, RoutedEventArgs e)
179
        {
180
            this.Text = Base_TextBox.Text;
181
            this.BaseTextbox_Caret.Visibility = Visibility.Collapsed;
182
            this.IsEditingMode = false;
183
            ApplyOverViewData();
184
        }
185

    
186
        //void TextControl_GotFocus(object sender, RoutedEventArgs e)
187
        //{
188
        //    Base_TextBox.Visibility = Visibility.Visible;
189
        //    Base_TextBlock.Visibility = Visibility.Collapsed;
190
        //    this.Base_TextBox.BorderThickness = new Thickness(1);
191
        //    if (UnderLine != null)
192
        //    {
193
        //        Base_TextBlock.TextDecorations = UnderLine;
194
        //    }
195
        //    if (this.Text != null)
196
        //    {
197
        //        Base_TextBox.Text = this.Text;
198
        //    }
199
        //    IsEditing = true;
200
        //}
201
        //void TextControl_LostFocus(object sender, RoutedEventArgs e)
202
        //{
203
        //    Base_TextBox.Visibility = Visibility.Collapsed;
204
        //    Base_TextBlock.Visibility = Visibility.Visible;
205
        //    this.Text = Base_TextBox.Text;
206
        //    if (UnderLine != null)
207
        //    {
208
        //        Base_TextBlock.TextDecorations = UnderLine;
209
        //    }
210
        //    Base_TextBlock.Margin =
211
        //       new Thickness(Base_TextBox.Margin.Left + 4, Base_TextBox.Margin.Top + 4, Base_TextBox.Margin.Right + 4, Base_TextBox.Margin.Bottom + 4);
212
        //    IsEditing = false;
213
        //}
214
        public void EditingMode()
215
        {            
216
            TextBoxVisibility = Visibility.Visible;
217
            TextBlockVisibility = Visibility.Collapsed;
218
            this.BaseTextbox_Caret.Visibility = Visibility.Visible;
219

    
220
            if (UnderLine != null)
221
                Base_TextBlock.TextDecorations = UnderLine;
222

    
223
        }
224

    
225
        public void UnEditingMode()
226
        {            
227
            TextBoxVisibility = Visibility.Collapsed;         
228
            TextBlockVisibility = Visibility.Visible; 
229
            this.BaseTextbox_Caret.Visibility = Visibility.Collapsed;
230

    
231
            if (UnderLine != null)
232
                Base_TextBlock.TextDecorations = UnderLine;
233

    
234
            
235
        }
236
        public void SetText()
237
        {
238
            if (IsHighLight)
239
            {
240
                this.BackInnerColor = new SolidColorBrush(Color.FromArgb(Convert.ToByte(255 * 0.6),
241
                    Colors.Yellow.R, Colors.Yellow.G, Colors.Yellow.B));
242
                this.BackColor = new SolidColorBrush(Color.FromArgb(Convert.ToByte(255 * 0.1),
243
                    Colors.Yellow.R, Colors.Yellow.G, Colors.Yellow.B));
244
            }
245
            else
246
            {
247
                this.BackInnerColor = new SolidColorBrush(Color.FromArgb(Convert.ToByte(255 * 0.6),
248
                    Colors.White.R, Colors.White.G, Colors.White.B));
249

    
250
                this.BackColor = new SolidColorBrush(Color.FromArgb(Convert.ToByte(255 * 0.1),
251
                    Colors.White.R, Colors.White.G, Colors.White.B));
252
            }
253
            if (Base_TextPath != null)
254
            {
255
                Base_TextPath.StrokeThickness = LineSize.Left;
256
            }
257
            
258
        }
259

    
260
        public void DrawingCloud()
261
        {
262
            
263
            List<Point> pCloud = new List<Point>
264
            {
265
                new Point(0, 0),
266
                new Point(0, 0 + BoxHeight + 0),
267
                new Point(0 + BoxWidth + 2, 0 + BoxHeight + 0),
268
                new Point(0 + BoxWidth + 2 ,0)
269
            };
270
            //this.Base_TextBox.Select(Base_TextBox.Text.Length, 0);
271
            if (Base_TextPath != null)
272
            {
273
                switch (ControlType_No)
274
                {
275
                    case 0:
276
                        {
277
                            PathData = new PathGeometry();
278
                            PathDataInner = (GenerateInner(pCloud));
279
                        }
280
                        break;
281
                    case 1:
282
                        {
283
                            PathData = (Generate_Rect(pCloud));
284
                            List<Point> pCloud2 = new List<Point>
285
                            {
286
                                new Point(0, 0),
287
                                new Point(0, 0 + BoxHeight + 0),
288
                                new Point(0 + BoxWidth + 10, 0 + BoxHeight + 0),
289
                                new Point(0 + BoxWidth + 10 ,0)
290
                            };
291
                            PathDataInner = (GenerateInner(pCloud));
292
                        }
293
                        break;
294
                    case 2:
295
                        {
296
                            PathData = (Generate(pCloud));
297
                            PathDataInner = (GenerateInner(pCloud));
298
                        }
299
                        break;
300
                }
301
            }
302

    
303
            //SetText();
304
        }
305
        #endregion Internal Method
306

    
307
        public void Dispose()
308
        {
309
            GC.Collect();
310
            GC.SuppressFinalize(this);
311
        }
312

    
313
        public override void UpdateControl()
314
        {
315
            if (this.PointSet.Count > 1)
316
            {
317
                this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y);
318
                this.EndPoint = new Point(this.PointSet[1].X, this.PointSet[1].Y);
319
            }
320
        }
321

    
322
        #region Drawing Cloud Method
323
        public static PathGeometry Generate_Rect(List<Point> pData)
324
        {
325
            PathFigure pathFigure = new PathFigure();
326
            pathFigure.StartPoint = pData[0];
327

    
328
            PolyLineSegment polyline = new PolyLineSegment(pData, true);
329
            pathFigure.Segments.Add(polyline);
330

    
331
            PathGeometry rectPathGeometry = new PathGeometry();
332
            rectPathGeometry.Figures = new PathFigureCollection();
333
            pathFigure.IsClosed = true;
334
            pathFigure.IsFilled = false;
335
            rectPathGeometry.Figures.Add(pathFigure);
336

    
337

    
338
            return rectPathGeometry;
339
        }
340

    
341
        public static PathGeometry Generate(List<Point> pData)
342
        {
343
            var _pathGeometry = new PathGeometry();
344
            double area = MathSet.AreaOf(pData);
345
            bool reverse = (area > 0);
346
            int count = pData.Count;
347
            for (int i = 0; i < count; i++)
348
            {
349
                PathFigure pathFigure = GenerateLineWithCloud(pData[i % count], pData[(i + 1) % count], 20, reverse);
350
                pathFigure.IsClosed = false;
351
                pathFigure.IsFilled = true;
352
                _pathGeometry.Figures.Add(pathFigure);
353
            }
354

    
355
            return _pathGeometry;
356
        }
357

    
358

    
359
        public static PathGeometry GenerateInner(List<Point> pData)
360
        {
361
            var _pathGeometry = new PathGeometry();
362
            double area = MathSet.AreaOf(pData);
363
            bool reverse = (area > 0);
364
            int count = pData.Count;
365

    
366
            PathFigure pathFigur2 = new PathFigure();
367
            pathFigur2.StartPoint = pData[0];
368

    
369
            PolyLineSegment polyline = new PolyLineSegment(pData, true);
370
            pathFigur2.Segments.Add(polyline);
371

    
372
            pathFigur2.IsClosed = true;
373
            pathFigur2.IsFilled = true;
374
            _pathGeometry.Figures.Add(pathFigur2);
375

    
376
            return _pathGeometry;
377
        }
378

    
379
        public static PathFigure GenerateLineWithCloud(Point p1, Point p2, double _arcLength, bool reverse)
380
        {
381
            PathFigure pathFigure = new PathFigure();
382
            pathFigure.StartPoint = p1;
383

    
384
            double arcLength = _arcLength;
385
            double dx = p2.X - p1.X;
386
            double dy = p2.Y - p1.Y;
387
            double l = MathSet.DistanceTo(p1, p2);
388
            double theta = Math.Atan2(Math.Abs(dy), Math.Abs(dx)) * 180 / Math.PI;
389
            Point lastPt = new Point(p1.X, p1.Y);
390
            double count = l / _arcLength;
391

    
392
            dx /= l;
393
            dy /= l;
394

    
395
            Double j = 1;
396
            for (j = 1; j < (count - 1); j++)
397
            {
398
                ArcSegment arcSeg = new ArcSegment();
399
                arcSeg.Size = new Size(arcLength * TextControl._CloudArcDepth, arcLength * TextControl._CloudArcDepth);
400
                arcSeg.Point = new Point(p1.X + j * dx * arcLength, p1.Y + j * dy * arcLength);
401
                lastPt = arcSeg.Point;
402
                arcSeg.RotationAngle = theta + 90;
403
                if (true == reverse)
404
                    arcSeg.SweepDirection = SweepDirection.Clockwise;
405
                pathFigure.Segments.Add(arcSeg);
406
            }
407

    
408
            if ((count > j) || count > 0)
409
            {
410
                arcLength = MathSet.DistanceTo(lastPt, p2);
411
                ArcSegment arcSeg = new ArcSegment();
412
                arcSeg.Size = new Size(arcLength * TextControl._CloudArcDepth, arcLength * TextControl._CloudArcDepth);
413
                arcSeg.Point = new Point(p2.X, p2.Y);
414
                arcSeg.RotationAngle = theta;
415

    
416
                if (true == reverse)
417
                    arcSeg.SweepDirection = SweepDirection.Clockwise;
418

    
419
                pathFigure.Segments.Add(arcSeg);
420

    
421
            }
422
            return pathFigure;
423
        }
424
        #endregion
425

    
426
        #region Dependency Properties
427
        public static readonly DependencyProperty ControlTypeProperty =
428
        DependencyProperty.Register("ControlType", typeof(ControlType), typeof(TextControl), new FrameworkPropertyMetadata(ControlType.TextControl));
429

    
430
        public static readonly DependencyProperty ControlType_NoProperty =
431
        DependencyProperty.Register("ControlType_No", typeof(int), typeof(TextControl), new FrameworkPropertyMetadata(0));
432

    
433
        public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register(
434
            "IsSelected", typeof(bool), typeof(TextControl), new FrameworkPropertyMetadata(false, IsSelectedChanged));
435

    
436
        public static readonly DependencyProperty PathGeometryProperty = DependencyProperty.Register(
437
            "PathGeometry", typeof(PathGeometry), typeof(TextControl), new PropertyMetadata(null, SetPathGeometryChanged));
438

    
439
        public static readonly DependencyProperty TextProperty = DependencyProperty.Register(
440
            "Text", typeof(string), typeof(TextControl), new PropertyMetadata(null));
441

    
442
        public static readonly DependencyProperty OverViewTextProperty = DependencyProperty.Register(
443
            "OverViewText", typeof(string), typeof(TextControl), new PropertyMetadata(null, new PropertyChangedCallback(TextChanged)));
444

    
445
        public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register(
446
            "UserID", typeof(string), typeof(TextControl), new PropertyMetadata(null));
447

    
448
        /*public static readonly DependencyProperty FontColorProperty = DependencyProperty.Register(
449
            "FontColor", typeof(SolidColorBrush), typeof(TextControl), new PropertyMetadata(new SolidColorBrush(Colors.Red)));*/
450

    
451
        public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register(
452
            "StrokeColor", typeof(SolidColorBrush), typeof(TextControl), new PropertyMetadata(new SolidColorBrush(Colors.Red)));
453

    
454
        //강인구 추가
455
        public static readonly DependencyProperty IsHighlightProperty = DependencyProperty.Register(
456
            "IsHighLight", typeof(bool), typeof(TextControl), new PropertyMetadata(false, PointValueChanged));
457

    
458
        public static readonly DependencyProperty BackColorProperty = DependencyProperty.Register(
459
            "BackColor", typeof(SolidColorBrush), typeof(TextControl), new PropertyMetadata(new SolidColorBrush(Colors.White)));
460

    
461
        public static readonly DependencyProperty BackInnerColorProperty = DependencyProperty.Register(
462
            "BackInnerColor", typeof(SolidColorBrush), typeof(TextControl), new PropertyMetadata(new SolidColorBrush(Colors.White)));
463

    
464
        public static readonly DependencyProperty UnderLineProperty = DependencyProperty.Register(
465
            "UnderLine", typeof(TextDecorationCollection), typeof(TextControl), new PropertyMetadata(null));
466

    
467
        public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register(
468
            "LineSize", typeof(Thickness), typeof(TextControl), new PropertyMetadata(new Thickness(4), PointValueChanged)); //여기만 4인지 모르겠지만 4 그대로 두겠음
469

    
470
        public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register(
471
            "PointSet", typeof(List<Point>), typeof(TextControl), new PropertyMetadata(new List<Point>()));
472

    
473
        public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register(
474
            "PathData", typeof(Geometry), typeof(TextControl), null);
475

    
476

    
477

    
478
        public static readonly DependencyProperty PathDataInnerProperty = DependencyProperty.Register(
479
    "PathDataInner", typeof(Geometry), typeof(TextControl), null);
480

    
481
        public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register(
482
            "OverViewPathDataProperty", typeof(Geometry), typeof(TextControl), null);
483

    
484
        public static readonly DependencyProperty TextStyleProperty = DependencyProperty.Register(
485
            "TextStyle", typeof(FontStyle), typeof(TextControl), new PropertyMetadata(FontStyles.Normal));
486

    
487
        public static readonly DependencyProperty TextFamilyProperty = DependencyProperty.Register(
488
            "TextFamily", typeof(FontFamily), typeof(TextControl), new PropertyMetadata(new FontFamily("Arial")));
489

    
490
        public static readonly DependencyProperty TextWeightProperty = DependencyProperty.Register(
491
            "TextWeight", typeof(FontWeight), typeof(TextControl), new PropertyMetadata(FontWeights.Normal));
492

    
493
        public static readonly DependencyProperty CenterXProperty = DependencyProperty.Register(
494
            "CenterX", typeof(double), typeof(TextControl), new PropertyMetadata((double)0, OnCenterXYChanged));
495

    
496
        public static readonly DependencyProperty CenterYProperty = DependencyProperty.Register(
497
            "CenterY", typeof(double), typeof(TextControl), new PropertyMetadata((double)0, OnCenterXYChanged));
498

    
499
        public static readonly DependencyProperty CanvasXProperty = DependencyProperty.Register(
500
           "CanvasX", typeof(double), typeof(TextControl), new PropertyMetadata((double)0, OnSetCansvasChanged));
501

    
502
        public static readonly DependencyProperty CanvasYProperty = DependencyProperty.Register(
503
            "CanvasY", typeof(double), typeof(TextControl), new PropertyMetadata((double)0, OnSetCansvasChanged));
504

    
505
        public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register(
506
              "StartPoint", typeof(Point), typeof(TextControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
507

    
508
        public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register(
509
             "EndPoint", typeof(Point), typeof(TextControl), new PropertyMetadata(new Point(100, 100), PointValueChanged));
510

    
511
        public static readonly DependencyProperty TextSizeProperty = DependencyProperty.Register(
512
               "TextSize", typeof(Double), typeof(TextControl), new PropertyMetadata((Double)30, PointValueChanged));
513

    
514
        public static readonly DependencyProperty PaintProperty = DependencyProperty.Register(
515
                "Paint", typeof(PaintSet), typeof(TextControl), new PropertyMetadata((PaintSet.None), PointValueChanged));
516

    
517
        public static readonly DependencyProperty OverViewPaintProperty = DependencyProperty.Register(
518
                "OverViewPaint", typeof(PaintSet), typeof(TextControl), new PropertyMetadata((PaintSet.None), PointValueChanged));
519

    
520
        public static readonly DependencyProperty AngleProperty = DependencyProperty.Register(
521
            "Angle", typeof(double), typeof(TextControl), new PropertyMetadata((double)0.0, new PropertyChangedCallback(AngleValueChanged)));
522

    
523
        public static readonly DependencyProperty EnableEditingProperty = DependencyProperty.Register(
524
           "EnableEditing", typeof(bool), typeof(TextControl), new PropertyMetadata((true), new PropertyChangedCallback(OnIsEditingChanged)));
525

    
526
        public static readonly DependencyProperty TextBoxVisibilityProperty = DependencyProperty.Register(
527
        "TextBoxVisibility", typeof(Visibility), typeof(TextControl), new PropertyMetadata((Visibility.Visible), OnTextBoxVisibilityChanged));
528

    
529
        public static readonly DependencyProperty TextBlockVisibilityProperty = DependencyProperty.Register(
530
        "TextBlockVisibility", typeof(Visibility), typeof(TextControl), new PropertyMetadata((Visibility.Collapsed), OnTextBlockVisibilityChanged));
531

    
532
        #endregion Dependency Properties
533

    
534
        #region dp Properties
535

    
536

    
537
        public override SolidColorBrush StrokeColor
538
        {
539
            get { return (SolidColorBrush)GetValue(StrokeColorProperty); }
540
            set
541
            {
542
                if (this.StrokeColor != value)
543
                {
544
                    SetValue(StrokeColorProperty, value);
545
                }
546
            }
547
        }
548

    
549

    
550

    
551
        public bool EnableEditing
552
        {
553
            get { return (bool)GetValue(EnableEditingProperty); }
554
            set
555
            {
556
                if (this.EnableEditing != value)
557
                {
558
                    SetValue(EnableEditingProperty, value);
559
                    OnPropertyChanged("EnableEditing");
560
                }
561
            }
562
        }
563

    
564
        public Thickness LineSize
565
        {
566
            get
567
            {
568
                return (Thickness)GetValue(LineSizeProperty);
569
            }
570
            set
571
            {
572
                if (this.LineSize != value)
573
                {
574
                    SetValue(LineSizeProperty, value);
575
                    OnPropertyChanged("LineSize");
576
                }
577
            }
578
        }
579

    
580
        public override ControlType ControlType
581
        {
582
            get
583
            {
584
                return (ControlType)GetValue(ControlTypeProperty);
585
            }
586
            set
587
            {
588
                SetValue(ControlTypeProperty, value);
589
            }
590
        }
591
        public int ControlType_No
592
        {
593
            get
594
            {
595
                return (int)GetValue(ControlType_NoProperty);
596
            }
597
            set
598
            {
599
                SetValue(ControlType_NoProperty, value);
600
            }
601
        }
602

    
603
        public string UserID
604
        {
605
            get { return (string)GetValue(UserIDProperty); }
606
            set
607
            {
608
                if (this.UserID != value)
609
                {
610
                    SetValue(UserIDProperty, value);
611
                    OnPropertyChanged("UserID");
612
                }
613
            }
614
        }
615

    
616
        public double CenterX
617
        {
618
            get { return (double)GetValue(CenterXProperty); }
619
            set
620
            {
621
                SetValue(CenterXProperty, value);
622
                OnPropertyChanged("CenterX");
623

    
624
            }
625
        }
626

    
627
        public double CenterY
628
        {
629
            get { return (double)GetValue(CenterYProperty); }
630
            set
631
            {
632
                SetValue(CenterYProperty, value);
633
                OnPropertyChanged("CenterY");
634
            }
635
        }
636

    
637
        public string Text
638
        {
639
            get { return (string)GetValue(TextProperty); }
640
            set
641
            {
642
                if (this.Text != value)
643
                {
644
                    SetValue(TextProperty, value);
645
                    OnPropertyChanged("Text");
646
                }
647
            }
648
        }
649

    
650
        public string OverViewText
651
        {
652
            get { return (string)GetValue(OverViewTextProperty); }
653
            set
654
            {
655
                if (this.OverViewText != value)
656
                {
657
                    SetValue(OverViewTextProperty, value);
658
                    OnPropertyChanged("OverViewText");
659
                }
660
            }
661
        }
662

    
663
        public Geometry OverViewPathData
664
        {
665
            get { return (Geometry)GetValue(OverViewPathDataProperty); }
666
            set
667
            {
668
                if (this.OverViewPathData != value)
669
                {
670
                    SetValue(OverViewPathDataProperty, value);
671
                    OnPropertyChanged("OverViewPathData");
672
                }
673
            }
674
        }
675

    
676
        public Visibility TextBoxVisibility
677
        {
678
            get { return (Visibility)GetValue(TextBoxVisibilityProperty); }
679
            set
680
            {
681
                if (this.TextBoxVisibility != value)
682
                {
683
                    SetValue(TextBoxVisibilityProperty, value);
684
                    OnPropertyChanged("TextBoxVisibility");
685
                }
686
            }
687
        }
688

    
689

    
690
        public Visibility TextBlockVisibility
691
        {
692
            get { return (Visibility)GetValue(TextBlockVisibilityProperty); }
693
            set
694
            {
695
                if (this.TextBlockVisibility != value)
696
                {
697
                    SetValue(TextBlockVisibilityProperty, value);
698
                    OnPropertyChanged("TextBlockVisibility");
699
                }
700
            }
701
        }
702

    
703

    
704

    
705
        public Double TextSize
706
        {
707
            get { return (Double)GetValue(TextSizeProperty); }
708
            set
709
            {
710
                if (this.TextSize != value)
711
                {
712
                    SetValue(TextSizeProperty, value);
713
                    OnPropertyChanged("TextSize");
714
                }
715
            }
716
        }
717
        /*
718
        public SolidColorBrush FontColor
719
        {
720
            get { return (SolidColorBrush)GetValue(FontColorProperty); }
721
            set
722
            {
723
                if (this.FontColor != value)
724
                {
725
                    SetValue(FontColorProperty, value);
726
                    OnPropertyChanged("FontColor");
727
                }
728
            }
729
        }*/
730

    
731
        public SolidColorBrush BackColor
732
        {
733
            get { return (SolidColorBrush)GetValue(BackColorProperty); }
734
            set
735
            {
736
                if (this.BackColor != value)
737
                {
738
                    SetValue(BackColorProperty, value);
739
                    OnPropertyChanged("BackColor");
740
                }
741
            }
742
        }
743

    
744
        public SolidColorBrush BackInnerColor
745
        {
746
            get { return (SolidColorBrush)GetValue(BackInnerColorProperty); }
747
            set
748
            {
749
                if (this.BackInnerColor != value)
750
                {
751
                    SetValue(BackInnerColorProperty, value);
752
                    OnPropertyChanged("BackInnerColor");
753
                }
754
            }
755
        }
756

    
757

    
758

    
759
        public TextDecorationCollection UnderLine
760
        {
761
            get
762
            {
763
                return (TextDecorationCollection)GetValue(UnderLineProperty);
764
            }
765
            set
766
            {
767
                if (this.UnderLine != value)
768
                {
769
                    SetValue(UnderLineProperty, value);
770
                    OnPropertyChanged("UnderLine");
771
                }
772
            }
773
        }
774

    
775
        public double CanvasX
776
        {
777
            get { return (double)GetValue(CanvasXProperty); }
778
            set
779
            {
780
                if (this.CanvasX != value)
781
                {
782
                    SetValue(CanvasXProperty, value);
783
                    OnPropertyChanged("CanvasX");
784
                }
785
            }
786
        }
787

    
788
        public double CanvasY
789
        {
790
            get { return (double)GetValue(CanvasYProperty); }
791
            set
792
            {
793
                if (this.CanvasY != value)
794
                {
795
                    SetValue(CanvasYProperty, value);
796
                    OnPropertyChanged("CanvasY");
797
                }
798
            }
799
        }
800

    
801
        public Point EndPoint
802
        {
803
            get { return (Point)GetValue(EndPointProperty); }
804
            set
805
            {
806
                if (this.EndPoint != value)
807
                {
808
                    SetValue(EndPointProperty, value);
809
                    OnPropertyChanged("EndPoint");
810
                }
811
            }
812
        }
813

    
814
        public Point StartPoint
815
        {
816
            get { return (Point)GetValue(StartPointProperty); }
817
            set
818
            {
819
                if (this.StartPoint != value)
820
                {
821
                    SetValue(StartPointProperty, value);
822
                    OnPropertyChanged("StartPoint");
823
                }
824
            }
825
        }
826

    
827
        public FontStyle TextStyle
828
        {
829
            get { return (FontStyle)GetValue(TextStyleProperty); }
830
            set
831
            {
832
                if (this.TextStyle != value)
833
                {
834
                    SetValue(TextStyleProperty, value);
835
                    OnPropertyChanged("TextStyle");
836
                }
837
            }
838
        }
839

    
840
        public FontFamily TextFamily
841
        {
842
            get { return (FontFamily)GetValue(TextFamilyProperty); }
843
            set
844
            {
845
                if (this.TextFamily != value)
846
                {
847
                    SetValue(TextFamilyProperty, value);
848
                    OnPropertyChanged("TextFamily");
849
                }
850
            }
851
        }
852

    
853
        public FontWeight TextWeight
854
        {
855
            get { return (FontWeight)GetValue(TextWeightProperty); }
856
            set
857
            {
858
                if (this.TextWeight != value)
859
                {
860
                    SetValue(TextWeightProperty, value);
861
                    OnPropertyChanged("TextWeight");
862
                }
863
            }
864
        }
865

    
866
        public PaintSet Paint
867
        {
868
            get { return (PaintSet)GetValue(PaintProperty); }
869
            set
870
            {
871
                if (this.Paint != value)
872
                {
873
                    SetValue(PaintProperty, value);
874
                    OnPropertyChanged("Paint");
875
                }
876
            }
877
        }
878

    
879
        public PaintSet OverViewPaint
880
        {
881
            get { return (PaintSet)GetValue(OverViewPaintProperty); }
882
            set
883
            {
884
                if (this.OverViewPaint != value)
885
                {
886
                    SetValue(OverViewPaintProperty, value);
887
                    OnPropertyChanged("OverViewPaint");
888
                }
889
            }
890
        }
891

    
892
        double IPath.LineSize
893
        {
894
            get
895
            {
896
                return this.LineSize.Left;
897
            }
898
            set
899
            {
900
                this.LineSize = new Thickness(value);
901
                OnPropertyChanged("LineSize");
902
            }
903
        }
904

    
905

    
906
        public Geometry PathData
907
        {
908
            get { return (Geometry)GetValue(PathDataProperty); }
909
            set
910
            {
911
                SetValue(PathDataProperty, value);
912
                OnPropertyChanged("PathData");
913
            }
914
        }
915

    
916
        public Geometry PathDataInner
917
        {
918
            get { return (Geometry)GetValue(PathDataInnerProperty); }
919
            set
920
            {
921
                SetValue(PathDataInnerProperty, value);
922
                OnPropertyChanged("PathDataInner");
923
            }
924
        }
925

    
926
        public override double Angle
927
        {
928
            get { return (double)GetValue(AngleProperty); }
929
            set
930
            {
931
                if (this.Angle != value)
932
                {
933
                    SetValue(AngleProperty, value);
934

    
935
                    OnPropertyChanged("Angle");
936
                    UpdateLayout();
937
                }
938
            }
939
        }
940

    
941
        public bool IsHighLight
942
        {
943
            get { return (bool)GetValue(IsHighlightProperty); }
944
            set
945
            {
946
                if (this.IsHighLight != value)
947
                {
948
                    SetValue(IsHighlightProperty, value);
949
                    OnPropertyChanged("IsHighLight");
950
                }
951
            }
952
        }
953

    
954
        public List<Point> PointSet
955
        {
956
            get { return (List<Point>)GetValue(PointSetProperty); }
957
            set
958
            {
959
                SetValue(PointSetProperty, value);
960
                OnPropertyChanged("PointSet");
961
            }
962
        }
963

    
964
        #endregion Properties
965

    
966
        #region Properties
967

    
968
        private bool _IsEditingMode;
969
        public bool IsEditingMode
970
        {
971
            get
972
            {
973
                return _IsEditingMode;
974
            }
975
            set
976
            {
977
                _IsEditingMode = value;
978
                OnPropertyChanged("IsEditingMode");
979
            }
980
        }
981

    
982
        public PathGeometry PathGeometry
983
        {
984
            get { return (PathGeometry)GetValue(PathGeometryProperty); }
985
            set
986
            {
987
                SetValue(PathGeometryProperty, value);
988
                OnPropertyChanged("PathGeometry");
989
            }
990
        }
991

    
992
        private double _BoxWidth;
993
        public double BoxWidth
994
        {
995
            get
996
            {
997
                return _BoxWidth;
998
            }
999
            set
1000
            {
1001
                _BoxWidth = value;
1002
                OnPropertyChanged("BoxWidth");
1003
            }
1004
        }
1005

    
1006
        private double _BoxHeight;
1007
        public double BoxHeight
1008
        {
1009
            get
1010
            {
1011
                return _BoxHeight;
1012
            }
1013
            set
1014
            {
1015
                _BoxHeight = value;
1016
                OnPropertyChanged("BoxHeight");
1017
            }
1018
        }
1019

    
1020
        #endregion
1021

    
1022
        #region CallBack Method
1023
        public static void SetPathGeometryChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1024
        {
1025
            var instance = (TextControl)sender;
1026

    
1027
            if (e.OldValue != e.NewValue && instance.Base_TextPath != null)
1028
            {
1029
                instance.SetValue(e.Property, e.NewValue);
1030
            }
1031
        }
1032

    
1033

    
1034
        public static void OnTextBoxVisibilityChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1035
        {
1036
            var instance = (TextControl)sender;
1037

    
1038
            if (e.OldValue != e.NewValue && instance.Base_TextPath != null)
1039
            {
1040
                instance.SetValue(e.Property, e.NewValue);
1041
            }
1042
        }
1043

    
1044
        public static void OnTextBlockVisibilityChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1045
        {
1046
            var instance = (TextControl)sender;
1047

    
1048
            if (e.OldValue != e.NewValue && instance.Base_TextPath != null)
1049
            {
1050
                instance.SetValue(e.Property, e.NewValue);
1051
            }
1052
        }
1053

    
1054
        public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1055
        {
1056
            //var instance = (TextControl)sender;
1057

    
1058
            //if (e.OldValue != e.NewValue && instance.Base_Border != null)
1059
            //{
1060
            //    instance.SetValue(e.Property, e.NewValue);
1061

    
1062
            //    if (instance.IsSelected)
1063
            //    {
1064
            //        instance.StrokeColor = new SolidColorBrush(Colors.Blue);
1065
            //        //instance.Base_Border.BorderBrush = new SolidColorBrush(Colors.Blue);
1066
            //    }
1067
            //    else
1068
            //    {
1069
            //        instance.StrokeColor = new SolidColorBrush(Colors.Red);
1070
            //        //instance.Base_Border.BorderBrush = new SolidColorBrush(Colors.Red);
1071
            //        //instance.FontColor = new SolidColorBrush(Colors.Transparent);
1072
            //        //instance.Base_Border.BorderBrush = new SolidColorBrush(Colors.Transparent);
1073
            //    }
1074

    
1075
            //}
1076
        }
1077

    
1078
        public static void OnSetCansvasChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1079
        {
1080
            var instance = (TextControl)sender;
1081

    
1082
            if (e.OldValue != e.NewValue && instance != null)
1083
            {
1084
                instance.SetValue(e.Property, e.NewValue);
1085

    
1086
                Canvas.SetLeft(instance, instance.CanvasX);
1087
                Canvas.SetTop(instance, instance.CanvasY);
1088
            }
1089
        }
1090

    
1091
        public static void OnIsEditingChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1092
        {
1093
            var instance = (TextControl)sender;
1094

    
1095
            if (e.OldValue != e.NewValue && instance.Base_TextBlock != null)
1096
            {
1097
                instance.SetValue(e.Property, e.NewValue);
1098

    
1099
                if (instance.EnableEditing)
1100
                {
1101
                    instance.EditingMode();
1102
                }
1103
                else
1104
                {
1105
                    instance.UnEditingMode();
1106
                }
1107
            }
1108
        }
1109
        public static void TextChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1110
        {
1111
            var instance = (TextControl)sender;
1112

    
1113
            if (e.OldValue != e.NewValue)
1114
            {
1115
                instance.SetValue(e.Property, e.NewValue);
1116
            }
1117
        }
1118

    
1119
        public static void OnCenterXYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1120
        {
1121
            var instance = (TextControl)sender;
1122

    
1123
            if (e.OldValue != e.NewValue && instance.Base_TextBlock != null)
1124
            {
1125
                instance.SetValue(e.Property, e.NewValue);
1126
                //instance.DrawingCloud();
1127
            }
1128
        }
1129

    
1130
        public static void AngleValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1131
        {
1132
            var instance = (TextControl)sender;
1133
            if (e.OldValue != e.NewValue && instance.Base_TextBlock != null)
1134
            {
1135
                instance.SetValue(e.Property, e.NewValue);
1136
                //instance.DrawingCloud();
1137
            }
1138
        }
1139

    
1140
        public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1141
        {
1142
            var instance = (TextControl)sender;
1143
            
1144
            if (e.OldValue != e.NewValue && instance.Base_TextBox != null)
1145
            {                       
1146
                instance.SetText();
1147
                instance.DrawingCloud();
1148
            }
1149

    
1150
        }
1151

    
1152
        #endregion CallBack Method
1153

    
1154
        protected void OnPropertyChanged(string propName)
1155
        {
1156
            if (PropertyChanged != null)
1157
                PropertyChanged(this, new PropertyChangedEventArgs(propName));
1158
        }
1159

    
1160
        /// <summary>
1161
        /// return textcontrols' area
1162
        /// </summary>
1163
        public override Rect ItemRect
1164
        {
1165
            get
1166
            {
1167
                Point start = new Point(this.CanvasX, this.CanvasY);
1168

    
1169
                Point length = new Point();
1170
                double angle = this.Angle * Math.PI / 180;
1171

    
1172
                length.X = this.BoxWidth * Math.Cos(angle) - this.BoxHeight * Math.Sin(angle);
1173
                length.Y = this.BoxWidth * Math.Sin(angle) + this.BoxHeight * Math.Cos(angle);
1174

    
1175
                Point end = new Point(start.X + length.X, start.Y + length.Y);
1176
                return new Rect(start, end);
1177
            }
1178
        }
1179

    
1180
        /// <summary>
1181
        /// translate control along given dx,dy
1182
        /// </summary>
1183
        /// <param name="dx"></param>
1184
        /// <param name="dy"></param>
1185
        public override void OnTranslate(double dx, double dy)
1186
        {
1187
            //this.CanvasX = Canvas.GetLeft(this) + dx;
1188
            //this.CanvasY = Canvas.GetTop(this) + dy;
1189
            this.StartPoint = new Point(this.StartPoint.X + dx, this.StartPoint.Y + dy);
1190
            this.EndPoint = new Point(this.EndPoint.X + dx, this.EndPoint.Y + dy);
1191

    
1192
            this.SetValue(TextControl.CanvasXProperty, Canvas.GetLeft(this) + dx);
1193
            this.SetValue(TextControl.CanvasYProperty, Canvas.GetTop(this) + dy);
1194

    
1195

    
1196

    
1197

    
1198
            //Canvas.SetLeft(this, Canvas.GetLeft(this) + dx);
1199
            //Canvas.SetTop(this, Canvas.GetTop(this) + dy);
1200
        }
1201

    
1202
        /// <summary>
1203
        /// Serialize this
1204
        /// </summary>
1205
        /// <param name="sUserId"></param>
1206
        /// <returns></returns>
1207
        public override string Serialize()
1208
        {
1209
            using (S_TextControl STemp = new S_TextControl())
1210
            {
1211
                STemp.TransformPoint = "0|0";
1212
                STemp.SizeSet = String.Format("{0}|{1}", this.LineSize.Left.ToString(), this.TextSize.ToString());
1213
                STemp.Text = this.Text;
1214
                STemp.UserID = this.UserID;
1215
                STemp.FontColor = this.StrokeColor.Color.ToString();
1216
                //STemp.FontColor = "#FFFFFF00";
1217

    
1218
                if (this.StartPoint == new Point())
1219
                    STemp.StartPoint = new Point(this.CanvasX, this.CanvasY);
1220
                else
1221
                    STemp.StartPoint = this.StartPoint;
1222

    
1223
                STemp.EndPoint = this.EndPoint;
1224
                STemp.Opac = this.Opacity;
1225
                STemp.PointSet = this.PointSet;
1226
                STemp.Angle = this.Angle;
1227
                STemp.paintMethod = this.ControlType_No;
1228
                STemp.BoxW = this.BoxWidth;
1229
                STemp.BoxH = this.BoxHeight;
1230
                STemp.isHighLight = this.IsHighLight;
1231
                STemp.Name = this.GetType().Name.ToString();
1232
                STemp.fontConfig = new List<string>()
1233
                            {
1234
                                this.TextFamily.ToString(),
1235
                                this.TextStyle.ToString(),
1236
                                this.TextWeight.ToString(),
1237
                            };
1238

    
1239

    
1240

    
1241
                if (this.UnderLine != null)
1242
                {
1243
                    STemp.fontConfig.Add("true");
1244
                }
1245

    
1246
                ///강인구 추가(2017.11.02)
1247
                ///Memo 추가
1248
                STemp.Memo = this.Memo;
1249

    
1250
                return "|DZ|" + JsonSerializerHelper.CompressString((STemp.JsonSerialize()));
1251
            }
1252
        }
1253

    
1254
        /// <summary>
1255
        /// create a textcontrol from given string
1256
        /// </summary>
1257
        /// <param name="str"></param>
1258
        /// <returns></returns>
1259
        public static TextControl FromString(string str, SolidColorBrush brush, string sProjectNo)
1260
        {
1261
            using (S_TextControl s = JsonSerializerHelper.JsonDeserialize<S_TextControl>(str))
1262
            {
1263
                string[] data2 = s.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
1264
                TextControl instance = new TextControl()
1265
                {
1266
                    Text = s.Text,
1267
                    StartPoint = s.StartPoint,
1268
                    EndPoint = s.EndPoint,
1269
                    CanvasX = s.StartPoint.X,
1270
                    CanvasY = s.StartPoint.Y,
1271
                    BoxWidth = s.BoxW,
1272
                    BoxHeight = s.BoxH,
1273
                    ControlType_No = s.paintMethod,
1274
                    LineSize = new Thickness(Convert.ToDouble(data2.First())),
1275
                    TextSize = Convert.ToDouble(data2[1]),
1276
                    StrokeColor = brush,
1277
                    FontSize = 10,
1278
                    UserID = s.UserID,
1279
                    IsHighLight = s.isHighLight,
1280
                    Angle = s.Angle,
1281
                    PointSet = s.PointSet,
1282
                    Opacity = s.Opac,
1283
                    TextFamily = new FontFamily(s.fontConfig[0]),
1284
                    //인구 추가(2018.04.17)
1285
                    TextStyle = StringToFont.ConFontStyle(s.fontConfig[1]),
1286
                    TextWeight = StringToFont.ConFontWeight(s.fontConfig[2]),
1287
                };
1288

    
1289
                if (s.fontConfig.Count() == 4)
1290
                {
1291
                    instance.UnderLine = TextDecorations.Underline;
1292
                }
1293

    
1294
                return instance;
1295
            }
1296
        }
1297
    }
1298
}
클립보드 이미지 추가 (최대 크기: 500 MB)