Architecture

HandWriter follows the Object Oriented paradigm.
The conversion of a document of text is done through multiple levels of abstraction. This allows the program to tackle arrangement and conversion problems at the stages where they are encountered. Inheritance is used to avoid multiple instances of the same data members through objects of each layer (a data member is thus initialized only once, saving memory).

The class LineParser sits at the bottom of this architecture. It’s methods parse_line() and parse_line_constrained() both directly use the hashes.pickle file and convert the line of text that is fed to them into a line of handwritten text, word by word, horizontally stacking each image of a letter to form the word. Furthermore, parse_line_constrained() has a parameter to constrain the number of characters in a line (which is what a line in a page is really like). When a word overflows this character limit, that word and the rest of the line is considered as leftover text, the rest of the line is filled with whitespace, and the image of the line and leftover text is returned.

The class PageParser inherits from LineParser and is used to stack lines of text on top of each other. It has the method parse_page_constrained(), that parses a page similar to how the aforementioned constrained method parses a line - it stacks images of lines on top of each other and returns the image of a page and leftover text, filling in with whitespace as needed. The method parse_page_constrained() handles stacking leftover words from the previous line into the new line (this happens because you can type many more characters in a line than you would normally write on a page), and text alignment.

The class DocumentParser inherits from PageParser and parses the whole document. It uses the python-docx module to read text and metadata from the document, then relays this information to PageParser methods. These methods return the pages of the document in handwriting which are then compiled into a PDF.