Skip to content

Commit

Permalink
Send non-stroke color to XML conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
pquentin committed Mar 6, 2018
1 parent b6c63be commit 2231f08
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
9 changes: 5 additions & 4 deletions pdfminer/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ def paint_path(self, gstate, stroke, fill, evenodd, path):
evenodd, gstate.scolor, gstate.ncolor))
return

def render_char(self, matrix, font, fontsize, scaling, rise, cid):
def render_char(self, matrix, font, fontsize, scaling, rise, cid, ncs, graphicstate):
try:
text = font.to_unichr(cid)
assert isinstance(text, six.text_type), str(type(text))
except PDFUnicodeNotDefined:
text = self.handle_undefined_char(font, cid)
textwidth = font.char_width(cid)
textdisp = font.char_disp(cid)
item = LTChar(matrix, font, fontsize, scaling, rise, text, textwidth, textdisp)
item = LTChar(matrix, font, fontsize, scaling, rise, text, textwidth, textdisp, ncs, graphicstate)
self.cur_item.add(item)
return item.adv

Expand Down Expand Up @@ -520,8 +520,9 @@ def render(item):
render(child)
self.write('</textbox>\n')
elif isinstance(item, LTChar):
self.write('<text font="%s" bbox="%s" size="%.3f">' %
(enc(item.fontname, None), bbox2str(item.bbox), item.size))
self.write('<text font="%s" bbox="%s" colourspace="%s" ncolour=%s" size="%.3f">' %
(enc(item.fontname, None), bbox2str(item.bbox),
item.ncs.name, item.graphicstate.ncolor, item.size))
self.write_text(item.get_text())
self.write('</text>\n')
elif isinstance(item, LTText):
Expand Down
4 changes: 3 additions & 1 deletion pdfminer/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,13 @@ def get_text(self):
class LTChar(LTComponent, LTText):

def __init__(self, matrix, font, fontsize, scaling, rise,
text, textwidth, textdisp):
text, textwidth, textdisp, ncs, graphicstate):
LTText.__init__(self)
self._text = text
self.matrix = matrix
self.fontname = font.fontname
self.ncs = ncs
self.graphicstate = graphicstate
self.adv = textwidth * fontsize * scaling
# compute the boundary rectangle.
if font.is_vertical():
Expand Down
20 changes: 12 additions & 8 deletions pdfminer/pdfdevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def render_string(self, textstate, seq):
##
class PDFTextDevice(PDFDevice):

def render_string(self, textstate, seq):
def render_string(self, textstate, seq, ncs, graphicstate):
matrix = utils.mult_matrix(textstate.matrix, self.ctm)
font = textstate.font
fontsize = textstate.fontsize
Expand All @@ -77,15 +77,16 @@ def render_string(self, textstate, seq):
if font.is_vertical():
textstate.linematrix = self.render_string_vertical(
seq, matrix, textstate.linematrix, font, fontsize,
scaling, charspace, wordspace, rise, dxscale)
scaling, charspace, wordspace, rise, dxscale, ncs, graphicstate)
else:
textstate.linematrix = self.render_string_horizontal(
seq, matrix, textstate.linematrix, font, fontsize,
scaling, charspace, wordspace, rise, dxscale)
scaling, charspace, wordspace, rise, dxscale, ncs, graphicstate)
return

def render_string_horizontal(self, seq, matrix, pos,
font, fontsize, scaling, charspace, wordspace, rise, dxscale):
font, fontsize, scaling, charspace, wordspace,
rise, dxscale, ncs, graphicstate):
(x, y) = pos
needcharspace = False
for obj in seq:
Expand All @@ -97,14 +98,16 @@ def render_string_horizontal(self, seq, matrix, pos,
if needcharspace:
x += charspace
x += self.render_char(utils.translate_matrix(matrix, (x, y)),
font, fontsize, scaling, rise, cid)
font, fontsize, scaling, rise, cid,
ncs, graphicstate)
if cid == 32 and wordspace:
x += wordspace
needcharspace = True
return (x, y)

def render_string_vertical(self, seq, matrix, pos,
font, fontsize, scaling, charspace, wordspace, rise, dxscale):
font, fontsize, scaling, charspace, wordspace,
rise, dxscale, ncs, graphicstate):
(x, y) = pos
needcharspace = False
for obj in seq:
Expand All @@ -116,13 +119,14 @@ def render_string_vertical(self, seq, matrix, pos,
if needcharspace:
y += charspace
y += self.render_char(utils.translate_matrix(matrix, (x, y)),
font, fontsize, scaling, rise, cid)
font, fontsize, scaling, rise, cid,
ncs, graphicstate)
if cid == 32 and wordspace:
y += wordspace
needcharspace = True
return (x, y)

def render_char(self, matrix, font, fontsize, scaling, rise, cid):
def render_char(self, matrix, font, fontsize, scaling, rise, cid, ncs, graphicstate):
return 0


Expand Down
6 changes: 3 additions & 3 deletions pdfminer/pdfinterp.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,13 +586,13 @@ def do_cs(self, name):

# setgray-stroking
def do_G(self, gray):
self.graphicstate.color = gray
self.graphicstate.scolor = gray
#self.do_CS(LITERAL_DEVICE_GRAY)
return

# setgray-non-stroking
def do_g(self, gray):
self.graphicstate.color = gray
self.graphicstate.ncolor = gray
#self.do_cs(LITERAL_DEVICE_GRAY)
return

Expand Down Expand Up @@ -769,7 +769,7 @@ def do_TJ(self, seq):
if settings.STRICT:
raise PDFInterpreterError('No font specified!')
return
self.device.render_string(self.textstate, seq)
self.device.render_string(self.textstate, seq, self.ncs, self.graphicstate.copy())
return

# show
Expand Down

0 comments on commit 2231f08

Please sign in to comment.