lib/isodoc/gb/gbwordconvert.rb in asciidoctor-gb-0.2.4 vs lib/isodoc/gb/gbwordconvert.rb in asciidoctor-gb-0.2.5
- old
+ new
@@ -1,30 +1,89 @@
require "isodoc"
-require_relative "./gbconvert"
+require_relative "gbconvert"
+require_relative "gbcleanup"
+require_relative "agencies"
+require_relative "metadata"
+require_relative "gbwordrender"
module IsoDoc
module Gb
# A {Converter} implementation that generates GB output, and a document
# schema encapsulation of the document for validation
- class WordConvert < IsoDoc::Gb::Convert
- include IsoDoc::WordConvertModule
+ class WordConvert < IsoDoc::WordConvert
+ def default_fonts(options)
+ script = options[:script] || "Hans"
+ b = options[:bodyfont] ||
+ (script == "Hans" ? '"SimSun",serif' :
+ script == "Latn" ? '"Cambria",serif' : '"SimSun",serif' )
+ h = options[:headerfont] ||
+ (script == "Hans" ? '"SimHei",sans-serif' :
+ script == "Latn" ? '"Calibri",sans-serif' : '"SimHei",sans-serif' )
+ m = options[:monospacefont] || '"Courier New",monospace'
+ scope = options[:scope] || "national"
+ t = options[:titlefont] ||
+ (scope == "national" ? (script != "Hans" ? '"Cambria",serif' : '"SimSun",serif' ) :
+ (script == "Hans" ? '"SimHei",sans-serif' : '"Calibri",sans-serif' ))
+ "$bodyfont: #{b};\n$headerfont: #{h};\n$monospacefont: #{m};\n$titlefont: #{t};\n"
+ end
+
+ def metadata_init(lang, script, labels)
+ @meta = Metadata.new(lang, script, labels)
+ @common = IsoDoc::Gb::Common.new(meta: @meta)
+ end
+
def html_doc_path(file)
File.join(File.dirname(__FILE__), File.join("html", file))
end
def initialize(options)
+ @common = IsoDoc::Gb::Common.new(options)
super
@wordstylesheet = generate_css(html_doc_path("wordstyle.scss"), false, default_fonts(options))
@standardstylesheet = generate_css(html_doc_path("gb.scss"), false, default_fonts(options))
@header = html_doc_path("header.html")
@wordcoverpage = html_doc_path("word_gb_titlepage.html")
@wordintropage = html_doc_path("word_gb_intro.html")
@ulstyle = "l7"
@olstyle = "l10"
end
+ def metadata_init(lang, script, labels)
+ @meta = Metadata.new(lang, script, labels)
+ @common = IsoDoc::Gb::Common.new(meta: @meta)
+ end
+
+ def cleanup(docxml)
+ @cleanup = Cleanup.new(@script, @deprecated_lbl)
+ super
+ @cleanup.cleanup(docxml)
+ docxml
+ end
+
+ def example_cleanup(docxml)
+ super
+ @cleanup.example_cleanup(docxml)
+ end
+
+ def html_doc_path(file)
+ File.join(File.dirname(__FILE__), File.join("html", file))
+ end
+
+ def i18n_init(lang, script)
+ super
+ y = if lang == "en"
+ YAML.load_file(File.join(File.dirname(__FILE__), "i18n-en.yaml"))
+ elsif lang == "zh" && script == "Hans"
+ YAML.load_file(File.join(File.dirname(__FILE__),
+ "i18n-zh-Hans.yaml"))
+ else
+ YAML.load_file(File.join(File.dirname(__FILE__), "i18n-zh-Hans.yaml"))
+ end
+ @labels = @labels.merge(y)
+ end
+
ENDLINE = <<~END.freeze
<v:line id="_x0000_s1026"
alt="" style='position:absolute;left:0;text-align:left;z-index:251662848;
mso-wrap-edited:f;mso-width-percent:0;mso-height-percent:0;
mso-width-percent:0;mso-height-percent:0'
@@ -37,15 +96,15 @@
end
def generate_header(filename, dir)
return unless @header
template = Liquid::Template.parse(File.read(@header, encoding: "UTF-8"))
- meta = get_metadata
+ meta = @meta.get
meta[:filename] = filename
params = meta.map { |k, v| [k.to_s, v] }.to_h
File.open("header.html", "w") { |f| f.write(template.render(params)) }
- system "cp #{fileloc(File.join('html', 'blank.png'))} blank.png"
+ system "cp #{@common.fileloc(File.join('html', 'blank.png'))} blank.png"
@files_to_delete << "blank.png"
@files_to_delete << "header.html"
end
def header_strip(h)
@@ -62,11 +121,11 @@
end
def word_cleanup(docxml)
word_preface(docxml)
word_annex_cleanup(docxml)
- title_cleanup(docxml.at('//div[@class="WordSection2"]'))
+ @cleanup.title_cleanup(docxml.at('//div[@class="WordSection2"]'))
docxml
end
#def word_intro(docxml)
#super
@@ -82,8 +141,12 @@
header_file: "header.html", dir: dir,
asciimathdelims: [@openmathdelim, @closemathdelim],
liststyles: {ul: "l7", ol: "l10"})
end
=end
+
+ def html_doc_path(file)
+ File.join(File.dirname(__FILE__), File.join("html", file))
+ end
end
end
end