typeset 0.1.0
縦書き・横書きの日本語組版ライブラリ(JLReq 水準、ラスタ / PDF / SVG)
読み取り中…
検索中…
一致する文字列を見つけられません
line_breaker.hpp
[詳解]
1#ifndef TYPESET_INL_LINE_BREAKER_HPP
2#define TYPESET_INL_LINE_BREAKER_HPP
3
4#include <cstdint>
5#include <vector>
6
8#include "typeset/style.hpp"
9
18namespace typeset::inl {
19
21struct LineShape {
22 Pt length = 0.0f;
23 Pt indent = 0.0f;
24};
25
27public:
28 virtual ~LineShapeProvider() = default;
30 virtual LineShape at(int lineIndex) const = 0;
35 virtual LineShape at(int lineIndex, Pt /*extraBlock*/) const { return at(lineIndex); }
36};
37
40public:
41 OffsetLineShape(const LineShapeProvider& base, const std::vector<Pt>& offsets, int firstLineIndex)
42 : base_(base), offsets_(offsets), first_(firstLineIndex) {}
43 LineShape at(int lineIndex) const override { return at(lineIndex, 0.0f); }
44 LineShape at(int lineIndex, Pt extraBlock) const override {
45 const int i = lineIndex - first_;
46 const Pt extra = (i >= 0 && static_cast<size_t>(i) < offsets_.size()) ? offsets_[static_cast<size_t>(i)]
47 : (offsets_.empty() ? 0.0f : offsets_.back());
48 return base_.at(lineIndex, extraBlock + extra);
49 }
50private:
51 const LineShapeProvider& base_;
52 const std::vector<Pt>& offsets_;
53 int first_;
54};
55
58public:
59 explicit ConstantLineShape(Pt length, Pt indent = 0.0f) : length_(length), indent_(indent) {}
60 LineShape at(int) const override { return LineShape{length_, indent_}; }
61private:
62 Pt length_;
63 Pt indent_;
64};
65
68public:
69 IndentedLineShape(const LineShapeProvider& base, int indentLine, Pt indent)
70 : base_(base), indentLine_(indentLine), indent_(indent) {}
71 LineShape at(int lineIndex) const override { return at(lineIndex, 0.0f); }
72 LineShape at(int lineIndex, Pt extraBlock) const override {
73 LineShape s = base_.at(lineIndex, extraBlock);
74 if (lineIndex == indentLine_) {
75 s.length -= indent_;
76 s.indent += indent_;
77 }
78 return s;
79 }
80private:
81 const LineShapeProvider& base_;
82 int indentLine_;
83 Pt indent_;
84};
85
87struct BreakLine {
88 uint32_t itemStart = 0;
89 uint32_t itemEnd = 0;
90 float ratio = 0.0f;
92 Pt width = 0.0f;
93 int lineIndex = 0;
95};
96
103std::vector<BreakLine> breakLines(const std::vector<LineItem>& items,
104 const LineShapeProvider& shape,
105 const BreakOptions& opts,
106 int firstLineIndex = 0);
107
108} // namespace typeset::inl
109
110#endif // TYPESET_INL_LINE_BREAKER_HPP
LineShape at(int) const override
lineIndex 行目の形(段落の先頭を 0 とは限らない。呼び出し側が firstLineIndex を渡す)
ConstantLineShape(Pt length, Pt indent=0.0f)
指定した行だけ行頭を下げる(一字下げ用)
LineShape at(int lineIndex) const override
lineIndex 行目の形(段落の先頭を 0 とは限らない。呼び出し側が firstLineIndex を渡す)
LineShape at(int lineIndex, Pt extraBlock) const override
行送りが広がった行の後ろでの形。extraBlock は「行番号 × 行送り」に対して実際の行位置が ずれている量(前の行までの追加の送り)。排除領域を見る実装だけが使う。既定は at(lineInde...
IndentedLineShape(const LineShapeProvider &base, int indentLine, Pt indent)
virtual LineShape at(int lineIndex, Pt) const
行送りが広がった行の後ろでの形。extraBlock は「行番号 × 行送り」に対して実際の行位置が ずれている量(前の行までの追加の送り)。排除領域を見る実装だけが使う。既定は at(lineInde...
virtual ~LineShapeProvider()=default
virtual LineShape at(int lineIndex) const =0
lineIndex 行目の形(段落の先頭を 0 とは限らない。呼び出し側が firstLineIndex を渡す)
行ごとの実際の位置のずれを base に渡す(段落レイアウタが行送りの広がりを反映するのに使う)
LineShape at(int lineIndex) const override
lineIndex 行目の形(段落の先頭を 0 とは限らない。呼び出し側が firstLineIndex を渡す)
OffsetLineShape(const LineShapeProvider &base, const std::vector< Pt > &offsets, int firstLineIndex)
LineShape at(int lineIndex, Pt extraBlock) const override
行送りが広がった行の後ろでの形。extraBlock は「行番号 × 行送り」に対して実際の行位置が ずれている量(前の行までの追加の送り)。排除領域を見る実装だけが使う。既定は at(lineInde...
inl/annotation — 行内に組み込む注記
std::vector< BreakLine > breakLines(const std::vector< LineItem > &items, const LineShapeProvider &shape, const BreakOptions &opts, int firstLineIndex=0)
行分割を実行する
float Pt
Definition geom.hpp:17
確定した 1 行
int lineIndex
LineShapeProvider に渡した行番号
uint32_t itemEnd
同・終端(ブレーク位置。この位置は含まない)
Pt naturalWidth
調整前の行長
LineShape shape
その行の形
uint32_t itemStart
行を構成するアイテムの開始
float ratio
グルーの調整比。>0 で伸ばす、<0 で縮める
Pt width
調整後の行長
1 行の形(行長と行頭の下げ)