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

Commit 193eb24

Browse files
ContendAlignment in WpfView
1 parent 98a4e81 commit 193eb24

6 files changed

Lines changed: 56 additions & 35 deletions

File tree

src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/ReportingFactory.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public IReportCreator ReportCreator (ReportModel reportModel) {
6060
}
6161

6262

63-
internal ReportModel LoadReportModel (Stream stream)
63+
internal IReportModel LoadReportModel (Stream stream)
6464
{
6565
var doc = new XmlDocument();
6666
doc.Load(stream);
@@ -69,7 +69,7 @@ internal ReportModel LoadReportModel (Stream stream)
6969
}
7070

7171

72-
static ReportModel LoadModel(XmlDocument doc)
72+
static IReportModel LoadModel(XmlDocument doc)
7373
{
7474
var loader = new ModelLoader();
7575
object root = loader.Load(doc.DocumentElement);
@@ -78,6 +78,6 @@ static ReportModel LoadModel(XmlDocument doc)
7878
}
7979

8080

81-
public ReportModel ReportModel {get;private set;}
81+
public IReportModel ReportModel {get;private set;}
8282
}
8383
}

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

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -151,51 +151,58 @@ static void SetPosition (UIElement element,IExportColumn exportColumn) {
151151
FixedPage.SetTop(element,exportColumn.Location.Y);
152152
}
153153

154-
155-
static void SetContentAlignment(TextBlock textBlock,ExportText exportText)
156-
{
157-
//Vertical alignment not working
158-
154+
public static Point CalculateAlignmentOffset (FormattedText formattedText, ExportText exportText) {
155+
var offset = new Point(0,0);
156+
double y = 0;
157+
double x = 0;
158+
var textLenDif = exportText.Size.Width - formattedText.Width;
159+
var textHeightDif = exportText.Size.Height - formattedText.Height;
160+
159161
switch (exportText.ContentAlignment) {
162+
// Top
160163
case System.Drawing.ContentAlignment.TopLeft:
161-
textBlock.VerticalAlignment = VerticalAlignment.Top;
162-
textBlock.TextAlignment = TextAlignment.Left;
163164
break;
165+
164166
case System.Drawing.ContentAlignment.TopCenter:
165-
textBlock.VerticalAlignment = VerticalAlignment.Top;
166-
textBlock.TextAlignment = TextAlignment.Center;
167+
x = textLenDif / 2;
167168
break;
169+
168170
case System.Drawing.ContentAlignment.TopRight:
169-
textBlock.VerticalAlignment = VerticalAlignment.Top;
170-
textBlock.TextAlignment = TextAlignment.Right;
171+
x = textLenDif;
171172
break;
173+
172174
// Middle
173175
case System.Drawing.ContentAlignment.MiddleLeft:
174-
textBlock.VerticalAlignment = VerticalAlignment.Center;
175-
textBlock.TextAlignment = TextAlignment.Left;
176+
y = textHeightDif / 2;
176177
break;
178+
177179
case System.Drawing.ContentAlignment.MiddleCenter:
178-
textBlock.VerticalAlignment = VerticalAlignment.Center;
179-
textBlock.TextAlignment = TextAlignment.Center;
180+
y = textHeightDif / 2;
181+
x = textLenDif / 2;
180182
break;
183+
181184
case System.Drawing.ContentAlignment.MiddleRight:
182-
textBlock.VerticalAlignment = VerticalAlignment.Center;
183-
textBlock.TextAlignment = TextAlignment.Right;
185+
x = textLenDif;;
186+
y = textHeightDif / 2;
184187
break;
188+
185189
//Bottom
186190
case System.Drawing.ContentAlignment.BottomLeft:
187-
textBlock.VerticalAlignment = VerticalAlignment.Bottom;
188-
textBlock.TextAlignment = TextAlignment.Left;
191+
x = 0;
192+
y = textHeightDif;
189193
break;
194+
190195
case System.Drawing.ContentAlignment.BottomCenter:
191-
textBlock.VerticalAlignment = VerticalAlignment.Bottom;
192-
textBlock.TextAlignment = TextAlignment.Center;
196+
x = textLenDif / 2;
197+
y = textHeightDif;
193198
break;
199+
194200
case System.Drawing.ContentAlignment.BottomRight:
195-
textBlock.VerticalAlignment = VerticalAlignment.Bottom;
196-
textBlock.TextAlignment = TextAlignment.Right;
201+
x = textLenDif;
202+
y = textHeightDif;
197203
break;
198204
}
205+
return new Point(x,y);
199206
}
200207

201208

@@ -217,13 +224,13 @@ public static Pen CreateWpfPen(IReportObject exportColumn){
217224
}
218225

219226

220-
public static Brush ConvertBrush(System.Drawing.Color color){
227+
public static Brush ConvertBrush(System.Drawing.Color color)
228+
{
221229
var b = new BrushConverter();
222-
if (b.IsValid(color.Name)){
230+
if (b.IsValid(color.Name)) {
223231
return b.ConvertFromString(color.Name) as SolidColorBrush;
224-
} else{
225-
return b.ConvertFromString("Black") as SolidColorBrush;
226232
}
233+
return b.ConvertFromString("Black") as SolidColorBrush;
227234
}
228235

229236

@@ -270,6 +277,7 @@ public static PenLineCap LineCap (System.Drawing.Drawing2D.LineCap lineCap) {
270277
return penLineCap;
271278
}
272279

280+
273281
public static DashStyle DashStyle (IExportGraphics exportGraphics) {
274282
var dashStyle = DashStyles.Solid;
275283

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,27 @@ Canvas RenderGraphicsContainer(IExportColumn column)
119119

120120
public override void Visit(ExportText exportColumn){
121121

122-
var ft = FixedDocumentCreator.CreateFormattedText((ExportText)exportColumn);
122+
var formattedText = FixedDocumentCreator.CreateFormattedText((ExportText)exportColumn);
123123
var visual = new DrawingVisual();
124+
124125
var location = new Point(exportColumn.Location.X,exportColumn.Location.Y);
126+
125127
using (var dc = visual.RenderOpen()){
126128
if (ShouldSetBackcolor(exportColumn)) {
127129
dc.DrawRectangle(FixedDocumentCreator.ConvertBrush(exportColumn.BackColor),
128130
null,
129131
new Rect(location,new Size(exportColumn.Size.Width,exportColumn.Size.Height)));
130132
}
131-
dc.DrawText(ft,location);
133+
134+
// http://stackoverflow.com/questions/9264398/how-to-calculate-wpf-textblock-width-for-its-known-font-size-and-characters
135+
136+
// if (exportColumn.ContentAlignment == System.Drawing.ContentAlignment.MiddleCenter) {
137+
// location = new Point(location.X + (exportColumn.Size.Width - formattedText.Width) /2,location.Y + (exportColumn.Size.Height - formattedText.Height) / 2);
138+
// }
139+
var offset = FixedDocumentCreator.CalculateAlignmentOffset(formattedText,exportColumn);
140+
var newLoc = new Point(location.X + offset.X,location.Y + offset.Y);
141+
// dc.DrawText(formattedText,location);
142+
dc.DrawText(formattedText,newLoc);
132143
}
133144
var dragingElement = new DrawingElement(visual);
134145
UIElement = dragingElement;

src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Model/Report_FromListFixture.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using System.Drawing;
2121
using System.Reflection;
2222

23+
using ICSharpCode.Reporting.Interfaces;
2324
using ICSharpCode.Reporting.Items;
2425
using NUnit.Framework;
2526

@@ -28,7 +29,7 @@ namespace ICSharpCode.Reporting.Test.Model
2829
[TestFixture]
2930
public class Report_FromListFixture
3031
{
31-
private ReportModel model;
32+
IReportModel model;
3233

3334
[Test]
3435
public void ReportHeaderContainsOneItem () {

src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Model/Report_TwoItemsFixture.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using System.Drawing;
2121
using System.Reflection;
2222

23+
using ICSharpCode.Reporting.Interfaces;
2324
using ICSharpCode.Reporting.Items;
2425
using NUnit.Framework;
2526

@@ -29,7 +30,7 @@ namespace ICSharpCode.Reporting.Test.Model
2930
public class ReportTwoItemsFixture
3031
{
3132

32-
private ReportModel model;
33+
IReportModel model;
3334

3435
[Test]
3536
public void LoadModelWithItems()

src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/PageBuilder/SectionConverterFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public void Init()
9595
container.Items.Add(item1);
9696
container.Items.Add(item2);
9797

98-
Bitmap bitmap = new Bitmap(700,1000);
98+
var bitmap = new Bitmap(700,1000);
9999
graphics = Graphics.FromImage(bitmap);
100100
}
101101
}

0 commit comments

Comments
 (0)