프로젝트

일반

사용자정보

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

markus / MarkupToPDF / Controls / Text / TextControl.cs @ e5bd2147

이력 | 보기 | 이력해설 | 다운로드 (45.2 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
using Markus.Fonts;
16

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

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

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

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

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

    
61
        #region Internal Method
62

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

    
68
        static TextControl()
69
        {
70
            DefaultStyleKeyProperty.OverrideMetadata(typeof(TextControl), new FrameworkPropertyMetadata(typeof(TextControl)));
71
            //ResourceDictionary dictionary = new ResourceDictionary();
72
            //dictionary.Source = new Uri("/MarkupToPDF;component/Themes/generic.xaml", UriKind.RelativeOrAbsolute);
73
            //if (!Application.Current.Resources.MergedDictionaries.Any(x => x.Source == dictionary.Source))
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
            BaseTextbox_Caret = GetTemplateChild(PART_BaseTextbox_Caret) as Border;
90
            //BaseTextbox_Caret.Height = this.Base_TextBox.FontSize;
91
            this.Base_TextBox.Text = this.Text;
92
            this.Base_TextBox.CaretIndex = this.Base_TextBox.Text.Length;
93
            this.Base_TextBox.CaretBrush = new SolidColorBrush(Colors.Transparent);
94
            this.Base_TextBox.ApplyTemplate();
95
            MoveCustomCaret();
96
            if(this.Base_TextBox.FontSize > this.BaseTextbox_Caret.Height)
97
            {
98
                BaseTextbox_Caret.Height = this.Base_TextBox.FontSize;
99
            }
100
            //BaseTextbox_Caret.Height = Base_TextBox.ActualHeight - 5;
101

    
102
            this.Base_TextBox.SizeChanged += new SizeChangedEventHandler(Base_TextBox_SizeChanged);
103
            this.Base_TextBox.TextChanged += new TextChangedEventHandler(Base_TextBox_TextChanged);
104
            this.Base_TextBlock.SizeChanged += new SizeChangedEventHandler(Base_TextBlock_SizeChanged);
105
            this.Base_TextBox.GotFocus += new RoutedEventHandler(Base_TextBox_GotFocus);
106
            this.Base_TextBox.LostFocus += new RoutedEventHandler(Base_TextBox_LostFocus);            
107
            this.Base_TextBox.SelectionChanged += (sender, e) => MoveCustomCaret();
108
            
109
            
110
            SetText();
111
            DrawingCloud();
112
        }
113

    
114
        public void SetFontFamily(FontFamily fontFamily)
115
        {
116
            
117
            if (this.Base_TextBlock != null) {
118
                this.Base_TextBlock.FontFamily = fontFamily;
119
            }
120

    
121
            if (this.Base_TextBox != null) {
122
                this.Base_TextBox.FontFamily = fontFamily;
123
            }
124
            this.FontFamily = fontFamily;
125
            this.TextFamily = fontFamily;
126
        }
127

    
128

    
129
        /// <summary>
130
        /// Moves the custom caret on the canvas.
131
        /// </summary>
132
        public void MoveCustomCaret()
133
        {
134

    
135
            var caretLocation = this.Base_TextBox.GetRectFromCharacterIndex(this.Base_TextBox.CaretIndex).Location;
136

    
137
            if (!double.IsInfinity(caretLocation.X)) {
138
                Canvas.SetLeft(this.BaseTextbox_Caret, caretLocation.X);
139
            }
140

    
141
            if (!double.IsInfinity(caretLocation.Y)) {
142
                Canvas.SetTop(this.BaseTextbox_Caret, caretLocation.Y);
143
                //Canvas.SetTop(this.BaseTextbox_Caret, (LineSize.Top - caretLocation.Y));
144
            }
145
        }
146

    
147
        
148

    
149
        public override void ApplyOverViewData()
150
        {
151
            this.OverViewPathData = this.PathData;
152
            if (Text == "")
153
                this.Text = this.OverViewText;
154
            else
155
                this.OverViewText = this.Text;
156
            
157
            this.OverViewPaint = this.Paint;
158

    
159
        }        
160

    
161
        void Base_TextBox_SizeChanged(object sender, SizeChangedEventArgs e)
162
        {
163
            BoxWidth = e.NewSize.Width;
164
            BoxHeight = e.NewSize.Height;
165

    
166
            DrawingCloud();
167
        }
168
        private void Base_TextBlock_SizeChanged(object sender, SizeChangedEventArgs e)
169
        {
170
            BoxWidth = e.NewSize.Width;
171
            BoxHeight = e.NewSize.Height;
172

    
173
            DrawingCloud();
174
        }
175
        private void Base_TextBox_TextChanged(object sender, TextChangedEventArgs e)
176
        {
177
            if (IsEditingMode)
178
            {
179
                if (Base_TextBox.Text.Contains("|OR||DZ|"))
180
                {
181
                    Base_TextBox.Text = this.Text;
182
                }
183

    
184
                this.Text = Base_TextBox.Text;
185

    
186
            }            
187
            DrawingCloud();
188
        }
189
        void Base_TextBox_GotFocus(object sender, RoutedEventArgs e)
190
        {
191
            this.BaseTextbox_Caret.Visibility = Visibility.Visible;
192
            MoveCustomCaret();
193
            Base_TextBox.Focus();
194
            this.IsEditingMode = true;
195
        }
196

    
197
        void Base_TextBox_LostFocus(object sender, RoutedEventArgs e)
198
        {
199
            this.Text = Base_TextBox.Text;
200
            this.BaseTextbox_Caret.Visibility = Visibility.Collapsed;
201
            this.IsEditingMode = false;
202
            ApplyOverViewData();
203
        }
204

    
205
        //void TextControl_GotFocus(object sender, RoutedEventArgs e)
206
        //{
207
        //    Base_TextBox.Visibility = Visibility.Visible;
208
        //    Base_TextBlock.Visibility = Visibility.Collapsed;
209
        //    this.Base_TextBox.BorderThickness = new Thickness(1);
210
        //    if (UnderLine != null)
211
        //    {
212
        //        Base_TextBlock.TextDecorations = UnderLine;
213
        //    }
214
        //    if (this.Text != null)
215
        //    {
216
        //        Base_TextBox.Text = this.Text;
217
        //    }
218
        //    IsEditing = true;
219
        //}
220
        //void TextControl_LostFocus(object sender, RoutedEventArgs e)
221
        //{
222
        //    Base_TextBox.Visibility = Visibility.Collapsed;
223
        //    Base_TextBlock.Visibility = Visibility.Visible;
224
        //    this.Text = Base_TextBox.Text;
225
        //    if (UnderLine != null)
226
        //    {
227
        //        Base_TextBlock.TextDecorations = UnderLine;
228
        //    }
229
        //    Base_TextBlock.Margin =
230
        //       new Thickness(Base_TextBox.Margin.Left + 4, Base_TextBox.Margin.Top + 4, Base_TextBox.Margin.Right + 4, Base_TextBox.Margin.Bottom + 4);
231
        //    IsEditing = false;
232
        //}
233
        public void EditingMode()
234
        {            
235
            TextBoxVisibility = Visibility.Visible;
236
            TextBlockVisibility = Visibility.Collapsed;
237
            this.BaseTextbox_Caret.Visibility = Visibility.Visible;
238

    
239
            if (UnderLine != null)
240
                Base_TextBlock.TextDecorations = UnderLine;
241

    
242
        }
243

    
244
        public void UnEditingMode()
245
        {            
246
            TextBoxVisibility = Visibility.Collapsed;         
247
            TextBlockVisibility = Visibility.Visible; 
248
            this.BaseTextbox_Caret.Visibility = Visibility.Collapsed;
249

    
250
            if (UnderLine != null)
251
                Base_TextBlock.TextDecorations = UnderLine;
252

    
253
            
254
        }
255
        public void SetText()
256
        {
257
            if (IsHighLight)
258
            {
259
                this.BackInnerColor = new SolidColorBrush(Color.FromArgb(Convert.ToByte(255 * 0.6),
260
                    Colors.Yellow.R, Colors.Yellow.G, Colors.Yellow.B));
261
                this.BackColor = new SolidColorBrush(Color.FromArgb(Convert.ToByte(255 * 0.1),
262
                    Colors.Yellow.R, Colors.Yellow.G, Colors.Yellow.B));
263
            }
264
            else
265
            {
266
                //this.BackInnerColor = new SolidColorBrush(Color.FromArgb(0x003, 0xFF, 0xFF, 0xFF));
267
                //this.BackColor = new SolidColorBrush(Color.FromArgb(0x003, 0xFF, 0xFF, 0xFF));
268

    
269
                this.BackInnerColor = new SolidColorBrush(Color.FromArgb(Convert.ToByte(255 * 0.6),
270
                    Colors.White.R, Colors.White.G, Colors.White.B));
271

    
272
                this.BackColor = new SolidColorBrush(Color.FromArgb(Convert.ToByte(255 * 0.1),
273
                    Colors.White.R, Colors.White.G, Colors.White.B));
274
            }
275
            if (Base_TextPath != null)
276
            {
277
                Base_TextPath.StrokeThickness = LineSize.Left;
278
            }
279
            
280
        }
281

    
282
        public void DrawingCloud()
283
        {
284
            
285
            List<Point> pCloud = new List<Point>
286
            {
287
                new Point(0, 0),
288
                new Point(0, 0 + BoxHeight + 0),
289
                new Point(0 + BoxWidth + 2, 0 + BoxHeight + 0),
290
                new Point(0 + BoxWidth + 2 ,0)
291
            };
292
            //this.Base_TextBox.Select(Base_TextBox.Text.Length, 0);
293
            if (Base_TextPath != null)
294
            {
295
                switch (ControlType_No)
296
                {
297
                    case 0:
298
                        {
299
                            PathData = new PathGeometry();
300
                            PathDataInner = (GenerateInner(pCloud));
301
                        }
302
                        break;
303
                    case 1:
304
                        {
305
                            PathData = (Generate_Rect(pCloud));
306
                            List<Point> pCloud2 = new List<Point>
307
                            {
308
                                new Point(0, 0),
309
                                new Point(0, 0 + BoxHeight + 0),
310
                                new Point(0 + BoxWidth + 10, 0 + BoxHeight + 0),
311
                                new Point(0 + BoxWidth + 10 ,0)
312
                            };
313
                            PathDataInner = (GenerateInner(pCloud));
314
                        }
315
                        break;
316
                    case 2:
317
                        {
318
                            PathData = (Generate(pCloud, this.ArcLength));
319
                            PathDataInner = (GenerateInner(pCloud));
320
                        }
321
                        break;
322
                }
323
            }
324
        }
325
        #endregion Internal Method
326

    
327
        public void Dispose()
328
        {
329
            //GC.Collect();
330
            ////GC.SuppressFinalize(this);
331
            this.Base_Border = null;
332
            this.Base_Canvas = null;
333
            this.Base_Grid = null;
334
            this.Base_TextBlock = null;
335
            this.Base_TextBox = null;
336
        }
337

    
338
        public override void UpdateControl()
339
        {
340
            if (this.PointSet.Count > 1)
341
            {
342
                this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y);
343
                this.EndPoint = new Point(this.PointSet[1].X, this.PointSet[1].Y);
344
            }
345
        }
346

    
347
        #region Drawing Cloud Method
348
        public static PathGeometry Generate_Rect(List<Point> pData)
349
        {
350
            PathFigure pathFigure = new PathFigure();
351
            pathFigure.StartPoint = pData[0];
352

    
353
            PolyLineSegment polyline = new PolyLineSegment(pData, true);
354
            pathFigure.Segments.Add(polyline);
355

    
356
            PathGeometry rectPathGeometry = new PathGeometry();
357
            rectPathGeometry.Figures = new PathFigureCollection();
358
            pathFigure.IsClosed = true;
359
            pathFigure.IsFilled = false;
360
            rectPathGeometry.Figures.Add(pathFigure);
361

    
362

    
363
            return rectPathGeometry;
364
        }
365

    
366
        public static PathGeometry Generate(List<Point> pData, double _ArcLength = 20)
367
        {
368
            var _pathGeometry = new PathGeometry();
369
            double area = MathSet.AreaOf(pData);
370
            bool reverse = (area > 0);
371
            int count = pData.Count;
372
            for (int i = 0; i < count; i++)
373
            {
374
                PathFigure pathFigure = Polygon.CloudControl.GenerateLineWithCloud(pData[i % count], pData[(i + 1) % count], _ArcLength, reverse);
375
                pathFigure.IsClosed = false;
376
                pathFigure.IsFilled = true;
377
                _pathGeometry.Figures.Add(pathFigure);
378
            }
379

    
380
            return _pathGeometry;
381
        }
382

    
383

    
384
        public static PathGeometry GenerateInner(List<Point> pData)
385
        {
386
            var _pathGeometry = new PathGeometry();
387
            double area = MathSet.AreaOf(pData);
388
            bool reverse = (area > 0);
389
            int count = pData.Count;
390

    
391
            PathFigure pathFigur2 = new PathFigure();
392
            pathFigur2.StartPoint = pData[0];
393

    
394
            PolyLineSegment polyline = new PolyLineSegment(pData, true);
395
            pathFigur2.Segments.Add(polyline);
396

    
397
            pathFigur2.IsClosed = true;
398
            pathFigur2.IsFilled = true;
399
            _pathGeometry.Figures.Add(pathFigur2);
400

    
401
            return _pathGeometry;
402
        }
403
        #endregion
404

    
405
        #region Dependency Properties
406
        public static readonly DependencyProperty ControlTypeProperty =
407
        DependencyProperty.Register("ControlType", typeof(ControlType), typeof(TextControl), new FrameworkPropertyMetadata(ControlType.TextControl));
408

    
409
        public static readonly DependencyProperty ControlType_NoProperty =
410
        DependencyProperty.Register("ControlType_No", typeof(int), typeof(TextControl), new FrameworkPropertyMetadata(0));
411

    
412
        public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register(
413
            "IsSelected", typeof(bool), typeof(TextControl), new FrameworkPropertyMetadata(false, IsSelectedChanged));
414

    
415
        public static readonly DependencyProperty PathGeometryProperty = DependencyProperty.Register(
416
            "PathGeometry", typeof(PathGeometry), typeof(TextControl), new PropertyMetadata(null, SetPathGeometryChanged));
417

    
418
        public static readonly DependencyProperty TextProperty = DependencyProperty.Register(
419
            "Text", typeof(string), typeof(TextControl), new PropertyMetadata(null));
420

    
421
        public static readonly DependencyProperty OverViewTextProperty = DependencyProperty.Register(
422
            "OverViewText", typeof(string), typeof(TextControl), new PropertyMetadata(null, new PropertyChangedCallback(TextChanged)));
423

    
424
        public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register(
425
            "UserID", typeof(string), typeof(TextControl), new PropertyMetadata(null));
426

    
427
        /*public static readonly DependencyProperty FontColorProperty = DependencyProperty.Register(
428
            "FontColor", typeof(SolidColorBrush), typeof(TextControl), new PropertyMetadata(new SolidColorBrush(Colors.Red)));*/
429

    
430
        public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register(
431
            "StrokeColor", typeof(SolidColorBrush), typeof(TextControl), new PropertyMetadata(new SolidColorBrush(Colors.Red)));
432

    
433
        public static readonly DependencyProperty ArcLengthProperty = DependencyProperty.Register(
434
            "ArcLength", typeof(double), typeof(TextControl), new PropertyMetadata((Double)10, PointValueChanged));
435

    
436
        //강인구 추가
437
        public static readonly DependencyProperty IsHighlightProperty = DependencyProperty.Register(
438
            "IsHighLight", typeof(bool), typeof(TextControl), new PropertyMetadata(false, PointValueChanged));
439

    
440
        public static readonly DependencyProperty BackColorProperty = DependencyProperty.Register(
441
            "BackColor", typeof(SolidColorBrush), typeof(TextControl), new PropertyMetadata(new SolidColorBrush(Colors.White)));
442

    
443
        public static readonly DependencyProperty BackInnerColorProperty = DependencyProperty.Register(
444
            "BackInnerColor", typeof(SolidColorBrush), typeof(TextControl), new PropertyMetadata(new SolidColorBrush(Colors.White)));
445

    
446
        public static readonly DependencyProperty UnderLineProperty = DependencyProperty.Register(
447
            "UnderLine", typeof(TextDecorationCollection), typeof(TextControl), new PropertyMetadata(null));
448

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

    
452
        public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register(
453
            "PointSet", typeof(List<Point>), typeof(TextControl), new PropertyMetadata(new List<Point>()));
454

    
455
        public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register(
456
            "PathData", typeof(Geometry), typeof(TextControl), null);
457

    
458
        public static readonly DependencyProperty PathDataInnerProperty = DependencyProperty.Register(
459
            "PathDataInner", typeof(Geometry), typeof(TextControl), null);
460

    
461
        public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register(
462
            "OverViewPathDataProperty", typeof(Geometry), typeof(TextControl), null);
463

    
464
        public static readonly DependencyProperty TextStyleProperty = DependencyProperty.Register(
465
            "TextStyle", typeof(FontStyle), typeof(TextControl), new PropertyMetadata(FontStyles.Normal));
466

    
467
        public static readonly DependencyProperty TextFamilyProperty = DependencyProperty.Register(
468
            "TextFamily", typeof(FontFamily), typeof(TextControl), 
469
                        new PropertyMetadata(new PropertyChangedCallback(TextFamilyPropertyChanged)));
470

    
471
        public static readonly DependencyProperty TextWeightProperty = DependencyProperty.Register(
472
            "TextWeight", typeof(FontWeight), typeof(TextControl), new PropertyMetadata(FontWeights.Normal));
473

    
474
        public static readonly DependencyProperty CenterXProperty = DependencyProperty.Register(
475
            "CenterX", typeof(double), typeof(TextControl), new PropertyMetadata((double)0, OnCenterXYChanged));
476

    
477
        public static readonly DependencyProperty CenterYProperty = DependencyProperty.Register(
478
            "CenterY", typeof(double), typeof(TextControl), new PropertyMetadata((double)0, OnCenterXYChanged));
479

    
480
        public static readonly DependencyProperty CanvasXProperty = DependencyProperty.Register(
481
           "CanvasX", typeof(double), typeof(TextControl), new PropertyMetadata((double)0, OnSetCansvasChanged));
482

    
483
        public static readonly DependencyProperty CanvasYProperty = DependencyProperty.Register(
484
            "CanvasY", typeof(double), typeof(TextControl), new PropertyMetadata((double)0, OnSetCansvasChanged));
485

    
486
        public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register(
487
            "StartPoint", typeof(Point), typeof(TextControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
488

    
489
        public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register(
490
            "EndPoint", typeof(Point), typeof(TextControl), new PropertyMetadata(new Point(100, 100), PointValueChanged));
491

    
492
        public static readonly DependencyProperty TextSizeProperty = DependencyProperty.Register(
493
            "TextSize", typeof(Double), typeof(TextControl), new PropertyMetadata((Double)30, PointValueChanged));
494

    
495
        public static readonly DependencyProperty PaintProperty = DependencyProperty.Register(
496
            "Paint", typeof(PaintSet), typeof(TextControl), new PropertyMetadata((PaintSet.None), PointValueChanged));
497

    
498
        public static readonly DependencyProperty OverViewPaintProperty = DependencyProperty.Register(
499
            "OverViewPaint", typeof(PaintSet), typeof(TextControl), new PropertyMetadata((PaintSet.None), PointValueChanged));
500

    
501
        public static readonly DependencyProperty AngleProperty = DependencyProperty.Register(
502
            "Angle", typeof(double), typeof(TextControl), new PropertyMetadata((double)0.0, new PropertyChangedCallback(AngleValueChanged)));
503

    
504
        public static readonly DependencyProperty EnableEditingProperty = DependencyProperty.Register(
505
           "EnableEditing", typeof(bool), typeof(TextControl), new PropertyMetadata((true), new PropertyChangedCallback(OnIsEditingChanged)));
506

    
507
        public static readonly DependencyProperty TextBoxVisibilityProperty = DependencyProperty.Register(
508
            "TextBoxVisibility", typeof(Visibility), typeof(TextControl), new PropertyMetadata((Visibility.Visible), OnTextBoxVisibilityChanged));
509

    
510
        public static readonly DependencyProperty TextBlockVisibilityProperty = DependencyProperty.Register(
511
            "TextBlockVisibility", typeof(Visibility), typeof(TextControl), new PropertyMetadata((Visibility.Collapsed), OnTextBlockVisibilityChanged));
512

    
513
        #endregion Dependency Properties
514

    
515
        #region dp Properties
516

    
517

    
518
        public override SolidColorBrush StrokeColor
519
        {
520
            get { return (SolidColorBrush)GetValue(StrokeColorProperty); }
521
            set
522
            {
523
                if (this.StrokeColor != value)
524
                {
525
                    SetValue(StrokeColorProperty, value);
526
                }
527
            }
528
        }
529

    
530
        public Double ArcLength
531
        {
532
            get { return (Double)GetValue(ArcLengthProperty); }
533
            set
534
            {
535
                if (this.ArcLength != value)
536
                {
537
                    SetValue(ArcLengthProperty, value);
538
                    OnPropertyChanged("ArcLength");
539
                }
540
            }
541
        }
542

    
543
        public bool EnableEditing
544
        {
545
            get { return (bool)GetValue(EnableEditingProperty); }
546
            set
547
            {
548
                if (this.EnableEditing != value)
549
                {
550
                    SetValue(EnableEditingProperty, value);
551
                    OnPropertyChanged("EnableEditing");
552
                }
553
            }
554
        }
555

    
556
        public Thickness LineSize
557
        {
558
            get
559
            {
560
                return (Thickness)GetValue(LineSizeProperty);
561
            }
562
            set
563
            {
564
                if (this.LineSize != value)
565
                {
566
                    SetValue(LineSizeProperty, value);
567
                    OnPropertyChanged("LineSize");
568
                }
569
            }
570
        }
571

    
572
        public override ControlType ControlType
573
        {
574
            get
575
            {
576
                return (ControlType)GetValue(ControlTypeProperty);
577
            }
578
            set
579
            {
580
                SetValue(ControlTypeProperty, value);
581
            }
582
        }
583
        public int ControlType_No
584
        {
585
            get
586
            {
587
                return (int)GetValue(ControlType_NoProperty);
588
            }
589
            set
590
            {
591
                SetValue(ControlType_NoProperty, value);
592
            }
593
        }
594

    
595
        public string UserID
596
        {
597
            get { return (string)GetValue(UserIDProperty); }
598
            set
599
            {
600
                if (this.UserID != value)
601
                {
602
                    SetValue(UserIDProperty, value);
603
                    OnPropertyChanged("UserID");
604
                }
605
            }
606
        }
607

    
608
        public double CenterX
609
        {
610
            get { return (double)GetValue(CenterXProperty); }
611
            set
612
            {
613
                SetValue(CenterXProperty, value);
614
                OnPropertyChanged("CenterX");
615

    
616
            }
617
        }
618

    
619
        public double CenterY
620
        {
621
            get { return (double)GetValue(CenterYProperty); }
622
            set
623
            {
624
                SetValue(CenterYProperty, value);
625
                OnPropertyChanged("CenterY");
626
            }
627
        }
628

    
629
        public string Text
630
        {
631
            get { return (string)GetValue(TextProperty); }
632
            set
633
            {
634
                if (this.Text != value)
635
                {
636
                    SetValue(TextProperty, value);
637
                    OnPropertyChanged("Text");
638
                }
639
            }
640
        }
641

    
642
        public string OverViewText
643
        {
644
            get { return (string)GetValue(OverViewTextProperty); }
645
            set
646
            {
647
                if (this.OverViewText != value)
648
                {
649
                    SetValue(OverViewTextProperty, value);
650
                    OnPropertyChanged("OverViewText");
651
                }
652
            }
653
        }
654

    
655
        public Geometry OverViewPathData
656
        {
657
            get { return (Geometry)GetValue(OverViewPathDataProperty); }
658
            set
659
            {
660
                if (this.OverViewPathData != value)
661
                {
662
                    SetValue(OverViewPathDataProperty, value);
663
                    OnPropertyChanged("OverViewPathData");
664
                }
665
            }
666
        }
667

    
668
        public Visibility TextBoxVisibility
669
        {
670
            get { return (Visibility)GetValue(TextBoxVisibilityProperty); }
671
            set
672
            {
673
                if (this.TextBoxVisibility != value)
674
                {
675
                    SetValue(TextBoxVisibilityProperty, value);
676
                    OnPropertyChanged("TextBoxVisibility");
677
                }
678
            }
679
        }
680

    
681

    
682
        public Visibility TextBlockVisibility
683
        {
684
            get { return (Visibility)GetValue(TextBlockVisibilityProperty); }
685
            set
686
            {
687
                if (this.TextBlockVisibility != value)
688
                {
689
                    SetValue(TextBlockVisibilityProperty, value);
690
                    OnPropertyChanged("TextBlockVisibility");
691
                }
692
            }
693
        }
694

    
695

    
696

    
697
        public Double TextSize
698
        {
699
            get { return (Double)GetValue(TextSizeProperty); }
700
            set
701
            {
702
                if (this.TextSize != value)
703
                {
704
                    SetValue(TextSizeProperty, value);
705
                    OnPropertyChanged("TextSize");
706
                }
707
            }
708
        }
709
        /*
710
        public SolidColorBrush FontColor
711
        {
712
            get { return (SolidColorBrush)GetValue(FontColorProperty); }
713
            set
714
            {
715
                if (this.FontColor != value)
716
                {
717
                    SetValue(FontColorProperty, value);
718
                    OnPropertyChanged("FontColor");
719
                }
720
            }
721
        }*/
722

    
723
        public SolidColorBrush BackColor
724
        {
725
            get { return (SolidColorBrush)GetValue(BackColorProperty); }
726
            set
727
            {
728
                if (this.BackColor != value)
729
                {
730
                    SetValue(BackColorProperty, value);
731
                    OnPropertyChanged("BackColor");
732
                }
733
            }
734
        }
735

    
736
        public SolidColorBrush BackInnerColor
737
        {
738
            get { return (SolidColorBrush)GetValue(BackInnerColorProperty); }
739
            set
740
            {
741
                if (this.BackInnerColor != value)
742
                {
743
                    SetValue(BackInnerColorProperty, value);
744
                    OnPropertyChanged("BackInnerColor");
745
                }
746
            }
747
        }
748

    
749

    
750

    
751
        public TextDecorationCollection UnderLine
752
        {
753
            get
754
            {
755
                return (TextDecorationCollection)GetValue(UnderLineProperty);
756
            }
757
            set
758
            {
759
                if (this.UnderLine != value)
760
                {
761
                    SetValue(UnderLineProperty, value);
762
                    OnPropertyChanged("UnderLine");
763
                }
764
            }
765
        }
766

    
767
        public double CanvasX
768
        {
769
            get { return (double)GetValue(CanvasXProperty); }
770
            set
771
            {
772
                if (this.CanvasX != value)
773
                {
774
                    SetValue(CanvasXProperty, value);
775
                    OnPropertyChanged("CanvasX");
776
                }
777
            }
778
        }
779

    
780
        public double CanvasY
781
        {
782
            get { return (double)GetValue(CanvasYProperty); }
783
            set
784
            {
785
                if (this.CanvasY != value)
786
                {
787
                    SetValue(CanvasYProperty, value);
788
                    OnPropertyChanged("CanvasY");
789
                }
790
            }
791
        }
792

    
793
        public Point EndPoint
794
        {
795
            get { return (Point)GetValue(EndPointProperty); }
796
            set
797
            {
798
                if (this.EndPoint != value)
799
                {
800
                    SetValue(EndPointProperty, value);
801
                    OnPropertyChanged("EndPoint");
802
                }
803
            }
804
        }
805

    
806
        public Point StartPoint
807
        {
808
            get { return (Point)GetValue(StartPointProperty); }
809
            set
810
            {
811
                if (this.StartPoint != value)
812
                {
813
                    SetValue(StartPointProperty, value);
814
                    OnPropertyChanged("StartPoint");
815
                }
816
            }
817
        }
818

    
819
        public FontStyle TextStyle
820
        {
821
            get { return (FontStyle)GetValue(TextStyleProperty); }
822
            set
823
            {
824
                if (this.TextStyle != value)
825
                {
826
                    SetValue(TextStyleProperty, value);
827
                    OnPropertyChanged("TextStyle");
828
                }
829
            }
830
        }
831

    
832
        public FontFamily TextFamily
833
        {
834
            get { return (FontFamily)GetValue(TextFamilyProperty); }
835
            set
836
            {
837
                if (this.TextFamily != value)
838
                {
839
                    SetValue(TextFamilyProperty, value);
840
                    OnPropertyChanged("TextFamily");
841
                }
842
            }
843
        }
844

    
845
        public FontWeight TextWeight
846
        {
847
            get { return (FontWeight)GetValue(TextWeightProperty); }
848
            set
849
            {
850
                if (this.TextWeight != value)
851
                {
852
                    SetValue(TextWeightProperty, value);
853
                    OnPropertyChanged("TextWeight");
854
                }
855
            }
856
        }
857

    
858
        public PaintSet Paint
859
        {
860
            get { return (PaintSet)GetValue(PaintProperty); }
861
            set
862
            {
863
                if (this.Paint != value)
864
                {
865
                    SetValue(PaintProperty, value);
866
                    OnPropertyChanged("Paint");
867
                }
868
            }
869
        }
870

    
871
        public PaintSet OverViewPaint
872
        {
873
            get { return (PaintSet)GetValue(OverViewPaintProperty); }
874
            set
875
            {
876
                if (this.OverViewPaint != value)
877
                {
878
                    SetValue(OverViewPaintProperty, value);
879
                    OnPropertyChanged("OverViewPaint");
880
                }
881
            }
882
        }
883

    
884
        double IPath.LineSize
885
        {
886
            get
887
            {
888
                return this.LineSize.Left;
889
            }
890
            set
891
            {
892
                this.LineSize = new Thickness(value);
893
                OnPropertyChanged("LineSize");
894
            }
895
        }
896

    
897

    
898
        public Geometry PathData
899
        {
900
            get { return (Geometry)GetValue(PathDataProperty); }
901
            set
902
            {
903
                SetValue(PathDataProperty, value);
904
                OnPropertyChanged("PathData");
905
            }
906
        }
907

    
908
        public Geometry PathDataInner
909
        {
910
            get { return (Geometry)GetValue(PathDataInnerProperty); }
911
            set
912
            {
913
                SetValue(PathDataInnerProperty, value);
914
                OnPropertyChanged("PathDataInner");
915
            }
916
        }
917

    
918
        public override double CommentAngle
919
        {
920
            get { return (double)GetValue(AngleProperty); }
921
            set
922
            {
923
                if (this.CommentAngle != value)
924
                {
925
                    SetValue(AngleProperty, value);
926

    
927
                    OnPropertyChanged("Angle");
928
                    UpdateLayout();
929
                }
930
            }
931
        }
932

    
933
        public bool IsHighLight
934
        {
935
            get { return (bool)GetValue(IsHighlightProperty); }
936
            set
937
            {
938
                if (this.IsHighLight != value)
939
                {
940
                    SetValue(IsHighlightProperty, value);
941
                    OnPropertyChanged("IsHighLight");
942
                }
943
            }
944
        }
945

    
946
        public List<Point> PointSet
947
        {
948
            get { return (List<Point>)GetValue(PointSetProperty); }
949
            set
950
            {
951
                SetValue(PointSetProperty, value);
952
                OnPropertyChanged("PointSet");
953
            }
954
        }
955

    
956
        #endregion Properties
957

    
958
        #region Properties
959

    
960
        private bool _IsEditingMode;
961
        public bool IsEditingMode
962
        {
963
            get
964
            {
965
                return _IsEditingMode;
966
            }
967
            set
968
            {
969
                _IsEditingMode = value;
970
                OnPropertyChanged("IsEditingMode");
971
            }
972
        }
973

    
974
        public PathGeometry PathGeometry
975
        {
976
            get { return (PathGeometry)GetValue(PathGeometryProperty); }
977
            set
978
            {
979
                SetValue(PathGeometryProperty, value);
980
                OnPropertyChanged("PathGeometry");
981
            }
982
        }
983

    
984
        private double _BoxWidth;
985
        public double BoxWidth
986
        {
987
            get
988
            {
989
                return _BoxWidth;
990
            }
991
            set
992
            {
993
                _BoxWidth = value;
994
                OnPropertyChanged("BoxWidth");
995
            }
996
        }
997

    
998
        private double _BoxHeight;
999
        public double BoxHeight
1000
        {
1001
            get
1002
            {
1003
                return _BoxHeight;
1004
            }
1005
            set
1006
            {
1007
                _BoxHeight = value;
1008
                OnPropertyChanged("BoxHeight");
1009
            }
1010
        }
1011

    
1012
        #endregion
1013

    
1014
        #region CallBack Method
1015

    
1016
        private static void TextFamilyPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
1017
        {
1018
            //var instance = (TextControl)d;
1019

    
1020
            //instance.SetFontFamily(e.NewValue as FontFamily);
1021
        }
1022

    
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
            if (propName == "UnderLine" && Base_TextBlock != null)
1160
            {
1161
                Base_TextBlock.TextDecorations = UnderLine;
1162
                //(sender as TextControl).Base_TextBlock.TextDecorations = (sender as TextControl).UnderLine;
1163
            }
1164
        }
1165

    
1166
        /// <summary>
1167
        /// return textcontrols' area
1168
        /// </summary>
1169
        public override Rect ItemRect
1170
        {
1171
            get
1172
            {
1173
                Point start = new Point(this.CanvasX, this.CanvasY);
1174

    
1175
                Point length = new Point();
1176
                double angle = this.CommentAngle * Math.PI / 180;
1177

    
1178
                length.X = this.BoxWidth * Math.Cos(angle) - this.BoxHeight * Math.Sin(angle);
1179
                length.Y = this.BoxWidth * Math.Sin(angle) + this.BoxHeight * Math.Cos(angle);
1180

    
1181
                Point end = new Point(start.X + length.X, start.Y + length.Y);
1182
                return new Rect(start, end);
1183
            }
1184
        }
1185

    
1186
        /// <summary>
1187
        /// translate control along given dx,dy
1188
        /// </summary>
1189
        /// <param name="dx"></param>
1190
        /// <param name="dy"></param>
1191
        public override void OnTranslate(double dx, double dy)
1192
        {
1193
            //this.CanvasX = Canvas.GetLeft(this) + dx;
1194
            //this.CanvasY = Canvas.GetTop(this) + dy;
1195
            this.StartPoint = new Point(this.StartPoint.X + dx, this.StartPoint.Y + dy);
1196
            this.EndPoint = new Point(this.EndPoint.X + dx, this.EndPoint.Y + dy);
1197

    
1198
            this.SetValue(TextControl.CanvasXProperty, Canvas.GetLeft(this) + dx);
1199
            this.SetValue(TextControl.CanvasYProperty, Canvas.GetTop(this) + dy);
1200

    
1201

    
1202

    
1203

    
1204
            //Canvas.SetLeft(this, Canvas.GetLeft(this) + dx);
1205
            //Canvas.SetTop(this, Canvas.GetTop(this) + dy);
1206
        }
1207

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

    
1224
                if (this.StartPoint == new Point())
1225
                    STemp.StartPoint = new Point(this.CanvasX, this.CanvasY);
1226
                else
1227
                    STemp.StartPoint = this.StartPoint;
1228

    
1229
                STemp.EndPoint = this.EndPoint;
1230
                STemp.Opac = this.Opacity;
1231
                STemp.PointSet = this.PointSet;
1232
                STemp.Angle = this.CommentAngle;
1233
                STemp.paintMethod = this.ControlType_No;
1234
                STemp.BoxW = this.BoxWidth;
1235
                STemp.BoxH = this.BoxHeight;
1236
                STemp.isHighLight = this.IsHighLight;
1237
                STemp.Name = this.GetType().Name.ToString();
1238
                STemp.fontConfig = new List<string>()
1239
                            {
1240
                                this.TextFamily.FontName(),
1241
                                this.TextStyle.ToString(),
1242
                                this.TextWeight.ToString(),
1243
                            };
1244

    
1245

    
1246

    
1247
                if (this.UnderLine != null)
1248
                {
1249
                    STemp.fontConfig.Add("true");
1250
                }
1251

    
1252
                ///강인구 추가(2017.11.02)
1253
                ///Memo 추가
1254
                STemp.Memo = this.Memo;
1255

    
1256
                return "|DZ|" + JsonSerializerHelper.CompressString((STemp.JsonSerialize()));
1257
            }
1258
        }
1259

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

    
1296
                if (s.fontConfig.Count() == 4)
1297
                {
1298
                    instance.UnderLine = TextDecorations.Underline;
1299
                }
1300

    
1301
                return instance;
1302
            }
1303
        }
1304
    }
1305
}
클립보드 이미지 추가 (최대 크기: 500 MB)