Skip to content

Commit

Permalink
Merge 'float' and 'sideways' (they are mutually exclusive)
Browse files Browse the repository at this point in the history
  • Loading branch information
brechtm committed Feb 22, 2022
1 parent d8edfe2 commit 7b03425
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ New Features:

* Support for sideways figures and tables; these are placed on a separate page,
rotated 90 degrees. This is useful for figures/tables that do not fit within
the page width.
the page width. See the *float* style attribute.
* The GroupedFlowables *same_page* style property forces all of a
GroupedFlowables' content to be placed on the same page (if possible).
* Support for OpenType fonts with non-BMP Unicode characters (PR #308 by James
Expand Down
2 changes: 1 addition & 1 deletion src/rinoh/data/stylesheets/sphinx.rts
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ horizontal_align=CENTER
; sideways figures and tables
[sideways float : Float(has_class='sideways')]
base = NEXT_MATCH
sideways = true
float = sideways

[figure]
space_above=10pt
Expand Down
19 changes: 12 additions & 7 deletions src/rinoh/flowable.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,11 +845,16 @@ def render(self, container, descender, state, **kwargs):
raise


class FloatLocation(OptionSet):

values = (None, 'here', 'sideways')


class FloatStyle(FlowableStyle):
float = Attribute(Bool, False, 'Float the flowable to the top or bottom '
'of the page')
sideways = Attribute(Bool, False, 'Render the flowable onto a separate '
'page, rotated 90 degrees')
float = Attribute(FloatLocation, None, 'Float the flowable to the top or '
'bottom of the current page, to a '
'dedicated page, or sideways to a '
'dedicated page')


class Float(Flowable):
Expand All @@ -870,14 +875,14 @@ class Float(Flowable):
def flow(self, container, last_descender, state=None, **kwargs):
document = container.document
id = self.get_id(document)
if self.get_style('sideways', container):
float = self.get_style('float', container)
if float == FloatLocation.SIDEWAYS:
if id not in document.registered_sideways_floats:
document.add_sideways_float(self)
state = CompletedFlowableState()
self.page_break(container, state)
return 0, 0, last_descender
elif (self.get_style('float', container)
and id not in document.floats):
elif (float == FloatLocation.HERE and id not in document.floats):
super().flow(container.float_space, None)
document.floats.add(id)
if not container.page.check_overflow():
Expand Down
2 changes: 1 addition & 1 deletion tests_regression/rst/table_sideways.rts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ base = sphinx_base14

[sideways-break float : Float(has_class='sideways-break')]
base = NEXT_MATCH
sideways = true
float = sideways
page_break = any

0 comments on commit 7b03425

Please sign in to comment.