Commit 3a643710 authored by Miguel Angel Reina Ortega's avatar Miguel Angel Reina Ortega
Browse files

Adding pure python emf to png converter

parent f46a2a97
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -20,3 +20,4 @@ rich==13.7.0
    # via oneM2M-spec-2-MD-converter (setup.py)
    # via oneM2M-spec-2-MD-converter (setup.py)
typing-extensions==4.8.0
typing-extensions==4.8.0
    # via python-docx
    # via python-docx
pillow==10.1.0
+13 −4
Original line number Original line Diff line number Diff line
@@ -26,6 +26,8 @@ from rich import inspect
import configparser, zipfile
import configparser, zipfile
from lxml import etree as ET
from lxml import etree as ET


from PIL import Image

class Style(IntEnum):
class Style(IntEnum):
	example = auto()
	example = auto()
	image = auto()
	image = auto()
@@ -620,6 +622,7 @@ def processDocuments(documents:list[str], outDirectory:str, skipImageConversion:
						elif style in docConfig.tablecaption:
						elif style in docConfig.tablecaption:
							lines.append('')
							lines.append('')
							caption = replaceNL(text).strip()
							caption = replaceNL(text).strip()
							caption = replaceNL(text).strip()
							anchor = f'<a name="table_{caption[6:].split(":")[0].strip()}"></a>' if caption.startswith('Table ') and ':' in caption else ''
							anchor = f'<a name="table_{caption[6:].split(":")[0].strip()}"></a>' if caption.startswith('Table ') and ':' in caption else ''
							lines.append(f'**{caption}**{anchor}')
							lines.append(f'**{caption}**{anchor}')


@@ -824,10 +827,12 @@ def processDocuments(documents:list[str], outDirectory:str, skipImageConversion:
						cmd = converter
						cmd = converter
						cmd = cmd.replace('{infile}', fn).replace('{outdir}', _t)
						cmd = cmd.replace('{infile}', fn).replace('{outdir}', _t)
						_print(f'Converting EMF file: {fn} to "{format}"', highlight = False)
						_print(f'Converting EMF file: {fn} to "{format}"', highlight = False)
						if (res := subprocess.run(cmd, shell = True, capture_output = True)).returncode != 0:

							_print(f'[red]Error running command: {res.stderr.decode("utf-8")}')
						convert(fn, fn[:-4])
							_print(f'[red]Please check the configuration file -> section "\[media]" for the converter command: {converter}')
						#if (res := subprocess.run(cmd, shell = True, capture_output = True)).returncode != 0:
							break
						#	_print(f'[red]Error running command: {res.stderr.decode("utf-8")}')
						#	_print(f'[red]Please check the configuration file -> section "\[media]" for the converter command: {converter}')
						#	break


			if not skipImageConversion:
			if not skipImageConversion:
				if docConfig.emfConverterPng:
				if docConfig.emfConverterPng:
@@ -842,6 +847,10 @@ def processDocuments(documents:list[str], outDirectory:str, skipImageConversion:


		progress.stop()
		progress.stop()


def convert(input:str, output_name:str):

	name=output_name+".png"
	Image.open(input).save(str(name))




if __name__ == '__main__':
if __name__ == '__main__':