/// <summary> /// Kalkuje wielkość obiektu potrzebną do pagehelpera /// </summary> /// <param name="gfx">Kontekst graficzny page'a</param> /// <param name="lastx">X ostatniego wyrenderowanego obiektu</param> /// <param name="_margins">Marginesy strony</param> public void CalculateSize(XGraphics gfx, double lastx, XPoint _margins) { if (height <= 0 || width <= 0) { if (width <= 0) { width = (gfx.PageSize.Width) - (_margins.X * 2); } if (height <= 0) { double wordWidth = 0, lineWidth = 0; string lineWord = "", tempWord = "", wholeWord = ""; for (int i = 0; i <= _text.Length; i++) { if (i < _text.Length) { while (true) { if (_text[i] == ' ') { tempWord += _text[i]; break; } else if (i >= (_text.Length - 1)) { if (i == _text.Length) { tempWord += _text[i]; } break; } else { tempWord += _text[i]; i++; } } } wordWidth = gfx.MeasureString(" " + tempWord, _font).Width; // XGraphics nie liczy szerokości spacji po słowie, ale przed nim już tak. lineWidth = gfx.MeasureString(lineWord, _font).Width; if (lineWidth + wordWidth >= width) { height += _font.GetHeight(gfx); wholeWord += lineWord; lineWord = tempWord; tempWord = ""; } else { lineWord += tempWord; tempWord = ""; } } height += _font.GetHeight(gfx); // Bez tego ostatnia linia nie jest dodawana przez pętlę, bo tekst w niej się mieści. } } }
private void MeasureText(XGraphics gfx, int number) { base.BeginBox(gfx, number, "Measure Text"); XFont xFont = new XFont("Times New Roman", 95.0, XFontStyle.Regular); XSize xSize = gfx.MeasureString("Hallo", xFont); double height = xFont.GetHeight(gfx); int lineSpacing = xFont.FontFamily.GetLineSpacing(XFontStyle.Regular); int cellAscent = xFont.FontFamily.GetCellAscent(XFontStyle.Regular); int cellDescent = xFont.FontFamily.GetCellDescent(XFontStyle.Regular); int num = lineSpacing - cellAscent - cellDescent; double num2 = height * (double)cellAscent / (double)lineSpacing; gfx.DrawRectangle(XBrushes.Bisque, 20.0, 100.0 - num2, xSize.Width, num2); double num3 = height * (double)cellDescent / (double)lineSpacing; gfx.DrawRectangle(XBrushes.LightGreen, 20.0, 100.0, xSize.Width, num3); double height2 = height * (double)num / (double)lineSpacing; gfx.DrawRectangle(XBrushes.Yellow, 20.0, 100.0 + num3, xSize.Width, height2); XColor darkSlateBlue = XColors.DarkSlateBlue; darkSlateBlue.A = 0.6; gfx.DrawString("Hallo", xFont, new XSolidBrush(darkSlateBlue), 20.0, 100.0); base.EndBox(gfx); }
/// <summary> /// Enhanced measure string function for PdfSharp Xgraphics /// wich take to account lineBreaks to calculate the real string /// height in a rectagle /// </summary> /// <param name="gfx"></param> /// <param name="text">Text to measure</param> /// <param name="maxWitdh">Maximum allowed width</param> /// <returns></returns> public static XSize MeasureStringExact(this XGraphics gfx, string content, XFont font, double maxWidth) { //Split by hard line break var contents = content.Split(new List <string> { "\n", "\r\n" }.ToArray(), StringSplitOptions.None); Func <string, XFont, XSize> measPdfSharp = (ct, ft) => { var size = gfx.MeasureString(ct, ft); var lineSpace = font.GetHeight(); var cellSpace = font.FontFamily.GetLineSpacing(ft.Style); var cellLeading = cellSpace - font.FontFamily.GetCellAscent(ft.Style) - font.FontFamily.GetCellDescent(ft.Style); var leading = lineSpace * cellLeading / cellSpace; size.Height += leading; if (size.Width > maxWidth) { var nbLine = gfx.GetSplittedLineCount(ct, ft, maxWidth); size.Height = (nbLine * lineSpace) + leading; size.Width = maxWidth; } return(size); }; var sizes = contents.Select(c => measPdfSharp(c, font)); return(new XSize(sizes.Max(w => w.Width), sizes.Sum(h => h.Height))); }
public void MeasureText(XGraphics gfx, int number) { const XFontStyle style = XFontStyle.Regular; XFont font = new XFont("Times New Roman", 95, style); const string text = "Hallo"; const 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); }
/// <summary> /// print the page to PDF /// </summary> protected void PrintPage() { // first page? then we should store some settings if (CurrentPageNr == 0) { if (FMarginType == eMarginType.ePrintableArea) { // if no printer is installed, use default values FLeftMargin = 0; FTopMargin = 0.1f; FRightMargin = -0.1f; FBottomMargin = 0.1f; FWidth = 8.268333f; FHeight = 11.69333f; } // Calculate the number of lines per page. FLinesPerPage = (float)FHeight / (float)FXDefaultFont.GetHeight() * CurrentLineHeight; if (FNumberOfPages == 0) { // do a dry run without printing but calculate the number of pages StartSimulatePrinting(); int pageCounter = 0; FNumberOfPages = 1; do { pageCounter++; PrintPage(); } while (HasMorePages()); FinishSimulatePrinting(); BeginPrint(null, null); FNumberOfPages = pageCounter; } } CurrentPageNr++; CurrentYPos = FTopMargin; CurrentXPos = FLeftMargin; FPrinterLayout.PrintPageHeader(); float CurrentYPosBefore = CurrentYPos; float CurrentXPosBefore = CurrentXPos; FPrinterLayout.PrintPageBody(); if ((CurrentYPosBefore == CurrentYPos) && (CurrentXPosBefore == CurrentXPos) && HasMorePages()) { throw new Exception("failure printing, does not fit the page"); } FPrinterLayout.PrintPageFooter(); }
/// <summary> /// Prints the formula of the competition. /// </summary> private void printCompetitionFormula() { //Starting on a new page if the given page is not empty. if (currentYCoordinate > pageTopSize) { currentYCoordinate = 810; } XGraphics graphics = XGraphics.FromPdfPage(getCurrentPage()); XFont font1 = new XFont(FONT_TYPE, 11, XFontStyle.Bold); XFont font2 = new XFont(FONT_TYPE, 10); double font1Height = font1.GetHeight(); double font2Height = font2.GetHeight(); double x = DEFAULT_START_X; graphics.DrawString(FRCPrinterConstants.FORMULA_OF_COMPETITION, font1, XBrushes.Black, x, currentYCoordinate); currentYCoordinate += font1Height * 2; string s1 = fencer.Count.ToString() + " " + FRCPrinterConstants.FENCERS_LOWER; graphics.DrawString(s1, font2, XBrushes.Black, x, currentYCoordinate); currentYCoordinate += font2Height * 3; for (int i = 0; i < pouleRound.Count; i++) { double totalY = currentYCoordinate + font2Height * 4.6; graphics = checkYCoordinate(graphics, totalY); string s2 = FRCPrinterConstants.POULES_ROUND + " " + (i + 1).ToString() + ":"; graphics.DrawString(s2, font2, XBrushes.Black, x, currentYCoordinate); currentYCoordinate += font2Height * 2; string s3 = pouleRound[i].amountOfFencers().ToString() + " " + FRCPrinterConstants.FENCERS_LOWER; graphics.DrawString(s3, font2, XBrushes.Black, x, currentYCoordinate); currentYCoordinate += font2Height * 1.3; string s4 = pouleRound[i].amountOfPoules().ToString() + " " + FRCPrinterConstants.POULES_LOWER + " "; graphics.DrawString(s4, font2, XBrushes.Black, x, currentYCoordinate); currentYCoordinate += font2Height * 1.3; string s5 = pouleRound[i].NumOfQualifiers.ToString() + " " + FRCPrinterConstants.QUALIFIERS; graphics.DrawString(s5, font2, XBrushes.Black, x, currentYCoordinate); currentYCoordinate += font2Height * 2; } if (interpreter.Tableau.amountOfFencers() > 0) { double totalY = currentYCoordinate + font2Height * 3; graphics = checkYCoordinate(graphics, totalY); string s6 = "----------------------------------------------------"; graphics.DrawString(s6, font2, XBrushes.Black, x, currentYCoordinate); currentYCoordinate += font2Height * 3; string s7 = FRCPrinterConstants.DIRECT_ELIMINATION + ": " + interpreter.Tableau.amountOfFencers().ToString() + " " + FRCPrinterConstants.FENCERS_LOWER; graphics.DrawString(s7, font2, XBrushes.Black, x, currentYCoordinate); currentYCoordinate += font2Height * 2; } graphics.Dispose(); }
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 }
/// <summary> /// Prints a page with all fencers with their initial rankings. /// </summary> private void printStartingFencersPage() { //Starting on a new page if the given page is not empty. if (currentYCoordinate > pageTopSize) { currentYCoordinate = 810; } XGraphics graphics = XGraphics.FromPdfPage(getCurrentPage()); XFont font1 = new XFont(FONT_TYPE, 11, XFontStyle.Bold); XFont font2 = new XFont(FONT_TYPE, 10); double font1Height = font1.GetHeight(); double font2Height = font2.GetHeight(); double x = DEFAULT_START_X; string title = FRCPrinterConstants.INITIAL_RANKING + " (" + fencer.Count + " " + FRCPrinterConstants.FENCERS_LOWER + ")"; graphics.DrawString(title, font1, XBrushes.Black, x, currentYCoordinate); currentYCoordinate += font1Height * 2; x += 5; graphics.DrawString(FRCPrinterConstants.RANKING, font2, XBrushes.Black, x, currentYCoordinate); graphics.DrawString(FRCPrinterConstants.NAME, font2, XBrushes.Black, x + 45, currentYCoordinate); graphics.DrawString(FRCPrinterConstants.NATION, font2, XBrushes.Black, x + 235, currentYCoordinate); graphics.DrawString(FRCPrinterConstants.CLUB, font2, XBrushes.Black, x + 285, currentYCoordinate); currentYCoordinate += font2Height * 2; sortFencerInitialRanking(); for (int i = 0; i < fencer.Count; i++) { double totalY = currentYCoordinate + font2Height * 1.3; graphics = checkYCoordinate(graphics, totalY); string ir = fencer[i].InitialRanking.ToString(); graphics.DrawString(ir, font2, XBrushes.Black, x + 30 - ir.Length * 5, currentYCoordinate); string name = fencer[i].LastName.ToUpper() + " " + fencer[i].FirstName; string club = fencer[i].Club; if (name.Length > 37) { name = name.Remove(37); } if (club.Length > 15) { club = club.Remove(15); } graphics.DrawString(name, font2, XBrushes.Black, x + 45, currentYCoordinate); graphics.DrawString(fencer[i].Nationality, font2, XBrushes.Black, x + 235, currentYCoordinate); graphics.DrawString(club, font2, XBrushes.Black, x + 285, currentYCoordinate); currentYCoordinate += font2Height * 1.3; } graphics.Dispose(); }
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); } } }
private static void DrawStringML(this XGraphics G, string Text, XFont font, XBrush brush, double x, ref double y, double mX) { string[] words = Text.Split(' '); double tempX = x; double totalSpace = mX - x; double measureWord = font.GetHeight(G); double tempWordWidth = 0; foreach (string word in words) { tempWordWidth = G.MeasureString(word, font).Width; measureWord += tempWordWidth; if (measureWord > totalSpace) { y += font.GetHeight(G); tempX = x; measureWord = tempWordWidth; } G.DrawString(word, font, brush, tempX, y); tempX += tempWordWidth + 4; } y += font.GetHeight(G); }
private double GetTextHeight(string text, XFont font, double rectWidth) { double fontHeight = font.GetHeight(); XSize measure = _gfx.MeasureString(text, font); double absoluteTextHeight = measure.Height; double absoluteTextWidth = measure.Width; if (absoluteTextWidth > rectWidth) { var linesToAdd = (int)Math.Ceiling(absoluteTextWidth / rectWidth) - 1; return(absoluteTextHeight + linesToAdd * (fontHeight)); } return(absoluteTextHeight); }
void Page_Load(object sender, EventArgs e) { if (Request.QueryString["pathid"] != null) { // Create new PDF document PdfDocument document = new PdfDocument(); document.Info.Title = "PDFsharp Clock Demo"; document.Info.Author = "Stefan Lange"; document.Info.Subject = "Server time: "; // Create new page PdfPage page = document.AddPage(); XGraphics gfx = XGraphics.FromPdfPage(page); XFont font = new XFont("Verdana", 12, XFontStyle.Regular); double x = 100, y = 100; double ls = font.GetHeight(gfx); string[] strinData = PolaczenieSQL.print_history_pdf(Request.QueryString["pathid"]); // Draw the text gfx.DrawString("Action: " + strinData[6], font, XBrushes.Black, x, y); y += ls; gfx.DrawString("Action Id: " + strinData[0], font, XBrushes.Black, x, y); y += ls; gfx.DrawString("Employe: " + strinData[1], font, XBrushes.Black, x, y); y += ls; gfx.DrawString("HR employee: " + strinData[2], font, XBrushes.Black, x, y); y += ls; gfx.DrawString("Days count: " + strinData[3], font, XBrushes.Black, x, y); y += ls; gfx.DrawString("Reason: " + strinData[4], font, XBrushes.Black, x, y); y += ls; gfx.DrawString("Date: " + strinData[5], font, XBrushes.Black, x, y); // Send PDF to browser MemoryStream stream = new MemoryStream(); document.Save(stream, false); Response.Clear(); Response.ContentType = "application/pdf"; Response.AddHeader("content-length", stream.Length.ToString()); Response.BinaryWrite(stream.ToArray()); Response.Flush(); stream.Close(); Response.End(); } }
private void GenerateFreeTextPage(XGraphics gfx) { //Add comment page header //======================================================================================================================================// var font = new XFont("Calibri", 30.0, XFontStyle.Bold); var stringSize = gfx.MeasureString("COMMENTS", font); var rect = new XRect(Margin, Margin, UsableWidth, font.GetHeight()); CreateTextFormatter(gfx, XParagraphAlignment.Center).DrawString("COMMENTS", font, TextBrush, rect, XStringFormats.TopLeft); //Add free text //======================================================================================================================================// font = new XFont("Calibri", 11.0, XFontStyle.Bold); rect = new XRect(Margin, rect.Location.Y + rect.Height + 5, UsableWidth, PageHeight - rect.Location.Y + rect.Height + 5); CreateTextFormatter(gfx, XParagraphAlignment.Left).DrawString(reportTab.rpData.tb_FreeText_Text, font, TextBrush, rect, XStringFormats.TopLeft); }
private static void CreateReceiveInventoryStagingReport(string path, int totalproduct) { XFont fontH1 = new XFont("Arial", 18, XFontStyle.Bold); XFont fontH2 = new XFont("Arial", 16, XFontStyle.Italic); XFont font = new XFont("Arial", 12); using (PdfDocument document = new PdfDocument()) { document.Info.Title = "Fox One POS Stage Received Inventory Report"; PdfPage page = document.AddPage(); double x = 50; double y = 100; using (XGraphics gfx = XGraphics.FromPdfPage(page)) { double ls = font.GetHeight(gfx); double lsH1 = fontH1.GetHeight(gfx); double lsH2 = fontH2.GetHeight(gfx); using (XImage img = XImage.FromFile(Configuration.LogoFile)) { double width = img.PixelWidth * 72 / img.HorizontalResolution; double height = img.PixelHeight * 72 / img.HorizontalResolution; gfx.DrawImage(img, x, y, width, height); y += height; } gfx.DrawString(Configuration.Current.BusinessName + " Stage Received Inventory Report", fontH1, XBrushes.Black, x, y); y += lsH1; gfx.DrawString("Station: " + Configuration.Current.StationID, fontH2, XBrushes.Black, x, y); y += lsH2; gfx.DrawString(DateTime.Now.ToString(), fontH2, XBrushes.Black, x, y); y += lsH2 * 2; gfx.DrawString("Total product received: " + totalproduct.ToString(), font, XBrushes.Black, x, y); } document.Save(path); } }
/// <summary> /// Fills a poule protocole with given poule at given coordinates. /// </summary> /// <param name="graphics"></param> /// <param name="font"></param> /// <param name="poule"></param> /// <param name="x">The x coordinate where a poule is already drawn.</param> /// <param name="y">The y coordinate where a poule is already drawn.</param> private void fillPouleProtocole(XGraphics graphics, XFont font, FRCPoule poule, double x, double y) { int length = poule.amountOfFencers(); double fontHeight = font.GetHeight(); double pouleRectWidth = POULE_TOTAL_WIDTH / length; FRCFencer fencer1, fencer2; FRCMatch match; string res1, res2; double x1, y1, x2, y2; y += fontHeight; for (int i = 0; i < poule.amountOfMatches(); i++) { match = poule.getNextMatch(); assignMatchResult(out res1, out res2, out fencer1, out fencer2, match); y1 = y + (fencer1.FencerNumberInPoule - 1) * fontHeight * 1.25; y2 = y + (fencer2.FencerNumberInPoule - 1) * fontHeight * 1.25; x1 = x + pouleRectWidth * (fencer2.FencerNumberInPoule - 1); x2 = x + pouleRectWidth * (fencer1.FencerNumberInPoule - 1); if (res1.Length == 1) { x1 += pouleRectWidth * 0.3; } else if (res1.Length == 2) { x1 += pouleRectWidth * 0.2; } if (res2.Length == 1) { x2 += pouleRectWidth * 0.3; } else if (res2.Length == 2) { x2 += pouleRectWidth * 0.2; } graphics.DrawString(res1, font, XBrushes.Black, x1, y1); graphics.DrawString(res2, font, XBrushes.Black, x2, y2); } }
private void drawTableauPartOnTableauPart(XGraphics graphics, XFont font, FRCTableauPart tableauPart, double tableauWidth, double tableauSpace, int partNumber, string title, double titleX, double titleY) { FRCMatch match; FRCFencer fencer1, fencer2, winner; double fontHeight = font.GetHeight(); int endPointIdx = 0; int tableauSize = tableauPart.Length; int iterationsPerPage = tableauSize / tableauPageCounter; FRCFencer[] ft = fencerInTableau.ToArray(); fencerInTableau.Clear(); for (int i = 0; i < tableauSize; i += 2) { XPoint point = tableauEndPoint[endPointIdx]; if ((i >= iterationsPerPage) && (i % iterationsPerPage == 0)) { graphics.Dispose(); pageIdx++; graphics = XGraphics.FromPdfPage(document.Pages[pageIdx]); graphics.DrawString(title, font, XBrushes.Black, titleX, titleY, XStringFormats.TopLeft); } fencer1 = ft[i]; fencer2 = ft[i + 1]; string name, score; tableauEndPoint[endPointIdx] = drawTableauLines(graphics, point, tableauSpace * Math.Pow(2, partNumber), tableauWidth, tableauWidth); XPoint endPoint = tableauEndPoint[endPointIdx]; endPointIdx += (int)Math.Pow(2, partNumber); if (fencer1 == null && fencer2 == null) { winner = null; name = "----------"; score = ""; } else if (fencer1 == null) { winner = fencer2; name = fencer2.LastName.ToUpper() + " " + fencer2.FirstName; score = ""; } else if (fencer2 == null) { winner = fencer1; name = fencer1.LastName.ToUpper() + " " + fencer1.FirstName; score = ""; } else { match = tableauPart.getNextMatch(); fencer1 = getFencerFromTableauMatchingID(match.FencerID1); fencer2 = getFencerFromTableauMatchingID(match.FencerID2); if (match.Fencer1Win) { winner = fencer1; name = fencer1.LastName.ToUpper() + " " + fencer1.FirstName; if (match.Fencer2Abandon) { score = "by abandonment"; } else if (match.Fencer2Forfait) { score = "by scratch"; } else if (match.Fencer2Exclusion) { score = "by exclusion"; } else { score = match.ScoreFencer1.ToString() + "/" + match.ScoreFencer2.ToString(); } } else { winner = fencer2; name = fencer2.LastName.ToUpper() + " " + fencer2.FirstName; if (match.Fencer1Abandon) { score = "by abandonment"; } else if (match.Fencer1Forfait) { score = "by scratch"; } else if (match.Fencer1Exclusion) { score = "by exclusion"; } else { score = match.ScoreFencer2.ToString() + "/" + match.ScoreFencer1.ToString(); } } } if (name.Length > 18) { name = name.Remove(18); } fencerInTableau.Add(winner); graphics.DrawString(name, font, XBrushes.Black, endPoint.X + 5, endPoint.Y - 2); graphics.DrawString(score, font, XBrushes.Black, endPoint.X + 15, endPoint.Y + fontHeight); } graphics.Dispose(); }
/// <summary> /// Should be used to draw the first tableau part. /// </summary> /// <param name="graphics"></param> /// <param name="font"></param> /// <param name="fontClub"></param> /// <param name="tableauPart"></param> /// <param name="qualifiers"></param> /// <param name="tableauWidth"></param> /// <param name="tableauSpace"></param> /// <param name="x"></param> /// <param name="y"></param> /// <param name="title"></param> /// <param name="titleY"></param> private void drawTableauPart(XGraphics graphics, XFont font, XFont fontClub, FRCTableauPart tableauPart, int qualifiers, double tableauWidth, double tableauSpace, double x, double y, string title, double titleY) { FRCMatch match; FRCFencer fencer1, fencer2, winner; double fontHeight = font.GetHeight(); double totalY; currentYCoordinate = y; int endPointIdx = 0; int rank1, rank2; int tableauSize = tableauPart.Length; interpreter.Tableau.calculateTableauNumbers(tableauSize); FRCFencer[] ft = fencerInTableau.ToArray(); fencerInTableau.Clear(); for (int i = 0; i < tableauSize; i += 2) { totalY = currentYCoordinate + tableauSpace * 2; graphics = checkYCoordinate(graphics, totalY); currentYCoordinate += tableauSpace; if (pageAdded) { graphics.DrawString(title, font, XBrushes.Black, (x + tableauWidth) / 2, titleY, XStringFormats.TopLeft); currentYCoordinate += fontHeight; pageAdded = false; } string name1, name2, name3, club1, club2, score; rank1 = interpreter.Tableau.getTableauNumber(i); rank2 = interpreter.Tableau.getTableauNumber(i + 1); if (!onlyOnce) { fencer1 = getFencerFromTableauMatchingInitialRanking(rank1); fencer2 = getFencerFromTableauMatchingInitialRanking(rank2); } else { fencer1 = ft[i]; fencer2 = ft[i + 1]; } if (fencer1 == null) { name1 = "----------"; club1 = ""; } else { name1 = fencer1.LastName.ToUpper() + " " + fencer1.FirstName; club1 = fencer1.Club; if (name1.Length > 22) { name1 = name1.Remove(22); } if (club1.Length > 15) { club1 = club1.Remove(15); } } if (fencer2 == null) { name2 = "----------"; club2 = ""; } else { name2 = fencer2.LastName.ToUpper() + " " + fencer2.FirstName; club2 = fencer2.Club; if (name2.Length > 22) { name2 = name2.Remove(22); } if (club2.Length > 15) { club2 = club2.Remove(15); } } if (fencer1 == null && fencer2 == null) { winner = null; name3 = "----------"; score = ""; } else if (fencer1 == null) { winner = fencer2; name3 = fencer2.LastName.ToUpper() + " " + fencer2.FirstName; score = ""; } else if (fencer2 == null) { winner = fencer1; name3 = fencer1.LastName.ToUpper() + " " + fencer1.FirstName; score = ""; } else { match = tableauPart.getNextMatch(); //Skip matches with REF=0 in extended format of xml file. while (match.FencerID1 == 0 || match.FencerID2 == 0) { match = tableauPart.getNextMatch(); } fencer1 = getFencerFromTableauMatchingID(match.FencerID1); fencer2 = getFencerFromTableauMatchingID(match.FencerID2); if (match.Fencer1Win) { winner = fencer1; name3 = fencer1.LastName.ToUpper() + " " + fencer1.FirstName; if (match.Fencer2Abandon) { score = "by abandonment"; } else if (match.Fencer2Forfait) { score = "by scratch"; } else if (match.Fencer2Exclusion) { score = "by exclusion"; } else { score = match.ScoreFencer1.ToString() + "/" + match.ScoreFencer2.ToString(); } } else { winner = fencer2; name3 = fencer2.LastName.ToUpper() + " " + fencer2.FirstName; if (match.Fencer1Abandon) { score = "by abandonment"; } else if (match.Fencer1Forfait) { score = "by scratch"; } else if (match.Fencer1Exclusion) { score = "by exclusion"; } else { score = match.ScoreFencer2.ToString() + "/" + match.ScoreFencer1.ToString(); } } } if (name3.Length > 18) { name3 = name3.Remove(18); } fencerInTableau.Add(winner); tableauEndPoint.Add(drawTableauLines(graphics, new XPoint(x, currentYCoordinate), tableauSpace, tableauWidth, tableauWidth * 0.7)); graphics.DrawString(rank1.ToString(), font, XBrushes.Black, x, currentYCoordinate - 2); graphics.DrawString(name1, font, XBrushes.Black, x + 20, currentYCoordinate - 2); graphics.DrawString(club1, fontClub, XBrushes.Black, x + 20, currentYCoordinate + fontHeight * 0.8); currentYCoordinate += tableauSpace; graphics.DrawString(rank2.ToString(), font, XBrushes.Black, x, currentYCoordinate - 2); graphics.DrawString(name2, font, XBrushes.Black, x + 20, currentYCoordinate - 2); graphics.DrawString(club2, fontClub, XBrushes.Black, x + 20, currentYCoordinate + fontHeight * 0.8); XPoint point = tableauEndPoint[endPointIdx]; endPointIdx++; graphics.DrawString(name3, font, XBrushes.Black, point.X + 5, point.Y - 2); graphics.DrawString(score, font, XBrushes.Black, point.X + 15, point.Y + fontHeight); } onlyOnce = true; graphics.Dispose(); }
// ----- DrawString --------------------------------------------------------------------------- public void DrawString(string s, XFont font, XBrush brush, XRect rect, XStringFormat format) { Realize(font, brush, 0); double x = rect.X; double y = rect.Y; double lineSpace = font.GetHeight(this.gfx); //int cellSpace = font.cellSpace; // font.FontFamily.GetLineSpacing(font.Style); //int cellAscent = font.cellAscent; // font.FontFamily.GetCellAscent(font.Style); //int cellDescent = font.cellDescent; // font.FontFamily.GetCellDescent(font.Style); //double cyAscent = lineSpace * cellAscent / cellSpace; //double cyDescent = lineSpace * cellDescent / cellSpace; double cyAscent = lineSpace * font.cellAscent / font.cellSpace; double cyDescent = lineSpace * font.cellDescent / font.cellSpace; double width = this.gfx.MeasureString(s, font).Width; bool bold = (font.Style & XFontStyle.Bold) != 0; bool italic = (font.Style & XFontStyle.Italic) != 0; bool strikeout = (font.Style & XFontStyle.Strikeout) != 0; bool underline = (font.Style & XFontStyle.Underline) != 0; switch (format.Alignment) { case XStringAlignment.Near: // nothing to do break; case XStringAlignment.Center: x += (rect.Width - width) / 2; break; case XStringAlignment.Far: x += rect.Width - width; break; } if (Gfx.PageDirection == XPageDirection.Downwards) { switch (format.LineAlignment) { case XLineAlignment.Near: y += cyAscent; break; case XLineAlignment.Center: // TODO use CapHeight. PDFlib also uses 3/4 of ascent y += (cyAscent * 3 / 4) / 2 + rect.Height / 2; break; case XLineAlignment.Far: y += -cyDescent + rect.Height; break; case XLineAlignment.BaseLine: // nothing to do break; } } else { switch (format.LineAlignment) { case XLineAlignment.Near: y += cyDescent; break; case XLineAlignment.Center: // TODO use CapHeight. PDFlib also uses 3/4 of ascent y += -(cyAscent * 3 / 4) / 2 + rect.Height / 2; break; case XLineAlignment.Far: y += -cyAscent + rect.Height; break; case XLineAlignment.BaseLine: // nothing to do break; } } PdfFont realizedFont = this.gfxState.realizedFont; Debug.Assert(realizedFont != null); realizedFont.AddChars(s); OpenTypeDescriptor descriptor = realizedFont.FontDescriptor.descriptor; if (bold && !descriptor.IsBoldFace) { // TODO: emulate bold by thicker outline } if (italic && !descriptor.IsBoldFace) { // TODO: emulate italic by shearing transformation } if (font.Unicode) { string s2 = ""; for (int idx = 0; idx < s.Length; idx++) { char ch = s[idx]; int glyphID = 0; if (descriptor.fontData.cmap.symbol) { glyphID = (int)ch + (descriptor.fontData.os2.usFirstCharIndex & 0xFF00); glyphID = descriptor.CharCodeToGlyphIndex((char)glyphID); } else glyphID = descriptor.CharCodeToGlyphIndex(ch); s2 += (char)glyphID; } s = s2; byte[] bytes = PdfEncoders.RawUnicodeEncoding.GetBytes(s); bytes = PdfEncoders.FormatStringLiteral(bytes, true, false, true, null); string text = PdfEncoders.RawEncoding.GetString(bytes, 0, bytes.Length); XPoint pos = new XPoint(x, y); AdjustTextMatrix(ref pos); AppendFormat( "{0:0.####} {1:0.####} Td {2} Tj\n", pos.x, pos.y, text); //PdfEncoders.ToStringLiteral(s, PdfStringEncoding.RawEncoding, null)); } else { byte[] bytes = PdfEncoders.WinAnsiEncoding.GetBytes(s); XPoint pos = new XPoint(x, y); AdjustTextMatrix(ref pos); AppendFormat( "{0:0.####} {1:0.####} Td {2} Tj\n", pos.x, pos.y, PdfEncoders.ToStringLiteral(bytes, false, null)); } if (underline) { double underlinePosition = lineSpace * realizedFont.FontDescriptor.descriptor.UnderlinePosition / font.cellSpace; double underlineThickness = lineSpace * realizedFont.FontDescriptor.descriptor.UnderlineThickness / font.cellSpace; DrawRectangle(null, brush, x, y - underlinePosition, width, underlineThickness); } if (strikeout) { double strikeoutPosition = lineSpace * realizedFont.FontDescriptor.descriptor.StrikeoutPosition / font.cellSpace; double strikeoutSize = lineSpace * realizedFont.FontDescriptor.descriptor.StrikeoutSize / font.cellSpace; DrawRectangle(null, brush, x, y - strikeoutPosition - strikeoutSize, width, strikeoutSize); } }
public static void SaveTest() { XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always); initialize(); PdfPage page = _document.AddPage(); XGraphics X = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Prepend); page.Size = PageSize.A4; double width = page.Width; double height = page.Height; double top = _margins.Top; double bottom = _margins.Bottom; double left = _margins.Left; double right = _margins.Right * 2; double y = top; double x = left; XFont titleFont = new XFont("Calibri", 14F, XFontStyle.Bold, options); XFont fontW = new XFont("Calibri", 100F, XFontStyle.Regular, options); XFont fontQ = new XFont("Calibri", 12F, XFontStyle.Regular, options); XFont fontA = new XFont("Calibri", 11F, XFontStyle.Regular, options); var img = new Bitmap(1, 1); XGraphics E = XGraphics.FromGraphics(Graphics.FromImage(img), new XSize()); X.DrawStringML(_title, titleFont, XBrushes.Black, x, ref y, width - right); y += titleFont.GetHeight() + 20; X.DrawString("Date: " + _date, fontQ, Brushes.Black, width - right - 40, y); X.DrawString("First Name: ___________________", fontQ, Brushes.Black, x, y); y += fontQ.GetHeight() + 5; X.DrawString("Last Name: ___________________", fontQ, Brushes.Black, x, y); y += fontQ.GetHeight() + 5; X.DrawString("Class: ________", fontQ, Brushes.Black, x, y); y += fontQ.GetHeight() + 5; X.DrawString("Points:________", fontQ, Brushes.Black, x, y); y += fontQ.GetHeight() + 35; X.DrawString("Choose the correct answer. There might be more than one correct answers.", fontQ, Brushes.Black, x, y); y += fontQ.GetHeight() + 20; for (int i = 0; i < _test.Count; i++) { string question = (i + 1) + ". " + _test[i].question; //Ipologismos gia allagi selidas double tempY = y; E.DrawStringML(question, fontQ, Brushes.Black, x, ref tempY, width - right); if (tempY > height - bottom) { watermarkprint(X, page, fontW); page = _document.AddPage(); page.Size = PageSize.A4; X = XGraphics.FromPdfPage(page); y = top; } //Prints Questions X.DrawStringML(question, fontQ, XBrushes.Black, x, ref y, width - right); for (int k = 0; k < _test[i].anwsers.Count; k++) { string answer = _test[i].anwsers[k].text; //ipologismos gia allagi selida tempY = y; E.DrawStringML(answer, fontQ, Brushes.Black, x, ref tempY, width - right); if (tempY > height - bottom) { watermarkprint(X, page, fontW); page = _document.AddPage(); page.Size = PageSize.A4; X = XGraphics.FromPdfPage(page); y = top; } y += 3; //Edw tipwnei apantisi X.DrawRectangle(new Pen(Color.Black), x + 15, y, 20, 20); if (_solved && _test[i].anwsers[k].correct) { var cube = new Bitmap(20, 20); Graphics C = Graphics.FromImage(cube); C.FillRectangle(Brushes.Black, 0, 0, 20, 20); X.DrawImage(cube, x + 15, y, 20, 20); } y += 12; X.DrawStringML(answer, fontA, Brushes.Black, x + 45, ref y, width - right); } y += 30; } watermarkprint(X, page, fontW); _document.Save(_savePath); Process.Start(_savePath); }
/// <summary> /// Prints the comptition title on the top of the pdf page. This method should be called once for each new page. /// </summary> private void printPageTop() { double fontSize1 = 12; double fontSize2 = 11; XGraphics graphics = XGraphics.FromPdfPage(currentPage); XFont font1 = new XFont(FONT_TYPE, fontSize1); XFont font2 = new XFont(FONT_TYPE, fontSize2); XFont pageNumberFont = new XFont(FONT_TYPE, 9); //Prints page number. string pageNumber = document.PageCount.ToString(); double y = 20; double x; if (pageNumber.Length > 1) { x = 572; } else { x = 575; } graphics.DrawString(pageNumber, pageNumberFont, XBrushes.Black, x, y); string title = interpreter.Formula.CompetitionName; string[] str; //There is no space for several lines in title if the tableau is larger than 16. So use TitreCourt in that case. if ((interpreter.Tableau.amountOfFencers() <= 16) && (title != null)) { str = title.Split('-'); } else { str = new string[1]; str[0] = interpreter.Formula.CompetitionNameShort; //str[0] = title; } x = 300; y = 30; double fontHeight; /* * double sumOfY; * do{ * //Calculate sum of y. * sumOfY = y + font2.GetHeight()*2; * for(int i=0; i<str.Length; i++) * { * if(i == 0) * sumOfY += font1.GetHeight(); * else * sumOfY += font2.GetHeight(); * } * * if(sumOfY >= 60) * { * fontSize1--; * fontSize2--; * font1 = new XFont(FONT_TYPE, fontSize1); * font2 = new XFont(FONT_TYPE, fontSize2); * * } * }while(sumOfY >= 60); */ //Print title. for (int i = 0; i < str.Length; i++) { str[i] = str[i].Trim(); if (i == 0) { graphics.DrawString(str[i], font1, XBrushes.Black, x, y, XStringFormats.Center); fontHeight = font1.GetHeight(); } else { graphics.DrawString(str[i], font2, XBrushes.Black, x, y, XStringFormats.Center); fontHeight = font2.GetHeight(); } y += fontHeight; } y += font2.GetHeight() * 2; pageTopSize = y; currentYCoordinate = y; graphics.Dispose(); }
/// <summary> /// Prints the result of given poule round. /// </summary> /// <param name="pouleRound"></param> private void printRankingAfterPouleRound(FRCPouleRound pouleRound) { //Starting on a new page if the given page is not empty. if (currentYCoordinate > pageTopSize) { currentYCoordinate = 810; } XGraphics graphics = XGraphics.FromPdfPage(getCurrentPage()); XFont font1 = new XFont(FONT_TYPE, 11, XFontStyle.Bold); XFont font2 = new XFont(FONT_TYPE, 10); double font1Height = font1.GetHeight(); double font2Height = font2.GetHeight(); double x = DEFAULT_START_X; FRCFencer fencer, fencerInList; int amountOfFencers = pouleRound.amountOfFencers(); for (int i = 0; i < pouleRound.amountOfFencers(); i++) { fencer = pouleRound.getNextFencer(); fencerInList = getFencerMatchingID(fencer.ID); if (fencerInList.Forfait || fencerInList.Excluded) { amountOfFencers--; } } string title = FRCPrinterConstants.RANKING_OF_POULES + ", " + FRCPrinterConstants.ROUND + " " + FRCPrinterConstants.NUMBER + " " + pouleRound.RoundNumber.ToString() + " (" + amountOfFencers.ToString() + " " + FRCPrinterConstants.FENCERS_LOWER + ")"; graphics.DrawString(title, font1, XBrushes.Black, x, currentYCoordinate); currentYCoordinate += font1Height * 2; x += 5; graphics.DrawString(FRCPrinterConstants.RANK, font2, XBrushes.Black, x, currentYCoordinate); graphics.DrawString(FRCPrinterConstants.NAME, font2, XBrushes.Black, x + 45, currentYCoordinate); graphics.DrawString(FRCPrinterConstants.CLUB, font2, XBrushes.Black, x + 235, currentYCoordinate); graphics.DrawString(FRCPrinterConstants.V_M, font2, XBrushes.Black, x + 330, currentYCoordinate); graphics.DrawString(FRCPrinterConstants.HS_HR, font2, XBrushes.Black, x + 365, currentYCoordinate); graphics.DrawString(FRCPrinterConstants.HS, font2, XBrushes.Black, x + 400, currentYCoordinate); graphics.DrawString(FRCPrinterConstants.Q_E, font2, XBrushes.Black, x + 425, currentYCoordinate); currentYCoordinate += font2Height * 2; //Added since the meaning of RangFinal is not consistent for all versions of EnGarde for (int i = 0; i < pouleRound.amountOfFencers(); i++) { fencer = pouleRound.getNextFencer(); fencerInList = getFencerMatchingID(fencer.ID); pouleRound.CopyPouleResult(fencerInList); } pouleRound.calculateFencerPouleRanking(); pouleRound.sortFencerPouleRanking(); for (int i = 0; i < pouleRound.amountOfFencers(); i++) { fencer = pouleRound.getNextFencer(); //fencerInList = getFencerMatchingID(fencer.ID); //Skip if the fencer got scratch or exclusion. if (fencer.Forfait || fencer.Excluded) { continue; } //Skip if the fencer does not have a status, since that is odd and happens sometime. if (fencer.NoStatusException == true) { continue; } double totalY = currentYCoordinate + font2Height * 1.3; graphics = checkYCoordinate(graphics, totalY); string pr = fencer.PhaseFinalRanking.ToString(); string name = fencer.LastName.ToUpper() + " " + fencer.FirstName; string club = fencer.Club; string ind = (fencer.HitsGivenInPoule - fencer.HitsTakenInPoule).ToString(); string hs = fencer.HitsGivenInPoule.ToString(); string qe; string vm_s = fencer.VM_String; if (fencer.IsStillInTheCompetition) { qe = FRCPrinterConstants.QUALIFIED; } else if (fencer.Abandoned) { qe = FRCPrinterConstants.ABANDONED; ind = " "; hs = ""; vm_s = ""; } else { qe = FRCPrinterConstants.ELIMINATED; qualifiedEnd = true; } if (name.Length > 37) { name = name.Remove(37); } if (club.Length > 15) { club = club.Remove(15); } if (qualifiedEnd && !eliminatedStarted) { XPen pen = new XPen(XColors.Black, 0.5); graphics = checkYCoordinate(graphics, totalY + font2Height * 0.5); //currentYCoordinate += font2Height * 0.25; graphics.DrawLine(pen, x, currentYCoordinate - font2Height * 0.7, x + 470, currentYCoordinate - font2Height * 0.7); currentYCoordinate += font2Height * 0.5; eliminatedStarted = true; } graphics.DrawString(pr, font2, XBrushes.Black, x + 15 - pr.Length * 5, currentYCoordinate); graphics.DrawString(name, font2, XBrushes.Black, x + 45, currentYCoordinate); graphics.DrawString(club, font2, XBrushes.Black, x + 235, currentYCoordinate); graphics.DrawString(vm_s, font2, XBrushes.Black, x + 330, currentYCoordinate); if (ind[0] == '-') { graphics.DrawString(ind, font2, XBrushes.Black, x + 374 - (ind.Length - 1) * 5, currentYCoordinate); } else { graphics.DrawString(ind, font2, XBrushes.Black, x + 377 - ind.Length * 5, currentYCoordinate); } graphics.DrawString(hs, font2, XBrushes.Black, x + 412 - hs.Length * 5, currentYCoordinate); graphics.DrawString(qe, font2, XBrushes.Black, x + 425, currentYCoordinate); currentYCoordinate += font2Height * 1.3; } qualifiedEnd = false; eliminatedStarted = false; graphics.Dispose(); }
// ----- DrawString --------------------------------------------------------------------------- public void DrawString(string s, XFont font, XBrush brush, XRect rect, XStringFormat format) { double x = rect.X; double y = rect.Y; double lineSpace = font.GetHeight(); double cyAscent = lineSpace * font.CellAscent / font.CellSpace; double cyDescent = lineSpace * font.CellDescent / font.CellSpace; double width = _gfx.MeasureString(s, font).Width; //bool bold = (font.Style & XFontStyle.Bold) != 0; //bool italic = (font.Style & XFontStyle.Italic) != 0; bool italicSimulation = (font.GlyphTypeface.StyleSimulations & XStyleSimulations.ItalicSimulation) != 0; bool boldSimulation = (font.GlyphTypeface.StyleSimulations & XStyleSimulations.BoldSimulation) != 0; bool strikeout = (font.Style & XFontStyle.Strikeout) != 0; bool underline = (font.Style & XFontStyle.Underline) != 0; Realize(font, brush, boldSimulation ? 2 : 0); switch (format.Alignment) { case XStringAlignment.Near: // nothing to do break; case XStringAlignment.Center: x += (rect.Width - width) / 2; break; case XStringAlignment.Far: x += rect.Width - width; break; } if (Gfx.PageDirection == XPageDirection.Downwards) { switch (format.LineAlignment) { case XLineAlignment.Near: y += cyAscent; break; case XLineAlignment.Center: // TODO: Use CapHeight. PDFlib also uses 3/4 of ascent y += (cyAscent * 3 / 4) / 2 + rect.Height / 2; break; case XLineAlignment.Far: y += -cyDescent + rect.Height; break; case XLineAlignment.BaseLine: // Nothing to do. break; } } else { switch (format.LineAlignment) { case XLineAlignment.Near: y += cyDescent; break; case XLineAlignment.Center: // TODO: Use CapHeight. PDFlib also uses 3/4 of ascent y += -(cyAscent * 3 / 4) / 2 + rect.Height / 2; break; case XLineAlignment.Far: y += -cyAscent + rect.Height; break; case XLineAlignment.BaseLine: // Nothing to do. break; } } PdfFont realizedFont = _gfxState._realizedFont; Debug.Assert(realizedFont != null); realizedFont.AddChars(s); const string format2 = Config.SignificantFigures4; OpenTypeDescriptor descriptor = realizedFont.FontDescriptor._descriptor; string text = null; if (font.Unicode) { StringBuilder sb = new StringBuilder(); bool isSymbolFont = descriptor.FontFace.cmap.symbol; for (int idx = 0; idx < s.Length; idx++) { char ch = s[idx]; if (isSymbolFont) { // Remap ch for symbol fonts. ch = (char)(ch | (descriptor.FontFace.os2.usFirstCharIndex & 0xFF00)); // @@@ refactor } int glyphID = descriptor.CharCodeToGlyphIndex(ch); sb.Append((char)glyphID); } s = sb.ToString(); byte[] bytes = PdfEncoders.RawUnicodeEncoding.GetBytes(s); bytes = PdfEncoders.FormatStringLiteral(bytes, true, false, true, null); text = PdfEncoders.RawEncoding.GetString(bytes, 0, bytes.Length); } else { byte[] bytes = PdfEncoders.WinAnsiEncoding.GetBytes(s); text = PdfEncoders.ToStringLiteral(bytes, false, null); } // Map absolute position to PDF world space. XPoint pos = new XPoint(x, y); pos = WorldToView(pos); double verticalOffset = 0; if (boldSimulation) { // Adjust baseline in case of bold simulation??? // No, because this would change the center of the glyphs. //verticalOffset = font.Size * Const.BoldEmphasis / 2; } #if ITALIC_SIMULATION if (italicSimulation) { if (_gfxState.ItalicSimulationOn) { AdjustTdOffset(ref pos, verticalOffset, true); AppendFormatArgs("{0:" + format2 + "} {1:" + format2 + "} Td\n{2} Tj\n", pos.X, pos.Y, text); } else { // Italic simulation is done by skewing characters 20° to the right. XMatrix m = new XMatrix(1, 0, Const.ItalicSkewAngleSinus, 1, pos.X, pos.Y); AppendFormatArgs("{0:" + format2 + "} {1:" + format2 + "} {2:" + format2 + "} {3:" + format2 + "} {4:" + format2 + "} {5:" + format2 + "} Tm\n{6} Tj\n", m.M11, m.M12, m.M21, m.M22, m.OffsetX, m.OffsetY, text); _gfxState.ItalicSimulationOn = true; AdjustTdOffset(ref pos, verticalOffset, false); } } else { if (_gfxState.ItalicSimulationOn) { XMatrix m = new XMatrix(1, 0, 0, 1, pos.X, pos.Y); AppendFormatArgs("{0:" + format2 + "} {1:" + format2 + "} {2:" + format2 + "} {3:" + format2 + "} {4:" + format2 + "} {5:" + format2 + "} Tm\n{6} Tj\n", m.M11, m.M12, m.M21, m.M22, m.OffsetX, m.OffsetY, text); _gfxState.ItalicSimulationOn = false; AdjustTdOffset(ref pos, verticalOffset, false); } else { AdjustTdOffset(ref pos, verticalOffset, false); AppendFormatArgs("{0:" + format2 + "} {1:" + format2 + "} Td {2} Tj\n", pos.X, pos.Y, text); } } #else AdjustTextMatrix(ref pos); AppendFormat2("{0:" + format2 + "} {1:" + format2 + "} Td {2} Tj\n", pos.X, pos.Y, text); #endif if (underline) { double underlinePosition = lineSpace * realizedFont.FontDescriptor._descriptor.UnderlinePosition / font.CellSpace; double underlineThickness = lineSpace * realizedFont.FontDescriptor._descriptor.UnderlineThickness / font.CellSpace; //DrawRectangle(null, brush, x, y - underlinePosition, width, underlineThickness); double underlineRectY = Gfx.PageDirection == XPageDirection.Downwards ? y - underlinePosition : y + underlinePosition - underlineThickness; DrawRectangle(null, brush, x, underlineRectY, width, underlineThickness); } if (strikeout) { double strikeoutPosition = lineSpace * realizedFont.FontDescriptor._descriptor.StrikeoutPosition / font.CellSpace; double strikeoutSize = lineSpace * realizedFont.FontDescriptor._descriptor.StrikeoutSize / font.CellSpace; //DrawRectangle(null, brush, x, y - strikeoutPosition - strikeoutSize, width, strikeoutSize); double strikeoutRectY = Gfx.PageDirection == XPageDirection.Downwards ? y - strikeoutPosition : y + strikeoutPosition - strikeoutSize; DrawRectangle(null, brush, x, strikeoutRectY, width, strikeoutSize); } }
/// <summary> /// Prints all poule rounds. And ranking after each poule round as well. /// </summary> private void printPouleRounds() { XGraphics graphics = null; XFont font = new XFont(FONT_TYPE, 11, XFontStyle.Bold); double fontHeight = font.GetHeight(); double x = DEFAULT_START_X; for (int i = 0; i < pouleRound.Count; i++) { //Starting on a new page if the given page is not empty. if (currentYCoordinate > pageTopSize) { currentYCoordinate = 810; } graphics = XGraphics.FromPdfPage(getCurrentPage()); string title = FRCPrinterConstants.POULES_ROUND + " " + (i + 1).ToString(); graphics.DrawString(title, font, XBrushes.Black, x, currentYCoordinate); currentYCoordinate += fontHeight * 3; for (int j = 0; j < pouleRound[i].NumOfPoules; j++) { XFont tempFont = new XFont(FONT_TYPE, 10); FRCPoule poule = pouleRound[i].getNextPoule(); double totalY = currentYCoordinate + tempFont.GetHeight() * (4.9 + 1.25 * poule.amountOfFencers()); graphics = checkYCoordinate(graphics, totalY); printPoule(graphics, poule, j + 1); } registerEliminationOnRankList(pouleRound[i]); if (i == pouleRound.Count - 1) { checkTableauRankFormat(pouleRound[i]); /* * if (qualifyAllRankAll) * Console.WriteLine("d"); * if (qualifyLastRankAll) * Console.WriteLine("b"); * if (qualifyLastRankLast) * Console.WriteLine("a"); */ //Different competition formats. if (qualifyLastRankLast) { //Do nothing. } else if (qualifyAllRankAll) { //Print summing ranking after all poule rounds and skip the ranking of the last poule. printRankingAfterAllPouleRounds(); break; } else if (qualifyLastRankAll) { //Do nothing. Print summing ranking later. } } printRankingAfterPouleRound(pouleRound[i]); } }
/// <summary> /// Prints the poule with given number. /// </summary> /// <param name="graphics"></param> /// <param name="poule">The poule to be printed.</param> /// <param name="pouleNumber">The poule number.</param> private void printPoule(XGraphics graphics, FRCPoule poule, int pouleNumber) { XFont font = new XFont(FONT_TYPE, 10); double fontHeight = font.GetHeight(); double x = DEFAULT_START_X; string s1 = FRCPrinterConstants.POULE + " " + FRCPrinterConstants.NUMBER + " " + pouleNumber + " " + poule.StartTime + " " + FRCPrinterConstants.PISTE + " " + FRCPrinterConstants.NUMBER + " " + poule.PisteNumber; string s2 = FRCPrinterConstants.REFEREE + ": "; for (int i = 0; i < poule.amountOfReferees(); i++) { FRCReferee referee = poule.getNextReferee(); s2 += referee.LastName.ToUpper() + " " + referee.FirstName + " " + referee.Club; if (poule.hasNextReferee()) { s2 += ", "; } } graphics.DrawString(s1, font, XBrushes.Black, x, currentYCoordinate); currentYCoordinate += fontHeight * 1.3; graphics.DrawString(s2, font, XBrushes.Black, x, currentYCoordinate); currentYCoordinate += fontHeight * 1.3; graphics.DrawString(FRCPrinterConstants.V_M, font, XBrushes.Black, x + 400, currentYCoordinate); graphics.DrawString(FRCPrinterConstants.HS_HR, font, XBrushes.Black, x + 435, currentYCoordinate); graphics.DrawString(FRCPrinterConstants.HS, font, XBrushes.Black, x + 470, currentYCoordinate); graphics.DrawString(FRCPrinterConstants.RANK, font, XBrushes.Black, x + 495, currentYCoordinate); currentYCoordinate += fontHeight * 1.3; drawPouleGraph(graphics, x + 250, currentYCoordinate, poule.amountOfFencers()); double savedY = currentYCoordinate; currentYCoordinate += fontHeight; poule.sortFencersFencerNumberInPoule(); for (int i = 0; i < poule.amountOfFencers(); i++) { FRCFencer fencer = poule.getNextFencer(); fencer = registerFencerStatusInPouleFromMatch(poule, fencer); copyFencerInfo(fencer); registerPouleResult(fencer); string name = fencer.LastName.ToUpper() + " " + fencer.FirstName; string club = fencer.Club; double vm = fencer.VM; string vm_s = vm.ToString().Replace(',', '.'); string ind = fencer.Index.ToString(); string hs = fencer.HitsGivenInPoule.ToString(); string rank = fencer.PouleRanking.ToString(); if (vm_s.Length == 1) { vm_s += "."; } vm_s += "000"; if (vm_s.Length > 5) { vm_s = vm_s.Remove(5); } //Saving the value for fencer list in this class. getFencerMatchingID(fencer.ID).VM_String = vm_s; if (name.Length > 30) { name = name.Remove(30); } if (club.Length > 15) { club = club.Remove(15); } if (fencer.Abandoned || fencer.Forfait || fencer.Excluded) { vm_s = ""; ind = " "; hs = ""; rank = ""; } graphics.DrawString(name, font, XBrushes.Black, x + 5, currentYCoordinate); graphics.DrawString(club, font, XBrushes.Black, x + 160, currentYCoordinate); graphics.DrawString(vm_s, font, XBrushes.Black, x + 400, currentYCoordinate); if (ind[0] == '-') { graphics.DrawString(ind, font, XBrushes.Black, x + 447 - (ind.Length - 1) * 5, currentYCoordinate); } else { graphics.DrawString(ind, font, XBrushes.Black, x + 450 - ind.Length * 5, currentYCoordinate); } graphics.DrawString(hs, font, XBrushes.Black, x + 482 - hs.Length * 5, currentYCoordinate); graphics.DrawString(rank, font, XBrushes.Black, x + 513 - rank.Length * 5, currentYCoordinate); currentYCoordinate += fontHeight * 1.25; } fillPouleProtocole(graphics, font, poule, x + 250, savedY); currentYCoordinate += fontHeight * 2; }
public override void RenderPage(XGraphics gfx) { base.RenderPage(gfx); string facename = "Times"; float size = 24; XFont fontR = new XFont(facename, size, this.properties.Font1.Style); fontR = this.properties.Font1.Font; //XFont fontB = new XFont(facename, size, XFontStyle.Bold); //XFont fontI = new XFont(facename, size, XFontStyle.Italic); //XFont fontBI = new XFont(facename, size, XFontStyle.Bold | XFontStyle.Italic); //gfx.DrawString("Hello", this.properties.Font1.Font, this.properties.Font1.Brush, 200, 200); float x0 = 80; float x1 = 520; float y0 = 80; float y1 = 760 / 2; RectangleF rect = new RectangleF(x0, y0, x1 - x0, y1 - y0); XPen pen = XPens.SlateBlue; gfx.DrawRectangle(pen, rect); gfx.DrawLine(pen, (x0 + x1) / 2, y0, (x0 + x1) / 2, y1); gfx.DrawLine(pen, x0, (y0 + y1) / 2, x1, (y0 + y1) / 2); XSolidBrush brush = this.properties.Font1.Brush; XStringFormat format = new XStringFormat(); 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; gfx.DrawString("TopLeft", fontR, brush, rect, format); format.Alignment = XStringAlignment.Center; gfx.DrawString("TopCenter", fontR, brush, rect, format); format.Alignment = XStringAlignment.Far; gfx.DrawString("TopRight", fontR, brush, rect, format); format.LineAlignment= XLineAlignment.Center; format.Alignment = XStringAlignment.Near; gfx.DrawString("CenterLeft", fontR, brush, rect, format); format.Alignment = XStringAlignment.Center; gfx.DrawString("Center", fontR, brush, rect, format); format.Alignment = XStringAlignment.Far; gfx.DrawString("CenterRight", fontR, brush, rect, format); format.LineAlignment= XLineAlignment.Far; format.Alignment = XStringAlignment.Near; gfx.DrawString("BottomLeft", fontR, brush, rect, format); format.Alignment = XStringAlignment.Center; gfx.DrawString("BottomCenter", fontR, brush, rect, format); format.Alignment = XStringAlignment.Far; gfx.DrawString("BottomRight", fontR, brush, rect, format); // format.LineAlignment= XLineAlignment.Center; // format.Alignment = XStringAlignment.Center; // gfx.DrawString("CenterLeft", fontR, brush, rect, format); // gfx.DrawString("Times 40", fontR, this.properties.Font1.Brush, x, 200); // gfx.DrawString("Times bold 40", fontB, this.properties.Font1.Brush, x, 300); // gfx.DrawString("Times italic 40", fontI, this.properties.Font1.Brush, x, 400); // gfx.DrawString("Times bold italic 40", fontBI, this.properties.Font1.Brush, x, 500); }
/// <summary> /// Prints referee activity page. /// </summary> private void printRefereeActivity() { //Starting on a new page if the given page is not empty. if (currentYCoordinate > pageTopSize) { currentYCoordinate = 810; } XGraphics graphics = XGraphics.FromPdfPage(getCurrentPage()); XFont font1 = new XFont(FONT_TYPE, 11, XFontStyle.Bold); XFont font2 = new XFont(FONT_TYPE, 10); double font1Height = font1.GetHeight(); double font2Height = font2.GetHeight(); double x = DEFAULT_START_X; string title = FRCPrinterConstants.REFEREE_ACTIVITY; graphics.DrawString(title, font1, XBrushes.Black, x, currentYCoordinate); currentYCoordinate += font1Height * 2; x += 5; graphics.DrawString(FRCPrinterConstants.NAME, font2, XBrushes.Black, x, currentYCoordinate); graphics.DrawString(FRCPrinterConstants.NATION, font2, XBrushes.Black, x + 190, currentYCoordinate); graphics.DrawString(FRCPrinterConstants.CLUB, font2, XBrushes.Black, x + 235, currentYCoordinate); graphics.DrawString(FRCPrinterConstants.CATEGORY, font2, XBrushes.Black, x + 320, currentYCoordinate); graphics.DrawString(FRCPrinterConstants.POULES, font2, XBrushes.Black, x + 365, currentYCoordinate); graphics.DrawString(FRCPrinterConstants.MATCHES, font2, XBrushes.Black, x + 410, currentYCoordinate); graphics.DrawString(FRCPrinterConstants.QUARTER_FINALS, font2, XBrushes.Black, x + 455, currentYCoordinate); graphics.DrawString(FRCPrinterConstants.FINALS, font2, XBrushes.Black, x + 500, currentYCoordinate); currentYCoordinate += font2Height * 2; List <FRCReferee> referee = interpreter.getRefereeList(); for (int i = 0; i < referee.Count; i++) { double totalY = currentYCoordinate + font2Height * 1.3; graphics = checkYCoordinate(graphics, totalY); string name = referee[i].LastName.ToUpper() + " " + referee[i].FirstName; string club = referee[i].Club; if (name.Length > 37) { name = name.Remove(37); } if (club.Length > 15) { club = club.Remove(15); } graphics.DrawString(name, font2, XBrushes.Black, x, currentYCoordinate); graphics.DrawString(referee[i].Nationality, font2, XBrushes.Black, x + 190, currentYCoordinate); graphics.DrawString(club, font2, XBrushes.Black, x + 235, currentYCoordinate); graphics.DrawString(referee[i].Category, font2, XBrushes.Black, x + 320, currentYCoordinate); graphics.DrawString(referee[i].RefereedPoules.ToString(), font2, XBrushes.Black, x + 365, currentYCoordinate); graphics.DrawString(referee[i].RefereedMatches.ToString(), font2, XBrushes.Black, x + 410, currentYCoordinate); graphics.DrawString(referee[i].RefereedQuarterFinals.ToString(), font2, XBrushes.Black, x + 455, currentYCoordinate); graphics.DrawString(referee[i].RefereedFinals.ToString(), font2, XBrushes.Black, x + 500, currentYCoordinate); currentYCoordinate += font2Height * 1.3; } graphics.Dispose(); }
internal static double GetSubSuperScaling(XFont font) { return(0.8 * GetAscent(font) / font.GetHeight()); }
/// <summary> /// Prints the tableau. /// </summary> private void printTableau() { tableauStarted = true; //Starting on a new page if the given page is not empty. if (currentYCoordinate > pageTopSize) { currentYCoordinate = 810; } XGraphics graphics = XGraphics.FromPdfPage(getCurrentPage()); XFont font = new XFont(FONT_TYPE, 10); XFont fontClub = new XFont(FONT_TYPE, 9); double fontHeight = font.GetHeight(); double x = DEFAULT_START_X; double titleY = currentYCoordinate; double tableauWidth = TABLEAU_WIDTH; double tableauSpace = TABLEAU_SPACE; string title; pageAdded = false; //Checks and fixes if two fencers has same ranking. interpreter.Tableau.checkRankingIND(); FRCTableauPart tableauPart = interpreter.Tableau.getNextTableauPart(); if (tableauPart.Length == 2) { title = FRCPrinterConstants.Final; } else if (tableauPart.Length == 4) { title = FRCPrinterConstants.SEMI_FINALS; } else { title = FRCPrinterConstants.TABLE_OF + " " + tableauPart.Length.ToString(); } if (tableauPart.Length > 16) { font = new XFont(FONT_TYPE, 8.5); fontClub = new XFont(FONT_TYPE, 7); fontHeight = font.GetHeight(); tableauSpace = tableauSpace * 0.68; tableauWidth = tableauWidth * 0.9; } graphics.DrawString(title, font, XBrushes.Black, (x + tableauWidth) / 2, titleY, XStringFormats.TopLeft); currentYCoordinate += fontHeight; tableauEndPoint.Clear(); //Draws the first part of tableau on the page. drawTableauPart(graphics, font, fontClub, tableauPart, interpreter.Tableau.amountOfFencers(), tableauWidth, tableauSpace, x, currentYCoordinate, title, titleY); x += tableauWidth * 1.8; tableauWidth = tableauWidth * 0.7; //Index for building tableau. int tableauBreakIdx; assignTableauBreakIndex(tableauPart, out tableauBreakIdx); //Builds with several tableau parts on the first part. for (int i = 0; i < tableauBreakIdx; i++) { if (interpreter.Tableau.hasNextTableauPart()) { tableauPart = interpreter.Tableau.getNextTableauPart(); if (tableauPart.Length == 2) { title = FRCPrinterConstants.Final; } else if (tableauPart.Length == 4) { title = FRCPrinterConstants.SEMI_FINALS; } else { title = FRCPrinterConstants.TABLE_OF + " " + tableauPart.Length.ToString(); } pageIdx = document.Pages.Count - tableauPageCounter; graphics = XGraphics.FromPdfPage(document.Pages[pageIdx]); graphics.DrawString(title, font, XBrushes.Black, (x + tableauWidth) / 1.9, titleY, XStringFormats.TopLeft); drawTableauPartOnTableauPart(graphics, font, tableauPart, tableauWidth, tableauSpace, i + 1, title, (x + tableauWidth) / 1.9, titleY); x += tableauWidth * 2; } } tableauPageCounter = 0; graphics.Dispose(); }
/// <summary> /// Resembles the DrawString function of GDI+. /// </summary> public void DrawString(XGraphics gfx, string text, XFont font, XBrush brush, XRect layoutRectangle, XStringFormat format) { double x = layoutRectangle.X; double y = layoutRectangle.Y; double lineSpace = font.GetHeight(); //old: font.GetHeight(gfx); double cyAscent = lineSpace * font.CellAscent / font.CellSpace; double cyDescent = lineSpace * font.CellDescent / font.CellSpace; bool bold = (font.Style & XFontStyle.Bold) != 0; bool italic = (font.Style & XFontStyle.Italic) != 0; bool strikeout = (font.Style & XFontStyle.Strikeout) != 0; bool underline = (font.Style & XFontStyle.Underline) != 0; //Debug.Assert(font.GlyphTypeface != null); TextBlock textBlock = new TextBlock(); //FontHelper.CreateTextBlock(text, font.GlyphTypeface, font.Size, brush.RealizeWpfBrush()); if (layoutRectangle.Width > 0) { textBlock.Width = layoutRectangle.Width; } switch (format.Alignment) { case XStringAlignment.Near: textBlock.TextAlignment = TextAlignment.Left; break; case XStringAlignment.Center: textBlock.TextAlignment = TextAlignment.Center; break; case XStringAlignment.Far: textBlock.TextAlignment = TextAlignment.Right; break; } if (gfx.PageDirection == XPageDirection.Downwards) { switch (format.LineAlignment) { case XLineAlignment.Near: //y += cyAscent; break; case XLineAlignment.Center: // TODO use CapHeight. PDFlib also uses 3/4 of ascent y += (layoutRectangle.Height - textBlock.ActualHeight) / 2; //y += -formattedText.Baseline + (font.Size * font.Metrics.CapHeight / font.unitsPerEm / 2) + layoutRectangle.Height / 2; break; case XLineAlignment.Far: y += layoutRectangle.Height - textBlock.ActualHeight; //y -= textBlock.ActualHeight; //-formattedText.Baseline - cyDescent + layoutRectangle.Height; break; case XLineAlignment.BaseLine: //#if !WINDOWS_PHONE y -= textBlock.BaselineOffset; //#else // // No BaselineOffset in Silverlight WP yet. // //y -= textBlock.BaselineOffset; //#endif break; } } else { throw new NotImplementedException("XPageDirection.Downwards"); } //if (bold && !descriptor.IsBoldFace) //{ // // TODO: emulate bold by thicker outline //} //if (italic && !descriptor.IsBoldFace) //{ // // TODO: emulate italic by shearing transformation //} if (underline) { textBlock.TextDecorations = TextDecorations.Underline; } // No strikethrough in Silverlight //if (strikeout) //{ // formattedText.SetTextDecorations(TextDecorations.Strikethrough); // //double strikeoutPosition = lineSpace * realizedFont.FontDescriptor.descriptor.StrikeoutPosition / font.cellSpace; // //double strikeoutSize = lineSpace * realizedFont.FontDescriptor.descriptor.StrikeoutSize / font.cellSpace; // //DrawRectangle(null, brush, x, y - strikeoutPosition - strikeoutSize, width, strikeoutSize); //} Canvas.SetLeft(textBlock, x); Canvas.SetTop(textBlock, y); ActiveCanvas.Children.Add(textBlock); }
/// <summary> /// Prints the overall ranking page. /// </summary> private void printOverallRanking() { XGraphics graphics = XGraphics.FromPdfPage(getCurrentPage()); XFont font1 = new XFont(FONT_TYPE, 11, XFontStyle.Bold); XFont font2 = new XFont(FONT_TYPE, 10); double font1Height = font1.GetHeight(); double font2Height = font2.GetHeight(); double x = DEFAULT_START_X; int amountOfFencers = fencer.Count; for (int i = 0; i < interpreter.Tableau.amountOfFencers(); i++) { copyFencerInfo(interpreter.Tableau.getNextFencer()); } //For a bug fix, Forfait and Exclusion must be checked from all poule matches here. registerForfaitExclusionFromPoules(); for (int i = 0; i < fencer.Count; i++) { if (fencer[i].Forfait || fencer[i].Excluded) { amountOfFencers--; } } string title = FRCPrinterConstants.FINAL_RESULTS + " (" + amountOfFencers.ToString() + " " + FRCPrinterConstants.FENCERS_LOWER + ")"; graphics.DrawString(title, font1, XBrushes.Black, x, currentYCoordinate); currentYCoordinate += font1Height * 2; x += 5; graphics.DrawString(FRCPrinterConstants.PLACE, font2, XBrushes.Black, x, currentYCoordinate); graphics.DrawString(FRCPrinterConstants.NAME, font2, XBrushes.Black, x + 30, currentYCoordinate); graphics.DrawString(FRCPrinterConstants.NATION, font2, XBrushes.Black, x + 220, currentYCoordinate); graphics.DrawString(FRCPrinterConstants.CLUB, font2, XBrushes.Black, x + 270, currentYCoordinate); currentYCoordinate += font2Height * 2; sortFencerFinalRanking(); for (int i = 0; i < fencer.Count; i++) { if (fencer[i].FinalRanking == 0) { continue; } double totalY = currentYCoordinate + font2Height * 1.3; graphics = checkYCoordinate(graphics, totalY); string fr = fencer[i].FinalRanking.ToString(); graphics.DrawString(fr, font2, XBrushes.Black, x + 20 - fr.Length * 5, currentYCoordinate); string name = fencer[i].LastName.ToUpper() + " " + fencer[i].FirstName; string club = fencer[i].Club; if (name.Length > 37) { name = name.Remove(37); } if (club.Length > 15) { club = club.Remove(15); } graphics.DrawString(name, font2, XBrushes.Black, x + 30, currentYCoordinate); graphics.DrawString(fencer[i].Nationality, font2, XBrushes.Black, x + 220, currentYCoordinate); graphics.DrawString(club, font2, XBrushes.Black, x + 270, currentYCoordinate); currentYCoordinate += font2Height * 1.3; } graphics.Dispose(); }
/// <summary> /// Renders the content of the page. /// </summary> public void Render(XGraphics gfx) { XRect rect; XPen pen; double x = 50, y = 100; XFont fontH1 = new XFont("Times", 18, XFontStyle.Bold); XFont font = new XFont("Times", 12); XFont fontItalic = new XFont("Times", 12, XFontStyle.BoldItalic); double ls = font.GetHeight(gfx); // Draw some text gfx.DrawString("Create PDF on the fly with PDFsharp", fontH1, XBrushes.Black, x, x); gfx.DrawString("With PDFsharp you can use the same code to draw graphic, " + "text and images on different targets.", font, XBrushes.Black, x, y); y += ls; gfx.DrawString("The object used for drawing is the XGraphics object.", font, XBrushes.Black, x, y); y += 2 * ls; // Draw an arc pen = new XPen(XColors.Red, 4); pen.DashStyle = XDashStyle.Dash; gfx.DrawArc(pen, x + 20, y, 100, 60, 150, 120); // Draw a star XGraphicsState gs = gfx.Save(); gfx.TranslateTransform(x + 140, y + 30); for (int idx = 0; idx < 360; idx += 10) { gfx.RotateTransform(10); gfx.DrawLine(XPens.DarkGreen, 0, 0, 30, 0); } gfx.Restore(gs); // Draw a rounded rectangle rect = new XRect(x + 230, y, 100, 60); pen = new XPen(XColors.DarkBlue, 2.5); XColor color1 = XColor.FromKnownColor(KnownColor.DarkBlue); XColor color2 = XColors.Red; XLinearGradientBrush lbrush = new XLinearGradientBrush(rect, color1, color2, XLinearGradientMode.Vertical); gfx.DrawRoundedRectangle(pen, lbrush, rect, new XSize(10, 10)); // Draw a pie pen = new XPen(XColors.DarkOrange, 1.5); pen.DashStyle = XDashStyle.Dot; gfx.DrawPie(pen, XBrushes.Blue, x + 360, y, 100, 60, -130, 135); // Draw some more text y += 60 + 2 * ls; gfx.DrawString("With XGraphics you can draw on a PDF page as well as " + "on any System.Drawing.Graphics object.", font, XBrushes.Black, x, y); y += ls * 1.1; gfx.DrawString("Use the same code to", font, XBrushes.Black, x, y); x += 10; y += ls * 1.1; gfx.DrawString("• draw on a newly created PDF page", font, XBrushes.Black, x, y); y += ls; gfx.DrawString("• draw above or beneath of the content of an existing PDF page", font, XBrushes.Black, x, y); y += ls; gfx.DrawString("• draw in a window", font, XBrushes.Black, x, y); y += ls; gfx.DrawString("• draw on a printer", font, XBrushes.Black, x, y); y += ls; gfx.DrawString("• draw in a bitmap image", font, XBrushes.Black, x, y); x -= 10; y += ls * 1.1; gfx.DrawString("You can also import an existing PDF page and use it like " + "an image, e.g. draw it on another PDF page.", font, XBrushes.Black, x, y); y += ls * 1.1 * 2; gfx.DrawString("Imported PDF pages are neither drawn nor printed; create a " + "PDF file to see or print them!", fontItalic, XBrushes.Firebrick, x, y); y += ls * 1.1; gfx.DrawString("Below this text is a PDF form that will be visible when " + "viewed or printed with a PDF viewer.", fontItalic, XBrushes.Firebrick, x, y); y += ls * 1.1; XGraphicsState state = gfx.Save(); XRect rcImage = new XRect(100, y, 100, 100 * Math.Sqrt(2)); gfx.DrawRectangle(XBrushes.Snow, rcImage); gfx.DrawImage(XPdfForm.FromFile("../../../../../PDFs/SomeLayout.pdf"), rcImage); gfx.Restore(state); }
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); }