【问题】用Microsoft Edge使用自己实现的虚拟打印机(Unidrv)打印页面到PDF,图片特别小,但是用IE打印就正常。
【分析】 Debug发现:用IE打印图片进OEMStretchBlt函数,但是用Edge打印图片进的是OEMPlgBlt函数,oemuni用的是目标的区域,而后者的目标区域是一个平行四边形,而且目标区域的类型是POINTFIX。维基一下,Fixed point是用整形表示浮点型,所以需要知道小数部分占几位,再查看DDK,是28.4,所以小数部分占4位,得到的这个值需要除以16,才能换算到整数部分。
维基:https://en.wikipedia.org/wiki/Fixed-point_arithmetic
DDK:FIX Coordinates
GraphicsDDIs use fractional coordinates that can specify a location on the devicesurface within one-sixteenth of a pixel. (On vector devices, the fractionalcoordinates are sixteen times more accurate than the device resolution.) Thefractional coordinates are represented as 32-bit numbers in signed 28.4 bit FIX notation. In this notation, the highest-order28 bits represent the integer part of the coordinate, and the lowest 4 bitsrepresent the fractional part. For example, 0x0000003C equals +3.7500, and0xFFFFFFE8 equals -1.5000.
FIXcoordinates represent control points for lines and Bezier curves. For certainobjects, such as rectangular clip regions, GDI uses signed 32-bit integers torepresent coordinates. Because coordinates are 28-bit quantities, the highest 5bits of an integer coordinate are either all cleared or all set.
【解决办法】
if (pco->iDComplexity==DC_RECT)
{
//28.4 fix point
rtlDes.left = LONG(pptfixDest[0].x / 16.0 + 0.5);
rtlDes.top = LONG(pptfixDest[0].y / 16.0 + 0.5);
rtlDes.right = LONG(pptfixDest[1].x / 16.0 + 0.5);
rtlDes.bottom = LONG(pptfixDest[2].y / 16.0 + 0.5);
}