Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

電書協最小対応版 #439

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions lib/aozora.rb
Original file line number Diff line number Diff line change
@@ -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
7 changes: 5 additions & 2 deletions lib/command/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

require_relative "../inventory"
require_relative "../commandbase"
require_relative "../aozora"

module Command
class Init < CommandBase
Expand Down Expand Up @@ -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])
Expand Down
1 change: 1 addition & 0 deletions lib/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
29 changes: 15 additions & 14 deletions lib/novelconverter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
require_relative "inventory"
require_relative "html"
require_relative "eventable"
require_relative "aozora"

class NovelConverter
include Narou::Eventable
Expand Down Expand Up @@ -85,35 +86,35 @@ 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
end

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

#
Expand Down
Original file line number Diff line number Diff line change
@@ -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; }

Expand All @@ -18,27 +31,38 @@ rt { font-size: 0.6em; }
/* カスタム注記用 */

/* 柱(もどき) */
/* 柱(もどき)は横書きされるので切替えは必要なさそう */
.running_head {
position: absolute !important;
top: 15px;
left: 10px;
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;
Expand All @@ -60,7 +84,8 @@ rt { font-size: 0.6em; }
}

/* 前書き */
.introduction {
/* height の設定あるので縦書き限定 */
.vrtl .introduction {
float: right;
font-size: 83%;
line-height: 1.5em !important;
Expand All @@ -82,7 +107,8 @@ rt { font-size: 0.6em; }
}

/* 後書き */
.postscript {
/* height の設定あるので縦書き限定 */
.vrtl .postscript {
float: right;
font-size: 83%;
line-height: 1.5em !important;
Expand All @@ -103,6 +129,9 @@ rt { font-size: 0.6em; }
display: inline-block;
}

/* .hltr .vrtl 無指定でも問題ないと思う */
div.clear {
clear: both;
}

/* 字詰め (.jzm) 設定はよく分からない */
10 changes: 10 additions & 0 deletions preset/vertical_font.css
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down