def gen_jrxml_sizes(jrxml, jrxml_opts):
    root = jrxml.getroot()

    for (size, orientation) in jrxml_opts.page_sizes:
        root.set('name', ('_'.join([root.get('name'), size, orientation])).lower())
        margin = int(root.get('leftMargin')) + int(root.get('rightMargin'))

        curr_width = int(root.get('pageWidth'))
        width_idx, height_idx = (int(orientation == 'landscape'),
                                 int(orientation != 'landscape'))
        (target_width,
         target_height) = (SIZE_REGISTRY[size][width_idx],
                           SIZE_REGISTRY[size][height_idx])

        root.set('pageWidth', '%d' % target_width)
        root.set('columnWidth', '%d' % (target_width - margin))
        root.set('pageHeight', '%d' % target_height)

        scaling_factor = float(target_width - margin) / float(curr_width - margin)
        scale = lambda x: round(x * scaling_factor)

        for component in root.xpath("//jr:reportElement/..", namespaces=JRXML_NS):
            set_x(component, scale(get_x(component)))
            set_width(component, scale(get_width(component)))

        for width_attr in root.xpath("//jr:*[@width and name() != 'reportElement']", namespaces=JRXML_NS):
            width_attr.set('width', '%d' % scale(int(width_attr.get('width'))))

        yield jrxml
Example #2
0
def gen_jrxml_sizes(jrxml, jrxml_opts):
    root = jrxml.getroot()

    for (size, orientation) in jrxml_opts.page_sizes:
        root.set('name', ('_'.join([root.get('name'), size,
                                    orientation])).lower())
        margin = int(root.get('leftMargin')) + int(root.get('rightMargin'))

        curr_width = int(root.get('pageWidth'))
        width_idx, height_idx = (int(orientation == 'landscape'),
                                 int(orientation != 'landscape'))
        (target_width, target_height) = (SIZE_REGISTRY[size][width_idx],
                                         SIZE_REGISTRY[size][height_idx])

        root.set('pageWidth', '%d' % target_width)
        root.set('columnWidth', '%d' % (target_width - margin))
        root.set('pageHeight', '%d' % target_height)

        scaling_factor = float(target_width - margin) / float(curr_width -
                                                              margin)
        scale = lambda x: round(x * scaling_factor)

        for component in root.xpath("//jr:reportElement/..",
                                    namespaces=JRXML_NS):
            set_x(component, scale(get_x(component)))
            set_width(component, scale(get_width(component)))

        for width_attr in root.xpath(
                "//jr:*[@width and name() != 'reportElement']",
                namespaces=JRXML_NS):
            width_attr.set('width', '%d' % scale(int(width_attr.get('width'))))

        yield jrxml
Example #3
0
def _get_cell_contents(props):
    _validate_cell_contents(props)

    style = None
    cell_contents = etree.Element(JR + 'cellContents')
    for prop in props:
        frame = deepcopy(prop.getparent().getparent())
        set_x(frame, 0)
        set_y(frame, 0)

        report_element = frame[0]
        style = report_element.get('style', None)
        if style is not None:
            del report_element.attrib['style']

        cell_contents.append(frame)

    if style is not None:
        cell_contents.set('style', style)

    return cell_contents
def _get_cell_contents(props):
    _validate_cell_contents(props)

    style = None
    cell_contents = etree.Element(JR + 'cellContents')
    for prop in props:
        frame = deepcopy(prop.getparent().getparent())
        set_x(frame, 0)
        set_y(frame, 0)

        report_element = frame[0]
        style = report_element.get('style', None)
        if style is not None:
            del report_element.attrib['style']

        cell_contents.append(frame)

    if style is not None:
        cell_contents.set('style', style)

    return cell_contents