I have a bunch of OpenType font files with different weights and style (For example, ComicSans100.otf, ComicSans200.otf, ComicSans300.otf and TimeNewRoman.otf and TimesNewRomanItalic.otf). The person who provided me these files wasn't sure if the weight and style of the different fonts were modified. For example, characters in ComicSans400.otf
are from ComicSans100.otf
with a weight of 400, but tweaked to look better.
I want to know if there is a way to be sure that if I take ComicSans100.otf and apply it a weight of 400, all the characters will look the same as the characters from ComicSans400.otf.
The reason I'm asking this is that I want to use these fonts in an Android app. And every font increases the size of the app.
Here is a simple and visual way to validate that two of your fonts produce the same characters.
Define a
ConstraintLayout
with fourTextViews
:tv1
,tv2
,tv3
andtv4
. Define the text colors and fonts as follows. You are checking font1 and font2 against each other. (Make sure that the background of theTextViews
is transparent.tv1
: red, font1tv2
: blue, font2tv3
: blue, font2tv4
: red, font1Place
tv1
on top oftv2
andtv3
ontv4
.Place all the characters you want to check into each of the
TextViews
. Look for any color that doesn't match the color of the topTextView
. Fortv1
on top oftv2
your should see all red and no blue. Fortv3
on top oftv4
your should see all blue and no red.This could be automated but may not be worth the effort if a simple setup and visual inspection will suffice. One worthwhile automation may be to look for pixels of an offending color.
Here is what the layout could be. This trivial case just looks at the default font as bold and not bold.
Here is the output to see the differences. This snapshot is from the Android Studio designer.
If there are potentially a lot of characters to check, the above method will be difficult and prone to error. A more automated way is to define two text views like above, load them with identical text but use two fonts that will be tested against each other.
MainActivity.java
Here is a short bit of code that takes two TextViews and compares them pixel-by-pixel and logs if they are different or the same.