Repository navigation
Expand file tree
/
Copy pathTextObject.cs
More file actions
1771 lines (1605 loc) · 65.4 KB
/
Copy pathTextObject.cs
File metadata and controls
1771 lines (1605 loc) · 65.4 KB
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
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Text;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Text;
using System.Drawing.Drawing2D;
using System.ComponentModel;
using FastReport.Utils;
using FastReport.Format;
using FastReport.Code;
using System.Windows.Forms;
using System.Drawing.Design;
namespace FastReport
{
/// <summary>
/// Specifies the horizontal alignment of a text in the TextObject object.
/// </summary>
public enum HorzAlign
{
/// <summary>
/// Specifies that text is aligned in the left of the layout rectangle.
/// </summary>
Left,
/// <summary>
/// Specifies that text is aligned in the center of the layout rectangle.
/// </summary>
Center,
/// <summary>
/// Specifies that text is aligned in the right of the layout rectangle.
/// </summary>
Right,
/// <summary>
/// Specifies that text is aligned in the left and right sides of the layout rectangle.
/// </summary>
Justify
}
/// <summary>
/// Specifies the vertical alignment of a text in the TextObject object.
/// </summary>
public enum VertAlign
{
/// <summary>
/// Specifies that text is aligned in the top of the layout rectangle.
/// </summary>
Top,
/// <summary>
/// Specifies that text is aligned in the center of the layout rectangle.
/// </summary>
Center,
/// <summary>
/// Specifies that text is aligned in the bottom of the layout rectangle.
/// </summary>
Bottom
}
/// <summary>
/// The type of text renderer
/// </summary>
public enum TextRenderType
{
/// <summary>
/// The default render
/// </summary>
Default,
/// <summary>
/// Render with some html tags and stable logic
/// </summary>
HtmlTags,
/// <summary>
/// Render with img tags, span etc. Experimental and unstable logic
/// </summary>
HtmlParagraph,
/// <summary>
/// Renders a text in a simplest way. For internal use only.
/// </summary>
Inline
}
/// <summary>
/// The format of paragraph
/// </summary>
[TypeConverter(typeof(TypeConverters.FRExpandableObjectConverter))]
public class ParagraphFormat
{
private float firstLineIndent;
private float lineSpacing;
private LineSpacingType lineSpacingType;
private bool skipFirstLineIndent;
/// <summary>
/// The first line on each paragraph, not effect if value less then 0
/// </summary>
[Browsable(true)]
[DefaultValue(0f)]
[TypeConverter("FastReport.TypeConverters.UnitsConverter, FastReport")]
public float FirstLineIndent
{
get { return firstLineIndent; }
set { if (value >= 0) firstLineIndent = value; }
}
/// <summary>
/// The distance between lines, not effect if value less then 0
/// </summary>
[Browsable(true)]
[DefaultValue(0f)]
[TypeConverter("FastReport.TypeConverters.UnitsConverter, FastReport")]
public float LineSpacing
{
get { return lineSpacing; }
set { if (value >= 0) lineSpacing = value; }
}
/// <summary>
/// The spacing type for distance between line calculation
/// </summary>
[Browsable(true)]
[DefaultValue(LineSpacingType.Single)]
public LineSpacingType LineSpacingType
{
get { return lineSpacingType; }
set { lineSpacingType = value; }
}
/// <summary>
/// The value for a multiplication line height for adding spacing
/// </summary>
[Browsable(true)]
[DefaultValue(0f)]
public float LineSpacingMultiple
{
get { return lineSpacing / 100f; }
set { if (value >= 0) lineSpacing = value * 100f; }
}
/// <summary>
/// Skip the line indent in the first paragraph, for broken paragraphs
/// </summary>
[Browsable(false)]
[DefaultValue(false)]
public bool SkipFirstLineIndent
{
get { return skipFirstLineIndent; }
set { skipFirstLineIndent = value; }
}
/// <summary>
/// clone with new scale;
/// </summary>
/// <param name="scale"></param>
/// <returns></returns>
internal ParagraphFormat MultipleScale(float scale)
{
ParagraphFormat clone = new ParagraphFormat();
clone.lineSpacingType = lineSpacingType;
if (LineSpacingType == LineSpacingType.Multiple)
clone.lineSpacing = lineSpacing;
else
clone.lineSpacing = lineSpacing * scale;
clone.firstLineIndent = firstLineIndent * scale;
clone.skipFirstLineIndent = skipFirstLineIndent;
return clone;
}
internal void Assign(ParagraphFormat p)
{
lineSpacingType = p.lineSpacingType;
lineSpacing = p.lineSpacing;
firstLineIndent = p.firstLineIndent;
skipFirstLineIndent = p.skipFirstLineIndent;
}
public override bool Equals(object obj)
{
ParagraphFormat format = obj as ParagraphFormat;
return format != null &&
firstLineIndent == format.firstLineIndent &&
lineSpacing == format.lineSpacing &&
lineSpacingType == format.lineSpacingType &&
skipFirstLineIndent == format.skipFirstLineIndent;
}
public override int GetHashCode()
{
unchecked
{
int hashCode = -1051315095;
hashCode = hashCode * -1521134295 + firstLineIndent.GetHashCode();
hashCode = hashCode * -1521134295 + lineSpacing.GetHashCode();
hashCode = hashCode * -1521134295 + lineSpacingType.GetHashCode();
hashCode = hashCode * -1521134295 + skipFirstLineIndent.GetHashCode();
return hashCode;
}
}
}
/// <summary>
/// The spacing type between lines
/// </summary>
public enum LineSpacingType
{
/// <summary>
/// Single spacing, not effect from LineSpacing
/// </summary>
Single,
/// <summary>
/// Minimal spacing in exactly size
/// </summary>
AtLeast,
/// <summary>
/// The specific distance between the lines, for some exports, does not work if the distance value is too small.
/// </summary>
Exactly,
/// <summary>
/// The calculated distance between lines, for some exports, does not work if the distance value is too small.
/// </summary>
Multiple
}
/// <summary>
/// Specifies the behavior of the <b>AutoShrink</b> feature of <b>TextObject</b>.
/// </summary>
public enum AutoShrinkMode
{
/// <summary>
/// AutoShrink is disabled.
/// </summary>
None,
/// <summary>
/// AutoShrink decreases the <b>Font.Size</b> property of the <b>TextObject</b>.
/// </summary>
FontSize,
/// <summary>
/// AutoShrink decreases the <b>FontWidthRatio</b> property of the <b>TextObject</b>.
/// </summary>
FontWidth
}
/// <summary>
/// Represents the Text object that may display one or several text lines.
/// </summary>
/// <remarks>
/// Specify the object's text in the <see cref="TextObjectBase.Text">Text</see> property.
/// Text may contain expressions and data items, for example: "Today is [Date]". When report
/// is running, all expressions are calculated and replaced with actual values, so the text
/// would be "Today is 01.01.2008".
/// <para/>The symbols used to find expressions in a text are set in the
/// <see cref="TextObjectBase.Brackets">Brackets</see> property. You also may disable expressions
/// using the <see cref="TextObjectBase.AllowExpressions">AllowExpressions</see> property.
/// <para/>To format an expression value, use the <see cref="Format"/> property.
/// </remarks>
public partial class TextObject : TextObjectBase
{
#region Fields
private bool autoWidth;
private HorzAlign horzAlign;
private VertAlign vertAlign;
private int angle;
private bool rightToLeft;
private bool wordWrap;
private bool underlines;
private Font font;
private FillBase textFill;
private TextOutline textOutline;
private StringTrimming trimming;
private float fontWidthRatio;
private float firstTabOffset;
private float tabWidth;
private FloatCollection tabPositions;
private bool clip;
private ConditionCollection highlight;
private bool wysiwyg;
private float lineHeight;
private bool forceJustify;
private TextRenderType textRenderType;
private AutoShrinkMode autoShrink;
private float autoShrinkMinSize;
private float paragraphOffset;
private FillBase savedTextFill;
private Font savedFont;
private string savedText;
private FormatBase savedFormat;
private InlineImageCache inlineImageCache;
private ParagraphFormat paragraphFormat;
private bool preserveLastLineSpace;
#endregion
#region Properties
/// <summary>
/// Gets or sets a paragraph format for a new html rendering type, not for others rendering
/// </summary>
[Category("Appearance")]
public ParagraphFormat ParagraphFormat
{
get { return paragraphFormat; }
set { paragraphFormat = value; }
}
/// <summary>
/// Gets or sets a value that determines if the text object should handle its width automatically.
/// </summary>
[DefaultValue(false)]
[Category("Behavior")]
public bool AutoWidth
{
get { return autoWidth; }
set { autoWidth = value; }
}
/// <summary>
/// Gets or sets a value that indicates whether the font size should shrink to
/// display the longest text line without word wrap.
/// </summary>
/// <remarks>
/// To limit the minimum size, use the <see cref="AutoShrinkMinSize"/> property.
/// </remarks>
[DefaultValue(AutoShrinkMode.None)]
[Category("Behavior")]
public AutoShrinkMode AutoShrink
{
get { return autoShrink; }
set { autoShrink = value; }
}
/// <summary>
/// Gets or sets the minimum size of font (or minimum width ratio) if the <see cref="AutoShrink"/>
/// mode is on.
/// </summary>
/// <remarks>
/// This property determines the minimum font size (in case the <see cref="AutoShrink"/> property is set to
/// <b>FontSize</b>), or the minimum font width ratio (if <b>AutoShrink</b> is set to <b>FontWidth</b>).
/// <para/>The default value is 0, that means no limits.
/// </remarks>
[DefaultValue(0f)]
[Category("Behavior")]
public float AutoShrinkMinSize
{
get { return autoShrinkMinSize; }
set { autoShrinkMinSize = value; }
}
/// <summary>
/// Gets or sets the horizontal alignment of a text in the TextObject object.
/// </summary>
[DefaultValue(HorzAlign.Left)]
[Category("Appearance")]
public HorzAlign HorzAlign
{
get { return horzAlign; }
set { horzAlign = value; }
}
/// <summary>
/// Gets or sets the vertical alignment of a text in the TextObject object.
/// </summary>
[DefaultValue(VertAlign.Top)]
[Category("Appearance")]
public VertAlign VertAlign
{
get { return vertAlign; }
set { vertAlign = value; }
}
/// <summary>
/// Gets or sets the text angle, in degrees.
/// </summary>
[DefaultValue(0)]
[Category("Appearance")]
[Editor("FastReport.TypeEditors.AngleEditor, FastReport", typeof(UITypeEditor))]
public int Angle
{
get { return angle; }
set { angle = value; }
}
/// <summary>
/// Gets or sets a value that indicates whether the component should draw right-to-left for RTL languages.
/// </summary>
[DefaultValue(false)]
[Category("Behavior")]
public bool RightToLeft
{
get { return rightToLeft; }
set { rightToLeft = value; }
}
/// <summary>
/// Gets or sets a value that indicates if lines are automatically word-wrapped.
/// </summary>
[DefaultValue(true)]
[Category("Behavior")]
public bool WordWrap
{
get { return wordWrap; }
set { wordWrap = value; }
}
/// <summary>
/// Gets or sets a value that determines if the text object will underline each text line.
/// </summary>
[DefaultValue(false)]
[Category("Appearance")]
public bool Underlines
{
get { return underlines; }
set { underlines = value; }
}
/// <summary>
/// Gets or sets the font settings for this object.
/// </summary>
[Category("Appearance")]
public Font Font
{
get { return font; }
set
{
font = value;
if (!String.IsNullOrEmpty(Style))
Style = "";
}
}
/// <summary>
/// Gets or sets a collection of TAB symbol positions, in pixels.
/// </summary>
/// <remarks>Use collection methods to add or remove TAB positions.</remarks>
public FloatCollection TabPositions
{
get { return tabPositions; }
set
{
if (value == null)
tabPositions.Clear();
else
tabPositions = value;
}
}
/// <summary>
/// Gets or sets the fill color used to draw a text.
/// </summary>
/// <remarks>
/// Default fill is <see cref="SolidFill"/>. You may specify other fill types, for example:
/// <code>
/// text1.TextFill = new HatchFill(Color.Black, Color.White, HatchStyle.Cross);
/// </code>
/// Use the <see cref="TextColor"/> property to set the solid text color.
/// </remarks>
[Category("Appearance")]
[Editor("FastReport.TypeEditors.FillEditor, FastReport", typeof(UITypeEditor))]
public FillBase TextFill
{
get { return textFill; }
set
{
if (value == null)
throw new ArgumentNullException("TextFill");
textFill = value;
if (!String.IsNullOrEmpty(Style))
Style = "";
}
}
/// <summary>
/// Gets or sets the text outline.
/// </summary>
[Category("Appearance")]
[Editor("FastReport.TypeEditors.OutlineEditor, FastReport", typeof(UITypeEditor))]
public TextOutline TextOutline
{
get { return textOutline; }
set
{
if (value == null)
throw new ArgumentNullException("TextOutline");
textOutline = value;
if (!String.IsNullOrEmpty(Style))
Style = "";
}
}
/// <summary>
/// Gets or sets the text color in a simple manner.
/// </summary>
/// <remarks>
/// This property can be used in a report script to change the text color of the object. It is
/// equivalent to: <code>textObject1.TextFill = new SolidFill(color);</code>
/// </remarks>
[Browsable(false)]
public Color TextColor
{
get { return TextFill is SolidFill ? (TextFill as SolidFill).Color : Color.Black; }
set { TextFill = new SolidFill(value); }
}
/// <summary>
/// Gets or sets the string trimming options.
/// </summary>
[DefaultValue(StringTrimming.None)]
[Category("Behavior")]
public StringTrimming Trimming
{
get { return trimming; }
set { trimming = value; }
}
/// <summary>
/// Gets or sets the width ratio of the font.
/// </summary>
/// <remarks>
/// Default value is 1. To make a font wider, set a value grether than 1; to make a font narrower,
/// set a value less than 1.
/// </remarks>
[DefaultValue(1f)]
[Category("Appearance")]
public float FontWidthRatio
{
get { return fontWidthRatio; }
set
{
if (value > 0)
fontWidthRatio = value;
else
fontWidthRatio = 1;
}
}
/// <summary>
/// Gets or sets the height of single text line, in pixels.
/// </summary>
[DefaultValue(0f)]
[Category("Appearance")]
public float LineHeight
{
get { return lineHeight; }
set { lineHeight = value; }
}
/// <summary>
/// Gets or sets the offset of the first TAB symbol.
/// </summary>
[DefaultValue(0f)]
[Category("Appearance")]
//[TypeConverter("FastReport.TypeConverters.UnitsConverter, FastReport")]
public float FirstTabOffset
{
get { return firstTabOffset; }
set { firstTabOffset = value; }
}
/// <summary>
/// Gets or sets the width of TAB symbol, in pixels.
/// </summary>
[DefaultValue(58f)]
[Category("Appearance")]
public float TabWidth
{
get { return tabWidth; }
set { tabWidth = value; }
}
/// <summary>
/// Gets or sets a value that indicates if text should be clipped inside the object's bounds.
/// </summary>
[DefaultValue(true)]
[Category("Behavior")]
public bool Clip
{
get { return clip; }
set { clip = value; }
}
/// <summary>
/// Gets the collection of conditional highlight attributes.
/// </summary>
/// <remarks>
/// Conditional highlight is used to change the visual appearance of the Text object
/// depending on some condition(s). For example, you may highlight negative values displayed by
/// the Text object with red color. To do this, add the highlight condition:
/// <code>
/// TextObject text1;
/// HighlightCondition highlight = new HighlightCondition();
/// highlight.Expression = "Value < 0";
/// highlight.Fill = new SolidFill(Color.Red);
/// highlight.ApplyFill = true;
/// text1.Highlight.Add(highlight);
/// </code>
/// </remarks>
[Category("Data")]
[Editor("FastReport.TypeEditors.HighlightEditor, FastReport", typeof(UITypeEditor))]
public ConditionCollection Highlight
{
get { return highlight; }
}
/// <summary>
/// Gets or sets a value that indicates if the text object should display its contents similar to the printout.
/// </summary>
[DefaultValue(false)]
[Category("Behavior")]
public bool Wysiwyg
{
get { return wysiwyg; }
set { wysiwyg = value; }
}
/// <summary>
/// Forces justify for the last text line.
/// </summary>
[Browsable(false)]
public bool ForceJustify
{
get { return forceJustify; }
set { forceJustify = value; }
}
/// <summary>
/// Allows handling html tags in the text.
/// </summary>
/// <remarks>
/// The following html tags can be used in the object's text: <b>, <i>, <u>,
/// <strike>, <sub>, <sup>, </b>, </i>, </u>,
/// </strike>, </sub>, </sup>,
/// <font color=&...&>, </font>. Font size cannot
/// be changed due to limitations in the rendering engine.
/// </remarks>
[DefaultValue(false)]
[Category("Behavior")]
[Browsable(false)]
[Obsolete("This method is deprecated please use TextRenderer")]
public bool HtmlTags
{
get
{
return HasHtmlTags;
}
set { textRenderType = value ? TextRenderType.HtmlTags : TextRenderType.Default; }
}
/// <summary>
/// Indicates handling html tags in the text.
/// </summary>
/// <remarks>To set the value use the TextRenderer property.</remarks>
[DefaultValue(false)]
[Category("Behavior")]
[Browsable(false)]
public bool HasHtmlTags
{
get
{
switch (textRenderType)
{
case TextRenderType.HtmlTags:
case TextRenderType.HtmlParagraph:
return true;
default:
return false;
}
}
}
/// <summary>
/// The type of text render
/// </summary>
/// /// <remarks>
/// The following html tags can be used in the object's text: <b>, <i>, <u>,
/// <strike>, <sub>, <sup>, </b>, </i>, </u>,
/// </strike>, </sub>, </sup>,
/// <font color=&...&>, </font>. Font size cannot
/// be changed due to limitations in the rendering engine.
/// </remarks>
[DefaultValue(TextRenderType.Default)]
[Category("Behavior")]
public TextRenderType TextRenderType
{
get { return textRenderType; }
set { textRenderType = value; }
}
/// <summary>
/// Gets or sets the paragraph offset, in pixels. For HtmlParagraph use ParagraphFormat.FirstLineIndent.
/// </summary>
[DefaultValue(0f)]
[Category("Appearance")]
[TypeConverter("FastReport.TypeConverters.UnitsConverter, FastReport")]
public float ParagraphOffset
{
get { return paragraphOffset; }
set { paragraphOffset = value; }
}
internal bool IsAdvancedRendererNeeded
{
get { return HorzAlign == HorzAlign.Justify || Wysiwyg || LineHeight != 0 || HasHtmlTags; }
}
internal bool PreserveLastLineSpace { get { return preserveLastLineSpace; } set { preserveLastLineSpace = value; } }
/// <summary>
/// Cache for inline images
/// </summary>
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public InlineImageCache InlineImageCache
{
get
{
if (inlineImageCache == null)
inlineImageCache = new InlineImageCache();
return inlineImageCache;
}
}
#endregion
#region Private Methods
private void DrawUnderlines(FRPaintEventArgs e)
{
if (!Underlines || Angle != 0)
return;
IGraphics g = e.Graphics;
float lineHeight = LineHeight == 0 ? Font.GetHeight() * DrawUtils.ScreenDpiFX : LineHeight;
lineHeight *= e.ScaleY;
float curY = AbsTop * e.ScaleY + lineHeight + 1;
Pen pen = e.Cache.GetPen(Border.Color, Border.Width * e.ScaleY, DashStyle.Solid);
while (curY < AbsBottom * e.ScaleY)
{
g.DrawLine(pen, AbsLeft * e.ScaleX, curY, AbsRight * e.ScaleY, curY);
curY += lineHeight;
}
}
private SizeF CalcSize()
{
Report report = Report;
if (String.IsNullOrEmpty(Text) || report == null)
return new SizeF(0, 0);
Font font = report.GraphicCache.GetFont(Font.FontFamily, Font.Size * 96f / DrawUtils.ScreenDpi, Font.Style);
float width = 0;
if (WordWrap)
{
if (Angle == 90 || Angle == 270)
width = Height - Padding.Vertical;
else
width = Width - Padding.Horizontal;
}
IGraphics g = report.MeasureGraphics;
IGraphicsState state = g.Save();
try
{
if (report.TextQuality != TextQuality.Default)
g.TextRenderingHint = report.GetTextQuality();
if (TextRenderType == TextRenderType.HtmlParagraph)
{
if (width == 0)
width = 100000;
using (HtmlTextRenderer htmlRenderer = GetHtmlTextRenderer(g, new RectangleF(0, 0, width, 100000), 1, 1))
{
float height = htmlRenderer.CalcHeight();
width = htmlRenderer.CalcWidth();
width += Padding.Horizontal + 1;
if (LineHeight == 0)
height += Padding.Vertical + 1;
return new SizeF(width, height);
}
}
#if CROSSPLATFORM && !SKIA
// in FR.Core we use AdvancedTextRenderer only if needed (IsAdvancedRendererNeeded) or if it's not Windows
if (IsAdvancedRendererNeeded || !Config.IsWindows)
#else
if (IsAdvancedRendererNeeded)
#endif
{
if (width == 0)
width = 100000;
AdvancedTextRenderer renderer = new AdvancedTextRenderer(Text, g, font, Brushes.Black, Pens.Black,
new RectangleF(0, 0, width, 100000), GetStringFormat(report.GraphicCache, 0),
HorzAlign, VertAlign, LineHeight, Angle, FontWidthRatio, false, Wysiwyg, HasHtmlTags, false, 96f / DrawUtils.ScreenDpi,
96f / DrawUtils.ScreenDpi, InlineImageCache);
float height = renderer.CalcHeight();
width = renderer.CalcWidth();
width += Padding.Horizontal + 1;
if (LineHeight == 0)
height += Padding.Vertical + 1;
return new SizeF(width, height);
}
else
{
if (FontWidthRatio != 1)
width /= FontWidthRatio;
SizeF size = g.MeasureString(Text, font, new SizeF(width, 100000));
size.Width += Padding.Horizontal + 1;
size.Height += Padding.Vertical + 1;
return size;
}
}
finally
{
g.Restore(state);
}
}
private float InternalCalcWidth()
{
bool saveWordWrap = WordWrap;
WordWrap = false;
float result = 0;
try
{
SizeF size = CalcSize();
result = size.Width;
}
finally
{
WordWrap = saveWordWrap;
}
return result;
}
private float InternalCalcHeight()
{
return CalcSize().Height;
}
private string BreakTextHtml(out bool endOnEnter)
{
endOnEnter = false;
ForceJustify = false;
if (String.IsNullOrEmpty(Text))
return "";
string result = null;
Report report = Report;
if (report == null)
return "";
StringFormat format = GetStringFormat(report.GraphicCache, StringFormatFlags.LineLimit);
RectangleF textRect = new RectangleF(0, 0, Width - Padding.Horizontal, Height - Padding.Vertical);
int charactersFitted;
IGraphics g = report.MeasureGraphics;
IGraphicsState state = g.Save();
if (report.TextQuality != TextQuality.Default)
g.TextRenderingHint = report.GetTextQuality();
try
{
using (HtmlTextRenderer htmlRenderer = GetHtmlTextRenderer(g, 1, 1, textRect, format))
{
htmlRenderer.CalcHeight(out charactersFitted);
if (charactersFitted == 0)
return null;
Text = HtmlTextRenderer.BreakHtml(Text, charactersFitted, out result, out endOnEnter);
if (HorzAlign == HorzAlign.Justify && !endOnEnter && result != "")
{
if (Text.EndsWith(" "))
Text = Text.TrimEnd(' ');
ForceJustify = true;
}
}
}
finally
{
g.Restore(state);
}
return result;
}
private string BreakText()
{
ForceJustify = false;
if (String.IsNullOrEmpty(Text))
return "";
string result = null;
Report report = Report;
if (report == null)
return "";
Font font = report.GraphicCache.GetFont(Font.FontFamily, Font.Size * 96f / DrawUtils.ScreenDpi, Font.Style);
StringFormat format = GetStringFormat(report.GraphicCache, StringFormatFlags.LineLimit);
RectangleF textRect = new RectangleF(0, 0, Width - Padding.Horizontal, Height - Padding.Vertical);
if (textRect.Height < 0)
return null;
int charactersFitted;
int linesFilled;
IGraphics g = report.MeasureGraphics;
IGraphicsState state = g.Save();
try
{
if (report.TextQuality != TextQuality.Default)
g.TextRenderingHint = report.GetTextQuality();
AdvancedTextRenderer.StyleDescriptor htmlStyle = null;
if (IsAdvancedRendererNeeded)
{
AdvancedTextRenderer renderer = new AdvancedTextRenderer(Text, g, font, Brushes.Black, Pens.Black,
textRect, format, HorzAlign, VertAlign, LineHeight, Angle, FontWidthRatio, false, Wysiwyg, HasHtmlTags, false, 96f / DrawUtils.ScreenDpi,
96f / DrawUtils.ScreenDpi, InlineImageCache);
renderer.CalcHeight(out charactersFitted, out htmlStyle);
if (charactersFitted == 0)
linesFilled = 0;
else
linesFilled = 2;
}
else
{
g.MeasureString(Text, font, textRect.Size, format, out charactersFitted, out linesFilled);
}
if (linesFilled == 0)
return null;
if (linesFilled == 1)
{
// check if there is enough space for one line
float lineHeight = g.MeasureString("Wg", font).Height;
if (textRect.Height < lineHeight)
return null;
}
if (charactersFitted < Text.Length)
result = Text.Substring(charactersFitted);
else
result = "";
Text = Text.Substring(0, charactersFitted);
if (HorzAlign == HorzAlign.Justify && !Text.EndsWith("\n") && result != "")
{
if (Text.EndsWith(" "))
Text = Text.Substring(0, Text.Length - 1);
ForceJustify = true;
}
if (HasHtmlTags && htmlStyle != null && result != "")
result = htmlStyle.ToString() + result;
}
finally
{
g.Restore(state);
}
return result;
}
private void ProcessAutoShrink()
{
if (TextRenderType == TextRenderType.HtmlParagraph)
return;
if (String.IsNullOrEmpty(Text))
return;
if (AutoShrink == AutoShrinkMode.FontSize)
{
while (CalcWidth() > Width - 1 && Font.Size > AutoShrinkMinSize && Font.Size>1)
{
Font = new Font(Font.FontFamily, Font.Size - 1, Font.Style);
}
}
else if (AutoShrink == AutoShrinkMode.FontWidth)
{
FontWidthRatio = 1;
float ratio = Converter.DecreasePrecision((Width - 1) / CalcWidth(), 2) - 0.01f;
if (ratio < 1)
FontWidthRatio = Math.Max(ratio, AutoShrinkMinSize);
}
}
private string MakeParagraphOffset(string text)
{
// fixed issue 2823
FirstTabOffset = ParagraphOffset;