From 7456ed5b0a4c85c3ea6ab808342689e38e222730 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Wed, 3 Oct 2012 00:22:04 -0400 Subject: v4: param (header make), epub, pdf, book cover images --- lib/sisu/v4/css.rb | 17 +++++++++++++ lib/sisu/v4/epub.rb | 49 ++++++++++++++++++++++++++++++++++-- lib/sisu/v4/epub_format.rb | 29 +++++++++++++++++++++- lib/sisu/v4/param.rb | 59 ++++++++++++++++++++++++++++++++++++++++++-- lib/sisu/v4/sysenv.rb | 4 +++ lib/sisu/v4/texpdf.rb | 18 ++++++++++++-- lib/sisu/v4/texpdf_format.rb | 3 ++- 7 files changed, 171 insertions(+), 8 deletions(-) (limited to 'lib') 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] << %{
\n
} @@toc[:scr] << %{
\n
} + 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=< + + + + Cover + + + + + +
+
+ + + +
+
+ + +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 } + 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"> #{@md.title.full} - #{author}#{editor}#{translator}#{illustrator}#{language}#{date_published}#{subject}#{rights} + #{cover_image}#{author}#{editor}#{translator}#{illustrator}#{language}#{date_published}#{subject}#{rights} #{f.output_path.epub.url}/#{f.base_filename.epub} urn:uuid:#{@md.dgst[1]} @@ -1589,6 +1595,16 @@ WOK 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 + else '' + end + end def manifest_content(dob,name=nil) name=name ? name : dob.name <\n"] imgs.each do |i| image,type=/(\S+?)\.(png|jpg|gif)/.match(i)[1,2] + type=type.sub(/jpg/,'jpeg') images<<< WOK @@ -1616,6 +1633,11 @@ WOK #spine: reading order of XHTML files from manifest, idref attribute refers back to id in manifest (exclude images, CSS etc.). < +WOK + end + def spine_cover_image + < WOK end def spine_sisu_toc @@ -1638,6 +1660,11 @@ WOK #guide: presentation order of XHTML files by reader). < +WOK + end + def guide_cover_image + < WOK end def guide_sisu_toc 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] =<