Open JustFrederik opened 1 year ago
You can add it by creating a new ExportFormat class in manga_translator/save.py. It will be auto registered and you can get the text regions and intermediate images from the ctx variable.
@thatDudo not what I meant. The question was what the args of the function are and what default values it should use. It has quite a lot of options https://github.com/JustFrederik/image_writer/blob/master/src/input.rs
It also has existing formats, but it would need to be benchmarked to decide which is actually faster
I think something like this would work for our usecases:
from rust_renderer import PdfRenderer
pdf = PdfRenderer()
pdf.set_background(img)
pdf.add_text("text", (x, y, w, h), font_size=10, alignment="center", font_family="...", style="italic", color=0xFF0000, vertical=False)
pdf.save("file.pdf")
You dont have to make classes though thats just my personal preference xD.
Not sure if auto_dir will be enough or if you have to add that read_direction parameter (And infer direction from language).
@thatDudo i used the default values from my original test. They most likly need some change. I created a branch with an example in main.py.
#maturin develop --release
#style, vertical
pdf = mit_tools.PangoRenderer("", False)
pdf.set_background(img)
# text, (x, y, width, height), font_size, vertical_allignment, horizontal_alignment, font_color
pdf.add_text("Hello world", (0.0, 0.0, 100.0, 100.0), 12, "center", "center", 0xFF5733)
# filename, width, height, output format
pdf.save("hello.pdf", 6000, 6000, "pdf false")
pdf.save("hello.png", 6000, 6000, "png true")
pdf.save("hello.svg", 6000, 6000, "svg")
Sorry it took me so long @JustFrederik . I just tested it on my local machine and it works quite fine.
I searched up whether it is possible to add python type hints (linting) to pyo3 libraries but im not sure. Is it possible?
Im not quite sure what you mean. Do you mean the signature of the functions? Pyo3 docs.
It seems as though the function gets recognized as Any
and so I dont know which functions and arguments I can use with it.
Its probably not that important though.
save(..., 'pdf false')
the false
bool should be optional.For the outputmode like here save(..., 'pdf false') the false bool should be optional.
What should be the default behavior? Keep it in memory and merge or saving the image? Same goes for the other values like lossless compression for png and jpeg image quality
If needed setter methods for more options could be implemented. You just need to say what you want to change(char spacing, stroke width…) and what you want to keep as default.
Issue
I wanted a svg and pdf output so i found pango/cairo which is a c library that does that. It seemed like the library needed to be installed for the python version so i implemented it in rust so it will be compiled into the library. This is what i got: Cairo/Pango image renderer. Its pretty simple, but should work. It only needs python functions to call the code. An example for rust libaries in python would be Huggingface downloader. If you look into the code its just some macros and the pyo3 dependency.
(Also contains function to merge multiple pdfs into one file & render as svg/ps/jpeg/png/pdf/{some other image formats})
I need to know how it could be imlpemented into the python code. How should the python function look like. Example: