simple grapihcs rendering
git-svn-id: https://pdfminerr.googlecode.com/svn/trunk/pdfminer@88 1aa58f4a-7d42-0410-adbc-911cccaed67cpull/1/head
parent
6d91453187
commit
2f1de93e6c
|
@ -44,10 +44,12 @@ class PDFDevice(object):
|
||||||
def end_figure(self, name):
|
def end_figure(self, name):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def paint_path(self, graphicstate, matrix, stroke, fill, evenodd, path):
|
||||||
|
return
|
||||||
def render_string(self, textstate, textmatrix, seq):
|
def render_string(self, textstate, textmatrix, seq):
|
||||||
raise NotImplementedError
|
return
|
||||||
def render_image(self, stream, size, matrix):
|
def render_image(self, stream, size, matrix):
|
||||||
raise NotImplementedError
|
return
|
||||||
|
|
||||||
|
|
||||||
## PageItem
|
## PageItem
|
||||||
|
@ -151,14 +153,28 @@ class PDFPageAggregator(PDFDevice):
|
||||||
self.cur_item.add(fig)
|
self.cur_item.add(fig)
|
||||||
return
|
return
|
||||||
|
|
||||||
def render_image(self, stream, size, matrix):
|
|
||||||
return
|
|
||||||
|
|
||||||
def handle_undefined_char(self, cidcoding, cid):
|
def handle_undefined_char(self, cidcoding, cid):
|
||||||
if self.debug:
|
if self.debug:
|
||||||
print >>stderr, 'undefined: %r, %r' % (cidcoding, cid)
|
print >>stderr, 'undefined: %r, %r' % (cidcoding, cid)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def paint_path(self, graphicstate, matrix, stroke, fill, evenodd, path):
|
||||||
|
shape = ''.join(x[0] for x in path)
|
||||||
|
if shape == 'ml': # single line
|
||||||
|
if path[0][1] == path[1][1]:
|
||||||
|
#print 'vertical'
|
||||||
|
pass
|
||||||
|
elif path[0][2] == path[1][2]:
|
||||||
|
#print 'horizontal'
|
||||||
|
pass
|
||||||
|
elif shape == 'mlllh': # rectangle
|
||||||
|
if ((path[0][1] == path[1][1] and path[1][2] == path[2][2] and
|
||||||
|
path[2][1] == path[3][1] and path[3][2] == path[0][2]) or
|
||||||
|
(path[0][2] == path[1][2] and path[1][1] == path[2][1] and
|
||||||
|
path[2][2] == path[3][2] and path[3][1] == path[0][1])):
|
||||||
|
pass
|
||||||
|
return
|
||||||
|
|
||||||
def render_chars(self, textmatrix, textstate, chars):
|
def render_chars(self, textmatrix, textstate, chars):
|
||||||
if not chars: return (0, 0)
|
if not chars: return (0, 0)
|
||||||
item = TextItem(textmatrix, textstate.font, textstate.fontsize, textstate.charspace, textstate.scaling, chars)
|
item = TextItem(textmatrix, textstate.font, textstate.fontsize, textstate.charspace, textstate.scaling, chars)
|
||||||
|
|
|
@ -231,6 +231,22 @@ class PDFPageInterpreter(object):
|
||||||
self.linematrix = (0, 0)
|
self.linematrix = (0, 0)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
class GraphicState(object):
|
||||||
|
def __init__(self):
|
||||||
|
self.linewidth = None
|
||||||
|
self.linecap = None
|
||||||
|
self.linejoin = None
|
||||||
|
self.miterlimit = None
|
||||||
|
self.dash = None
|
||||||
|
self.intent = None
|
||||||
|
self.flatness = None
|
||||||
|
return
|
||||||
|
def __repr__(self):
|
||||||
|
return ('<GraphicState: linewidth=%r, linecap=%r, linejoin=%r, '
|
||||||
|
' miterlimit=%r, dash=%r, intent=%r, flatness=%r>' %
|
||||||
|
(self.linewidth, self.linecap, self.linejoin,
|
||||||
|
self.miterlimit, self.dash, self.intent, self.flatness))
|
||||||
|
|
||||||
def __init__(self, rsrc, device):
|
def __init__(self, rsrc, device):
|
||||||
self.rsrc = rsrc
|
self.rsrc = rsrc
|
||||||
self.device = device
|
self.device = device
|
||||||
|
@ -281,7 +297,9 @@ class PDFPageInterpreter(object):
|
||||||
self.gstack = []
|
self.gstack = []
|
||||||
self.ctm = ctm
|
self.ctm = ctm
|
||||||
self.device.set_ctm(self.ctm)
|
self.device.set_ctm(self.ctm)
|
||||||
self.textstate = PDFPageInterpreter.TextState()
|
self.textstate = self.TextState()
|
||||||
|
self.graphicstate = self.GraphicState()
|
||||||
|
self.curpath = []
|
||||||
# argstack: stack for command arguments.
|
# argstack: stack for command arguments.
|
||||||
self.argstack = []
|
self.argstack = []
|
||||||
# set some global states.
|
# set some global states.
|
||||||
|
@ -301,10 +319,10 @@ class PDFPageInterpreter(object):
|
||||||
return x
|
return x
|
||||||
|
|
||||||
def get_current_state(self):
|
def get_current_state(self):
|
||||||
return (self.ctm, self.textstate)
|
return (self.ctm, self.textstate, self.graphicstate)
|
||||||
|
|
||||||
def set_current_state(self, state):
|
def set_current_state(self, state):
|
||||||
(self.ctm, self.textstate) = state
|
(self.ctm, self.textstate, self.graphicstate) = state
|
||||||
self.device.set_ctm(self.ctm)
|
self.device.set_ctm(self.ctm)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -325,57 +343,117 @@ class PDFPageInterpreter(object):
|
||||||
return
|
return
|
||||||
|
|
||||||
# setlinewidth
|
# setlinewidth
|
||||||
def do_w(self, width): return
|
def do_w(self, linewidth):
|
||||||
|
self.graphicstate.linewidth = linewidth
|
||||||
|
return
|
||||||
# setlinecap
|
# setlinecap
|
||||||
def do_J(self, cap): return
|
def do_J(self, linecap):
|
||||||
|
self.graphicstate.linecap = linecap
|
||||||
|
return
|
||||||
# setlinejoin
|
# setlinejoin
|
||||||
def do_j(self, join): return
|
def do_j(self, linejoin):
|
||||||
|
self.graphicstate.linejoin = linejoin
|
||||||
|
return
|
||||||
# setmiterlimit
|
# setmiterlimit
|
||||||
def do_M(self, limit): return
|
def do_M(self, limit):
|
||||||
|
self.graphicstate.miterlimit = miterlimit
|
||||||
|
return
|
||||||
# setdash
|
# setdash
|
||||||
def do_d(self, dash, phase): return
|
def do_d(self, dash, phase):
|
||||||
|
self.graphicstate.dash = (dash, phase)
|
||||||
|
return
|
||||||
# setintent
|
# setintent
|
||||||
def do_ri(self, intent): return
|
def do_ri(self, intent):
|
||||||
|
self.graphicstate.intent = intent
|
||||||
|
return
|
||||||
# setflatness
|
# setflatness
|
||||||
def do_i(self, flatness): return
|
def do_i(self, flatness):
|
||||||
# savedict
|
self.graphicstate.flatness = flatness
|
||||||
def do_gs(self, name): return
|
return
|
||||||
|
# load-gstate
|
||||||
|
def do_gs(self, name):
|
||||||
|
#XXX
|
||||||
|
return
|
||||||
|
|
||||||
# moveto
|
# moveto
|
||||||
def do_m(self, x, y): return
|
def do_m(self, x, y):
|
||||||
|
self.curpath.append(('m',x,y))
|
||||||
|
return
|
||||||
# lineto
|
# lineto
|
||||||
def do_l(self, x, y): return
|
def do_l(self, x, y):
|
||||||
|
self.curpath.append(('l',x,y))
|
||||||
|
return
|
||||||
# curveto
|
# curveto
|
||||||
def do_c(self, x1, y1, x2, y2, x3, y3): return
|
def do_c(self, x1, y1, x2, y2, x3, y3):
|
||||||
|
self.curpath.append(('c',x1,y1,x2,y2,x3,y3))
|
||||||
|
return
|
||||||
# urveto
|
# urveto
|
||||||
def do_v(self, x2, y2, x3, y3): return
|
def do_v(self, x2, y2, x3, y3):
|
||||||
|
self.curpath.append(('v',x2,y2,x3,y3))
|
||||||
|
return
|
||||||
# rveto
|
# rveto
|
||||||
def do_y(self, x1, y1, x3, y3): return
|
def do_y(self, x1, y1, x3, y3):
|
||||||
|
self.curpath.append(('y',x1,y1,x3,y3))
|
||||||
|
return
|
||||||
# closepath
|
# closepath
|
||||||
def do_h(self): return
|
def do_h(self):
|
||||||
|
self.curpath.append(('h',))
|
||||||
|
return
|
||||||
# rectangle
|
# rectangle
|
||||||
def do_re(self, x, y, w, h): return
|
def do_re(self, x, y, w, h):
|
||||||
|
self.curpath.append(('m',x,y))
|
||||||
|
self.curpath.append(('l',x+w,y))
|
||||||
|
self.curpath.append(('l',x+w,y+h))
|
||||||
|
self.curpath.append(('l',x,y+h))
|
||||||
|
self.curpath.append(('h',))
|
||||||
|
return
|
||||||
|
|
||||||
# stroke
|
# stroke
|
||||||
def do_S(self): return
|
def do_S(self):
|
||||||
|
self.device.paint_path(self.graphicstate, self.ctm, True, False, False, self.curpath)
|
||||||
|
self.curpath = []
|
||||||
|
return
|
||||||
# close-and-stroke
|
# close-and-stroke
|
||||||
def do_s(self): return
|
def do_s(self):
|
||||||
|
self.do_h()
|
||||||
|
self.do_S()
|
||||||
|
return
|
||||||
# fill
|
# fill
|
||||||
def do_f(self): return
|
def do_f(self):
|
||||||
|
self.device.paint_path(self.graphicstate, self.ctm, False, True, False, self.curpath)
|
||||||
|
self.curpath = []
|
||||||
|
return
|
||||||
# fill (obsolete)
|
# fill (obsolete)
|
||||||
do_F = do_f
|
do_F = do_f
|
||||||
# fill-even-odd
|
# fill-even-odd
|
||||||
def do_f_a(self): return
|
def do_f_a(self):
|
||||||
|
self.device.paint_path(self.graphicstate, self.ctm, False, True, True, self.curpath)
|
||||||
|
self.curpath = []
|
||||||
|
return
|
||||||
# fill-and-stroke
|
# fill-and-stroke
|
||||||
def do_B(self): return
|
def do_B(self):
|
||||||
|
self.device.paint_path(self.graphicstate, self.ctm, True, True, False, self.curpath)
|
||||||
|
self.curpath = []
|
||||||
|
return
|
||||||
# fill-and-stroke-even-odd
|
# fill-and-stroke-even-odd
|
||||||
def do_B_a(self): return
|
def do_B_a(self):
|
||||||
|
self.device.paint_path(self.graphicstate, self.ctm, True, True, True, self.curpath)
|
||||||
|
self.curpath = []
|
||||||
|
return
|
||||||
# close-fill-and-stroke
|
# close-fill-and-stroke
|
||||||
def do_b(self): return
|
def do_b(self):
|
||||||
|
self.do_h()
|
||||||
|
self.do_B()
|
||||||
|
return
|
||||||
# close-fill-and-stroke-even-odd
|
# close-fill-and-stroke-even-odd
|
||||||
def do_b_a(self): return
|
def do_b_a(self):
|
||||||
|
self.do_h()
|
||||||
|
self.do_B_a()
|
||||||
|
return
|
||||||
# close-only
|
# close-only
|
||||||
def do_n(self): return
|
def do_n(self):
|
||||||
|
self.curpath = []
|
||||||
|
return
|
||||||
# clip
|
# clip
|
||||||
def do_W(self): return
|
def do_W(self): return
|
||||||
# clip-even-odd
|
# clip-even-odd
|
||||||
|
|
Loading…
Reference in New Issue