Browse Source

ContendAlignment in WpfView

pull/725/head
Peter Forstmeier 11 years ago
parent
commit
193eb24fad
  1. 6
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/ReportingFactory.cs
  2. 62
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Wpf/Visitor/FixedDocumentCreator.cs
  3. 15
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Wpf/Visitor/WpfVisitor.cs
  4. 3
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Model/Report_FromListFixture.cs
  5. 3
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Model/Report_TwoItemsFixture.cs
  6. 2
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/PageBuilder/SectionConverterFixture.cs

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

@ -60,7 +60,7 @@ namespace ICSharpCode.Reporting @@ -60,7 +60,7 @@ namespace ICSharpCode.Reporting
}
internal ReportModel LoadReportModel (Stream stream)
internal IReportModel LoadReportModel (Stream stream)
{
var doc = new XmlDocument();
doc.Load(stream);
@ -69,7 +69,7 @@ namespace ICSharpCode.Reporting @@ -69,7 +69,7 @@ namespace ICSharpCode.Reporting
}
static ReportModel LoadModel(XmlDocument doc)
static IReportModel LoadModel(XmlDocument doc)
{
var loader = new ModelLoader();
object root = loader.Load(doc.DocumentElement);
@ -78,6 +78,6 @@ namespace ICSharpCode.Reporting @@ -78,6 +78,6 @@ namespace ICSharpCode.Reporting
}
public ReportModel ReportModel {get;private set;}
public IReportModel ReportModel {get;private set;}
}
}

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

@ -151,51 +151,58 @@ namespace ICSharpCode.Reporting.WpfReportViewer.Visitor @@ -151,51 +151,58 @@ namespace ICSharpCode.Reporting.WpfReportViewer.Visitor
FixedPage.SetTop(element,exportColumn.Location.Y);
}
static void SetContentAlignment(TextBlock textBlock,ExportText exportText)
{
//Vertical alignment not working
public static Point CalculateAlignmentOffset (FormattedText formattedText, ExportText exportText) {
var offset = new Point(0,0);
double y = 0;
double x = 0;
var textLenDif = exportText.Size.Width - formattedText.Width;
var textHeightDif = exportText.Size.Height - formattedText.Height;
switch (exportText.ContentAlignment) {
// Top
case System.Drawing.ContentAlignment.TopLeft:
textBlock.VerticalAlignment = VerticalAlignment.Top;
textBlock.TextAlignment = TextAlignment.Left;
break;
case System.Drawing.ContentAlignment.TopCenter:
textBlock.VerticalAlignment = VerticalAlignment.Top;
textBlock.TextAlignment = TextAlignment.Center;
x = textLenDif / 2;
break;
case System.Drawing.ContentAlignment.TopRight:
textBlock.VerticalAlignment = VerticalAlignment.Top;
textBlock.TextAlignment = TextAlignment.Right;
x = textLenDif;
break;
// Middle
case System.Drawing.ContentAlignment.MiddleLeft:
textBlock.VerticalAlignment = VerticalAlignment.Center;
textBlock.TextAlignment = TextAlignment.Left;
y = textHeightDif / 2;
break;
case System.Drawing.ContentAlignment.MiddleCenter:
textBlock.VerticalAlignment = VerticalAlignment.Center;
textBlock.TextAlignment = TextAlignment.Center;
y = textHeightDif / 2;
x = textLenDif / 2;
break;
case System.Drawing.ContentAlignment.MiddleRight:
textBlock.VerticalAlignment = VerticalAlignment.Center;
textBlock.TextAlignment = TextAlignment.Right;
x = textLenDif;;
y = textHeightDif / 2;
break;
//Bottom
case System.Drawing.ContentAlignment.BottomLeft:
textBlock.VerticalAlignment = VerticalAlignment.Bottom;
textBlock.TextAlignment = TextAlignment.Left;
x = 0;
y = textHeightDif;
break;
case System.Drawing.ContentAlignment.BottomCenter:
textBlock.VerticalAlignment = VerticalAlignment.Bottom;
textBlock.TextAlignment = TextAlignment.Center;
x = textLenDif / 2;
y = textHeightDif;
break;
case System.Drawing.ContentAlignment.BottomRight:
textBlock.VerticalAlignment = VerticalAlignment.Bottom;
textBlock.TextAlignment = TextAlignment.Right;
x = textLenDif;
y = textHeightDif;
break;
}
return new Point(x,y);
}
@ -217,13 +224,13 @@ namespace ICSharpCode.Reporting.WpfReportViewer.Visitor @@ -217,13 +224,13 @@ namespace ICSharpCode.Reporting.WpfReportViewer.Visitor
}
public static Brush ConvertBrush(System.Drawing.Color color){
public static Brush ConvertBrush(System.Drawing.Color color)
{
var b = new BrushConverter();
if (b.IsValid(color.Name)){
if (b.IsValid(color.Name)) {
return b.ConvertFromString(color.Name) as SolidColorBrush;
} else{
return b.ConvertFromString("Black") as SolidColorBrush;
}
return b.ConvertFromString("Black") as SolidColorBrush;
}
@ -270,6 +277,7 @@ namespace ICSharpCode.Reporting.WpfReportViewer.Visitor @@ -270,6 +277,7 @@ namespace ICSharpCode.Reporting.WpfReportViewer.Visitor
return penLineCap;
}
public static DashStyle DashStyle (IExportGraphics exportGraphics) {
var dashStyle = DashStyles.Solid;

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

@ -119,16 +119,27 @@ namespace ICSharpCode.Reporting.WpfReportViewer.Visitor @@ -119,16 +119,27 @@ namespace ICSharpCode.Reporting.WpfReportViewer.Visitor
public override void Visit(ExportText exportColumn){
var ft = FixedDocumentCreator.CreateFormattedText((ExportText)exportColumn);
var formattedText = FixedDocumentCreator.CreateFormattedText((ExportText)exportColumn);
var visual = new DrawingVisual();
var location = new Point(exportColumn.Location.X,exportColumn.Location.Y);
using (var dc = visual.RenderOpen()){
if (ShouldSetBackcolor(exportColumn)) {
dc.DrawRectangle(FixedDocumentCreator.ConvertBrush(exportColumn.BackColor),
null,
new Rect(location,new Size(exportColumn.Size.Width,exportColumn.Size.Height)));
}
dc.DrawText(ft,location);
// http://stackoverflow.com/questions/9264398/how-to-calculate-wpf-textblock-width-for-its-known-font-size-and-characters
// if (exportColumn.ContentAlignment == System.Drawing.ContentAlignment.MiddleCenter) {
// location = new Point(location.X + (exportColumn.Size.Width - formattedText.Width) /2,location.Y + (exportColumn.Size.Height - formattedText.Height) / 2);
// }
var offset = FixedDocumentCreator.CalculateAlignmentOffset(formattedText,exportColumn);
var newLoc = new Point(location.X + offset.X,location.Y + offset.Y);
// dc.DrawText(formattedText,location);
dc.DrawText(formattedText,newLoc);
}
var dragingElement = new DrawingElement(visual);
UIElement = dragingElement;

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

@ -20,6 +20,7 @@ using System; @@ -20,6 +20,7 @@ using System;
using System.Drawing;
using System.Reflection;
using ICSharpCode.Reporting.Interfaces;
using ICSharpCode.Reporting.Items;
using NUnit.Framework;
@ -28,7 +29,7 @@ namespace ICSharpCode.Reporting.Test.Model @@ -28,7 +29,7 @@ namespace ICSharpCode.Reporting.Test.Model
[TestFixture]
public class Report_FromListFixture
{
private ReportModel model;
IReportModel model;
[Test]
public void ReportHeaderContainsOneItem () {

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

@ -20,6 +20,7 @@ using System; @@ -20,6 +20,7 @@ using System;
using System.Drawing;
using System.Reflection;
using ICSharpCode.Reporting.Interfaces;
using ICSharpCode.Reporting.Items;
using NUnit.Framework;
@ -29,7 +30,7 @@ namespace ICSharpCode.Reporting.Test.Model @@ -29,7 +30,7 @@ namespace ICSharpCode.Reporting.Test.Model
public class ReportTwoItemsFixture
{
private ReportModel model;
IReportModel model;
[Test]
public void LoadModelWithItems()

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

@ -95,7 +95,7 @@ namespace ICSharpCode.Reporting.Test.PageBuilder @@ -95,7 +95,7 @@ namespace ICSharpCode.Reporting.Test.PageBuilder
container.Items.Add(item1);
container.Items.Add(item2);
Bitmap bitmap = new Bitmap(700,1000);
var bitmap = new Bitmap(700,1000);
graphics = Graphics.FromImage(bitmap);
}
}

Loading…
Cancel
Save