It seems the best way is to lead to the canonical form {{_, _}, {_, _}}
every option on the first step, then handle their inter-dependencies separately. The following module returns complete horizontal and vertical margins {mHor, mVert}
for "Input"
style:
Module[{m, f, fm},
{m, f, fm} = CurrentValue[EvaluationNotebook[], {StyleDefinitions, "Input", #}] & /@ {CellMargins, CellFrame, CellFrameMargins};
(* canonicalization *)
{m, f, fm} = Replace[{m, f, fm}, x : Except[{{_, _}, {_, _}}] :> {{x, x}, {x, x}}, {1}];
(* replacing CellFrameMargins by zeros where the frame is off *)
fm = ReplacePart[fm, Position[f, Except[True | _?(Positive[Abs[#]] &)], {2}, Heads -> False] -> 0];
(* clearing up non-numeric values *)
{m, f, fm} = Replace[{m, f, fm}, x_ /; Not@NumericQ[x] :> 0, {3}];
Total /@ (m + f + fm)]
{76, 15}
Note that the above implementation is still incomplete because it doesn't take into account CellLabelMargins
and CellFrameLabelMargins
as well as "Widths"
suboption of CellBracketOptions
.