forked from rozenasf/Matlab2Powerpoint
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdate_Single_Powerpoint_Figure.m
More file actions
51 lines (44 loc) · 2.11 KB
/
Update_Single_Powerpoint_Figure.m
File metadata and controls
51 lines (44 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
function Update_Single_Powerpoint_Figure(fig_number)
FigureNumber=fig_number;
% resolution='300';
mresolution='2';
SizeFactor=2;
Path = [pwd,'\'];
handles=findall(0,'type','figure');
ind = find([handles.Number] == FigureNumber);
if(isempty(ind)); return ;end
figure_handle = handles(ind);
if(isfield(figure_handle.UserData,'Scale'))
SizeFactor=figure_handle.UserData.Scale;
end
% figure_handle.Position
[MatlabPPT] = RefreshPPT();
Objs = Obj_From_Placeholder(['figure',num2str(FigureNumber)],MatlabPPT);
if(isempty(Objs));return;end
for i=1:numel(Objs)
Obj=Objs{i};
%Change only hight
% new_height = Obj.Height./Obj.Width * figure_handle.Position(3);
% figure_handle.Position(2) = figure_handle.Position(2) - (new_height - figure_handle.Position(4));
% figure_handle.Position(4) = new_height;
%change both hight and width
new_height = Obj.Height*SizeFactor;
new_width = Obj.Width*SizeFactor;
figure_handle.Position(2) = figure_handle.Position(2) - (new_height - figure_handle.Position(4));
figure_handle.Position(1) = figure_handle.Position(1) - (new_width - figure_handle.Position(3));
figure_handle.Position(4) = new_height;
figure_handle.Position(3) = new_width;
drawnow;
if(abs(figure_handle.Position(3)-new_width)>1e-3 || abs(figure_handle.Position(4)-new_height)>1e-3)
warning('The figure scaled is too small\large. change scaling by: Fx=gcf;Fx.UserData.Scale=#');
end
Ax = figure_handle.CurrentAxes;
Backup_color = get(Ax,'color');
set(Ax,'color','none');
% export_fig(figure_handle,[Path,'temp.png'],'-dpng',['-r',resolution],'-transparent');
export_fig(figure_handle,[Path,'temp.png'],'-nocrop','-dpng',['-m',mresolution],'-transparent');
set(Ax,'color',Backup_color);
% print(figure_handle,[Path,'temp.jpg'],'-dpng',['-r',resolution]);
ReplaceImage(Obj,[Path,'temp.png']);
end
end