MathGroup Archive 2001

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: graphics cell background


At 03:16 PM 7/21/2001, Mark Fisher wrote:
>How can I find (automatically) what the Background color is for Graphics
>cells in a notebook?
>
>I am writing some grahics code that uses the Background color to mask
>some unwanted features. I'd like the code to work generally. My code is
>built on top of ListPlot. As a first pass, I dealt with "Background ->
>Automatic" by treating it as "Background -> RGBColor[1,1,1]", but that's
>not always true. The Background in a Graphics object is inherited from
>the Background of Graphics cells, which can be set in the style sheet
>and inherited from the notebook. It's not clear to me how to discover
>the proper value short of opening the style sheet and searching through
>it in various places.
>
>--Mark.

The only way to do this is to examine the style sheet. But this can be done 
by the kernel.

BackgroundColor[gropt___?OptionQ] :=
   Block[{sd, grdef, nbopt, nbdef, $Messages = {},
       noauto = {Automatic -> Background, None -> Background}},
     sd = StyleDefinitions /. Options[EvaluationNotebook[]] /.
         StyleDefinitions -> "Default.nb";
     If[StringQ[sd],
       sd = Get[ToFileName[{$TopDirectory, "SystemFiles", "FrontEnd",
               "StyleSheets"}, sd]]
       ];(* works for most style sheets *)
     If[Head[sd] =!= Notebook, sd={}];
     grdef = Flatten[
           Cases[sd, Cell[StyleData["Graphics"], opts___] :> {opts}, 
Infinity]];
     nbopt = Options[EvaluationNotebook[], Background];
     nbdef = Flatten[
           Cases[sd, Cell[StyleData["Notebook"], opts___] :> {opts}, 
Infinity]];
     Background /. {gropt} /. noauto /. grdef /. noauto /. nbopt /. noauto /.
           nbdef /. noauto /. Background -> GrayLevel[1]
     ]



  • Prev by Date: Re: Thickness Isn't Thickness
  • Next by Date: Re: Delay in $Context changes taking effect?
  • Previous by thread: graphics cell background
  • Next by thread: Leibniz as an educational frontend