Text in documents can be accessed by finding the glyphs nodes on a page. Each glyphs node will contain a run of text.
Mako Text Analysis
Some documents can be poorly constructed when it comes to text. You may find a document where each character is individually placed. In this case, when Mako imports a document, it uses intelligent heuristics to try and join these individual characters up into runs of text to make onwards processing easier.
The following code finds all glyphs nodes font anywhere within the content node.
Updating text requires a little more knowledge about how documents are constructed. Specifically, A document may contain a font which is subsetted. This means that only the parts of the font used in the document is included.
For example, if a document contains glyphs with the characters 'a', 'b' and 'c', the embedded font may only contain visual information for the characters 'a', 'b' and 'c'. Therefore, if you update the glyphs text from 'abc' to 'abcd', you may find that the character 'd' is not rendered correctly when the document is output and viewed.
To avoid this issue, the full font should be loaded. This can be done by retrieving a specific font from disk, or by finding the font using Mako APIs.
Once the full font has been loaded or found, the text can be updated by using:
If the replacement font is different, it's always a good idea to reset the font's indices in the glyphs node.
Loading a Font from Disk
The code below finds the path to the Arial font in the Windows font folder.
Finding a Font using Mako
The code below finds the name of the font used in an existing glyphs node. This font is then attempted to be found using the mako API IJawsMako::findFont(...). If it can't find it, the code returns Arial as a default.
Converting Text to Paths
In some cases, it may be desired to convert all text into paths. Thankfully Mako makes this very simple.
The code below calls getEquivalentPath(...) to get a new IDOMPathNode. This IDOMPathNode contains the vector content that represents the orignal text. It's been setup correctly so the next step is simple to replace the existing IDOMGlyphs node.