当前位置: 首页>>代码示例>>Python>>正文


Python ParagraphStyle.splitLongWords方法代码示例

本文整理汇总了Python中reportlab.lib.styles.ParagraphStyle.splitLongWords方法的典型用法代码示例。如果您正苦于以下问题:Python ParagraphStyle.splitLongWords方法的具体用法?Python ParagraphStyle.splitLongWords怎么用?Python ParagraphStyle.splitLongWords使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在reportlab.lib.styles.ParagraphStyle的用法示例。


在下文中一共展示了ParagraphStyle.splitLongWords方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _makeGrid

# 需要导入模块: from reportlab.lib.styles import ParagraphStyle [as 别名]
# 或者: from reportlab.lib.styles.ParagraphStyle import splitLongWords [as 别名]
def _makeGrid(
    page,
    items,
    days,
    origin,
    size,
    gridline,
    gridcolor,
    **excessParams
    ):
    """
    Creates a single week of an itemized todo list.

    Keyword arguments:
    page -- a Canvas instance on which to draw
    items -- list of topics for a given week
    days -- list of day labels; 'Notes' creates a formatted note column
    origin -- origin of drawing area as (x, y) tuple
    size -- size of grid as (width, height) tuple
    gridline -- thickness of lines around cells
    gridcolor -- color of grid lines around cells
    """

    page.saveState()

    # fonts

    font_topics = 'FreeUniversal-Italic'
    font_days = 'FreeUniversal-Bold'

    # dimensions and layout

    days_label_size = 12
    topic_padding = 2

    (area_w, area_h) = size
    inner_h = area_h - days_label_size
    cell_h = inner_h / len(items)

        # check topic length

    max_topic_len = 40
    for item in items:
        if len(item) > max_topic_len:
            raise ValueError("The topic \'" + item + "\' is " + str(len(item))
                             + ' characters but should be under '
                             + str(max_topic_len) + ' characters.')

        # topic style

    topic_style = ParagraphStyle('TopicStyle')
    topic_style.fontSize = 10
    topic_style.leading = 12
    topic_style.alignment = TA_CENTER
    topic_style.fontName = font_topics
    topic_style.splitLongWords = 1

    topics = list()  # (topic, wrap_length)
    for item in items:
        p = Paragraph(item, topic_style)
        l = p.wrap(cell_h - 2 * topic_padding, 0)[1]
        topics.append((p, l))

        # max label size

    topic_label_size = topic_style.leading
    for (topic, wrap_length) in topics:
        if wrap_length > topic_label_size:
            topic_label_size = wrap_length

    topic_label_size_padded = topic_label_size + 2 * topic_padding  # add padding

    global key_spacer_left, key_spacer_indent
    key_spacer_left = topic_label_size_padded + key_spacer_indent

    inner_w = area_w - topic_label_size_padded
    cell_w = inner_w / len(days)

    if inner_w < 0 or inner_h < 0:
        raise ValueError('Specified dimensions do not fit on page.')

    # create plain table

    days_row = [[''] + days]
    tasks_rows = [[''] * (1 + len(days))] * len(items)

    data = days_row + tasks_rows
    col_w = [topic_label_size_padded] + [cell_w] * len(days)
    row_h = [days_label_size] + [cell_h] * len(items)
    table = Table(data, colWidths=col_w, rowHeights=row_h)

    # apply table style

    table_style = TableStyle()

    table_style.add('VALIGN', (1, 0), (-1, 0), 'MIDDLE')
    table_style.add('ALIGN', (1, 0), (-1, 0), 'CENTER')

    table_style.add('FONT', (1, 0), (-1, 0), font_days, 10)  # days
    table_style.add('TEXTCOLOR', (1, 0), (-1, 0), grey(100))
#.........这里部分代码省略.........
开发者ID:aboolean,项目名称:give-a-sheet,代码行数:103,代码来源:todo.py


注:本文中的reportlab.lib.styles.ParagraphStyle.splitLongWords方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。