PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

XTextFormatter
https://forum.pdfsharp.net/viewtopic.php?f=2&t=77
Page 1 of 1

Author:  AFin [ Tue Feb 13, 2007 11:46 am ]
Post subject:  XTextFormatter

Is there any way of using the XTextFormatter class to determine how high a XRect object should be? For example, I am taking a paragraph from a database, and need to render it to the page. I don't know how big to make the rect object. If I feed mystery function xyz the text and the width of the rect, can it return the height of the rect I need?

Any suggestions on how I can do this?

Also, is there a way of rotating the text 90 degrees so that it prints vertically?

Author:  Stefan Lange [ Thu Mar 08, 2007 11:35 pm ]
Post subject: 

>>Any suggestions on how I can do this?
Extend the class XTextFormatter, this is simple.

>>Also, is there a way of rotating the text 90 degrees so that it prints vertically?

Yes, use XGraphics.RotateTransform.

Author:  thorstenw [ Wed May 09, 2007 2:08 pm ]
Post subject: 

Hi,

sorry, i can't find a way to get the Height of a Text-Rect.

Could anybody please help me?!

best regards
t

Author:  thorstenw [ Wed May 09, 2007 3:20 pm ]
Post subject: 

i think i got it...

Code:
      /// <summary>
      /// finds out the height of a textrect by giving the width.
      /// </summary>
      /// <param name="text">The text</param>
      /// <param name="font">The font.</param>
      /// <param name="rectWidth">The width of the textrect.</param>
      public double getTextRectHeight(string text, XFont font, double rectWidth)
      {
          Text = text;
          Font = font;
          CreateBlocks();

          double rectHeight = this.cyAscent + this.cyDescent;
          int firstIndex = 0;
          double x = 0, y = 0;
          int count = this.blocks.Count;
          for (int idx = 0; idx < count; idx++)
          {
              Block block = (Block)this.blocks[idx];
              if (block.Type == BlockType.LineBreak)
              {
                  firstIndex = idx + 1;
                  x = 0;
                  y += this.lineSpace;
              }
              else
              {
                  double width = this.spaceWidth + block.Width;
                  if ((x + width <= rectWidth || x == 0) && block.Type != BlockType.LineBreak)
                  {
                      block.Location = new XPoint(x, y);
                      x += width;
                  }
                  else
                  {
                      firstIndex = idx;
                      y += this.lineSpace;
                      block.Location = new XPoint(0, y);
                      x = width;
                  }
              }
          }

          return rectHeight + y;
      }


i just copied and modified the code of the CreateLayout-Function and tested it with the TextLayout-Example ... and it seems to work

8)

Author:  Rusty_Adams [ Wed May 23, 2007 9:04 pm ]
Post subject: 

thorstenw,

Since writing this code, how reliable have you found it to be?

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/