Inkscape: 예쁜 인쇄 없이 svg 파일을 저장하시겠습니까?

Inkscape: 예쁜 인쇄 없이 svg 파일을 저장하시겠습니까?

이제 Inkscape에서 편집하고 싶은 Powerpoint에서 생성된 SVG 파일이 있습니다. 수정 없이 Inkscape에서 해당 파일을 열고 저장하면 파일 크기가 120kB에서 170kB로 늘어납니다(Inkscape SVG가 아닌 일반 SVG로 저장합니다).

내가 아는 한, 이는 Inkscape에서 생성된 SVG가 꽤 인쇄되어 쓸모없는 공백이 많기 때문입니다.예쁜 글씨 없이 SVG 파일을 저장하는 방법이 있나요?

예를 들어 원본 파일의 다음 부분은 다음과 같습니다.

<linearGradient x1="272" y1="618" x2="272" y2="643" gradientUnits="userSpaceOnUse" spreadMethod="reflect" id="fill25"><stop offset="0" stop-color="#D2D2D2"/><stop offset="0.5" stop-color="#C8C8C8"/><stop offset="1" stop-color="#C0C0C0"/></linearGradient>

다음과 같이 저장됩니다.

<linearGradient
   id="fill1"
   spreadMethod="reflect"
   gradientUnits="userSpaceOnUse"
   y2="159"
   x2="272"
   y1="134"
   x1="272">
  <stop
     id="stop6277"
     stop-color="#D2D2D2"
     offset="0" />
  <stop
     id="stop6279"
     stop-color="#C8C8C8"
     offset="0.5" />
  <stop
     id="stop6281"
     stop-color="#C0C0C0"
     offset="1" />
</linearGradient>

답변1

예쁜 글씨 없이 SVG 파일을 저장하는 방법이 있나요?

주의 사항을 살펴보고 싶을 수도 있습니다.XML 형식화아래의 옵션SVG 출력환경설정:

전. XML 형식화

Inkscape SVG 출력 XML 형식 지정 - 스크린샷

이러한 옵션은 다음을 통해 사용할 수 있습니다.편집 → 환경 설정 → 입력/출력 → SVG 출력 → XML 형식 지정. 참고하세요편집 → 환경설정Ctrl+ Shift+ P(표시된 대로)를 통해서도 사용할 수 있습니다 .

Inline attributes(위) 에 대한 옵션을 표시하면 다음과 같이 유지되어야 합니다.

<linearGradient
   id="fill1"
   spreadMethod="reflect"
   gradientUnits="userSpaceOnUse"
   y2="159"
   x2="272"
   y1="134"
   x1="272">
  <stop
     id="stop6277"
     stop-color="#D2D2D2"
     offset="0" />
  <stop
     id="stop6279"
     stop-color="#C8C8C8"
     offset="0.5" />
  <stop
     id="stop6281"
     stop-color="#C0C0C0"
     offset="1" />
</linearGradient>

예:

<linearGradient x1="272" y1="618" x2="272" y2="643" gradientUnits="userSpaceOnUse" spreadMethod="reflect" id="fill25"><stop offset="0" stop-color="#D2D2D2"/><stop offset="0.5" stop-color="#C8C8C8"/><stop offset="1" stop-color="#C0C0C0"/></linearGradient>

주의사항

  • Inkscape가 파일을 원본과 약간 다른 형식으로 저장할 수 있기 때문에("plain"을 사용하더라도 .svg) Inkscape로 편집된 파일에는 약간의 작은 오버헤드가 여전히 적용될 수 있습니다.

  • 선행 공백 등과 관련하여 "전체" .svg태그는 깔끔한 인쇄를 위해 들여쓰기될 수 있습니다. 예:

    <g>
        <path fill="#FFFFFF" stroke="#F1F2F2" stroke-width="3" stroke-miterlimit="10" d="M314.267,104.257h-0.006H314.267z"/>
    

내가 착각한 것이 아니라면 현재 예를 들어 이미 인쇄가 잘 된 파일 Indent, spaces에는 조정이 아무런 영향을 미치지 않는 것 같습니다 . .svg태그(즉, 이 옵션은 새 파일에만 적용되는 것 같습니다).

선행 공백 등이 제거되었는지 확인하려면 텍스트 편집기나 스크립트를 사용하여 수동으로 제거해야 합니다.

  • 다음과 같은 텍스트 편집기를 사용할 수 있습니다.메모장++파일 을 열고 .svg선택하려면편집 → 공백 작업 → 선행 공백 자르기선행 공백을 제거합니다. 당신은 또한 사용할 수 있습니다편집 → 라인 작업 → 빈 라인 제거빈 줄을 제거하려면.

  • .svg특정 디렉터리에 있는 하나 이상의 파일에 대해 위 작업을 수행하는 스크립트를 작성할 수 있습니다 . 예를 들어,파이썬 3:

전. 감소_svg_files.py

    # Remove leading spaces and blank lines from a set of text files (e.g. ".svg"
    # files) in a directory with Python.

    # Preserves '\n' (linefeed) line endings (for file size considerations) by
    # reading/writing files as "binary".

    # This script would be run in the same directory as the original files.


    # --- Imports ---

    import os
    import os.path
    import sys


    # --- Variables ---

    # Where are the original files located?
    root_dir = '.\\'

    # What is the directory/path to write any reduced files to?
    mini_directory_name = 'mini'
    mini_output_directory = os.path.join(root_dir, mini_directory_name)

    # What file extension should the script work with?
    ext = '.svg'

    # What suffix should be added to the end of any reduced files?
    mini_suffix = ' - mini'


    # --- Main ---

    try:

        # Create the directory specified by "mini_output_directory", as needed.
        os.makedirs(mini_output_directory, exist_ok=True)

        # Read the directory contents (files and folder names) of "root_dir".
        directory_items = os.listdir(root_dir)

        # For every directory item returned...
        for directory_item in directory_items:

            # If that item is a file that also ends with "ext"...
            if os.path.isfile(directory_item) and directory_item.endswith(ext):

                # Create a list to hold the reduced contents of the file.
                svg_contents = []

                # Read the contents of the original file.
                with open(directory_item, 'rb') as svg_file:

                    # For each line in the file...
                    for svg_line in svg_file:

                        # Remove any leading spaces, etc. with ".lstrip()" and
                        # store each "cleaned" line in svg_contents[] (from above).
                        svg_contents.append(svg_line.lstrip())

                    # Then...

                    # Remove the "ext" from the original file name by replacing it
                    # with "nothing".
                    mini_title = directory_item.replace(ext, '')

                    # Add "mini_suffix" and then the "ext" back to the stripped
                    # file name to create the name for the reduced file.
                    mini_file = mini_title + mini_suffix + ext

                    # Create the full path to where the reduced file should be
                    # stored.
                    mini_path = os.path.join(mini_output_directory, mini_file)

                # Write the reduced file to this path.
                with open(mini_path, 'wb') as mini_output_path:
                    mini_output_path.writelines(svg_contents)

    # If there is a problem working with the OS while running the script, catch any
    # error then quit.
    except OSError as err:

        print('')
        print(err)
        sys.exit()

위의 두 옵션 모두 줄 끝을 유지하여 서식을 유지합니다. 주석에서 지적했듯이 줄 끝이 문제가 되지 않으면 Notepad++에서 다음과 같은 한 번의 작업으로 위와 동일한 두 단계를 (거의) 수행할 수 있습니다.편집 → 공백 작업 → 불필요한 공백 및 EOL 제거(모든 .svg파일 내용을 공백이 포함된 단일 텍스트 문자열로 변환)

태그 사이의 공백도 제거하려면 위의 Python 스크립트를 사용하여 다음을 변경할 수 있습니다.

svg_contents.append(svg_line.lstrip())

그냥 :

svg_contents.append(svg_line.strip())

그러나 이 두 번째 옵션을 사용하면 .svg각 줄이 "전체" 요소로 구성되지 않은 경우 출력 파일이 잘못 렌더링되어 읽을 수 없게 될 수 있습니다. 즉, <tag>원본 .svg파일 내용이 원하는 내용과 같게 보이도록 해야 합니다. 원래 질문에서 바람직하지 않은 "요소 목록").

관련 정보