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
} }
internal ReportModel LoadReportModel (Stream stream) internal IReportModel LoadReportModel (Stream stream)
{ {
var doc = new XmlDocument(); var doc = new XmlDocument();
doc.Load(stream); doc.Load(stream);
@ -69,7 +69,7 @@ namespace ICSharpCode.Reporting
} }
static ReportModel LoadModel(XmlDocument doc) static IReportModel LoadModel(XmlDocument doc)
{ {
var loader = new ModelLoader(); var loader = new ModelLoader();
object root = loader.Load(doc.DocumentElement); object root = loader.Load(doc.DocumentElement);
@ -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
FixedPage.SetTop(element,exportColumn.Location.Y); FixedPage.SetTop(element,exportColumn.Location.Y);
} }
public static Point CalculateAlignmentOffset (FormattedText formattedText, ExportText exportText) {
static void SetContentAlignment(TextBlock textBlock,ExportText exportText) var offset = new Point(0,0);
{ double y = 0;
//Vertical alignment not working double x = 0;
var textLenDif = exportText.Size.Width - formattedText.Width;
var textHeightDif = exportText.Size.Height - formattedText.Height;
switch (exportText.ContentAlignment) { switch (exportText.ContentAlignment) {
// Top
case System.Drawing.ContentAlignment.TopLeft: case System.Drawing.ContentAlignment.TopLeft:
textBlock.VerticalAlignment = VerticalAlignment.Top;
textBlock.TextAlignment = TextAlignment.Left;
break; break;
case System.Drawing.ContentAlignment.TopCenter: case System.Drawing.ContentAlignment.TopCenter:
textBlock.VerticalAlignment = VerticalAlignment.Top; x = textLenDif / 2;
textBlock.TextAlignment = TextAlignment.Center;
break; break;
case System.Drawing.ContentAlignment.TopRight: case System.Drawing.ContentAlignment.TopRight:
textBlock.VerticalAlignment = VerticalAlignment.Top; x = textLenDif;
textBlock.TextAlignment = TextAlignment.Right;
break; break;
// Middle // Middle
case System.Drawing.ContentAlignment.MiddleLeft: case System.Drawing.ContentAlignment.MiddleLeft:
textBlock.VerticalAlignment = VerticalAlignment.Center; y = textHeightDif / 2;
textBlock.TextAlignment = TextAlignment.Left;
break; break;
case System.Drawing.ContentAlignment.MiddleCenter: case System.Drawing.ContentAlignment.MiddleCenter:
textBlock.VerticalAlignment = VerticalAlignment.Center; y = textHeightDif / 2;
textBlock.TextAlignment = TextAlignment.Center; x = textLenDif / 2;
break; break;
case System.Drawing.ContentAlignment.MiddleRight: case System.Drawing.ContentAlignment.MiddleRight:
textBlock.VerticalAlignment = VerticalAlignment.Center; x = textLenDif;;
textBlock.TextAlignment = TextAlignment.Right; y = textHeightDif / 2;
break; break;
//Bottom //Bottom
case System.Drawing.ContentAlignment.BottomLeft: case System.Drawing.ContentAlignment.BottomLeft:
textBlock.VerticalAlignment = VerticalAlignment.Bottom; x = 0;
textBlock.TextAlignment = TextAlignment.Left; y = textHeightDif;
break; break;
case System.Drawing.ContentAlignment.BottomCenter: case System.Drawing.ContentAlignment.BottomCenter:
textBlock.VerticalAlignment = VerticalAlignment.Bottom; x = textLenDif / 2;
textBlock.TextAlignment = TextAlignment.Center; y = textHeightDif;
break; break;
case System.Drawing.ContentAlignment.BottomRight: case System.Drawing.ContentAlignment.BottomRight:
textBlock.VerticalAlignment = VerticalAlignment.Bottom; x = textLenDif;
textBlock.TextAlignment = TextAlignment.Right; y = textHeightDif;
break; break;
} }
return new Point(x,y);
} }
@ -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(); var b = new BrushConverter();
if (b.IsValid(color.Name)){ if (b.IsValid(color.Name)) {
return b.ConvertFromString(color.Name) as SolidColorBrush; 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
return penLineCap; return penLineCap;
} }
public static DashStyle DashStyle (IExportGraphics exportGraphics) { public static DashStyle DashStyle (IExportGraphics exportGraphics) {
var dashStyle = DashStyles.Solid; 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
public override void Visit(ExportText exportColumn){ public override void Visit(ExportText exportColumn){
var ft = FixedDocumentCreator.CreateFormattedText((ExportText)exportColumn); var formattedText = FixedDocumentCreator.CreateFormattedText((ExportText)exportColumn);
var visual = new DrawingVisual(); var visual = new DrawingVisual();
var location = new Point(exportColumn.Location.X,exportColumn.Location.Y); var location = new Point(exportColumn.Location.X,exportColumn.Location.Y);
using (var dc = visual.RenderOpen()){ using (var dc = visual.RenderOpen()){
if (ShouldSetBackcolor(exportColumn)) { if (ShouldSetBackcolor(exportColumn)) {
dc.DrawRectangle(FixedDocumentCreator.ConvertBrush(exportColumn.BackColor), dc.DrawRectangle(FixedDocumentCreator.ConvertBrush(exportColumn.BackColor),
null, null,
new Rect(location,new Size(exportColumn.Size.Width,exportColumn.Size.Height))); 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); var dragingElement = new DrawingElement(visual);
UIElement = dragingElement; UIElement = dragingElement;

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

@ -20,6 +20,7 @@ using System;
using System.Drawing; using System.Drawing;
using System.Reflection; using System.Reflection;
using ICSharpCode.Reporting.Interfaces;
using ICSharpCode.Reporting.Items; using ICSharpCode.Reporting.Items;
using NUnit.Framework; using NUnit.Framework;
@ -28,7 +29,7 @@ namespace ICSharpCode.Reporting.Test.Model
[TestFixture] [TestFixture]
public class Report_FromListFixture public class Report_FromListFixture
{ {
private ReportModel model; IReportModel model;
[Test] [Test]
public void ReportHeaderContainsOneItem () { 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;
using System.Drawing; using System.Drawing;
using System.Reflection; using System.Reflection;
using ICSharpCode.Reporting.Interfaces;
using ICSharpCode.Reporting.Items; using ICSharpCode.Reporting.Items;
using NUnit.Framework; using NUnit.Framework;
@ -29,7 +30,7 @@ namespace ICSharpCode.Reporting.Test.Model
public class ReportTwoItemsFixture public class ReportTwoItemsFixture
{ {
private ReportModel model; IReportModel model;
[Test] [Test]
public void LoadModelWithItems() 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
container.Items.Add(item1); container.Items.Add(item1);
container.Items.Add(item2); container.Items.Add(item2);
Bitmap bitmap = new Bitmap(700,1000); var bitmap = new Bitmap(700,1000);
graphics = Graphics.FromImage(bitmap); graphics = Graphics.FromImage(bitmap);
} }
} }

Loading…
Cancel
Save