typeset 0.1.0
縦書き・横書きの日本語組版ライブラリ(JLReq 水準、ラスタ / PDF / SVG)
読み取り中…
検索中…
一致する文字列を見つけられません
block.hpp
[詳解]
1#ifndef TYPESET_BLOCK_BLOCK_HPP
2#define TYPESET_BLOCK_BLOCK_HPP
3
4#include <map>
5#include <optional>
6#include <variant>
7#include <vector>
8
10#include "typeset/geom.hpp"
12
18namespace typeset::block {
19
20enum class BreakKind : uint8_t { Auto, Column, Page };
21
25struct BlockStyle {
26 Pt spaceBefore = 0.0f;
27 Pt spaceAfter = 0.0f;
28 int orphans = 1;
29 int widows = 1;
30 bool keepWithNext = false;
31 bool keepTogether = false;
34 bool spanColumns = false;
35
37 std::string label;
38
40 std::optional<Color> background;
41 Pt padding = 0.0f;
42};
43
48
51 int level = 1;
53 bool numbered = false;
55 bool bookmark = true;
56 BlockStyle block = [] { BlockStyle b; b.keepWithNext = true; return b; }();
57};
58
60struct RuleBlock {
61 Pt thickness = 0.5f;
62 Color color{0, 0, 0, 255};
63 Pt inset = 0.0f;
65};
66
68 Pt size = 0.0f;
70};
71
81 std::vector<inl::Paragraph> body;
82 Pt labelWidth = 0.0f;
83 Pt gap = 0.0f;
85};
86
91 std::optional<int> columns;
92 std::optional<Pt> columnGap;
93};
94
95enum class ImagePlacement : uint8_t {
96 Block,
98 FloatEnd,
99};
100
108 std::shared_ptr<const dl::Image> image;
112 Pt gap = 6.0f;
114 std::optional<inl::Paragraph> caption;
117};
118
127 std::string handler;
128 std::u16string source;
129 std::map<std::string, std::string> params;
131 bool numbered = false;
133 std::optional<inl::Paragraph> caption;
136};
137
147
148enum class VAlign : uint8_t { Top, Middle, Bottom };
149
150struct TableCell {
151 std::vector<inl::Paragraph> paras;
152 int colspan = 1;
153 int rowspan = 1;
155};
156
157struct TableRow {
158 std::vector<TableCell> cells;
159 bool header = false;
160};
161
163 Pt outer = 0.75f;
164 Pt inner = 0.25f;
165 Pt headerRule = 0.75f;
166 bool vertical = true;
167 bool horizontal = true;
168 Color color{0, 0, 0, 255};
169};
170
172 std::vector<TableColumn> columns;
173 std::vector<TableRow> rows;
176 bool fullWidth = true;
178 bool repeatHeader = true;
180 std::optional<inl::Paragraph> caption;
183};
184
188struct ListBlock {
189 enum class Marker : uint8_t { Bullet, Numbered };
190 std::vector<inl::Paragraph> items;
192 std::u16string bullet = u"・";
193 std::u16string numberSuffix = u".";
194 Pt labelWidth = 0.0f;
195 Pt gap = 0.0f;
196 Pt itemGap = 0.0f;
198};
199
203struct TocBlock {
204 int maxLevel = 2;
206 std::optional<TextStyle> subStyle;
209 bool leader = true;
211};
212
219 std::optional<TextStyle> groupStyle;
220 bool grouped = true;
221 bool leader = true;
223 std::u16string pageSeparator = u", ";
225};
226
229
230struct Flow {
231 std::vector<Block> blocks;
232
233 void add(Block b) { blocks.push_back(std::move(b)); }
235 blocks.push_back(ParagraphBlock{std::move(p), std::move(style)});
236 }
237 void addHeading(inl::Paragraph p, int level = 1, std::optional<BlockStyle> style = std::nullopt,
238 bool numbered = false) {
239 HeadingBlock h;
240 h.para = std::move(p);
241 h.level = level;
242 h.numbered = numbered;
243 if (style) h.block = *style;
244 blocks.push_back(std::move(h));
245 }
246 void addList(ListBlock list) { blocks.push_back(std::move(list)); }
247 void addToc(TocBlock toc) { blocks.push_back(std::move(toc)); }
248 void addIndex(IndexBlock idx) { blocks.push_back(std::move(idx)); }
249 void addLabeled(inl::Paragraph label, inl::Paragraph body, Pt labelWidth, Pt gap = 0.0f,
250 BlockStyle style = {}) {
251 LabeledBlock b;
252 b.label = std::move(label);
253 b.body.push_back(std::move(body));
254 b.labelWidth = labelWidth;
255 b.gap = gap;
256 b.block = std::move(style);
257 blocks.push_back(std::move(b));
258 }
259 void addRule(Pt thickness = 0.5f, Color color = Color{0, 0, 0, 255}, BlockStyle style = {}) {
260 RuleBlock r;
261 r.thickness = thickness;
262 r.color = color;
263 r.block = std::move(style);
264 blocks.push_back(std::move(r));
265 }
266 void addSpacer(Pt size) { blocks.push_back(SpacerBlock{size, {}}); }
267 void addImage(ImageBlock img) { blocks.push_back(std::move(img)); }
268 void addObject(ObjectBlock obj) { blocks.push_back(std::move(obj)); }
269 void addObject(std::string handler, std::u16string source, TextStyle textStyle,
270 std::map<std::string, std::string> params = {}, bool numbered = false,
271 BlockStyle style = {}) {
272 ObjectBlock o;
273 o.handler = std::move(handler);
274 o.source = std::move(source);
275 o.params = std::move(params);
276 o.textStyle = std::move(textStyle);
277 o.numbered = numbered;
278 o.block = std::move(style);
279 blocks.push_back(std::move(o));
280 }
281 void addTable(TableBlock table) { blocks.push_back(std::move(table)); }
283 SpacerBlock s;
285 blocks.push_back(std::move(s));
286 }
288 SpacerBlock s;
290 blocks.push_back(std::move(s));
291 }
292};
293
294} // namespace typeset::block
295
296#endif // TYPESET_BLOCK_BLOCK_HPP
block — ブロック(段落・見出し・罫線・ラベル付き段落・アキ・セクション)
Definition block.hpp:18
std::variant< ParagraphBlock, HeadingBlock, RuleBlock, SpacerBlock, LabeledBlock, SectionBlock, ImageBlock, TableBlock, ListBlock, TocBlock, ObjectBlock, IndexBlock > Block
Definition block.hpp:228
@ FloatEnd
行末側に寄せて本文を回り込ませる
@ FloatStart
行頭側に寄せて本文を回り込ませる(横組み: 左、縦組み: 上)
@ Block
本文の流れに置く(行送り方向に高さぶん消費する)
float Pt
Definition geom.hpp:17
色(非前乗算 RGBA)
Definition geom.hpp:117
文字スタイル
Definition style.hpp:86
ブロック共通のスタイル(配置・改ページ制御)
Definition block.hpp:25
Pt spaceBefore
ブロック前のアキ(行送り方向、pt)
Definition block.hpp:26
bool keepTogether
ブロックを段の境で分けない(段より大きければ分ける)
Definition block.hpp:31
bool keepWithNext
次のブロックと同じ段に置く(見出し)
Definition block.hpp:30
int orphans
段の末尾に残す最小行数
Definition block.hpp:28
std::string label
相互参照のラベル。本文の {ref:ラベル} が番号(見出し・図・表)、{page:ラベル} がページ番号になる
Definition block.hpp:37
int widows
段の先頭に送る最小行数
Definition block.hpp:29
bool spanColumns
段抜き(全幅に置く。段組のときだけ意味がある)
Definition block.hpp:34
std::optional< Color > background
背景(段落・コードブロック用)。padding は背景の内側の余白(行送り方向)
Definition block.hpp:40
void addObject(std::string handler, std::u16string source, TextStyle textStyle, std::map< std::string, std::string > params={}, bool numbered=false, BlockStyle style={})
Definition block.hpp:269
void addTable(TableBlock table)
Definition block.hpp:281
void addSpacer(Pt size)
Definition block.hpp:266
void addParagraph(inl::Paragraph p, BlockStyle style={})
Definition block.hpp:234
void addIndex(IndexBlock idx)
Definition block.hpp:248
void addRule(Pt thickness=0.5f, Color color=Color{0, 0, 0, 255}, BlockStyle style={})
Definition block.hpp:259
std::vector< Block > blocks
Definition block.hpp:231
void addObject(ObjectBlock obj)
Definition block.hpp:268
void addList(ListBlock list)
Definition block.hpp:246
void addImage(ImageBlock img)
Definition block.hpp:267
void addToc(TocBlock toc)
Definition block.hpp:247
void addLabeled(inl::Paragraph label, inl::Paragraph body, Pt labelWidth, Pt gap=0.0f, BlockStyle style={})
Definition block.hpp:249
void add(Block b)
Definition block.hpp:233
void addHeading(inl::Paragraph p, int level=1, std::optional< BlockStyle > style=std::nullopt, bool numbered=false)
Definition block.hpp:237
bool numbered
自動採番(レベル 1: "1."、レベル 2 以降: "1.1")を見出しの前に付ける
Definition block.hpp:53
bool bookmark
PDF のしおりに入れる
Definition block.hpp:55
画像ブロック
Definition block.hpp:107
std::optional< inl::Paragraph > caption
画像の下(行送り方向の後)に置く。テキストの {fig} は図番号になる
Definition block.hpp:114
ImagePlacement placement
Definition block.hpp:110
Align align
Block のときの行方向の揃え
Definition block.hpp:111
Pt gap
回り込みの本文との間隔
Definition block.hpp:112
std::shared_ptr< const dl::Image > image
Definition block.hpp:108
索引。本文中の {index:用語} / {index:よみ|用語} を集め、読みの順(かな: 五十音、欧文: A–Z)に 用語とページ番号を並べる。目次と同じく前のパスで集めた情報を使う(2〜3 パス...
Definition block.hpp:217
std::u16string pageSeparator
Definition block.hpp:223
bool grouped
行(あ・か・さ…)ごとに見出しを入れる
Definition block.hpp:220
TextStyle style
項目の文字
Definition block.hpp:218
std::optional< TextStyle > groupStyle
見出し文字(あ・か・さ… / A・B…)。無ければ style
Definition block.hpp:219
ラベル付き段落 — 台本の「名前欄+本文」、箇条書き、用語集
Definition block.hpp:79
std::vector< inl::Paragraph > body
Definition block.hpp:81
箇条書き(ラベル付き段落の列)
Definition block.hpp:188
Pt itemGap
項目間のアキ
Definition block.hpp:196
std::u16string numberSuffix
Numbered のとき "1." の "."
Definition block.hpp:193
Pt labelWidth
0 なら 1.5em(本文サイズ基準)
Definition block.hpp:194
std::u16string bullet
Definition block.hpp:192
std::vector< inl::Paragraph > items
Definition block.hpp:190
外部ハンドラで生成するオブジェクトのブロック(別行立ての数式・グラフなど)
Definition block.hpp:126
std::optional< inl::Paragraph > caption
Definition block.hpp:133
std::map< std::string, std::string > params
Definition block.hpp:129
std::u16string source
Definition block.hpp:128
罫線(行送り方向に thickness を占め、行の方向いっぱいに引く)
Definition block.hpp:60
Pt inset
両端を縮める量
Definition block.hpp:63
以降の段数を切り替える。段の途中なら次のページから効く
Definition block.hpp:90
std::optional< int > columns
Definition block.hpp:91
std::optional< Pt > columnGap
Definition block.hpp:92
std::vector< TableColumn > columns
空なら行のセル数から自動列数(全部自動幅)
Definition block.hpp:172
bool fullWidth
段の幅いっぱいに広げる(false なら自然幅で align)
Definition block.hpp:176
std::optional< inl::Paragraph > caption
表の上に置くキャプション。テキストの {table} は表番号になる
Definition block.hpp:180
std::vector< TableRow > rows
Definition block.hpp:173
Pt headerRule
ヘッダ行の下
Definition block.hpp:165
bool horizontal
横罫(行の境)を引く
Definition block.hpp:167
bool vertical
縦罫(列の境)を引く
Definition block.hpp:166
std::vector< inl::Paragraph > paras
Definition block.hpp:151
int rowspan
下の行へまたぐ。またいだ行はページをまたがない(まとめて次の段へ)
Definition block.hpp:153
表 — TeX の tabular 水準(列幅指定/自動、罫線、colspan、ヘッダ行の繰り返し、ページまたぎ)
Definition block.hpp:143
Align align
セル内の揃え(段落の align を上書き)
Definition block.hpp:145
Pt width
0 = 自動(内容の自然幅から配分)
Definition block.hpp:144
bool header
ヘッダ行(ページをまたぐときに繰り返す)
Definition block.hpp:159
std::vector< TableCell > cells
Definition block.hpp:158
目次。前のパスで集めた見出し(番号付き)とページ番号を並べる
Definition block.hpp:203
Pt indentPerLevel
0 なら 1em
Definition block.hpp:207
std::optional< TextStyle > subStyle
level 2 以降(無ければ style)
Definition block.hpp:206
TextStyle style
項目の文字(level 1)
Definition block.hpp:205