ankidroid/Anki-Android — pull request #162 by chajadan (2014-01-06 20:00:45+00:00)
Title: Implement default font with override font

This change is on top of an as of yet uncommitted change #132, as I expect that change will be committed. This change fully contains the changes in #132 -- I recommend committing #132 explicitly, then this one if it is to be incorporated.

The design is as follows: default font will be set on any element that has no font otherwise specified for it, override font will override any font settings that have been specified, including default font. Override font is a simplistic way for a user to control the appearance of decks they did not author, without having to get into anki workings. Override functionality is now more deserving of its name, being applied to all html elements that may have had a font specified for them in cases where it wasn't being applied before. You want a hammer, you have a hammer.

One area of this change deserves a review, as it removes a section of code which was apparently considered important. Namely, it is the section where, upon creating the AnkiFont of a custom font, a list of attributes (bold, italic, etc.) where added to it. These are superfluous when one considers that the fonts being added, such as OpenSans-Bold.ttf, have these features built into the very font itself without a need to specify css styles about it. However, I believe this is because all of the OpenSans-***.ttf files were being passed in as a font-face of "OpenSans", which is generic. Thus, a list of imported files were all sharing the same reference, making it hard to distinguish individual entries by font-family alone.

The thing is, these @font-face declarations allow you to create a random id of your choice for the font. It seems the original code in this area wanted to preserve a generic family name across the OpenSans fonts, to be somehow representative. The result with override fonts was then that the font-family of OpenSans was being used, but font-style, such as italic, might very well be ignored. It doesn't make sense to ignore Italic-ness when the user specifically set up "OpenSans-Italic" as their override font. I had two choices: the change as I'm proposing it, or, to add !important after each attribute when a font is an override.

What was:
@font-face { font-family: "OpenSans"; font-weight: bolder; src: url('OpenSans-Bold.ttf'); }
@font-face { font-family: "OpenSans"; font-style: italic; src: url('OpenSans-Italic.ttf'); }

Is now:
@font-face { font-family: "OpenSans-BoldFontId"; src: url('OpenSans-Bold.ttf'); }
@font-face { font-family: "OpenSans-ItalicFontId"; src: url('OpenSans-Italic.ttf'); }

Notice that the font-family is made unique, going out of its way to avoid any association with any system font that may exist.

The concern is that somewhere somehow this "font css attributizing" is necessary of used in a way that necessitates the code that has been here sotofar.