Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"env": {
"PYTHONPATH": "${workspaceFolder}"
}
}
]
}
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Textporter -

Basic developer instructions here.
37 changes: 15 additions & 22 deletions dialog extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,23 @@
import fitz # PyMuPDF for PDF handling
import re
from krita import Krita
from collections import ChainMap

# Load default character styles from an .ini file
def load_default_styles_from_ini(file_path):
config = configparser.ConfigParser()
config.read(file_path)
character_styles = {}

ini_dict = {section: dict(config.items(section)) for section in config.sections()}
default_values = {'DefaultStyle':
{
'color':'0,0,0',
'font':'Arial',
'size':'12'
}}

for section in config.sections():
color_str = config.get(section, "color", fallback="0,0,0")
color = [int(c) for c in color_str.split(",")] # Store color as [R, G, B] list
character_styles[section] = {
"font": config.get(section, "font", fallback="Arial"),
"size": config.getint(section, "size", fallback=14),
"color": color
}

# Check if "default" is present, else add a default entry
if "default" not in character_styles:
character_styles["default"] = {
"font": "Arial",
"size": 14,
"color": [0, 0, 0]
}

return character_styles
merged_dict = {section: dict(ChainMap(ini_dict.get(section, {}), default_values[section])) for section in default_values}
return merged_dict

# Save character styles dictionary to JSON file

Expand Down Expand Up @@ -160,11 +152,12 @@ def add_dialogue_to_krita(pdf_file, page_ranges):
# Main usage example
if __name__ == "__main__":
# Load default styles from .ini file
print(" ✨ Loading default styles from settings.ini")
default_styles = load_default_styles_from_ini("settings.ini")
print(default_styles)
print("------------------------")
# Path to the PDF file
pdf_file = "/home/dave/Documents/Comic Jams/366_DungeonsAndBreakfast/Mimosa_FernNorfolk.docx.pdf"
#pdf_file = "/home/dave/Documents/Comic Jams/366_DungeonsAndBreakfast/Mimosa_FernNorfolk.docx.pdf"

# read in the text file an populate the characters
#default_styles = parse_character_styles_from_pdf(pdf_file, default_styles)
Expand All @@ -178,5 +171,5 @@ def add_dialogue_to_krita(pdf_file, page_ranges):
# Save parsed character styles to JSON for future use
#save_character_styles_to_json(default_styles, "/home/dave/Documents/Comic Jams/366_DungeonsAndBreakfast/character_styles.json")
#load parsed character styles from JSON
default_styles = load_character_styles_from_json("/home/dave/Documents/Comic Jams/366_DungeonsAndBreakfast/character_styles.json")
print(default_styles.keys())
#default_styles = load_character_styles_from_json("/home/dave/Documents/Comic Jams/366_DungeonsAndBreakfast/character_styles.json")
#print(default_styles.keys())
53 changes: 53 additions & 0 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[tool.poetry]
name = "textporter"
version = "0.1.0"
description = "Description Here"
authors = ["Dave Hingley <anim8or_2000@yahoo.co.uk>"]
license = "TBC"
readme = "README.md"
package-mode = false

[tool.poetry.dependencies]
python = "^3.12"
configparser = "^7.1.0"
pymupdf = "^1.24.13"
krita = {git = "https://github.com/rbreu/krita-python-mock.git"}


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
2 changes: 1 addition & 1 deletion settings.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[DefaultStyle]
font = Arial
size = 30
color = black
color = 0,0,0