def _cache_xobj(contents, resources, mbox, bbox, rotation): ''' Return a cached Form XObject, or create a new one and cache it. Adds private members x, y, w, h ''' cachedict = contents.xobj_cachedict cachekey = mbox, bbox, rotation result = cachedict.get(cachekey) if result is None: func = (_get_fullpage, _get_subpage)[mbox != bbox] result = PdfDict( func(contents, resources, mbox, bbox, rotation), Type=PdfName.XObject, Subtype=PdfName.Form, FormType=1, BBox=PdfArray(bbox), ) rect = bbox if rotation: matrix = (rotate_point((1, 0), rotation) + rotate_point((0, 1), rotation)) result.Matrix = PdfArray(matrix + (0, 0)) rect = rotate_rect(rect, rotation) result.private.x = rect[0] result.private.y = rect[1] result.private.w = rect[2] - rect[0] result.private.h = rect[3] - rect[1] cachedict[cachekey] = result return result
def _cache_xobj(contents, resources, mbox, bbox, rotation): ''' Return a cached Form XObject, or create a new one and cache it. Adds private members x, y, w, h ''' cachedict = contents.xobj_cachedict if cachedict is None: cachedict = contents.private.xobj_cachedict = {} cachekey = mbox, bbox, rotation result = cachedict.get(cachekey) if result is None: func = (_get_fullpage, _get_subpage)[mbox != bbox] result = PdfDict( func(contents, resources, mbox, bbox, rotation), Type=PdfName.XObject, Subtype=PdfName.Form, FormType=1, BBox=PdfArray(bbox), ) rect = bbox if rotation: matrix = rotate_point((1, 0), rotation) + \ rotate_point((0, 1), rotation) result.Matrix = PdfArray(matrix + (0, 0)) rect = rotate_rect(rect, rotation) result.private.x = rect[0] result.private.y = rect[1] result.private.w = rect[2] - rect[0] result.private.h = rect[3] - rect[1] cachedict[cachekey] = result return result