Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 6570b60

Browse files
Change text drawing to FormattedText and DrawingVisual
1 parent b3946f3 commit 6570b60

4 files changed

Lines changed: 65 additions & 26 deletions

File tree

src/AddIns/Analysis/CodeQuality/Reporting/OverviewReport.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ void HandleSectionEvents(object sender, SectionEventArgs e)
8181
if (sectionName == ReportSectionNames.ReportHeader) {
8282

8383
var param1 = (BaseTextItem)e.Section.Items.FirstOrDefault(n => n.Name == "Param1");
84-
FileInfo fi =new FileInfo(FileNames[0]);
84+
// FileInfo fi =new FileInfo(FileNames[0]);
8585
// var s = fi..Directory + fi.Name;
86-
param1.Text = fi.Name;
86+
param1.Text = FileNames[0];
8787
var param2 = (BaseTextItem)e.Section.Items.FirstOrDefault(n => n.Name == "Param2");
8888
param2.Text = list.Count.ToString();
8989
}

src/AddIns/Analysis/CodeQuality/Reporting/Overviewreport.srd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,12 @@
116116
</BaseTextItem>
117117
<BaseTextItem>
118118
<Location>139, 91</Location>
119-
<Size>438, 20</Size>
119+
<Size>377, 20</Size>
120120
<BackColor>White</BackColor>
121121
<Font>Segoe UI, 9pt</Font>
122122
<StringTrimming>None</StringTrimming>
123123
<ContentAlignment>TopLeft</ContentAlignment>
124-
<CanGrow>False</CanGrow>
124+
<CanGrow>True</CanGrow>
125125
<CanShrink>False</CanShrink>
126126
<RTL>No</RTL>
127127
<Text>Parameters!param1</Text>

src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Wpf/Visitor/FixedDocumentCreator.cs

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public static Canvas CreateContainer(ExportContainer container) {
5959
return canvas;
6060
}
6161

62-
62+
/*
6363
public static TextBlock CreateTextBlock(ExportText exportText,bool setBackcolor){
6464
6565
var textBlock = new TextBlock();
@@ -79,8 +79,9 @@ public static TextBlock CreateTextBlock(ExportText exportText,bool setBackcolor)
7979
MeasureTextBlock (textBlock,exportText);
8080
return textBlock;
8181
}
82+
*/
8283

83-
84+
/*
8485
static void CheckForNewLine(TextBlock textBlock,ExportText exportText) {
8586
string [] inlines = exportText.Text.Split(Environment.NewLine.ToCharArray());
8687
for (int i = 0; i < inlines.Length; i++) {
@@ -101,22 +102,15 @@ static void MeasureTextBlock(TextBlock textBlock,ExportText exportText)
101102
textBlock.Height = wpfSize.Height;
102103
}
103104
105+
*/
104106

107+
/*
105108
static Size MeasureTextInWpf(ExportText exportText){
106109
107110
if (exportText.CanGrow) {
108-
var formattedText = new FormattedText(exportText.Text,
109-
CultureInfo.CurrentCulture,
110-
FlowDirection.LeftToRight,
111-
new Typeface(exportText.Font.FontFamily.Name),
112-
exportText.Font.Size,
113-
new SolidColorBrush(exportText.ForeColor.ToWpf()),
114-
null,
115-
TextFormattingMode.Display);
111+
var formattedText = NewMethod(exportText);
116112
117113
formattedText.MaxTextWidth = exportText.DesiredSize.Width * 96.0 / 72.0;
118-
// ft.MaxTextHeight = exportText.DesiredSize.Height + 5 * 96.0 / 72.0;
119-
// ft.MaxTextHeight = Double.MaxValue ;
120114
121115
formattedText.SetFontSize(Math.Floor(exportText.Font.Size * 96.0 / 72.0));
122116
@@ -127,6 +121,34 @@ static Size MeasureTextInWpf(ExportText exportText){
127121
}
128122
return new Size(exportText.Size.Width,exportText.Size.Height);
129123
}
124+
125+
*/
126+
127+
128+
public static FormattedText CreateFormattedText(ExportText exportText)
129+
{
130+
var formattedText = new FormattedText(exportText.Text,
131+
CultureInfo.CurrentCulture,
132+
FlowDirection.LeftToRight,
133+
new Typeface(exportText.Font.FontFamily.Name),
134+
exportText.Font.Size,
135+
new SolidColorBrush(exportText.ForeColor.ToWpf()), null, TextFormattingMode.Display);
136+
137+
formattedText.MaxTextWidth = exportText.DesiredSize.Width * 96.0 / 72.0;
138+
formattedText.SetFontSize(Math.Floor(exportText.Font.Size * 96.0 / 72.0));
139+
140+
var td = new TextDecorationCollection() ;
141+
CheckUnderline(td,exportText);
142+
formattedText.SetTextDecorations(td);
143+
return formattedText;
144+
}
145+
146+
static void CheckUnderline(TextDecorationCollection td, ExportText exportText)
147+
{
148+
if (exportText.Font.Underline) {
149+
td.Add(new TextDecoration{Location = TextDecorationLocation.Underline});
150+
}
151+
}
130152

131153

132154
static Canvas CreateCanvas(ExportContainer container){
@@ -158,7 +180,7 @@ static void SetPosition (UIElement element,IExportColumn exportColumn) {
158180
FixedPage.SetTop(element,exportColumn.Location.Y);
159181
}
160182

161-
183+
/*
162184
static void SetFont(TextBlock textBlock,IExportText exportText){
163185
textBlock.FontFamily = new FontFamily(exportText.Font.FontFamily.Name);
164186
@@ -180,7 +202,7 @@ static void SetFont(TextBlock textBlock,IExportText exportText){
180202
CreateStrikeout(textBlock,exportText);
181203
}
182204
}
183-
205+
*/
184206

185207
static void SetContentAlignment(TextBlock textBlock,ExportText exportText)
186208
{
@@ -244,7 +266,7 @@ static void CreateStrikeout (TextBlock textBlock,IExportText exportColumn ){
244266
textBlock.TextDecorations.Add(strikeOut);
245267
}
246268

247-
269+
/*
248270
static void CreateUnderline(TextBlock textBlock,IExportText exportColumn){
249271
if (exportColumn == null)
250272
throw new ArgumentNullException("exportColumn");
@@ -256,14 +278,15 @@ static void CreateUnderline(TextBlock textBlock,IExportText exportColumn){
256278
underLine.PenThicknessUnit = TextDecorationUnit.FontRecommended;
257279
textBlock.TextDecorations.Add(underLine);
258280
}
259-
281+
*/
260282

261283
public static Pen CreateWpfPen(IReportObject exportColumn){
262284
if (exportColumn == null)
263285
throw new ArgumentNullException("exportColumn");
264286
var pen = new Pen();
265287
pen.Brush = ConvertBrush(exportColumn.ForeColor);
266288
pen.Thickness = 1;
289+
267290
var exportGraphics = exportColumn as IExportGraphics;
268291
if (exportGraphics != null) {
269292
pen.Thickness = exportGraphics.Thickness;

src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Wpf/Visitor/WpfVisitor.cs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,28 @@ void PerformList(Canvas myCanvas, System.Collections.Generic.List<IExportColumn>
7979

8080

8181
public override void Visit(ExportText exportColumn){
82+
/*
8283
var textBlock = FixedDocumentCreator.CreateTextBlock((ExportText)exportColumn,ShouldSetBackcolor(exportColumn));
8384
CanvasHelper.SetPosition(textBlock,new Point(exportColumn.Location.X,exportColumn.Location.Y));
8485
UIElement = textBlock;
86+
*/
87+
88+
var ft = FixedDocumentCreator.CreateFormattedText((ExportText)exportColumn);
89+
var visual = new DrawingVisual();
90+
var location = new Point(exportColumn.Location.X,exportColumn.Location.Y);
91+
using (var dc = visual.RenderOpen()){
92+
if (ShouldSetBackcolor(exportColumn)) {
93+
dc.DrawRectangle(FixedDocumentCreator.ConvertBrush(exportColumn.BackColor),
94+
null,
95+
new Rect(location,new Size(exportColumn.Size.Width,exportColumn.Size.Height)));
96+
}
97+
dc.DrawText(ft,location);
98+
}
99+
var dragingElement = new DrawingElement(visual);
100+
UIElement = dragingElement;
101+
85102
}
86-
87-
103+
88104

89105
public override void Visit(ExportLine exportGraphics)
90106
{
@@ -111,8 +127,8 @@ public override void Visit(ExportRectangle exportRectangle)
111127
new Rect(exportRectangle.Location.X,exportRectangle.Location.Y,
112128
exportRectangle.Size.Width,exportRectangle.Size.Height));
113129
}
114-
DrawingElement m = new DrawingElement(visual);
115-
UIElement = m;
130+
var dragingElement = new DrawingElement(visual);
131+
UIElement = dragingElement;
116132
}
117133

118134
public override void Visit(ExportCircle exportCircle)
@@ -132,8 +148,8 @@ public override void Visit(ExportCircle exportCircle)
132148

133149

134150
}
135-
DrawingElement m = new DrawingElement(visual);
136-
UIElement = m;
151+
var dragingElement = new DrawingElement(visual);
152+
UIElement = dragingElement;
137153
}
138154

139155
static Point CalcRad(System.Drawing.Size size) {

0 commit comments

Comments
 (0)