Re: graphics cell background
- To: mathgroup at smc.vnet.net
- Subject: [mg30052] Re: [mg30017] graphics cell background
- From: Omega Consulting <omega_consulting at yahoo.com>
- Date: Wed, 25 Jul 2001 01:00:37 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
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] ]