2

Short version

How to use custom font, namely Kanji Stroke Order, in cards in AnkiDroid which is running on Android 9?

Full version

I'm learning Kanji characters. It's important to learn also how to draw them - the order of strokes. This is shown in Anki cards by using a special font - Kanji Stroke Orders - and simply printing the character in card with this font. However, I'm unable to make AnkiDroid to use the font, but it was working on my previous device (Android 5.1).

The deck describes that the font file should be copied to fonts sub-directory of AnkiDroid directory. And that it might be needed to remove version part of file name. So I copied the fonts to following paths:

  • /storage/emulated/0/AnkiDroid/fonts/KanjiStrokeOrders_v4.002.ttf
  • /storage/emulated/0/AnkiDroid/fonts/KanjiStrokeOrders.ttf

Doesn't work (the character is drawn simply with Arial or something like that).

I found another way - Installing Fonts in Anki documentation. This guide describes following approach:

  • Add underscore to the font file name.
  • Copy it to "collection.media" sub-directory of "User 1" sub-directory of AnkiDroid directory. I couldn't find the "User 1", but there was "collection.media" in AnkiDroid directory, so I used that.
  • Add @font-face { font-family: myfont; src: url("_arial.ttf"); } to style section of a card and use font-family: myfont in style of the kanji text block.

So what I added to the style section is:

@font-face
{
  font-family: KanjiStrokeOrders;
  src: url("_KanjiStrokeOrders.ttf");
}

Then I added to card text:

<span style="font-family:KanjiStrokeOrders;">{{Expression}}</style>

And copied the font files to:

  • /storage/emulated/0/AnkiDroid/collection.media/_KanjiStrokeOrders_v4.002.ttf
  • /storage/emulated/0/AnkiDroid/collection.media/_KanjiStrokeOrders.ttf

And just in case, I also created files:

  • /storage/emulated/0/AnkiDroid/fonts/_KanjiStrokeOrders_v4.002.ttf
  • /storage/emulated/0/AnkiDroid/fonts/_KanjiStrokeOrders.ttf
  • /storage/emulated/0/AnkiDroid/collection.media/KanjiStrokeOrders_v4.002.ttf
  • /storage/emulated/0/AnkiDroid/collection.media/KanjiStrokeOrders.ttf

Still doesn't work, the text replacing {{Expression}} placeholder is still rendered in Arial (or similar).

Other notes

  • The /storage/emulated/0/AnkiDroid directory was already created and contains Anki data, similar to what is in ~/Anki/User 1 on my PC (Linux, Ubuntu).
  • I'm sure the cards/notes are correct (correct format, content, etc.), because it works on PC and worked on my older Android 5.1 phone (I used export/import to migrate and for backups). (I don't rember where I put the font file in my previous phone; the device screen died and so I cannot check now.)
  • It seems that the AnkiDroid actually see the font; in settings / Appearance / Default font, there actually is option to select Kanji Stroke Orders (all four versions - with/without underscore and with/without version suffix). When I choose it (and set Default font applicability to Always), nothing change. But the font is also available under Browser and editor font - when I set this one to Kanji Stroke Orders, it will change questions and answers in Card browser and field values in note editor. So the font seems to be recognized by AnkiDroid and working.
4
  • Have you tried all of these debugging steps? github.com/ankidroid/Anki-Android/wiki/… – Nicolas Raoul Sep 11 '20 at 10:15
  • @NicolasRaoul Thanks for pointing that, I totally missed the page! So I started thoroughly checking one point after another. At point 5 - I already tried the PC version, but when I tried AnkiWeb now, it wasn't working. So I opened developer console in Firefox - and it contains errors like "glyf: Bad glyph flag (111), bit 6 must be set to zero for flag 529" for the font - it seems there's some problem with it. So I searched for another version (4.004 at nihilist.org.uk ) - and it's working (looking bit weird, but usable). So thanks a lot for pointing the way! – Early Blue Apple Sep 11 '20 at 18:19
  • @NicolasRaoul But I'm not sure how to handle this question now. Should I delete it? Or create an answer that the problem is with the font and Android 9 is unable to open it unlike 5? Or should you create answer from your comment? – Early Blue Apple Sep 11 '20 at 18:22
  • Just post your own answer, and accept it. It might be useful to others :-) – Nicolas Raoul Sep 13 '20 at 9:30
0

Short answer

The problem was in the font file. In case of Kanji Stroke Order, I used version 4.002 while newer version (4.004 when writing this answer), which can be downloaded at www.nihilist.org.uk, is working.

Long answer

I somehow missed faq when custom font is not working on AnkiDroid - it's good idea to check all of them.

My problem would be caught at point #9 (try different font) or #10 (if #9 is working, it means my font is not supported), although I found it already during test #5 - test on both Anki Desktop and Anki Web. As stated in question, I already tried the desktop, but until now I didn't try the web version. Turns out that web version wasn't working, but I could open developer console where I found out that the font file is referenced correctly, but browser has an issue with it.

Moral of the story:

  • AnkiDroid is using web browser functionality to display cards. Whether something on card (e.g. a font) works depends on the device.
  • When trying troubleshooting steps, do them all and as exactly as possible. I was really tempted to skip Anki Web (I already proved that my cards and font are working in desktop version) which actually pointed me in the right direction (you can open developer tools in desktop web browser while there is no such thing in AnkiDroid itself).

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.