
    h                         d Z ddlZddlZddlZddlmZ ddlmZmZ ddlm	Z	m
Z
mZmZ ddlmZ ddlmZ ddlmZ 	  ed	      Zddedee   ddfdZddZy# e$ r d
ZY w xY w)a  A tool for converting SVG to PDF.

This module provides a high-level function for converting SVG files to PDF format
using the ReportLab graphics library. It also serves as the main entry point for
the svglib package.

The module includes:
- svg2pdf(): Convert SVG files to PDF programmatically.
- main(): Command-line interface for SVG to PDF conversion.
- Automatic file path handling and output generation.
    N)datetime)PackageNotFoundErrorversion)basenamedirnameexistssplitext)Optional)	renderPDF)svglibr   unknownpath	outputPatreturnc                 f   t        |       xs dt        |       t        t        |       d         t        |       d   t        j                         dd}|xs d}||z  } |j
                  d
i |}	 t        j                  |       }|rt        j                  ||d       y	y	#  t        d        xY w)a  Convert an SVG file to PDF format.

    High-level function that loads an SVG file, converts it to a ReportLab drawing,
    and saves it as a PDF file. Supports both .svg and .svgz (compressed SVG) files.

    Args:
        path: Path to the input SVG file (.svg or .svgz extension).
        outputPat: Optional output path pattern. Supports placeholders:
            - %(dirname)s: Directory of input file
            - %(basename)s: Full filename with extension
            - %(base)s: Filename without extension
            - %(ext)s: File extension
            - %(now)s: Current datetime object
            - %(format)s: Output format (always "pdf")
            Also supports {name} format strings.

    Returns:
        None. The PDF file is written to disk.

    Raises:
        FileNotFoundError: If the input SVG file does not exist.
        Exception: If SVG parsing or PDF generation fails.
        OSError: If the output directory is not writable.

    Examples:
        Basic conversion:
        >>> svg2pdf("input.svg")  # Creates "input.pdf"

        Custom output location:
        >>> svg2pdf("input.svg", "output.pdf")

        Using placeholders:
        >>> svg2pdf("path/file.svg", "%(dirname)s/converted/%(base)s.pdf")
        # Creates "path/converted/file.pdf"

        Timestamped output:
        >>> svg2pdf("file.svg", "backup/%(now.year)s-%(now.month)s-%(base)s.pdf")

    Note:
        The function will overwrite existing PDF files without warning.
        For compressed SVG files (.svgz), the file is automatically decompressed.
    .r      pdf)r   r   baseextnowformatz%(dirname)s/%(base)s.%(format)szRendering failed.)showBoundaryN )r   r   r	   r   r   r   r   svg2rlgprintr   
drawToFile)r   r   	file_infoout_patternout_pathdrawings         ?/home/dcms/DCMS/lib/python3.12/site-packages/svglib/__init__.pysvg2pdfr#      s    \ 4='CTN$*+~a ||~I @@KY&Hx++H..& WhQ? !"s   1B" "B0c                  x   d} | j                         }t        t        t        j                  d         t
        d| |      }|dxx   d|d   z  z  cc<    dj                  di |}|d	j                  |      z  }t        j                   d
j                  di |      }t        j                  ||t        j                        }|j                  dddd       |j                  dddd       |j                  dddd       |j                         }|j                  r#t        t
               t        j                           |j"                  s$|j%                          t        j                           |j"                  D cg c]  }t'        |      s| }}|D ]  }	t)        |	|j*                          yc c}w )zMain entry point for the CLI.r   r   zC{{dirname}}/out-{{now.hour}}-{{now.minute}}-{{now.second}}-%(base)s)progr   
ts_patternr   ext_capsr&   z.%sr   z{prog} v. {version}
z4A converter from SVG to {} (via ReportLab Graphics)
a          examples:
          # convert path/file.svg to path/file.{ext}
          {prog} path/file.svg

          # convert file1.svg to file1.{ext} and file2.svgz to file2.{ext}
          {prog} file1.svg file2.svgz

          # convert file.svg to out.{ext}
          {prog} -o out.{ext} file.svg

          # convert all SVG files in path/ to PDF files with names like:
          # path/file1.svg -> file1.{ext}
          {prog} -o "%(base)s.{ext}" path/file*.svg

          # like before but with timestamp in the PDF files:
          # path/file1.svg -> path/out-12-58-36-file1.{ext}
          {prog} -o {ts_pattern} path/file*.svg

        issues/pull requests:
            https://github.com/deeplook/svglib
        )descriptionepilogformatter_classz-vz	--versionzPrint version number and exit.
store_true)helpactionz-oz--outputPATH_PATzsSet output path (incl. the placeholders: dirname, basename,base, ext, now) in both, %%(name)s and {name} notations.)metavarr,   inputPATH*z1Input SVG file path with extension .svg or .svgz.)r/   nargsr,   )r   Nr   )upperdictr   sysargv__version__r   textwrapdedentargparseArgumentParserRawDescriptionHelpFormatteradd_argument
parse_argsr   r   exitr0   print_usager   r#   output)
r   r'   format_argsdescr)   pargsapathsr   s
             r"   mainrI   g   s   
Cyy{Hchhqk" K U);!;;)"))8K8DCJJ8TTD__	 	* F+	"* !+	"F0 	 <<	A NNk @   NNC	   NN@	   <<>D||k
::	


01fQiQ0E0 -,- 1s   F7F7)N)r   N)__doc__r;   r6   r9   r   importlib.metadatar   r   os.pathr   r   r   r	   typingr
   reportlab.graphicsr   r   r8   strr#   rI   r       r"   <module>rQ      s}   
  
   < 7 7  ( (#K
D@# D@(3- D@4 D@PM-Y  Ks   A A! A!