def test_hpgl_flex_no_pagesize(simple_printer_config): doc = vp.Document() doc.add(vp.LineCollection([(1 + 1j, 2 + 4j)])) vp.config_manager.load_config_file(simple_printer_config) with pytest.raises(ValueError): vp.write_hpgl( output=sys.stdout, document=doc, landscape=False, center=False, device="simple", page_size="simple_flex_portrait", velocity=None, )
def test_hpgl_wrong_ref(simple_printer_config): doc = vp.Document() doc.add(vp.LineCollection([(1 + 1j, 2 + 4j)])) doc.page_size = 10, 15 vp.config_manager.load_config_file(simple_printer_config) with pytest.raises(ValueError): vp.write_hpgl( output=sys.stdout, document=doc, landscape=False, center=False, device="defective", page_size="wrong_ref", velocity=None, )
def write( document: vp.Document, cmd_string: Optional[str], output, file_format: str, page_size: str, landscape: bool, center: bool, layer_label: str, pen_up: bool, color_mode: str, device: Optional[str], velocity: Optional[int], quiet: bool, single_path: bool, ): """Write command.""" if document.is_empty(): logging.warning("no geometry to save, no file created") return document if file_format is None: # infer format _, ext = os.path.splitext(output.name) file_format = ext.lstrip(".").lower() if file_format == "svg": page_size_px = None if page_size: page_size_px = vp.convert_page_size(page_size) if landscape: page_size_px = page_size_px[::-1] vp.write_svg( output=output, document=document, page_size=page_size_px, center=center, source_string=cmd_string if cmd_string is not None else "", layer_label_format=layer_label, show_pen_up=pen_up, color_mode=color_mode, single_path=single_path, ) elif file_format == "hpgl": if not page_size: config = vp.config_manager.get_plotter_config(device) if config is not None: paper_config = config.paper_config_from_size( document.page_size) else: paper_config = None if paper_config and document.page_size is not None: page_size = paper_config.name landscape = document.page_size[0] > document.page_size[1] else: logging.error( "write: the plotter page size could not be inferred from the current page " "size (use the `--page-size SIZE` option)") return document vp.write_hpgl( output=output, document=document, landscape=landscape, center=center, device=device, page_size=page_size, velocity=velocity, quiet=quiet, ) else: logging.warning( f"write: format could not be inferred or format unknown '{file_format}', " "no file created (use the `--format` option)") return document
def write( vector_data: VectorData, cmd_string: Optional[str], output, file_format: str, page_format: str, landscape: bool, center: bool, layer_label: str, pen_up: bool, color_mode: str, single_path: bool, device: Optional[str], velocity: Optional[int], quiet: bool, ): """Write command.""" if vector_data.is_empty(): logging.warning("no geometry to save, no file created") return vector_data if file_format is None: # infer format _, ext = os.path.splitext(output.name) file_format = ext.lstrip(".").lower() if file_format == "svg": page_format_px = convert_page_format(page_format) if landscape: page_format_px = page_format_px[::-1] write_svg( output=output, vector_data=vector_data, page_format=page_format_px, center=center, source_string=cmd_string if cmd_string is not None else "", layer_label_format=layer_label, single_path=single_path, show_pen_up=pen_up, color_mode=color_mode, ) elif file_format == "hpgl": write_hpgl( output=output, vector_data=vector_data, landscape=landscape, center=center, device=device, page_format=page_format, velocity=velocity, quiet=quiet, ) else: logging.warning( f"write: format could not be inferred or format unknown '{file_format}', " "no file created" ) return vector_data