issue with Custom Font Not Displaying Properly in Microsoft Word when Switching to Russian Language

25 Views Asked by At

I'm encountering an issue with a custom font I've created. The font contains both English and Russian characters. When I add the custom font to Microsoft Word and switch from English to Russian language, the font changes to the default one instead of displaying the Russian characters from my custom font.

Created font: https://dropmefiles.net/ru/SHRNkYEV4m (don't pay attention to the characters in the font, this is just for example so there is not too much information. When I fill in all the characters, the error disappears)

Additionally, when I highlight text and select my custom font, the font applies correctly to the letters within the highlighted text. However, when I switch to the Russian language, the font reverts back to the default font, despite having chosen the custom font.

I've taken several steps to address this issue. I created the font using Python, copying characters and metadata from an existing font that supports both English and Russian. I ensured that Unicode code points for Russian characters are correctly copied (e.g., 0x430 for "а"). The encoding in my font is UnicodeFull, and metadata like language and encoding match those in the existing font.

I've tested the font in various text editors, and it displays both English and Russian characters as intended. The problem seems specific to Microsoft Word.

In addition, I tried copying all symbols from the functional font using FontForge and pasted them into my font. Despite these efforts, the issue persists.

Thank you in advance for your assistance!

    import sys
import os
import json
import uuid



class SVGtoTTF:

def convert(self, directory, outdir, config, metadata=None):
  
    import subprocess
    import platform

    subprocess.run(
        (
            ["ffpython"]
            if platform.system() == "Windows"
            else ["fontforge", "-script"]
        )
        + [
            os.path.abspath(__file__),
            config,
            directory,
            outdir,
            json.dumps(metadata),
        ]
    )

def set_properties(self):
    """Set metadata of the font from config."""
    props = self.config['props']
    lang = props.pop('lang', 'English (US)')
    family = props.pop('family', None)
    style = props.pop('style', 'Regular')
    props['encoding'] = props.get('encoding', 'UnicodeFull')
    if family is not None:
        self.font.familyname = family
        self.font.fontname = family + '-' + style
        self.font.fullname = family + ' ' + style
    for k, v in self.config['props'].items():
        if hasattr(self.font, k):
            if isinstance(v, list):
                v = tuple(v)
            setattr(self.font, k, v)
        else:
            self.font.appendSFNTName(lang, k, v)
    for t in self.config.get('sfnt_names', []):
        self.font.appendSFNTName(str(t[0]), str(t[1]), str(t[2]))

def add_glyphs(self, directory):
    IMPORT_OPTIONS = ('removeoverlap', 'correctdir')
    for k, v in self.config['glyphs'].items():
        g =  self.font.createMappedChar(int(k, 0))
        # Get outlines
        src = '%s.svg' % k
        if not isinstance(v, dict):
            v = {'src': v or src}
        src = v.pop('src', src)
        g.importOutlines(src, IMPORT_OPTIONS)
        g.removeOverlap()
        # Copy attributes
        for k2, v2 in v.items():
            if hasattr(g, k2):
                if isinstance(v2, list):
                    v2 = tuple(v2)
                setattr(g, k2, v2)


def generate_font_file(self, filename, outdir, config_file):
    if filename is None:
        raise NameError("filename not found in config file.")

    outfile = str(
        outdir
        + os.sep
        + (filename + ".ttf" if not filename.endswith(".ttf") else filename)
    )

    while os.path.exists(outfile):
        outfile = os.path.splitext(outfile)[0] + " (1).ttf"

    sys.stderr.write("\nGenerating %s...\n" % outfile)
    self.font.generate(outfile)

def convert_main(self, config_file, directory, outdir, metadata):
    try:
        self.font = fontforge.font()
    except:
        import fontforge

    with open(config_file) as f:
        self.config = json.load(f)
    self.metadata = json.loads(metadata) or {}

    self.font = fontforge.font()
    self.unicode_mapping = {}
    self.set_properties()
    self.add_glyphs(directory)

    # bearing table


    # Generate font and save as a .ttf file
    filename = self.metadata.get("filename", None) or self.config["props"].get(
        "filename", None
    )
    self.generate_font_file(str(filename), outdir, config_file)


if __name__ == "__main__":
    if len(sys.argv) != 5:
        raise ValueError("Incorrect call to SVGtoTTF")
    SVGtoTTF().convert_main(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])

Main:

from handwrite.svgtottf_new import  SVGtoTTF


from self import self


if __name__ == "__main__":

    metadata = {'filename': '_testNormalEng', "family": "testNormalEng", "style": "Regular"}
    characters_dir = "D:\\1\\newtest\\1\\"
    
    outDir = "D:\\1\\newtest\\"
    #
    convert = SVGtoTTF.convert(self=self, directory=characters_dir, outdir=outDir,metadata=metadata,config=".\\tests\\example.json")

Json:

    {
  "props": {
    "ascent": 96,
    "descent": 32,
    "em": 128,
    "encoding": "UnicodeFull",
    "lang": "English (US)",
    "family": "Example",
    "style": "Regular",
    "familyname": "Example",
    "fontname": "Example-Regular",
    "fullname": "Example Regular"
  },
  "glyphs":
  { "0x41": { "src": "D:\\1\\newtest\\1\\112\\112.svg" }
  , "0x42": { "src": "D:\\1\\newtest\\1\\113\\113.svg" }
  , "67": "D:\\1\\newtest\\1\\114\\114.svg"
  , "0x430": "D:\\1\\newtest\\1\\1045\\1045.svg"
  , "1046": "D:\\1\\newtest\\1\\1046\\1046.svg"
  },
  "sfnt_names": [
    [
      "English (US)",
      "Copyright",
      "Copyright (c) 2014 by Nobody"
    ],
    [
      "English (US)",
      "Family",
      "2Example"
    ],
    [
      "English (US)",
      "SubFamily",
      "Regular"
    ],
    [
      "English (US)",
      "UniqueID",
      "Example 20142-12-04"
    ],
    [
      "English (US)",
      "Fullname",
      "2Example Regular"
    ],
    [
      "English (US)",
      "Version",
      "Version 001.000"
    ],
    [
      "English (US)",
      "PostScriptName",
      "Example-Regular"
    ]
  ],



}
0

There are 0 best solutions below