public MeasureString ( string text, XFont font ) : XSize | ||
text | string | |
font | XFont | |
return | XSize |
public override void RenderPage(XGraphics gfx) { base.RenderPage(gfx); string facename = "Times"; XFont fontR = new XFont(facename, 40); XFont fontB = new XFont(facename, 40, XFontStyle.Bold); XFont fontI = new XFont(facename, 40, XFontStyle.Italic); XFont fontBI = new XFont(facename, 40, XFontStyle.Bold | XFontStyle.Italic); //gfx.DrawString("Hello", this.properties.Font1.Font, this.properties.Font1.Brush, 200, 200); double x = 80; XPen pen = XPens.SlateBlue; gfx.DrawLine(pen, x, 100, x, 600); gfx.DrawLine(pen, x - 50, 200, 400, 200); gfx.DrawLine(pen, x - 50, 300, 400, 300); gfx.DrawLine(pen, x - 50, 400, 400, 400); gfx.DrawLine(pen, x - 50, 500, 400, 500); double lineSpace = fontR.GetHeight(gfx); int cellSpace = fontR.FontFamily.GetLineSpacing(fontR.Style); int cellAscent = fontR.FontFamily.GetCellAscent(fontR.Style); int cellDescent = fontR.FontFamily.GetCellDescent(fontR.Style); double cyAscent = lineSpace * cellAscent / cellSpace; XFontMetrics metrics = fontR.Metrics; XSize size; gfx.DrawString("Times 40", fontR, this.properties.Font1.Brush, x, 200); size = gfx.MeasureString("Times 40", fontR); gfx.DrawLine(this.properties.Pen3.Pen, x, 200, x + size.Width, 200); gfx.DrawString("Times bold 40", fontB, this.properties.Font1.Brush, x, 300); size = gfx.MeasureString("Times bold 40", fontB); //gfx.DrawLine(this.properties.Pen3.Pen, x, 300, x + size.Width, 300); gfx.DrawString("Times italic 40", fontI, this.properties.Font1.Brush, x, 400); size = gfx.MeasureString("Times italic 40", fontI); //gfx.DrawLine(this.properties.Pen3.Pen, x, 400, x + size.Width, 400); gfx.DrawString("Times bold italic 40", fontBI, this.properties.Font1.Brush, x, 500); size = gfx.MeasureString("Times bold italic 40", fontBI); //gfx.DrawLine(this.properties.Pen3.Pen, x, 500, x + size.Width, 500); #if true___ // Check Malayalam XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always); XFont Kartika = new XFont("Kartika", 20, XFontStyle.Regular, options); XFont AnjaliOldLipi = new XFont("AnjaliOldLipi", 20, XFontStyle.Regular, options); gfx.DrawString("മകനെ ഇത് ഇന്ത്യയുടെ ഭൂപടം", Kartika, this.properties.Font1.Brush, x, 600); gfx.DrawString("മകനെ ഇത് ഇന്ത്യയുടെ ഭൂപടം", AnjaliOldLipi, this.properties.Font1.Brush, x, 650); #endif }
public void DrawPage(XGraphics gfx, PointF pagepos, PageDrawOptions opts) { float acty = 0; for (int i = 0; i < m_noDelimPageCount; i++) { Pane pane = m_panes[i]; pane.Draw(gfx, new PointF(pagepos.X, pagepos.Y + acty), true); acty += pane.Height; } if (opts != null) { string header = opts.Header.Replace("%c", PageNumber.ToString()); string footer = opts.Footer.Replace("%c", PageNumber.ToString()); if (header != "") { float hdrwi = (float)gfx.MeasureString(header, opts.HeaderFont).Width; float hdrhi = (float)gfx.MeasureString(header, opts.HeaderFont).Height; gfx.DrawString(header, opts.HeaderFont, opts.HeaderColor, new PointF(pagepos.X + opts.PageWidth / 2 - hdrwi / 2, pagepos.Y - hdrhi), XStringFormat.TopLeft); } if (footer != "") { float ftrwi = (float)gfx.MeasureString(footer, opts.FooterFont).Width; gfx.DrawString(footer, opts.FooterFont, opts.FooterColor, new PointF(pagepos.X + opts.PageWidth / 2 - ftrwi / 2, pagepos.Y + opts.PageHeight), XStringFormat.TopLeft); } } }
public static void DrawMultilineString(XGraphics gfx, string text, XFont font, XRect rect, Alignment alignment) { var size = gfx.MeasureString(text, font, XStringFormats.Center); rect = new XRect(rect.X, rect.Y + (rect.Height - size.Height) / 2, rect.Width, 0); var parts = text.Split('\n'); var height = gfx.MeasureString(parts[0], font, XStringFormats.Center).Height; rect.Height = height; for (int i = 0; i < parts.Length; ++i) { DrawString(gfx, parts[i], font, rect, alignment); rect = new XRect(rect.X, rect.Y + height, rect.Width, rect.Height); } }
void RenderMeasureText(XGraphics gfx) { gfx.TranslateTransform(15, 20); XFontStyle style = XFontStyle.Regular; XFont font = new XFont("Times New Roman", 95, style); string text = "Hello"; double x = 20, y = 100; XSize size = gfx.MeasureString(text, font); double lineSpace = font.GetHeight(gfx); int cellSpace = font.FontFamily.GetLineSpacing(style); int cellAscent = font.FontFamily.GetCellAscent(style); int cellDescent = font.FontFamily.GetCellDescent(style); int cellLeading = cellSpace - cellAscent - cellDescent; // Get effective ascent double ascent = lineSpace * cellAscent / cellSpace; gfx.DrawRectangle(XBrushes.Bisque, x, y - ascent, size.Width, ascent); // Get effective descent double descent = lineSpace * cellDescent / cellSpace; gfx.DrawRectangle(XBrushes.LightGreen, x, y, size.Width, descent); // Get effective leading double leading = lineSpace * cellLeading / cellSpace; gfx.DrawRectangle(XBrushes.Yellow, x, y + descent, size.Width, leading); // Draw text half transparent XColor color = XColors.DarkSlateBlue; color.A = 0.6; gfx.DrawString(text, font, new XSolidBrush(color), x, y); }
public void Draw(XGraphics gfx) { var tf = new XTextFormatter(gfx) {Alignment = Alignment}; XSize size = gfx.MeasureString(Content, Font); Rect = new XRect(Rect.X, Rect.Y, Rect.Width, size.Height*(Math.Ceiling(size.Width/Rect.Width) + 1)); tf.DrawString(Content, Font, Brush, Rect, XStringFormats.TopLeft); }
public override void RenderPage(XGraphics gfx) { base.RenderPage(gfx); string text = "TgfÄÖÜWi9"; if (this.properties.Font1.Text != "") text = this.properties.Font1.Text; float x = 100, y = 300; string familyName = properties.Font1.FamilyName; XFontStyle style = this.properties.Font1.Style; float emSize = this.properties.Font1.Size; //familyName = "Verdana"; //style = XFontStyle.Regular; //emSize = 20; //text = "X"; XFont font = CreateFont(familyName, emSize, style); //font = this.properties.Font1.Font; XSize size = gfx.MeasureString(text, font); double lineSpace = font.GetHeight(gfx); int cellSpace = font.FontFamily.GetLineSpacing(style); int cellAscent = font.FontFamily.GetCellAscent(style); int cellDescent = font.FontFamily.GetCellDescent(style); int cellLeading = cellSpace - cellAscent - cellDescent; double ascent = lineSpace * cellAscent / cellSpace; gfx.DrawRectangle(XBrushes.Bisque, x, y - ascent, size.Width, ascent); double descent = lineSpace * cellDescent / cellSpace; gfx.DrawRectangle(XBrushes.LightGreen, x, y, size.Width, descent); double leading = lineSpace * cellLeading / cellSpace; gfx.DrawRectangle(XBrushes.Yellow, x, y + descent, size.Width, leading); //gfx.DrawRectangle(this.properties.Brush1.Brush, x, y - size.Height, size.Width, size.Height); //gfx.DrawLine(this.properties.Pen2.Pen, x, y, x + size.Width, y); //gfx.DrawString("Hello", this.properties.Font1.Font, this.properties.Font1.Brush, 200, 200); #if true_ XPdfFontOptions pdfOptions = new XPdfFontOptions(false, true); font = new XFont("Tahoma", 8, XFontStyle.Regular, pdfOptions); text = "Hallo"; text = chinese; #endif gfx.DrawString(text, font, this.properties.Font1.Brush, x, y); #if true XFont font2 = CreateFont(familyName, emSize, XFontStyle.Italic); gfx.DrawString(text, font2, this.properties.Font1.Brush, x, y+50); #endif //gfx.DrawLine(XPens.Red, x, y + 10, x + 13.7, y + 10); //gfx.DrawString(text, font, this.properties.Font1.Brush, x, y + 20); }
public void Draw(XGraphics gfx) { string s = "Testtext"; //gfx.DrawLine(XPens.GreenYellow, 5, 100, 30, 50); //gfx.DrawEllipse(XBrushes.DarkBlue, new XRect(30, 40, 250, 235)); XFont font = new XFont("Arial", 40, XFontStyle.Italic); gfx.DrawString(s, font, XBrushes.Firebrick, 40, 60); XSize size = gfx.MeasureString(s, font); gfx.DrawLine(XPens.DarkBlue, 40, 60, 40 + size.Width, 60); gfx.DrawLine(XPens.DarkBlue, 40, 60, 40, 60 + size.Height); }
protected void DrawGridlines(XGraphics gfx) { XPen majorpen = XPens.DarkGray.Clone(); majorpen.Width = 1; XPen minorpen = XPens.LightGray.Clone(); minorpen.Width = 0.1f; gfx.SmoothingMode = XSmoothingMode.HighSpeed; DrawGridlines(gfx, new XPoint(100, 100), majorpen, 100, minorpen, 10); string text = this.Description; XFont font = new XFont("Verdana", 14, XFontStyle.Bold); XSize size = gfx.MeasureString(text, font); gfx.DrawString(text, font, XBrushes.Black, (600 - size.Width) / 2, 30); }
void DrawCodePage(XGraphics gfx, XPoint origin) { const double dx = 25; const double dy = 25; XFont labelFont = new XFont("Verdana", 10, XFontStyle.Bold); //XFont font = new XFont("Bauhaus", 16); XFont font = this.properties.Font1.Font; //XFont labelFont = font; //font = new XFont("Symbol", 16); Encoding encoding = Encoding.GetEncoding(1252); double asdf = XColors.LightGray.GS; //XBrush lighter = new XSolidBrush(XColor.FromGrayScale(XColor.LightGray.GS * 1.1)); XBrush lighter = new XSolidBrush(XColor.FromGrayScale(0.9)); XFontStyle style = font.Style; double lineSpace = font.GetHeight(gfx); int cellSpace = font.FontFamily.GetLineSpacing(style); int cellAscent = font.FontFamily.GetCellAscent(style); int cellDescent = font.FontFamily.GetCellDescent(style); int cellLeading = cellSpace - cellAscent - cellDescent; double ascent = lineSpace * cellAscent / cellSpace; double descent = lineSpace * cellDescent / cellSpace; double leading = lineSpace * cellLeading / cellSpace; double x = origin.X + dx; double y = origin.Y; //for (int idx = 0; idx < 16; idx++) // gfx.DrawString("x" + idx.ToString("X"), labelFont, XBrushes.DarkGray, x + idx * dx, y); for (int row = 0; row < 16; row++) { x = origin.X; y += dy; //gfx.DrawString(row.ToString("X") + "x", labelFont, XBrushes.DarkGray, x, y); for (int clm = 0; clm < 16; clm++) { x += dx; string glyph = encoding.GetString(new byte[1]{Convert.ToByte(row * 16 + clm)}); glyph += "!"; XSize size = gfx.MeasureString(glyph, font); gfx.DrawRectangle(XBrushes.LightGray, x, y - size.Height + descent, size.Width, size.Height); gfx.DrawRectangle(lighter, x, y - size.Height + descent, size.Width, leading); gfx.DrawRectangle(lighter, x, y, size.Width, descent); gfx.DrawString(glyph, font, XBrushes.Black, x, y); } } }
public static void DrawString(XGraphics gfx, string text, XFont font, XRect rect, Alignment alignment) { var size = gfx.MeasureString(text, font, XStringFormats.Center); switch (alignment) { case Alignment.Right: rect = new XRect(new XPoint(rect.X + rect.Width - size.Width, rect.Y), new XSize(size.Width, rect.Height)); break; case Alignment.Center: break; default: rect = new XRect(new XPoint(rect.X, rect.Y), new XSize(size.Width, rect.Height)); break; } gfx.DrawString(text, font, XBrushes.Black, rect, XStringFormats.Center); }
public override float Draw(XGraphics gfx, PointF pt, bool dorender) { float acty = 0; foreach (string line in GetLines(gfx)) { float tpos = m_x0, apos = m_x0; SongLineParser par = new SongLineParser(line); while (par.Current != SongLineParser.Token.End) { if (par.Current == SongLineParser.Token.Word) { float wordwi = (float)gfx.MeasureString(par.Data, Options.TextFont).Width; if (dorender) gfx.DrawString(par.Data, Options.TextFont, Options.TextColor, new PointF(pt.X + tpos, acty + pt.Y + Options.ChordHeight), XStringFormat.TopLeft); tpos += wordwi; } if (par.Current == SongLineParser.Token.Space) { tpos += Options.HTextSpace; } if (par.Current == SongLineParser.Token.Chord) { if (tpos < apos) tpos = apos; // aby nebyly 2 akordy pres sebe apos = tpos; float chordwi = (float)gfx.MeasureString(par.Data, Options.ChordFont).Width; if (dorender) gfx.DrawString(par.Data, Options.ChordFont, Options.ChordColor, new PointF(pt.X + apos, acty + pt.Y), XStringFormat.TopLeft); apos += chordwi + Options.HChordSpace; } par.Read(); } acty += Options.ChordHeight + Options.TextHeight; } DrawLabel(gfx, pt, Options.ChordHeight + Options.TextHeight); return acty; }
private XPoint CalculatePosition(PdfPage page, XGraphics gfx, XFont font, string text, double relativeX, double relativeY, HorizontalAlignment horizontal, VerticalAlignment vertical) { XSize size = gfx.MeasureString(text, font); if (!ShouldHandleOrientation(page)) { XPoint position = new XPoint(); position.X = page.Width * relativeX; position.Y = page.Height * relativeY; if (horizontal == HorizontalAlignment.Center) position.X -= size.Width / 2; if (horizontal == HorizontalAlignment.Right) position.X -= size.Width; if (vertical == VerticalAlignment.Center) position.Y += size.Height / 2; if (vertical == VerticalAlignment.Top) position.Y += size.Height; return position; } else { XPoint position = new XPoint(); position.X = page.Width * (1 - relativeY); position.Y = page.Height * relativeX; if (horizontal == HorizontalAlignment.Center) position.Y -= size.Width / 2; if (horizontal == HorizontalAlignment.Right) position.Y -= size.Width; if (vertical == VerticalAlignment.Center) position.X -= size.Height / 2; if (vertical == VerticalAlignment.Top) position.X -= size.Height; return position; } }
/* * Draws the text in the top right corner and returns a new rect with reduced hight that fills the rest of the rect. */ public static XRect DrawStringTopRight(XGraphics gfx, string text, XFont font, XRect rect) { if (text == null) text = string.Empty; XSize size = gfx.MeasureString(text, font, XStringFormats.TopLeft); XRect topRight = new XRect(rect.Right - size.Width, rect.Top, size.Width, size.Height); gfx.DrawString(text, font, XBrushes.Black, topRight, XStringFormats.TopLeft); return new XRect(rect.Left, rect.Top + size.Height, rect.Width, rect.Height); }
/* * Draws the text in the bottom right corner at an offset from the bottom. */ public static void DrawStringBottomRight(XGraphics gfx, string text, XFont font, XRect rect, double offset) { if (text == null) text = string.Empty; XSize size = gfx.MeasureString(text, font, XStringFormats.TopLeft); XRect bottomRight = new XRect(rect.Right - size.Width, rect.Bottom - size.Height - offset, size.Width, size.Height); gfx.DrawString(text, font, XBrushes.Black, bottomRight, XStringFormats.TopLeft); }
private static void CheckWidth(XGraphics gfx, XFont font, XRect rect, string text) { if (gfx.MeasureString(text, font).Width > rect.Width) throw new Exception("Uh oh."); }
private static int CalculateFontSize(string text, RectangleF adjustedBounds, XGraphics gfx) { int fontSizeGuess = Math.Max(1, (int)(adjustedBounds.Height)); var measuredBoundsForGuess = gfx.MeasureString(text, new XFont("Times New Roman", fontSizeGuess, XFontStyle.Regular)); double adjustmentFactor = adjustedBounds.Width / measuredBoundsForGuess.Width; int adjustedFontSize = Math.Max(1, (int)Math.Round(fontSizeGuess * adjustmentFactor)); return adjustedFontSize; }
private void RebuildCachedLayout(XGraphics graphics, Font font, ref Vector pos, ref Vector size, XStringFormat baseFormat) { // for diagnostic purposes ++s_rebuildCount; // store current settings to help us tell if we need a rebuild next time around m_requestedFormat = new XStringFormat(); m_requestedFormat.Alignment = baseFormat.Alignment; m_requestedFormat.FormatFlags = baseFormat.FormatFlags; m_requestedFormat.LineAlignment = baseFormat.LineAlignment; m_actualFormat = new XStringFormat(); m_actualFormat.Alignment = baseFormat.Alignment; m_actualFormat.FormatFlags = baseFormat.FormatFlags; m_actualFormat.LineAlignment = baseFormat.LineAlignment; m_pos = pos; m_size = size; var text = m_text; if (text.IndexOf('\n') == -1 && size.X > 0 && size.Y > 0 && graphics.MeasureString(text, font).Width > size.X) { // wrap single-line text to fit in rectangle // measure a space, countering the APIs unwillingness to measure spaces var spaceLength = (float)(graphics.MeasureString("M M", font).Width - graphics.MeasureString("M", font).Width * 2); var words = new List<Word>(); foreach (var word in text.Split(' ')) { if (words.Count != 0) { words.Add(new Word(" ", spaceLength)); } words.Add(new Word(word, (float)graphics.MeasureString(word, font).Width)); } var lineLength = 0.0f; var total = string.Empty; var line = string.Empty; foreach (var word in words) { if (word.Text != " " && word.Length > Math.Max(0, size.X - lineLength) && lineLength > 0) { if (line.Length > 0) { if (total.Length > 0) { total += "\n"; } total += line; lineLength = word.Length + spaceLength; line = word.Text; } } else { line += word.Text; lineLength += word.Length + spaceLength; } } if (line.Length > 0) { if (total.Length > 0) { total += "\n"; } total += line; } text = total; } m_lineHeight = font.GetHeight(); m_lines.Clear(); m_lines.AddRange(text.Split('\n')); switch (m_actualFormat.LineAlignment) { case XLineAlignment.Near: default: m_origin = pos; m_delta = new Vector(0, m_lineHeight); break; case XLineAlignment.Far: m_origin = new Vector(pos.X, pos.Y + size.Y - m_lineHeight); if (size.Y > 0) { var count = m_lines.Count; while (m_origin.Y - m_lineHeight >= pos.Y && --count > 0) { m_origin.Y -= m_lineHeight; } } else { m_origin.Y -= (m_lines.Count - 1) * m_lineHeight; } m_delta = new Vector(0, m_lineHeight); break; case XLineAlignment.Center: m_origin = new Vector(pos.X, pos.Y + size.Y / 2 - (m_lines.Count - 1) * m_lineHeight / 2 - m_lineHeight / 2); m_delta = new Vector(0, m_lineHeight); break; } m_actualFormat.LineAlignment = XLineAlignment.Near; switch (m_actualFormat.Alignment) { case XStringAlignment.Far: m_origin.X = pos.X + size.X; break; case XStringAlignment.Center: m_origin.X = pos.X + size.X / 2; break; } }
public void DrawName(XGraphics graphics, RectangleF rect, MapOptions options, XFont font, XBrush textBrush, LabelStyle labelStyle) { if (graphics == null) throw new ArgumentNullException("graphics"); RectangleF bounds = TransformedBounds; if (bounds.IntersectsWith(rect)) { if (Name != null) { string str = Name; if (labelStyle.Uppercase) str = str.ToUpperInvariant(); PointF pos = NamePosition;// PointF( bounds.Left + bounds.Width / 2, bounds.Top + bounds.Height / 2 ); using (RenderUtil.SaveState(graphics)) { XMatrix matrix = new XMatrix(); matrix.TranslatePrepend(pos.X, pos.Y); matrix.ScalePrepend(1.0f / Astrometrics.ParsecScaleX, 1.0f / Astrometrics.ParsecScaleY); matrix.RotatePrepend(-labelStyle.Rotation); // Rotate it graphics.MultiplyTransform(matrix, XMatrixOrder.Prepend); XSize size = graphics.MeasureString(str, font); graphics.TranslateTransform(-size.Width / 2, -size.Height / 2); // Center the text RectangleF textBounds = new RectangleF(0, 0, (float)size.Width, (float)size.Height * 2); // *2 or it gets cut off at high sizes XTextFormatter tf = new XTextFormatter(graphics); tf.Alignment = XParagraphAlignment.Center; tf.DrawString(str, font, textBrush, textBounds); } } } }
private string GetCellText(Cell cell, XGraphics gfx) { var text = string.Empty; var size = gfx.MeasureString(cell.Text, cell.font, XStringFormats.Center); var parts = cell.Text.Split(new char[]{' '}, StringSplitOptions.RemoveEmptyEntries); while (parts.Length > 0) { int i; for (i = parts.Length; i > 0 && size.Width > cell.width; --i) { size = gfx.MeasureString(String.Join(" ", parts.Take(i)), cell.font, XStringFormats.Center); } text += String.Join(" ", parts.Take(i)) + '\n'; parts = parts.Skip(i).ToArray(); } return (text != string.Empty && text.Last() == '\n') ? text.Substring(0, text.Length - 1) : text; }
private XUnit GetCellHeight(Cell cell, XGraphics gfx) { if (cell.height != XUnit.Zero) return cell.height; else return gfx.MeasureString(GetCellText(cell, gfx), cell.font, XStringFormats.Center).Height; }
private void PrintQuoteDetails(XGraphics gfx, XFont font) { try { int xStartDetailRect = 80; int yStartDetailRect = 400; int widthDetailRect = 1100; int heightDetailRect = 700; int heightHeaderRect = 50; int xLineColumn = 150; int xQuantityColumn = 200; int xDescriptionColumn = 790; int xDimensionColumn = 920; int xSqFtColumn = 980; int xUnitPriceColumn = 1080; int xTotalColumn = 1180; XPen pen = new XPen(XColors.Black, 1); XRect detailsRect = new XRect(xStartDetailRect, yStartDetailRect, widthDetailRect, heightDetailRect); gfx.DrawRectangle(pen, detailsRect); XStringFormat format = new XStringFormat(); XRect headerRect = new XRect(xStartDetailRect, yStartDetailRect, widthDetailRect, heightHeaderRect); gfx.DrawRectangle(pen, XBrushes.Gray, headerRect); gfx.DrawLine(XPens.Black, xLineColumn, yStartDetailRect, xLineColumn, yStartDetailRect + detailsRect.Height); gfx.DrawLine(XPens.Black, xQuantityColumn, yStartDetailRect, xQuantityColumn, yStartDetailRect + detailsRect.Height); gfx.DrawLine(XPens.Black, xDescriptionColumn, yStartDetailRect, xDescriptionColumn, yStartDetailRect + detailsRect.Height); gfx.DrawLine(XPens.Black, xDimensionColumn, yStartDetailRect, xDimensionColumn, yStartDetailRect + detailsRect.Height); gfx.DrawLine(XPens.Black, xSqFtColumn, yStartDetailRect, xSqFtColumn, yStartDetailRect + detailsRect.Height); gfx.DrawLine(XPens.Black, xUnitPriceColumn, yStartDetailRect, xUnitPriceColumn, yStartDetailRect + detailsRect.Height); gfx.DrawLine(XPens.Black, xTotalColumn, yStartDetailRect, xTotalColumn, yStartDetailRect + detailsRect.Height); XBrush brush = XBrushes.White; gfx.DrawString("Line No.", font, brush, new XRect(xStartDetailRect + 15, yStartDetailRect + 15, xLineColumn, heightHeaderRect), format); gfx.DrawString("Qty", font, brush, new XRect(xLineColumn + 15, yStartDetailRect + 15, xQuantityColumn, heightHeaderRect), format); gfx.DrawString("Description", font, brush, new XRect(xQuantityColumn + 65, yStartDetailRect + 15, xDescriptionColumn, heightHeaderRect), format); gfx.DrawString("Dimension (in)", font, brush, new XRect(xDescriptionColumn + 15, yStartDetailRect + 15, xDimensionColumn, heightHeaderRect), format); gfx.DrawString("Sq.Ft.", font, brush, new XRect(xDimensionColumn + 15, yStartDetailRect + 15, xSqFtColumn, heightHeaderRect), format); gfx.DrawString("Price/Pc ($)", font, brush, new XRect(xSqFtColumn + 15, yStartDetailRect + 15, xUnitPriceColumn, heightHeaderRect), format); gfx.DrawString("Total ($)", font, brush, new XRect(xUnitPriceColumn + 15, yStartDetailRect + 15, xTotalColumn, heightHeaderRect), format); int yQuoteItemOffset = yStartDetailRect + 45; int yOffset = 20; brush = XBrushes.Black; XTextFormatter tf = new XTextFormatter(gfx); //gfx.DrawRectangle(XBrushes.SeaShell, rect); //tf.Alignment = ParagraphAlignment.Left; XRect rect; foreach (QuoteGridEntity selectedLineItem in allQuoteData) { if (selectedLineItem == null || selectedLineItem.Description == null || selectedLineItem.Dimension == null) continue; XSize size = gfx.MeasureString(selectedLineItem.Description, font); gfx.DrawString(selectedLineItem.LineID.ToString(), font, brush, new XRect(xStartDetailRect + 40, yQuoteItemOffset + yOffset, xLineColumn, heightHeaderRect), format); gfx.DrawString(selectedLineItem.Quantity.ToString(), font, brush, new XRect(xLineColumn + 25, yQuoteItemOffset + yOffset, xQuantityColumn, heightHeaderRect), format); rect = new XRect(xQuantityColumn + 15, yQuoteItemOffset + yOffset, xDescriptionColumn, heightHeaderRect + 100); tf.DrawString(selectedLineItem.Description, font, XBrushes.Black, rect, XStringFormats.TopLeft); //gfx.DrawString(selectedLineItem.Description, font, brush, new XRect(xQuantityColumn + 15, yQuoteItemOffset + yOffset, xDescriptionColumn, heightHeaderRect + size.Height), format); gfx.DrawString(selectedLineItem.Dimension, font, brush, new XRect(xDescriptionColumn + 15, yQuoteItemOffset + yOffset, xDimensionColumn, heightHeaderRect), format); gfx.DrawString(selectedLineItem.TotalSqFt.ToString("0.00"), font, brush, new XRect(xDimensionColumn + 15, yQuoteItemOffset + yOffset, xSqFtColumn, heightHeaderRect), format); gfx.DrawString(selectedLineItem.UnitPrice, font, brush, new XRect(xSqFtColumn + 15, yQuoteItemOffset + yOffset, xUnitPriceColumn, heightHeaderRect), format); gfx.DrawString(double.Parse(selectedLineItem.Total).ToString("0.00"), font, brush, new XRect(xUnitPriceColumn + 15, yQuoteItemOffset + yOffset, xTotalColumn, heightHeaderRect), format); yQuoteItemOffset += 50; } } catch (Exception ex) { Logger.LogException(ex); } }
public void Render(XGraphics graphics) { this.graphics = graphics; solidBrush = new XSolidBrush(); pen = new XPen(XColor.Empty); List<Timer> timers = new List<Timer>(); using (var fonts = new FontCache(styles)) { #region resources lock (s_imageInitLock) { if (styles.showNebulaBackground && s_nebulaImage == null) s_nebulaImage = XImage.FromFile(resourceManager.Server.MapPath(@"~/res/Candy/Nebula.png")); if (styles.showRiftOverlay && s_riftImage == null) s_riftImage = new ImageHolder(Image.FromFile(resourceManager.Server.MapPath(@"~/res/Candy/Rifts.png"))); if (styles.showGalaxyBackground && s_galaxyImage == null) { // TODO: Don't load both unless necessary s_galaxyImage = new ImageHolder(Image.FromFile(resourceManager.Server.MapPath(@"~/res/Candy/Galaxy.png"))); s_galaxyImageGray = new ImageHolder(Image.FromFile(resourceManager.Server.MapPath(@"~/res/Candy/Galaxy_Gray.png"))); } if (styles.useWorldImages && s_worldImages == null) { s_worldImages = new Dictionary<string, XImage> { { "Hyd0", XImage.FromFile(resourceManager.Server.MapPath(@"~/res/Candy/Hyd0.png")) }, { "Hyd1", XImage.FromFile(resourceManager.Server.MapPath(@"~/res/Candy/Hyd1.png")) }, { "Hyd2", XImage.FromFile(resourceManager.Server.MapPath(@"~/res/Candy/Hyd2.png")) }, { "Hyd3", XImage.FromFile(resourceManager.Server.MapPath(@"~/res/Candy/Hyd3.png")) }, { "Hyd4", XImage.FromFile(resourceManager.Server.MapPath(@"~/res/Candy/Hyd4.png")) }, { "Hyd5", XImage.FromFile(resourceManager.Server.MapPath(@"~/res/Candy/Hyd5.png")) }, { "Hyd6", XImage.FromFile(resourceManager.Server.MapPath(@"~/res/Candy/Hyd6.png")) }, { "Hyd7", XImage.FromFile(resourceManager.Server.MapPath(@"~/res/Candy/Hyd7.png")) }, { "Hyd8", XImage.FromFile(resourceManager.Server.MapPath(@"~/res/Candy/Hyd8.png")) }, { "Hyd9", XImage.FromFile(resourceManager.Server.MapPath(@"~/res/Candy/Hyd9.png")) }, { "HydA", XImage.FromFile(resourceManager.Server.MapPath(@"~/res/Candy/HydA.png")) }, { "Belt", XImage.FromFile(resourceManager.Server.MapPath(@"~/res/Candy/Belt.png")) } }; } if (Silly && s_sillyImageColor == null) { // Happy face c/o http://bighappyfaces.com/ s_sillyImageColor = XImage.FromFile(resourceManager.Server.MapPath(@"~/res/AprilFools/Starburst.png")); s_sillyImageGray = XImage.FromFile(resourceManager.Server.MapPath(@"~/res/AprilFools/Starburst_Gray.png")); } } #endregion timers.Add(new Timer("preload")); ////////////////////////////////////////////////////////////// // // Image-Space Rendering // ////////////////////////////////////////////////////////////// using (RenderUtil.SaveState(graphics)) { if (ClipPath != null) { graphics.MultiplyTransform(imageSpaceToWorldSpace); graphics.IntersectClip(ClipPath); graphics.MultiplyTransform(worldSpaceToImageSpace); } // Fill graphics.SmoothingMode = XSmoothingMode.HighSpeed; solidBrush.Color = styles.backgroundColor; graphics.DrawRectangle(solidBrush, 0, 0, tileSize.Width, tileSize.Height); } timers.Add(new Timer("imagespace")); ////////////////////////////////////////////////////////////// // // World-Space Rendering // ////////////////////////////////////////////////////////////// graphics.MultiplyTransform(imageSpaceToWorldSpace); using (RenderUtil.SaveState(graphics)) { //------------------------------------------------------------ // Explicit Clipping //------------------------------------------------------------ if (ClipPath != null) graphics.IntersectClip(ClipPath); //------------------------------------------------------------ // Background //------------------------------------------------------------ timers.Add(new Timer("prep")); #region nebula-background //------------------------------------------------------------ // Local background (Nebula) //------------------------------------------------------------ // NOTE: Since alpha texture brushes aren't supported without // creating a new image (slow!) we render the local background // first, then overlay the deep background over it, for // basically the same effect since the alphas sum to 1. if (styles.showNebulaBackground) DrawNebulaBackground(); timers.Add(new Timer("background (nebula)")); #endregion #region galaxy-background //------------------------------------------------------------ // Deep background (Galaxy) //------------------------------------------------------------ if (styles.showGalaxyBackground && styles.deepBackgroundOpacity > 0f && galacticBounds.IntersectsWith(tileRect)) { using (RenderUtil.SaveState(graphics)) { graphics.MultiplyTransform(xformLinehanToMikesh); ImageHolder galaxyImage = styles.lightBackground ? s_galaxyImageGray : s_galaxyImage; RenderUtil.DrawImageAlpha(graphics, styles.deepBackgroundOpacity, galaxyImage, galaxyImageRect); } } timers.Add(new Timer("background (galaxy)")); #endregion #region pseudorandom-stars //------------------------------------------------------------ // Pseudo-Random Stars //------------------------------------------------------------ if (styles.pseudoRandomStars.visible) DrawPseudoRandomStars(); timers.Add(new Timer("pseudorandom")); #endregion #region rifts //------------------------------------------------------------ // Rifts in Charted Space //------------------------------------------------------------ if (styles.showRiftOverlay && styles.riftOpacity > 0f) RenderUtil.DrawImageAlpha(graphics, styles.riftOpacity, s_riftImage, riftImageRect); timers.Add(new Timer("rifts")); #endregion #region april-fools //------------------------------------------------------------ // April Fool's Day //------------------------------------------------------------ if (Silly) { using (RenderUtil.SaveState(graphics)) { // Render in image-space graphics.MultiplyTransform(worldSpaceToImageSpace); XImage sillyImage = styles.grayscale ? s_sillyImageGray : s_sillyImageColor; lock (sillyImage) { graphics.DrawImage(sillyImage, 0, 0, tileSize.Width, tileSize.Height); } } timers.Add(new Timer("silly")); } #endregion //------------------------------------------------------------ // Foreground //------------------------------------------------------------ #region macro-borders //------------------------------------------------------------ // Macro: Borders object //------------------------------------------------------------ if (styles.macroBorders.visible) { styles.macroBorders.pen.Apply(ref pen); graphics.SmoothingMode = XSmoothingMode.AntiAlias; foreach (var vec in borderFiles .Select(file => resourceManager.GetXmlFileObject(file, typeof(VectorObject))) .OfType<VectorObject>() .Where(vec => (vec.MapOptions & options & MapOptions.BordersMask) != 0)) { vec.Draw(graphics, tileRect, pen); } } timers.Add(new Timer("macro-borders")); #endregion #region macro-routes //------------------------------------------------------------ // Macro: Route object //------------------------------------------------------------ if (styles.macroRoutes.visible) { styles.macroRoutes.pen.Apply(ref pen); graphics.SmoothingMode = XSmoothingMode.AntiAlias; foreach (var vec in routeFiles .Select(file => resourceManager.GetXmlFileObject(file, typeof(VectorObject))) .OfType<VectorObject>() .Where(vec => (vec.MapOptions & options & MapOptions.BordersMask) != 0)) { vec.Draw(graphics, tileRect, pen); } } timers.Add(new Timer("macro-routes")); #endregion #region sector-grid //------------------------------------------------------------ // Sector Grid //------------------------------------------------------------ graphics.SmoothingMode = XSmoothingMode.HighSpeed; if (styles.sectorGrid.visible) { const int gridSlop = 10; styles.sectorGrid.pen.Apply(ref pen); for (float h = ((float)(Math.Floor((tileRect.Left) / Astrometrics.SectorWidth) - 1) - Astrometrics.ReferenceSector.X) * Astrometrics.SectorWidth - Astrometrics.ReferenceHex.X; h <= tileRect.Right + Astrometrics.SectorWidth; h += Astrometrics.SectorWidth) graphics.DrawLine(pen, h, tileRect.Top - gridSlop, h, tileRect.Bottom + gridSlop); for (float v = ((float)(Math.Floor((tileRect.Top) / Astrometrics.SectorHeight) - 1) - Astrometrics.ReferenceSector.Y) * Astrometrics.SectorHeight - Astrometrics.ReferenceHex.Y; v <= tileRect.Bottom + Astrometrics.SectorHeight; v += Astrometrics.SectorHeight) graphics.DrawLine(pen, tileRect.Left - gridSlop, v, tileRect.Right + gridSlop, v); } timers.Add(new Timer("sector grid")); #endregion #region subsector-grid //------------------------------------------------------------ // Subsector Grid //------------------------------------------------------------ graphics.SmoothingMode = XSmoothingMode.HighSpeed; if (styles.subsectorGrid.visible) { const int gridSlop = 10; styles.subsectorGrid.pen.Apply(ref pen); int hmin = (int)Math.Floor(tileRect.Left / Astrometrics.SubsectorWidth) - 1 - Astrometrics.ReferenceSector.X, hmax = (int)Math.Ceiling((tileRect.Right + Astrometrics.SubsectorWidth + Astrometrics.ReferenceHex.X) / Astrometrics.SubsectorWidth); for (int hi = hmin; hi <= hmax; ++hi) { if (hi % 4 == 0) continue; float h = hi * Astrometrics.SubsectorWidth - Astrometrics.ReferenceHex.X; graphics.DrawLine(pen, h, tileRect.Top - gridSlop, h, tileRect.Bottom + gridSlop); } int vmin = (int)Math.Floor(tileRect.Top / Astrometrics.SubsectorHeight) - 1 - Astrometrics.ReferenceSector.Y, vmax = (int)Math.Ceiling((tileRect.Bottom + Astrometrics.SubsectorHeight + Astrometrics.ReferenceHex.Y) / Astrometrics.SubsectorHeight); for (int vi = vmin; vi <= vmax; ++vi) { if (vi % 4 == 0) continue; float v = vi * Astrometrics.SubsectorHeight - Astrometrics.ReferenceHex.Y; graphics.DrawLine(pen, tileRect.Left - gridSlop, v, tileRect.Right + gridSlop, v); } } timers.Add(new Timer("subsector grid")); #endregion #region parsec-grid //------------------------------------------------------------ // Parsec Grid //------------------------------------------------------------ // TODO: Optimize - timers indicate this is slow graphics.SmoothingMode = XSmoothingMode.HighQuality; if (styles.parsecGrid.visible) DrawParsecGrid(); timers.Add(new Timer("parsec grid")); #endregion #region subsector-names //------------------------------------------------------------ // Subsector Names //------------------------------------------------------------ if (styles.subsectorNames.visible) { solidBrush.Color = styles.subsectorNames.textColor; foreach (Sector sector in selector.Sectors) { for (int i = 0; i < 16; i++) { Subsector ss = sector.Subsector(i); if (ss == null || string.IsNullOrEmpty(ss.Name)) continue; Point center = sector.SubsectorCenter(i); RenderUtil.DrawLabel(graphics, ss.Name, center, styles.subsectorNames.Font, solidBrush, styles.subsectorNames.textStyle); } } } timers.Add(new Timer("subsector names")); #endregion #region micro-borders //------------------------------------------------------------ // Micro: Borders //------------------------------------------------------------ if (styles.microBorders.visible) { if (styles.fillMicroBorders) DrawMicroBorders(BorderLayer.Fill); DrawMicroBorders(BorderLayer.Stroke); } timers.Add(new Timer("micro-borders")); #endregion #region micro-routes //------------------------------------------------------------ // Micro: Routes //------------------------------------------------------------ if (styles.microRoutes.visible) DrawRoutes(); timers.Add(new Timer("micro-routes")); #endregion #region micro-border-labels //------------------------------------------------------------ // Micro: Border Labels & Explicit Labels //------------------------------------------------------------ if (styles.showMicroNames) DrawLabels(); timers.Add(new Timer("micro-border labels")); #endregion #region sector-names //------------------------------------------------------------ // Sector Names //------------------------------------------------------------ if (styles.showSomeSectorNames || styles.showAllSectorNames) { foreach (Sector sector in selector.Sectors .Where(sector => styles.showAllSectorNames || (styles.showSomeSectorNames && sector.Selected)) .Where(sector => sector.Names.Any() || sector.Label != null)) { solidBrush.Color = styles.sectorName.textColor; string name = sector.Label ?? sector.Names[0].Text; RenderUtil.DrawLabel(graphics, name, sector.Center, styles.sectorName.Font, solidBrush, styles.sectorName.textStyle); } } timers.Add(new Timer("sector names")); #endregion #region government-rift-names //------------------------------------------------------------ // Macro: Government / Rift / Route Names //------------------------------------------------------------ if (styles.macroNames.visible) DrawMacroNames(); timers.Add(new Timer("macro names")); #endregion #region capitals-homeworlds //------------------------------------------------------------ // Macro: Capitals & Home Worlds //------------------------------------------------------------ if (styles.capitals.visible && (options & MapOptions.WorldsMask) != 0) { WorldObjectCollection worlds = resourceManager.GetXmlFileObject(@"~/res/Worlds.xml", typeof(WorldObjectCollection)) as WorldObjectCollection; if (worlds != null && worlds.Worlds != null) { solidBrush.Color = styles.capitals.textColor; foreach (WorldObject world in worlds.Worlds.Where(world => (world.MapOptions & options) != 0)) { world.Paint(graphics, styles.capitals.fillColor, solidBrush, styles.macroNames.SmallFont); } } } timers.Add(new Timer("macro worlds")); #endregion #region mega-names //------------------------------------------------------------ // Mega: Galaxy-Scale Labels //------------------------------------------------------------ if (styles.megaNames.visible) { solidBrush.Color = styles.megaNames.textColor; foreach (var label in megaLabels) { using (RenderUtil.SaveState(graphics)) { XMatrix matrix = new XMatrix(); matrix.ScalePrepend(1.0f / Astrometrics.ParsecScaleX, 1.0f / Astrometrics.ParsecScaleY); matrix.TranslatePrepend(label.position.X, label.position.Y); graphics.MultiplyTransform(matrix, XMatrixOrder.Prepend); XFont font = label.minor ? styles.megaNames.SmallFont : styles.megaNames.Font; XSize size = graphics.MeasureString(label.text, font); graphics.TranslateTransform(-size.Width / 2, -size.Height / 2); // Center the text RectangleF textBounds = new RectangleF(0, 0, (float)size.Width * 1.01f, (float)size.Height * 2); // *2 or it gets cut off at high sizes XTextFormatter formatter = new XTextFormatter(graphics); formatter.Alignment = XParagraphAlignment.Center; formatter.DrawString(label.text, font, solidBrush, textBounds); } } } timers.Add(new Timer("mega names")); #endregion } // End of clipping, so world names are not clipped in jumpmaps. #region worlds //------------------------------------------------------------ // Worlds //------------------------------------------------------------ if (styles.worlds.visible) { // TODO: selector may be expensive foreach (World world in selector.Worlds) { DrawWorld(fonts, world, WorldLayer.Background); } foreach (World world in selector.Worlds) { DrawWorld(fonts, world, WorldLayer.Foreground); } } timers.Add(new Timer("worlds")); #endregion //------------------------------------------------------------ // Overlays //------------------------------------------------------------ #region droyne //------------------------------------------------------------ // Droyne/Chirper Worlds //------------------------------------------------------------ if (styles.droyneWorlds.visible) { solidBrush.Color = styles.droyneWorlds.textColor; foreach (World world in selector.Worlds) { bool droyne = world.HasCodePrefix("Droy") != null; bool chirpers = world.HasCodePrefix("Chir") != null; if (droyne || chirpers) { string glyph = droyne ? "\u2605" : "\u2606"; PointF center = Astrometrics.HexToCenter(world.Coordinates); using (RenderUtil.SaveState(graphics)) { XMatrix matrix = new XMatrix(); matrix.TranslatePrepend(center.X, center.Y); matrix.ScalePrepend(1 / Astrometrics.ParsecScaleX, 1 / Astrometrics.ParsecScaleY); graphics.MultiplyTransform(matrix, XMatrixOrder.Prepend); graphics.DrawString(glyph, styles.droyneWorlds.Font, solidBrush, 0, 0, RenderUtil.StringFormatCentered); } } } } timers.Add(new Timer("droyne")); #endregion #region unofficial //------------------------------------------------------------ // Unofficial //------------------------------------------------------------ if (styles.dimUnofficialSectors && styles.worlds.visible) { solidBrush.Color = Color.FromArgb(128, styles.backgroundColor); foreach (Sector sector in selector.Sectors .Where(sector => !sector.Tags.Contains("Official") && !sector.Tags.Contains("Preserve") && !sector.Tags.Contains("InReview"))) graphics.DrawRectangle(solidBrush, sector.Bounds); } timers.Add(new Timer("unofficial")); #endregion #region timing #if SHOW_TIMING using( RenderUtil.SaveState( graphics ) ) { XFont font = new XFont( FontFamily.GenericSansSerif, 12, XFontStyle.Regular, new XPdfFontOptions(PdfSharp.Pdf.PdfFontEncoding.Unicode) ); graphics.MultiplyTransform( worldSpaceToImageSpace ); double cursorX = 20.0, cursorY = 20.0; DateTime last = dtStart; foreach( Timer s in timers ) { TimeSpan ts = s.dt - last; last = s.dt; for( int dx = -1; dx <= 1; ++dx ) { for( int dy = -1; dy <= 1; ++dy ) { graphics.DrawString( String.Format( "{0} {1}", Math.Round( ts.TotalMilliseconds ), s.label ), font, XBrushes.Black, cursorX + dx, cursorY + dy ); } } graphics.DrawString( String.Format("{0} {1}", Math.Round(ts.TotalMilliseconds), s.label), font, XBrushes.Yellow, cursorX, cursorY ); cursorY += 14; } } #endif #endregion } }
private void PrintQuoteDetails(XGraphics gfx, XFont font, int startLineItem, int numberOfLineItems, bool isFirstPageOfQuote, bool isMiddlePageOfQuote, bool isLastPage) { try { int xStartDetailRect = 10; int yStartDetailRect = 400; if (startLineItem != 0) { yStartDetailRect = 40; } int widthDetailRect = 1180; int heightDetailRect = 950; if (isFirstPageOfQuote == true) { heightDetailRect = 1150; } else if (isMiddlePageOfQuote == true) { heightDetailRect = 1550; } else if (isLastPage == true) { heightDetailRect = 1350; } int heightHeaderRect = 50; int xLineColumn = 90; int xQuantityColumn = 150; int xDescriptionColumn = 790; int xDimensionColumn = 930; int xSqFtColumn = 990; int xUnitPriceColumn = 1080; int xTotalColumn = 1190; XPen pen = new XPen(XColors.Black, 1); XRect detailsRect = new XRect(xStartDetailRect, yStartDetailRect, widthDetailRect, heightDetailRect); gfx.DrawRectangle(pen, detailsRect); XStringFormat format = new XStringFormat(); XRect headerRect = new XRect(xStartDetailRect, yStartDetailRect, widthDetailRect, heightHeaderRect); gfx.DrawRectangle(pen, XBrushes.Gray, headerRect); gfx.DrawLine(XPens.Black, xLineColumn, yStartDetailRect, xLineColumn, yStartDetailRect + detailsRect.Height); gfx.DrawLine(XPens.Black, xQuantityColumn, yStartDetailRect, xQuantityColumn, yStartDetailRect + detailsRect.Height); gfx.DrawLine(XPens.Black, xDescriptionColumn, yStartDetailRect, xDescriptionColumn, yStartDetailRect + detailsRect.Height); gfx.DrawLine(XPens.Black, xDimensionColumn, yStartDetailRect, xDimensionColumn, yStartDetailRect + detailsRect.Height); gfx.DrawLine(XPens.Black, xSqFtColumn, yStartDetailRect, xSqFtColumn, yStartDetailRect + detailsRect.Height); gfx.DrawLine(XPens.Black, xUnitPriceColumn, yStartDetailRect, xUnitPriceColumn, yStartDetailRect + detailsRect.Height); gfx.DrawLine(XPens.Black, xTotalColumn, yStartDetailRect, xTotalColumn, yStartDetailRect + detailsRect.Height); XBrush brush = XBrushes.White; gfx.DrawString("Line No.", font, brush, new XRect(xStartDetailRect + 15, yStartDetailRect + 15, xLineColumn, heightHeaderRect), format); gfx.DrawString("Qty", font, brush, new XRect(xLineColumn + 15, yStartDetailRect + 15, xQuantityColumn, heightHeaderRect), format); gfx.DrawString("Description", font, brush, new XRect(xQuantityColumn + 65, yStartDetailRect + 15, xDescriptionColumn, heightHeaderRect), format); gfx.DrawString("Dimension (in)", font, brush, new XRect(xDescriptionColumn + 15, yStartDetailRect + 15, xDimensionColumn, heightHeaderRect), format); gfx.DrawString("Sq.Ft.", font, brush, new XRect(xDimensionColumn + 15, yStartDetailRect + 15, xSqFtColumn, heightHeaderRect), format); gfx.DrawString("Price/Pc($)", font, brush, new XRect(xSqFtColumn + 10, yStartDetailRect + 15, xUnitPriceColumn, heightHeaderRect), format); gfx.DrawString("Total ($)", font, brush, new XRect(xUnitPriceColumn + 15, yStartDetailRect + 15, xTotalColumn, heightHeaderRect), format); int yQuoteItemOffset = yStartDetailRect + 45; int yOffset = 20; brush = XBrushes.Black; XTextFormatter tf = new XTextFormatter(gfx); //gfx.DrawRectangle(XBrushes.SeaShell, rect); //tf.Alignment = ParagraphAlignment.Left; XRect rect; int counter = 0; foreach (QuoteGridEntity selectedLineItem in allQuoteData) { // Start printing from specific line item if (startLineItem != 0 && counter < startLineItem) { counter++; continue; } // Print only number of line items provided if (counter >= numberOfLineItems) { break; } counter++; if (selectedLineItem == null || selectedLineItem.Description == null || selectedLineItem.Dimension == null) continue; XSize size = gfx.MeasureString(selectedLineItem.Description, font); gfx.DrawString(selectedLineItem.LineID.ToString(), font, brush, new XRect(xStartDetailRect + 40, yQuoteItemOffset + yOffset, xLineColumn, heightHeaderRect), format); gfx.DrawString(selectedLineItem.Quantity.ToString(), font, brush, new XRect(xLineColumn + 25, yQuoteItemOffset + yOffset, xQuantityColumn, heightHeaderRect), format); rect = new XRect(xQuantityColumn + 15, yQuoteItemOffset + yOffset, xDescriptionColumn - 150, heightHeaderRect + 300); tf.DrawString(selectedLineItem.Description, font, XBrushes.Black, rect, XStringFormats.TopLeft); //gfx.DrawString(selectedLineItem.Description, font, brush, new XRect(xQuantityColumn + 15, yQuoteItemOffset + yOffset, xDescriptionColumn, heightHeaderRect + size.Height), format); gfx.DrawString(selectedLineItem.Dimension, font, brush, new XRect(xDescriptionColumn + 15, yQuoteItemOffset + yOffset, xDimensionColumn, heightHeaderRect), format); gfx.DrawString(selectedLineItem.TotalSqFt.ToString("0.00"), font, brush, new XRect(xDimensionColumn + 15, yQuoteItemOffset + yOffset, xSqFtColumn, heightHeaderRect), format); gfx.DrawString(selectedLineItem.UnitPrice, font, brush, new XRect(xSqFtColumn + 15, yQuoteItemOffset + yOffset, xUnitPriceColumn, heightHeaderRect), format); gfx.DrawString(double.Parse(selectedLineItem.Total).ToString("0.00"), font, brush, new XRect(xUnitPriceColumn + 15, yQuoteItemOffset + yOffset, xTotalColumn, heightHeaderRect), format); yQuoteItemOffset += 80; } } catch (Exception ex) { Logger.LogException(ex); } }
public void Paint(XGraphics graphics, RectangleF rect, MapOptions options, Color dotColor, XBrush labelBrush, XFont labelFont) { if (graphics == null) throw new ArgumentNullException("graphics"); Point pt = Astrometrics.LocationToCoordinates(Location); using (RenderUtil.SaveState(graphics)) { graphics.SmoothingMode = XSmoothingMode.HighSpeed; graphics.TranslateTransform(pt.X, pt.Y); graphics.ScaleTransform(1.0f / Astrometrics.ParsecScaleX, 1.0f / Astrometrics.ParsecScaleY); const float radius = 3; XBrush brush = new XSolidBrush(dotColor); XPen pen = new XPen(dotColor); graphics.DrawEllipse(brush, -radius / 2, -radius / 2, radius, radius); graphics.SmoothingMode = XSmoothingMode.HighQuality; graphics.DrawEllipse(pen, -radius / 2, -radius / 2, radius, radius); XStringFormat format = (LabelBiasX == -1) ? RenderUtil.StringFormatTopRight : (LabelBiasX == 1) ? RenderUtil.StringFormatTopLeft : RenderUtil.StringFormatTopCenter; XSize size = graphics.MeasureString(Name, labelFont); XPoint pos = new XPoint(0, 0); //pos.X += ( LabelBiasX * radius / 2 ) + ( -size.Width * ( 1 - LabelBiasX ) / 2.0f ); pos.Y += (LabelBiasY * radius / 2) + (-size.Height * (1 - LabelBiasY) / 2.0f); pos.X += (LabelBiasX * radius / 2); //pos.Y += ( LabelBiasY * radius / 2 ); graphics.DrawString(Name, labelFont, labelBrush, pos.X, pos.Y, format); } }
static void watermarkprint(XGraphics gfx, PdfPage page, XFont font) { string watermark = "TestME"; // Get the size (in point) of the text XSize size = gfx.MeasureString(watermark, font); // Define a rotation transformation at the center of the page gfx.TranslateTransform(page.Width / 2, page.Height / 2); gfx.RotateTransform(-Math.Atan(page.Height / page.Width) * 180 / Math.PI); gfx.TranslateTransform(-page.Width / 2, -page.Height / 2); // Create a string format XStringFormat format = new XStringFormat(); format.Alignment = XStringAlignment.Near; format.LineAlignment = XLineAlignment.Near; // Create a dimmed red brush XBrush brush = new XSolidBrush(XColor.FromArgb(60, 128, 125, 123)); // Draw the string gfx.DrawString(watermark, font, brush, new XPoint((page.Width - size.Width) / 2, (page.Height - size.Height) / 2), format); }
/// <summary> /// Draw a multi-line string as it would be drawn by GDI+. /// Compensates for issues and draw-vs-PDF differences in PDFsharp. /// </summary> /// <param name="graphics">The graphics with which to draw.</param> /// <param name="text">The text to draw, which may contain line breaks.</param> /// <param name="font">The font with which to draw.</param> /// <param name="brush">The brush with which to draw.</param> /// <param name="pos">The position at which to draw.</param> /// <param name="size">The size to which to limit the drawn text; or Vector.Zero for no limit.</param> /// <param name="format">The string format to use.</param> /// <remarks> /// PDFsharp cannot currently render multi-line text to PDF files; it comes out as single line. /// This method simulates standard Graphics.DrawString() over PDFsharp. /// It always has the effect of StringFormatFlags.LineLimit (which PDFsharp does not support). /// </remarks> public void Draw(XGraphics graphics, Font font, Brush brush, Vector pos, Vector size, XStringFormat format) { // do a quick test to see if text is going to get drawn at the same size as last time; // if so, assume we don't need to recompute our layout for that reason. var sizeChecker = graphics.MeasureString("M q", font); if (sizeChecker != m_sizeChecker || pos != m_pos || m_size != size || m_requestedFormat.Alignment != format.Alignment || m_requestedFormat.LineAlignment != format.LineAlignment || m_requestedFormat.FormatFlags != format.FormatFlags) { m_invalidLayout = true; } m_sizeChecker = sizeChecker; if (m_invalidLayout) { // something vital has changed; rebuild our cached layout data RebuildCachedLayout(graphics, font, ref pos, ref size, format); m_invalidLayout = false; } var state = graphics.Save(); if (size != Vector.Zero) { graphics.IntersectClip(new RectangleF(pos.X, pos.Y, size.X, size.Y)); } // disable smoothing whilst rendering text; // visually this is no different, but is faster var smoothingMode = graphics.SmoothingMode; graphics.SmoothingMode = XSmoothingMode.HighSpeed; var origin = m_origin; for (var index=0; index<m_lines.Count; ++index) { if (size.Y > 0 && size.Y < m_lineHeight) break; // not enough remaining vertical space for a whole line var line = m_lines[index]; graphics.DrawString(line, font, brush, origin.X, origin.Y, m_actualFormat); origin += m_delta; size.Y -= m_lineHeight; } graphics.SmoothingMode = smoothingMode; graphics.Restore(state); }
/* * Draws the text and returns a new rect with reduced height that fits under the text and within the rect. */ public static XRect DrawString(XGraphics gfx, string text, XFont font, XRect rect, XStringFormat format, double maxWidth = 0) { if (text == null) text = string.Empty; if (maxWidth == 0) maxWidth = rect.Width; var lines = text.Split(new char[] { ' ' }, 2); XSize size = gfx.MeasureString(text, font, format); if (size.Width > maxWidth && lines.Count() > 1 && format != XStringFormats.Center) { foreach (var line in lines) rect = DrawString(gfx, line, font, rect, format); return rect; } gfx.DrawString(text, font, XBrushes.Black, rect, format); return new XRect(rect.Left, rect.Top + size.Height, rect.Width, rect.Height - size.Height); }
public static void DrawLabel(XGraphics g, string text, PointF labelPos, XFont font, XBrush brush, LabelStyle labelStyle) { using (RenderUtil.SaveState(g)) { if (labelStyle.Uppercase) text = text.ToUpper(); if (labelStyle.Wrap) text = text.Replace(' ', '\n'); g.TranslateTransform(labelPos.X, labelPos.Y); g.ScaleTransform(1.0f / Astrometrics.ParsecScaleX, 1.0f / Astrometrics.ParsecScaleY); g.TranslateTransform(labelStyle.Translation.X, labelStyle.Translation.Y); g.RotateTransform(labelStyle.Rotation); g.ScaleTransform(labelStyle.Scale.Width, labelStyle.Scale.Height); if (labelStyle.Rotation != 0) g.Graphics.TextRenderingHint = TextRenderingHint.AntiAlias; XSize size = g.MeasureString(text, font); size.Width *= 2; // prevent cut-off e.g. when rotated XRect bounds = new XRect(-size.Width / 2, -size.Height / 2, size.Width, size.Height); XTextFormatter tf = new XTextFormatter(g); tf.Alignment = XParagraphAlignment.Center; tf.DrawString(text, font, brush, bounds); } }
private static void GenerateReferenceId(XGraphics gfx, Trade trade) { var text = "Reference ID: " + trade.TradeId.ToString().ToUpper(); var tf = CreateTextFormatter(gfx); tf.DrawString( text, ConditionsFont, TextBrush, new XRect(PageWidth - Margin - gfx.MeasureString(text, ConditionsFont).Width, PageSizeConverter.ToSize(PageSize).Height - Margin - ConditionsFont.GetHeight(), Width, ConditionsFont.GetHeight()), XStringFormats.TopLeft); }
/// <summary> /// Demonstrates serveral bar code types. /// </summary> public override void RenderPage(XGraphics gfx) { base.RenderPage(gfx); XFont font = new XFont("Verdana", 14, XFontStyle.Bold); string info = "DataMatrix is a fake in the Open Source version!"; XSize size = gfx.MeasureString(info, font); gfx.DrawString(info, font, XBrushes.Firebrick, (600 - size.Width) / 2, 50); //Graphics grfx = gfx.Internals.Graphics; CodeDataMatrix dm = new CodeDataMatrix("test", 26); dm.Size = new XSize(XUnit.FromMillimeter(15), XUnit.FromMillimeter(15)); gfx.DrawMatrixCode(dm, XBrushes.DarkBlue, new XPoint(100, 100)); dm = new CodeDataMatrix("test", 12, 12); dm.Size = new XSize(XUnit.FromMillimeter(15), XUnit.FromMillimeter(15)); gfx.DrawMatrixCode(dm, XBrushes.DarkBlue, new XPoint(300, 100)); dm = new CodeDataMatrix("test", 16, 48); dm.Size = new XSize(XUnit.FromMillimeter(50), XUnit.FromMillimeter(18)); gfx.DrawMatrixCode(dm, XBrushes.DarkBlue, new XPoint(500, 100)); dm = new CodeDataMatrix("0123456789", 52); dm.Size = new XSize(XUnit.FromMillimeter(30), XUnit.FromMillimeter(30)); gfx.DrawMatrixCode(dm, XBrushes.DarkBlue, new XPoint(100, 300)); dm = new CodeDataMatrix("0123456789", 12, 26); dm.Direction = CodeDirection.TopToBottom; dm.Size = new XSize(XUnit.FromMillimeter(14), XUnit.FromMillimeter(7)); gfx.DrawMatrixCode(dm, XBrushes.DarkBlue, new XPoint(300, 300)); dm = new CodeDataMatrix("0123456789", 96); dm.Size = new XSize(XUnit.FromMillimeter(30), XUnit.FromMillimeter(30)); gfx.DrawMatrixCode(dm, XBrushes.DarkBlue, new XPoint(500, 300)); dm = new CodeDataMatrix("www.empira.de", 20); dm.Direction = CodeDirection.BottomToTop; dm.Size = new XSize(XUnit.FromMillimeter(7), XUnit.FromMillimeter(7)); gfx.DrawMatrixCode(dm, XBrushes.DarkBlue, new XPoint(100, 500)); dm = new CodeDataMatrix("www.empira.de", 144, 144, 2); dm.Size = new XSize(XUnit.FromMillimeter(50), XUnit.FromMillimeter(50)); gfx.DrawMatrixCode(dm, XBrushes.DarkBlue, new XPoint(300, 500)); dm = new CodeDataMatrix("www.empira.de", 88); dm.Direction = CodeDirection.RightToLeft; dm.Size = new XSize(XUnit.FromMillimeter(15), XUnit.FromMillimeter(15)); gfx.DrawMatrixCode(dm, XBrushes.DarkBlue, new XPoint(500, 500)); }