示例#1
0
文件: bookjs.py 项目: fm-admin/Objavi
def make_pagination_config(args):
    """Creates pagination config. text using page setting arguments.
    """
    page_settings = book_utils.get_page_settings(args)

    # NOTE: size values from page settings are always in "points"

    page_size     = page_settings.get("pointsize", (420, 595))
    top_margin    = page_settings.get("top_margin",    0.8 * 72)
    bottom_margin = page_settings.get("bottom_margin", 0.8 * 72)
    side_margin   = page_settings.get("side_margin",   0.5 * 72)
    gutter        = page_settings.get("gutter",        0.8 * 72)

    page_width, page_height = page_size

    def unit(x):
        # Convert from points (pt) to whatever is specified by lengthUnit.
        # Division by 0.75 is because of a bug currently present in the
        # renderer using pt as device pixel instead of px.
        return x / 72.0 / 0.75

    config = {
        "lengthUnit"  : "in",
        "pageWidth"   : unit(page_width),
        "pageHeight"  : unit(page_height),
        "outerMargin" : unit(side_margin),
        "innerMargin" : unit(gutter),
        "contentsTopMargin"    : unit(top_margin),
        "contentsBottomMargin" : unit(bottom_margin),
    }

    items = ["%s:%s" % (key,repr(val)) for key,val in config.items()]
    text = ",".join(items)

    return text
示例#2
0
文件: tasks.py 项目: jalal70/Objavi
def make_book(context, args):
    """Creates a Book instance for the specified request context and request arguments.
    """
    book_args = {
        "page_settings"     : book_utils.get_page_settings(args),
        "watchers"          : context.get_watchers(),
        "license"           : args.get("license"),
        "max_age"           : float(args.get("max_age")),
        "page_number_style" : args.get("page_numbers"),
        }

    if args.get("isbn"):
        book_args["isbn"] = args.get("isbn")
    if args.get("title"):
        book_args["title"] = args.get("title")

    book = fmbook.Book(context.bookid, context.server, context.bookname, **book_args)

    toc_header = args.get("toc_header")
    if toc_header:
        book.toc_header = toc_header

    return book
示例#3
0
文件: tasks.py 项目: fm-admin/Objavi
def make_book(context, args):
    """Creates a Book instance for the specified request context and request arguments.
    """
    book_args = {
        "page_settings"     : book_utils.get_page_settings(args),
        "watchers"          : context.get_watchers(),
        "license"           : args.get("license"),
        "max_age"           : float(args.get("max_age")),
        "page_number_style" : args.get("page_numbers"),
        }

    if args.get("isbn"):
        book_args["isbn"] = args.get("isbn")
    if args.get("title"):
        book_args["title"] = args.get("title")

    book = fmbook.Book(context.bookid, context.server, context.bookname, **book_args)

    toc_header = args.get("toc_header")
    if toc_header:
        book.toc_header = toc_header

    return book
示例#4
0
文件: bookjs.py 项目: fm-admin/Objavi
def make_page_settings_css(args):
    """Creates a CSS using page setting arguments.
    """
    page_settings = book_utils.get_page_settings(args)

    page_size     = page_settings.get("pointsize", (420, 595))
    top_margin    = page_settings.get("top_margin",    0.4 * 72)
    bottom_margin = page_settings.get("bottom_margin", 0.4 * 72)
    side_margin   = page_settings.get("side_margin",   0.8 * 72)
    gutter        = page_settings.get("gutter",        1.0 * 72)

    page_width, page_height = page_size

    top            = 0.8 * 72
    bottom         = 0.8 * 72
    contents_width  = page_width - side_margin - gutter
    contents_height = page_height - top - bottom

    css_text = ""

    css_text += """
.page {
    width:  %fpt;
    height: %fpt;
}
""" % (page_width, page_height)

    css_text += """
.contents {
    height: %fpt;  /* page-height - top - bottom */
    top:    %fpt;  /* top-margin + header.height */
    bottom: %fpt;  /* bottom-margin + footer.height */
}
""" % (contents_height, top, bottom)

    css_text += """
.pagenumber {
    bottom: %fpt;  /* bottom-margin */
}

.header {
    top: %fpt;     /* top-margin */
}
""" % (bottom_margin, top_margin)

    css_text += """
.page:nth-child(odd) .contents, .page:nth-child(odd) .pagenumber, .page:nth-child(odd) .header {
    left:  %fpt;   /* gutter */
    right: %fpt;   /* side-margin */
}

.page:nth-child(even) .contents, .page:nth-child(even) .pagenumber, .page:nth-child(even) .header {
    left:  %fpt;   /* side-margin */
    right: %fpt;   /* gutter */
}
""" % (gutter, side_margin, side_margin, gutter)

    css_text += """
img {
    max-width:  %fpt;  /* contents-width  * <0,1] */
    max-height: %fpt;  /* contents-height * <0,1] */
}
""" % (contents_width * 0.9, contents_height * 0.8)

    return css_text