Click here to Skip to main content
15,919,178 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: help needed Pin
YaronNir10-Oct-03 5:30
YaronNir10-Oct-03 5:30 
GeneralRe: help needed Pin
Joaquín M López Muñoz12-Oct-03 19:55
Joaquín M López Muñoz12-Oct-03 19:55 
GeneralRe: help needed Pin
YaronNir11-Oct-03 8:23
YaronNir11-Oct-03 8:23 
GeneralQuestion about "!". Pin
esepich9-Oct-03 10:14
esepich9-Oct-03 10:14 
GeneralRe: Question about "!". Pin
W. Hammer -sledge-9-Oct-03 10:23
W. Hammer -sledge-9-Oct-03 10:23 
GeneralRe: Question about "!". Pin
DougW489-Oct-03 10:25
DougW489-Oct-03 10:25 
GeneralCan't use C# dll in MFC - Program won't run. Pin
IrishSonic9-Oct-03 10:02
IrishSonic9-Oct-03 10:02 
GeneralWYSIWYG Printing Pin
Larry J. Siddens9-Oct-03 9:48
Larry J. Siddens9-Oct-03 9:48 
As most of you know, I have been trying to do WYSIWYG printing from a CRichEditCtrl. The problems I was having was that the font bring printed was either too big or too small for the perscribed area.

OK, here is some what of a solution (except it isn't bullet proof!)

I create a device context to the display (while printing and in print preview), create the font scaled to the display and scaled to the printer. I then get the size of the line for each. I then calculate the scaling factor by getting the pixels in the X axis for both and dividing. For the printer here at work, it is 1200DPI, and the screen is 96DPI. This factor works out to be 12.5.

I then take the text width on the screen and multiply it by this ratio to
get an ideal output width. Divide the printer width by the ideal width that gives a ratio. I then get the average character width (from
GetTextMetrics - Printer). I then multiply this value with the ration from the ideal vs. actual printer. Then set this value in the LOGFONT.lfWidth and create a new font and select it into the printer device context.

As an example:
The width of text on the display is 410 pixels, this same string on the
printer (with no change in the character width) is 5352. The scaling factor of 12.5 means that the ideal lenght is 5112.5 pixels. The division of the Printer/Ideal = 1.066146. The average character width for the printer (with selected font) is 80 pixels. So, divide the 80 / 1.066... and the new character width is 75.

I read in Petzold's book that the lfWidth of the LOGFONT can be set to the tmAvgCharWidth from the TEXTMETRIC structure. AND, that it can be scaled.

The resulting output for the TIMES NEW ROMAN 12/10pt and COURIER NEW 12/10pt are right on (with the exception of a rounding error of a pixel). I do this for each line.

Now the caveat! When I use Arial Normal, the last line which isn't as long as the rest, and this creates an average character width is bigger than the previous lines.

I think there is something in the TrueType specification that can help with this. Does anyone know? If so, what?


Larry J. Siddens
Cornerstone Communications

TAME THE DOCUMENT MONSTER
www.unifier.biz



GeneralfImagelist from files Pin
santu9-Oct-03 8:56
santu9-Oct-03 8:56 
General"Transparent" Control Pin
User-3779369-Oct-03 8:32
User-3779369-Oct-03 8:32 
GeneralRe: "Transparent" Control Pin
YaronNir9-Oct-03 11:06
YaronNir9-Oct-03 11:06 
GeneralRe: "Transparent" Control Pin
YaronNir9-Oct-03 11:08
YaronNir9-Oct-03 11:08 
GeneralRe: "Transparent" Control Pin
User-3779369-Oct-03 22:46
User-3779369-Oct-03 22:46 
QuestionDisassembly to Source Code??? Pin
MrGee9-Oct-03 8:08
MrGee9-Oct-03 8:08 
AnswerRe: Disassembly to Source Code??? Pin
Michael Dunn9-Oct-03 8:17
sitebuilderMichael Dunn9-Oct-03 8:17 
QuestionSaving multiple RTFs to string for storage? Pin
Kayembi9-Oct-03 7:27
Kayembi9-Oct-03 7:27 
AnswerRe: Saving multiple RTFs to string for storage? Pin
John M. Drescher9-Oct-03 7:51
John M. Drescher9-Oct-03 7:51 
Questionmfc42u.lib ? Pin
spiritualfields9-Oct-03 5:39
spiritualfields9-Oct-03 5:39 
AnswerRe: mfc42u.lib ? Pin
W. Hammer -sledge-9-Oct-03 6:04
W. Hammer -sledge-9-Oct-03 6:04 
AnswerRe: mfc42u.lib ? Pin
Garth J Lancaster9-Oct-03 17:49
professionalGarth J Lancaster9-Oct-03 17:49 
AnswerRe: mfc42u.lib ? Pin
speedo21shree14-Oct-10 23:11
speedo21shree14-Oct-10 23:11 
GeneralC to C++ link error Pin
jimNLX9-Oct-03 5:05
jimNLX9-Oct-03 5:05 
GeneralRe: C to C++ link error Pin
Joaquín M López Muñoz9-Oct-03 7:51
Joaquín M López Muñoz9-Oct-03 7:51 
GeneralRe: C to C++ link error Pin
jimNLX9-Oct-03 7:57
jimNLX9-Oct-03 7:57 
GeneralRe: C to C++ link error Pin
jimNLX9-Oct-03 8:02
jimNLX9-Oct-03 8:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.