/
iMarkupYourOtherMind.cs
696 lines (540 loc) · 27.3 KB
/
iMarkupYourOtherMind.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
// iMarkupYourOtherMind.cs
//
// Copyright (c) 2013 Brent Knowles (http://www.brentknowles.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// Review documentation at http://www.yourothermind.com for updated implementation notes, license updates
// or other general information/
//
// Author information available at http://www.brentknowles.com or http://www.amazon.com/Brent-Knowles/e/B0035WW7OW
// Full source code: https://github.com/BrentKnowles/YourOtherMind
//###
//
// iMarkupYourOtherMind.cs
//
// Authors:
// Brent Knowles <writer@brentknowles.com>
//
// Copyright (C) 2013 Brent Knowles
// [LICENSE MUST BE REDONE]
//
using System;
using Layout;
using CoreUtilities;
using System.Windows.Forms;
using System.Drawing;
using System.Collections;
using System.Text.RegularExpressions;
using System.Collections.Generic;
namespace YourOtherMind
{
public class iMarkupYourOtherMind : iMarkupLanguage
{
public iMarkupYourOtherMind ()
{
}
public override string ToString ()
{
return nameAndIdentifier;
}
private string nameAndIdentifier= Loc.Instance.GetString("YourOtherMind");
public string NameAndIdentifier {
get {
return nameAndIdentifier;
}
set {
nameAndIdentifier = value;
}
}
public string CleanWordRequest(string incoming)
{
string sLine = incoming.Replace ("[[words]]", "").Trim ();
return sLine;
}
public bool IsWordRequest (string incoming)
{
bool result = false;
if (incoming.IndexOf ("[[words]]") > -1) {
result = true;
}
return result;
}
public bool IsOver (string incoming)
{
bool result = false;
if (incoming.IndexOf ("[[end") > -1) {
result = true;
}
return result;
}
public bool IsGroupRequest (string incoming)
{
bool result = false;
if (incoming.IndexOf ("[[Group") > -1) {
result = true;
}
return result;
}
public bool IsIndex (string incoming)
{
bool result = false;
if ( "[[index]]" == incoming) {
result = true;
}
return result;
}
void PaintLink (PaintEventArgs e, int Start, int End, RichTextBox RichText)
{
Graphics g;
g = RichText.CreateGraphics ();
//Pen myPen = null;// new Pen (Color.FromArgb (60, Color.Yellow)); // Alpha did not seem to work this way
// this gets tricky. The loop is just to find all the [[~scenes]] on the note
// even if offscreen.
// OK: but with th eoptimization to only show on screen stuff, do we need this anymore???
// august 10 - settting it back
// now trying regex
System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex ("\\w\\|\\w",
System.Text.RegularExpressions.RegexOptions.IgnoreCase |
System.Text.RegularExpressions.RegexOptions.Multiline);
System.Text.RegularExpressions.MatchCollection matches = regex.Matches (RichText.Text, Start);
foreach (System.Text.RegularExpressions.Match match in matches) {
if (match.Index > End)
break; // we exit if already at end
Point pos = RichText.GetPositionFromCharIndex (match.Index);
if (pos.X > -1 && pos.Y > -1) {
int testpos = match.Index + 2;
Color colorToUse = Color.FromArgb(255, ControlPaint.Dark (TextUtils.InvertColor(RichText.BackColor)));
// default is [[facts]] and stuff
pos = CoreUtilities.General.BuildLocationForOverlayText (pos, DockStyle.Bottom, "|");
System.Drawing.SolidBrush brush1 = new System.Drawing.SolidBrush( colorToUse);
//myPen.Width = 1;
//myPen.Color = Color.Red;
int scaler = Math.Max (10, (int)(Math.Round (RichText.ZoomFactor / 2) * 10));
Rectangle rec = new Rectangle (new Point (pos.X, pos.Y - 25), new Size ((int)(scaler * 1.5), (int)(scaler * 0.75)));
Rectangle rec2 = new Rectangle (new Point (pos.X+20, pos.Y - 25), new Size ((int)(scaler * 1), (int)(scaler * 0.65)));
//g.DrawLine(myPen, pos.X, pos.Y -10, pos.X + 50, pos.Y-10);
//g.FillRectangle (brush1, rec);
g.FillEllipse(brush1, rec);
g.FillEllipse(brush1, rec2);
}
/*
locationInText = locationInText + sParam.Length;
if (locationInText > end)
{
// don't search past visible end
pos = emptyPoint;
}
else
pos = GetPositionForFoundText(sParam, ref locationInText);*/
}
// regex matches
g.Dispose ();
//myPen.Dispose ();
}
int BuildScaler (float zoomFactor)
{
return Math.Max (10, (int)(Math.Round (zoomFactor / 2) * 10));
}
void PaintNoSpaceAfterPeriod (PaintEventArgs e, int Start, int End, RichTextBox RichText)
{
Graphics g;
g = RichText.CreateGraphics ();
//Pen myPen = null;// new Pen (Color.FromArgb (60, Color.Yellow)); // Alpha did not seem to work this way
// this gets tricky. The loop is just to find all the [[~scenes]] on the note
// even if offscreen.
// OK: but with th eoptimization to only show on screen stuff, do we need this anymore???
// august 10 - settting it back
// now trying regex
System.Text.RegularExpressions.Regex regex =
new System.Text.RegularExpressions.Regex ("\\.\\w|\\. \\w|\\?\\w|\\? \\w|\\!\\w|\\! \\w|\\;\\w|\\; \\w|\\:\\w|\\: \\w|\\,\\w|\\, \\w",
System.Text.RegularExpressions.RegexOptions.IgnoreCase | RegexOptions.Compiled|
System.Text.RegularExpressions.RegexOptions.Multiline);
System.Text.RegularExpressions.MatchCollection matches = regex.Matches (RichText.Text, Start);
foreach (System.Text.RegularExpressions.Match match in matches) {
if (match.Index > End)
break; // we exit if already at end
Point pos = RichText.GetPositionFromCharIndex (match.Index);
if (pos.X > -1 && pos.Y > -1) {
int testpos = match.Index + 2;
Color colorToUse = Color.FromArgb(175, Color.Red);
// default is [[facts]] and stuff
// pos = CoreUtilities.General.BuildLocationForOverlayText (pos, DockStyle.Bottom, " ");
// System.Drawing.SolidBrush brush1 = new System.Drawing.SolidBrush( colorToUse);
System.Drawing.Pen pen1 = new Pen(colorToUse);
//myPen.Width = 1;
//myPen.Color = Color.Red;
// int scaler = BuildScaler(RichText.ZoomFactor);
Rectangle rec = GetRectangleForSmallRectangle(g, pos, RichText, match.Index, match.Value, true);// new Rectangle (new Point (pos.X+(int)(scaler*1.5), pos.Y -(5+scaler)), new Size ((int)(scaler * 1.5), (int)(scaler * 1.5)));
//Rectangle rec = new Rectangle (new Point (pos.X+scaler, pos.Y-15), new Size ((int)(scaler * 1.5), (int)(scaler * 0.75)));
// Rectangle rec2 = new Rectangle (new Point (pos.X+20, pos.Y - 25), new Size ((int)(scaler * 1), (int)(scaler * 0.65)));
//g.DrawLine(myPen, pos.X, pos.Y -10, pos.X + 50, pos.Y-10);
//g.FillRectangle (brush1, rec);
//g.FillEllipse(brush1, rec);
rec.Height = 1;
g.DrawRectangle(pen1, rec);
// g.FillEllipse(brush1, rec2);
}
/*
locationInText = locationInText + sParam.Length;
if (locationInText > end)
{
// don't search past visible end
pos = emptyPoint;
}
else
pos = GetPositionForFoundText(sParam, ref locationInText);*/
}
// regex matches
g.Dispose ();
//myPen.Dispose ();
}
void PaintDoubleSpaces (PaintEventArgs e, int Start, int End, RichTextBox RichText)
{
Graphics g;
g = RichText.CreateGraphics ();
//Pen myPen = null;// new Pen (Color.FromArgb (60, Color.Yellow)); // Alpha did not seem to work this way
// this gets tricky. The loop is just to find all the [[~scenes]] on the note
// even if offscreen.
// OK: but with th eoptimization to only show on screen stuff, do we need this anymore???
// august 10 - settting it back
// now trying regex
System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex ("\\w \\w",
System.Text.RegularExpressions.RegexOptions.IgnoreCase | RegexOptions.Compiled|
System.Text.RegularExpressions.RegexOptions.Multiline);
System.Text.RegularExpressions.MatchCollection matches = regex.Matches (RichText.Text, Start);
foreach (System.Text.RegularExpressions.Match match in matches) {
if (match.Index > End)
break; // we exit if already at end
Point pos = RichText.GetPositionFromCharIndex (match.Index);
if (pos.X > -1 && pos.Y > -1) {
int testpos = match.Index + 2;
Color colorToUse = Color.FromArgb(175, Color.Red);
// default is [[facts]] and stuff
// pos = CoreUtilities.General.BuildLocationForOverlayText (pos, DockStyle.Bottom, " ");
// System.Drawing.SolidBrush brush1 = new System.Drawing.SolidBrush( colorToUse);
System.Drawing.Pen pen1 = new Pen(colorToUse);
//myPen.Width = 1;
//myPen.Color = Color.Red;
// int scaler = BuildScaler(RichText.ZoomFactor);
Rectangle rec = GetRectangleForSmallRectangle(g, pos, RichText, match.Index, match.Value, true);// new Rectangle (new Point (pos.X+(int)(scaler*1.5), pos.Y -(5+scaler)), new Size ((int)(scaler * 1.5), (int)(scaler * 1.5)));
//Rectangle rec = new Rectangle (new Point (pos.X+scaler, pos.Y-15), new Size ((int)(scaler * 1.5), (int)(scaler * 0.75)));
// Rectangle rec2 = new Rectangle (new Point (pos.X+20, pos.Y - 25), new Size ((int)(scaler * 1), (int)(scaler * 0.65)));
//g.DrawLine(myPen, pos.X, pos.Y -10, pos.X + 50, pos.Y-10);
//g.FillRectangle (brush1, rec);
//g.FillEllipse(brush1, rec);
rec.Height = 1;
g.DrawRectangle(pen1, rec);
// g.FillEllipse(brush1, rec2);
}
/*
locationInText = locationInText + sParam.Length;
if (locationInText > end)
{
// don't search past visible end
pos = emptyPoint;
}
else
pos = GetPositionForFoundText(sParam, ref locationInText);*/
}
// regex matches
g.Dispose ();
//myPen.Dispose ();
}
/// <summary>
/// Gets the main headings.
///
/// Used for TabNavigation
/// </summary>
/// <returns>
/// The main headings.
/// </returns>
/// <param name='box'>
/// Box.
/// </param>
public List<string> GetMainHeadings (RichTextBox box)
{
System.Text.RegularExpressions.Regex Mainheading = new System.Text.RegularExpressions.Regex ("^=[^=]+=$",
RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.Multiline);
MatchCollection matches = Mainheading.Matches (box.Text, 0);
List<string> result = new List<string>();
foreach (System.Text.RegularExpressions.Match match in matches) {
result.Add (match.Value);
}
return result;
}
void PaintHeadings (PaintEventArgs e, int Start, int End, RichTextBox RichText, System.Text.RegularExpressions.Regex regex2, Color color, string text, Font f)
{
//string exp = ".*\\=([^)]+?)\\=";
// this one was fast but inaccurate (very)
//string exp = String.Format (".*?\\=\\w([^)]+?)\\w\\={0}?", Environment.NewLine); // added lazy operations to attempt a speed improvement
Graphics g = e.Graphics;//RichText.CreateGraphics ();
System.Drawing.Pen pen1 = new Pen(color);
System.Text.RegularExpressions.MatchCollection matches = regex2.Matches (RichText.Text, Start);
foreach (System.Text.RegularExpressions.Match match in matches) {
if (match.Index > End)
break; // we exit if already at end
Point pos = RichText.GetPositionFromCharIndex (match.Index);
if (pos.X > -1 && pos.Y > -1) {
pen1.Width = 8;
string stext = text+match.Value+text;
//pos = CoreUtilities.General.BuildLocationForOverlayText (pos, DockStyle.Right,match.Value );
int newWidth = Convert.ToInt32 (g.MeasureString (stext, f).Width * RichText.ZoomFactor);
pos = new Point(pos.X + (newWidth), pos.Y + 10);
g.DrawLine (pen1, pos.X, pos.Y, pos.X + 500, pos.Y);
// Rectangle rec = GetRectangleForSmallRectangle(g, pos, RichText, match.Index, match.Value, true);// new Rectangle (new Point (pos.X+(int)(scaler*1.5), pos.Y -(5+scaler)), new Size ((int)(scaler * 1.5), (int)(scaler * 1.5)));
// rec.Height = 2;
//
// g.DrawRectangle(pen1, rec);
}
}
// g.Dispose (); don't dispose what we are borrowing
}
System.Text.RegularExpressions.Regex Mainheading = new System.Text.RegularExpressions.Regex ("^=[^=]+=$",
RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Compiled| System.Text.RegularExpressions.RegexOptions.Multiline );
System.Text.RegularExpressions.Regex Mainheading2 = new System.Text.RegularExpressions.Regex ("^==[^=]+==$",
RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Compiled| System.Text.RegularExpressions.RegexOptions.Multiline );
System.Text.RegularExpressions.Regex Mainheading3 = new System.Text.RegularExpressions.Regex ("^===[^=]+===$",
RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Compiled| System.Text.RegularExpressions.RegexOptions.Multiline );
public void DoPaint (PaintEventArgs e, int Start, int End, RichTextBox RichText)
{
try {
PaintDoubleSpaces(e, Start, End, RichText);
PaintNoSpaceAfterPeriod(e, Start, End, RichText);
PaintLink(e, Start, End, RichText);
bool doheadings = true;
if (doheadings)
{
Font f = new Font(RichText.Font.FontFamily, RichText.Font.Size, RichText.Font.Style, GraphicsUnit.Pixel, Convert.ToByte(0), false);
Color newColor = TextUtils.InvertColor(RichText.BackColor);
Color colorToUse = Color.FromArgb(175, ControlPaint.Dark(newColor));
PaintHeadings(e, Start, End, RichText, Mainheading, colorToUse,"=",f);
colorToUse = Color.FromArgb(175,ControlPaint.Light(newColor));
PaintHeadings(e, Start, End, RichText, Mainheading2, colorToUse,"==",f);
colorToUse = Color.FromArgb(175, ControlPaint.LightLight(newColor));
PaintHeadings(e, Start, End, RichText, Mainheading3, colorToUse,"===",f);
}
// int locationInText = GetCharIndexFromPosition(new Point(0, 0));
string sParam = "[[~scene]]";
// assuming function only being used for [[~scene]] delimiters
// I've moved this position up to core function as an optimization
// instead of being used in each call to GetPositionForFoundText
// int start =
// if (locationInText < start)
// {
// locationInText = start;
// }
// The loop is what makes this
// Point pos = GetPositionForFoundText(sParam, ref locationInText);
Graphics g;
//g = RichText.CreateGraphics ();
g = e.Graphics;
Pen myPen = new Pen (Color.FromArgb (255, ControlPaint.LightLight (TextUtils.InvertColor(RichText.BackColor))));
// this gets tricky. The loop is just to find all the [[~scenes]] on the note
// even if offscreen.
// OK: but with th eoptimization to only show on screen stuff, do we need this anymore???
// august 10 - settting it back
// now trying regex
// This worked for = match but it was WAAY too slow
// System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex (".*\\=([^)]+)\\=",
// System.Text.RegularExpressions.RegexOptions.IgnoreCase);
// this works just experimenting
System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex ("\\[\\[(.*?)\\]\\]",
System.Text.RegularExpressions.RegexOptions.IgnoreCase |
System.Text.RegularExpressions.RegexOptions.Multiline);
System.Text.RegularExpressions.MatchCollection matches = regex.Matches (RichText.Text, Start);
foreach (System.Text.RegularExpressions.Match match in matches) {
if (match.Index > End)
break; // we exit if already at end
Point pos = RichText.GetPositionFromCharIndex (match.Index);
if (pos.X > -1 && pos.Y > -1) {
// but we only draw the line IF we are onscreen
//if (pos.X > -1 && pos.Y > -1)
//if (sParam == "[[~scene]]")
//test instead to see if pos + 2 is a ~
int testpos = match.Index + 2;
/// November 2012 - only want this to appear for ~scene
if (RichText.Text.Length > (testpos + 1) && RichText.Text [testpos] == '~' && RichText.Text [testpos + 1] == 's') {
if (g != null) {
//myPen.Color = Color.Yellow;
// myPen = new Pen (Color.FromArgb (225, Color.Yellow));
myPen.Width = 8;
pos = CoreUtilities.General.BuildLocationForOverlayText (pos, DockStyle.Right, sParam);
g.DrawLine (myPen, pos.X, pos.Y, pos.X + 500, pos.Y);
}
} else {
Color colorToUse = Color.FromArgb (255, ControlPaint.LightLight (TextUtils.InvertColor(RichText.BackColor)));//Color.FromArgb(255, Color.Green);
// November 2012 - testing to see if there's a period right before which means it will count)
if (match.Index > 0) {
if ('.' == RichText.Text [match.Index - 1]) {
// we have a period so the code .[[f]] will not do anything
// show in a different color
colorToUse = Color.Red;// Alpha worked but because not all areas are redrawn at same time did not look right (May 2013) Color.FromArgb(255, Color.Red);
}
}
// default is [[facts]] and stuff
//pos = CoreUtilities.General.BuildLocationForOverlayText (pos, DockStyle.Bottom, sParam);
// if (e.Graphics. .Contains(pos))
{
//System.Drawing.SolidBrush brush1 = new System.Drawing.SolidBrush (colorToUse);
System.Drawing.Pen pen1 = new System.Drawing.Pen (colorToUse);
//myPen.Width = 1;
//myPen.Color = Color.Red;
//int scaler = BuildScaler(RichText.ZoomFactor);
Rectangle rec = GetRectangleForSmallRectangle(g, pos, RichText, match.Index, match.Value, false);// new Rectangle (new Point (pos.X+(int)(scaler*1.5), pos.Y -(5+scaler)), new Size ((int)(scaler * 1.5), (int)(scaler * 1.5)));
//g.DrawLine(myPen, pos.X, pos.Y -10, pos.X + 50, pos.Y-10);
// SolidBrush brushEmpty = new SolidBrush(RichText.BackColor);
// g.FillRectangle (brushEmpty, rec);
g.DrawRectangle (pen1, rec);
}
}
/*
locationInText = locationInText + sParam.Length;
if (locationInText > end)
{
// don't search past visible end
pos = emptyPoint;
}
else
pos = GetPositionForFoundText(sParam, ref locationInText);*/
}
} // regex matches
// don't dispose of this, since it is used elsewhere (i.e., we did not create it)
// g.Dispose ();
myPen.Dispose ();
} catch (Exception ex) {
NewMessage.Show (String.Format ("Failed in WRITER part Start {0} End {1}", Start, End) + ex.ToString ());
}
}
// used for starting a rectangle or line from the point of a match
Point GetBottomLeftCornerOfMatch(Point passedPos, RichTextBox box)
{
Point newPoint = new Point ( (int)(passedPos.X + box.ZoomFactor), (int)(passedPos.Y - (box.ZoomFactor *.95)));
return newPoint;
}
// Rectangle GetRectangleForSmallRectangle (Graphics g, Point passedPos, RichTextBox box, int textposition, string text, bool drawFromBottom)
// {
// return GetRectangleForSmallRectangle(g, passedPos, box, textposition, text, drawFromBottom,Constants.BLANK);
// }
// returns a rectangle suitable for a small rectangle covering the beginning of the matched text
Rectangle GetRectangleForSmallRectangle (Graphics g, Point passedPos, RichTextBox box, int textposition, string text, bool drawFromBottom/*, string offsetx*/)
{
int scaler = BuildScaler (box.ZoomFactor);
Point newPos = GetBottomLeftCornerOfMatch (passedPos, box);
// int newX = ((int)(scaler * 1.5)) - scaler;
// int newY = (int)(scaler * 1.5);
// default is ignored. We construct width and height based on size of text
Size newSize = new Size (100, 100);
using (Font f = new Font(box.Font.FontFamily, box.Font.Size, box.Font.Style, GraphicsUnit.Pixel, Convert.ToByte(0), false)) {
//char ch = box.Text [textposition];
//newSize.Width = Convert.ToInt32 (g.MeasureString (ch.ToString(), f).Width * box.ZoomFactor);
newSize.Width = Convert.ToInt32 (g.MeasureString (text, f).Width * box.ZoomFactor);
// June 2013 -- the box height is slightly too much, trying to reduce
newSize.Height = Convert.ToInt32 (box.Font.Height * (box.ZoomFactor-0.15));
// // doh. We need to adjust yPosition to accomdate the way rectangles draw
if (true == drawFromBottom) {
newPos.Y = newPos.Y + newSize.Height;
}
// if (Constants.BLANK != offsetx) {
// // by default we start at the first left
// // but for certain things like headings we actually want to sh ift over towards the right a measure
// newPos.X = newPos.X + (offsetx.Length * newSize.Width);
// }
}
return new Rectangle(newPos, newSize);
}
public ArrayList GetListOfPages(string sLine, ref bool bGetWords, LayoutPanelBase usedLayout)
{
//NewMessage.Show ("YOM GetListOfPages for line = " + sLine);
ArrayList ListOfParsePages = new ArrayList();
string[] items = sLine.Split(',');
if (items != null)
{
string sStoryboardName = items[1];
string sGroupMatch = items[2];
if (sLine.IndexOf(",words") > -1)
{
bGetWords = true;
}
ListOfParsePages.AddRange(usedLayout.GetListOfGroupEmNameMatching(sStoryboardName, sGroupMatch));
//NewMessage.Show(sStoryboardName + " " + sGroupMatch);
}
return ListOfParsePages;
}
/// <summary>
/// Builds the list. for the bookmark system
/// </summary>
/// <returns>
/// The list.
/// </returns>
/// <param name='RichText'>
/// Rich text.
/// </param>
public List<TreeItem> BuildList (NoteDataXML_RichText RichText)
{
System.Text.RegularExpressions.Regex Mainheading = new System.Text.RegularExpressions.Regex ("^=[^=]+=$",
RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.Multiline);
System.Text.RegularExpressions.Regex Mainheading2 = new System.Text.RegularExpressions.Regex ("^==[^=]+==$",
RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.Multiline);
System.Text.RegularExpressions.Regex Mainheading3 = new System.Text.RegularExpressions.Regex ("^===[^=]+===$",
RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.Multiline);
System.Text.RegularExpressions.Regex Mainheading4 = new System.Text.RegularExpressions.Regex ("^====[^=]+====$",
RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.Multiline);
System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex ("\\[\\[~(.*?)\\]\\]",
System.Text.RegularExpressions.RegexOptions.IgnoreCase |
System.Text.RegularExpressions.RegexOptions.Multiline);
//TODO: Move this into the MarkupLanguage
List<TreeItem> items = new List<TreeItem> ();
//For [ ] text
System.Text.RegularExpressions.MatchCollection matches = regex.Matches (RichText.GetRichTextBox().Text, 0);
foreach (System.Text.RegularExpressions.Match match in matches) {
string value = match.Value;
if (value.IndexOf("~var") > -1)
{
// December 2013
// we don't show variable text.
}
else
{
items.Add (new TreeItem(match.Value, 0,match.Index));
}
}
matches = Mainheading.Matches (RichText.GetRichTextBox().Text, 0);
foreach (System.Text.RegularExpressions.Match match in matches) {
items.Add (new TreeItem(match.Value.Replace ("=",""), 0,match.Index));
}
matches = Mainheading2.Matches (RichText.GetRichTextBox().Text, 0);
foreach (System.Text.RegularExpressions.Match match in matches) {
items.Add (new TreeItem(match.Value.Replace ("=",""), 1,match.Index));
}
matches = Mainheading3.Matches (RichText.GetRichTextBox().Text, 0);
foreach (System.Text.RegularExpressions.Match match in matches) {
items.Add (new TreeItem(match.Value.Replace ("=",""), 2,match.Index));
}
matches = Mainheading4.Matches (RichText.GetRichTextBox().Text, 0);
foreach (System.Text.RegularExpressions.Match match in matches) {
items.Add (new TreeItem(match.Value.Replace ("=",""), 3,match.Index));
}
//need to somehow merge and sort by index
// need to a custom fort
items.Sort ();
return items;
}
}
}