Advertisement
Guest User

brebs

a guest
Apr 26th, 2010
659
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3.  
  4. def addFontSpec(strSpec, strFontSpecs):
  5.  
  6. if strSpec == 'normal':
  7. return strFontSpecs
  8. else:
  9. if strFontSpecs == '':
  10. return strSpec
  11. else:
  12. return strFontSpecs + ', ' + strSpec
  13.  
  14.  
  15. def main():
  16.  
  17. lstFontSets = [{'setName': 'Microsoft core web', 'fontNameList': ['Arial', 'Arial Black', 'Comic Sans MS', 'Georgia', 'Impact', 'Times New Roman', 'Trebuchet MS', 'Verdana', 'Courier New']}]
  18. 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']}]
  19. lstFontSets += [{'setName': 'Mac', 'fontNameList': ['Chicago', 'New York', 'Palatino', 'Charcoal', 'Geneva', 'Monaco']}]
  20. 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']}]
  21. lstFontSets += [{'setName': 'Web standard', 'fontNameList': ['serif', 'sans-serif', 'monospace', 'Courier']}]
  22. 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']}]
  23.  
  24. #lstWeights = ['thin', 'extralight', 'light', 'book', 'normal', 'medium', 'semibold', 'bold', 'extrabold', 'heavy']
  25. # These are the HTML names, rather than the fontconfig names - http://www.w3.org/Style/Examples/007/fonts
  26. lstWeights = ['100', 'normal', 'bold']
  27. # oblique is rare, so don't bother with it.
  28. # Sometimes italic is smaller than normal, and sometimes bigger.
  29. lstSlants = ['normal', 'italic']
  30. lstSizes = [8, 9, 10, 11, 12]
  31.  
  32. # font-stretch isn't implemented in firefox - https://bugzilla.mozilla.org/show_bug.cgi?id=3512
  33. # 'extra-condensed', 'condensed', 'semi-condensed', ... , 'semi-expanded', 'expanded'
  34. #lstWidths = ['narrower', 'normal']
  35.  
  36. strDir = '/tmp/'
  37. strFileNameBody = 'fontsample'
  38.  
  39. # HTML header
  40. strHtmlText=''
  41. strCssText = '<style type="text/css">'
  42.  
  43. strSample = 'the quick brown fox jumped over the lazy dog. 1234567890. THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG.'
  44.  
  45. lngFontExample = 0
  46. for dicFontType in lstFontSets:
  47. strHtmlText += '<h1><font face="Times">' + dicFontType['setName'] + ' fonts</h1>'
  48. lstFontNames = dicFontType['fontNameList']
  49. for strFontName in sorted(dicFontType['fontNameList']):
  50. strHtmlText += '<table border="0">'
  51. for strWeight in lstWeights:
  52. for strSlant in lstSlants:
  53. for lngSize in lstSizes:
  54. # font-stretch isn't implemented in firefox - https://bugzilla.mozilla.org/show_bug.cgi?id=3512
  55. #for strWidth in lstWidths:
  56. lngFontExample += 1
  57. strFontSpecs = ''
  58. strFontSpecs = addFontSpec(str(lngSize), strFontSpecs) + 'pt'
  59. strFontSpecs = addFontSpec(strWeight, strFontSpecs)
  60. strFontSpecs = addFontSpec(strSlant, strFontSpecs)
  61. #strFontSpecs = addFontSpec(strWidth, strFontSpecs)
  62. # font-stretch: ' + strWidth + ';
  63. strCssText += 'p' + str(lngFontExample) + ' { font-family: "' + strFontName + '"; font-size: ' + str(lngSize) + 'pt; font-weight: ' + strWeight + '; font-style: ' + strSlant + '; }\n'
  64. strHtmlText += '<tr><td>' + strFontName + '</td><td>' + strFontSpecs + '</td><td>' + '<p' + str(lngFontExample) + '>' + strSample + '</p' + str(lngFontExample) + '></td></tr>\n'
  65. strHtmlText += '</table>'
  66.  
  67. strCssText += '</style>'
  68. strHtmlText += '</body></html>'
  69. strFileText = '<html><head>' + strCssText + '</head>' + strHtmlText
  70.  
  71. fHtml = open(strDir + strFileNameBody + '.html', 'wt')
  72. fHtml.write(strFileText)
  73. fHtml.close()
  74.  
  75.  
  76. if __name__ == '__main__':
  77.  
  78. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement