PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 7:37 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: XTextFormatter
PostPosted: Tue Feb 13, 2007 11:46 am 
Offline

Joined: Tue Feb 13, 2007 11:27 am
Posts: 2
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?


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Mar 08, 2007 11:35 pm 
Offline
empira Employee
User avatar

Joined: Thu Oct 12, 2006 10:07 pm
Posts: 49
Location: Cologne, Germany
>>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.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed May 09, 2007 2:08 pm 
Offline

Joined: Wed May 09, 2007 2:05 pm
Posts: 2
Hi,

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

Could anybody please help me?!

best regards
t


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed May 09, 2007 3:20 pm 
Offline

Joined: Wed May 09, 2007 2:05 pm
Posts: 2
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)


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed May 23, 2007 9:04 pm 
Offline

Joined: Wed May 23, 2007 9:00 pm
Posts: 1
Location: Stockport, UK
thorstenw,

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

_________________
All work and no play makes Rusty a dull boy


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 139 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group