diff --git a/lib/aozora.rb b/lib/aozora.rb new file mode 100644 index 00000000..fa3aa8c0 --- /dev/null +++ b/lib/aozora.rb @@ -0,0 +1,57 @@ +# frozen_string_literal: true + +# +# Copyright 2013 whiteleaf. All rights reserved. +# + +require "memoist" +require "pathname" +require "active_support/core_ext/hash/deep_merge" +require_relative "narou" + +module AozoraEpub3 + _ORG = { + type: :org, + name: "AozoraEpub3 (元祖)", + exist: "template/OPS/css/vertical_font.css", + dakuten: [:css, :font], + css: { + mode: :erb, + src: "vertical_font.css", + dst: "template/OPS/css_custom/vertical_font.css", + }, + font: { + mode: :copy, + src: "DMincho.ttf", + dst: "template/OPS/fonts/DMincho.ttf", + }, + } + _DEN = _ORG.deep_merge({ # hash#deep_merge <- active_support + type: :den, + name: "AozoraEpub3 (電書協)", + exist: "template/item/style/font.css", + css: { + src: "denshokyo_font.css", + dst: "template/item/style_custom/font.css", + }, + font: { dst: "template/item/fonts/DMincho.ttf" }, + }) + AOZORAEPUB3_TYPE = [_ORG, _DEN] + + class << self + extend Memoist + + def aozoraepub3_type + aozoraepub3_type_with_path(Narou.aozoraepub3_path.dirname) + end + memoize :aozoraepub3_type + + # ファイル配置がオリジナルタイプか電書協タイプか判定する + def aozoraepub3_type_with_path(aozora_path) + AOZORAEPUB3_TYPE.find do |item| + aozora_path.join(item[:exist]).exist? + end + end + + end +end diff --git a/lib/command/init.rb b/lib/command/init.rb index f2555588..432ef086 100644 --- a/lib/command/init.rb +++ b/lib/command/init.rb @@ -6,6 +6,7 @@ require_relative "../inventory" require_relative "../commandbase" +require_relative "../aozora" module Command class Init < CommandBase @@ -127,8 +128,10 @@ def rewrite_aozoraepub3_files(aozora_path, line_height) puts chuki_tag_path puts # ファイルコピー - src = ["AozoraEpub3.ini", "vertical_font.css"] - dst = ["AozoraEpub3.ini", "template/OPS/css_custom/vertical_font.css"] + type = AozoraEpub3.aozoraepub3_type_with_path(Pathname(aozora_path)) + src = ["AozoraEpub3.ini", type[:css][:src]] + dst = ["AozoraEpub3.ini", type[:css][:dst]] + use_dakuten_font = false puts "(次のファイルをコピーor上書きしました)" src.size.times do |i| src_full_path = File.join(Narou.preset_dir, src[i]) diff --git a/lib/helper.rb b/lib/helper.rb index 0de6a9e7..6e9683ee 100644 --- a/lib/helper.rb +++ b/lib/helper.rb @@ -376,6 +376,7 @@ def truncate_folder_title(title, limit = Inventory.load["folder-length-limit"]) def erb_copy(src, dst, _binding) data = File.read(src, mode: "r:BOM|UTF-8") result = ERB.new(data, trim_mode: "-").result(_binding) + Pathname(dst).dirname.mkpath File.write(dst, result) end diff --git a/lib/novelconverter.rb b/lib/novelconverter.rb index 1c12a469..e6818121 100644 --- a/lib/novelconverter.rb +++ b/lib/novelconverter.rb @@ -17,6 +17,7 @@ require_relative "inventory" require_relative "html" require_relative "eventable" +require_relative "aozora" class NovelConverter include Narou::Eventable @@ -85,22 +86,20 @@ def self.convert_file(filename, options = {}) } end - DAKUTEN_FROM = ["vertical_font_with_dakuten.css", "DMincho.ttf"] - DAKUTEN_TO = ["template/OPS/css_custom/vertical_font.css", "template/OPS/fonts/DMincho.ttf"] - DAKUTEN_ERB = [true, false] - def self.activate_dakuten_font_files preset_dir = Narou.preset_dir - aozora_dir = File.dirname(Narou.aozoraepub3_path) + aozora_dir = Narou.aozoraepub3_path.dirname + type = AozoraEpub3.aozoraepub3_type line_height = Narou.line_height + use_dakuten_font = true - DAKUTEN_FROM.each_with_index do |name, i| - src = File.join(preset_dir, name) - dst = File.join(aozora_dir, DAKUTEN_TO[i]) - if DAKUTEN_ERB[i] + type[:dakuten].each do |name| + src = preset_dir.join(type[name][:src]) + dst = aozora_dir.join(type[name][:dst]) + if type[name][:mode] == :erb Helper.erb_copy(src, dst, binding) else - FileUtils.mkdir_p(File.dirname(dst)) + dst.dirname.mkpath FileUtils.copy(src, dst) end end @@ -108,12 +107,14 @@ def self.activate_dakuten_font_files def self.inactivate_dakuten_font_files preset_dir = Narou.preset_dir - aozora_dir = File.dirname(Narou.aozoraepub3_path) - path_normal_vertical_css = File.join(preset_dir, "vertical_font.css") + aozora_dir = Narou.aozoraepub3_path.dirname + type = AozoraEpub3.aozoraepub3_type + path_normal_css = preset_dir.join(type[:css][:src]) line_height = Narou.line_height + use_dakuten_font = false - Helper.erb_copy(path_normal_vertical_css, File.join(aozora_dir, DAKUTEN_TO[0]), binding) - FileUtils.remove(File.join(aozora_dir, DAKUTEN_TO[1])) + Helper.erb_copy(path_normal_css, aozora_dir.join(type[:css][:dst]), binding) + aozora_dir.join(type[:font][:dst]).delete end # diff --git a/preset/vertical_font_with_dakuten.css b/preset/denshokyo_font.css similarity index 60% rename from preset/vertical_font_with_dakuten.css rename to preset/denshokyo_font.css index c611a738..0f0ac00a 100644 --- a/preset/vertical_font_with_dakuten.css +++ b/preset/denshokyo_font.css @@ -1,15 +1,28 @@ @charset "utf-8"; @namespace "http://www.w3.org/1999/xhtml"; -body { +/** 横書きフォント */ +.hltr body { + font-family: "MS 明朝", "MS Mincho", "ヒラギノ明朝 ProN W3", "HiraMinProN-W3", serif, sans-serif; +} +/** 縦書きフォント */ +.vrtl body { font-family: "@MS 明朝", "@MS Mincho", "ヒラギノ明朝 ProN W3", "HiraMinProN-W3", serif, sans-serif; +} + +/** 以下 narou.rb オリジナル設定 */ + +body { line-height: <%= line_height %>em !important; } -.gtc, .b { +/* .gtc .b .i は電書協準拠により .gfont .bold .italic となる */ +/* AozoraEpub3には太字注記でゴシックを使うオプション(BoldUseGothic)あるが.bに設定している */ +.vrtl .bold { font-family: '@MS ゴシック','@MS Gothic',sans-serif !important; } +/* .bold と .italic の設定は標準で成されている気がするけど */ .b { font-weight: bold; } .i { font-style: italic; } @@ -18,6 +31,7 @@ rt { font-size: 0.6em; } /* カスタム注記用 */ /* 柱(もどき) */ +/* 柱(もどき)は横書きされるので切替えは必要なさそう */ .running_head { position: absolute !important; top: 15px; @@ -25,20 +39,30 @@ rt { font-size: 0.6em; } font-size: 0.8em; } +/* ページ左右中央 調整 */ +/* ページ左右中央では html.hltr なので横書きの3字下げも付くのを防ぐ */ +.main.vrtl.block-align-center div.mt3 { + margin-left: 0; +} + +<% if use_dakuten_font %> /* 濁点フォント */ @font-face { font-family: "DakutenAokinMincho"; src: url(../fonts/DMincho.ttf) format("truetype"); } +/* 横書きでは設定の有無に関わらず濁点は付かない。narou.rbで縦書きに限定すべき? */ .dakuten { font-family: "DakutenAokinMincho" !important; } +<% end %> /* 二分アキ */ -.half_em_space { padding-top: 0.5em; } +.vrtl .half_em_space { padding-top: 0.5em; } /* パラメーター(折り返しあり) */ +/* margin, padding の設定あるが許容範囲? */ .custom_parameter_block { font-size: 100%; line-height: 1.2em !important; @@ -60,7 +84,8 @@ rt { font-size: 0.6em; } } /* 前書き */ -.introduction { +/* height の設定あるので縦書き限定 */ +.vrtl .introduction { float: right; font-size: 83%; line-height: 1.5em !important; @@ -82,7 +107,8 @@ rt { font-size: 0.6em; } } /* 後書き */ -.postscript { +/* height の設定あるので縦書き限定 */ +.vrtl .postscript { float: right; font-size: 83%; line-height: 1.5em !important; @@ -103,6 +129,9 @@ rt { font-size: 0.6em; } display: inline-block; } +/* .hltr .vrtl 無指定でも問題ないと思う */ div.clear { clear: both; } + +/* 字詰め (.jzm) 設定はよく分からない */ diff --git a/preset/vertical_font.css b/preset/vertical_font.css index c77f0307..e8bebe67 100644 --- a/preset/vertical_font.css +++ b/preset/vertical_font.css @@ -24,7 +24,17 @@ rt { font-size: 0.6em; } left: 10px; font-size: 0.8em; } +<% if use_dakuten_font %> +/* 濁点フォント */ +@font-face { + font-family: "DakutenAokinMincho"; + src: url(../fonts/DMincho.ttf) format("truetype"); +} +.dakuten { + font-family: "DakutenAokinMincho" !important; +} +<% end %> /* 二分アキ */ .half_em_space { padding-top: 0.5em; }