PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index PDFsharp - moved to http://forum.pdfsharp.net/
Please visit the new PDFsharp forum at http://forum.pdfsharp.net/
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

XTextFormatter

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index -> Support - moved to http://forum.pdfsharp.net/
View previous topic :: View next topic  
Author Message
AFin



Joined: 13 Feb 2007
Posts: 2

PostPosted: Tue Feb 13, 2007 11:46 am    Post subject: XTextFormatter Reply with quote

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?
Back to top
View user's profile Send private message
Stefan Lange



Joined: 12 Oct 2006
Posts: 47
Location: Cologne, Germany

PostPosted: Thu Mar 08, 2007 11:35 pm    Post subject: Reply with quote

>>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.
Back to top
View user's profile Send private message Send e-mail
thorstenw



Joined: 09 May 2007
Posts: 2

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

Hi,

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

Could anybody please help me?!

best regards
t
Back to top
View user's profile Send private message
thorstenw



Joined: 09 May 2007
Posts: 2

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

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

Cool
Back to top
View user's profile Send private message
Rusty_Adams



Joined: 23 May 2007
Posts: 1
Location: Stockport, UK

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

thorstenw,

Since writing this code, how reliable have you found it to be?
_________________
All work and no play makes Rusty a dull boy
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index -> Support - moved to http://forum.pdfsharp.net/ All times are GMT
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © phpBB Group. Hosted by phpBB.BizHat.com


Start Your Own YouTube Clone

Free Web Hosting | Free Forum Hosting | FlashWebHost.com | Image Hosting | Photo Gallery | FreeMarriage.com

Powered by PhpBBweb.com, setup your forum now!
For Support, visit Forums.BizHat.com