My main goal is described here.

How can Microsoft Word or Wordpad or other word editing software render fonts when these fonts seems to not follow the same rules?

How do they render characters glyph based on adjacent(or sometimes even further neighboring) characters?

For example look at this font(it is free). opening it using font forge i learned that code-points from U+FE00 to U+FE87 are assigned to glyphs that do not represent those code points characters. still when you type in Word using that font and entering the keystrokes for those glyphs, the glyphs are rendered correctly.

Note: These glyph represent characters that do not have specific keys on keyboard, but are different forms of other characters. for example "ﻟ" is initial form of "ل" so Word must have some instruction(built-in instructions or instructions stored in font file) to render the desired form instead of isolated form.

Another example is the font IranNastaliq(also free) which is a very popular font in farsi and it's output is like calligraphy done in farsi. so it has lots of glyphs for combination of characters, etc.

  1. How does Word render these?
  2. How can I mimic it?
  3. How can I read the instructions(if there is any) inside of the font file?
  • 2
    I think it is safe to assume Word contains some components for Font rendering and character grouping which were developed by several dozens of devs over some decades, integrating tons of knowledge about how to solve this task. I doubt this question can be answered here on this site in a short paragraph (maybe parts of it).
    – Doc Brown
    Aug 8 '18 at 6:45
  • thanks for responding. now that i think about it you are probably right about the question as a whole but i think at least about incorrect codepoints people may be able to help.
    – HKhoshdel
    Aug 8 '18 at 6:53
  • Font rendering is fairly complicated, but that's the job of some font rendering engine. The font itself includes code that chooses appropriate forms and ligatures, this code is interpreted by the font rendering engine. You may be able to explicitly select various font features for OpenType fonts. E.g. CSS3 lets you play with these through the low-level font-feature-settings property.
    – amon
    Aug 8 '18 at 7:28
  • NOTE: Windows does have multiple input engines to deal with mapping your keyboard to a target language. Those input engines work for all applications, not just Word. That's how you include support for eastern languages when you are using a western keyboard for example. However, that is separate from the Unicode specification itself which has support for compound characters. Aug 15 '18 at 13:10

Those code points are variation sequences, which are combining marks that you use to select the visual variant of the prior code point, so that a single code point can have multiple visual representations. This is similar to diacritical marks, but instead of rendering on top of the glyph of the previous code point, they specify a different glyph or visual representation.

The rendering of unicode is specified in the unicode standard. All operating systems or rendering systems that implement the unicode standard can render variation sequences.

In fonts variation sequences are supported by mapping tables, which specify how to map particular code point sequences to indexes inside the font's table of glyphs.

  • thanks for the answer and sorry for the late response. though I did not fully understand your answer(maybe because of my English), it gave me some good idea and references about how it works so with things that i learned after reading your answer and links, i found some instructions inside the font file in some "GSUB" table. do you happen to know a way to use these instructions directly?
    – HKhoshdel
    Aug 11 '18 at 5:28
  • Sorry, I don't know that much about unicode rendering. I think you'll have to read the unicode specifications to figure all of this out. Aug 13 '18 at 7:20

Thanks to Joeri's answer I found out that along many other things, there is a table in ttf fonts called GSUB. In the GSUB table there are multiple sub-tables. These tables provide information to software like word so that they can choose the appropriate glyphs depending on where the character is in the word and what other character are adjacent to it and so on.

For using these table I could not find an easy way so i used fonttools to convert ttf data to xml format. inside the xml you can see that GSUB table has some lookup tables. To me the most interesting ones where the ones that where corresponding to initial,medial,final and isolated ("init","medi","fina" and "isol" respectively) characters. Using them I was able to determine the correct code-point of desired glyph. Although the problem with fonts like W_japan has been solved, for fonts like IranNastaliq there are many many details(about 300 subtables) to go through which is very hard.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.