1#ifndef TYPESET_GEOM_HPP
2#define TYPESET_GEOM_HPP
20constexpr Pt kMm = 72.0f / 25.4f;
41 bool empty()
const {
return w <= 0.0f ||
h <= 0.0f; }
55 float xx = 1.0f,
xy = 0.0f;
56 float yx = 0.0f,
yy = 1.0f;
59 return xx == 1.0f &&
xy == 0.0f &&
yx == 0.0f &&
yy == 1.0f;
69 float xx = 1.0f,
xy = 0.0f,
dx = 0.0f;
70 float yx = 0.0f,
yy = 1.0f,
dy = 0.0f;
78 const float c = std::cos(radians), s = std::sin(radians);
95 return xx == 1.0f &&
xy == 0.0f &&
dx == 0.0f &&
96 yx == 0.0f &&
yy == 1.0f &&
dy == 0.0f;
118 uint8_t
r = 0,
g = 0,
b = 0,
a = 255;
123 return Color{
static_cast<uint8_t
>((v >> 16) & 0xFF),
static_cast<uint8_t
>((v >> 8) & 0xFF),
124 static_cast<uint8_t
>(v & 0xFF),
static_cast<uint8_t
>((v >> 24) & 0xFF)};
127 return (
static_cast<uint32_t
>(
a) << 24) | (
static_cast<uint32_t
>(
r) << 16) |
128 (
static_cast<uint32_t
>(
g) << 8) |
static_cast<uint32_t
>(
b);
196 if (t <=
stops.front().offset)
return stops.front().color;
197 if (t >=
stops.back().offset)
return stops.back().color;
198 for (
size_t i = 1; i <
stops.size(); ++i) {
199 if (t >
stops[i].offset)
continue;
203 const float u = span > 0.0f ? (t - a.
offset) / span : 0.0f;
204 auto mix = [&](uint8_t x, uint8_t y) {
205 return static_cast<uint8_t
>(x + (
static_cast<float>(y) - x) * u + 0.5f);
210 return stops.back().color;
271 pts.push_back({c1x, c1y});
pts.push_back({c2x, c2y});
pts.push_back({x, y});
287 std::vector<bool>* closedFlags =
nullptr);
Matrix multiply(const Matrix &a, const Matrix &b)
a を後から適用する合成(結果 = a ∘ b。b で写してから a)
std::vector< std::vector< Point > > flattenPath(const Path &path, float tolerance, std::vector< bool > *closedFlags=nullptr)
曲線を折れ線に平坦化した閉/開多角形列を得る(tolerance は pt)
Matrix invert(const Matrix &m, bool *ok=nullptr)
逆行列。特異なら単位行列を返し ok=false
static Color rgb(uint8_t r, uint8_t g, uint8_t b)
bool operator==(const Color &o) const
static Color rgba(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
static Color argb(uint32_t v)
bool operator!=(const Color &o) const
bool operator==(const GradientStop &o) const
2x2 行列(平行移動なし)。グリフ固有の変形に使う。 x' = xx*x + xy*y y' = yx*x + yy*y
2x3 アフィン行列(行優先) x' = xx*x + xy*y + dx y' = yx*x + yy*y + dy
static Matrix scaling(float sx, float sy)
static Matrix rotation(float radians)
回転(ラジアン。y-down なので画面上では時計回りが正)
float determinant() const
static Matrix translation(Pt tx, Pt ty)
Point apply(Point p) const
Point applyVector(Point v) const
static Matrix fromMat2(const Mat2 &r, Pt tx=0.0f, Pt ty=0.0f)
bool operator==(const Paint &o) const
Color solid() const
単色として扱うときの色(グラデーションは中間の色)
bool operator!=(const Paint &o) const
std::vector< GradientStop > stops
offset の昇順
static Paint linear(Point from, Point to, std::vector< GradientStop > stops, PaintUnits units=PaintUnits::BoundingBox)
Point start
Linear: 始点/Radial: 中心
static Paint radial(Point center, float radius, std::vector< GradientStop > stops, PaintUnits units=PaintUnits::BoundingBox)
Color at(float t) const
t(0〜1)の色。停止点の間を線形補間する
uint8_t maxAlpha() const
不透明度の代表値(グラデーションは最大)
パス(moveTo / lineTo / quadTo / cubicTo / close)
void addRect(const Rect &r)
Rect controlBounds() const
制御点を含むバウンディングボックス
void addEllipse(const Rect &r)
楕円(矩形に内接)を 4 本の 3 次ベジェで近似
void cubicTo(Pt c1x, Pt c1y, Pt c2x, Pt c2y, Pt x, Pt y)
Path transformed(const Matrix &m) const
void quadTo(Pt cx, Pt cy, Pt x, Pt y)
void addLine(Point a, Point b)
Rect intersect(const Rect &o) const
bool contains(Point p) const
Rect unite(const Rect &o) const
Paint color
線の塗り(単色または グラデーション。Color から暗黙に作れる)
bool operator==(const Stroke &o) const
bool operator!=(const Stroke &o) const