Exemplo n.º 1
0
 def initialize(self, choices=None):
     from calibre.utils.icu import numeric_sort_key
     if self.system_default_paper_size is None:
         PaperSizes.system_default_paper_size = 'a4'
         if iswindows or ismacos:
             # On Linux, this can cause Qt to load the system cups plugin
             # which can crash: https://bugs.launchpad.net/calibre/+bug/1861741
             PaperSizes.system_default_paper_size = 'letter' if QPrinter(
             ).pageSize() == QPagedPaintDevice.PageSize.Letter else 'a4'
     if not choices:
         from calibre.ebooks.conversion.plugins.pdf_output import PAPER_SIZES
         choices = PAPER_SIZES
     for a in sorted(choices, key=numeric_sort_key):
         s = getattr(QPageSize, a.capitalize())
         sz = QPageSize.definitionSize(s)
         unit = {
             QPageSize.Unit.Millimeter: 'mm',
             QPageSize.Unit.Inch: 'inch'
         }[QPageSize.definitionUnits(s)]
         name = f'{QPageSize.name(s)} ({sz.width():g} x {sz.height():g} {unit})'
         self.addItem(name, a)
Exemplo n.º 2
0
def get_page_size(opts, for_comic=False):
    use_profile = opts.use_profile_size and opts.output_profile.short_name != 'default' and opts.output_profile.width <= 9999
    if use_profile:
        w = (opts.output_profile.comic_screen_size[0]
             if for_comic else opts.output_profile.width)
        h = (opts.output_profile.comic_screen_size[1]
             if for_comic else opts.output_profile.height)
        dpi = opts.output_profile.dpi
        factor = 72.0 / dpi
        page_size = QPageSize(QSizeF(factor * w, factor * h),
                              QPageSize.Unit.Point,
                              matchPolicy=QPageSize.SizeMatchPolicy.ExactMatch)
    else:
        page_size = None
        if opts.custom_size is not None:
            page_size = parse_pdf_page_size(opts.custom_size, opts.unit,
                                            opts.output_profile.dpi)
        if page_size is None:
            page_size = QPageSize(
                getattr(QPageSize, opts.paper_size.capitalize()))
    return page_size
Exemplo n.º 3
0
 def start_print(self, data):
     margins = QMarginsF(0, 0, 0, 0)
     page_size = QPageSize(QPageSize.PageSizeId.A4)
     if isinstance(data, dict):
         try:
             if 'margins' in data:
                 margins = QMarginsF(*data['margins'])
             if 'size' in data:
                 sz = data['size']
                 if type(getattr(QPageSize, sz, None)) is type(
                         QPageSize.PageSizeId.A4):  # noqa
                     page_size = QPageSize(getattr(QPageSize, sz))
                 else:
                     from calibre.ebooks.pdf.image_writer import parse_pdf_page_size
                     ps = parse_pdf_page_size(sz, data.get('unit', 'inch'))
                     if ps is not None:
                         page_size = ps
         except Exception:
             pass
     page_layout = QPageLayout(page_size, QPageLayout.Orientation.Portrait,
                               margins)
     self.printToPdf('rendered.pdf', page_layout)
     self.printing_started = True
     self.start_time = monotonic()
Exemplo n.º 4
0
def parse_pdf_page_size(spec, unit='inch', dpi=72.0):
    width, sep, height = spec.lower().partition('x')
    if height:
        try:
            width = float(width.replace(',', '.'))
            height = float(height.replace(',', '.'))
        except Exception:
            pass
        else:
            if unit == 'devicepixel':
                factor = 72.0 / dpi
            else:
                factor = {
                    'point': 1.0,
                    'inch': inch,
                    'cicero': cicero,
                    'didot': didot,
                    'pica': pica,
                    'millimeter': mm,
                    'centimeter': cm
                }.get(unit, 1.0)
            return QPageSize(QSizeF(factor * width, factor * height),
                             QPageSize.Unit.Point,
                             matchPolicy=QPageSize.SizeMatchPolicy.ExactMatch)
Exemplo n.º 5
0
 def do_print(self, ok):
     p = QPageLayout(QPageSize(QPageSize(QPageSize.PageSizeId.A4)), QPageLayout.Orientation.Portrait, QMarginsF(72, 0, 72, 0))
     self.printToPdf(self.print_finished, p)