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


C# Drawing.XStringFormat类代码示例

本文整理汇总了C#中PdfSharp.Drawing.XStringFormat的典型用法代码示例。如果您正苦于以下问题:C# XStringFormat类的具体用法?C# XStringFormat怎么用?C# XStringFormat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: RenderTextAlignment

    void RenderTextAlignment(XGraphics gfx)
    {
      gfx.TranslateTransform(15, 20);

      XRect rect = new XRect(0, 0, 250, 140);

      XFont font = new XFont("Verdana", 10);
      XBrush brush = XBrushes.Purple;
      XStringFormat format = new XStringFormat();

      gfx.DrawRectangle(XPens.YellowGreen, rect);
      gfx.DrawLine(XPens.YellowGreen, rect.Width / 2, 0, rect.Width / 2, rect.Height);
      gfx.DrawLine(XPens.YellowGreen, 0, rect.Height / 2, rect.Width, rect.Height / 2);

#if true
      gfx.DrawString("TopLeft", font, brush, rect, format);

      format.Alignment = XStringAlignment.Center;
      gfx.DrawString("TopCenter", font, brush, rect, format);

      format.Alignment = XStringAlignment.Far;
      gfx.DrawString("TopRight", font, brush, rect, format);

      format.LineAlignment = XLineAlignment.Center;
      format.Alignment = XStringAlignment.Near;
      gfx.DrawString("CenterLeft", font, brush, rect, format);

      format.Alignment = XStringAlignment.Center;
      gfx.DrawString("Center", font, brush, rect, format);

      format.Alignment = XStringAlignment.Far;
      gfx.DrawString("CenterRight", font, brush, rect, format);

      format.LineAlignment = XLineAlignment.Far;
      format.Alignment = XStringAlignment.Near;
      gfx.DrawString("BottomLeft", font, brush, rect, format);

      format.Alignment = XStringAlignment.Center;
      gfx.DrawString("BottomCenter", font, brush, rect, format);

      format.Alignment = XStringAlignment.Far;
      gfx.DrawString("BottomRight", font, brush, rect, format);
#else
      format.Alignment = XStringAlignment.Far;
      gfx.DrawString("TopRight", font, brush, rect, format);
#endif
    }
开发者ID:vronikp,项目名称:EventRegistration,代码行数:47,代码来源:TextAlignment.cs

示例2: GraphicsAdapter

 static GraphicsAdapter()
 {
     _stringFormat = new XStringFormat();
     _stringFormat.Alignment = XStringAlignment.Near;
     _stringFormat.LineAlignment = XLineAlignment.Near;
     _stringFormat.FormatFlags = XStringFormatFlags.MeasureTrailingSpaces;
 }
开发者ID:michaelremund,项目名称:HTML-Renderer,代码行数:7,代码来源:GraphicsAdapter.cs

示例3: MeasureString

    // ...took a look at the source code of WPF. About 50 classes and several 10,000 lines of code
    // deal with that what colloquial is called 'fonts'.
    // So let's start simple.
    /// <summary>
    /// Simple measure string function.
    /// </summary>
    public static XSize MeasureString(string text, XFont font, XStringFormat stringFormat)
    {
      XSize size = new XSize();

      OpenTypeDescriptor descriptor = FontDescriptorStock.Global.CreateDescriptor(font) as OpenTypeDescriptor;
      if (descriptor != null)
      {
        size.Height = (descriptor.Ascender + Math.Abs(descriptor.Descender)) * font.Size / font.unitsPerEm;
        Debug.Assert(descriptor.Ascender > 0);

        bool symbol = descriptor.fontData.cmap.symbol;
        int length = text.Length;
        int width = 0;
        for (int idx = 0; idx < length; idx++)
        {
          char ch = text[idx];
          int glyphIndex = 0;
          if (symbol)
          {
            glyphIndex = ch + (descriptor.fontData.os2.usFirstCharIndex & 0xFF00); // @@@
            glyphIndex = descriptor.CharCodeToGlyphIndex((char)glyphIndex);
          }
          else
            glyphIndex = descriptor.CharCodeToGlyphIndex(ch);

          //double width = descriptor.GlyphIndexToEmfWidth(glyphIndex, font.Size);
          //size.Width += width;
          width += descriptor.GlyphIndexToWidth(glyphIndex);
        }
        size.Width = width * font.Size * (font.Italic ? 1 : 1) / descriptor.UnitsPerEm;
      }
      Debug.Assert(descriptor != null, "No OpenTypeDescriptor.");
      return size;
    }
开发者ID:inexorabletash,项目名称:PDFsharp,代码行数:40,代码来源:FontHelper14.cs

示例4: RenderWord

        private static void RenderWord(string word, XGraphics gfx, XRect rect, int fontsize, string color = null)
        {
            XFont font = new XFont("Garamond", fontsize, XFontStyle.Regular, new XPdfFontOptions(PdfFontEncoding.Unicode));
            XBrush brush;
            if(string.IsNullOrEmpty(color))
                brush = XBrushes.Black;
            else
            {
                XColor xcolor = XColor.FromArgb(ColorTranslator.FromHtml("#" + color));
                brush = new XSolidBrush(xcolor);
            }

            XStringFormat format = new XStringFormat();

            format.Alignment = XStringAlignment.Center;
            format.LineAlignment = XLineAlignment.Center;
            gfx.DrawString(word.ToLower(), font, brush, rect, format);
        }
开发者ID:marto83,项目名称:flashcardgenerator,代码行数:18,代码来源:HomeController.cs

示例5: MeasureString

        /// <summary>
        /// Measure string directly from font data.
        /// </summary>
        public static XSize MeasureString(string text, XFont font, XStringFormat stringFormat)
        {
            XSize size = new XSize();

            OpenTypeDescriptor descriptor = FontDescriptorCache.GetOrCreateDescriptorFor(font) as OpenTypeDescriptor;
            if (descriptor != null)
            {
                // Height is the sum of ascender and descender.
                size.Height = (descriptor.Ascender + descriptor.Descender) * font.Size / font.UnitsPerEm;
                Debug.Assert(descriptor.Ascender > 0);

                bool symbol = descriptor.FontFace.cmap.symbol;
                int length = text.Length;
                int width = 0;
                for (int idx = 0; idx < length; idx++)
                {
                    char ch = text[idx];
                    // HACK: Unclear what to do here.
                    if (ch < 32)
                        continue;

                    if (symbol)
                    {
                        // Remap ch for symbol fonts.
                        ch = (char)(ch | (descriptor.FontFace.os2.usFirstCharIndex & 0xFF00));  // @@@ refactor
                        // Used | instead of + because of: http://pdfsharp.codeplex.com/workitem/15954
                    }
                    int glyphIndex = descriptor.CharCodeToGlyphIndex(ch);
                    width += descriptor.GlyphIndexToWidth(glyphIndex);
                }
                // What? size.Width = width * font.Size * (font.Italic ? 1 : 1) / descriptor.UnitsPerEm;
                size.Width = width * font.Size / descriptor.UnitsPerEm;

                // Adjust bold simulation.
                if ((font.GlyphTypeface.StyleSimulations & XStyleSimulations.BoldSimulation) == XStyleSimulations.BoldSimulation)
                {
                    // Add 2% of the em-size for each character.
                    // Unsure how to deal with white space. Currently count as regular character.
                    size.Width += length * font.Size * Const.BoldEmphasis;
                }
            }
            Debug.Assert(descriptor != null, "No OpenTypeDescriptor.");
            return size;
        }
开发者ID:Sl0vi,项目名称:PDFsharp,代码行数:47,代码来源:FontHelper.cs

示例6: DrawTextAlignment

    /// <summary>
    /// Shows how to align text in the layout rectangle.
    /// </summary>
    void DrawTextAlignment(XGraphics gfx, int number)
    {
      BeginBox(gfx, number, "Text Alignment");
      XRect rect = new XRect(0, 0, 250, 140);

      XFont font = new XFont("Verdana", 10);
      XBrush brush = XBrushes.Purple;
      XStringFormat format = new XStringFormat();

      gfx.DrawRectangle(XPens.YellowGreen, rect);
      gfx.DrawLine(XPens.YellowGreen, rect.Width / 2, 0, rect.Width / 2, rect.Height);
      gfx.DrawLine(XPens.YellowGreen, 0, rect.Height / 2, rect.Width, rect.Height / 2);

      gfx.DrawString("TopLeft", font, brush, rect, format);

      format.Alignment = XStringAlignment.Center;
      gfx.DrawString("TopCenter", font, brush, rect, format);

      format.Alignment = XStringAlignment.Far;
      gfx.DrawString("TopRight", font, brush, rect, format);

      format.LineAlignment = XLineAlignment.Center;
      format.Alignment = XStringAlignment.Near;
      gfx.DrawString("CenterLeft", font, brush, rect, format);

      format.Alignment = XStringAlignment.Center;
      gfx.DrawString("Center", font, brush, rect, format);

      format.Alignment = XStringAlignment.Far;
      gfx.DrawString("CenterRight", font, brush, rect, format);

      format.LineAlignment = XLineAlignment.Far;
      format.Alignment = XStringAlignment.Near;
      gfx.DrawString("BottomLeft", font, brush, rect, format);

      format.Alignment = XStringAlignment.Center;
      gfx.DrawString("BottomCenter", font, brush, rect, format);

      format.Alignment = XStringAlignment.Far;
      gfx.DrawString("BottomRight", font, brush, rect, format);

      EndBox(gfx);
    }
开发者ID:AnthonyNystrom,项目名称:Pikling,代码行数:46,代码来源:Text.cs

示例7: DrawTitle

    /// <summary>
    /// Draws the page title and footer.
    /// </summary>
    public void DrawTitle(PdfPage page, XGraphics gfx, string title)
    {
      XRect rect = new XRect(new XPoint(), gfx.PageSize);
      rect.Inflate(-10, -15);
      XFont font = new XFont("Verdana", 14, XFontStyle.Bold);
      gfx.DrawString(title, font, XBrushes.MidnightBlue, rect, XStringFormats.TopCenter);

      rect.Offset(0, 5);
      font = new XFont("Verdana", 8, XFontStyle.Italic);
      XStringFormat format = new XStringFormat();
      format.Alignment = XStringAlignment.Near;
      format.LineAlignment = XLineAlignment.Far;
      gfx.DrawString("Created with " + PdfSharp.ProductVersionInfo.Producer, font, XBrushes.DarkOrchid, rect, format);

      font = new XFont("Verdana", 8);
      format.Alignment = XStringAlignment.Center;
      gfx.DrawString(Program.s_document.PageCount.ToString(), font, XBrushes.DarkOrchid, rect, format);

      Program.s_document.Outlines.Add(title, page, true);
    }
开发者ID:bossaia,项目名称:alexandrialibrary,代码行数:23,代码来源:Base.cs

示例8: WriteWatermark

        /// <summary>
        /// Erstellt eine Wassserzeichen
        /// </summary>
        /// <param name="watermarkText">Text fuer das Wasserzeichen</param>
        /// <param name="source">Quelle PDF Stream</param>
        /// <param name="target">Ziel PDF Stream</param>
        public static void WriteWatermark(string watermarkText, MemoryStream source, MemoryStream target)
        {
            PdfDocument originalPdf = PdfSharp.Pdf.IO.PdfReader.Open(source, PdfSharp.Pdf.IO.PdfDocumentOpenMode.Modify);
            foreach (PdfPage page in originalPdf.Pages)
            {
                var gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Prepend);
                var font = new XFont("Verdana", 120);
                var size = gfx.MeasureString(watermarkText, font);
                var brush = new XSolidBrush(XColor.FromArgb(128, 255, 0, 0));
                gfx.TranslateTransform(page.Width.Value / 2, page.Height.Value / 2);
                gfx.RotateTransform(-Math.Atan(page.Height.Value / page.Width.Value) * 180 / Math.PI);
                gfx.TranslateTransform(-page.Width.Value / 2, -page.Height.Value / 2);
                var format = new XStringFormat();
                format.Alignment = XStringAlignment.Near;
                format.LineAlignment = XLineAlignment.Near;
                gfx.DrawString(watermarkText, font, brush, new XPoint((page.Width.Value - size.Width) / 2, (page.Height.Value - size.Height) / 2), format);
            }

            originalPdf.Save(target, false);
        }
开发者ID:HedinRakot,项目名称:KVS,代码行数:26,代码来源:PDFSharpUtil.cs

示例9: DrawString

 /// <summary>
 /// Draws the specified text string.
 /// </summary>
 public void DrawString(string s, XFont font, XBrush brush, RectangleF layoutRectangle, XStringFormat format)
 {
   DrawString(s, font, brush, new XRect(layoutRectangle), format);
 }
开发者ID:Davincier,项目名称:openpetra,代码行数:7,代码来源:XGraphics.cs

示例10: RebuildCachedLayout

        private void RebuildCachedLayout(XGraphics graphics, Font font, ref Vector pos, ref Vector size, XStringFormat baseFormat)
        {
            // for diagnostic purposes
            ++s_rebuildCount;

            // store current settings to help us tell if we need a rebuild next time around
            m_requestedFormat = new XStringFormat();
            m_requestedFormat.Alignment = baseFormat.Alignment;
            m_requestedFormat.FormatFlags = baseFormat.FormatFlags;
            m_requestedFormat.LineAlignment = baseFormat.LineAlignment;
            m_actualFormat = new XStringFormat();
            m_actualFormat.Alignment = baseFormat.Alignment;
            m_actualFormat.FormatFlags = baseFormat.FormatFlags;
            m_actualFormat.LineAlignment = baseFormat.LineAlignment;
            m_pos = pos;
            m_size = size;

            var text = m_text;
            if (text.IndexOf('\n') == -1 && size.X > 0 && size.Y > 0 && graphics.MeasureString(text, font).Width > size.X)
            {
                // wrap single-line text to fit in rectangle

                // measure a space, countering the APIs unwillingness to measure spaces
                var spaceLength = (float)(graphics.MeasureString("M M", font).Width - graphics.MeasureString("M", font).Width * 2);

                var words = new List<Word>();
                foreach (var word in text.Split(' '))
                {
                    if (words.Count != 0)
                    {
                        words.Add(new Word(" ", spaceLength));
                    }
                    words.Add(new Word(word, (float)graphics.MeasureString(word, font).Width));
                }

                var lineLength = 0.0f;
                var total = string.Empty;
                var line = string.Empty;

                foreach (var word in words)
                {
                    if (word.Text != " " && word.Length > Math.Max(0, size.X - lineLength) && lineLength > 0)
                    {
                        if (line.Length > 0)
                        {
                            if (total.Length > 0)
                            {
                                total += "\n";
                            }
                            total += line;
                            lineLength = word.Length + spaceLength;
                            line = word.Text;
                        }
                    }
                    else
                    {
                        line += word.Text;
                        lineLength += word.Length + spaceLength;
                    }
                }

                if (line.Length > 0)
                {
                    if (total.Length > 0)
                    {
                        total += "\n";
                    }
                    total += line;
                }

                text = total;
            }

            m_lineHeight = font.GetHeight();

            m_lines.Clear();
            m_lines.AddRange(text.Split('\n'));

            switch (m_actualFormat.LineAlignment)
            {
                case XLineAlignment.Near:
                default:
                    m_origin = pos;
                    m_delta = new Vector(0, m_lineHeight);
                    break;
                case XLineAlignment.Far:
                    m_origin = new Vector(pos.X, pos.Y + size.Y - m_lineHeight);
                    if (size.Y > 0)
                    {
                        var count = m_lines.Count;
                        while (m_origin.Y - m_lineHeight >= pos.Y && --count > 0)
                        {
                            m_origin.Y -= m_lineHeight;
                        }
                    }
                    else
                    {
                        m_origin.Y -= (m_lines.Count - 1) * m_lineHeight;
                    }
                    m_delta = new Vector(0, m_lineHeight);
//.........这里部分代码省略.........
开发者ID:ChrisPC,项目名称:trizbort,代码行数:101,代码来源:TextBlock.cs

示例11: Draw

        /// <summary>
        /// Draw a multi-line string as it would be drawn by GDI+.
        /// Compensates for issues and draw-vs-PDF differences in PDFsharp.
        /// </summary>
        /// <param name="graphics">The graphics with which to draw.</param>
        /// <param name="text">The text to draw, which may contain line breaks.</param>
        /// <param name="font">The font with which to draw.</param>
        /// <param name="brush">The brush with which to draw.</param>
        /// <param name="pos">The position at which to draw.</param>
        /// <param name="size">The size to which to limit the drawn text; or Vector.Zero for no limit.</param>
        /// <param name="format">The string format to use.</param>
        /// <remarks>
        /// PDFsharp cannot currently render multi-line text to PDF files; it comes out as single line.
        /// This method simulates standard Graphics.DrawString() over PDFsharp.
        /// It always has the effect of StringFormatFlags.LineLimit (which PDFsharp does not support).
        /// </remarks>
        public void Draw(XGraphics graphics, Font font, Brush brush, Vector pos, Vector size, XStringFormat format)
        {
            // do a quick test to see if text is going to get drawn at the same size as last time;
            // if so, assume we don't need to recompute our layout for that reason.
            var sizeChecker = graphics.MeasureString("M q", font);
            if (sizeChecker != m_sizeChecker || pos != m_pos || m_size != size || m_requestedFormat.Alignment != format.Alignment || m_requestedFormat.LineAlignment != format.LineAlignment || m_requestedFormat.FormatFlags != format.FormatFlags)
            {
                m_invalidLayout = true;
            }
            m_sizeChecker = sizeChecker;

            if (m_invalidLayout)
            {
                // something vital has changed; rebuild our cached layout data
                RebuildCachedLayout(graphics, font, ref pos, ref size, format);
                m_invalidLayout = false;
            }

            var state = graphics.Save();
            if (size != Vector.Zero)
            {
                graphics.IntersectClip(new RectangleF(pos.X, pos.Y, size.X, size.Y));
            }

            // disable smoothing whilst rendering text;
            // visually this is no different, but is faster
            var smoothingMode = graphics.SmoothingMode;
            graphics.SmoothingMode = XSmoothingMode.HighSpeed;

            var origin = m_origin;
            for (var index=0; index<m_lines.Count; ++index)
            {
                if (size.Y > 0 && size.Y < m_lineHeight)
                    break; // not enough remaining vertical space for a whole line

                var line = m_lines[index];

                graphics.DrawString(line, font, brush, origin.X, origin.Y, m_actualFormat);
                origin += m_delta;
                size.Y -= m_lineHeight;
            }

            graphics.SmoothingMode = smoothingMode;
            graphics.Restore(state);
        }
开发者ID:ChrisPC,项目名称:trizbort,代码行数:61,代码来源:TextBlock.cs

示例12: Main

    static void Main()
    {
      const string watermark = "PDFsharp";
      const int emSize = 150;

      // Get a fresh copy of the sample PDF file
      const string filename = "Portable Document Format.pdf";
      File.Copy(Path.Combine("../../../../../PDFs/", filename),
        Path.Combine(Directory.GetCurrentDirectory(), filename), true);

      // Create the font for drawing the watermark
      XFont font = new XFont("Times New Roman", emSize, XFontStyle.BoldItalic);

      // Open an existing document for editing and loop through its pages
      PdfDocument document = PdfReader.Open(filename);

      // Set version to PDF 1.4 (Acrobat 5) because we use transparency.
      if (document.Version < 14)
        document.Version = 14;

      for (int idx = 0; idx < document.Pages.Count; idx++)
      {
        //if (idx == 1) break;
        PdfPage page = document.Pages[idx];

        switch (idx % 3)
        {
          case 0:
            {
              // Variation 1: Draw watermark as text string

              // Get an XGraphics object for drawing beneath the existing content
              XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Prepend);

#if true_
            // Fill background with linear gradient color
            XRect rect = page.MediaBox.ToXRect();
            XLinearGradientBrush gbrush = new XLinearGradientBrush(rect,
              XColors.LightSalmon, XColors.WhiteSmoke, XLinearGradientMode.Vertical);
            gfx.DrawRectangle(gbrush, rect);
#endif

              // Get the size (in point) of the text
              XSize size = gfx.MeasureString(watermark, font);

              // Define a rotation transformation at the center of the page
              gfx.TranslateTransform(page.Width / 2, page.Height / 2);
              gfx.RotateTransform(-Math.Atan(page.Height / page.Width) * 180 / Math.PI);
              gfx.TranslateTransform(-page.Width / 2, -page.Height / 2);

              // Create a string format
              XStringFormat format = new XStringFormat();
              format.Alignment = XStringAlignment.Near;
              format.LineAlignment = XLineAlignment.Near;

              // Create a dimmed red brush
              XBrush brush = new XSolidBrush(XColor.FromArgb(128, 255, 0, 0));

              // Draw the string
              gfx.DrawString(watermark, font, brush,
                new XPoint((page.Width - size.Width) / 2, (page.Height - size.Height) / 2),
                format);
            }
            break;

          case 1:
            {
              // Variation 2: Draw watermark as outlined graphical path

              // Get an XGraphics object for drawing beneath the existing content
              XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Prepend);

              // Get the size (in point) of the text
              XSize size = gfx.MeasureString(watermark, font);

              // Define a rotation transformation at the center of the page
              gfx.TranslateTransform(page.Width / 2, page.Height / 2);
              gfx.RotateTransform(-Math.Atan(page.Height / page.Width) * 180 / Math.PI);
              gfx.TranslateTransform(-page.Width / 2, -page.Height / 2);

              // Create a graphical path
              XGraphicsPath path = new XGraphicsPath();

              // Add the text to the path
              path.AddString(watermark, font.FontFamily, XFontStyle.BoldItalic, 150,
                new XPoint((page.Width - size.Width) / 2, (page.Height - size.Height) / 2),
                XStringFormats.Default);

              // Create a dimmed red pen
              XPen pen = new XPen(XColor.FromArgb(128, 255, 0, 0), 2);

              // Stroke the outline of the path
              gfx.DrawPath(pen, path);
            }
            break;

          case 2:
            {
              // Variation 3: Draw watermark as transparent graphical path above text

//.........这里部分代码省略.........
开发者ID:vronikp,项目名称:EventRegistration,代码行数:101,代码来源:Program.cs

示例13: watermarkprint

        static void watermarkprint(XGraphics gfx, PdfPage page, XFont font)
        {
            string watermark = "TestME";

            // Get the size (in point) of the text
            XSize size = gfx.MeasureString(watermark, font);

            // Define a rotation transformation at the center of the page
            gfx.TranslateTransform(page.Width / 2, page.Height / 2);
            gfx.RotateTransform(-Math.Atan(page.Height / page.Width) * 180 / Math.PI);
            gfx.TranslateTransform(-page.Width / 2, -page.Height / 2);

            // Create a string format
            XStringFormat format = new XStringFormat();
            format.Alignment = XStringAlignment.Near;
            format.LineAlignment = XLineAlignment.Near;

            // Create a dimmed red brush
            XBrush brush = new XSolidBrush(XColor.FromArgb(60, 128, 125, 123));

            // Draw the string
            gfx.DrawString(watermark, font, brush,
              new XPoint((page.Width - size.Width) / 2, (page.Height - size.Height) / 2),
              format);
        }
开发者ID:Hli4S,项目名称:TestMeApp,代码行数:25,代码来源:SavePDF.cs

示例14: DrawString

    /// <summary>
    /// Draws the text.
    /// </summary>
    /// <param name="text">The text to be drawn.</param>
    /// <param name="font">The font.</param>
    /// <param name="brush">The text brush.</param>
    /// <param name="layoutRectangle">The layout rectangle.</param>
    /// <param name="format">The format. Must be <c>XStringFormat.TopLeft</c></param>
    public void DrawString(string text, XFont font, XBrush brush, XRect layoutRectangle, XStringFormat format)
    {
      if (text == null)
        throw new ArgumentNullException("text");
      if (font == null)
        throw new ArgumentNullException("font");
      if (brush == null)
        throw new ArgumentNullException("brush");
      if (format.Alignment != XStringAlignment.Near || format.LineAlignment!= XLineAlignment.Near)
        throw new ArgumentException("Only TopLeft alignment is currently implemented.");

      Text = text;
      Font = font;
      LayoutRectangle = layoutRectangle;

      if (text.Length == 0)
        return;

      CreateBlocks();
      
      CreateLayout();

      double dx = layoutRectangle.Location.x;
      double dy = layoutRectangle.Location.y + cyAscent;
      int count = this.blocks.Count;
      for (int idx = 0; idx < count; idx++)
      {
        Block block = (Block)this.blocks[idx];
        if (block.Stop)
          break;
        if (block.Type == BlockType.LineBreak)
          continue;
        gfx.DrawString(block.Text, font, brush, dx + block.Location.x, dy + block.Location.y);
      }
    }
开发者ID:bossaia,项目名称:alexandrialibrary,代码行数:43,代码来源:XTextFormatter.cs

示例15: DrawText

        /// <summary>
        /// Draws the text.
        /// </summary>
        /// <param name="p">The p.</param>
        /// <param name="text">The text.</param>
        /// <param name="fill">The fill color.</param>
        /// <param name="fontFamily">The font family.</param>
        /// <param name="fontSize">Size of the font.</param>
        /// <param name="fontWeight">The font weight.</param>
        /// <param name="rotate">The rotation angle.</param>
        /// <param name="halign">The horizontal alignment.</param>
        /// <param name="valign">The vertical alignment.</param>
        /// <param name="maxSize">The maximum size of the text.</param>
        public override void DrawText(
            ScreenPoint p,
            string text,
            OxyColor fill,
            string fontFamily,
            double fontSize,
            double fontWeight,
            double rotate,
            HorizontalAlignment halign,
            VerticalAlignment valign,
            OxySize? maxSize)
        {
            if (text == null)
            {
                return;
            }

            var fs = XFontStyle.Regular;
            if (fontWeight > FontWeights.Normal)
            {
                fs = XFontStyle.Bold;
            }

            var font = new XFont(fontFamily, (float)fontSize * FontsizeFactor, fs);

            var size = this.g.MeasureString(text, font);

#if SILVERLIGHT
            // Correct the height, MeasureString returns 2x height
            size.Height *= 0.5;
#endif

            if (maxSize != null)
            {
                if (size.Width > maxSize.Value.Width)
                {
                    size.Width = Math.Max(maxSize.Value.Width, 0);
                }

                if (size.Height > maxSize.Value.Height)
                {
                    size.Height = Math.Max(maxSize.Value.Height, 0);
                }
            }

            double dx = 0;
            if (halign == HorizontalAlignment.Center)
            {
                dx = -size.Width / 2;
            }

            if (halign == HorizontalAlignment.Right)
            {
                dx = -size.Width;
            }

            double dy = 0;

            if (valign == VerticalAlignment.Middle)
            {
                dy = -size.Height / 2;
            }

            if (valign == VerticalAlignment.Bottom)
            {
                dy = -size.Height;
            }

            var state = this.g.Save();
            this.g.TranslateTransform(dx, dy);
            if (Math.Abs(rotate) > double.Epsilon)
            {
                this.g.RotateAtTransform((float)rotate, new XPoint((float)p.X + (float)(size.Width / 2.0), (float)p.Y));
            }

            this.g.TranslateTransform((float)p.X, (float)p.Y);

            var layoutRectangle = new XRect(0, 0, size.Width, size.Height);
            var sf = new XStringFormat { Alignment = XStringAlignment.Near, LineAlignment = XLineAlignment.Near };
            this.g.DrawString(text, font, ToBrush(fill), layoutRectangle, sf);
            this.g.Restore(state);
        }
开发者ID:benjaminrupp,项目名称:oxyplot,代码行数:95,代码来源:PdfRenderContext.cs


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