E
Eric Eggermann
Hello all,
I'm building an app that lays out and prints flash cards. Now the card might
be any size, but when the user is working on the card, I draw the preview
isotropically, as large as possible. The user specifies a font size for the
document, but I need to scale this for the preview.
The scaling code I have is very close but not right. I can only notice that
it's wrong occasionally when I have a piece of text that wraps, and the wrap
occurs at a different place in the printed output than in the preview. I
need to make my preview jive with the output. One more thing, the preview
seems to always be on the small side.
Pseudo code is like this
Convert the size of the actual card from hundreths of an inch to pixels
Divide the width and height of the preview rectangle by their respective
values in the size derived above, and use the lesser of those
two values as the scale.
Determine the scaled font size by multiplying the user selected font
size by the scale factor determined above, and create a new font with
this new size, and draw the text.
Here's the relevant code mashed into a straight line.
//Get the size of the card in hundreths of an inch
SizeF cardUnitSize = PaperType.CardSizein;
if(isLandscape)
{
//switch around the cardUnitSize values
float temp;
temp = cardUnitSize.Height;
cardUnitSize.Height = cardUnitSize.Width;
cardUnitSize.Width = temp;
}
SizeF screenSize = new SizeF(cardUnitSize.Width / 100 * grfx.DpiX,
cardUnitSize.Height / 100 * grfx.DpiY);
float scale = Math.Min(this.Parent.PreviewRect.Size.Width /
cardUnitSize.Width,
this.Parent.PreviewRect.Size.Height / cardUnitSize.Height);
float scaleSize = font.SizeInPoints * scale;
textFont = new Font(font.FontFamily,
scaleSize,
font.Style);
grfx.DrawString(strContent, textFont, txtBrush, rectDest, strFmt);
I've also mucked about with the PageScale, and ScaleTransform properties,
and managed to do no better. Any ideas?
TIA
Eric
I'm building an app that lays out and prints flash cards. Now the card might
be any size, but when the user is working on the card, I draw the preview
isotropically, as large as possible. The user specifies a font size for the
document, but I need to scale this for the preview.
The scaling code I have is very close but not right. I can only notice that
it's wrong occasionally when I have a piece of text that wraps, and the wrap
occurs at a different place in the printed output than in the preview. I
need to make my preview jive with the output. One more thing, the preview
seems to always be on the small side.
Pseudo code is like this
Convert the size of the actual card from hundreths of an inch to pixels
Divide the width and height of the preview rectangle by their respective
values in the size derived above, and use the lesser of those
two values as the scale.
Determine the scaled font size by multiplying the user selected font
size by the scale factor determined above, and create a new font with
this new size, and draw the text.
Here's the relevant code mashed into a straight line.
//Get the size of the card in hundreths of an inch
SizeF cardUnitSize = PaperType.CardSizein;
if(isLandscape)
{
//switch around the cardUnitSize values
float temp;
temp = cardUnitSize.Height;
cardUnitSize.Height = cardUnitSize.Width;
cardUnitSize.Width = temp;
}
SizeF screenSize = new SizeF(cardUnitSize.Width / 100 * grfx.DpiX,
cardUnitSize.Height / 100 * grfx.DpiY);
float scale = Math.Min(this.Parent.PreviewRect.Size.Width /
cardUnitSize.Width,
this.Parent.PreviewRect.Size.Height / cardUnitSize.Height);
float scaleSize = font.SizeInPoints * scale;
textFont = new Font(font.FontFamily,
scaleSize,
font.Style);
grfx.DrawString(strContent, textFont, txtBrush, rectDest, strFmt);
I've also mucked about with the PageScale, and ScaleTransform properties,
and managed to do no better. Any ideas?
TIA
Eric