From b8ae17ecf7492fe307e32a1e9d42589845b475d4 Mon Sep 17 00:00:00 2001 From: Akira TAGOH Date: Jan 19 2011 12:43:57 +0000 Subject: make html more decorative and informative --- diff --git a/bin/gen-defaultfonts-table.rb b/bin/gen-defaultfonts-table.rb index 6754467..42a8921 100755 --- a/bin/gen-defaultfonts-table.rb +++ b/bin/gen-defaultfonts-table.rb @@ -37,6 +37,18 @@ rescue LoadError require File.join(File.dirname(__FILE__), '..', 'lib', 'fontpackages', 'fontconfig') end +class FontInfo + + def initialize(fn, pkg, prio) + @fontname = fn + @package = pkg + @priority = prio + end # def initialize + + attr_reader :fontname, :package, :priority + +end # class FontInfo + yum_opts = nil rawhidever = nil ignore = false @@ -63,11 +75,17 @@ end pkg2lang = {} lang2pkg = {} -font2pkg = {} y = FontPackages::YumRepos.new(yum_opts) fp = FontPackages::FontPackages.new("f#{ARGV[0]}") -i = 0 +langpkglist = {} +Comps::Root.new("f#{ARGV[0]}").groups(:langonly).each do |g| + langpkglist[g.lang] = Comps::Group.new(g.name, g.lang, g.is_enabled?, g.is_visible?) + langpkglist[g.lang].push(*g.packages(:default).map {|p| p.name =~ /-fonts\Z/ ? p : nil}.compact) +end +fontgrppkglist = Comps::Group.new('fonts', nil, true, true) +fontgrppkglist.push(*Comps::Root.new("f#{ARGV[0]}").groups.map{|g| g.name == 'fonts' || g.name == 'legacy-fonts' ? g : nil}.compact.map {|g| g.packages(:default).map {|p| p.name =~ /-fonts\Z/ ? p : nil}.compact}.flatten) + fp.fontpackages(:default).sort.each do |pkg| next if pkg2lang.include?(pkg.name) STDERR.printf("%s\n", pkg.name) @@ -93,21 +111,14 @@ fp.fontpackages(:default).sort.each do |pkg| # for packages that has multiple config files. if fc.include?(generic_names_rule) then rules_availability |= true - font = nil if fc.has_alias?('sans-serif') then - font = fc.entity_of_alias('sans-serif') - sans << [priority, font] + sans << FontInfo.new(fc.entity_of_alias('sans-serif'), pkg, priority) end if fc.has_alias?('serif') then - font = fc.entity_of_alias('serif') - serif << [priority, font] + serif << FontInfo.new(fc.entity_of_alias('serif'), pkg, priority) end if fc.has_alias?('monospace') then - font = fc.entity_of_alias('monospace') - monospace << [priority, font] - end - unless font.nil? then - font2pkg[font] = pkg.name + monospace << FontInfo.new(fc.entity_of_alias('monospace'), pkg, priority) end end end @@ -118,7 +129,7 @@ fp.fontpackages(:default).sort.each do |pkg| end if sans.empty? && serif.empty? && monospace.empty? then - other << pkg.name + other << pkg end end rescue RuntimeError => e @@ -160,7 +171,7 @@ lang2pkg.each do |l,v| if k == :other then lang2pkg[l][k] = vv.sort elsif vv.length > 0 then - lang2pkg[l][k] = vv.sort{|x,y| x[0] <=> y[0]}.map{|x| x[1]} + lang2pkg[l][k] = vv.sort{|x,y| x.priority <=> y.priority} end end end @@ -174,43 +185,53 @@ print "table, th, td {\n" print " border: 1px solid black;\n" print "}" print "\n" -print "\n" +print "\n" +print "
Legend: Bold: default font, Italic: installed only when selecting the language support, gray color: affecting to the language if installed
" +print "
languagesansserifmonospaceother
\n" print "" +proc = Proc.new do |a,lang| + default = false + lang_default = false + (0..a.length-1).each do |i| + printf(", ") if i > 0 + in_font = fontgrppkglist.has_package?(a[i].package) + in_lang = !langpkglist[lang].nil? && langpkglist[lang].has_package?(a[i].package) + printf("") if (!default && (in_font || (!in_font && !in_lang))) || (!lang_default && in_lang) + printf("") if !in_font && in_lang + printf("%s", a[i].package.name, !in_font && !in_lang ? "color: gray;" : "", a[i].fontname) + printf("") if !in_font && in_lang + printf("") if (!default && (in_font || (!in_font && !in_lang))) || (!lang_default && in_lang) + if in_font then + default = lang_default = true + elsif in_lang then + lang_default = true + else + default = true + end + end +end lang2pkg.keys.sort.each do |l| print "" printf("", l) printf("\n\n\n\n") print "\n" end print "
languagesansserifmonospaceother
%s") - (0..lang2pkg[l][:sans].length-1).each do |i| - printf(", ") if i > 0 - printf("") if i == 0 - font = lang2pkg[l][:sans][i] - printf("%s", font2pkg[font], font) - printf("") if i == 0 - end + proc.call(lang2pkg[l][:sans], l) printf("") - (0..lang2pkg[l][:serif].length-1).each do |i| - printf(", ") if i > 0 - printf("") if i == 0 - font = lang2pkg[l][:serif][i] - printf("%s", font2pkg[font], font) - printf("") if i == 0 - end + proc.call(lang2pkg[l][:serif], l) printf("") - (0..lang2pkg[l][:monospace].length-1).each do |i| - printf(", ") if i > 0 - printf("") if i == 0 - font = lang2pkg[l][:monospace][i] - printf("%s", font2pkg[font], font) - printf("") if i == 0 - end + proc.call(lang2pkg[l][:monospace], l) printf("") (0..lang2pkg[l][:other].length-1).each do |i| printf(", ") if i > 0 - printf("%s", lang2pkg[l][:other][i]) + package = lang2pkg[l][:other][i] + in_font = fontgrppkglist.has_package?(package) + in_lang = !langpkglist[l].nil? && langpkglist[l].has_package?(package) + printf("") if !in_font && in_lang + printf("%s", !in_font && !in_lang ? "color: gray;" : "", package.name) + printf("") if !in_font && in_lang end printf("
\n" -print "
Generated by #{File.basename(__FILE__)} at fontpackages
\n" +print "
Generated by #{File.basename(__FILE__)} in fontpackages
\n" print "\n" diff --git a/lib/fontpackages/comps.rb b/lib/fontpackages/comps.rb index 1d3d184..b367ab5 100644 --- a/lib/fontpackages/comps.rb +++ b/lib/fontpackages/comps.rb @@ -149,7 +149,7 @@ module Comps Dir.chdir(tmpdir) system("git clone git://git.fedorahosted.org/git/comps.git 1>&2") Dir.glob("comps/comps-*.xml.in") do |fn| - doc = Hpricot(File.open(fn).read) + doc = Hpricot.XML(File.open(fn).read) fn =~ /comps-(.*)\.xml\.in/ @@Releases2comps[$1] = doc end