When processing printing, sometimes calculate the paging situation in advance, or the area border is performed on the report header, which is to calculate the tightening of the text in advance (before actual output). The practice is to select the font of the text into the DC, then remove the TextMetric from the DC, and then remove the word height and spacing from it. When actually output (print or preview), the row is recalculated again to output (using Textout requires area parameters).
Discovery Problem: When output to the dialog (implementation print preview), the re-computational row is different from the high calculation line. Thus, the positioning is not allowed (if the calculation is small before, the contents in the table are stacked, because the position of each part is used to calculate the calculated value before the actual output.)
Check it carefully and discovered the cause of the problem: A: When the first calculation: is the DC of the printer according to the current printer, then select the corresponding font into the DC, and finally remove the TextMetric from the DC, calculate the height. B: When the actual preview box is output: Take the DC of the preview dialog and set the mapping mode for mm_anisotropic (for the preview scaling), the proportion sets the initial value according to the size of the page (uncertain, such as 0.6), It can be arbitrarily specified by the user, and the font is selected into the DC in the program, and then the TextMetric is removed from the DC and finally specifies the output area according to the high degree of highness at this time.
The problem is here: A, B calculate the high value different. When the value of 1 is obviously less than 2, the display misalignment (superior) is inevitable.
Cause Analysis: Testing found that even the same font settings are selected in the same manner, the TextMetric taken out from the DC will be slightly different. Differences are generated as follows: 1: The DC of the print DC and the normal form will have a small difference. 2: Set the mapping mode to mm_anisotropic, then set different ratio values, there will be more than 1 greater difference. (The reason for the error is more this)
Workaround: 1: Taking the calculated value of the print DC to specify the output area when the actual output is specified, of course, if the value is very different, the output may have problems, such as: actual output value is much greater than before calculating incomplete display. 2: After calculating delay, use the actual high value when the actual output is used. Of course, this will cause the problem logic.
Note: The method of selecting font to DC is: cfontholder.select, Cylogical and Cyhimetric values are fixed by 254 and 2540.
Why does this difference that does not find a related explanation in MSDN.