当前位置: 首页>>代码示例>>C#>>正文


C# XFont.GetHeight方法代码示例

本文整理汇总了C#中PdfSharp.Drawing.XFont.GetHeight方法的典型用法代码示例。如果您正苦于以下问题:C# XFont.GetHeight方法的具体用法?C# XFont.GetHeight怎么用?C# XFont.GetHeight使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PdfSharp.Drawing.XFont的用法示例。


在下文中一共展示了XFont.GetHeight方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RenderPage

    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
    }
开发者ID:vronikp,项目名称:EventRegistration,代码行数:52,代码来源:TestText02.cs

示例2: RenderMeasureText

    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);
    }
开发者ID:vronikp,项目名称:EventRegistration,代码行数:34,代码来源:MeasureText.cs

示例3: Render

        /// <summary>
        /// Renders the content of the page.
        /// </summary>
        public void Render(XGraphics xGraphics)
        {
            const double textPossitionX = 50;
            double textPossitionY = 100;
            const string fontFamilyName = "Times";
            const int fontSizeHeader = 18;
            const int fontSizeText = 12;

            XFont fontHeader = new XFont(fontFamilyName, fontSizeHeader, XFontStyle.Bold);
            XFont fontText = new XFont(fontFamilyName, fontSizeText);
            XFont fontItalic = new XFont(fontFamilyName, fontSizeText, XFontStyle.BoldItalic);
            double lineSpacing = fontText.GetHeight(xGraphics);

            xGraphics.DrawString("This is Header", fontHeader, XBrushes.Black, textPossitionX, textPossitionX);
            textPossitionY += lineSpacing;
            xGraphics.DrawString("This is normal.", fontText, XBrushes.Black, textPossitionX, textPossitionY);
            textPossitionY += lineSpacing;
            xGraphics.DrawString("This is Italic.", fontItalic, XBrushes.Black, textPossitionX, textPossitionY);

            textPossitionY += lineSpacing*3;

            //Bitmap bitmap = (Bitmap)Image.FromFile(@"E:\temp\klicaj.jpeg");
            XImage xImage = null;
            if (item != null)
            {
                if (item.Image != null)
                {
                    MemoryStream memoryStream = new MemoryStream(item.Image);
                    Bitmap bitmap = (Bitmap) Image.FromStream(memoryStream, true, true);
                    xImage = XImage.FromGdiPlusImage(bitmap);
                }
            }

            if (xImage != null)
            {
                XRect rcImage = new XRect(100, textPossitionY, 100, 100*Math.Sqrt(2));
                xGraphics.DrawImage(xImage, rcImage);
            }

            XGraphicsState state = xGraphics.Save();
            xGraphics.Restore(state);
        }
开发者ID:trippleflux,项目名称:jezatools,代码行数:45,代码来源:Renderer.cs

示例4: SaveTest

        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);
        }
开发者ID:Hli4S,项目名称:TestMeApp,代码行数:97,代码来源:SavePDF.cs

示例5: DrawStringML

 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);
 }
开发者ID:Hli4S,项目名称:TestMeApp,代码行数:22,代码来源:SavePDF.cs

示例6: Render

    /// <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);
    }
开发者ID:AnthonyNystrom,项目名称:Pikling,代码行数:87,代码来源:Program.cs

示例7: CreateReceiveInventoryStagingReport

        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);
            }
        }
开发者ID:russjudge,项目名称:SmallBusinessManager,代码行数:44,代码来源:TransactionEngine.cs

示例8: CalcVerticalInfo

    VerticalLineInfo CalcVerticalInfo(XFont font)
    {
      ParagraphFormat paragraphFormat = this.paragraph.Format;
      LineSpacingRule spacingRule = paragraphFormat.LineSpacingRule;
      XUnit lineHeight = 0;

      XUnit descent = FontHandler.GetDescent(font);
      descent = Math.Max(this.currentVerticalInfo.descent, descent);

      XUnit singleLineSpace = font.GetHeight();
      RenderInfo imageRenderInfo = this.CurrentImageRenderInfo;
      if (imageRenderInfo != null)
        singleLineSpace = singleLineSpace - FontHandler.GetAscent(font) + imageRenderInfo.LayoutInfo.ContentArea.Height;

      XUnit inherentLineSpace = Math.Max(this.currentVerticalInfo.inherentlineSpace, singleLineSpace);
      switch (spacingRule)
      {
        case LineSpacingRule.Single:
          lineHeight = singleLineSpace;
          break;

        case LineSpacingRule.OnePtFive:
          lineHeight = 1.5 * singleLineSpace;
          break;

        case LineSpacingRule.Double:
          lineHeight = 2.0 * singleLineSpace;
          break;

        case LineSpacingRule.Multiple:
          lineHeight = this.paragraph.Format.LineSpacing * singleLineSpace;
          break;

        case LineSpacingRule.AtLeast:
          lineHeight = Math.Max(singleLineSpace, paragraph.Format.LineSpacing);
          break;

        case LineSpacingRule.Exactly:
          lineHeight = new XUnit(paragraph.Format.LineSpacing);
          inherentLineSpace = paragraph.Format.LineSpacing.Point;
          break;
      }
      lineHeight = Math.Max(this.currentVerticalInfo.height, lineHeight);
      if (this.MaxElementHeight > 0)
        lineHeight = Math.Min(this.MaxElementHeight - Renderer.Tolerance, lineHeight);

      return new VerticalLineInfo(lineHeight, descent, inherentLineSpace);
    }
开发者ID:DavidS,项目名称:MigraDoc,代码行数:48,代码来源:ParagraphRenderer.cs

示例9: SimulateBaselineOffset

        /// <summary>
        /// Calculates the offset for BaseLine positioning simulation:
        /// In GDI we have only Near, Center and Far as LineAlignment and no BaseLine. For XLineAlignment.BaseLine StringAlignment.Near is returned.
        /// We now return the negative drawed ascender height.
        /// This has to be added to the LayoutRect/Origin before each _gdipPath.AddString().
        /// </summary>
        /// <param name="family"></param>
        /// <param name="style"></param>
        /// <param name="emSize"></param>
        /// <param name="format"></param>
        /// <returns></returns>
        private float SimulateBaselineOffset(XFontFamily family, XFontStyle style, double emSize, XStringFormat format)
        {
            XFont font = new XFont(family.Name, emSize, style);

            if (format.LineAlignment == XLineAlignment.BaseLine)
            {
                double lineSpace = font.GetHeight();
                int cellSpace = font.FontFamily.GetLineSpacing(font.Style);
                int cellAscent = font.FontFamily.GetCellAscent(font.Style);
                int cellDescent = font.FontFamily.GetCellDescent(font.Style);
                double cyAscent = lineSpace * cellAscent / cellSpace;
                cyAscent = lineSpace * font.CellAscent / font.CellSpace;
                return (float)-cyAscent;
            }
            return 0;
        }
开发者ID:Core2D,项目名称:PDFsharp,代码行数:27,代码来源:XGraphicsPath.cs

示例10: AddString

        /// <summary>
        /// Adds a text string to this path.
        /// </summary>
        public void AddString(string s, XFontFamily family, XFontStyle style, double emSize, XPoint origin,
            XStringFormat format)
        {
            try
            {
#if CORE
                DiagnosticsHelper.HandleNotImplemented("XGraphicsPath.AddString");
#endif
#if GDI
                if (family.GdiFamily == null)
                    throw new NotFiniteNumberException(PSSR.NotImplementedForFontsRetrievedWithFontResolver(family.Name));

                PointF p = origin.ToPointF();
                p.Y += SimulateBaselineOffset(family, style, emSize, format);

                try
                {
                    Lock.EnterGdiPlus();
                    _gdipPath.AddString(s, family.GdiFamily, (int)style, (float)emSize, p, format.RealizeGdiStringFormat());
                }
                finally { Lock.ExitGdiPlus(); }
#endif
#if WPF
                if (family.WpfFamily == null)
                    throw new NotFiniteNumberException(PSSR.NotImplementedForFontsRetrievedWithFontResolver(family.Name));
#if !SILVERLIGHT
                XFont font = new XFont(family.Name, emSize, style);

                double x = origin.X;
                double y = origin.Y;

                double lineSpace = font.GetHeight();
                double cyAscent = lineSpace * font.CellAscent / font.CellSpace;
                double cyDescent = lineSpace * font.CellDescent / font.CellSpace;

                Typeface typeface = FontHelper.CreateTypeface(family.WpfFamily, style);
                FormattedText formattedText = FontHelper.CreateFormattedText(s, typeface, emSize, WpfBrushes.Black);

                switch (format.Alignment)
                {
                    case XStringAlignment.Near:
                        // nothing to do, this is the default
                        //formattedText.TextAlignment = TextAlignment.Left;
                        break;

                    case XStringAlignment.Center:
                        formattedText.TextAlignment = TextAlignment.Center;
                        break;

                    case XStringAlignment.Far:
                        formattedText.TextAlignment = TextAlignment.Right;
                        break;
                }
                switch (format.LineAlignment)
                {
                    case XLineAlignment.Near:
                        //y += cyAscent;
                        break;

                    case XLineAlignment.Center:
                        // TODO use CapHeight. PDFlib also uses 3/4 of ascent
                        y += -lineSpace / 2; //-formattedText.Baseline + (cyAscent * 2 / 4);
                        break;

                    case XLineAlignment.Far:
                        y += -formattedText.Baseline - cyDescent;
                        break;

                    case XLineAlignment.BaseLine:
                        y -= formattedText.Baseline;
                        break;
                }

                Geometry geo = formattedText.BuildGeometry(new XPoint(x, y));
                _pathGeometry.AddGeometry(geo);
#else
                // AG-HACK
                throw new InvalidOperationException("Silverlight cannot create geometry of glyphs.");
                // TODO: Get the outline directly from the font.
#endif
#endif
            }
            catch
            {
                throw;
            }
        }
开发者ID:Core2D,项目名称:PDFsharp,代码行数:90,代码来源:XGraphicsPath.cs

示例11: RenderPage

    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);
    }
开发者ID:bossaia,项目名称:alexandrialibrary,代码行数:70,代码来源:TextAlign.cs

示例12: Render

        public void Render(XGraphics gfx)
        {
            XPen pen;
            double x = 50;
            XFont fontH1 = new XFont("Times", 18, XFontStyle.Bold);

            XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);
            XFont font = new XFont("Times", 12, XFontStyle.Regular, options);
            XFont fontItalic = new XFont("Times", 12, XFontStyle.BoldItalic);
            double ls = font.GetHeight(gfx);

            pen = new XPen(XColors.Black, 0.5);
            pen.DashStyle = XDashStyle.Solid;

            double tablePositionX = 15, tablePositionY = 30, tablePositionX2 = gfx.PageSize.Width - tablePositionX, 
                    tablePositionY2 = tablePositionY + 30;

            // draw plan title
            string title = LoadedPlan.Name + " " + LoadedPlan.Departament.Name + " " + LoadedPlan.Faculty.Name + " " + LoadedPlan.StudiesType.Name;
            
            System.Drawing.Font ff = new Font("Times", 12);
            Size titleSize = System.Windows.Forms.TextRenderer.MeasureText(title, ff);

            gfx.DrawString(title, font, XBrushes.Black, x, 20);
            double fullLength = 0;

            string legend = "Kolorem czerwonym oznaczono przedmioty obieralne, kolorem czarnym - przedmioty obowiązkowe";
            Size legendSize = System.Windows.Forms.TextRenderer.MeasureText(legend, ff);

            if (LoadedPlan.SubjectsDatas.Count > 0)
            {
                // draw table headers
                gfx.DrawLine(pen, tablePositionX, tablePositionY, tablePositionX, tablePositionY2);
                gfx.DrawLine(pen, tablePositionX + 30, tablePositionY, tablePositionX + 30, tablePositionY2);

                tablePositionY += 11;
                gfx.DrawString("Lp.", font, XBrushes.Black, tablePositionX + 2, tablePositionY);
                gfx.DrawString("Przedmiot", font, XBrushes.Black, tablePositionX + 32, tablePositionY);

                Size nameLength = System.Windows.Forms.TextRenderer.MeasureText("Przedmiot", ff);

                List<Semester> semesters = new List<Semester>();
                List<SubjectTypesData> subjectTypes = new List<SubjectTypesData>();

                Size semNameLength = new Size(0, 0);

                foreach (SubjectsData sd in LoadedPlan.SubjectsDatas)
                {
                    bool semOnList = false;
                    
                    foreach (Semester s in semesters)
                    {
                        if (s.SemesterID == sd.SemesterID)
                            semOnList = true;
                    }

                    foreach (SubjectTypesData st in sd.SubjectTypesDatas)
                    {
                        bool stOnList = false;
                        foreach (SubjectTypesData std in subjectTypes)
                            if (st.SubjectTypeID == std.SubjectTypeID)
                                stOnList = true;

                        if (!stOnList)
                            subjectTypes.Add(st);
                    }

                    if (!semOnList)
                    {
                        semesters.Add(sd.Semester);
                        Size tmp = System.Windows.Forms.TextRenderer.MeasureText(sd.Semester.Name, ff);
                        if (tmp.Width > semNameLength.Width)
                            semNameLength = tmp;
                    }
                }

                semesters = semesters.OrderBy(c => c.Semester1).ToList();

                double oldX = tablePositionX;

                LoadedPlan.SubjectsDatas.OrderBy(c => c.Semester.Semester1);
                List<string> subjectNames = new List<string>();
                foreach (SubjectsData sd in LoadedPlan.SubjectsDatas)
                {
                    bool isOnList = false;
                    foreach (string name in subjectNames)
                        if (name.Equals(sd.Subject.Name))
                            isOnList = true;

                    if (!isOnList)
                    {
                        Size tmp = System.Windows.Forms.TextRenderer.MeasureText(sd.Subject.Name, ff);
                        subjectNames.Add(sd.Subject.Name);
                        if (tmp.Width > nameLength.Width)
                            nameLength.Width = tmp.Width;
                    }
                }

                // -32
                tablePositionX += nameLength.Width + 34;
//.........这里部分代码省略.........
开发者ID:ViniciusConsultor,项目名称:studiesplans2,代码行数:101,代码来源:RenderPdf.cs

示例13: DrawString

    /// <summary>
    /// Draws the specified text string.
    /// </summary>
    public void DrawString(string s, XFont font, XBrush brush, XRect layoutRectangle, XStringFormat format)
    {
      if (s == null)
        throw new ArgumentNullException("s");
      if (font == null)
        throw new ArgumentNullException("font");
      if (brush == null)
        throw new ArgumentNullException("brush");

      if (format.LineAlignment == XLineAlignment.BaseLine && layoutRectangle.Height != 0)
        throw new InvalidOperationException("DrawString: With XLineAlignment.BaseLine the height of the layout rectangle must be 0.");

      if (s.Length == 0)
        return;

      if (format == null)
        format = XStringFormat.Default;

      if (this.drawGraphics)
      {
        RectangleF rect = layoutRectangle.ToRectangleF();
        if (format.LineAlignment == XLineAlignment.BaseLine)
        {
          // TODO optimze
          double lineSpace = font.GetHeight(this);
          int cellSpace = font.FontFamily.GetLineSpacing(font.Style);
          int cellAscent = font.FontFamily.GetCellAscent(font.Style);
          int cellDescent = font.FontFamily.GetCellDescent(font.Style);
          double cyAscent = lineSpace * cellAscent / cellSpace;
          cyAscent = lineSpace * font.cellAscent / font.cellSpace;
          rect.Offset(0, (float)-cyAscent);
        }
        this.gfx.DrawString(s, font.RealizeGdiFont(), brush.RealizeGdiBrush(), rect,
          format != null ? format.RealizeGdiStringFormat() : null);
      }

      if (this.renderer != null)
        this.renderer.DrawString(s, font, brush, layoutRectangle, format);
    }
开发者ID:BackupTheBerlios,项目名称:zp7-svn,代码行数:42,代码来源:XGraphics.cs

示例14: AddString

    /// <summary>
    /// Adds a text string to this path.
    /// </summary>
    public void AddString(string s, XFontFamily family, XFontStyle style, double emSize, XRect layoutRect, XStringFormat format)
    {
      if (s == null)
        throw new ArgumentNullException("s");
      if (family == null)
        throw new ArgumentNullException("family");

      if (format.LineAlignment == XLineAlignment.BaseLine && layoutRect.Height != 0)
        throw new InvalidOperationException("DrawString: With XLineAlignment.BaseLine the height of the layout rectangle must be 0.");

      if (s.Length == 0)
        return;

      if (format == null)
        format = XStringFormats.Default;

      XFont font = new XFont(family.Name, emSize, style);
#if GDI && !WPF
          RectangleF rc = layoutRect.ToRectangleF();
          if (format.LineAlignment == XLineAlignment.BaseLine)
          {
            double lineSpace = font.GetHeight();
            int cellSpace = font.FontFamily.GetLineSpacing(font.Style);
            int cellAscent = font.FontFamily.GetCellAscent(font.Style);
            int cellDescent = font.FontFamily.GetCellDescent(font.Style);
            double cyAscent = lineSpace * cellAscent / cellSpace;
            cyAscent = lineSpace * font.cellAscent / font.cellSpace;
            rc.Offset(0, (float)-cyAscent);
          }
          //this.gfx.DrawString(text, font.RealizeGdiFont(), brush.RealizeGdiBrush(), rect,
          //  format != null ? format.RealizeGdiStringFormat() : null);
      this.gdipPath.AddString(s, family.gdiFamily, (int)style, (float)emSize, rc, format.RealizeGdiStringFormat());
#endif
#if WPF && !GDI
      // Just a first sketch, but currently we do not need it and there is enough to do...
      double x = layoutRect.X;
      double y = layoutRect.Y;

      //double lineSpace = font.GetHeight(this);
      //double cyAscent = lineSpace * font.cellAscent / font.cellSpace;
      //double cyDescent = lineSpace * font.cellDescent / font.cellSpace;

      //double cyAscent = family.GetCellAscent(style) * family.GetLineSpacing(style) / family.getl; //fontlineSpace * font.cellAscent / font.cellSpace;
      //double cyDescent =family.GetCellDescent(style); // lineSpace * font.cellDescent / font.cellSpace;
      double lineSpace = font.GetHeight();
      double cyAscent = lineSpace * font.cellAscent / font.cellSpace;
      double cyDescent = lineSpace * font.cellDescent / font.cellSpace;

      bool bold = (style & XFontStyle.Bold) != 0;
      bool italic = (style & XFontStyle.Italic) != 0;
      bool strikeout = (style & XFontStyle.Strikeout) != 0;
      bool underline = (style & XFontStyle.Underline) != 0;

      Typeface typeface = FontHelper.CreateTypeface(family, style);
      FormattedText formattedText = new FormattedText(s, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, typeface, emSize,
        System.Windows.Media.Brushes.Black);

      switch (format.Alignment)
      {
        case XStringAlignment.Near:
          // nothing to do, this is the default
          //formattedText.TextAlignment = TextAlignment.Left;
          break;

        case XStringAlignment.Center:
          x += layoutRect.Width / 2;
          formattedText.TextAlignment = TextAlignment.Center;
          break;

        case XStringAlignment.Far:
          x += layoutRect.Width;
          formattedText.TextAlignment = TextAlignment.Right;
          break;
      }
      //if (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 += -formattedText.Baseline + (cyAscent * 2 / 4) + layoutRect.Height / 2;
          break;

        case XLineAlignment.Far:
          y += -formattedText.Baseline - cyDescent + layoutRect.Height;
          break;

        case XLineAlignment.BaseLine:
          y -= formattedText.Baseline;
          break;
      }
      //}
      //else
//.........这里部分代码省略.........
开发者ID:AnthonyNystrom,项目名称:Pikling,代码行数:101,代码来源:XGraphicsPath.cs

示例15: DrawString

    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(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;

      //FormattedText formattedText = new FormattedText(text, new CultureInfo("en-us"), // WPFHACK
      //  FlowDirection.LeftToRight, font.typeface, font.Size, brush.RealizeWpfBrush());
      TextBlock textBlock = FontHelper.CreateTextBlock(text, null, font.Size, brush.RealizeWpfBrush());

      Canvas.SetLeft(textBlock, x);
      Canvas.SetTop(textBlock, y);

      //formattedText.SetTextDecorations(TextDecorations.OverLine);
      switch (format.Alignment)
      {
        case XStringAlignment.Near:
          // nothing to do, this is the default
          //formattedText.TextAlignment = TextAlignment.Left;
          break;

        case XStringAlignment.Center:
          x += layoutRectangle.Width / 2;
          textBlock.TextAlignment = TextAlignment.Center;
          break;

        case XStringAlignment.Far:
          x += layoutRectangle.Width;
          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 += -formattedText.Baseline + (cyAscent * 1 / 3) + layoutRectangle.Height / 2;
          //  //y += -formattedText.Baseline + (font.Size * font.Metrics.CapHeight / font.unitsPerEm / 2) + layoutRectangle.Height / 2;
          //  break;

          //case XLineAlignment.Far:
          //  y += -formattedText.Baseline - cyDescent + layoutRectangle.Height;
          //  break;

          //case XLineAlignment.BaseLine:
          //  y -= formattedText.Baseline;
          //  break;
        }
      }
      else
      {
        // TODOWPF: make unit test
        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;
        }
      }

      //if (bold && !descriptor.IsBoldFace)
      //{
      //  // TODO: emulate bold by thicker outline
      //}

      //if (italic && !descriptor.IsBoldFace)
      //{
      //  // TODO: emulate italic by shearing transformation
      //}

      //if (underline)
      //{
      //  formattedText.FontStyle.SetTextDecorations(TextDecorations.Underline);
      //  //double underlinePosition = lineSpace * realizedFont.FontDescriptor.descriptor.UnderlinePosition / font.cellSpace;
//.........这里部分代码省略.........
开发者ID:alexiej,项目名称:YATE,代码行数:101,代码来源:DrawingContext.cs


注:本文中的PdfSharp.Drawing.XFont.GetHeight方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。