Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- def addFontSpec(strSpec, strFontSpecs):
- if strSpec == 'normal':
- return strFontSpecs
- else:
- if strFontSpecs == '':
- return strSpec
- else:
- return strFontSpecs + ', ' + strSpec
- def main():
- lstFontSets = [{'setName': 'Microsoft core web', 'fontNameList': ['Arial', 'Arial Black', 'Comic Sans MS', 'Georgia', 'Impact', 'Times New Roman', 'Trebuchet MS', 'Verdana', 'Courier New']}]
- lstFontSets += [{'setName': 'Windows', 'fontNameList': ['Book Antiqua', 'Bookman Old Style', 'Calibri', 'Calisto MT', 'Candara', 'Cambria', 'Constantia', 'Corbel', 'Century Gothic', 'Garamond', 'Microsoft Sans Serif', 'News Gothic MT', 'Palatino Linotype', 'Tahoma', 'Monotype Corsiva', 'Andale Mono', 'Consolas', 'MS Mincho']}]
- lstFontSets += [{'setName': 'Mac', 'fontNameList': ['Chicago', 'New York', 'Palatino', 'Charcoal', 'Geneva', 'Monaco']}]
- lstFontSets += [{'setName': 'Linux', 'fontNameList': ['Bitstream Vera Sans', 'Bitstream Vera Sans mono', 'Bitstream Vera Serif', 'DejaVu Sans', 'DejaVu Sans mono', 'DejaVu Serif', 'Liberation Mono', 'Liberation Sans', 'Liberation Serif', 'Luxi Mono', 'Luxi Sans', 'Luxi Serif', 'New Century Schoolbook', 'Times', 'Utopia']}]
- lstFontSets += [{'setName': 'Web standard', 'fontNameList': ['serif', 'sans-serif', 'monospace', 'Courier']}]
- lstFontSets += [{'setName': 'Interesting', 'fontNameList': ['Lucida Console', 'Lucida Grande', 'Lucida Sans', 'Lucida Sans Unicode', 'Times New Roman PS', 'Times Ten', 'Times', 'Times New Roman', 'Arial MT', 'Arial Unicode MS', 'Century Schoolbook L', 'URW Gothic L', 'URW Chancery L', 'Nimbus Mono L', 'Nimbus Sans L', 'URW Palladio L', 'FreeMono', 'FreeSans', 'FreeSerif', 'Nimbus Roman No9 L', 'Baskerville', 'Inconsolata', 'Arial Narrow', 'Courier10 BT', 'DejaVu LGC Sans Mono', 'Lacuna']}]
- #lstWeights = ['thin', 'extralight', 'light', 'book', 'normal', 'medium', 'semibold', 'bold', 'extrabold', 'heavy']
- # These are the HTML names, rather than the fontconfig names - http://www.w3.org/Style/Examples/007/fonts
- lstWeights = ['100', 'normal', 'bold']
- # oblique is rare, so don't bother with it.
- # Sometimes italic is smaller than normal, and sometimes bigger.
- lstSlants = ['normal', 'italic']
- lstSizes = [8, 9, 10, 11, 12]
- # font-stretch isn't implemented in firefox - https://bugzilla.mozilla.org/show_bug.cgi?id=3512
- # 'extra-condensed', 'condensed', 'semi-condensed', ... , 'semi-expanded', 'expanded'
- #lstWidths = ['narrower', 'normal']
- strDir = '/tmp/'
- strFileNameBody = 'fontsample'
- # HTML header
- strHtmlText=''
- strCssText = '<style type="text/css">'
- strSample = 'the quick brown fox jumped over the lazy dog. 1234567890. THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG.'
- lngFontExample = 0
- for dicFontType in lstFontSets:
- strHtmlText += '<h1><font face="Times">' + dicFontType['setName'] + ' fonts</h1>'
- lstFontNames = dicFontType['fontNameList']
- for strFontName in sorted(dicFontType['fontNameList']):
- strHtmlText += '<table border="0">'
- for strWeight in lstWeights:
- for strSlant in lstSlants:
- for lngSize in lstSizes:
- # font-stretch isn't implemented in firefox - https://bugzilla.mozilla.org/show_bug.cgi?id=3512
- #for strWidth in lstWidths:
- lngFontExample += 1
- strFontSpecs = ''
- strFontSpecs = addFontSpec(str(lngSize), strFontSpecs) + 'pt'
- strFontSpecs = addFontSpec(strWeight, strFontSpecs)
- strFontSpecs = addFontSpec(strSlant, strFontSpecs)
- #strFontSpecs = addFontSpec(strWidth, strFontSpecs)
- # font-stretch: ' + strWidth + ';
- strCssText += 'p' + str(lngFontExample) + ' { font-family: "' + strFontName + '"; font-size: ' + str(lngSize) + 'pt; font-weight: ' + strWeight + '; font-style: ' + strSlant + '; }\n'
- strHtmlText += '<tr><td>' + strFontName + '</td><td>' + strFontSpecs + '</td><td>' + '<p' + str(lngFontExample) + '>' + strSample + '</p' + str(lngFontExample) + '></td></tr>\n'
- strHtmlText += '</table>'
- strCssText += '</style>'
- strHtmlText += '</body></html>'
- strFileText = '<html><head>' + strCssText + '</head>' + strHtmlText
- fHtml = open(strDir + strFileNameBody + '.html', 'wt')
- fHtml.write(strFileText)
- fHtml.close()
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement