Three sets of changes from Grail:
date: 1996/08/14 17:27:21; author: fdrake; state: Exp; lines: +11 -9 (formatter.py): Establish a consistent space-handling policy, so that all spaces are handled by the outermost context in which they might be considered. (I.e., softspaces at element boundaries migrate outwards.) For instance: "<A> <IMG> </A>" becomes " <A><IMG></A> ". This avoids some of those nasty underlined spaces around images. It does not affect spaces *between* images within an anchor. date: 1996/08/01 17:02:09; author: fdrake; state: Exp; lines: +3 -2 (formatter.py): Added required parameter to the NullFormatter class; this was omitted by accident. Made AbstractFormatter.add_literal_data() handle preceeding softspace correctly instead of expecting the caller to do it. date: 1996/07/23 22:18:56; author: fdrake; state: Exp; lines: +1 -1 (formatter.py): Correct assert_line_data() to update all internal conditions; This now handles headers with only image content immediately followed by anything.
This commit is contained in:
parent
f8abb38737
commit
8e44991b34
|
@ -10,7 +10,7 @@ AS_IS = None
|
||||||
|
|
||||||
class NullFormatter:
|
class NullFormatter:
|
||||||
|
|
||||||
def __init__(self): pass
|
def __init__(self, writer): pass
|
||||||
def end_paragraph(self, blankline): pass
|
def end_paragraph(self, blankline): pass
|
||||||
def add_line_break(self): pass
|
def add_line_break(self): pass
|
||||||
def add_hor_rule(self, abswidth=None, percentwidth=1.0,
|
def add_hor_rule(self, abswidth=None, percentwidth=1.0,
|
||||||
|
@ -33,6 +33,11 @@ class NullFormatter:
|
||||||
|
|
||||||
class AbstractFormatter:
|
class AbstractFormatter:
|
||||||
|
|
||||||
|
# Space handling policy: blank spaces at the boundary between elements
|
||||||
|
# are handled by the outermost context. "Literal" data is not checked
|
||||||
|
# to determine context, so spaces in literal data are handled directly
|
||||||
|
# in all circumstances.
|
||||||
|
|
||||||
def __init__(self, writer):
|
def __init__(self, writer):
|
||||||
self.writer = writer # Output device
|
self.writer = writer # Output device
|
||||||
self.align = None # Current alignment
|
self.align = None # Current alignment
|
||||||
|
@ -162,7 +167,8 @@ class AbstractFormatter:
|
||||||
|
|
||||||
def add_literal_data(self, data):
|
def add_literal_data(self, data):
|
||||||
if not data: return
|
if not data: return
|
||||||
# Caller is expected to cause flush_softspace() if needed.
|
if self.softspace:
|
||||||
|
self.writer.send_flowing_data(" ")
|
||||||
self.hard_break = data[-1:] == '\n'
|
self.hard_break = data[-1:] == '\n'
|
||||||
self.nospace = self.para_end = self.softspace = \
|
self.nospace = self.para_end = self.softspace = \
|
||||||
self.parskip = self.have_label = 0
|
self.parskip = self.have_label = 0
|
||||||
|
@ -170,8 +176,9 @@ class AbstractFormatter:
|
||||||
|
|
||||||
def flush_softspace(self):
|
def flush_softspace(self):
|
||||||
if self.softspace:
|
if self.softspace:
|
||||||
self.hard_break = self.nospace = self.para_end = self.parskip = \
|
self.hard_break = self.para_end = self.parskip = \
|
||||||
self.have_label = self.softspace = 0
|
self.have_label = self.softspace = 0
|
||||||
|
self.nospace = 1
|
||||||
self.writer.send_flowing_data(' ')
|
self.writer.send_flowing_data(' ')
|
||||||
|
|
||||||
def push_alignment(self, align):
|
def push_alignment(self, align):
|
||||||
|
@ -194,7 +201,8 @@ class AbstractFormatter:
|
||||||
|
|
||||||
def push_font(self, (size, i, b, tt)):
|
def push_font(self, (size, i, b, tt)):
|
||||||
if self.softspace:
|
if self.softspace:
|
||||||
self.hard_break = self.nospace = self.para_end = self.softspace = 0
|
self.hard_break = self.para_end = self.softspace = 0
|
||||||
|
self.nospace = 1
|
||||||
self.writer.send_flowing_data(' ')
|
self.writer.send_flowing_data(' ')
|
||||||
if self.font_stack:
|
if self.font_stack:
|
||||||
csize, ci, cb, ctt = self.font_stack[-1]
|
csize, ci, cb, ctt = self.font_stack[-1]
|
||||||
|
@ -207,9 +215,6 @@ class AbstractFormatter:
|
||||||
self.writer.new_font(font)
|
self.writer.new_font(font)
|
||||||
|
|
||||||
def pop_font(self):
|
def pop_font(self):
|
||||||
if self.softspace:
|
|
||||||
self.hard_break = self.nospace = self.para_end = self.softspace = 0
|
|
||||||
self.writer.send_flowing_data(' ')
|
|
||||||
if self.font_stack:
|
if self.font_stack:
|
||||||
del self.font_stack[-1]
|
del self.font_stack[-1]
|
||||||
if self.font_stack:
|
if self.font_stack:
|
||||||
|
@ -241,22 +246,20 @@ class AbstractFormatter:
|
||||||
|
|
||||||
def push_style(self, *styles):
|
def push_style(self, *styles):
|
||||||
if self.softspace:
|
if self.softspace:
|
||||||
self.hard_break = self.nospace = self.para_end = self.softspace = 0
|
self.hard_break = self.para_end = self.softspace = 0
|
||||||
|
self.nospace = 1
|
||||||
self.writer.send_flowing_data(' ')
|
self.writer.send_flowing_data(' ')
|
||||||
for style in styles:
|
for style in styles:
|
||||||
self.style_stack.append(style)
|
self.style_stack.append(style)
|
||||||
self.writer.new_styles(tuple(self.style_stack))
|
self.writer.new_styles(tuple(self.style_stack))
|
||||||
|
|
||||||
def pop_style(self, n=1):
|
def pop_style(self, n=1):
|
||||||
if self.softspace:
|
|
||||||
self.hard_break = self.nospace = self.para_end = self.softspace = 0
|
|
||||||
self.writer.send_flowing_data(' ')
|
|
||||||
del self.style_stack[-n:]
|
del self.style_stack[-n:]
|
||||||
self.writer.new_styles(tuple(self.style_stack))
|
self.writer.new_styles(tuple(self.style_stack))
|
||||||
|
|
||||||
def assert_line_data(self, flag=1):
|
def assert_line_data(self, flag=1):
|
||||||
self.nospace = self.hard_break = not flag
|
self.nospace = self.hard_break = not flag
|
||||||
self.para_end = self.have_label = 0
|
self.para_end = self.parskip = self.have_label = 0
|
||||||
|
|
||||||
|
|
||||||
class NullWriter:
|
class NullWriter:
|
||||||
|
|
Loading…
Reference in New Issue