Skip to content

Commit cae0741

Browse files
committed
[FIX] style: rotation fix for centered text
Task: 5400633
1 parent c674f82 commit cae0741

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

packages/o-spreadsheet-engine/src/helpers/text_helper.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,12 @@ export function computeRotationPosition(
469469
} else {
470470
if (center) {
471471
x -= sh / 2;
472+
y -= height / 2;
473+
if (rotateTowardCellCenter) {
474+
y += sh;
475+
} else {
476+
y -= sh;
477+
}
472478
} else if (rotateTowardCellCenter) {
473479
x -= sh;
474480
y -= sw / 2;

tests/helpers/text_helper.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ describe("computeRotationPosition", () => {
160160
test.each([Math.PI / 2, Math.PI / 3, Math.PI / 4])("Positive Rotation", (rotation) => {
161161
const sin = Math.sin(rotation);
162162
const newX = textBox.x + (sin * textHeight) / 2;
163-
const newY = textBox.y;
163+
const newY = textBox.y - textHeight / 2 + sin * textHeight;
164164

165165
expect(computeRotationPosition(textBox, { ...style, rotation })).toMatchObject({
166166
x: expect.toBeCloseTo(rotate(newX, newY, rotation).x),
@@ -171,7 +171,7 @@ describe("computeRotationPosition", () => {
171171
test.each([-Math.PI / 2, -Math.PI / 3, -Math.PI / 4])("Negative Rotation", (rotation) => {
172172
const sin = Math.sin(rotation);
173173
const newX = textBox.x + (sin * textHeight) / 2;
174-
const newY = textBox.y;
174+
const newY = textBox.y - textHeight / 2 - sin * textHeight;
175175
expect(computeRotationPosition(textBox, { ...style, rotation })).toMatchObject({
176176
x: expect.toBeCloseTo(rotate(newX, newY, rotation).x),
177177
y: expect.toBeCloseTo(rotate(newX, newY, rotation).y),

0 commit comments

Comments
 (0)