Peter Ward avatar Peter Ward committed 6a27b07

move out helper functions into main module

Comments (0)

Files changed (5)

docs/fake/multiple.py

-from collections import namedtuple
-
-class TextFragment(namedtuple('TextFragment', 'text cost')):
-    """
-    A piece of text which must be placed on the same slide, with an associated
-    cost for breaking after this piece of text.
-
-    :param text: string
-    :param cost: float
-    """
-
-class GreedyDualSize(object):
-    """
-    This text layout strategy will lay out the text on slides using two font
-    sizes: a user-specified "major" size and a smaller "minor" font size to
-    avoid widows from wrapped text.
-    """
-    def __init__(self, major_size, min_minor_size):
-        pass
-
-    def determine_breaks(self, text_fragments):
-        """
-        This is the first phase, which greedily breaks the given text into
-        slides. Fragments of text are placed on the slide at the major font
-        size until the slide vertically overflows, at which point the last
-        fragment is moved to the next slide, and the process continues.
-
-        :param text_fragments: list of TextFragment objects. The cost is unused.
-        :rtype: list of list of TextFragments.
-        """
-        pass
-
-    def determine_minor_size(self, slides):
-        """
-        The second phase determines the smaller font size by looking at the text
-        shape of each slide, and identifying widows from line wrapping. If any
-        exist, the font size is reduced until no lines have widows.
-        The minor font size is then the smallest required font size, unless it
-        is smaller than min_minor_size.
-
-        :param slides: list of list of TextFragments.
-        :rtype: float
-        """
-        pass
-
Add a comment to this file

docs/fake/shinypress/__init__.py

Empty file added.

docs/fake/shinypress/text/__init__.py

+from collections import namedtuple
+
+class TextFragment(namedtuple('TextFragment', 'text cost')):
+    """
+    A piece of text which must be placed on the same slide, with an associated
+    cost for breaking after this piece of text.
+
+    :param text: string
+    :param cost: float
+    """
+
+def find_possible_breaks(text):
+    """
+    Split the given text into sentences, and put each sentence in its own TextFragment.
+    Costs are inversely proportional to the sentence length.
+    """

docs/fake/shinypress/text/multiple.py

+class GreedyDualSize(object):
+    """
+    This text layout strategy will lay out the text on slides using two font
+    sizes: a user-specified "major" size and a smaller "minor" font size to
+    avoid widows from wrapped text.
+    """
+    def __init__(self, major_size, min_minor_size):
+        pass
+
+    def determine_breaks(self, text_fragments):
+        """
+        This is the first phase, which greedily breaks the given text into
+        slides. Fragments of text are placed on the slide at the major font
+        size until the slide vertically overflows, at which point the last
+        fragment is moved to the next slide, and the process continues.
+
+        :param text_fragments: list of TextFragment objects. The cost is unused.
+        :rtype: list of list of TextFragments.
+        """
+        pass
+
+    def determine_minor_size(self, slides):
+        """
+        The second phase determines the smaller font size by looking at the text
+        shape of each slide, and identifying widows from line wrapping. If any
+        exist, the font size is reduced until no lines have widows.
+        The minor font size is then the smallest required font size, unless it
+        is smaller than min_minor_size.
+
+        :param slides: list of list of TextFragment objects.
+        :rtype: float
+        """
+        pass
+
+    def layout(self, text_fragments):
+        """
+        Determine how to lay out the text.
+
+        :param text_fragments: list of TextFragment objects
+        :rtype: list of PangoLayout objects
+        """
+        pass
+
 optimising text layout on a single slide, whereas the *multiple* module provides
 functions for laying out text which make break across several slides.
 
+Usage
+~~~~~
+
+.. code-block:: python
+
+    from gi.repository import Pango
+
+    from shinypress.text import find_possible_breaks
+    from shinypress.text.multiple import GreedyDualSize
+
+    with open('pandp.txt', 'r') as f:
+        fragments = find_possible_breaks(f.read())
+
+    strategy = GreedyDualSize(48 * Pango.SCALE, 24 * Pango.SCALE)
+    pango_layouts = strategy.layout(fragments)
+
+Helper functions
+~~~~~~~~~~~~~~~~
+
+.. automodule:: shinypress.text
+    :members:
+
 Multiple slide layout
 ~~~~~~~~~~~~~~~~~~~~~
 
-.. automodule:: multiple
+.. automodule:: shinypress.text.multiple
     :members:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.