프로젝트

일반

사용자정보

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

markus / MarkupToPDF / Controls / Text / TextControl.cs @ 359bfdbe

이력 | 보기 | 이력해설 | 다운로드 (43.9 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
    [TemplatePart(Name = "PART_TextBox", Type = typeof(TextBox))]
19
    [TemplatePart(Name = "PART_TextBlock", Type = typeof(TextBlock))]
20
    [TemplatePart(Name = "PART_TextPath", Type = typeof(Path))]
21
    [TemplatePart(Name = "PART_Border", Type = typeof(Border))]
22
    [TemplatePart(Name = "PART_Grid", Type = typeof(Grid))]
23
    public class TextControl : CommentUserInfo, INotifyPropertyChanged, IMarkupControlData, IPath
24
    {
25
        public event PropertyChangedEventHandler PropertyChanged;
26

    
27
        private const string PART_Grid = "PART_Grid";
28
        private const string PART_Border = "PART_Border";
29
        private const string PART_TextBox = "PART_TextBox";
30
        private const string PART_TextPath = "PART_TextPath";
31
        private const string PART_TextBlock = "PART_TextBlock";
32
        private const string PART_Canvas = "PART_TextControlCanvas";
33
        //private const string PART_TextPrefix = "PART_TextPrefix";
34

    
35
        public Path Base_TextPath = null;
36
        public Grid Base_Grid = null;
37
        public Border Base_Border = null;
38
        public Canvas Base_Canvas = null;
39
        //public TextBlock Base_TextPrefixBlock = null;
40
        public TextBlock Base_TextBlock = null;
41
        public TextBox Base_TextBox = null;
42

    
43
        public RotateTransform _rotation = null;
44
        public TranslateTransform _translation = null;
45
        public ScaleTransform _scale = null;
46

    
47
        private const double _CloudArcDepth = 0.8;  /// 2018.05.14 added by humkyung
48

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

    
62
        #region Internal Method
63

    
64
        public TextControl()
65
        {
66
            this.DefaultStyleKey = typeof(TextControl);           
67
        }
68

    
69
        static TextControl()
70
        {
71
            DefaultStyleKeyProperty.OverrideMetadata(typeof(TextControl), new FrameworkPropertyMetadata(typeof(TextControl)));
72
            ResourceDictionary dictionary = new ResourceDictionary();
73
            dictionary.Source = new Uri("/MarkupToPDF;component/Themes/generic.xaml", UriKind.RelativeOrAbsolute);
74
            Application.Current.Resources.MergedDictionaries.Add(dictionary);
75
            
76
        }
77
        
78
        
79
        public override void OnApplyTemplate()
80
        {
81
            base.OnApplyTemplate();            
82

    
83
            Base_TextPath = GetTemplateChild(PART_TextPath) as Path;
84
            Base_TextBox = GetTemplateChild(PART_TextBox) as TextBox;
85
            Base_TextBlock = GetTemplateChild(PART_TextBlock) as TextBlock;
86
            Base_Grid = GetTemplateChild(PART_Grid) as Grid;
87
            Base_Border = GetTemplateChild(PART_Border) as Border;
88
            Base_Canvas = GetTemplateChild(PART_Canvas) as Canvas;
89
            
90
            this.Base_TextBox.SizeChanged += new SizeChangedEventHandler(Base_TextBox_SizeChanged);
91
            this.Base_TextBlock.SizeChanged += new SizeChangedEventHandler(Base_TextBlock_SizeChanged);
92
            this.Base_TextBox.GotFocus += new RoutedEventHandler(TextControl_GotFocus);
93
            this.Base_TextBox.LostFocus += new RoutedEventHandler(TextControl_LostFocus);
94
           
95
            DrawingCloud();
96
            SetText();
97
        }
98

    
99
        public override void ApplyOverViewData()
100
        {
101
            this.OverViewPathData = this.PathData;
102
            this.OverViewText = this.Text;
103
            this.OverViewPaint = this.Paint;
104

    
105
        }
106

    
107
        void Base_TextBlock_SizeChanged(object sender, SizeChangedEventArgs e)
108
        {
109
            
110

    
111
            this.Text = Base_TextBox.Text;
112

    
113
            BoxWidth = e.NewSize.Width;
114
            BoxHeight = e.NewSize.Height;
115

    
116
            this.ApplyTemplate();
117

    
118
            DrawingCloud();
119
        }
120

    
121
        //void TextControl_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
122
        //{
123
        //    this.Focus();
124
        //}
125

    
126
        void Base_TextBox_SizeChanged(object sender, SizeChangedEventArgs e)
127
        {
128
            if (Base_TextBox.Text.Contains("|OR||DZ|"))
129
            {
130
                Base_TextBox.Text = this.Text;
131
            }
132

    
133
            this.Text = Base_TextBox.Text;
134
            BoxWidth = e.NewSize.Width;
135
            BoxHeight = e.NewSize.Height;
136
            this.ApplyTemplate();
137
            DrawingCloud();
138
        }
139

    
140
        void TextControl_GotFocus(object sender, RoutedEventArgs e)
141
        {
142
            if (EnableEditing)
143
            {
144
                EditingMode();
145
            }
146
            else
147
            {
148
                UnEditingMode();
149
            }
150
        }
151

    
152
        void TextControl_LostFocus(object sender, RoutedEventArgs e)
153
        {
154
            UnEditingMode();
155
            ApplyOverViewData();
156
        }
157

    
158
        //void TextControl_GotFocus(object sender, RoutedEventArgs e)
159
        //{
160
        //    Base_TextBox.Visibility = Visibility.Visible;
161
        //    Base_TextBlock.Visibility = Visibility.Collapsed;
162
        //    this.Base_TextBox.BorderThickness = new Thickness(1);
163
        //    if (UnderLine != null)
164
        //    {
165
        //        Base_TextBlock.TextDecorations = UnderLine;
166
        //    }
167
        //    if (this.Text != null)
168
        //    {
169
        //        Base_TextBox.Text = this.Text;
170
        //    }
171
        //    IsEditing = true;
172
        //}
173
        //void TextControl_LostFocus(object sender, RoutedEventArgs e)
174
        //{
175
        //    Base_TextBox.Visibility = Visibility.Collapsed;
176
        //    Base_TextBlock.Visibility = Visibility.Visible;
177
        //    this.Text = Base_TextBox.Text;
178
        //    if (UnderLine != null)
179
        //    {
180
        //        Base_TextBlock.TextDecorations = UnderLine;
181
        //    }
182
        //    Base_TextBlock.Margin =
183
        //       new Thickness(Base_TextBox.Margin.Left + 4, Base_TextBox.Margin.Top + 4, Base_TextBox.Margin.Right + 4, Base_TextBox.Margin.Bottom + 4);
184
        //    IsEditing = false;
185
        //}
186

    
187
        public void EditingMode()
188
        {
189
            //this.Base_TextBox.Focus();
190
            //System.Diagnostics.Debug.WriteLine(DateTime.Now.ToLongTimeString());
191
            TextBoxVisibility = Visibility.Visible;
192
            //Base_TextBox.Visibility = System.Windows.Visibility.Visible;
193

    
194
            TextBlockVisibility = Visibility.Collapsed;
195
            //Base_TextBlock.Visibility = System.Windows.Visibility.Collapsed;
196

    
197

    
198
            //this.Base_TextBox.BorderThickness = new Thickness(1);
199

    
200
            if (UnderLine != null)
201
                Base_TextBlock.TextDecorations = UnderLine;
202

    
203
            if (this.Text != null)
204
                Base_TextBox.Text = this.Text;
205

    
206
            //            Base_TextBox.Margin =
207
            //new Thickness(Base_TextBlock.Margin.Left + -2, Base_TextBlock.Margin.Top + 0,
208
            //Base_TextBlock.Margin.Right + 0, Base_TextBlock.Margin.Bottom + -2);
209
        }
210

    
211
        public void UnEditingMode()
212
        {
213
            if (EnableEditing)
214
                this.Text = Base_TextBox.Text;
215

    
216
            TextBoxVisibility = Visibility.Collapsed;
217
            //Base_TextBox.Visibility = System.Windows.Visibility.Collapsed;
218

    
219
            TextBlockVisibility = Visibility.Visible;
220
            //Base_TextBlock.Visibility = System.Windows.Visibility.Visible;
221

    
222
            if (UnderLine != null)
223
                Base_TextBlock.TextDecorations = UnderLine;
224

    
225
            //Base_TextBox.Focusable = false;
226

    
227
            //Base_TextBlock.Margin =
228
            //     new Thickness(Base_TextBox.Margin.Left + 4, Base_TextBox.Margin.Top + 4,
229
            //         Base_TextBox.Margin.Right + 4, Base_TextBox.Margin.Bottom + 4);
230

    
231
            //       Base_TextBlock.Margin =
232
            //new Thickness(Base_TextBox.Margin.Left + 2, Base_TextBox.Margin.Top + 2,
233
            //    Base_TextBox.Margin.Right + 2, Base_TextBox.Margin.Bottom + 2);
234

    
235
            //            Base_TextBlock.Margin =
236
            //new Thickness(Base_TextBox.Margin.Left + 5, Base_TextBox.Margin.Top + 0,
237
            //Base_TextBox.Margin.Right + 0, Base_TextBox.Margin.Bottom + 2);
238
        }
239

    
240
        public void SetText()
241
        {
242
            this.ApplyTemplate();
243
            if (IsHighLight)
244
            {
245
                this.BackInnerColor = new SolidColorBrush(Color.FromArgb(Convert.ToByte(255 * 0.6),
246
                    Colors.Yellow.R, Colors.Yellow.G, Colors.Yellow.B));
247
                this.BackColor = new SolidColorBrush(Color.FromArgb(Convert.ToByte(255 * 0.1),
248
                    Colors.Yellow.R, Colors.Yellow.G, Colors.Yellow.B));
249
            }
250
            else
251
            {
252
                this.BackInnerColor = new SolidColorBrush(Color.FromArgb(Convert.ToByte(255 * 0.6),
253
                    Colors.White.R, Colors.White.G, Colors.White.B));
254

    
255
                this.BackColor = new SolidColorBrush(Color.FromArgb(Convert.ToByte(255 * 0.1),
256
                    Colors.White.R, Colors.White.G, Colors.White.B));
257
            }
258
            if (Base_TextPath != null)
259
            {
260
                Base_TextPath.StrokeThickness = LineSize.Left;
261
            }
262
        }
263

    
264
        public void DrawingCloud()
265
        {
266
            this.ApplyTemplate();
267
            
268
            List<Point> pCloud = new List<Point>
269
            {
270
                new Point(0, 0),
271
                new Point(0, 0 + BoxHeight + 0),
272
                new Point(0 + BoxWidth + 2, 0 + BoxHeight + 0),
273
                new Point(0 + BoxWidth + 2 ,0),
274
            };
275

    
276
            if (Base_TextPath != null)
277
            {
278
                switch (ControlType_No)
279
                {
280
                    case 0:
281
                        {
282
                            PathData = new PathGeometry();
283
                            PathDataInner = (GenerateInner(pCloud));
284
                        }
285
                        break;
286
                    case 1:
287
                        {
288
                            PathData = (Generate_Rect(pCloud));
289
                            List<Point> pCloud2 = new List<Point>
290
                            {
291
                                new Point(0, 0),
292
                                new Point(0, 0 + BoxHeight + 0),
293
                                new Point(0 + BoxWidth + 10, 0 + BoxHeight + 0),
294
                                new Point(0 + BoxWidth + 10 ,0),
295
                            };
296
                            PathDataInner = (GenerateInner(pCloud));
297
                        }
298
                        break;
299
                    case 2:
300
                        {
301
                            PathData = (Generate(pCloud));
302
                            PathDataInner = (GenerateInner(pCloud));
303
                        }
304
                        break;
305
                }
306
            }
307

    
308
            //SetText();
309
        }
310
        #endregion Internal Method
311

    
312
        public void Dispose()
313
        {
314
            GC.Collect();
315
            GC.SuppressFinalize(this);
316
        }
317

    
318
        public override void UpdateControl()
319
        {
320
            if (this.PointSet.Count > 1)
321
            {
322
                this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y);
323
                this.EndPoint = new Point(this.PointSet[1].X, this.PointSet[1].Y);
324
            }
325
        }
326

    
327
        #region Drawing Cloud Method
328
        public static PathGeometry Generate_Rect(List<Point> pData)
329
        {
330
            PathFigure pathFigure = new PathFigure();
331
            pathFigure.StartPoint = pData[0];
332

    
333
            PolyLineSegment polyline = new PolyLineSegment(pData, true);
334
            pathFigure.Segments.Add(polyline);
335

    
336
            PathGeometry rectPathGeometry = new PathGeometry();
337
            rectPathGeometry.Figures = new PathFigureCollection();
338
            pathFigure.IsClosed = true;
339
            pathFigure.IsFilled = false;
340
            rectPathGeometry.Figures.Add(pathFigure);
341

    
342

    
343
            return rectPathGeometry;
344
        }
345

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

    
360
            return _pathGeometry;
361
        }
362

    
363

    
364
        public static PathGeometry GenerateInner(List<Point> pData)
365
        {
366
            var _pathGeometry = new PathGeometry();
367
            double area = MathSet.AreaOf(pData);
368
            bool reverse = (area > 0);
369
            int count = pData.Count;
370

    
371
            PathFigure pathFigur2 = new PathFigure();
372
            pathFigur2.StartPoint = pData[0];
373

    
374
            PolyLineSegment polyline = new PolyLineSegment(pData, true);
375
            pathFigur2.Segments.Add(polyline);
376

    
377
            pathFigur2.IsClosed = true;
378
            pathFigur2.IsFilled = true;
379
            _pathGeometry.Figures.Add(pathFigur2);
380

    
381
            return _pathGeometry;
382
        }
383

    
384
        public static PathFigure GenerateLineWithCloud(Point p1, Point p2, double _arcLength, bool reverse)
385
        {
386
            PathFigure pathFigure = new PathFigure();
387
            pathFigure.StartPoint = p1;
388

    
389
            double arcLength = _arcLength;
390
            double dx = p2.X - p1.X;
391
            double dy = p2.Y - p1.Y;
392
            double l = MathSet.DistanceTo(p1, p2);
393
            double theta = Math.Atan2(Math.Abs(dy), Math.Abs(dx)) * 180 / Math.PI;
394
            Point lastPt = new Point(p1.X, p1.Y);
395
            double count = l / _arcLength;
396

    
397
            dx /= l;
398
            dy /= l;
399

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

    
413
            if ((count > j) || count > 0)
414
            {
415
                arcLength = MathSet.DistanceTo(lastPt, p2);
416
                ArcSegment arcSeg = new ArcSegment();
417
                arcSeg.Size = new Size(arcLength * TextControl._CloudArcDepth, arcLength * TextControl._CloudArcDepth);
418
                arcSeg.Point = new Point(p2.X, p2.Y);
419
                arcSeg.RotationAngle = theta;
420

    
421
                if (true == reverse)
422
                    arcSeg.SweepDirection = SweepDirection.Clockwise;
423

    
424
                pathFigure.Segments.Add(arcSeg);
425

    
426
            }
427
            return pathFigure;
428
        }
429
        #endregion
430

    
431
        #region Dependency Properties
432
        public static readonly DependencyProperty ControlTypeProperty =
433
        DependencyProperty.Register("ControlType", typeof(ControlType), typeof(TextControl), new FrameworkPropertyMetadata(ControlType.TextControl));
434

    
435
        public static readonly DependencyProperty ControlType_NoProperty =
436
        DependencyProperty.Register("ControlType_No", typeof(int), typeof(TextControl), new FrameworkPropertyMetadata(0));
437

    
438
        public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register(
439
            "IsSelected", typeof(bool), typeof(TextControl), new FrameworkPropertyMetadata(false, IsSelectedChanged));
440

    
441
        public static readonly DependencyProperty PathGeometryProperty = DependencyProperty.Register(
442
            "PathGeometry", typeof(PathGeometry), typeof(TextControl), new PropertyMetadata(null, SetPathGeometryChanged));
443

    
444
        public static readonly DependencyProperty TextProperty = DependencyProperty.Register(
445
            "Text", typeof(string), typeof(TextControl), new PropertyMetadata(null));
446

    
447
        public static readonly DependencyProperty OverViewTextProperty = DependencyProperty.Register(
448
            "OverViewText", typeof(string), typeof(TextControl), new PropertyMetadata(null));
449

    
450
        public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register(
451
            "UserID", typeof(string), typeof(TextControl), new PropertyMetadata(null));
452

    
453
        /*public static readonly DependencyProperty FontColorProperty = DependencyProperty.Register(
454
            "FontColor", typeof(SolidColorBrush), typeof(TextControl), new PropertyMetadata(new SolidColorBrush(Colors.Red)));*/
455

    
456
        public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register(
457
            "StrokeColor", typeof(SolidColorBrush), typeof(TextControl), new PropertyMetadata(new SolidColorBrush(Colors.Red)));
458

    
459
        //강인구 추가
460
        public static readonly DependencyProperty IsHighlightProperty = DependencyProperty.Register(
461
            "IsHighLight", typeof(bool), typeof(TextControl), new PropertyMetadata(false, PointValueChanged));
462

    
463
        public static readonly DependencyProperty BackColorProperty = DependencyProperty.Register(
464
            "BackColor", typeof(SolidColorBrush), typeof(TextControl), new PropertyMetadata(new SolidColorBrush(Colors.White)));
465

    
466
        public static readonly DependencyProperty BackInnerColorProperty = DependencyProperty.Register(
467
            "BackInnerColor", typeof(SolidColorBrush), typeof(TextControl), new PropertyMetadata(new SolidColorBrush(Colors.White)));
468

    
469
        public static readonly DependencyProperty UnderLineProperty = DependencyProperty.Register(
470
            "UnderLine", typeof(TextDecorationCollection), typeof(TextControl), new PropertyMetadata(null));
471

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

    
475
        public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register(
476
            "PointSet", typeof(List<Point>), typeof(TextControl), new PropertyMetadata(new List<Point>()));
477

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

    
481

    
482

    
483
        public static readonly DependencyProperty PathDataInnerProperty = DependencyProperty.Register(
484
    "PathDataInner", typeof(Geometry), typeof(TextControl), null);
485

    
486
        public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register(
487
            "OverViewPathDataProperty", typeof(Geometry), typeof(TextControl), null);
488

    
489
        public static readonly DependencyProperty TextStyleProperty = DependencyProperty.Register(
490
            "TextStyle", typeof(FontStyle), typeof(TextControl), new PropertyMetadata(FontStyles.Normal));
491

    
492
        public static readonly DependencyProperty TextFamilyProperty = DependencyProperty.Register(
493
            "TextFamily", typeof(FontFamily), typeof(TextControl), new PropertyMetadata(new FontFamily("Arial")));
494

    
495
        public static readonly DependencyProperty TextWeightProperty = DependencyProperty.Register(
496
            "TextWeight", typeof(FontWeight), typeof(TextControl), new PropertyMetadata(FontWeights.Normal));
497

    
498
        public static readonly DependencyProperty CenterXProperty = DependencyProperty.Register(
499
            "CenterX", typeof(double), typeof(TextControl), new PropertyMetadata((double)0, OnCenterXYChanged));
500

    
501
        public static readonly DependencyProperty CenterYProperty = DependencyProperty.Register(
502
            "CenterY", typeof(double), typeof(TextControl), new PropertyMetadata((double)0, OnCenterXYChanged));
503

    
504
        public static readonly DependencyProperty CanvasXProperty = DependencyProperty.Register(
505
           "CanvasX", typeof(double), typeof(TextControl), new PropertyMetadata((double)0, OnSetCansvasChanged));
506

    
507
        public static readonly DependencyProperty CanvasYProperty = DependencyProperty.Register(
508
            "CanvasY", typeof(double), typeof(TextControl), new PropertyMetadata((double)0, OnSetCansvasChanged));
509

    
510
        public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register(
511
              "StartPoint", typeof(Point), typeof(TextControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
512

    
513
        public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register(
514
             "EndPoint", typeof(Point), typeof(TextControl), new PropertyMetadata(new Point(100, 100), PointValueChanged));
515

    
516
        public static readonly DependencyProperty TextSizeProperty = DependencyProperty.Register(
517
               "TextSize", typeof(Double), typeof(TextControl), new PropertyMetadata((Double)30, PointValueChanged));
518

    
519
        public static readonly DependencyProperty PaintProperty = DependencyProperty.Register(
520
                "Paint", typeof(PaintSet), typeof(TextControl), new PropertyMetadata((PaintSet.None), PointValueChanged));
521

    
522
        public static readonly DependencyProperty OverViewPaintProperty = DependencyProperty.Register(
523
                "OverViewPaint", typeof(PaintSet), typeof(TextControl), new PropertyMetadata((PaintSet.None), PointValueChanged));
524

    
525
        public static readonly DependencyProperty AngleProperty = DependencyProperty.Register(
526
            "Angle", typeof(double), typeof(TextControl), new PropertyMetadata((double)0.0, new PropertyChangedCallback(AngleValueChanged)));
527

    
528
        public static readonly DependencyProperty EnableEditingProperty = DependencyProperty.Register(
529
           "EnableEditing", typeof(bool), typeof(TextControl), new PropertyMetadata((true), new PropertyChangedCallback(OnIsEditingChanged)));
530

    
531
        public static readonly DependencyProperty TextBoxVisibilityProperty = DependencyProperty.Register(
532
        "TextBoxVisibility", typeof(Visibility), typeof(TextControl), new PropertyMetadata((Visibility.Visible), OnTextBoxVisibilityChanged));
533

    
534
        public static readonly DependencyProperty TextBlockVisibilityProperty = DependencyProperty.Register(
535
        "TextBlockVisibility", typeof(Visibility), typeof(TextControl), new PropertyMetadata((Visibility.Collapsed), OnTextBlockVisibilityChanged));
536

    
537
        #endregion Dependency Properties
538

    
539
        #region dp Properties
540

    
541

    
542
        public override SolidColorBrush StrokeColor
543
        {
544
            get { return (SolidColorBrush)GetValue(StrokeColorProperty); }
545
            set
546
            {
547
                if (this.StrokeColor != value)
548
                {
549
                    SetValue(StrokeColorProperty, value);
550
                }
551
            }
552
        }
553

    
554
      
555

    
556
        public bool EnableEditing
557
        {
558
            get { return (bool)GetValue(EnableEditingProperty); }
559
            set
560
            {
561
                if (this.EnableEditing != value)
562
                {
563
                    SetValue(EnableEditingProperty, value);
564
                    OnPropertyChanged("EnableEditing");
565
                }
566
            }
567
        }
568

    
569
        public Thickness LineSize
570
        {
571
            get
572
            {
573
                return (Thickness)GetValue(LineSizeProperty);
574
            }
575
            set
576
            {
577
                if (this.LineSize != value)
578
                {
579
                    SetValue(LineSizeProperty, value);
580
                    OnPropertyChanged("LineSize");
581
                }
582
            }
583
        }
584

    
585
        public override ControlType ControlType
586
        {
587
            get
588
            {
589
                return (ControlType)GetValue(ControlTypeProperty);
590
            }
591
            set
592
            {
593
                SetValue(ControlTypeProperty, value);
594
            }
595
        }
596
        public int ControlType_No
597
        {
598
            get
599
            {
600
                return (int)GetValue(ControlType_NoProperty);
601
            }
602
            set
603
            {
604
                SetValue(ControlType_NoProperty, value);
605
            }
606
        }
607

    
608
        public string UserID
609
        {
610
            get { return (string)GetValue(UserIDProperty); }
611
            set
612
            {
613
                if (this.UserID != value)
614
                {
615
                    SetValue(UserIDProperty, value);
616
                    OnPropertyChanged("UserID");
617
                }
618
            }
619
        }
620

    
621
        public double CenterX
622
        {
623
            get { return (double)GetValue(CenterXProperty); }
624
            set { SetValue(CenterXProperty, value);
625
            OnPropertyChanged("CenterX");
626
            
627
            }
628
        }
629

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

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

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

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

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

    
690

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

    
704

    
705

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

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

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

    
758
        
759

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

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

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

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

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

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

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

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

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

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

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

    
906

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

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

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

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

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

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

    
961
        #endregion Properties
962

    
963
        #region Properties
964

    
965

    
966

    
967
        public PathGeometry PathGeometry 
968
        {
969
            get { return (PathGeometry)GetValue(PathGeometryProperty); }
970
            set
971
            {
972
                SetValue(PathGeometryProperty, value);
973
                OnPropertyChanged("PathGeometry");
974
            }
975
        }
976

    
977
        private double _BoxWidth;
978
        public double BoxWidth
979
        {
980
            get
981
            {
982
                return _BoxWidth;
983
            }
984
            set
985
            {
986
                _BoxWidth = value;
987
                OnPropertyChanged("BoxWidth");
988
            }
989
        }
990

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

    
1005
        #endregion
1006

    
1007
        #region CallBack Method
1008
        public static void SetPathGeometryChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1009
        {
1010
            var instance = (TextControl)sender;
1011

    
1012
            if (e.OldValue != e.NewValue && instance.Base_TextPath != null)
1013
            {
1014
                instance.SetValue(e.Property, e.NewValue);
1015
            }
1016
        }
1017

    
1018

    
1019
        public static void OnTextBoxVisibilityChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1020
        {
1021
            var instance = (TextControl)sender;
1022

    
1023
            if (e.OldValue != e.NewValue && instance.Base_TextPath != null)
1024
            {
1025
                instance.SetValue(e.Property, e.NewValue);
1026
            }
1027
        }
1028

    
1029
        public static void OnTextBlockVisibilityChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1030
        {
1031
            var instance = (TextControl)sender;
1032

    
1033
            if (e.OldValue != e.NewValue && instance.Base_TextPath != null)
1034
            {
1035
                instance.SetValue(e.Property, e.NewValue);
1036
            }
1037
        }
1038

    
1039
        public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1040
        {
1041
            var instance = (TextControl)sender;
1042

    
1043
            if (e.OldValue != e.NewValue && instance.Base_Border != null)
1044
            {
1045
                instance.SetValue(e.Property, e.NewValue);
1046

    
1047
                if (instance.IsSelected)
1048
                {
1049
                    instance.StrokeColor = new SolidColorBrush(Colors.Blue);
1050
                    //instance.Base_Border.BorderBrush = new SolidColorBrush(Colors.Blue);
1051
                }
1052
                else
1053
                {
1054
                    instance.StrokeColor = new SolidColorBrush(Colors.Red);
1055
                    //instance.Base_Border.BorderBrush = new SolidColorBrush(Colors.Red);
1056
                    //instance.FontColor = new SolidColorBrush(Colors.Transparent);
1057
                    //instance.Base_Border.BorderBrush = new SolidColorBrush(Colors.Transparent);
1058
                }
1059

    
1060
            }
1061
        }
1062

    
1063
        public static void OnSetCansvasChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1064
        {
1065
            var instance = (TextControl)sender;
1066

    
1067
            if (e.OldValue != e.NewValue && instance != null)
1068
            {
1069
                instance.SetValue(e.Property, e.NewValue);
1070

    
1071
                Canvas.SetLeft(instance, instance.CanvasX);
1072
                Canvas.SetTop(instance, instance.CanvasY);
1073
            }
1074
        }
1075

    
1076
        public static void OnIsEditingChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1077
        {
1078
            var instance = (TextControl)sender;
1079

    
1080
            if (e.OldValue != e.NewValue && instance.Base_TextBlock != null)
1081
            {
1082
                instance.SetValue(e.Property, e.NewValue);
1083

    
1084
                //if (instance.EnableEditing)
1085
                //{
1086
                //    instance.EditingMode();
1087
                //}
1088
                //else
1089
                //{
1090
                //    instance.UnEditingMode();
1091
                //}
1092
            }
1093
        }
1094

    
1095
        public static void OnCenterXYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1096
        {
1097
            var instance = (TextControl)sender;
1098

    
1099
            if (e.OldValue != e.NewValue && instance.Base_TextBlock != null)
1100
            {
1101
                instance.SetValue(e.Property, e.NewValue);
1102
                //instance.DrawingCloud();
1103
            }
1104
        }
1105

    
1106
        public static void AngleValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1107
        {
1108
            var instance = (TextControl)sender;
1109
            if (e.OldValue != e.NewValue && instance.Base_TextBlock != null)
1110
            {
1111
                instance.SetValue(e.Property, e.NewValue);
1112
                //instance.DrawingCloud();
1113
            }
1114
        }
1115

    
1116
        public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1117
        {
1118
            var instance = (TextControl)sender;
1119
            if (e.OldValue != e.NewValue && instance!= null)
1120
            {
1121
                instance.SetValue(e.Property, e.NewValue);
1122
                //instance.DrawingCloud();
1123
            }
1124
        }
1125
            
1126
        #endregion CallBack Method
1127

    
1128
        protected void OnPropertyChanged(string propName)
1129
        {
1130
            if (PropertyChanged != null)
1131
                PropertyChanged(this, new PropertyChangedEventArgs(propName));
1132
        }
1133

    
1134
        /// <summary>
1135
        /// return textcontrols' area
1136
        /// </summary>
1137
        public override Rect ItemRect
1138
        {
1139
            get
1140
            {
1141
                Point start = new Point(this.CanvasX, this.CanvasY);
1142

    
1143
                Point length = new Point();
1144
                double angle = this.Angle * Math.PI / 180;
1145

    
1146
                length.X = this.BoxWidth * Math.Cos(angle) - this.BoxHeight * Math.Sin(angle);
1147
                length.Y = this.BoxWidth * Math.Sin(angle) + this.BoxHeight * Math.Cos(angle);
1148

    
1149
                Point end = new Point(start.X + length.X, start.Y + length.Y);
1150
                return new Rect(start, end);
1151
            }
1152
        }
1153

    
1154
        /// <summary>
1155
        /// translate control along given dx,dy
1156
        /// </summary>
1157
        /// <param name="dx"></param>
1158
        /// <param name="dy"></param>
1159
        public override void OnTranslate(double dx, double dy)
1160
        {
1161
            //this.CanvasX = Canvas.GetLeft(this) + dx;
1162
            //this.CanvasY = Canvas.GetTop(this) + dy;
1163
            this.StartPoint = new Point(this.StartPoint.X + dx, this.StartPoint.Y + dy);
1164
            this.EndPoint = new Point(this.EndPoint.X + dx, this.EndPoint.Y + dy);
1165

    
1166
            this.SetValue(TextControl.CanvasXProperty, Canvas.GetLeft(this) + dx);
1167
            this.SetValue(TextControl.CanvasYProperty, Canvas.GetTop(this) + dy);
1168

    
1169
            
1170

    
1171
            
1172
            //Canvas.SetLeft(this, Canvas.GetLeft(this) + dx);
1173
            //Canvas.SetTop(this, Canvas.GetTop(this) + dy);
1174
        }
1175

    
1176
        /// <summary>
1177
        /// Serialize this
1178
        /// </summary>
1179
        /// <param name="sUserId"></param>
1180
        /// <returns></returns>
1181
        public override string Serialize()
1182
        {
1183
            using (S_TextControl STemp = new S_TextControl())
1184
            {
1185
                STemp.TransformPoint = "0|0";
1186
                STemp.SizeSet = String.Format("{0}|{1}", this.LineSize.Left.ToString(), this.TextSize.ToString());
1187
                STemp.Text = this.Text;
1188
                STemp.UserID = this.UserID;
1189
                STemp.FontColor = this.StrokeColor.Color.ToString();
1190
                //STemp.FontColor = "#FFFFFF00";
1191

    
1192
                if (this.StartPoint == new Point())
1193
                    STemp.StartPoint = new Point(this.CanvasX, this.CanvasY);
1194
                else
1195
                    STemp.StartPoint = this.StartPoint;
1196

    
1197
                STemp.EndPoint = this.EndPoint;
1198
                STemp.Opac = this.Opacity;
1199
                STemp.PointSet = this.PointSet;
1200
                STemp.Angle = this.Angle;
1201
                STemp.paintMethod = this.ControlType_No;
1202
                STemp.BoxW = this.BoxWidth;
1203
                STemp.BoxH = this.BoxHeight;
1204
                STemp.isHighLight = this.IsHighLight;
1205
                STemp.Name = this.GetType().Name.ToString();
1206
                STemp.fontConfig = new List<string>()
1207
                            {
1208
                                this.TextFamily.ToString(),
1209
                                this.TextStyle.ToString(),
1210
                                this.TextWeight.ToString(),
1211
                            };
1212

    
1213

    
1214

    
1215
                if (this.UnderLine != null)
1216
                {
1217
                    STemp.fontConfig.Add("true");
1218
                }
1219

    
1220
                ///강인구 추가(2017.11.02)
1221
                ///Memo 추가
1222
                STemp.Memo = this.Memo;
1223

    
1224
                return "|DZ|" + JsonSerializerHelper.CompressString((STemp.JsonSerialize()));
1225
            }
1226
        }
1227

    
1228
        /// <summary>
1229
        /// create a textcontrol from given string
1230
        /// </summary>
1231
        /// <param name="str"></param>
1232
        /// <returns></returns>
1233
        public static TextControl FromString(string str, SolidColorBrush brush, string sProjectNo)
1234
        {
1235
            using (S_TextControl s = JsonSerializerHelper.JsonDeserialize<S_TextControl>(str))
1236
            {
1237
                string[] data2 = s.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
1238
                TextControl instance = new TextControl()
1239
                {
1240
                    Text = s.Text,
1241
                    StartPoint = s.StartPoint,
1242
                    EndPoint = s.EndPoint,
1243
                    CanvasX = s.StartPoint.X,
1244
                    CanvasY = s.StartPoint.Y,
1245
                    BoxWidth = s.BoxW,
1246
                    BoxHeight = s.BoxH,
1247
                    ControlType_No = s.paintMethod,
1248
                    LineSize = new Thickness(Convert.ToDouble(data2.First())),
1249
                    TextSize = Convert.ToDouble(data2[1]),
1250
                    StrokeColor = brush,
1251
                    FontSize = 10,
1252
                    UserID = s.UserID,
1253
                    IsHighLight = s.isHighLight,
1254
                    Angle = s.Angle,
1255
                    PointSet = s.PointSet,
1256
                    Opacity = s.Opac,
1257
                    TextFamily = new FontFamily(s.fontConfig[0]),
1258
                    //인구 추가(2018.04.17)
1259
                    TextStyle = StringToFont.ConFontStyle(s.fontConfig[1]),
1260
                    TextWeight = StringToFont.ConFontWeight(s.fontConfig[2]),
1261
                };
1262

    
1263
                if (s.fontConfig.Count() == 4)
1264
                {
1265
                    instance.UnderLine = TextDecorations.Underline;
1266
                }
1267

    
1268
                return instance;
1269
            }
1270
        }
1271
    }
1272
}
클립보드 이미지 추가 (최대 크기: 500 MB)