Created
March 4, 2009 10:38
-
-
Save kogakure/73789 to your computer and use it in GitHub Desktop.
Python: Simple calculator for target font-size (CSS) with em
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
def fontsize(base_fontsize, target_fontsize, lineheight): | |
lineheight_px = base_fontsize * lineheight | |
target_lineheight = lineheight_px / target_fontsize | |
target_fontsize_em = 1.0 / base_fontsize * target_fontsize | |
target_lineheight = round(target_lineheight, 4) | |
target_fontsize_em = round(target_fontsize_em, 4) | |
return "###################\nfont-size: %sem\nline-height: %s\nmargin-bottom: %s\n###################" % (target_fontsize_em, target_lineheight, target_lineheight) | |
base_fontsize = int(raw_input('base fontsize (px): ')) | |
lineheight = float(raw_input('line-height: ')) | |
target_fontsize = float(raw_input('Target font-size (px): ')) | |
result = fontsize(base_fontsize, target_fontsize, lineheight) | |
print result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment