View previous topic :: View next topic |
Author |
Message |
AFin
Joined: 13 Feb 2007 Posts: 2
|
Posted: 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? |
|
Back to top |
|
|
Stefan Lange
Joined: 12 Oct 2006 Posts: 47 Location: Cologne, Germany
|
Posted: 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. |
|
Back to top |
|
|
thorstenw
Joined: 09 May 2007 Posts: 2
|
Posted: 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 |
|
Back to top |
|
|
thorstenw
Joined: 09 May 2007 Posts: 2
|
Posted: 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
|
|
Back to top |
|
|
Rusty_Adams
Joined: 23 May 2007 Posts: 1 Location: Stockport, UK
|
Posted: Wed May 23, 2007 9:04 pm Post subject: |
|
|
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 |
|
|
|