Add a rotation to the text effect's placement
text_rotation turns the text and its box about the box's centre, so the centring and the offset still decide where it sits. Like the other placement params it stays on the stage and is not carried by a style. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <numbers>
|
||||
|
||||
#include "core/parallel.hpp"
|
||||
#include "effects/source_fill.hpp"
|
||||
@@ -57,6 +58,10 @@ const std::vector<ParamSpec>& TextEffect::params() const {
|
||||
"Moves the text right by this many pixels (left when negative)."),
|
||||
ParamSpec::makeInt("text_offset_y", "Offset Y", 0, -20000, 20000,
|
||||
"Moves the text down by this many pixels (up when negative)."),
|
||||
ParamSpec::makeDouble("text_rotation", "Rotation", 0.0, -360.0, 360.0,
|
||||
"Turns the text and its box about their centre by this many "
|
||||
"degrees, clockwise (anticlockwise when negative).",
|
||||
1.0, 1),
|
||||
ParamSpec::makeDouble("text_opacity", "Text opacity", 1.0, 0.0, 1.0,
|
||||
"How strongly the glyphs are mixed over what is behind them.")
|
||||
.styled(),
|
||||
@@ -264,6 +269,18 @@ Image TextEffect::render(const std::vector<Image>& sources, int width, int heigh
|
||||
const double boxY = (centre ? (height - boxHeight) / 2.0 : 0.0) +
|
||||
static_cast<double>(paramInt(values, "text_offset_y", 0));
|
||||
|
||||
// The turn is about the middle of the box, so it never moves the text away
|
||||
// from where the centring and the offset put it. Cairo's y points down,
|
||||
// which makes a positive angle clockwise on screen.
|
||||
const double rotation = paramDouble(values, "text_rotation", 0.0);
|
||||
if (rotation != 0.0) {
|
||||
const double cx = boxX + boxWidth / 2.0;
|
||||
const double cy = boxY + boxHeight / 2.0;
|
||||
cairo_translate(cr.get, cx, cy);
|
||||
cairo_rotate(cr.get, rotation * std::numbers::pi / 180.0);
|
||||
cairo_translate(cr.get, -cx, -cy);
|
||||
}
|
||||
|
||||
if (drawsBox) {
|
||||
cairo_save(cr.get);
|
||||
cairo_rectangle(cr.get, boxX, boxY, boxWidth, boxHeight);
|
||||
|
||||
Reference in New Issue
Block a user