This is a static copy of a profile report

Home

graphics/private/preparehg (40 calls, 6.930 sec)
Generated 05-Aug-2011 13:03:07 using cpu time.
function in file /usr/local/MATLAB/R2011a/toolbox/matlab/graphics/private/preparehg.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
graphics/private/preparefunction40
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
43
fireprintbehavior(h,'PrePrintC...
403.443 s49.7%
165
savtoner( 'save', h );
402.088 s30.1%
118
pj = prepareui(pj, h);
400.568 s8.2%
122
hgdata.PixelObjects = [findall...
400.273 s3.9%
130
hgdata.FontPixelObjects = [fin...
400.208 s3.0%
All other lines  0.350 s5.0%
Totals  6.930 s100% 
Children (called functions)

Function NameFunction TypeCallsTotal Time% TimeTime Plot
graphics/private/fireprintbehaviorfunction403.443 s49.7%
savtonerfunction402.077 s30.0%
graphics/private/prepareuifunction400.557 s8.0%
findallfunction3200.481 s6.9%
noanimatefunction400.153 s2.2%
graphics/private/noselectionfunction400.077 s1.1%
usejavafunction400.011 s0.2%
getprinttemplatefunction400.011 s0.2%
graphics/private/isfigurefunction400.011 s0.2%
graphics/private/bltfunction400 s0%
graphics/private/useOriginalHGPrintingfunction400 s0%
Self time (built-ins, overhead, etc.)  0.109 s1.6%
Totals  6.930 s100% 
Code Analyzer results
Line numberMessage
186NOANIMATE will be removed in a future release. There is no simple replacement for this.
Coverage results
[ Show coverage for parent directory ]
Total lines in function233
Non-code lines (comments, blank lines)111
Code lines (lines that can run)122
Code lines that did run55
Code lines that did not run67
Coverage (did run/can run)45.08 %
Function listing
   time   calls  line
1 function pj = preparehg( pj, h )
2 %PREPAREHG Method to ready a Figure for printing.
3 % Modify properties of a Figure and its children based on property values
4 % and PrintJob state. Changes include color of objects and size of Figure
5 % on screen if a ResizeFcn needs to be called.
6 % Creates and returns a structure with fields containing various data
7 % we have to save for restoration of the Figure and its children.
8 %
9 % Ex:
10 % pj = PREPAREHG( pj, h ); %modifies PrintJob object pj and Figure h
11 %
12 % See also PRINT, PREPARE, RESTORE, RESTOREHG.
13
14 % Copyright 1984-2010 The MathWorks, Inc.
15 % $Revision: 1.10.4.16 $ $Date: 2010/08/16 21:02:24 $
16
17 % Uses structure because of the danger of not clearing out state variables
18 % in the PrintJob object between renderings of different Figures.
19 % ResizeFcn %Original value of ResizeFcn, nulled out during print
20 % ResizedWindow %True if had to resize Figure on screen because of ResizeFcn
21 % WindowUnits %Original Window units while we work in points
22 % WindowPos %Original Window position in original units
23 % PixelObjects %Vector of handles to objects positioned in pixel units
24 % FontPixelObjects %Vector of handles to objects with FontUnits of pixels
25 % Inverted %1 = Force white background 2 = force transparent background
26 % Undithered %True if changed foreground colors of Text and Lines to black
27 % Renderer %Save original renderer if using different one while printing
28 % RendererAutoMode %If setting different renderer, don't change mode as a result
29 % PrintTemplate %Copy of Figure's template for output formating with saved state for later restoration
30
40 31 error( nargchk(2,2,nargin,'struct') )
32
40 33 if (~useOriginalHGPrinting())
34 error('MATLAB:Print:ObsoleteFunction', 'The function %s should only be called when original HG printing is enabled.', upper(mfilename));
35 end
36
0.01 40 37 if ~isequal(size(h), [1 1]) || ~isfigure( h )
38 error('MATLAB:preparehg:InvalidHandle', 'Need a handle to a Figure object.' )
39 end
40
41 % Indicate that we are about to start printing.
40 42 setappdata(0,'BusyPrinting',true);
3.44 40 43 fireprintbehavior(h,'PrePrintCallback');
44
45 %Early exit, want to save Figure as is.
40 46 if strcmp(pj.Driver, 'mfile')
47 pj.hgdata = [];
48 return
49 end
50
51 %Figures can be formatted for output via a PrintTemplate object
0.01 40 52 pt = getprinttemplate(h);
40 53 if isempty( pt )
40 54 hgdata.PrintTemplate = [];
55 else
56 hgdata.PrintTemplate = ptpreparehg( pt, h );
57 end
58
59 %Fun with resize functions.
60 %--------------------------
61 %Make Figure the size it is going to be while printing (i.e. PaperPosition).
62 %This will cause the user's ResizeFcn to be called while the Figure is
63 %still at screen resolution. This gives the user a chance to move and
64 %resize things the way s/he wants. Afterwards the ResizeFcn is nulled,
65 %always, so that the resizing of the Figure that happens internally
66 %when changing to the driver resolution does not cause any
67 %weird results. For the same reason, objects in Pixel units are
68 %set to Points so they do not draw screenDPI/driverDPI too small or big.
69
40 70 adjustResizeFcn = 1;
40 71 rf = get( h, 'ResizeFcn' );
40 72 if ischar(rf)
40 73 if strcmp( rf, 'legend(''ResizeLegend'')' ) ...
74 || strcmp( rf, 'doresize(gcbf)')
75
76 %This is a known good ResizeFcn, can handle being called during
77 %printing, so let's not resize on screen and output the warning.
78 hgdata.ResizeFcn = '';
79 hgdata.ResizedWindow = 0;
80 adjustResizeFcn = 0;
81 end
40 82 end
40 83 if adjustResizeFcn
40 84 hgdata.ResizeFcn = rf;
40 85 if isempty(hgdata.ResizeFcn) || strcmp( 'auto', get( h, 'paperpositionmode' ) )
40 86 hgdata.ResizedWindow = 0;
87 else
88 hgdata.ResizedWindow = 1;
89 hgdata.WindowUnits = get( h, 'units' );
90 hgdata.WindowPos = get( h, 'position' );
91 set( h, 'units', 'points' )
92 pointsWindowPos = get( h, 'position' );
93 pointsPaperPos = getget( h, 'paperposition' ); %already in points units
94 set( h, 'units', hgdata.WindowUnits )
95
96 if (pointsWindowPos(3)~=pointsPaperPos(3)) || ...
97 (pointsWindowPos(4)~=pointsPaperPos(4))
98 printbehavior = hggetbehavior(h,'Print','-peek');
99 if isempty(printbehavior) || ...
100 strcmp(printbehavior.WarnOnCustomResizeFcn,'on')
101 warning('MATLAB:Print:CustomResizeFcnInPrint',[ ...
102 'Positioning Figure for ResizeFcn. ',...
103 'Set PaperPositionMode to ''auto''\n',...
104 ' (match figure screen size) to ',...
105 'avoid resizing and this warning.']);
106 end
107 screenpos( h, [ pointsWindowPos(1:2) pointsPaperPos(3:4) ] );
108 %Implicit drawnow in getframe not reliable, may not have any UIControls
109 drawnow
110 end
111 end
40 112 if ~isempty(hgdata.ResizeFcn )
113 set( h, 'ResizeFcn', '' );
114 end
40 115 end
116
117 %%%Capture images to stand in place of uicontrols which do not print.
0.57 40 118 pj = prepareui(pj, h);
119
120 %PrintUI stuff may have made, or there already existed, Pixel position Axes.
121 %Set all Pixel objects to Points so they handle being printed at driver DPI.
0.27 40 122 hgdata.PixelObjects = [findall(h,'type','axes', 'units','pixels')
123 findall(h,'type','text', 'units','pixels')
124 findall(h,'type','uipanel', 'units','pixels')
125 findall(h,'type','uicontainer','units','pixels')];
40 126 if ~isempty( hgdata.PixelObjects )
127 set( hgdata.PixelObjects, 'units', 'points' )
128 end
129 %Same thing for Axes and Text objects with FontUnits set to pixels.
0.21 40 130 hgdata.FontPixelObjects = [findall(h,'type','axes', 'fontunits','pixels')
131 findall(h,'type','text', 'fontunits','pixels')
132 findall(h,'type','uipanel', 'fontunits','pixels')
133 findall(h,'type','uicontainer','fontunits','pixels')];
40 134 if ~isempty( hgdata.FontPixelObjects )
135 set( hgdata.FontPixelObjects, 'fontunits', 'points' )
136 end
137
138
139 % Possibly invert B&W color properties of Figure and child objects
140 % The following should be changed when we add "transparent" as a "Inverted" option
141 % CopyOptions is set in uiw\menu_w.c as a flag to let us know where we came from
142
40 143 hgdata.Inverted = 0;
40 144 hasPrefs = 0;
40 145 honorPrefs = 0;
0.02 40 146 if usejava('awt')
40 147 try %#ok
40 148 honorPrefs = javaMethod('getIntegerPref', 'com.mathworks.services.Prefs', ...
149 'CopyOptions.HonorCOPrefs') ~= 0;
40 150 hasPrefs = 1;
40 151 end
40 152 end
40 153 if (hasPrefs && honorPrefs)
154 figbkcolor = javaMethod('getIntegerPref', 'com.mathworks.services.Prefs', 'CopyOptions.FigureBackground');
155 if isequal(figbkcolor, 0) % "none"
156 hgdata.Inverted = 2;
157 localcolornone('save', h);
158 elseif isequal(figbkcolor, 1)
159 hgdata.Inverted = 1;
160 savtoner( 'save', h );
161 end
40 162 else
0.01 40 163 if strcmp('on', get(h,'InvertHardcopy'))
40 164 hgdata.Inverted = 1;
2.09 40 165 savtoner( 'save', h );
40 166 end
40 167 end
168
169 % Possibly set Lines and Text to B or W, what contrasts with background
40 170 if blt(pj,h)
40 171 hgdata.Undithered = 0;
172 else
173 hgdata.Undithered = 1;
174 nodither( 'save', h );
175 end
176
177 %Deselect all objects so that we do not print their selection handles.
0.09 40 178 noselection('save',h);
179
180 % if printing to JPEG or TIFF file, then we need to convert animated
181 % objects to 'erasemode','normal' so that they will render into the
182 % Z-Buffer. Same if producing TIFF for EPS preview of printed Figure.
40 183 if strcmp(pj.DriverClass, 'IM') || ((pj.PostScriptPreview == pj.TiffPreview) && ~pj.GhostImage)
40 184 [prevWarnMsg prevWarnID] = lastwarn;
0.01 40 185 noanimateWarn = warning('off', 'MATLAB:noanimate:DeprecatedFunction');
0.15 40 186 noanimate('save',h);
40 187 warning(noanimateWarn);
40 188 lastwarn(prevWarnMsg, prevWarnID);
40 189 end
190
191 %If not using Painters renderer (i.e. Figure is not set to Painters or user asked for Z) ...
40 192 if strcmp(get(h,'rendererMode'),'manual') && ~(strcmp( 'painters', get(h,'renderer')) || strcmp(pj.Renderer,'painters') )
193 %and if using a driver or on an X system that can not create Zbuffer ...
194 if (strcmp(pj.Driver, 'hpgl') || strcmp(pj.Driver, 'ill')) || pj.XTerminalMode
195 %just use Painters
196 if ~strcmp(pj.Renderer,'painters') && ~isempty(pj.Renderer)
197 ren = pj.Renderer;
198 else
199 ren = get(h,'renderer');
200 end
201 if ~pj.XTerminalMode
202 warning('MATLAB:Print:BadPrintDeviceRenderer',[ ...
203 'The %s device option does not support the %s renderer.\n', ...
204 ' Printing Figure with Painters renderer. Figures with \n',...
205 ' interpolated shading or images may not print correctly.'], ...
206 upper(pj.Driver),ren)
207 end
208 pj.Renderer = 'painters';
209 end
210 end
211
212 % Temporary workaround for opengl printing problem - use zbuffer - now
213 % turned off
214 %if (~isempty( pj.Renderer ) && strcmpi(pj.Renderer, 'opengl')) || ...
215 % (isempty( pj.Renderer ) && strcmpi( get(h, 'renderer'), 'opengl'))
216 % pj.Renderer = 'zbuffer';
217 %end
218
219 % If renderer is None, set it to painters for the print rendering, then
220 % set it back.
0.04 40 221 if strcmp(get(h,'renderer'),'None')
222 pj.Renderer = 'painters';
223 end
224
225 % Set render to use while printing now
40 226 if ~isempty( pj.Renderer )
227 hgdata.Renderer = get( h, 'renderer' );
228 hgdata.RendererAutoMode = strcmp( get( h, 'renderermode' ), 'auto' );
229 set( h, 'renderer', pj.Renderer )
230 end
231
232 %Save it in object for later retrevial
40 233 pj.hgdata = hgdata;

Other subfunctions in this file are not included in this listing.