diff options
author | Ralph Amissah <ralph@amissah.com> | 2012-10-03 00:22:04 -0400 |
---|---|---|
committer | Ralph Amissah <ralph@amissah.com> | 2012-10-03 00:22:04 -0400 |
commit | 7456ed5b0a4c85c3ea6ab808342689e38e222730 (patch) | |
tree | 48adb32c257d7f0c93c2b5ec622e470da714900f /lib/sisu/v4 | |
parent | v4 (&v3): markup samples, for v4 remove skins, separate (v3 & v4) directories (diff) |
v4: param (header make), epub, pdf, book cover images
Diffstat (limited to 'lib/sisu/v4')
-rw-r--r-- | lib/sisu/v4/css.rb | 17 | ||||
-rw-r--r-- | lib/sisu/v4/epub.rb | 49 | ||||
-rw-r--r-- | lib/sisu/v4/epub_format.rb | 29 | ||||
-rw-r--r-- | lib/sisu/v4/param.rb | 59 | ||||
-rw-r--r-- | lib/sisu/v4/sysenv.rb | 4 | ||||
-rw-r--r-- | lib/sisu/v4/texpdf.rb | 18 | ||||
-rw-r--r-- | lib/sisu/v4/texpdf_format.rb | 3 |
7 files changed, 171 insertions, 8 deletions
diff --git a/lib/sisu/v4/css.rb b/lib/sisu/v4/css.rb index 52e2d997..f723853f 100644 --- a/lib/sisu/v4/css.rb +++ b/lib/sisu/v4/css.rb @@ -2402,6 +2402,23 @@ WOK p.right, th.right, td.right { text-align: right; } + + .svg_outer { + display: block; + margin-bottom: 0; + margin-left: 0; + margin-right: 0; + margin-top: 0; + padding-bottom: 0; + padding-left: 0; + padding-right: 0; + padding-top: 0; + text-align: left; + } + .svg_inner { + display: block; + text-align: center; + } WOK end def xml_sax #stylesheet for xml sax diff --git a/lib/sisu/v4/epub.rb b/lib/sisu/v4/epub.rb index e8430aa5..9ac4b610 100644 --- a/lib/sisu/v4/epub.rb +++ b/lib/sisu/v4/epub.rb @@ -208,6 +208,13 @@ module SiSU_EPUB @@toc[:opf] << @epub.metadata_opf.manifest_open @@toc[:seg] << %{<div class="content">\n<div class="substance">} @@toc[:scr] << %{<div class="content">\n<div class="substance">} + if defined? @md.make.cover_image \ + and @md.make.cover_image.is_a?(Hash) \ + and @md.make.cover_image[:cover] =~/\S+/ + md_opf_a_content << @epub.metadata_opf.manifest_cover_image_information(@md) + md_opf_a_spine << @epub.metadata_opf.spine_cover_image + md_opf_a_guide << @epub.metadata_opf.guide_cover_image + end md_opf_a_content << @epub.metadata_opf.manifest_content_sisu_toc if @make.build.toc? md_opf_a_spine << @epub.metadata_opf.spine_sisu_toc @@ -546,7 +553,8 @@ module SiSU_EPUB #Segtoc tail added here segtoc << format_head_toc.xhtml_close segtoc=segtoc.flatten.compact #watch - SiSU_EPUB::Source::Output.new(@md,segtoc).segtoc + SiSU_EPUB::Source::Output.new(@md).make_cover_image + SiSU_EPUB::Source::Output.new(@md,segtoc).make_segtoc segtoc=[] @toc[:scr],@toc[:seg]=[],[] toc_shared @@ -654,7 +662,44 @@ module SiSU_EPUB end end end - def segtoc + def make_cover_image + begin + if @md.make.cover_image? \ + and @md.make.cover_image.is_a?(Hash) \ + and @md.make.cover_image[:cover] =~/\S+/ + filename_xhtml=@make_file.epub.xhtml_cover_image + cover_image=<<WOK +<?xml version='1.0' encoding='utf-8'?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" + "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> + <title>Cover</title> + <meta http-equiv="Content-Type" content='text/html; charset=utf-8' /> + <link rel="stylesheet" href="css/xhtml.css" type="text/css" /> + <style type="text/css"> img { max-width: 100%; } </style> +</head> +<body bgcolor="#ffffff" text="#000000" link="#003090" lang="en" xml:lang="en"> + <div class="svg_outer"> + <div class="svg_inner"> + <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100%" height="100%" viewBox="0 0 #{@md.make.cover_image[:w]} #{@md.make.cover_image[:h]}" preserveAspectRatio="xMidYMid meet"> + <image width="#{@md.make.cover_image[:w]}" height="#{@md.make.cover_image[:h]}" xlink:href="image/#{@md.make.cover_image[:cover]}" /> + </svg> + </div> + </div> +</body> +</html> +WOK + filename_xhtml.puts cover_image,"\n" + filename_xhtml.close + end + rescue + SiSU_Errors::InfoError.new($!,$@,@md.opt.cmd,@md.fns).error do + __LINE__.to_s + ':' + __FILE__ + end + end + end + def make_segtoc begin if @make.build.toc? filename_xhtml=@make_file.epub.xhtml_index diff --git a/lib/sisu/v4/epub_format.rb b/lib/sisu/v4/epub_format.rb index 2889c7b1..98fc385d 100644 --- a/lib/sisu/v4/epub_format.rb +++ b/lib/sisu/v4/epub_format.rb @@ -1445,6 +1445,12 @@ WOK WOK end def metadata #metadata dc + cover_image=if defined? @md.make.cover_image \ + and @md.make.cover_image.is_a?(Hash) \ + and @md.make.cover_image[:cover] =~/\S+/ + %{\n <meta name="cover" content="cover_image" />} + else '' + end author=if defined? @md.creator.author \ and @md.creator.author =~/\S+/ m='' @@ -1567,7 +1573,7 @@ WOK xmlns:opf="http://www.idpf.org/2007/opf" unique-identifier="urn:uuid:#{@md.dgst[1]}" version="2.0"> <dc:title>#{@md.title.full}</dc:title> - #{author}#{editor}#{translator}#{illustrator}#{language}#{date_published}#{subject}#{rights} + #{cover_image}#{author}#{editor}#{translator}#{illustrator}#{language}#{date_published}#{subject}#{rights} <dc:identifier opf:scheme="URI">#{f.output_path.epub.url}/#{f.base_filename.epub}</dc:identifier> <dc:identifier id="bookid">urn:uuid:#{@md.dgst[1]}</dc:identifier> <!-- <dc:identifier id="EPB-UUID">urn:uuid:#{@md.dgst[1]}</dc:identifier> --> @@ -1589,6 +1595,16 @@ WOK <item id="index" href="index.xhtml" media-type="application/xhtml+xml" /> WOK end + def manifest_cover_image_information(md) + cover_image=if defined? md.make.cover_image \ + and @md.make.cover_image.is_a?(Hash) \ + and md.make.cover_image[:cover] =~/\S+/ + <<WOK + <item id="cover_image_file" href="cover_image#{Sfx[:epub_xhtml]}" media-type="application/xhtml+xml" /> +WOK + else '' + end + end def manifest_content(dob,name=nil) name=name ? name : dob.name <<WOK @@ -1600,6 +1616,7 @@ WOK images=[" <!-- Images -->\n"] imgs.each do |i| image,type=/(\S+?)\.(png|jpg|gif)/.match(i)[1,2] + type=type.sub(/jpg/,'jpeg') images<<<<WOK <item id="#{image}" href="image/#{image}.#{type}" media-type="image/#{type}" /> WOK @@ -1618,6 +1635,11 @@ WOK <spine toc="ncx"> WOK end + def spine_cover_image + <<WOK + <itemref idref="cover_image_file" /> +WOK + end def spine_sisu_toc <<WOK <itemref idref="index" linear="yes" /> @@ -1640,6 +1662,11 @@ WOK <guide> WOK end + def guide_cover_image + <<WOK + <reference type="cover" title="Cover of [book title]" href="cover_image#{Sfx[:epub_xhtml]}" /> +WOK + end def guide_sisu_toc <<WOK <reference type="index" href="index#{Sfx[:epub_xhtml]}" /> diff --git a/lib/sisu/v4/param.rb b/lib/sisu/v4/param.rb index d1b00cfc..b75a8808 100644 --- a/lib/sisu/v4/param.rb +++ b/lib/sisu/v4/param.rb @@ -922,6 +922,11 @@ module SiSU_Param ? :off : :na end + def cover_image? + (omit.list.inspect =~/"cover_image"/) \ + ? :off + : :na + end def texpdf_font def main @h['texpdf_font'] \ @@ -987,6 +992,50 @@ module SiSU_Param end manpage end + def get_image_dimentions(img) + imgk=SiSU_Env::SystemCall.new.imagemagick + gmgk=SiSU_Env::SystemCall.new.graphicksmagick + if imgk or gmgk + img_pth=@env.path.image_source_include + if imgk + imgsys=`identify #{img_pth}/#{img}`.strip #system call + elsif gmgk + imgsys=`gm identify #{img_pth}/#{img}`.strip #system call + end + w,h=/(\d+)x(\d+)/m.match(imgsys)[1,2] + else + w,h='600','800' + end + {w: w, h: h} + end + def cover_image + s=nil + if @h['cover_image'] + s=@h['cover_image'].split(/\s*;\s*/) + s=s[0] #if + image={} + if s =~/{(\S+\.(?:jpg|png|gif))(?:\s+(\d+x\d+))?\s+(?:"(.+?)")?\s*}image/ + image[:cover]=$1 + if $2 + image[:dimentions]=$2 + image[:w],image[:h]=/(\d+)x(\d+)/m.match(image[:dimentions])[1,2] + else + d=get_image_dimentions(image[:cover]) + image[:w],image[:h]=d[:w],d[:h] + image[:dimentions]="#{d[:w]}x#{d[:h]}" + end + image[:note]=$3 + elsif s =~/(\S+\.(?:jpg|png|gif))/ + image[:cover]=$1 + d=get_image_dimentions(image[:cover]) + image[:w],image[:h]=d[:w],d[:h] + image[:dimentions]="#{d[:w]}x#{d[:h]}" + image[:note]=nil + end + image + else nil + end + end self end def current_publisher @@ -1055,9 +1104,9 @@ module SiSU_Param @doc={ lv: [] } @doc[:fns],@doc[:fnb],@doc[:scr_suffix]='','','' @@publisher='SiSU scribe' - attr_accessor :make,:env,:path,:file,:fn,:fns,:fno,:fnb,:fnn,:fnt,:fnl,:flv,:fnz,:fnstex,:ocn,:sfx_src,:pdf,:file_type,:dir_out,:dir_tex,:dir_lout,:txt_path,:sisu,:sisu_version,:ruby_version,:title,:subtitle,:full_title,:html_title,:subtitle_tex,:creator,:classify,:author_home,:author,:author_title,:author_nationality,:authors,:authorship,:translator,:illustrator,:prepared_by,:digitized_by,:subject,:description,:publisher,:current_publisher,:contributor,:date,:date_created,:date_issued,:date_available,:date_valid,:date_modified,:date_translated,:date_added_to_site,:date_scheme,:date_created_scheme,:date_issued_scheme,:date_available_scheme,:date_valid_scheme,:date_modified_scheme,:type,:format,:identifier,:source,:language,:language_original,:relation,:coverage,:rights,:keywords,:comments,:abstract,:cls_loc,:cls_dewey,:cls_pg,:cls_isbn,:papersize,:papersize_array,:toc,:lv1,:lv2,:lv3,:lv4,:lv5,:lv6,:lvs,:pagenew,:pagebreak,:num_top,:toc_lev_limit,:flag_endnotes,:flag_auto_endnotes,:flag_separate_endnotes,:flag_separate_endnotes_make,:markup,:markup_instruction,:markup_version,:markup_declared,:flag_tables,:vocabulary,:doc_css,:yaml,:lnk,:links,:prefix_a,:prefix_b,:suffix,:information,:contact,:icon,:image,:ad_url,:ad_png,:ad_alt,:ad_began,:flag_promo,:promo,:ad_home,:stmp,:stmpd,:sc_filename,:sc_number,:sc_date,:sc_time,:sc_info,:yamladdr,:locale,:wc_lines,:wc_words,:wc_bytes,:file_encoding,:filesize,:user,:home,:hostname,:pwd,:firstseg,:programs,:author_copymark,:i18n,:lang,:lang_code_insert,:en,:notes,:dgst,:generated,:tags,:tag_array,:concord_make,:seg_names,:seg_autoname_safe,:set_header_title,:set_heading_top,:set_heading_seg,:heading_seg_first,:heading_seg_first_flag,:base_program,:ec,:opt,:sem_tag,:book_idx,:topic_register,:topic_register_array,:original,:writing_focus,:audio,:daisy + attr_accessor :make,:env,:path,:file,:fn,:fns,:fno,:fnb,:fnn,:fnt,:fnl,:flv,:fnz,:fnstex,:ocn,:sfx_src,:pdf,:file_type,:dir_out,:dir_tex,:dir_lout,:txt_path,:sisu,:sisu_version,:ruby_version,:title,:subtitle,:full_title,:html_title,:subtitle_tex,:creator,:classify,:author_home,:author,:author_title,:author_nationality,:authors,:authorship,:translator,:illustrator,:prepared_by,:digitized_by,:subject,:description,:publisher,:current_publisher,:contributor,:date,:date_created,:date_issued,:date_available,:date_valid,:date_modified,:date_translated,:date_added_to_site,:date_scheme,:date_created_scheme,:date_issued_scheme,:date_available_scheme,:date_valid_scheme,:date_modified_scheme,:type,:format,:identifier,:source,:language,:language_original,:relation,:coverage,:rights,:keywords,:comments,:abstract,:cls_loc,:cls_dewey,:cls_pg,:cls_isbn,:papersize,:papersize_array,:toc,:lv1,:lv2,:lv3,:lv4,:lv5,:lv6,:lvs,:pagenew,:pagebreak,:num_top,:toc_lev_limit,:flag_endnotes,:flag_auto_endnotes,:flag_separate_endnotes,:flag_separate_endnotes_make,:markup,:markup_instruction,:markup_version,:markup_declared,:flag_tables,:vocabulary,:doc_css,:yaml,:lnk,:links,:prefix_a,:prefix_b,:suffix,:information,:contact,:icon,:image,:ad_url,:ad_png,:ad_alt,:ad_began,:flag_promo,:promo,:ad_home,:stmp,:stmpd,:sc_filename,:sc_number,:sc_date,:sc_time,:sc_info,:yamladdr,:locale,:wc_lines,:wc_words,:wc_bytes,:file_encoding,:filesize,:user,:home,:hostname,:pwd,:firstseg,:programs,:author_copymark,:i18n,:lang,:lang_code_insert,:en,:notes,:dgst,:generated,:tags,:tag_array,:concord_make,:seg_names,:seg_autoname_safe,:set_header_title,:set_heading_top,:set_heading_seg,:heading_seg_first,:heading_seg_first_flag,:base_program,:ec,:opt,:sem_tag,:book_idx,:topic_register,:topic_register_array,:original,:writing_focus,:audio,:daisy,:home_button_image,:home_button_links,:footer_links,:cover_image,:man_section def initialize(fns_array,opt) - @env=@path,@file=@fn=@fns=@fno=@fnb=@fnn=@fnt=@fnl=@flv=@fnz=@fnstex=@ocn=@sfx_src=@pdf=@file_type=@dir_out=@dir_tex=@dir_lout=@txt_path=@make=@flag_endnotes=@flag_auto_endnotes=@flag_separate_endnotes=@flag_separate_endnotes_make=@sisu=@sisu_version=@ruby_version=@title=@subtitle=@full_title=@html_title=@subtitle_tex=@creator=@classify=@author_home=@author=@author_title=@author_nationality=@translator=@illustrator=@prepared_by=@digitized_by=@subject=@description=@publisher=@current_publisher=@contributor=@date=@date_created=@date_issued=@date_available=@date_valid=@date_modified=@date_translated=@date_added_to_site=@date_scheme=@date_created_scheme=@date_issued_scheme=@date_available_scheme=@date_valid_scheme=@date_modified_scheme=@type=@format=@identifier=@source=@language=@language_original=@relation=@coverage=@rights=@keywords=@comments=@abstract=@cls_loc=@cls_dewey=@cls_pg=@cls_isbn=@papersize=@toc=@lv1=@lv2=@lv3=@lv4=@lv5=@lv6=@pagenew=@pagebreak=@num_top=@toc_lev_limit=@flag_tables=@vocabulary=@doc_css=@yaml=@lnk=@links=@prefix_a=@prefix_b=@suffix=@information=@contact=@icon=@ad_url=@ad_png=@ad_alt=@ad_began=@promo=@ad_home=@stmp=@stmpd=@sc_filename=@sc_number=@sc_date=@sc_time=@sc_info=@yamladdr=@locale=@wc_lines=@wc_words=@wc_bytes=@file_encoding=@filesize=@firstseg=@programs=@author_copymark=@i18n=@lang=@lang_code_insert=@en=@notes=@dgst=@generated=@heading_seg_first=@base_program=@topic_register=@original=@writing_focus=@audio=nil + @env=@path,@file=@fn=@fns=@fno=@fnb=@fnn=@fnt=@fnl=@flv=@fnz=@fnstex=@ocn=@sfx_src=@pdf=@file_type=@dir_out=@dir_tex=@dir_lout=@txt_path=@make=@flag_endnotes=@flag_auto_endnotes=@flag_separate_endnotes=@flag_separate_endnotes_make=@sisu=@sisu_version=@ruby_version=@title=@subtitle=@full_title=@html_title=@subtitle_tex=@creator=@classify=@author_home=@author=@author_title=@author_nationality=@translator=@illustrator=@prepared_by=@digitized_by=@subject=@description=@publisher=@current_publisher=@contributor=@date=@date_created=@date_issued=@date_available=@date_valid=@date_modified=@date_translated=@date_added_to_site=@date_scheme=@date_created_scheme=@date_issued_scheme=@date_available_scheme=@date_valid_scheme=@date_modified_scheme=@type=@format=@identifier=@source=@language=@language_original=@relation=@coverage=@rights=@keywords=@comments=@abstract=@cls_loc=@cls_dewey=@cls_pg=@cls_isbn=@papersize=@toc=@lv1=@lv2=@lv3=@lv4=@lv5=@lv6=@pagenew=@pagebreak=@num_top=@toc_lev_limit=@flag_tables=@vocabulary=@doc_css=@yaml=@lnk=@links=@prefix_a=@prefix_b=@suffix=@information=@contact=@icon=@ad_url=@ad_png=@ad_alt=@ad_began=@promo=@ad_home=@stmp=@stmpd=@sc_filename=@sc_number=@sc_date=@sc_time=@sc_info=@yamladdr=@locale=@wc_lines=@wc_words=@wc_bytes=@file_encoding=@filesize=@firstseg=@programs=@author_copymark=@i18n=@lang=@lang_code_insert=@en=@notes=@dgst=@generated=@heading_seg_first=@base_program=@topic_register=@original=@writing_focus=@audio=@home_button_image=@home_button_links=@cover_image=@man_section=nil @data,@path,@fns,@fno,@opt=fns_array,opt.pth,opt.fns,opt.fno,opt #@data used as data @flag_tables,@set_header_title,@set_heading_top,@set_heading_seg,@heading_seg_first_flag,@flag_promo,@book_idx=false,false,false,false,false,false,false @seg_autoname_safe=true @@ -1402,6 +1451,12 @@ module SiSU_Param end @make=SiSU_Param::Parameters::Md.new('@make: ',@opt,@env).make end + if @cover_image \ + and @cover_image.is_a?(Hash) \ + and (@cover_image[:cover] =~@rgx_image \ + or @cover_image[:cover] =~/\S+?.(?:jpg|png|gif)/) + @ec[:image] << @cover_image[:cover] + end if @ec[:image].length > 0 @ec[:image]=@ec[:image].flatten.uniq @ec[:image].delete_if {|x| x =~/https?:\/\// } diff --git a/lib/sisu/v4/sysenv.rb b/lib/sisu/v4/sysenv.rb index 788c8780..cc1b463c 100644 --- a/lib/sisu/v4/sysenv.rb +++ b/lib/sisu/v4/sysenv.rb @@ -5552,6 +5552,10 @@ WOK filename_index="#{@pth}/#{Ep[:d_oebps]}/index.xhtml" File.new(filename_index,'w+') end + def xhtml_cover_image + filename_index="#{@pth}/#{Ep[:d_oebps]}/cover_image.xhtml" + File.new(filename_index,'w+') + end def xhtml_segtoc filename_segtoc="#{@pth}/#{Ep[:d_oebps]}/toc.xhtml" File.new(filename_segtoc,'w+') diff --git a/lib/sisu/v4/texpdf.rb b/lib/sisu/v4/texpdf.rb index c52b0641..f5c90cf5 100644 --- a/lib/sisu/v4/texpdf.rb +++ b/lib/sisu/v4/texpdf.rb @@ -731,8 +731,22 @@ WOK else "\n\\author{#{@copymark} \\textnormal{#{author}}}" end end - @tex_file << unless @md.fnb =~/^mail\s*$/; @tex_ml.site - else '\date' + if defined? @md.make.cover_image \ + and not @md.make.cover_image.nil? \ + and @md.make.cover_image[:cover] =~/\S+/ + x={} + dir=SiSU_Env::InfoEnv.new(@md.fns) + x[:l] =<<WOK +\\titlepic{\\includegraphics[width=0.3\\textwidth]{#{dir.path.image_source_include}/#{@md.make.cover_image[:cover]}}} +WOK + x[:p] =<<WOK +\\titlepic{\\includegraphics[width=0.6\\textwidth]{#{dir.path.image_source_include}/#{@md.make.cover_image[:cover]}}} +WOK + @tex_file << x + x=nil + end + @tex_file << unless @md.fnb =~/^mail\s*$/ then @tex_ml.site + else '\date' end @tex_file <<<<WOK \\pagenumbering{roman}\\maketitle diff --git a/lib/sisu/v4/texpdf_format.rb b/lib/sisu/v4/texpdf_format.rb index d65067c3..3c2d9231 100644 --- a/lib/sisu/v4/texpdf_format.rb +++ b/lib/sisu/v4/texpdf_format.rb @@ -1045,6 +1045,7 @@ WOK \\usepackage[normalem]{ulem} \\usepackage{soul} \\usepackage{longtable} +\\usepackage[tc]{titlepic} \\usepackage{graphicx} \\makeatletter \\parindent0pt @@ -1435,7 +1436,7 @@ WOK def site if not @vz.url_home.empty? \ and not @vz.url_txt.empty? - "\n\\date{\\begin{footnotesize} copy @ \\href{#{@vz.url_home}}{#{@vz.url_txt}} \\end{footnotesize}}" + "\n\\date{\\begin{tiny} \\end{tiny}}" else '' end end |