summaryrefslogtreecommitdiff
path: root/support/rfil/lib/rfil/rfi_plugin_latex.rb
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /support/rfil/lib/rfil/rfi_plugin_latex.rb
Initial commit
Diffstat (limited to 'support/rfil/lib/rfil/rfi_plugin_latex.rb')
-rw-r--r--support/rfil/lib/rfil/rfi_plugin_latex.rb95
1 files changed, 95 insertions, 0 deletions
diff --git a/support/rfil/lib/rfil/rfi_plugin_latex.rb b/support/rfil/lib/rfil/rfi_plugin_latex.rb
new file mode 100644
index 0000000000..86f2e9a1ad
--- /dev/null
+++ b/support/rfil/lib/rfil/rfi_plugin_latex.rb
@@ -0,0 +1,95 @@
+=begin rdoc
+Plugin for RFIL to create a fontdefinition file (<tt>.fd</tt>) for LaTeX
+=end
+
+# :enddoc:
+
+class FDWriterLaTeX < RFIL::RFI::Plugin
+
+ def initialize(fontcollection)
+ @fc=fontcollection
+ super(:latex,:sty)
+ end
+
+ def run_plugin
+ ret=[]
+ @fc.texenc.each { |e|
+ h={}
+ h[:type]=:fd
+ h[:filename],h[:contents]=latex_fd(e)
+ ret.push(h)
+ }
+ ret
+ end
+
+
+ # example, should be an extra plugin
+ def latex_fd(e)
+ latexenc=case e.encname
+ when "ECEncoding","T1Encoding"
+ "T1"
+ when "TeXBase1Encoding"
+ "8r"
+ when "TS1Encoding"
+ "TS1"
+ when "OT2AdobeEncoding"
+ "OT2"
+ else
+ raise "unknown latex encoding: #{e.encname}"
+ end
+ filename="#{latexenc}#{@fc.name}.fd"
+
+ fd="\\ProvidesFile{#{filename}}
+\\DeclareFontFamily{#{latexenc}}{#{@fc.name}}{}
+"
+ weight=[:m,:b,:bx]
+ variant=[:n,:sc,:sl,:it]
+ for i in 0..11
+ w=weight[i/4]
+ v=variant[i % 4]
+ f=find_font(w,v)
+ if f
+ name = f.tex_fontname(e)
+ else
+ if i < 4
+ name = "ssub * #{@fc.name}/m/n"
+ else
+ name = "ssub * #{@fc.name}/#{weight[i/4 - 1]}/#{v}"
+ end
+ end
+
+# [[:m,:n],[:m,:sc],[:m,:sl],[:m,:it],
+# [:b,:n],[:b,:sc],[:b,:sl],[:b,:it],
+# [:bx,:n],[:bx,:sc],[:bx,:sl],[:bx,:it]].each{ |w,v|
+# f=find_font(w,v)
+
+# name = f ? f.tex_fontname(e) : "<->ssub * #{@fc.name}/m/n"
+ fd << "\\DeclareFontShape{#{latexenc}}{#{@fc.name}}{#{w}}{#{v}}{
+ <-> #{name}
+}{}
+"
+ end
+ return [filename,fd]
+end
+ def find_font(w,v)
+ weight={}
+ variant={}
+ weight[:m]=:regular
+ weight[:b]=:bold
+ variant[:n]=:regular
+ variant[:it]=:italic
+ variant[:sl]=:slanted
+ variant[:sc]=:smallcaps
+
+ # w is one of :m, :b, :bx
+ # v is one of :n, :sc, :sl, :it
+ @fc.fonts.each { |font|
+ #p b[:weight]==weight[w]
+ if font.variant ==variant[v] and font.weight==weight[w]
+ return font
+ end
+ }
+ return nil
+ end
+
+end