Custom font in AnkiDroid in Android 9? (Kanji Stroke Order)


Question

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.


Answer

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).


Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes