Author: kagula
Date: 2015-10-08
问题分析:
怀疑是逻辑单位打印,Windows Driver自动转物理单位时精度损失,后把映射模式从0.1mm为单位改为物理单位,问题解决。
//现在需要切换到物理坐标,否则打印条码由于线条太模糊会扫不出来。
//因为每10英寸对应254毫米,计算出每0.1mm对应多少物理单位点。
SetMapMode(printcd, MM_TEXT);
//http://blog.sciencenet.cn/blog-244606-747345.html
double fDPIX = (double)GetDeviceCaps(printcd.GetSafeHdc(), LOGPIXELSX)/254;
double fDPIY = (double)GetDeviceCaps(printcd.GetSafeHdc(), LOGPIXELSY)/254;
RECT region;
region.left = x;
region.right = region.left + body.GetBarcode_width();
region.top = y;
region.bottom = region.top + body.GetBarcode_height();
//0.1mm为单位转为物理单位
region.left = region.left * fDPIX;
region.right = region.right * fDPIX;
region.top = region.top * fDPIY;
region.bottom = region.bottom * fDPIY;
//调用普通的绘图程序,绘制条码。
CCode93 objCode93;
objCode93.DrawBarcode(printcd.GetSafeHdc(),body.GetBarcode_content(),region);
//恢复为逻辑坐标,因为其它元素的打印不需要高精度。
SetMapMode(printcd, MM_LOMETRIC);//0.1 mm