楼主的代码写的很pl,不错,值得赞扬

解决方案 »

  1.   

    谢谢楼上的赞扬。感觉v:line不好解决,还要考虑没线得中心线坐标,
    即使是点(1,1)--点(1,9) 宽度1,其区域也是[(0.5,1),(1.5,9)],出现半个px就麻烦了用没有边框的v:rect好像可以起到替代作用,暂时觉得还行,连放大图片缩小显示都作用不大了.自己修改后的方法,供参考://创建条码信息
    VmlCard.prototype.createBarcode = function(bL,bT,str,bartype,h,n,b,o){
    //默认值设置 bL,bT为条码区域在卡片中的坐标(竖向条码时坐标为中心位置?) 必需
    if(o==undefined) o=0; //方向 0-正常 1-∠90 2-∠180 3-∠270
    if(b==undefined) b=2; //宽线条宽度 px
    if(n==undefined) n=1; //窄线条宽度 px
    if(h==undefined) h=20; //条码高度 px
    if(bartype==undefined) bartype = "CODE39";  //条码类型 现在有 ITF25 和 CODE39 两种
    eval("var prn = "+bartype+"(str.toUpperCase());"); var shape_h = h;
    var shape_w = 10;  //留一点点空隙,不让最后条码意外超出范围 好像理想状态不需要
    for(var i=0;i<prn.length;i++){
    shape_w += ((prn.charAt(i)=="0")?n:b);
    }
    var shapObj = document.createElement("<v:group style=\"position:absolute;top:"+bT+";left:"+bL+";width:"+shape_w+"px;height:"+shape_h+"px;\" coordsize=\""+shape_w+","+shape_h+"\" />"); var rect_rl = new Point(0.0,0.0);
    for(var i=0;i<prn.length;i++){
    var wt = ((prn.charAt(i)=="0")?n:b);
    if(i%2==0){
    shapObj.insertBefore(document.createElement("<v:Rect fillcolor=black stroked='f' style=\"position:absolute;top:"+rect_rl.y+";left:"+rect_rl.x+";width:"+wt+";height:"+h+"\"/>"));
    }
    rect_rl.moveX(wt);
    } this.group.insertBefore(shapObj);
    shapObj.Rotation = 90*o;
    }