diff options
Diffstat (limited to 'fonts/gentium-tug/source/gentium.rb')
-rw-r--r-- | fonts/gentium-tug/source/gentium.rb | 153 |
1 files changed, 139 insertions, 14 deletions
diff --git a/fonts/gentium-tug/source/gentium.rb b/fonts/gentium-tug/source/gentium.rb index 9f68654fd9..3e000645cf 100644 --- a/fonts/gentium-tug/source/gentium.rb +++ b/fonts/gentium-tug/source/gentium.rb @@ -1,5 +1,11 @@ # This file is part of the Gentium package for TeX. # It is licensed under the Expat License, see doc//README for details. +# +# This is just helper file for the main script generate-support-files.rb. +# It is not intended to be run directly +# +# TODO: Make it work with current version of Ruby! It works with version +# 1.8.7, but not with version as old as 1.9.1. require 'fileutils' @@ -226,7 +232,8 @@ class Encoding end end def has_bold? - return @supported_by_basic_family + # TODO: (Pavel) All fonts have bold weight. Refactor out the tests for bold. + return true end def has_smallcaps? if ["ts1", "agr", "lgr"].include?(@name) then @@ -274,8 +281,7 @@ class Encoding return "\\DeclareFontShape{#{name_latex_uppercase}}{gentium}{#{width1}}{#{shape1}}{<->ssub * gentium/#{width2}/#{shape2}}{}" end def generate_fd - date = "2012/02/06" - date = "2011/01/13" + date = "2022/05/09" filename = "#{name_latex}gentium.fd" File.open(File.join($path_fd,filename), 'w') do |file| @@ -293,14 +299,17 @@ class Encoding file.puts declare_font_shape("m", "n", "plus-regular") file.puts declare_font_shape("m", "it", "plus-italic") if has_bold? then - file.puts declare_font_shape("b", "n", "basic-bold") - file.puts declare_font_shape("b", "it", "basic-bolditalic") + file.puts declare_font_shape("b", "n", "plus-bold") + file.puts declare_font_shape("b", "it", "plus-bolditalic") # TODO: set the correct tfm names in the following two lines if has_smallcaps? then file.puts declare_font_shape("m", "sc", "plus-regular-sc") file.puts declare_font_shape("m", "scit", "plus-italic-sc") + file.puts declare_font_shape("b", "sc", "plus-bold-sc") + file.puts declare_font_shape("b", "scit", "plus-bolditalic-sc") end # TODO: a clever algorithm to do replacements instead + # TODO: (Pavel) Look at substitutions (bold, small caps) file.puts declare_font_shape_sub("m", "sl", "m", "it") file.puts declare_font_shape_sub("b", "sl", "b", "it") file.puts declare_font_shape_sub("bx", "sl", "b", "it") @@ -314,6 +323,59 @@ class Encoding end end + # TODO: (Pavel) Merge the following 3 methods with the previous 3 methods + def declare_font_shape_book(width, shape, name) + text = "\\DeclareFontShape{#{name_latex_uppercase}}{gentiumbook}{#{width}}{#{shape}}{\n" + + " <-> \\gentiumbook@@scale #{@name}-gentium#{name}\n" + + "}{}\n\n" + return text + end + def declare_font_shape_sub_book(width1, shape1, width2, shape2) + return "\\DeclareFontShape{#{name_latex_uppercase}}{gentiumbook}{#{width1}}{#{shape1}}{<->ssub * gentiumbook/#{width2}/#{shape2}}{}" + end + def generate_fd_book + date = "2022/05/09" + + filename = "#{name_latex}gentiumbook.fd" + File.open(File.join($path_fd,filename), 'w') do |file| + file.puts "\\ProvidesFile{#{name_latex}gentiumbook.fd}" + file.puts " [#{date} Font definitions for gentiumbook.]" + file.puts + file.puts '\expandafter\ifx\csname gentiumbook@scale\endcsname\relax' + file.puts ' \let\gentiumbook@@scale\@empty' + file.puts '\else' + file.puts ' \edef\gentiumbook@@scale{s*[\csname gentiumbook@scale\endcsname]}%' + file.puts '\fi' + file.puts + file.puts "\\DeclareFontFamily{#{name_latex_uppercase}}{gentiumbook}{}" + file.puts + file.puts declare_font_shape_book("m", "n", "book-regular") + file.puts declare_font_shape_book("m", "it", "book-italic") + if has_bold? then + file.puts declare_font_shape_book("b", "n", "book-bold") + file.puts declare_font_shape_book("b", "it", "book-bolditalic") + # TODO: set the correct tfm names in the following two lines + if has_smallcaps? then + file.puts declare_font_shape_book("m", "sc", "book-regular-sc") + file.puts declare_font_shape_book("m", "scit", "book-italic-sc") + file.puts declare_font_shape_book("b", "sc", "book-bold-sc") + file.puts declare_font_shape_book("b", "scit", "book-bolditalic-sc") + end + # TODO: a clever algorithm to do replacements instead + # TODO: (Pavel) Look at substitutions (bold, small caps) + file.puts declare_font_shape_sub_book("m", "sl", "m", "it") + file.puts declare_font_shape_sub_book("b", "sl", "b", "it") + file.puts declare_font_shape_sub_book("bx", "sl", "b", "it") + file.puts declare_font_shape_sub_book("bx", "it", "b", "it") + file.puts declare_font_shape_sub_book("bx", "n", "b", "n") + else + file.puts declare_font_shape_sub_book("m", "sl", "m", "it") + end + file.puts + file.puts '\endinput' + end + end + attr_reader :name end @@ -332,32 +394,95 @@ class EncodingSet < Hash fontlist.each do |font| self.each_value do |encoding| # TODO: fix the last name (gentium) & encodings: this is another parameter that we have to introduce - name_tfm = "#{encoding.name}-#{font.filename_tex}".ljust(33) + name_tfm = "#{encoding.name}-#{font.filename_tex}".ljust(35) + line_reenc = "\"gentium-#{encoding.name}Encoding ReEncodeFont\"".ljust(42) + name_enc = "gentium-#{encoding.name}.enc" + name_enc_ttf = "gentium-#{encoding.name_truetype}.enc" + + # normal + if font.is_plus? or encoding.has_bold? then + map_lines_type1[encoding.name].push("#{name_tfm} #{font.name_something.ljust(28)} #{line_reenc} <#{name_enc.ljust(24)} <#{font.filename_type1}") + map_lines_ttf[encoding.name].push("#{name_tfm} #{font.name_something.ljust(28)} <#{font.filename_ttf.ljust(18)} #{name_enc_ttf}") + end + # small caps + if font.is_plus? and encoding.has_smallcaps? then + name_tfm = "#{encoding.name}-#{font.filename_tex}-sc".ljust(35) + line_reenc = "\"gentium-#{encoding.name}scEncoding ReEncodeFont\"".ljust(42) + name_enc = "gentium-#{encoding.name}-sc.enc" + name_enc_ttf = "gentium-#{encoding.name_truetype_sc}.enc" + + map_lines_type1[encoding.name].push("#{name_tfm} #{font.name_something.ljust(28)} #{line_reenc} <#{name_enc.ljust(24)} <#{font.filename_type1}") + map_lines_ttf[encoding.name].push("#{name_tfm} #{font.name_something.ljust(28)} <#{font.filename_ttf.ljust(18)} #{name_enc_ttf}") + end + end + end + + # write map files into files + map_file_type1 = File.open(File.join($path_map, "gentiumplus-type1.map" ), 'w') + map_file_ttf = File.open(File.join($path_map_ttf, "gentiumplus-truetype.map"), 'w') + self.sort.map do |k,encoding| + # map file for Type1 + map_lines_type1[encoding.name].each do |line| + map_file_type1.puts line + end + # map file fon TrueType + map_lines_ttf[encoding.name].each do |line| + map_file_ttf.puts line + end + # map file for TrueType for a single encoding (for ConTeXt) + # if encoding.is_used_in_context? then + if true then + File.open(File.join($path_map_ttf, "gentiumplus-#{encoding.name}.map"), 'w') do |map_file_enc| + map_lines_ttf[encoding.name].each do |line| + map_file_enc.puts line + end + end + end + end + map_file_type1.close + map_file_ttf.close + end + + # TODO: (Pavel) Merge methods "generate_maps" and "generate_maps_book" + def generate_maps_book(fontlist) + # initialize lines for map files, one array for each encoding + map_lines_type1 = Hash.new + map_lines_ttf = Hash.new + self.each_value do |encoding| + map_lines_type1[encoding.name] = Array.new + map_lines_ttf[encoding.name] = Array.new + end + + # fill data + fontlist.each do |font| + self.each_value do |encoding| + # TODO: fix the last name (gentium) & encodings: this is another parameter that we have to introduce + name_tfm = "#{encoding.name}-#{font.filename_tex}".ljust(35) line_reenc = "\"gentium-#{encoding.name}Encoding ReEncodeFont\"".ljust(42) name_enc = "gentium-#{encoding.name}.enc" name_enc_ttf = "gentium-#{encoding.name_truetype}.enc" # normal if font.is_plus? or encoding.has_bold? then - map_lines_type1[encoding.name].push("#{name_tfm} #{font.name_something.ljust(24)} #{line_reenc} <#{name_enc.ljust(24)} <#{font.filename_type1}") - map_lines_ttf[encoding.name].push("#{name_tfm} #{font.name_something.ljust(24)} <#{font.filename_ttf.ljust(18)} #{name_enc_ttf}") + map_lines_type1[encoding.name].push("#{name_tfm} #{font.name_something.ljust(28)} #{line_reenc} <#{name_enc.ljust(24)} <#{font.filename_type1}") + map_lines_ttf[encoding.name].push("#{name_tfm} #{font.name_something.ljust(28)} <#{font.filename_ttf.ljust(18)} #{name_enc_ttf}") end # small caps if font.is_plus? and encoding.has_smallcaps? then - name_tfm = "#{encoding.name}-#{font.filename_tex}-sc".ljust(33) + name_tfm = "#{encoding.name}-#{font.filename_tex}-sc".ljust(35) line_reenc = "\"gentium-#{encoding.name}scEncoding ReEncodeFont\"".ljust(42) name_enc = "gentium-#{encoding.name}-sc.enc" name_enc_ttf = "gentium-#{encoding.name_truetype_sc}.enc" - map_lines_type1[encoding.name].push("#{name_tfm} #{font.name_something.ljust(24)} #{line_reenc} <#{name_enc.ljust(24)} <#{font.filename_type1}") - map_lines_ttf[encoding.name].push("#{name_tfm} #{font.name_something.ljust(24)} <#{font.filename_ttf.ljust(18)} #{name_enc_ttf}") + map_lines_type1[encoding.name].push("#{name_tfm} #{font.name_something.ljust(28)} #{line_reenc} <#{name_enc.ljust(24)} <#{font.filename_type1}") + map_lines_ttf[encoding.name].push("#{name_tfm} #{font.name_something.ljust(28)} <#{font.filename_ttf.ljust(18)} #{name_enc_ttf}") end end end # write map files into files - map_file_type1 = File.open(File.join($path_map, "gentium-type1.map" ), 'w') - map_file_ttf = File.open(File.join($path_map_ttf, "gentium-truetype.map"), 'w') + map_file_type1 = File.open(File.join($path_map, "gentiumbook-type1.map" ), 'w') + map_file_ttf = File.open(File.join($path_map_ttf, "gentiumbook-truetype.map"), 'w') self.sort.map do |k,encoding| # map file for Type1 map_lines_type1[encoding.name].each do |line| @@ -370,7 +495,7 @@ class EncodingSet < Hash # map file for TrueType for a single encoding (for ConTeXt) # if encoding.is_used_in_context? then if true then - File.open(File.join($path_map_ttf, "gentium-#{encoding.name}.map"), 'w') do |map_file_enc| + File.open(File.join($path_map_ttf, "gentiumbook-#{encoding.name}.map"), 'w') do |map_file_enc| map_lines_ttf[encoding.name].each do |line| map_file_enc.puts line end |