Esempio n. 1
0
def RoundRect(ctx, page, i):
    cy, cx, y2, x2, y1, x1 = page.cmds[i].args
    x1, y1 = wmfdraw.convcoords(page, ctx, x1, y1)
    x2, y2 = wmfdraw.convcoords(page, ctx, x2, y2)
    if x1 > x2:
        x = x1
        x1 = x2
        x2 = x
    if y1 > y2:
        x = y1
        y1 = y2
        y2 = x
    cx = cx * 1. / page.DCs[page.curdc].Wx
    cy = cy * 1. / page.DCs[page.curdc].Wy
    ctx.move_to(x1 + cx / 2., y1)
    ## here elliptical arc to next point (x2,y1+cy/2) xc = x2-cx/2., yc = y1+cy/2.  90 0
    xc = x1 + cx / 2.
    yc = y1 + cy / 2.
    ctx.save()
    m = cairo.Matrix(cx / 2., 0, 0, cy / 2., xc, yc)
    ctx.transform(m)
    ctx.arc_negative(0., 0., 1., -0.5 * math.pi, math.pi)
    ctx.restore()
    ctx.line_to(x1, y2 - cy / 2.)
    ## here elliptical arc to next point x2-cx/2. ,y2  xc = x2-cx/2.,yc=y2-cy/2.  0 -90
    xc = x1 + cx / 2.
    yc = y2 - cy / 2.
    ctx.save()
    ##    ctx.translate(xc,yc)
    ##    ctx.scale(cx/2., cy/2.)
    m = cairo.Matrix(cx / 2., 0, 0, cy / 2., xc, yc)
    ctx.transform(m)
    ctx.arc_negative(0., 0., 1., math.pi, 0.5 * math.pi)
    ctx.restore()
    ctx.line_to(x2 - cx / 2., y2)
    ##    ## here elliptical arc to next point x1,y2-cy/2.  xc = x1+cx/2.,yc=y2-cy/2.  -90  180
    xc = x2 - cx / 2.
    yc = y2 - cy / 2.
    ctx.save()
    ##    ctx.translate(xc,yc)
    ##    ctx.scale(cx/2., cy/2.)
    m = cairo.Matrix(cx / 2., 0, 0, cy / 2., xc, yc)
    ctx.transform(m)
    ctx.arc_negative(0., 0., 1., 0.5 * math.pi, 0)
    ctx.restore()
    ctx.line_to(x2, y1 + cy / 2.)
    ##    ## here elliptical arc to next point x1+cx/2,y1  xc = x1+cx/2.,yc=y1+cy/2.  180  90
    xc = x2 - cx / 2.
    yc = y1 + cy / 2.
    ctx.save()
    ##    ctx.translate(xc,yc)
    ##    ctx.scale(cx/2., cy/2.)
    m = cairo.Matrix(cx / 2., 0, 0, cy / 2., xc, yc)
    ctx.transform(m)
    ctx.arc_negative(0., 0., 1., 0, -0.5 * math.pi)
    ctx.restore()
    ctx.close_path()
    wmfdraw.FillPath(ctx, page, i)
    wmfdraw.StrokePath(ctx, page, i)
Esempio n. 2
0
def RoundRect(ctx,page,i):
    cy,cx,y2,x2,y1,x1 = page.cmds[i].args
    x1,y1 = wmfdraw.convcoords(page,ctx,x1,y1)
    x2,y2 = wmfdraw.convcoords(page,ctx,x2,y2)
    if x1 > x2:
        x = x1
        x1 = x2
        x2 = x
    if y1 > y2:
        x = y1
        y1 = y2
        y2 = x
    cx=cx*1./page.DCs[page.curdc].Wx
    cy=cy*1./page.DCs[page.curdc].Wy
    ctx.move_to(x1+cx/2.,y1)
    ## here elliptical arc to next point (x2,y1+cy/2) xc = x2-cx/2., yc = y1+cy/2.  90 0
    xc = x1+cx/2.
    yc = y1+cy/2.
    ctx.save()
    m = cairo.Matrix(cx/2.,0,0,cy/2.,xc,yc)
    ctx.transform(m)
    ctx.arc_negative(0.,0.,1.,-0.5*math.pi,math.pi)
    ctx.restore()
    ctx.line_to(x1,y2-cy/2.)
    ## here elliptical arc to next point x2-cx/2. ,y2  xc = x2-cx/2.,yc=y2-cy/2.  0 -90
    xc = x1+cx/2.
    yc = y2-cy/2.
    ctx.save()
##    ctx.translate(xc,yc)
##    ctx.scale(cx/2., cy/2.)
    m = cairo.Matrix(cx/2.,0,0,cy/2.,xc,yc)
    ctx.transform(m)
    ctx.arc_negative(0.,0.,1.,math.pi,0.5*math.pi)
    ctx.restore()
    ctx.line_to(x2-cx/2.,y2)
##    ## here elliptical arc to next point x1,y2-cy/2.  xc = x1+cx/2.,yc=y2-cy/2.  -90  180
    xc = x2-cx/2.
    yc = y2-cy/2.
    ctx.save()
##    ctx.translate(xc,yc)
##    ctx.scale(cx/2., cy/2.)
    m = cairo.Matrix(cx/2.,0,0,cy/2.,xc,yc)
    ctx.transform(m)
    ctx.arc_negative(0.,0.,1.,0.5*math.pi,0)
    ctx.restore()
    ctx.line_to(x2,y1+cy/2.)
##    ## here elliptical arc to next point x1+cx/2,y1  xc = x1+cx/2.,yc=y1+cy/2.  180  90
    xc = x2-cx/2.
    yc = y1+cy/2.
    ctx.save()
##    ctx.translate(xc,yc)
##    ctx.scale(cx/2., cy/2.)
    m = cairo.Matrix(cx/2.,0,0,cy/2.,xc,yc)
    ctx.transform(m)
    ctx.arc_negative(0.,0.,1.,0,-0.5*math.pi)
    ctx.restore()
    ctx.close_path()
    wmfdraw.FillPath(ctx,page,i)
    wmfdraw.StrokePath(ctx,page,i)
Esempio n. 3
0
def Rectangle(ctx, page, i):
    y2, x2, y1, x1 = page.cmds[i].args
    x1, y1 = wmfdraw.convcoords(page, ctx, x1, y1)
    x2, y2 = wmfdraw.convcoords(page, ctx, x2, y2)
    ctx.move_to(x1, y1)
    ctx.line_to(x1, y2)
    ctx.line_to(x2, y2)
    ctx.line_to(x2, y1)
    ctx.close_path()
    wmfdraw.FillPath(ctx, page, i)
    wmfdraw.StrokePath(ctx, page, i)
Esempio n. 4
0
def Polygone(ctx,page,i):
    x,y = page.cmds[i].args[0]
    x,y = wmfdraw.convcoords(page,ctx,x,y)
    ctx.move_to(x,y)
    for j in range(len(page.cmds[i].args)):
        x,y = page.cmds[i].args[j]
        x,y = wmfdraw.convcoords(page,ctx,x,y)
        ctx.line_to(x,y)
    ctx.close_path()
    wmfdraw.FillPath(ctx,page,i)
    wmfdraw.StrokePath(ctx,page,i)
Esempio n. 5
0
def Polygone(ctx, page, i):
    x, y = page.cmds[i].args[0]
    x, y = wmfdraw.convcoords(page, ctx, x, y)
    ctx.move_to(x, y)
    for j in range(len(page.cmds[i].args)):
        x, y = page.cmds[i].args[j]
        x, y = wmfdraw.convcoords(page, ctx, x, y)
        ctx.line_to(x, y)
    ctx.close_path()
    wmfdraw.FillPath(ctx, page, i)
    wmfdraw.StrokePath(ctx, page, i)
Esempio n. 6
0
def Rectangle(ctx,page,i):
    y2,x2,y1,x1 = page.cmds[i].args
    x1,y1 = wmfdraw.convcoords(page,ctx,x1,y1)
    x2,y2 = wmfdraw.convcoords(page,ctx,x2,y2)
    ctx.move_to(x1,y1)
    ctx.line_to(x1,y2)
    ctx.line_to(x2,y2)
    ctx.line_to(x2,y1)
    ctx.close_path()
    wmfdraw.FillPath(ctx,page,i)
    wmfdraw.StrokePath(ctx,page,i)
Esempio n. 7
0
def ArcTo(ctx,page,i):
    ye,xe,ys,xs,b,r,t,l = page.cmds[i].args
    xe,ye = wmfdraw.convcoords(page,ctx,xe,ye)
    xs,ys = wmfdraw.convcoords(page,ctx,xs,ys)
    xc,yc = wmfdraw.convcoords(page,ctx,(l+r)/2.,(t+b)/2.)
    dx = math.fabs((r-l)*1./page.DCs[page.curdc].Wx)
    dy = math.fabs((b-t)*1./page.DCs[page.curdc].Wy)
    ang1 = math.atan2((ys-yc),(xs-xc))
    ang2 = math.atan2((ye-yc),(xe-xc))
    ctx.save()
    m = cairo.Matrix(dx/2.,0,0,dy/2.,xc,yc)
    ctx.transform(m)
    ctx.arc_negative(0.,0.,1.,ang1,ang2)
    ctx.restore()
Esempio n. 8
0
def ArcTo(ctx, page, i):
    ye, xe, ys, xs, b, r, t, l = page.cmds[i].args
    xe, ye = wmfdraw.convcoords(page, ctx, xe, ye)
    xs, ys = wmfdraw.convcoords(page, ctx, xs, ys)
    xc, yc = wmfdraw.convcoords(page, ctx, (l + r) / 2., (t + b) / 2.)
    dx = math.fabs((r - l) * 1. / page.DCs[page.curdc].Wx)
    dy = math.fabs((b - t) * 1. / page.DCs[page.curdc].Wy)
    ang1 = math.atan2((ys - yc), (xs - xc))
    ang2 = math.atan2((ye - yc), (xe - xc))
    ctx.save()
    m = cairo.Matrix(dx / 2., 0, 0, dy / 2., xc, yc)
    ctx.transform(m)
    ctx.arc_negative(0., 0., 1., ang1, ang2)
    ctx.restore()
Esempio n. 9
0
def Pie(ctx, page, i):
    ye, xe, ys, xs, b, r, t, l = page.cmds[i].args
    xc, yc = wmfdraw.convcoords(page, ctx, (l + r) / 2., (t + b) / 2.)
    ArcTo(ctx, page, i)
    ctx.line_to(xc, yc)
    ctx.close_path()
    wmfdraw.FillPath(ctx, page, i)
    wmfdraw.StrokePath(ctx, page, i)
Esempio n. 10
0
def Pie(ctx,page,i):
    ye,xe,ys,xs,b,r,t,l = page.cmds[i].args
    xc,yc = wmfdraw.convcoords(page,ctx,(l+r)/2.,(t+b)/2.)
    ArcTo(ctx,page,i)
    ctx.line_to(xc,yc)
    ctx.close_path()
    wmfdraw.FillPath(ctx,page,i)
    wmfdraw.StrokePath(ctx,page,i)
Esempio n. 11
0
def PolyPolygone(ctx,page,i):
    nPolys = page.cmds[i].args[0]
    aptl = page.cmds[i].args[1]
    data = page.cmds[i].args[2]
    shift = 0
    for k in range(nPolys): ## number of polygones
        [x] = struct.unpack('<h',data[shift:shift+2])
        [y] = struct.unpack('<h',data[shift+2:shift+4])
        x,y = wmfdraw.convcoords(page,ctx,x,y)
        ctx.move_to(x,y)
        for j in range(aptl[k]): ## number of gones for i-th polygone
            [x] = struct.unpack('<h',data[j*4+shift:j*4+shift+2])
            [y] = struct.unpack('<h',data[j*4+shift+2:j*4+shift+4])
            x,y = wmfdraw.convcoords(page,ctx,x,y)
            ctx.line_to(x,y)
        ctx.close_path()
        shift+=aptl[k]*4
    wmfdraw.FillPath(ctx,page,i)
    wmfdraw.StrokePath(ctx,page,i)
Esempio n. 12
0
def PolyPolygone(ctx, page, i):
    nPolys = page.cmds[i].args[0]
    aptl = page.cmds[i].args[1]
    data = page.cmds[i].args[2]
    shift = 0
    for k in range(nPolys):  ## number of polygones
        [x] = struct.unpack('<h', data[shift:shift + 2])
        [y] = struct.unpack('<h', data[shift + 2:shift + 4])
        x, y = wmfdraw.convcoords(page, ctx, x, y)
        ctx.move_to(x, y)
        for j in range(aptl[k]):  ## number of gones for i-th polygone
            [x] = struct.unpack('<h', data[j * 4 + shift:j * 4 + shift + 2])
            [y] = struct.unpack('<h',
                                data[j * 4 + shift + 2:j * 4 + shift + 4])
            x, y = wmfdraw.convcoords(page, ctx, x, y)
            ctx.line_to(x, y)
        ctx.close_path()
        shift += aptl[k] * 4
    wmfdraw.FillPath(ctx, page, i)
    wmfdraw.StrokePath(ctx, page, i)
Esempio n. 13
0
def Ellipse(ctx,page,i):
    x,y = ctx.get_current_point()
    x,y = wmfdraw.convcoords(page,ctx,x,y)
    y2,x2,y1,x1 = page.cmds[i].args
    x1,y1 = wmfdraw.convcoords(page,ctx,x1,y1)
    x2,y2 = wmfdraw.convcoords(page,ctx,x2,y2)
    xc = 0.5*(x1+x2)
    yc = 0.5*(y1+y2)
    dx = x2-x1
    dy = y2-y1
    print i,'Ellipse: c(%02f %02f) d(%02f %02f)'%(xc,yc,dx,dy),x2,x1,y2,y1
    ctx.move_to(xc,yc)
    ctx.save()
    ctx.translate(xc,yc)
    ctx.move_to(dx/2., 0)
    ctx.scale(dx/2., dy/2.)
    ctx.arc(0.,0.,1.,0.,2*math.pi)
    ctx.restore()
    ctx.move_to(x,y)
    wmfdraw.FillPath(ctx,page,i)
    wmfdraw.StrokePath(ctx,page,i)
Esempio n. 14
0
def Ellipse(ctx, page, i):
    x, y = ctx.get_current_point()
    x, y = wmfdraw.convcoords(page, ctx, x, y)
    y2, x2, y1, x1 = page.cmds[i].args
    x1, y1 = wmfdraw.convcoords(page, ctx, x1, y1)
    x2, y2 = wmfdraw.convcoords(page, ctx, x2, y2)
    xc = 0.5 * (x1 + x2)
    yc = 0.5 * (y1 + y2)
    dx = x2 - x1
    dy = y2 - y1
    print i, 'Ellipse: c(%02f %02f) d(%02f %02f)' % (xc, yc, dx,
                                                     dy), x2, x1, y2, y1
    ctx.move_to(xc, yc)
    ctx.save()
    ctx.translate(xc, yc)
    ctx.move_to(dx / 2., 0)
    ctx.scale(dx / 2., dy / 2.)
    ctx.arc(0., 0., 1., 0., 2 * math.pi)
    ctx.restore()
    ctx.move_to(x, y)
    wmfdraw.FillPath(ctx, page, i)
    wmfdraw.StrokePath(ctx, page, i)
Esempio n. 15
0
def ExtTextOut(ctx,page,i):

    x,y,text,dx = page.cmds[i].args
    print 'ExtText:',text
    lentext = len(text)
    textstr = text
    alignh = txtalign[page.txtalign]
    eonum = page.curfnt
    eo = page.mfobjs[eonum]
    size = eo.size
    bld = ''
    itl = ''
    if eo.weight > 400:
        bld = 'Bold '
    if eo.italic !=0:
        itl = 'Italic '
    FONT = eo.font+' '+bld+itl+str(size/1.5)
    fdesc = pango.FontDescription(FONT)
    if eo.font == 'Symbol':
        textstr=unicode(symbol_to_utf(text),'utf-16')
    if eo.charset > 77 and charsets.has_key(eo.charset):
        # have to reencode and have no idea about Mac encoding
        print 'Reencoding from charset %s'%charsets[eo.charset],'text: ',text
        textstr = unicode(text,charsets[eo.charset])
        textstr.encode('utf-8')

    if cpupdate.has_key(page.txtalign):
        x,y = ctx.get_current_point()
        ytr = y/1.5
    else:
        x,y = wmfdraw.convcoords(page,ctx,x,y)
        ytr = y - size*1./page.height
    print 'X,Y: ',x,y
    dxsum = 0
    if len(dx)>3: ## there is shifts
        print 'Shifts'
        dxoffs = 0
        dxlist = []
        if lentext/2. != lentext/2:
            dxoffs = 1
        for i in range(lentext-1):
            [d] = struct.unpack('h',dx[i*2+dxoffs:i*2+2+dxoffs])
            dxlist.append(d)
            dxsum=dxsum+d
        dxlist.append(0) ## to simplify my life later


    ctx.save()
    if page.width != 1 and page.height !=1:
        matrix = cairo.Matrix(1./page.width,0,0,1./page.height,0,0)##x,ytr)
        ctx.transform(matrix)
    layout = ctx.create_layout()
    layout.set_font_description(fdesc)

    layout.set_text(textstr)
    xsize,ysize = layout.get_size()
    xsize=xsize/1000./page.width
    ysize=ysize/1000./page.height
    if len(dx)>3: ## there is shifts
        t = text[lentext-1]
        layout.set_text(textstr)
        x0,y0 = layout.get_size()
        xsize=x0/1000.+dxsum
    
    if alignh == 0:
        xs = x
    if alignh == 1:
        xs = x-xsize/2.
    if alignh == 2:
        xs = x-xsize
    if page.txtalign<8: ##top
        ys = y + ysize
    if page.txtalign>7 and page.txtalign<24: ##bottom
        ys = y 
    if page.txtalign>23: ##baseline
        ys = y - ysize/1.25
    
    if cpupdate.has_key(page.txtalign):
        xe = xs+xsize
        ye = ys+ysize
    else:
        xe = xs+xsize*page.width
        ye = ys+ysize*page.height
    
    print 'Xs,Ys: ',xs,ys,'Xe,Ye: ',xe,ye

    if page.width != 1 and page.height !=1:
        ctx.translate(xs*page.width, ys*page.height)

    ctx.save()
    if eo.escape !=0:  ## change it with transform
        ctx.translate(xs,ys)
        ctx.rotate(-eo.escape*math.pi/1800) ## rotation angle is set in 10th of degree
        ctx.translate(-xs,-ys)
        
    if page.bkmode == 2:
        r = page.bkcolor.r
        g = page.bkcolor.g
        b = page.bkcolor.b
        ctx.save()
        ctx.set_source_rgba(r/255.,g/255.,b/255.,1)
        ctx.move_to(xs,ys)
        ctx.line_to(xe,ys)
        ctx.line_to(xe,ye)
        ctx.line_to(xs,ye)
        ctx.close_path()
        ctx.fill()
        ctx.restore()
    ctx.set_source_rgba(page.txtclr.r/255.,page.txtclr.g/255.,page.txtclr.b/255.,1)
    if eo.under == 1:
        if dxsum > 0:
            xf = xs+dxsum
            t = text[len(text)-1]
            layout.set_text(t)
            x0,y0 = layout.get_size()
            xf+=x0/1000.
        else:
            xf = xe
        ctx.move_to(xs,ys+ysize*page.height/1.05)
        ctx.line_to(xf,ys+ysize*page.height/1.05)
        ctx.set_line_width(size*0.06)
        ctx.stroke()
    if eo.strike == 1:
        if dxsum > 0:
            xf = xs+dxsum
            t = text[len(text)-1]
            layout.set_text(t)
            x0,y0 = layout.get_size()
            xf+=x0/1000.
        else:
            xf = xe
        ctx.move_to(xs,ys+ysize*page.height/2.)
        ctx.line_to(xf,ys+ysize*page.height/2.)
        ctx.set_line_width(size*0.06)
        ctx.stroke()
    ctx.move_to(xs,ys)
    if dxsum>0 or (eo.orient!=0 and page.ai==0):
        ctx.save()
        for i in range(lentext):
            t = textstr[i]
            layout.set_text(t)
            x0,y0 = layout.get_size()
            ctx.save()
            if eo.orient!=0 and page.ai ==0:
                ctx.translate(xs+x0/2000.,ys+y0/2000.)
                ctx.rotate(-eo.orient*math.pi/1800.) ## rotation angle is set in 10th of degree
                ctx.translate(-xs-x0/2000.,-ys-y0/2000.)
                xup = abs(x0*math.sin(eo.orient*math.pi/1800.)/1000.+y0*math.cos(eo.orient*math.pi/1800.)/1000.)
            ctx.show_layout(layout)
            if dxsum >0:
                xs=xs+dxlist[i]*1.
            else:
                xs = xs+xup
            ctx.restore()
            ctx.move_to(xs,ys) 
        ctx.restore()
    else:
        layout.set_text(textstr)
        ctx.show_layout(layout)
    ctx.restore()
    
    ctx.restore()
Esempio n. 16
0
def Polyline(ctx, page, i):
    x, y = page.cmds[i].args[0]
    x, y = wmfdraw.convcoords(page, ctx, x, y)
    ctx.move_to(x, y)
    PolylineTo(ctx, page, i)
    wmfdraw.StrokePath(ctx, page, i)
Esempio n. 17
0
def LineTo(ctx,page,i):
    y,x = page.cmds[i].args
    x,y = wmfdraw.convcoords(page,ctx,x,y)
    ctx.line_to(x,y)
    wmfdraw.StrokePath(ctx,page,i)    
Esempio n. 18
0
def MoveTo(ctx,page,i):
    y,x = page.cmds[i].args
    x,y = wmfdraw.convcoords(page,ctx,x,y)
    ctx.move_to(x,y)
Esempio n. 19
0
def PolylineTo(ctx,page,i):
    for j in range(len(page.cmds[i].args)):
        x1,y1 = page.cmds[i].args[j]
        x1,y1 = wmfdraw.convcoords(page,ctx,x1,y1)
        ctx.line_to(x1,y1)
Esempio n. 20
0
def Polyline(ctx,page,i):
    x,y = page.cmds[i].args[0]
    x,y = wmfdraw.convcoords(page,ctx,x,y)
    ctx.move_to(x,y)
    PolylineTo(ctx,page,i)
    wmfdraw.StrokePath(ctx,page,i)
Esempio n. 21
0
def PolylineTo(ctx, page, i):
    for j in range(len(page.cmds[i].args)):
        x1, y1 = page.cmds[i].args[j]
        x1, y1 = wmfdraw.convcoords(page, ctx, x1, y1)
        ctx.line_to(x1, y1)
Esempio n. 22
0
def MoveTo(ctx, page, i):
    y, x = page.cmds[i].args
    x, y = wmfdraw.convcoords(page, ctx, x, y)
    ctx.move_to(x, y)
Esempio n. 23
0
def LineTo(ctx, page, i):
    y, x = page.cmds[i].args
    x, y = wmfdraw.convcoords(page, ctx, x, y)
    ctx.line_to(x, y)
    wmfdraw.StrokePath(ctx, page, i)