Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The following code finds all glyphs nodes font anywhere within the content node.

Code Block
languagec#
titleC#
linenumberstrue
CEDLVectIDOMNode glyphsNodes = content.findChildrenOfType(eDOMNodeType.eDOMGlyphsNode);

...

Once the full font has been loaded or found, the text can be updated by using:

Code Block
languagec#
titleC#
linenumberstrue
glyphs.setFont(fullFont);
glyphs.setUnicodeString(updatedText);
glyphs.setIndices(string.Empty);

...

The code below finds the path to the Arial font in the Windows font folder.

Code Block
languagec#
titleC#
linenumberstrue
var arialFontPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "Arial.ttf");
using var stream = IInputStream.createFromFile(factory, arialFontPath);

using var font = IDOMFontOpenType.create(factory, stream);

...

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.

Code Block
languagec#
titleC#
linenumberstrue
using var originalFont = glyphs.getFont();

if (originalFont.getFontType() != IDOMFont.eFontType.eFontTypeOpenType)
    throw new InvalidOperationException("Font is not compatible with Mako.");

var originalTrueTypeFont = IDOMFontOpenType.fromRCObject(originalFont.toRCObject());
var fontName = originalTrueTypeFont.getFullName(factory, (int) glyphs.getFontIndex());

try
{
    return jawsMako.findFont(fontName, out _);
}
catch (Exception e)
{
    Console.WriteLine($"Failed to find font on local system: {e.Message}");
                
    // Fallback to Arial for testing.
    return jawsMako.findFont("Arial", out _);
}

...

The code below calls getEquivalentPath(...) to get a new IDOMPathNode. This IDOMPathNode contains the vector content that represents the original text. It's been setup correctly so the next step is simple to replace the existing IDOMGlyphs node.

Code Block
languagec#
titleC#
linenumberstrue
using var path = glyphs.getEquivalentPath();
glyphs.getParentNode().replaceChild(glyphs, path);

...