Skip to content

Commit

Permalink
Landscape and portrait sections: metanorma/metanorma-standoc#173
Browse files Browse the repository at this point in the history
  • Loading branch information
opoudjis committed Feb 4, 2020
1 parent 6ae49a0 commit 3973f41
Show file tree
Hide file tree
Showing 6 changed files with 193 additions and 8 deletions.
4 changes: 0 additions & 4 deletions lib/isodoc/convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,6 @@ def generate_css(filename, stripwordcss, fontheader)
"lib", "isodoc")
SassC.load_paths << File.dirname(filename)
engine = SassC::Engine.new(fontheader + stylesheet, syntax: :scss)
#outname = File.basename(filename, ".*") + ".css"
#File.open(outname, "w:UTF-8") { |f| f.write(engine.render) }
#@files_to_delete << outname
#outname
Tempfile.open([File.basename(filename, ".*"), "css"],
:encoding => "utf-8") do |f|
f.write(engine.render)
Expand Down
1 change: 0 additions & 1 deletion lib/isodoc/function/to_word_html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def rel_tmpimagedir
def define_head(head, filename, _dir)
if @standardstylesheet
head.style do |style|
#stylesheet = File.read(@standardstylesheet, encoding: "utf-8").
@standardstylesheet.open
stylesheet = @standardstylesheet.read.
gsub("FILENAME", File.basename(filename))
Expand Down
20 changes: 19 additions & 1 deletion lib/isodoc/word_function/postprocess.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ def postprocess(result, filename, dir)
def toWord(result, filename, dir, header)
result = populate_template(result, :word)
result = from_xhtml(word_cleanup(to_xhtml(result)))
unless @landscapestyle.empty?
@wordstylesheet&.open
@wordstylesheet&.write(@landscapestyle)
@wordstylesheet&.close
end
Html2Doc.process(result, filename: filename, stylesheet: @wordstylesheet&.path,
header_file: header&.path, dir: dir,
asciimathdelims: [@openmathdelim, @closemathdelim],
Expand Down Expand Up @@ -177,8 +182,21 @@ def generate_header(filename, _dir)
end

def word_section_breaks(docxml)
docxml.xpath("//br[@orientation]").each do |br|
@landscapestyle = ""
word_section_breaks1(docxml, "WordSection2")
word_section_breaks1(docxml, "WordSection3")
end

def word_section_breaks1(docxml, sect)
docxml.xpath("//div[@class = '#{sect}']//br[@orientation]").reverse.
each_with_index do |br, i|
@landscapestyle += "\ndiv.#{sect}_#{i} {page:#{sect}"\
"#{br["orientation"] == "landscape" ? "L" : "P"};}\n"
br.delete("orientation")
move = br.parent.xpath("following::node()") &
br.document.xpath("//div[@class = '#{sect}']//*")
docxml.at("//div[@class = '#{sect}']").
after("<div class='#{sect}_#{i}'/>").next_element << move.remove
end
end
end
Expand Down
1 change: 1 addition & 0 deletions spec/isodoc/cleanup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -762,4 +762,5 @@
OUTPUT
end

end
47 changes: 45 additions & 2 deletions spec/isodoc/inline_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<p>
<em>A</em> <strong>B</strong> <sup>C</sup> <sub>D</sub> <tt>E</tt>
<strike>F</strike> <smallcap>G</smallcap> <keyword>I</keyword> <br/> <hr/>
<bookmark id="H"/> <pagebreak/>
<bookmark id="H"/> <pagebreak/> <pagebreak orientation="landscape"/>
</p>
</foreword></preface>
<sections>
Expand All @@ -21,7 +21,7 @@
<p>
<i>A</i> <b>B</b> <sup>C</sup> <sub>D</sub> <tt>E</tt>
<s>F</s> <span style="font-variant:small-caps;">G</span> <span class="keyword">I</span> <br/> <hr/>
<a id="H"/> <br/>
<a id="H"/> <br/> <br/>
</p>
</div>
<p class="zzSTDTitle1"/>
Expand All @@ -31,6 +31,49 @@
OUTPUT
end

it "processes inline formatting (Word)" do
expect(xmlpp(IsoDoc::WordConvert.new({}).convert("test", <<~"INPUT", true))).to be_equivalent_to xmlpp(<<~"OUTPUT")
<iso-standard xmlns="http://riboseinc.com/isoxml">
<preface/><sections><clause>
<p>
<em>A</em> <strong>B</strong> <sup>C</sup> <sub>D</sub> <tt>E</tt>
<strike>F</strike> <smallcap>G</smallcap> <keyword>I</keyword> <br/> <hr/>
<bookmark id="H"/> <pagebreak/> <pagebreak orientation="landscape"/>
</p>
</clause></sections>
</iso-standard>
INPUT
#{WORD_HDR}
<p class='zzSTDTitle1'/>
<div>
<h1/>
<p>
<i>A</i>
<b>B</b>
<sup>C</sup>
<sub>D</sub>
<tt>E</tt>
<s>F</s>
<span style='font-variant:small-caps;'>G</span>
<span class='keyword'>I</span>
<br/>
<hr/>
<a id='H'/>
<p>
<br clear='all' style='mso-special-character:line-break;page-break-before:always'/>
</p>
<p>
<br clear='all' class='section' orientation='landscape'/>
</p>
</p>
</div>
</div>
</body>
</html>
OUTPUT
end

it "ignores index entries" do
expect(xmlpp(IsoDoc::HtmlConvert.new({}).convert("test", <<~"INPUT", true))).to be_equivalent_to xmlpp(<<~"OUTPUT")
<iso-standard xmlns="http://riboseinc.com/isoxml">
Expand Down
128 changes: 128 additions & 0 deletions spec/isodoc/postproc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1221,4 +1221,132 @@
OUTPUT
end

it "deals with landscape and portrait pagebreaks (Word)" do
FileUtils.rm_f "test.doc"
IsoDoc::WordConvert.new({wordstylesheet: "spec/assets/word.css", htmlstylesheet: "spec/assets/html.css", filename: "test"}).convert("test", <<~"INPUT", false)
<standard-document xmlns="http://riboseinc.com/isoxml">
<bibdata type="standard">
<title language="en" format="text/plain">Document title</title>
<version>
<draft>1.2</draft>
</version>
<language>en</language>
<script>Latn</script>
<status><stage>published</stage></status>
<ext>
<doctype>article</doctype>
</ext>
</bibdata>
<preface>
<introduction><title>Preface 1</title>
<p align="center">This is a <pagebreak orientation="landscape"/> paragraph</p>
<table>
<tbody>
<tr><td>A</td><td>B</td></tr>
</tbody>
</table>
<clause><title>Preface 1.1</title>
<p>On my side</p>
<pagebreak orientation="portrait"/>
<p>Upright again</p>
</clause>
<clause><title>Preface 1.3</title>
<p>And still upright</p>
</clause>
</introduction>
</preface>
<sections><clause><title>Foreword</title>
<note>
<p id="_">For further information on the Foreword, see <strong>ISO/IEC Directives, Part 2, 2016, Clause 12.</strong></p>
<pagebreak orientation="landscape"/>
<p>And side</p>
<pagebreak orientation="portrait"/>
<p>And up</p>
</note>
</clause></sections>
</standard-document>
INPUT
expect(File.exist?("test.doc")).to be true
html = File.read("test.doc", encoding: "UTF-8")
expect(html).to include "div.WordSection2_0 {page:WordSection2P;}"
expect(html).to include "div.WordSection2_1 {page:WordSection2L;}"
expect(html).to include "div.WordSection3_0 {page:WordSection3P;}"
expect(html).to include "div.WordSection3_1 {page:WordSection3L;}"

expect(xmlpp(html.sub(/^.*<body /m, "<body ").sub(%r{</body>.*$}m, "</body>"))).to be_equivalent_to xmlpp(<<~"OUTPUT")
<body lang='EN-US' xml:lang='EN-US' link='blue' vlink='#954F72'>
<div class='WordSection1'>
<p class='MsoNormal'>&#xA0;</p>
</div>
<p class='MsoNormal'>
<br clear='all' class='section'/>
</p>
<div class='WordSection2'>
<p class='MsoNormal'>
<br clear='all' style='mso-special-character:line-break;page-break-before:always'/>
</p>
<div class='Section3' id=''>
<h1 class='IntroTitle'>Introduction</h1>
<p align='center' style='text-align:center' class='MsoNormal'>
This is a
<p class='MsoNormal'>
<br clear='all' class='section'/>
</p>
paragraph
</p>
</div>
</div>
<div class='WordSection2_1'>
<div align='center' class='table_container'> </div>
<table class='MsoISOTable' style='mso-table-lspace:15.0cm;margin-left:423.0pt;mso-table-rspace:15.0cm;margin-right:423.0pt;mso-table-anchor-horizontal:column;mso-table-overlap:never;border-spacing:0;border-width:1px;'> </table>
<tbody> </tbody>
<tr> </tr>
<td style='border-top:solid windowtext 1.5pt;mso-border-top-alt:solid windowtext 1.5pt;border-bottom:solid windowtext 1.5pt;mso-border-bottom-alt:solid windowtext 1.5pt;'>A</td>
<td style='border-top:solid windowtext 1.5pt;mso-border-top-alt:solid windowtext 1.5pt;border-bottom:solid windowtext 1.5pt;mso-border-bottom-alt:solid windowtext 1.5pt;'>B</td>
<div> </div>
<h1>Preface 1.1</h1>
<p class='MsoNormal'>On my side</p>
<p class='MsoNormal'/>
<br clear='all' class='section'/>
</div>
<div class='WordSection2_0'>
<p class='MsoNormal'>Upright again</p>
<div> </div>
<h1>Preface 1.3</h1>
<p class='MsoNormal'>And still upright</p>
<p class='MsoNormal'>&#xA0;</p>
</div>
<p class='MsoNormal'>
<br clear='all' class='section'/>
</p>
<div class='WordSection3'>
<p class='zzSTDTitle1'>Document title</p>
<div>
<h1>Foreword</h1>
<div id='' class='Note'>
<p class='Note'>
<span class='note_label'>NOTE 1</span>
<span style='mso-tab-count:1'>&#xA0; </span>
For further information on the Foreword, see
<b>ISO/IEC Directives, Part 2, 2016, Clause 12.</b>
</p>
<p class='Note'>
<br clear='all' class='section'/>
</p>
</div>
</div>
</div>
<div class='WordSection3_1'>
<p class='Note'>And side</p>
<p class='Note'> </p>
<br clear='all' class='section'/>
</div>
<div class='WordSection3_0'>
<p class='Note'>And up</p>
</div>
<div style='mso-element:footnote-list'/>
</body>
OUTPUT
end

end

0 comments on commit 3973f41

Please sign in to comment.