Personally I don't think we can find out an algorithm to calculate the most matched text color by specifying the background color.
I think currently the artist should have a list of color pairs which has good reading quality, we can add them to a table, and set one of these pairs randomly as our reading theme...
this is much reasonable, and we won't get ugly color pairs....