@@ -307,6 +307,7 @@ def generate_isd_sequence(
307
307
styles .StyleProperties .FontSize ,
308
308
styles .StyleProperties .Extent ,
309
309
styles .StyleProperties .Origin ,
310
+ styles .StyleProperties .Position ,
310
311
styles .StyleProperties .LineHeight ,
311
312
styles .StyleProperties .LinePadding ,
312
313
styles .StyleProperties .RubyReserve ,
@@ -467,10 +468,22 @@ def _process_element(
467
468
if isd_element .has_style (initial_style ):
468
469
continue
469
470
470
- initial_value = doc .get_initial_value (initial_style ) if doc .has_initial_value (initial_style ) \
471
- else initial_style .make_initial_value ()
471
+ if doc .has_initial_value (initial_style ):
472
+
473
+ initial_value = doc .get_initial_value (initial_style )
474
+
475
+ elif initial_style is not styles .StyleProperties .Position :
476
+
477
+ # the initial value of the Position style property is set to Origin as part of style computation
478
+
479
+ initial_value = initial_style .make_initial_value ()
480
+
481
+ else :
482
+
483
+ initial_value = None
472
484
473
485
styles_to_be_computed .add (initial_style )
486
+
474
487
isd_element .set_style (initial_style , initial_value )
475
488
476
489
# compute style properties
@@ -535,9 +548,9 @@ def _process_element(
535
548
536
549
# remove styles that are not applicable
537
550
538
- for computed_style_prop in list (isd_element .iter_styles ()):
539
- if not isd_element .is_style_applicable (computed_style_prop ):
540
- isd_element .set_style (computed_style_prop , None )
551
+ for style_prop in list (isd_element .iter_styles ()):
552
+ if not isd_element .is_style_applicable (style_prop ):
553
+ isd_element .set_style (style_prop , None )
541
554
542
555
# prune or keep the element
543
556
@@ -903,14 +916,14 @@ class Origin(StyleProcessor):
903
916
@classmethod
904
917
def compute (cls , parent : model .ContentElement , element : model .ContentElement ):
905
918
906
- style_value : styles .PositionType = element .get_style (cls .style_prop )
919
+ style_value : styles .CoordinateType = element .get_style (cls .style_prop )
907
920
908
921
# height
909
922
910
923
y = _compute_length (
911
924
style_value .y ,
912
925
_make_rh_length (100 ),
913
- element . get_style ( styles . StyleProperties . FontSize ) ,
926
+ None ,
914
927
_make_rh_length (100 / element .get_doc ().get_cell_resolution ().rows ),
915
928
_make_rh_length (100 / element .get_doc ().get_px_resolution ().height )
916
929
)
@@ -920,14 +933,14 @@ def compute(cls, parent: model.ContentElement, element: model.ContentElement):
920
933
x = _compute_length (
921
934
style_value .x ,
922
935
_make_rw_length (100 ),
923
- element . get_style ( styles . StyleProperties . FontSize ) ,
936
+ None ,
924
937
_make_rw_length (100 / element .get_doc ().get_cell_resolution ().columns ),
925
938
_make_rw_length (100 / element .get_doc ().get_px_resolution ().width )
926
939
)
927
940
928
941
element .set_style (
929
942
cls .style_prop ,
930
- styles .PositionType (
943
+ styles .CoordinateType (
931
944
x = x ,
932
945
y = y
933
946
)
@@ -992,6 +1005,81 @@ def compute(cls, parent: model.ContentElement, element: model.ContentElement):
992
1005
styles .PaddingType (c_before , c_end , c_after , c_start )
993
1006
)
994
1007
1008
+ class Position (StyleProcessor ):
1009
+ style_prop = styles .StyleProperties .Position
1010
+
1011
+ @classmethod
1012
+ def compute (cls , parent : model .ContentElement , element : model .ContentElement ):
1013
+
1014
+ position : styles .PositionType = element .get_style (styles .StyleProperties .Position )
1015
+
1016
+ if position is None :
1017
+
1018
+ # if no Position style property was specified, use the value of the Origin style property
1019
+
1020
+ origin : styles .CoordinateType = element .get_style (styles .StyleProperties .Origin )
1021
+
1022
+ element .set_style (
1023
+ styles .StyleProperties .Position ,
1024
+ styles .PositionType (
1025
+ h_offset = origin .x ,
1026
+ v_offset = origin .y
1027
+ )
1028
+ )
1029
+
1030
+ return
1031
+
1032
+ extent : styles .ExtentType = element .get_style (styles .StyleProperties .Extent )
1033
+
1034
+ assert extent .height .units is styles .LengthType .Units .rh
1035
+ assert extent .width .units is styles .LengthType .Units .rw
1036
+
1037
+ v_offset = _compute_length (
1038
+ position .v_offset ,
1039
+ _make_rh_length (100 - extent .height .value ),
1040
+ None ,
1041
+ _make_rh_length (100 / element .get_doc ().get_cell_resolution ().rows ),
1042
+ _make_rh_length (100 / element .get_doc ().get_px_resolution ().height )
1043
+ )
1044
+
1045
+ if position .v_edge is styles .PositionType .VEdge .bottom :
1046
+ v_offset = styles .LengthType (
1047
+ value = 100 - v_offset .value ,
1048
+ units = v_offset .units
1049
+ )
1050
+
1051
+ h_offset = _compute_length (
1052
+ position .h_offset ,
1053
+ _make_rw_length (100 - extent .width .value ),
1054
+ None ,
1055
+ _make_rw_length (100 / element .get_doc ().get_cell_resolution ().columns ),
1056
+ _make_rw_length (100 / element .get_doc ().get_px_resolution ().width )
1057
+ )
1058
+
1059
+ if position .h_edge is styles .PositionType .HEdge .right :
1060
+ h_offset = styles .LengthType (
1061
+ value = 100 - h_offset .value ,
1062
+ units = h_offset .units
1063
+ )
1064
+
1065
+ # if specified, the Position style property overrides the Origin style property
1066
+
1067
+ element .set_style (
1068
+ styles .StyleProperties .Origin ,
1069
+ styles .CoordinateType (
1070
+ x = h_offset ,
1071
+ y = v_offset
1072
+ )
1073
+ )
1074
+
1075
+ element .set_style (
1076
+ styles .StyleProperties .Position ,
1077
+ styles .PositionType (
1078
+ h_offset = h_offset ,
1079
+ v_offset = v_offset
1080
+ )
1081
+ )
1082
+
995
1083
class RubyAlign (StyleProcessor ):
996
1084
style_prop = styles .StyleProperties .RubyAlign
997
1085
0 commit comments