| 1 |
function [orig] = initializeGlobalState() |
| 2 |
% Initialize global state. Set working directory and various properties of |
| 3 |
% the graphical root to ensure reliable output of the ACID testsuite. |
| 4 |
% See #542 and #552 |
| 5 |
% |
| 6 |
% 1. Working directory |
| 7 |
% 2. Bring get(0,'Default') in line with get(0,'Factory') |
| 8 |
% 3. Set specific properties, required by matlab2tikz |
| 9 |
fprintf('Initialize global state...\n'); |
| 10 |
orig = struct(); |
| 11 |
|
| 12 |
%--- Extract user defined default properties and set factory state |
| 13 |
default = get(0,'Default'); |
| 14 |
factory = get(0,'Factory'); |
| 15 |
|
| 16 |
f = fieldnames(default); % fields of user's default state |
| 17 |
for i = 1:length(f) |
| 18 |
factory_property_name = strrep(f{i},'default','factory'); |
| 19 |
factory_property_value = factory.(factory_property_name); |
| 20 |
orig.(f{i}).val = ... |
| 21 |
swapPropertyState(0, f{i}, factory_property_value); |
| 22 |
end |
| 23 |
|
| 24 |
%--- Define desired global state properties |
| 25 |
% defaultAxesColorOrder: on HG1 'default' and 'factory' differ and |
| 26 |
% HG1 differs from HG2. Consequently use HG2 colors (the new standard). |
| 27 |
new.defaultAxesColorOrder.val = [0.000 0.447 0.741; ... |
| 28 |
0.850 0.325 0.098; ... |
| 29 |
0.929 0.694 0.125; ... |
| 30 |
0.494 0.184 0.556; ... |
| 31 |
0.466 0.674 0.188; ... |
| 32 |
0.301 0.745 0.933; ... |
| 33 |
0.635 0.0780 0.184]; |
| 34 |
new.defaultAxesColorOrder.ignore= false; |
| 35 |
|
| 36 |
% defaultFigurePosition: width and height influence cleanfigure() and |
| 37 |
% the number/location of axis ticks |
| 38 |
new.defaultFigurePosition.val = [300,200,560,420]; |
| 39 |
new.defaultFigurePosition.ignore= false; |
| 40 |
|
| 41 |
% ScreenPixelsPerInch: TODO: determine, if necessary |
| 42 |
% (probably needed for new line simplification algorithm) |
| 43 |
% not possible in octave |
| 44 |
new.ScreenPixelsPerInch.val = 96; |
| 45 |
new.ScreenPixelsPerInch.ignore = strcmpi(getEnvironment,'octave'); |
| 46 |
|
| 47 |
% MATLAB's factory values differ from their default values of a clean |
| 48 |
% MATLAB installation (observed on R2014a, Linux) |
| 49 |
new.defaultAxesColor.val = [1 1 1]; |
| 50 |
new.defaultAxesColor.ignore = false; |
| 51 |
new.defaultLineColor.val = [0 0 0]; |
| 52 |
new.defaultLineColor.ignore = false; |
| 53 |
new.defaultTextColor.val = [0 0 0]; |
| 54 |
new.defaultTextColor.ignore = false; |
| 55 |
new.defaultAxesXColor.val = [0 0 0]; |
| 56 |
new.defaultAxesXColor.ignore = false; |
| 57 |
new.defaultAxesYColor.val = [0 0 0]; |
| 58 |
new.defaultAxesYColor.ignore = false; |
| 59 |
new.defaultAxesZColor.val = [0 0 0]; |
| 60 |
new.defaultAxesZColor.ignore = false; |
| 61 |
new.defaultFigureColor.val = [0.8 0.8 0.8]; |
| 62 |
new.defaultFigureColor.ignore = false; |
| 63 |
new.defaultPatchEdgeColor.val = [0 0 0]; |
| 64 |
new.defaultPatchEdgeColor.ignore = false; |
| 65 |
new.defaultPatchFaceColor.val = [0 0 0]; |
| 66 |
new.defaultPatchFaceColor.ignore = false; |
| 67 |
new.defaultFigurePaperType.val = 'A4'; |
| 68 |
new.defaultFigurePaperType.ignore = false; |
| 69 |
new.defaultFigurePaperSize.val = [20.9840 29.6774]; |
| 70 |
new.defaultFigurePaperSize.ignore = false; |
| 71 |
new.defaultFigurePaperUnits.val = 'centimeters'; |
| 72 |
new.defaultFigurePaperUnits.ignore = false; |
| 73 |
|
| 74 |
%--- Extract relevant properties and set desired state |
| 75 |
f = fieldnames(new); % fields of new state |
| 76 |
for i = 1:length(f) |
| 77 |
% ignore property on specified environments |
| 78 |
if ~new.(f{i}).ignore |
| 79 |
val = swapPropertyState(0, f{i}, new.(f{i}).val); |
| 80 |
|
| 81 |
% store original value only, if not set by user's defaults |
| 82 |
if ~isfield(orig,f{i}) |
| 83 |
orig.(f{i}).val = val; |
| 84 |
end |
| 85 |
end |
| 86 |
end |
| 87 |
end |
| 88 |
% ========================================================================= |
| 89 |
function old = swapPropertyState(h, property, new) |
| 90 |
% read current property of graphical object |
| 91 |
% set new value, if not empty |
| 92 |
if nargin < 3, new = []; end |
| 93 |
|
| 94 |
old = get(h, property); |
| 95 |
|
| 96 |
if ~isempty(new) |
| 97 |
set(h, property, new); |
| 98 |
end |
| 99 |
end |