Browse Source

ContentAlignment is Obsolte,

use TextAlignment as replacement to print Left,Center,Right and Justified Text
pull/503/head
Peter Forstmeier 11 years ago
parent
commit
9219731848
  1. 34
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/DesignableItems/BaseTextItem.cs
  2. 6
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/TypeProvider/TypeProviderHelper.cs
  3. 5
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Arrange/ArrangeStrategy.cs
  4. 71
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/BaseClasses/TextDrawer.cs
  5. 1
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Globals/MeasurementService.cs
  6. 10
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/BaseTextItem.cs
  7. 5
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/ExportColumns/ExportText.cs
  8. 19
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Wpf/Visitor/FixedDocumentCreator.cs
  9. 16
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Wpf/Visitor/WpfVisitor.cs

34
src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/DesignableItems/BaseTextItem.cs

@ -10,6 +10,7 @@ using System; @@ -10,6 +10,7 @@ using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Windows;
using ICSharpCode.Reporting.BaseClasses;
using ICSharpCode.Reporting.Globals;
using ICSharpCode.Reporting.Addin.Designer;
@ -31,18 +32,18 @@ namespace ICSharpCode.Reporting.Addin.DesignableItems @@ -31,18 +32,18 @@ namespace ICSharpCode.Reporting.Addin.DesignableItems
StringFormat stringFormat;
StringTrimming stringTrimming;
ContentAlignment contentAlignment;
TextAlignment textAlignment;
public BaseTextItem(){
DefaultSize = GlobalValues.PreferedSize;
Size = GlobalValues.PreferedSize;
BackColor = Color.White;
contentAlignment = ContentAlignment.TopLeft;
textAlignment = TextAlignment.Left;
TypeDescriptor.AddProvider(new TextItemTypeProvider(), typeof(BaseTextItem));
}
// [EditorBrowsableAttribute()]
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e){
base.OnPaint(e);
Draw(e.Graphics);
@ -64,7 +65,8 @@ namespace ICSharpCode.Reporting.Addin.DesignableItems @@ -64,7 +65,8 @@ namespace ICSharpCode.Reporting.Addin.DesignableItems
designTrimmimg = stringTrimming;
}
stringFormat = TextDrawer.BuildStringFormat(designTrimmimg, contentAlignment);
// stringFormat = TextDrawer.BuildStringFormat(designTrimmimg, contentAlignment);
stringFormat = TextDrawer.BuildStringFormat(designTrimmimg, textAlignment);
using (var textBrush = new SolidBrush(ForeColor)) {
TextDrawer.DrawString(graphics, Text, Font, textBrush, ClientRectangle, stringFormat);
}
@ -119,10 +121,9 @@ namespace ICSharpCode.Reporting.Addin.DesignableItems @@ -119,10 +121,9 @@ namespace ICSharpCode.Reporting.Addin.DesignableItems
}
[Category("Appearance")]
[EditorAttribute(typeof(ContentAlignmentEditor),
typeof(UITypeEditor) )]
typeof(UITypeEditor) )]
public ContentAlignment ContentAlignment {
get { return contentAlignment; }
set {
@ -132,18 +133,15 @@ namespace ICSharpCode.Reporting.Addin.DesignableItems @@ -132,18 +133,15 @@ namespace ICSharpCode.Reporting.Addin.DesignableItems
}
[Category("Appearance")]
public TextAlignment TextAlignment {
get { return textAlignment;}
set {textAlignment = value;
Invalidate();}
}
#endregion
// #region RighToLeft
//
// [Category("Appearance")]
// public System.Windows.Forms.RightToLeft RTL
// {
// get { return base.RightToLeft; }
// set { base.RightToLeft = value; }
// }
//
// #endregion
#region DataType
@ -158,10 +156,10 @@ namespace ICSharpCode.Reporting.Addin.DesignableItems @@ -158,10 +156,10 @@ namespace ICSharpCode.Reporting.Addin.DesignableItems
#region Expression
[Browsable(true),
Category("Expression"),
Description("Enter a valid Expression")]
Category("Expression"),
Description("Enter a valid Expression")]
[EditorAttribute(typeof(ExpressionEditor),
typeof(UITypeEditor) )]
typeof(UITypeEditor) )]
public string Expression {get;set;}
#endregion

6
src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/TypeProvider/TypeProviderHelper.cs

@ -99,6 +99,9 @@ namespace ICSharpCode.Reporting.Addin.TypeProvider @@ -99,6 +99,9 @@ namespace ICSharpCode.Reporting.Addin.TypeProvider
prop = props.Find("ContentAlignment",true);
allProperties.Add(prop);
prop = props.Find("TextAlignment",true);
allProperties.Add(prop);
prop = props.Find("CanGrow",true);
allProperties.Add(prop);
@ -107,9 +110,6 @@ namespace ICSharpCode.Reporting.Addin.TypeProvider @@ -107,9 +110,6 @@ namespace ICSharpCode.Reporting.Addin.TypeProvider
prop = props.Find("DataType",true);
allProperties.Add(prop);
// prop = props.Find("RTL",true);
// allProperties.Add(prop);
}
public static void AddGraphicProperties (List<PropertyDescriptor> allProperties,

5
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Arrange/ArrangeStrategy.cs

@ -58,7 +58,6 @@ namespace ICSharpCode.Reporting.Arrange @@ -58,7 +58,6 @@ namespace ICSharpCode.Reporting.Arrange
{
var containerRectangle = container.DisplayRectangle;
Rectangle elementRectangle = Rectangle.Empty;
foreach (var element in container.ExportedItems) {
var con = element as IExportContainer;
if (con != null) {
@ -76,9 +75,7 @@ namespace ICSharpCode.Reporting.Arrange @@ -76,9 +75,7 @@ namespace ICSharpCode.Reporting.Arrange
containerRectangle = new Rectangle(containerRectangle.Left,
containerRectangle.Top ,
containerRectangle.Width,
element.Location.Y + elementRectangle.Size.Height + 5);
// containerRectangle = Rectangle.Union(containerRectangle,elementRectangle);
element.Location.Y + elementRectangle.Size.Height + 5);
}
}
return containerRectangle.Size;

71
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/BaseClasses/TextDrawer.cs

@ -9,20 +9,15 @@ @@ -9,20 +9,15 @@
using System;
using System.Drawing;
using System.Drawing.Text;
using System.Windows;
namespace ICSharpCode.Reporting.BaseClasses
{
/// <summary>
/// Description of TextDrawer.
/// </summary>
public sealed class TextDrawer
public static class TextDrawer
{
private TextDrawer()
{
}
public static void DrawString(Graphics graphics,string text,
Font font,Brush brush,
RectangleF rectangle,
@ -38,41 +33,40 @@ namespace ICSharpCode.Reporting.BaseClasses @@ -38,41 +33,40 @@ namespace ICSharpCode.Reporting.BaseClasses
rectangle,
format);
}
public static void DrawString (Graphics graphics,string text)
{
if (graphics == null) {
throw new ArgumentNullException("graphics");
public static StringFormat BuildStringFormat(StringTrimming stringTrimming,TextAlignment alignment){
StringFormat format = StringFormat.GenericTypographic;
format.Trimming = stringTrimming;
format.FormatFlags = StringFormatFlags.LineLimit;
switch (alignment) {
case TextAlignment.Left:{
format.Alignment = StringAlignment.Near;
format.LineAlignment = StringAlignment.Near;
return format;
}
case TextAlignment.Center:{
format.Alignment = StringAlignment.Center;
format.LineAlignment = StringAlignment.Near;
return format;
}
case TextAlignment.Right:{
format.Alignment = StringAlignment.Far;
format.LineAlignment = StringAlignment.Near;
return format;
}
case TextAlignment.Justify:{
format.Alignment = StringAlignment.Center;
format.LineAlignment = StringAlignment.Near;
return format;
}
}
// if (decorator == null) {
// throw new ArgumentNullException("decorator");
// }
// StringFormat stringFormat = BuildStringFormat(decorator.StringTrimming,decorator.ContentAlignment);
//
// if (decorator.RightToLeft ==System.Windows.Forms.RightToLeft.Yes) {
// stringFormat.FormatFlags = stringFormat.FormatFlags | StringFormatFlags.DirectionRightToLeft;
// }
var formattedString = text;
// if (! String.IsNullOrEmpty(decorator.FormatString)) {
// formattedString = StandardFormatter.FormatOutput(text,decorator.FormatString,decorator.DataType,String.Empty);
// }
graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
// graphics.DrawString (formattedString,decorator.Font,
// new SolidBrush(decorator.ForeColor),
// new Rectangle(decorator.Location.X,
// decorator.Location.Y,
// decorator.Size.Width,
// decorator.Size.Height),
// stringFormat);
return format;
}
/*
public static StringFormat BuildStringFormat(StringTrimming stringTrimming,ContentAlignment alignment)
{
StringFormat format = StringFormat.GenericTypographic;
@ -139,5 +133,6 @@ namespace ICSharpCode.Reporting.BaseClasses @@ -139,5 +133,6 @@ namespace ICSharpCode.Reporting.BaseClasses
format.LineAlignment = StringAlignment.Far;
return format;
}
*/
}
}

1
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Globals/MeasurementService.cs

@ -45,6 +45,7 @@ namespace ICSharpCode.Reporting.Globals @@ -45,6 +45,7 @@ namespace ICSharpCode.Reporting.Globals
}
return new Size(item.Size.Width,(int)Math.Ceiling(sizeF.Height));
}
Console.WriteLine ("measure {0}",item.Size);
return item.Size;
}
}

10
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/BaseTextItem.cs

@ -18,6 +18,7 @@ @@ -18,6 +18,7 @@
using System;
using System.Drawing;
using System.Windows;
using ICSharpCode.Reporting.Globals;
using ICSharpCode.Reporting.Interfaces;
using ICSharpCode.Reporting.Interfaces.Export;
@ -33,6 +34,7 @@ namespace ICSharpCode.Reporting.Items @@ -33,6 +34,7 @@ namespace ICSharpCode.Reporting.Items
Font Font {get;set;}
string Text {get;set;}
ContentAlignment ContentAlignment {get;set;}
TextAlignment TextAlignment {get;set;}
string FormatString {get;set;}
string DataType {get;set;}
@ -44,7 +46,8 @@ namespace ICSharpCode.Reporting.Items @@ -44,7 +46,8 @@ namespace ICSharpCode.Reporting.Items
Name = "BaseTextItem";
Font = GlobalValues.DefaultFont;
}
public Font Font {get;set;}
@ -52,8 +55,12 @@ namespace ICSharpCode.Reporting.Items @@ -52,8 +55,12 @@ namespace ICSharpCode.Reporting.Items
public string FormatString {get;set;}
[Obsolete ("Use TextAlignment")]
public ContentAlignment ContentAlignment {get;set;}
public TextAlignment TextAlignment {get;set;}
string dataType;
public string DataType
@ -83,6 +90,7 @@ namespace ICSharpCode.Reporting.Items @@ -83,6 +90,7 @@ namespace ICSharpCode.Reporting.Items
ex.Text = Text;
ex.FormatString = FormatString;
ex.ContentAlignment = ContentAlignment;
ex.TextAlignment = TextAlignment;
ex.DataType = DataType;
ex.CanGrow = CanGrow;
ex.DrawBorder = DrawBorder;

5
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/ExportColumns/ExportText.cs

@ -18,6 +18,7 @@ @@ -18,6 +18,7 @@
using System;
using System.Drawing;
using System.Windows;
using ICSharpCode.Reporting.Arrange;
using ICSharpCode.Reporting.Exporter;
using ICSharpCode.Reporting.Exporter.Visitors;
@ -34,6 +35,7 @@ namespace ICSharpCode.Reporting.PageBuilder.ExportColumns @@ -34,6 +35,7 @@ namespace ICSharpCode.Reporting.PageBuilder.ExportColumns
Font Font {get;set;}
string Text {get;set;}
ContentAlignment ContentAlignment {get;set;}
TextAlignment TextAlignment {get;set;}
string DataType {get;set;}
string FormatString {get;set;}
}
@ -57,8 +59,11 @@ namespace ICSharpCode.Reporting.PageBuilder.ExportColumns @@ -57,8 +59,11 @@ namespace ICSharpCode.Reporting.PageBuilder.ExportColumns
public string FormatString {get;set;}
[Obsolete ("Use TextAlignment")]
public ContentAlignment ContentAlignment {get;set;}
public TextAlignment TextAlignment {get;set;}
public string DataType {get;set;}
public override ICSharpCode.Reporting.Arrange.IMeasurementStrategy MeasurementStrategy()

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

@ -40,7 +40,6 @@ namespace ICSharpCode.Reporting.WpfReportViewer.Visitor @@ -40,7 +40,6 @@ namespace ICSharpCode.Reporting.WpfReportViewer.Visitor
static class FixedDocumentCreator
{
public static FixedPage CreateFixedPage(ExportPage exportPage) {
var fixedPage = new FixedPage();
fixedPage.Width = exportPage.Size.ToWpf().Width;
@ -63,10 +62,8 @@ namespace ICSharpCode.Reporting.WpfReportViewer.Visitor @@ -63,10 +62,8 @@ namespace ICSharpCode.Reporting.WpfReportViewer.Visitor
public static FormattedText CreateFormattedText(ExportText exportText)
{
FlowDirection flowDirection;
var culture = CultureInfo.CurrentCulture;
flowDirection = culture.TextInfo.IsRightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;
var flowDirection = culture.TextInfo.IsRightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;
var emSize = ExtensionMethodes.ToPoints((int)exportText.Font.SizeInPoints +1);
@ -78,15 +75,16 @@ namespace ICSharpCode.Reporting.WpfReportViewer.Visitor @@ -78,15 +75,16 @@ namespace ICSharpCode.Reporting.WpfReportViewer.Visitor
new SolidColorBrush(exportText.ForeColor.ToWpf()), null, TextFormattingMode.Display);
formattedText.MaxTextWidth = exportText.DesiredSize.Width ;
formattedText.TextAlignment = exportText.TextAlignment;
// formattedText.TextAlignment = TextAlignment.Justify;
if (!exportText.CanGrow) {
formattedText.MaxTextHeight = exportText.Size.Height;
} else {
formattedText.MaxTextHeight = exportText.Size.Height;
} else {
formattedText.MaxTextHeight = ExtensionMethodes.ToPoints(exportText.DesiredSize.Height );
}
}
ApplyPrintStyles(formattedText,exportText);
return formattedText;
}
@ -153,6 +151,7 @@ namespace ICSharpCode.Reporting.WpfReportViewer.Visitor @@ -153,6 +151,7 @@ namespace ICSharpCode.Reporting.WpfReportViewer.Visitor
FixedPage.SetTop(element,exportColumn.Location.Y);
}
/*
public static Point CalculateAlignmentOffset (FormattedText formattedText, ExportText exportText) {
var offset = new Point(0,0);
double y = 0;
@ -206,7 +205,7 @@ namespace ICSharpCode.Reporting.WpfReportViewer.Visitor @@ -206,7 +205,7 @@ namespace ICSharpCode.Reporting.WpfReportViewer.Visitor
}
return new Point(x,y);
}
*/
public static Pen CreateWpfPen(IReportObject exportColumn){
if (exportColumn == null)

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

@ -60,7 +60,8 @@ namespace ICSharpCode.Reporting.WpfReportViewer.Visitor @@ -60,7 +60,8 @@ namespace ICSharpCode.Reporting.WpfReportViewer.Visitor
Canvas RenderSectionContainer (ExportContainer container) {
Console.WriteLine("--------------");
Console.WriteLine("Container {0}",container.Name);
var canvas = FixedDocumentCreator.CreateContainer(container);
foreach (var element in container.ExportedItems) {
if (IsContainer(element)) {
@ -120,11 +121,13 @@ namespace ICSharpCode.Reporting.WpfReportViewer.Visitor @@ -120,11 +121,13 @@ namespace ICSharpCode.Reporting.WpfReportViewer.Visitor
public override void Visit(ExportText exportColumn){
var formattedText = FixedDocumentCreator.CreateFormattedText((ExportText)exportColumn);
var location = new Point(exportColumn.Location.X,exportColumn.Location.Y);
var visual = new DrawingVisual();
using (var drawingContext = visual.RenderOpen()){
if (ShouldSetBackcolor(exportColumn)) {
var r = new Rect(location,new Size(exportColumn.Size.Width,exportColumn.Size.Height));
drawingContext.DrawRectangle(FixedDocumentCreator.ConvertBrush(exportColumn.BackColor),
null,
new Rect(location,new Size(exportColumn.Size.Width,exportColumn.Size.Height)));
@ -132,12 +135,15 @@ namespace ICSharpCode.Reporting.WpfReportViewer.Visitor @@ -132,12 +135,15 @@ namespace ICSharpCode.Reporting.WpfReportViewer.Visitor
//http://stackoverflow.com/questions/4542717/length-of-string-that-will-fit-in-a-specific-width
// http://stackoverflow.com/questions/9264398/how-to-calculate-wpf-textblock-width-for-its-known-font-size-and-characters
var offset = FixedDocumentCreator.CalculateAlignmentOffset(formattedText,exportColumn);
var newLoc = new Point(location.X + offset.X,location.Y + offset.Y);
drawingContext.DrawText(formattedText,newLoc);
// var offset = FixedDocumentCreator.CalculateAlignmentOffset(formattedText,exportColumn);
// var newLoc = new Point(location.X + offset.X,location.Y + offset.Y);
// Console.WriteLine(" FT for {0} at {1}",formattedText.Text.Substring(0,5),newLoc);
// drawingContext.DrawText(formattedText,newLoc);
drawingContext.DrawText(formattedText,location);
}
var dragingElement = new DrawingElement(visual);
UIElement = dragingElement;
}

Loading…
Cancel
Save