Browse Source

StringMeasurement inside Container, StringTrimming in TextBlock

reports
Peter Forstmeier 12 years ago
parent
commit
d6a9f13d54
  1. 4
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Arrange/MeasurementStrategy.cs
  2. 130
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/ExportRenderer/FixedDocumentCreator.cs
  3. 6
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Exporter/Visitors/CanvasExtension.cs
  4. 7
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Globals/MeasurementService.cs

4
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Arrange/MeasurementStrategy.cs

@ -31,6 +31,10 @@ namespace ICSharpCode.Reporting.Arrange @@ -31,6 +31,10 @@ namespace ICSharpCode.Reporting.Arrange
var items = ((ExportContainer)exportColumn).ExportedItems;
foreach (var element in items) {
if (element is IExportContainer) {
Console.WriteLine("Measure -> Container found");
Measure(element,graphics);
}
var tbi = element as IExportText;
if (tbi != null) {
element.DesiredSize = MeasurementService.Measure(tbi,graphics);

130
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/ExportRenderer/FixedDocumentCreator.cs

@ -7,7 +7,6 @@ @@ -7,7 +7,6 @@
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
@ -56,25 +55,35 @@ namespace ICSharpCode.Reporting.ExportRenderer @@ -56,25 +55,35 @@ namespace ICSharpCode.Reporting.ExportRenderer
canvas.UpdateLayout();
return canvas;
}
public TextBlock CreateTextBlock(ExportText exportText,bool setBackcolor){
var textBlock = new TextBlock();
var textBlock = new TextBlock();
textBlock.Foreground = ConvertBrush(exportText.ForeColor);
/*
if (setBackcolor) {
textBlock.Background = ConvertBrush(exportText.BackColor);
}
*/
textBlock.Background = ConvertBrush(System.Drawing.Color.LightPink);
// textBlock.Background = ConvertBrush(System.Drawing.Color.LightGray);
SetFont(textBlock,exportText);
textBlock.TextWrapping = TextWrapping.WrapWithOverflow;
textBlock.TextWrapping = TextWrapping.Wrap;
textBlock.TextTrimming = TextTrimming.CharacterEllipsis;
string [] inlines = exportText.Text.Split(System.Environment.NewLine.ToCharArray());
CheckForNewLine (textBlock,exportText);
SetContentAlignment(textBlock,exportText);
MeasureTextBlock (textBlock,exportText);
return textBlock;
}
static void CheckForNewLine(TextBlock textBlock,ExportText exportText) {
string [] inlines = exportText.Text.Split(Environment.NewLine.ToCharArray());
for (int i = 0; i < inlines.Length; i++) {
if (inlines[i].Length > 0) {
textBlock.Inlines.Add(new Run(inlines[i]));
@ -83,45 +92,37 @@ namespace ICSharpCode.Reporting.ExportRenderer @@ -83,45 +92,37 @@ namespace ICSharpCode.Reporting.ExportRenderer
}
var li = textBlock.Inlines.LastInline;
textBlock.Inlines.Remove(li);
SetContentAlignment(textBlock,exportText);
}
static void MeasureTextBlock(TextBlock textBlock,ExportText exportText)
{
var wpfSize = MeasureTextInWpf(exportText);
textBlock.Width = wpfSize.Width;
textBlock.Height = wpfSize.Height;
// textBlock.Background = ConvertBrush(exportText.StyleDecorator.BackColor);
// SetContendAlignment(textBlock,exportText.StyleDecorator);
if (exportText.ContentAlignment != System.Drawing.ContentAlignment.TopLeft) {
Console.WriteLine("----Aliogn --------{0}",exportText.ContentAlignment.ToString());
}
// SetContentAlignment(textBlock,exportText);
return textBlock;
}
}
static Size MeasureTextInWpf(ExportText exportText){
if (exportText.CanGrow) {
FormattedText ft = new FormattedText(exportText.Text,
CultureInfo.CurrentCulture,
System.Windows.FlowDirection.LeftToRight,
new Typeface(exportText.Font.FontFamily.Name),
exportText.Font.Size,
// System.Windows.Media.Brushes.Black,
new SolidColorBrush(exportText.ForeColor.ToWpf()),
null,
TextFormattingMode.Display);
ft.MaxTextWidth = exportText.Size.Width * 96.0 / 72.0;
ft.MaxTextHeight = Double.MaxValue ;
ft.SetFontSize(exportText.Font.Size * 96.0 / 72.0);
var ss = new Size {
Width = ft.WidthIncludingTrailingWhitespace,
Height = ft.Height};
return ss;
FormattedText ft = new FormattedText(exportText.Text,
CultureInfo.CurrentCulture,
System.Windows.FlowDirection.LeftToRight,
new Typeface(exportText.Font.FontFamily.Name),
exportText.Font.Size,
new SolidColorBrush(exportText.ForeColor.ToWpf()),
null,
TextFormattingMode.Display);
ft.MaxTextWidth = exportText.Size.Width * 96.0 / 72.0;
ft.MaxTextHeight = Double.MaxValue ;
ft.SetFontSize(exportText.Font.Size * 96.0 / 72.0);
var size = new Size {
Width = ft.WidthIncludingTrailingWhitespace,
Height = ft.Height};
return size;
}
return new Size(exportText.Size.Width,exportText.Size.Height);
}
@ -185,7 +186,6 @@ namespace ICSharpCode.Reporting.ExportRenderer @@ -185,7 +186,6 @@ namespace ICSharpCode.Reporting.ExportRenderer
// http://social.msdn.microsoft.com/Forums/vstudio/en-US/e480abb9-a86c-4f78-8955-dddb866bcfef/vertical-text-alignment-in-textblock?forum=wpf
//Vertical alignment not working
Console.WriteLine("align {0}",exportText.ContentAlignment);
switch (exportText.ContentAlignment) {
case System.Drawing.ContentAlignment.TopLeft:
textBlock.VerticalAlignment = VerticalAlignment.Top;
@ -227,52 +227,8 @@ namespace ICSharpCode.Reporting.ExportRenderer @@ -227,52 +227,8 @@ namespace ICSharpCode.Reporting.ExportRenderer
break;
}
}
/*
private void SetContendAlignment(TextBlock textBlock,TextStyleDecorator decorator)
{
switch (decorator.ContentAlignment)
{
case ContentAlignment.TopLeft:
textBlock.VerticalAlignment = VerticalAlignment.Top;
textBlock.TextAlignment = TextAlignment.Left;
break;
case ContentAlignment.TopCenter:
textBlock.VerticalAlignment = VerticalAlignment.Top;
textBlock.TextAlignment = TextAlignment.Center;
break;
case ContentAlignment.TopRight:
textBlock.VerticalAlignment = VerticalAlignment.Top;
textBlock.TextAlignment = TextAlignment.Right;
break;
// Middle
case ContentAlignment.MiddleLeft:
textBlock.VerticalAlignment = VerticalAlignment.Center;
textBlock.TextAlignment = TextAlignment.Left;
break;
case ContentAlignment.MiddleCenter:
textBlock.VerticalAlignment = VerticalAlignment.Center;
textBlock.TextAlignment = TextAlignment.Center;
break;
case ContentAlignment.MiddleRight:
textBlock.VerticalAlignment = VerticalAlignment.Center;
textBlock.TextAlignment = TextAlignment.Right;
break;
//Bottom
case ContentAlignment.BottomLeft:
textBlock.VerticalAlignment = VerticalAlignment.Bottom;
textBlock.TextAlignment = TextAlignment.Left;
break;
case ContentAlignment.BottomCenter:
textBlock.VerticalAlignment = VerticalAlignment.Bottom;
textBlock.TextAlignment = TextAlignment.Center;
break;
case ContentAlignment.BottomRight:
textBlock.VerticalAlignment = VerticalAlignment.Bottom;
textBlock.TextAlignment = TextAlignment.Right;
break;
}
}
*/
void CreateStrikeout (TextBlock textBlock,IExportText exportColumn ){
if (textBlock == null)
throw new ArgumentNullException("textBlock");

6
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Exporter/Visitors/CanvasExtension.cs

@ -15,7 +15,7 @@ namespace ICSharpCode.Reporting.Exporter.Visitors @@ -15,7 +15,7 @@ namespace ICSharpCode.Reporting.Exporter.Visitors
public static void AddChild<T>(this Canvas canvas, T element)
{
UIElement uiElement = element as UIElement;
var uiElement = element as UIElement;
if (uiElement != null && !canvas.Children.Contains(uiElement))
canvas.Children.Add(uiElement);
}
@ -23,7 +23,7 @@ namespace ICSharpCode.Reporting.Exporter.Visitors @@ -23,7 +23,7 @@ namespace ICSharpCode.Reporting.Exporter.Visitors
public static void RemoveChild<T>(this Canvas canvas, T element)
{
UIElement uiElement = element as UIElement;
var uiElement = element as UIElement;
if (uiElement != null && canvas.Children.Contains(uiElement))
canvas.Children.Remove(uiElement);
}
@ -31,7 +31,7 @@ namespace ICSharpCode.Reporting.Exporter.Visitors @@ -31,7 +31,7 @@ namespace ICSharpCode.Reporting.Exporter.Visitors
public static void InsertChild<T>(this Canvas canvas, int index, T element)
{
UIElement uiElement = element as UIElement;
var uiElement = element as UIElement;
if (uiElement != null && !canvas.Children.Contains(uiElement))
canvas.Children.Insert(index, uiElement);
}

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

@ -15,15 +15,12 @@ namespace ICSharpCode.Reporting.Globals @@ -15,15 +15,12 @@ namespace ICSharpCode.Reporting.Globals
/// <summary>
/// Description of MeasurementService.
/// </summary>
internal class MeasurementService
internal static class MeasurementService
{
public MeasurementService()
{
}
public static Size Measure (IExportText item,Graphics graphics) {
Console.WriteLine("Measure {0}",item.Text);
if (!item.CanGrow) {
return item.Size;
}

Loading…
Cancel
Save