@@ -15,7 +15,12 @@ import { functionRegistry } from "@odoo/o-spreadsheet-engine/functions/function_
1515import { toScalar } from "@odoo/o-spreadsheet-engine/functions/helper_matrices" ;
1616import { toString } from "@odoo/o-spreadsheet-engine/functions/helpers" ;
1717import { Model } from "@odoo/o-spreadsheet-engine/model" ;
18- import { fontSizeInPixels , getCellContentHeight , toCartesian } from "../../src/helpers" ;
18+ import {
19+ fontSizeInPixels ,
20+ getCellContentHeight ,
21+ positionToZone ,
22+ toCartesian ,
23+ } from "../../src/helpers" ;
1924import { CommandResult , Format , SetDecimalStep , UID } from "../../src/types" ;
2025import {
2126 createSheet ,
@@ -824,4 +829,58 @@ describe("Autoresize", () => {
824829 expect ( getCellContent ( model , "A1" ) ) . toEqual ( "-7" ) ;
825830 expect ( model . getters . getRowSize ( sheetId , 0 ) ) . toEqual ( initialSize ) ;
826831 } ) ;
832+
833+ test . each ( [
834+ 0 ,
835+ - Math . PI / 2 ,
836+ - Math . PI / 3 ,
837+ - Math . PI / 4 ,
838+ 0 ,
839+ Math . PI / 4 ,
840+ Math . PI / 3 ,
841+ Math . PI / 2 ,
842+ ] ) ( "Autoresize work with rotated text %s" , ( rotation ) => {
843+ model . dispatch ( "SET_FORMATTING" , {
844+ sheetId,
845+ target : [ positionToZone ( toCartesian ( "A2" ) ) ] ,
846+ style : { rotation, fontSize : 20 } ,
847+ } ) ;
848+
849+ const cos = Math . abs ( Math . cos ( rotation ) ) ;
850+ const sin = Math . abs ( Math . sin ( rotation ) ) ;
851+ let width , height ;
852+
853+ setCellContent ( model , "A1" , "ABC" ) ;
854+ ( { width, height } = model . getters . getMultilineTextSize ( [ "ABC" ] , { rotation, fontSize : 20 } ) ) ;
855+ model . dispatch ( "AUTORESIZE_COLUMNS" , { sheetId, cols : [ 0 ] } ) ;
856+ expect ( model . getters . getColSize ( sheetId , 0 ) ) . toEqual (
857+ cos * width + sin * height + 2 * PADDING_AUTORESIZE_HORIZONTAL
858+ ) ;
859+ model . dispatch ( "AUTORESIZE_ROWS" , { sheetId, rows : [ 0 ] } ) ;
860+ expect ( model . getters . getRowSize ( sheetId , 0 ) ) . toEqual (
861+ sin * width + cos * height + 2 * PADDING_AUTORESIZE_VERTICAL
862+ ) ;
863+
864+ setCellContent ( model , "A1" , "ABC\n123" ) ;
865+ ( { width, height } = model . getters . getMultilineTextSize ( [ "ABC" , "123" ] , { rotation } ) ) ;
866+ model . dispatch ( "AUTORESIZE_COLUMNS" , { sheetId, cols : [ 0 ] } ) ;
867+ expect ( model . getters . getColSize ( sheetId , 0 ) ) . toEqual (
868+ cos * width + sin * height + 2 * PADDING_AUTORESIZE_HORIZONTAL
869+ ) ;
870+ model . dispatch ( "AUTORESIZE_ROWS" , { sheetId, rows : [ 0 ] } ) ;
871+ expect ( model . getters . getRowSize ( sheetId , 0 ) ) . toEqual (
872+ sin * width + cos * height + 2 * PADDING_AUTORESIZE_VERTICAL
873+ ) ;
874+
875+ setCellContent ( model , "A1" , "ABC-123" ) ;
876+ ( { width, height } = model . getters . getMultilineTextSize ( [ "ABC-123" ] , { rotation } ) ) ;
877+ model . dispatch ( "AUTORESIZE_COLUMNS" , { sheetId, cols : [ 0 ] } ) ;
878+ expect ( model . getters . getColSize ( sheetId , 0 ) ) . toEqual (
879+ cos * width + sin * height + 2 * PADDING_AUTORESIZE_HORIZONTAL
880+ ) ;
881+ model . dispatch ( "AUTORESIZE_ROWS" , { sheetId, rows : [ 0 ] } ) ;
882+ expect ( model . getters . getRowSize ( sheetId , 0 ) ) . toEqual (
883+ sin * width + cos * height + 2 * PADDING_AUTORESIZE_VERTICAL
884+ ) ;
885+ } ) ;
827886} ) ;
0 commit comments