public static FormattedText CreateFormattedText(ExportText exportText) { var culture = CultureInfo.CurrentCulture; var flowDirection = culture.TextInfo.IsRightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight; var emSize = ExtensionMethodes.ToPoints((int)exportText.Font.SizeInPoints +1); var formattedText = new FormattedText(exportText.Text, CultureInfo.CurrentCulture, flowDirection, new Typeface(exportText.Font.FontFamily.Name), emSize, new SolidColorBrush(exportText.ForeColor.ToWpf()), null, TextFormattingMode.Display); formattedText.MaxTextWidth = exportText.DesiredSize.Width ; formattedText.TextAlignment = exportText.TextAlignment; // var s = formattedText.Height; if (!exportText.CanGrow) { formattedText.MaxTextHeight = exportText.Size.Height; } // // else { //// formattedText.MaxTextHeight = ExtensionMethodes.ToPoints(exportText.DesiredSize.Height ); // } ApplyPrintStyles(formattedText,exportText); return formattedText; }
public TextBlock CreateTextBlock(ExportText exportText) { var textBlock = new TextBlock(); textBlock.Text = exportText.Text; textBlock.Foreground = ConvertBrush(exportText.ForeColor); SetFont(textBlock,exportText); textBlock.TextWrapping = TextWrapping.WrapWithOverflow; // string [] inlines = exportText.Text.Split(System.Environment.NewLine.ToCharArray()); //string [] inlines = "jmb,.n,knn-.n.-n.n-.n.n.-"; // for (int i = 0; i < inlines.Length; i++) { // if (inlines[i].Length > 0) { // textBlock.Inlines.Add(new Run(inlines[i])); //// textBlock.Inlines.Add(new LineBreak()); // } // } // var li = textBlock.Inlines.LastInline; // textBlock.Inlines.Remove(li); // SetDimension(textBlock,exportText.StyleDecorator); // textBlock.Background = ConvertBrush(exportText.StyleDecorator.BackColor); // SetContendAlignment(textBlock,exportText.StyleDecorator); SetPosition(textBlock,exportText); SetDimension(textBlock,exportText); textBlock.Background = ConvertBrush(exportText.BackColor); return textBlock; }
public override void Visit(ExportText exportColumn) { Console.WriteLine(exportColumn.Text); if (!String.IsNullOrEmpty(exportColumn.FormatString)) { StandardFormatter.FormatOutput(exportColumn); } }
public static FormattedText CreateFormattedText(ExportText exportText) { FlowDirection flowDirection; var culture = CultureInfo.CurrentCulture; if (culture.TextInfo.IsRightToLeft) { flowDirection = FlowDirection.RightToLeft; } else { flowDirection = FlowDirection.LeftToRight; } var emSize = ExtensionMethodes.ToPoints((int)exportText.Font.SizeInPoints +1); var formattedText = new FormattedText(exportText.Text, CultureInfo.CurrentCulture, flowDirection, new Typeface(exportText.Font.FontFamily.Name), emSize, new SolidColorBrush(exportText.ForeColor.ToWpf()), null, TextFormattingMode.Display); formattedText.MaxTextWidth = ExtensionMethodes.ToPoints(exportText.DesiredSize.Width); ApplyPrintStyles(formattedText,exportText); return formattedText; }
public static void WriteText(XTextFormatter textFormatter,Point columnLocation, ExportText exportColumn) { var font = PdfHelper.CreatePdfFont(exportColumn); var rect = new Rectangle(columnLocation,exportColumn.DesiredSize).ToXRect(); textFormatter.DrawString(exportColumn.Text, font, CreateBrush(exportColumn.ForeColor), rect, XStringFormats.TopLeft); }
public override void Visit(ExportText exportText) { var columnLocation = containerLocation; columnLocation.Offset(exportText.Location); if (ShouldSetBackcolor(exportText)) { var r = new Rectangle(columnLocation,exportText.DisplayRectangle.Size); PdfHelper.FillRectangle(r,exportText.BackColor,gfx); } PdfHelper.WriteText(textFormatter,columnLocation, exportText); }
public override void Visit(ExportText exportColumn) { if (ExpressionHelper.CanEvaluate(exportColumn.Text)) { try { object result = Evaluate(exportColumn); exportColumn.Text = result.ToString(); } catch (Exception e) { var s = String.Format(CultureInfo.CurrentCulture,"SharpReport.Expressions -> {0} for {1}",e.Message,exportColumn.Text); Console.WriteLine(s); } } }
public override IExportColumn CreateExportColumn() { var ex = new ExportText(); ex.Name = Name; ex.Location = Location; ex.ForeColor = ForeColor; ex.BackColor = BackColor; ex.FrameColor = FrameColor; ex.Size = Size; ex.Font = Font; ex.Text = Text; ex.CanGrow = CanGrow; return ex; }
public override IExportColumn CreateExportColumn() { var ex = new ExportText(); ex.Name = Name; ex.Location = Location; ex.ForeColor = ForeColor; ex.BackColor = BackColor; ex.FrameColor = FrameColor; ex.Size = Size; ex.Font = Font; ex.Text = Text; ex.FormatString = FormatString; ex.ContentAlignment = ContentAlignment; ex.DataType = DataType; ex.CanGrow = CanGrow; ex.DrawBorder = DrawBorder; return ex; }
public override void Visit(ExportText exportColumn){ /* var textBlock = FixedDocumentCreator.CreateTextBlock((ExportText)exportColumn,ShouldSetBackcolor(exportColumn)); CanvasHelper.SetPosition(textBlock,new Point(exportColumn.Location.X,exportColumn.Location.Y)); UIElement = textBlock; */ var ft = 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); } var dragingElement = new DrawingElement(visual); UIElement = dragingElement; }
public void ContainerContainsTwoItems_OneCanGrow() { var container = CreateContainer(); var item1 = new ExportText(){ CanGrow = true, Name = "Item1", Location = new Point(80,20), Size = new Size (60,70), Parent = container }; container.ExportedItems.Add(item1); Measure(container); strategy.Arrange(container); foreach (var element in container.ExportedItems) { var arrangedRect = new Rectangle(container.Location.X + element.Location.X,container.Location.Y + element.Location.Y, element.Size.Width,element.Size.Height); Assert.That(container.DisplayRectangle.IntersectsWith(arrangedRect)); Assert.That(container.DisplayRectangle.Contains(arrangedRect)); } }
/* static void SetFont(TextBlock textBlock,IExportText exportText){ textBlock.FontFamily = new FontFamily(exportText.Font.FontFamily.Name); //http://www.codeproject.com/Articles/441009/Drawing-Formatted-Text-in-a-Windows-Forms-Applicat textBlock.FontSize = Math.Floor(exportText.Font.Size * 96/72); if (exportText.Font.Bold) { textBlock.FontWeight = FontWeights.Bold; } if (exportText.Font.Underline) { CreateUnderline(textBlock,exportText); } if (exportText.Font.Italic) { textBlock.FontStyle = FontStyles.Italic ; } if (exportText.Font.Strikeout) { CreateStrikeout(textBlock,exportText); } } */ static void SetContentAlignment(TextBlock textBlock,ExportText exportText) { // 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 switch (exportText.ContentAlignment) { 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; break; case System.Drawing.ContentAlignment.TopRight: textBlock.VerticalAlignment = VerticalAlignment.Top; textBlock.TextAlignment = TextAlignment.Right; break; // Middle case System.Drawing.ContentAlignment.MiddleLeft: textBlock.VerticalAlignment = VerticalAlignment.Center; textBlock.TextAlignment = TextAlignment.Left; break; case System.Drawing.ContentAlignment.MiddleCenter: textBlock.VerticalAlignment = VerticalAlignment.Center; textBlock.TextAlignment = TextAlignment.Center; break; case System.Drawing.ContentAlignment.MiddleRight: textBlock.VerticalAlignment = VerticalAlignment.Center; textBlock.TextAlignment = TextAlignment.Right; break; //Bottom case System.Drawing.ContentAlignment.BottomLeft: textBlock.VerticalAlignment = VerticalAlignment.Bottom; textBlock.TextAlignment = TextAlignment.Left; break; case System.Drawing.ContentAlignment.BottomCenter: textBlock.VerticalAlignment = VerticalAlignment.Bottom; textBlock.TextAlignment = TextAlignment.Center; break; case System.Drawing.ContentAlignment.BottomRight: textBlock.VerticalAlignment = VerticalAlignment.Bottom; textBlock.TextAlignment = TextAlignment.Right; break; } }
static void CheckUnderline(TextDecorationCollection td, ExportText exportText) { if (exportText.Font.Underline) { td.Add(new TextDecoration{Location = TextDecorationLocation.Underline}); } }
// http://stackoverflow.com/questions/25308612/vertical-alignment-with-drawingcontext-drawtext 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()){ var bachgroundRect = new Rect(location,new Size(exportColumn.DesiredSize.Width,formattedText.MaxTextHeight)); if (ShouldSetBackcolor(exportColumn)) { drawingContext.DrawRectangle(FixedDocumentCreator.ConvertBrush(exportColumn.BackColor), null,bachgroundRect); } drawingContext.DrawText(formattedText,location); if (HasFrame(exportColumn)) { var frameRect = new Rect(location,new Size(exportColumn.DesiredSize.Width,formattedText.Height)); var pen = FixedDocumentCreator.CreateWpfPen(exportColumn); pen.Thickness = 1; drawingContext.DrawRectangle(null, pen, frameRect); } } var drawingElement = new DrawingElement(visual); UIElement = drawingElement; }
public override void Visit(ExportText exportText) { var columnLocation = new Point(containerLocation.X + exportText.Location.X,containerLocation.Y + exportText.Location.Y); var columnRect = new Rectangle(columnLocation,exportText.DisplayRectangle.Size).ToXRect(); if (ShouldSetBackcolor(exportText)) { PdfHelper.FillRectangle(columnRect,exportText.BackColor,xGraphics); } if (HasFrame(exportText)) { PdfHelper.DrawBorder(columnRect,exportText,xGraphics); } PdfHelper.WriteText(textFormatter,columnLocation, exportText); }
public override void Visit(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))); } // 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; }
object Evaluate(ExportText exportColumn) { var str = ExpressionHelper.ExtractExpressionPart(exportColumn.Text); var result = evaluator.Evaluate(str); return result; }
private IExportText CreateCanGrowText(IExportContainer container) { var secondItem = new ExportText(){ Name = "Item1", Location = new Point(80,10), Size = new Size (20,70), DesiredSize = new Size (20,70), CanGrow = true, Parent = container }; return secondItem; }
public override void Visit(ExportText exportColumn) { if (!String.IsNullOrEmpty(exportColumn.FormatString)) { StandardFormatter.FormatOutput(exportColumn); } }
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: break; case System.Drawing.ContentAlignment.TopCenter: x = textLenDif / 2; break; case System.Drawing.ContentAlignment.TopRight: x = textLenDif; break; // Middle case System.Drawing.ContentAlignment.MiddleLeft: y = textHeightDif / 2; break; case System.Drawing.ContentAlignment.MiddleCenter: y = textHeightDif / 2; x = textLenDif / 2; break; case System.Drawing.ContentAlignment.MiddleRight: x = textLenDif;; y = textHeightDif / 2; break; //Bottom case System.Drawing.ContentAlignment.BottomLeft: x = 0; y = textHeightDif; break; case System.Drawing.ContentAlignment.BottomCenter: x = textLenDif / 2; y = textHeightDif; break; case System.Drawing.ContentAlignment.BottomRight: x = textLenDif; y = textHeightDif; break; } return new Point(x,y); }
void SetFont(TextBlock textBlock,ExportText exportText) { textBlock.FontFamily = new FontFamily(exportText.Font.FontFamily.Name); textBlock.FontSize = exportText.Font.Size * 96/72; if (exportText.Font.Bold) { textBlock.FontWeight = FontWeights.Bold; } if (exportText.Font.Underline) { CreateUnderline(textBlock,exportText); } if (exportText.Font.Italic) { textBlock.FontStyle = System.Windows.FontStyles.Italic ; } if (exportText.Font.Strikeout) { CreateStrikeout(textBlock,exportText); } }
/* public static TextBlock CreateTextBlock(ExportText exportText,bool setBackcolor){ var textBlock = new TextBlock(); textBlock.Foreground = ConvertBrush(exportText.ForeColor); if (setBackcolor) { textBlock.Background = ConvertBrush(exportText.BackColor); } SetFont(textBlock,exportText); textBlock.TextWrapping = TextWrapping.Wrap; 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])); textBlock.Inlines.Add(new LineBreak()); } } var li = textBlock.Inlines.LastInline; textBlock.Inlines.Remove(li); } static void MeasureTextBlock(TextBlock textBlock,ExportText exportText) { var wpfSize = MeasureTextInWpf(exportText); textBlock.Width = wpfSize.Width; textBlock.Height = wpfSize.Height; } */ /* static Size MeasureTextInWpf(ExportText exportText){ if (exportText.CanGrow) { var formattedText = NewMethod(exportText); formattedText.MaxTextWidth = exportText.DesiredSize.Width * 96.0 / 72.0; formattedText.SetFontSize(Math.Floor(exportText.Font.Size * 96.0 / 72.0)); var size = new Size { Width = formattedText.WidthIncludingTrailingWhitespace, Height = formattedText.Height + 6}; return size; } return new Size(exportText.Size.Width,exportText.Size.Height); } */ public static FormattedText CreateFormattedText(ExportText exportText) { var formattedText = new FormattedText(exportText.Text, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface(exportText.Font.FontFamily.Name), exportText.Font.Size, new SolidColorBrush(exportText.ForeColor.ToWpf()), null, TextFormattingMode.Display); formattedText.MaxTextWidth = exportText.DesiredSize.Width * 96.0 / 72.0; formattedText.SetFontSize(Math.Floor(exportText.Font.Size * 96.0 / 72.0)); var td = new TextDecorationCollection() ; CheckUnderline(td,exportText); formattedText.SetTextDecorations(td); return formattedText; }
public static XParagraphAlignment XParagraphAlignment(ExportText exportColumn) { switch (exportColumn.TextAlignment) { case System.Windows.TextAlignment.Left: return PdfSharp.Drawing.Layout.XParagraphAlignment.Left; case System.Windows.TextAlignment.Center: return PdfSharp.Drawing.Layout.XParagraphAlignment.Center; case System.Windows.TextAlignment.Right: return PdfSharp.Drawing.Layout.XParagraphAlignment.Right; case System.Windows.TextAlignment.Justify: return PdfSharp.Drawing.Layout.XParagraphAlignment.Justify; } return PdfSharp.Drawing.Layout.XParagraphAlignment.Left; }
public override void Visit(ExportText exportColumn) { // Console.WriteLine("Wpf-Visit ExportText {0} - {1} - {2}", exportColumn.Name,exportColumn.Size,exportColumn.DesiredSize); var textBlock = documentCreator.CreateTextBlock(exportColumn); UIElement = textBlock; }
IExportContainer CreateContainer() { var container = new ExportContainer(){ Size = new Size (720,60), Location = new Point(50,50), Name ="Section" }; var item1 = new ExportText(){ Name = "Item1", Location = new Point(10,10), Size = new Size (60,20), Parent = container }; container.ExportedItems.Add(item1); return container; }
public override void Visit(ExportText exportColumn) { }
public abstract void Visit(ExportText exportColumn);
public override void Visit(ExportText exportText){ var columnLocation = new Point(containerLocation.X + exportText.Location.X,containerLocation.Y + exportText.Location.Y); if (ShouldSetBackcolor(exportText)) { var r = new Rectangle(columnLocation,exportText.DisplayRectangle.Size); PdfHelper.FillRectangle(r,exportText.BackColor,xGraphics); } PdfHelper.WriteText(textFormatter,columnLocation, exportText); }
public virtual void Visit(ExportText exportColumn) { }
static void ApplyPrintStyles(FormattedText formattedText,ExportText exportText) { var font = exportText.Font; var textDecorations = new TextDecorationCollection(); FontStyle fontStyle; FontWeight fontWeight; if ((font.Style & System.Drawing.FontStyle.Italic) != 0) { fontStyle = FontStyles.Italic; } else { fontStyle = FontStyles.Normal; } formattedText.SetFontStyle(fontStyle); if ((font.Style & System.Drawing.FontStyle.Bold) != 0) { fontWeight = FontWeights.Bold; } else { fontWeight = FontWeights.Normal; } formattedText.SetFontWeight(fontWeight); if ((font.Style & System.Drawing.FontStyle.Underline) != 0) { textDecorations.Add(TextDecorations.Underline); } if ((font.Style & System.Drawing.FontStyle.Strikeout) != 0) { textDecorations.Add(TextDecorations.Strikethrough); } formattedText.SetTextDecorations(textDecorations); }