Class: TypescriptWriterConTeXt

Inherits:
RFIL::RFI::Plugin show all
Defined in:
lib/rfil/rfi_plugin_context.rb

Overview

:enddoc:

Constant Summary collapse

STOPTYPESCRIPT =
"\\stoptypescript\n\n"

Instance Attribute Summary

Attributes inherited from RFIL::RFI::Plugin

#filetypes, #name

Instance Method Summary collapse

Constructor Details

#initialize(fontcollection) ⇒ TypescriptWriterConTeXt

Returns a new instance of TypescriptWriterConTeXt.



9
10
11
12
# File 'lib/rfil/rfi_plugin_context.rb', line 9

def initialize(fontcollection)
  @fc=fontcollection
  super(:context,:typescript)
end

Instance Method Details

#find_fontsObject

Returns hash: Style, font



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rfil/rfi_plugin_context.rb', line 32

def find_fonts
  ret={}
  @fc.fonts.each { |font|
    ret[""]=font if font.variant==:regular and font.weight==:regular 
#      ret[""]=font if font.variant==:regular and font.weight==:regular and font.style!=:sans
    ret["Bold"]=font if font.variant==:regular and font.weight==:bold
    ret["Italic"]=font if font.variant==:italic and font.weight==:regular
    ret["Caps"]=font if font.variant==:smallcaps and font.weight==:regular
  }
  ret
end

#run_pluginObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rfil/rfi_plugin_context.rb', line 16

def run_plugin
  ret=[]
  str=""
  puts "running context plugin" if @fc.options[:verbose]
  @fc.texenc.each { |e|
    str << typescript(e)
    str << "\n"
  }
  h={}
  h[:type]=:typescript
  h[:filename],h[:contents]=["type-#{@fc.name}.tex",str]
  ret.push(h)
  ret
end

#typescript(e) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/rfil/rfi_plugin_context.rb', line 43

def typescript(e)
  contextenc=case e.encname
             when "ECEncoding"
               "ec"
             when "TS1Encoding"
               "ts1"
             when "T1Encoding"
               "tex256"
             when "TeXBase1Encoding"
               "8r"
             else
               raise "unknown context encoding: #{e.encname}"
             end
  # i know that this is crap, it's just a start
  contextstyle=case @fc.style
               when :sans
                 "Sans"
               when :roman, :serif
                 "Serif"
               when :typewriter
                 "Typewriter"
               else
                 raise "unknown style found: #{@fc.style}"
               end
  tmp = ""
  fontname=@fc.name
  tmp << "\\starttypescript[#{@fc.style}][#{fontname}][name]\n"
  find_fonts.sort{ |a,b| a[0] <=> b[0]}.each { |style,font|
    tmp << "\\definefontsynonym [#{contextstyle}"
    p style
    tmp << "#{style}" if style.length > 0
    tmp << "] [#{fontname}"
    tmp << "-#{style}" if style.length > 0
    tmp << "]\n"
  }
  tmp << STOPTYPESCRIPT

  tmp << "\\starttypescript[#{@fc.style}][#{fontname}][#{contextenc}]\n"
  find_fonts.sort{ |a,b| a[0] <=> b[0]}.each { |style,font|
    tmp << "\\definefontsynonym [#{fontname}"
    tmp << "-#{style}" if style.length > 0
    tmp << "][#{font.tex_fontname(e)}]\n"
  }
  tmp << STOPTYPESCRIPT

  return tmp
end