aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/sisu/v0/texpdf_format.rb
diff options
context:
space:
mode:
authorRalph Amissah <ralph@amissah.com>2007-12-17 00:07:08 +0000
committerRalph Amissah <ralph@amissah.com>2007-12-17 00:07:08 +0000
commita9d166c65f9d56b1d4de20fbdfae6e940681c535 (patch)
tree1b4efaac829c7be258a178e85728d959dbd01151 /lib/sisu/v0/texpdf_format.rb
parentsisu-0.62.4 + md5s (diff)
texpdf, generate sisu latex output in a single pass
implications if additional modules added e.g. provide dvi file without latex pdf headers or generate an A6 document by default for e-readers capable of reading pdf (this would otherwise require a separate pass/loop of content for each type to be generated) current shortcoming, images are sized for smaller landscape output by default, image dimension adjustments not yet made (for different orientation)
Diffstat (limited to 'lib/sisu/v0/texpdf_format.rb')
-rw-r--r--lib/sisu/v0/texpdf_format.rb95
1 files changed, 63 insertions, 32 deletions
diff --git a/lib/sisu/v0/texpdf_format.rb b/lib/sisu/v0/texpdf_format.rb
index f7d2177a..9506e17b 100644
--- a/lib/sisu/v0/texpdf_format.rb
+++ b/lib/sisu/v0/texpdf_format.rb
@@ -64,8 +64,8 @@ module SiSU_TeX_Pdf
include SiSU_Viz
class Use_TeX
attr_accessor :url,:txt,:date
- def initialize(md,orientation='')
- @md,@orientation=md,orientation
+ def initialize(md)
+ @md=md
@vz=SiSU_Env::Get_init.instance.skin
@date=SiSU_Env::Info_date.new # #{@date.year}
@copymark='{\\begin{footnotesize}\\raisebox{1ex}{\\copyright}\\end{footnotesize}}'
@@ -122,8 +122,8 @@ module SiSU_TeX_Pdf
"Contact Details for Original Promulgating Authority"
end
#BOOK standard dimensions - 229x156
- def newpage
- case @orientation
+ def newpage(orientation)
+ case orientation
when /landscape/ # using longtable latex package
<<WOK
\\clearpage
@@ -268,7 +268,7 @@ WOK
@@tex_backslash="\\\\"
@@tilde='\\\\\\~' #?? debug crazy
@@tex_pattern_margin_number="\\\\begin\\\{tiny\\\}~\\\\end\\\{tiny\\\}\\\{\\\\marginpar.+?\s+"
- @@tableheader=0
+ @@tableheader={ :p => 0, :l => 0 }
@@sys=SiSU_Env::System_call.new
@@flag_code=false
@@dp=nil
@@ -298,12 +298,12 @@ WOK
else @tx.a4.landscape.w #default currently A4
end
textwidth=(tw.to_i/2) - 24
- @@tableheader=1 if @string =~/<!Th/
- @w=cols_width.split(/;\s*/)
+ @@tableheader[:l]=1 if @string =~/<!Th/
+ w=cols_width.split(/;\s*/)
@@number_of_cols=no_of_cols
@colW=[]
@colW << '{'
- @w.each do |x|
+ w.each do |x|
x.strip!
x=(x.to_i * textwidth)/100
col_w=x.to_s # x.gsub(/.+/,'l\|') #unless x.nil?
@@ -319,14 +319,14 @@ WOK
@string.gsub!(/<!TZ!>/," #@end_table\n\\end{tiny}")
end
@string.gsub!(/<!¡/,'')
- if @@tableheader == 1
+ if @@tableheader[:l] == 1
if @string =~/¡\d+?¡(.+?)(?:¡|!)/
tablefoot=@string[/\<!f(.+?)!\>/,1]
@string.gsub!(/\<!f(.+?)!\>/,'')
@string.gsub!(/¡\d+?¡(.+?)(?:¡|!)/,'\bfseries \1&')
@string.gsub!(/&>\s*$/," #@row_break \\hline\\endhead #@row_break")
@string="#@string \\multicolumn{#{@@number_of_cols}}{l}{\\tiny #{tablefoot}} \\\\ \\hline\n\\endfoot\n\\hline\n" if tablefoot
- @@tableheader,@@number_of_cols=0,0
+ @@tableheader[:l],@@number_of_cols=0,0
end
else
if @string =~/¡\d+?¡(.+?)(?:¡|!)/
@@ -334,7 +334,9 @@ WOK
@string.gsub!(/&>\s*$/," #@row_break")
end
end
- @string="<~#{ocn}>" + @string
+ @string=if ocn; "<~#{ocn}>" + @string
+ else @string
+ end
end
def longtable_portrait
@end_table='\end{longtable}'
@@ -350,12 +352,12 @@ WOK
else @tx.a4.portrait.w #default currently A4
end
textwidth=tw.to_i - 20
- @@tableheader=1 if @string =~/<!Th/
- @w=cols_width.split(/;\s*/)
+ @@tableheader[:p]=1 if @string =~/<!Th/
+ w=cols_width.split(/;\s*/)
@@number_of_cols=no_of_cols
@colW=[]
@colW << '{'
- @w.each do |x|
+ w.each do |x|
x.strip!
x=(x.to_i * textwidth)/100
#x=(x.to_i/100.0 * 160)
@@ -372,14 +374,14 @@ WOK
@string.gsub!(/<!TZ!>/," #@end_table\n\\end{tiny}")
end
@string.gsub!(/<!¡/,'')
- if @@tableheader == 1
+ if @@tableheader[:p] == 1
if @string =~/¡\d+?¡(.+?)(?:¡|!)/
tablefoot=@string[/\<!f(.+?)!\>/,1]
@string.gsub!(/\<!f(.+?)!\>/,'')
@string.gsub!(/¡\d+?¡(.+?)(?:¡|!)/,'\bfseries \1&')
@string.gsub!(/&>\s*$/," #@row_break \\hline\\endhead #@row_break")
@string="#@string \\multicolumn{#{@@number_of_cols}}{l}{\\tiny #{tablefoot}} \\\\ \\hline\n\\endfoot\n\\hline\n" if tablefoot
- @@tableheader,@@number_of_cols=0,0
+ @@tableheader[:p],@@number_of_cols=0,0
end
else
if @string =~/¡\d+?¡(.+?)(?:¡|!)/
@@ -387,7 +389,9 @@ WOK
@string.gsub!(/&>\s*$/," #@row_break")
end
end
- @string="<~#{ocn}>" + @string
+ @string=if ocn; "<~#{ocn}>" + @string
+ else @string
+ end
end
def scopedtable
# some features related to headers have been incorporated in longtable that are not included yet here,
@@ -799,7 +803,7 @@ WOK
@string.gsub!(/\\\{\S+\.(png|jpg|gif).+?\}(image|png)/,'') # fragile match operator\\ fragile !
end
end
- def http_word_mode(orientation='')
+ def http_word_mode #(orientation='')
# clean up ! - work area, testing
dir=SiSU_Env::Info_env.new(@md.fns)
@words=[]
@@ -831,16 +835,9 @@ WOK
when /a5/; @tx.a5
else @tx.a4
end
- width=if orientation =~/portrait/ #value is not currently passed
- width=if width.to_i > dm.portrait.img_px
- dm.portrait.img_px
- else width
- end
- else
- width=if width.to_i > dm.landscape.img_px
- dm.landscape.img_px
- else width
- end
+ width=if width.to_i > dm.landscape.img_px
+ dm.landscape.img_px
+ else width
end
c=z[/``(.+?)''/m,1]
hsp="\n{\\color{mywhite} .}&~\n" # ~ character for hardspace
@@ -887,9 +884,9 @@ WOK
@words=@words.join
@words
end
- def http(orientation)
+ def http
wm=@string.dup.scan(/\\\{.+?\\\}(?:(?:https?|file|ftp):\S+|image)|\w+\s*|./m)
- @string=SiSU_TeX_Pdf::Format_text_object.new(@md,wm).http_word_mode(orientation)
+ @string=SiSU_TeX_Pdf::Format_text_object.new(@md,wm).http_word_mode #(orientation)
end
def language
@lang=if @md.dc_language[:code]
@@ -1000,6 +997,18 @@ WOK
\\setlength{\\marginparwidth}{#{d[:marginparwidth]}}
WOK
end
+ def tex_head_paper_portrait_dvi(d)
+ <<WOK
+#{tex_head_info}
+\\documentclass[#{d[:fontsize]},#{d[:papertype]},#{tex_head_lang},titlepage]{scrartcl} %with titlepage
+\\setlength{\\textheight}{#{d[:textheight]}mm} \\setlength{\\textwidth}{#{d[:textwidth]}mm}
+\\setlength{\\oddsidemargin}{#{d[:oddsidemargin]}} \\setlength{\\evensidemargin}{#{d[:evensidemargin]}}
+\\setlength{\\topmargin}{#{d[:topmargin]}} \\setlength{\\headheight}{#{d[:headheight]}}
+\\setlength{\\headsep}{#{d[:headsep]}}
+\\setlength{\\marginparsep}{#{d[:marginparsep]}}
+\\setlength{\\marginparwidth}{#{d[:marginparwidth]}}
+WOK
+ end
def tex_head_paper_dimensions
d={}
case @string
@@ -1067,7 +1076,7 @@ WOK
tex_head_paper_landscape(tex_head_paper_dimensions)
end
end
- def tex_head_pdftex
+ def tex_head_pdftex_dvi
color=case @string
when /portrait/
<<WOK
@@ -1084,6 +1093,7 @@ WOK
linkcolor=myred, % \\href{...} and \\pageref{...}
WOK
end
+ if @string =~/portrait|landscape/
<<WOK
\\usepackage{url}
\\usepackage{alltt}
@@ -1121,6 +1131,27 @@ WOK
\\definecolor{myblue}{rgb}{0,0,0.5}
\\definecolor{mywhite}{rgb}{1,1,1}
WOK
+ elsif @string =~/dvi/
+ <<WOK
+\\usepackage{url}
+\\usepackage{alltt}
+ #{color.strip}
+ pageanchor=true,
+ plainpages=true,
+ pagebackref,
+ bookmarks=true,
+ bookmarksopen=true,
+ plainpages=false,
+]
+{hyperref}
+\\usepackage[usenames]{color}
+\\definecolor{myblack}{rgb}{0,0,0}
+\\definecolor{myred}{rgb}{0.75,0,0}
+\\definecolor{mygreen}{rgb}{0,0.5,0}
+\\definecolor{myblue}{rgb}{0,0,0.5}
+\\definecolor{mywhite}{rgb}{1,1,1}
+WOK
+ end
end
def tex_head_misc
<<WOK
@@ -1143,7 +1174,7 @@ WOK
<<WOK
#{tex_head_paper}
#{tex_head_encode}
-#{tex_head_pdftex}
+#{tex_head_pdftex_dvi}
#{tex_head_misc}
\\setcounter{secnumdepth}{2}
\\setcounter{tocdepth}{4}