Changeset 10635 for issm/trunk
- Timestamp:
- 11/14/11 15:29:23 (13 years ago)
- Location:
- issm/trunk/externalpackages/export_fig
- Files:
-
- 2 added
- 1 deleted
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk/externalpackages/export_fig/export_fig.m
r9572 r10635 7 7 % export_fig filename -format1 -format2 8 8 % export_fig ... -nocrop 9 % export_fig ... -transparent 9 10 % export_fig ... -native 10 11 % export_fig ... -m<val> … … 41 42 % (the latter approximately, and ignoring cropping & magnification) in the 42 43 % output file. For transparent background (and semi-transparent patch 43 % objects), set the figure (and axes) 'Color' property to 'none'; pdf, eps 44 % and png are the only file formats to support a transparent background, 45 % whilst the png format alone supports transparency of patch objects. 44 % objects), use the -transparent option or set the figure 'Color' property 45 % to 'none'. To make axes transparent set the axes 'Color' property to 46 % 'none'. Pdf, eps and png are the only file formats to support a 47 % transparent background, whilst the png format alone supports transparency 48 % of patch objects. 46 49 % 47 50 % The choice of renderer (opengl, zbuffer or painters) has a large impact … … 78 81 % -nocrop - option indicating that the borders of the output are not to 79 82 % be cropped. 83 % -transparent - option indicating that the figure background is to be 84 % made transparent (png, pdf and eps output only). 80 85 % -m<val> - option where val indicates the factor to magnify the 81 86 % on-screen figure dimensions by when generating bitmap … … 115 120 % exists, the figure is to be appended as a new page, instead 116 121 % of being overwritten (default). 117 % handle - The handle of the figure or axes to be saved. Default: gcf. 122 % handle - The handle of the figure or axes (can be an array of handles 123 % of several axes, but these must be in the same figure) to be 124 % saved. Default: gcf. 118 125 % 119 126 %OUT: … … 127 134 % See also PRINT, SAVEAS. 128 135 129 % Copyright (C) Oliver Woodford 2008-201 0136 % Copyright (C) Oliver Woodford 2008-2011 130 137 131 138 % The idea of using ghostscript is inspired by Peder Axensten's SAVEFIG … … 153 160 [fig options] = parse_args(nargout, varargin{:}); 154 161 % Isolate the subplot, if it is one 155 cls = strcmp(get(fig , 'Type'), 'axes');162 cls = strcmp(get(fig(1), 'Type'), 'axes'); 156 163 if cls 157 % Given a handle of a single set of axes158 fig = isolate_ subplot(fig);164 % Given handles of one or more axes, so isolate them from the rest 165 fig = isolate_axes(fig); 159 166 else 160 167 old_mode = get(fig, 'InvertHardcopy'); … … 193 200 if isbitmap(options) 194 201 % Get the background colour 195 tcol = get(fig, 'Color'); 196 if isequal(tcol, 'none') && (options.png || options.alpha) 202 if options.transparent && (options.png || options.alpha) 197 203 % Get out an alpha channel 198 204 % MATLAB "feature": black colorbar axes can change to white and vice versa! … … 216 222 % Set the background colour to black, and set size in case it was 217 223 % changed internally 224 tcol = get(fig, 'Color'); 218 225 set(fig, 'Color', 'k', 'Position', pos); 219 226 % Correct the colorbar axes colours … … 223 230 B = print2array(fig, magnify, renderer); 224 231 % Downscale the image 225 B = downsize(single(B), 0,options.aa_factor);232 B = downsize(single(B), options.aa_factor); 226 233 % Set background to white (and set size) 227 234 set(fig, 'Color', 'w', 'Position', pos); … … 232 239 A = print2array(fig, magnify, renderer); 233 240 % Downscale the image 234 A = downsize(single(A), 255,options.aa_factor);241 A = downsize(single(A), options.aa_factor); 235 242 % Set the background colour (and size) back to normal 236 set(fig, 'Color', 'none', 'Position', pos);243 set(fig, 'Color', tcol, 'Position', pos); 237 244 % Compute the alpha map 238 alpha = sum(B - A, 3) / (255*3) + 1;245 alpha = round(sum(B - A, 3)) / (255 * 3) + 1; 239 246 A = alpha; 240 247 A(A==0) = 1; … … 281 288 else 282 289 % Print large version to array 283 if isequal(tcol, 'none')290 if options.transparent 284 291 % MATLAB "feature": apparently figure size can change when changing 285 292 % colour in -nodisplay mode 286 293 pos = get(fig, 'Position'); 294 tcol = get(fig, 'Color'); 287 295 set(fig, 'Color', 'w', 'Position', pos); 288 296 A = print2array(fig, magnify, renderer); 289 set(fig, 'Color', 'none', 'Position', pos);297 set(fig, 'Color', tcol, 'Position', pos); 290 298 tcol = 255; 291 299 else 292 A = print2array(fig, magnify, renderer); 293 tcol = tcol * 255; 294 if ~isequal(tcol, round(tcol)) 295 tcol = squeeze(A(1,1,:)); 296 end 300 [A tcol] = print2array(fig, magnify, renderer); 297 301 end 298 302 % Crop the background … … 301 305 end 302 306 % Downscale the image 303 A = downsize(A, tcol,options.aa_factor);307 A = downsize(A, options.aa_factor); 304 308 if options.colourspace == 2 305 309 % Convert to greyscale … … 378 382 % Generate an eps 379 383 print2eps(tmp_nam, fig, p2eArgs{:}); 384 % Remove the background, if desired 385 if options.transparent && ~isequal(get(fig, 'Color'), 'none') 386 eps_remove_background(tmp_nam); 387 end 380 388 % Generate a pdf 381 389 eps2pdf(tmp_nam, pdf_nam, 1, options.append, options.colourspace==2, options.quality); 382 catch 390 catch ex 383 391 % Delete the eps 384 392 delete(tmp_nam); 385 rethrow( lasterror);393 rethrow(ex); 386 394 end 387 395 % Delete the eps … … 391 399 % Generate an eps from the pdf 392 400 pdf2eps(pdf_nam, [options.name '.eps']); 393 catch 401 catch ex 394 402 if ~options.pdf 395 403 % Delete the pdf 396 404 delete(pdf_nam); 397 405 end 398 rethrow( lasterror);406 rethrow(ex); 399 407 end 400 408 if ~options.pdf … … 419 427 options = struct('name', 'export_fig_out', ... 420 428 'crop', true, ... 429 'transparent', false, ... 421 430 'renderer', 0, ... % 0: default, 1: OpenGL, 2: ZBuffer, 3: Painters 422 431 'pdf', false, ... … … 426 435 'jpg', false, ... 427 436 'bmp', false, ... 428 'colourspace', 0, ... % ): RGB/gray, 1: CMYK, 2: gray437 'colourspace', 0, ... % 0: RGB/gray, 1: CMYK, 2: gray 429 438 'append', false, ... 430 439 'im', nout == 1, ... 431 440 'alpha', nout == 2, ... 432 'aa_factor', 4, ...441 'aa_factor', 3, ... 433 442 'magnify', 1, ... 434 443 'quality', []); … … 437 446 % Go through the other arguments 438 447 for a = 1:nargin-1 439 if ishandle(varargin{a})448 if all(ishandle(varargin{a})) 440 449 fig = varargin{a}; 441 450 elseif ischar(varargin{a}) && ~isempty(varargin{a}) … … 444 453 case 'nocrop' 445 454 options.crop = false; 455 case {'trans', 'transparent'} 456 options.transparent = true; 446 457 case 'opengl' 447 458 options.renderer = 1; … … 489 500 end 490 501 else 491 name = varargin{a}; 492 if numel(name) > 3 && name(end-3) == '.' && any(strcmpi(name(end-2:end), {'pdf', 'eps', 'png', 'tif', 'jpg', 'bmp'})) 493 options.(lower(name(end-2:end))) = true; 494 name = name(1:end-4); 502 [p options.name ext] = fileparts(varargin{a}); 503 if ~isempty(p) 504 options.name = [p filesep options.name]; 495 505 end 496 options.name = name; 506 switch lower(ext) 507 case {'.tif', '.tiff'} 508 options.tif = true; 509 case {'.jpg', '.jpeg'} 510 options.jpg = true; 511 case '.png' 512 options.png = true; 513 case '.bmp' 514 options.bmp = true; 515 case '.eps' 516 options.eps = true; 517 case '.pdf' 518 options.pdf = true; 519 otherwise 520 options.name = varargin{a}; 521 end 497 522 end 498 523 end … … 507 532 if ~isvector(options) && ~isbitmap(options) 508 533 options.png = true; 534 end 535 536 % Check whether transparent background is wanted (old way) 537 if isequal(get(fig, 'Color'), 'none') 538 options.transparent = true; 509 539 end 510 540 … … 555 585 return 556 586 557 function fh = isolate_subplot(ah, vis) 558 % Isolate the axes in a figure on their own 559 % Tag the axes so we can find them in the copy 560 old_tag = get(ah, 'Tag'); 561 set(ah, 'Tag', 'ObjectToCopy'); 562 % Create a new figure exactly the same as the old one 563 fh = copyfig(ancestor(ah, 'figure')); %copyobj(ancestor(ah, 'figure'), 0); 564 if nargin < 2 || ~vis 565 set(fh, 'Visible', 'off'); 566 end 567 % Reset the axes tag 568 set(ah, 'Tag', old_tag); 569 % Get all the axes and gui objects 570 axs = get(fh, 'Children'); 571 % Find the objects to save 572 ah = findobj(axs, 'Tag', 'ObjectToCopy'); 573 if numel(ah) ~= 1 574 close(fh); 575 error('Too many axes found'); 576 end 577 I = true(size(axs)); 578 I(axs==ah) = false; 579 % Set the axes tag to what it should be 580 set(ah, 'Tag', old_tag); 581 % Keep any legends which overlap the subplot 582 ax_pos = get(ah, 'OuterPosition'); 583 ax_pos(3:4) = ax_pos(3:4) + ax_pos(1:2); 584 for ah = findobj(axs, 'Tag', 'legend', '-or', 'Tag', 'Colorbar')' 585 leg_pos = get(ah, 'OuterPosition'); 586 leg_pos(3:4) = leg_pos(3:4) + leg_pos(1:2); 587 % Overlap test 588 if leg_pos(1) < ax_pos(3) && leg_pos(2) < ax_pos(4) &&... 589 leg_pos(3) > ax_pos(1) && leg_pos(4) > ax_pos(2) 590 I(axs==ah) = false; 591 end 592 end 593 % Delete all axes except for the input axes and associated items 594 delete(axs(I)); 595 return 596 597 function fh = copyfig(fh) 598 % Is there a legend? 599 if isempty(findobj(fh, 'Type', 'axes', 'Tag', 'legend')) 600 % Safe to copy using copyobj 601 fh = copyobj(fh, 0); 602 else 603 % copyobj will change the figure, so save and then load it instead 604 tmp_nam = [tempname '.fig']; 605 hgsave(fh, tmp_nam); 606 fh = hgload(tmp_nam); 607 delete(tmp_nam); 608 end 609 return 610 611 function A = downsize(A, padval, factor) 587 function A = downsize(A, factor) 612 588 % Downsample an image 613 589 if factor == 1 … … 621 597 % No image processing toolbox - resize manually 622 598 % Lowpass filter - use Gaussian as is separable, so faster 623 switch factor 624 case 4 625 % sigma: 1.7 626 filt = single([0.0148395 0.0498173 0.118323 0.198829 0.236384 0.198829 0.118323 0.0498173 0.0148395]); 627 case 3 628 % sigma: 1.35 629 filt = single([0.025219 0.099418 0.226417 0.297892 0.226417 0.099418 0.025219]); 630 case 2 631 % sigma: 1.0 632 filt = single([0.054489 0.244201 0.40262 0.244201 0.054489]); 633 end 599 % Compute the 1d Gaussian filter 600 filt = (-factor-1:factor+1) / (factor * 0.6); 601 filt = exp(-filt .* filt); 602 % Normalize the filter 603 filt = single(filt / sum(filt)); 604 % Filter the image 634 605 padding = floor(numel(filt) / 2); 635 if numel(padval) == 3 && padval(1) == padval(2) && padval(2) == padval(3)636 padval = padval(1);637 end638 if numel(padval) == 1639 B = repmat(single(padval), [size(A, 1) size(A, 2)] + (2 * padding));640 end641 606 for a = 1:size(A, 3) 642 if numel(padval) == 3 643 B = repmat(single(padval(a)), [size(A, 1) size(A, 2)] + (2 * padding)); 644 end 645 B(padding+1:end-padding,padding+1:end-padding) = A(:,:,a); 646 A(:,:,a) = conv2(filt, filt', B, 'valid'); 647 end 648 clear B 607 A(:,:,a) = conv2(filt, filt', single(A([ones(1, padding) 1:end repmat(end, 1, padding)],[ones(1, padding) 1:end repmat(end, 1, padding)],a)), 'valid'); 608 end 649 609 % Subsample 650 A = A( 2:factor:end,2:factor:end,:);610 A = A(1+floor(mod(end-1, factor)/2):factor:end,1+floor(mod(end-1, factor)/2):factor:end,:); 651 611 end 652 612 return … … 719 679 end 720 680 end 721 % Crop the background 722 A = A(t:b,l:r,:); 723 v = [t b l r]; 681 % Crop the background, leaving one boundary pixel to avoid bleeding on 682 % resize 683 v = [max(t-1, 1) min(b+1, h) max(l-1, 1) min(r+1, w)]; 684 A = A(v(1):v(2),v(3):v(4),:); 685 return 686 687 function eps_remove_background(fname) 688 % Remove the background of an eps file 689 % Open the file 690 fh = fopen(fname, 'r+'); 691 if fh == -1 692 error('Not able to open file %s.', fname); 693 end 694 % Read the file line by line 695 while true 696 % Get the next line 697 l = fgets(fh); 698 if isequal(l, -1) 699 break; % Quit, no rectangle found 700 end 701 % Check if the line contains the background rectangle 702 if isequal(regexp(l, ' *0 +0 +\d+ +\d+ +rf *[\n\r]+', 'start'), 1) 703 % Set the line to whitespace and quit 704 l(1:regexp(l, '[\n\r]', 'start', 'once')-1) = ' '; 705 fseek(fh, -numel(l), 0); 706 fprintf(fh, l); 707 break; 708 end 709 end 710 % Close the file 711 fclose(fh); 724 712 return 725 713 -
issm/trunk/externalpackages/export_fig/fix_lines.m
r7182 r10635 41 41 try 42 42 fstrm = fread(fh, '*char')'; 43 catch 43 catch ex 44 44 fclose(fh); 45 rethrow( lasterror);45 rethrow(ex); 46 46 end 47 47 fclose(fh); … … 113 113 114 114 % Isolate line style definition section 115 first_sec = findstr(fstrm, '% line types:');115 first_sec = strfind(fstrm, '% line types:'); 116 116 [second_sec remaining] = strtok(fstrm(first_sec+1:end), '/'); 117 [ dummyremaining] = strtok(remaining, '%');117 [remaining remaining] = strtok(remaining, '%'); 118 118 119 119 % Define the new styles, including the new GR format … … 147 147 fprintf(fh, '%s\r', new_style{:}); 148 148 fwrite(fh, remaining, 'char*1'); 149 catch 149 catch ex 150 150 fclose(fh); 151 rethrow( lasterror);151 rethrow(ex); 152 152 end 153 153 fclose(fh); -
issm/trunk/externalpackages/export_fig/ghostscript.m
r7810 r10635 29 29 % Windows systems. 30 30 31 % 27/4/11 - Find 64-bit Ghostscript on Windows. Thanks to Paul Durack and 32 % Shaun Kline for pointing out the issue 33 34 % 4/5/11 - Thanks to David Chorlian for pointing out an alternative 35 % location for gs on linux. 36 31 37 % Call ghostscript 32 38 [varargout{1:nargout}] = system(sprintf('"%s" %s', gs_path, cmd)); … … 36 42 % Return a valid path 37 43 % Start with the currently set path 38 path = current_gs_path;44 path = user_string('ghostscript'); 39 45 % Check the path works 40 46 if check_gs_path(path) … … 43 49 % Check whether the binary is on the path 44 50 if ispc 45 bin = 'gswin32c.exe';51 bin = {'gswin32c.exe', 'gswin64c.exe'}; 46 52 else 47 bin = 'gs';53 bin = {'gs'}; 48 54 end 49 if check_store_gs_path(bin) 50 path = bin; 51 return 55 for a = 1:numel(bin) 56 path = bin{a}; 57 if check_store_gs_path(path) 58 return 59 end 52 60 end 53 61 % Search the obvious places … … 59 67 dir_list = dir(default_location); 60 68 end 61 executable = '\bin\gswin32c.exe';69 executable = {'\bin\gswin32c.exe', '\bin\gswin64c.exe'}; 62 70 ver_num = 0; 63 71 % If there are multiple versions, use the newest … … 65 73 ver_num2 = sscanf(dir_list(a).name, 'gs%g'); 66 74 if ~isempty(ver_num2) && ver_num2 > ver_num 67 path2 = [default_location dir_list(a).name executable]; 68 if exist(path2, 'file') == 2 69 path = path2; 70 ver_num = ver_num2; 75 for b = 1:numel(executable) 76 path2 = [default_location dir_list(a).name executable{b}]; 77 if exist(path2, 'file') == 2 78 path = path2; 79 ver_num = ver_num2; 80 end 71 81 end 72 82 end 73 83 end 84 if check_store_gs_path(path) 85 return 86 end 74 87 else 75 path = '/usr/local/bin/gs'; 76 end 77 if check_store_gs_path(path) 78 return 88 bin = {'/usr/bin/gs', '/usr/local/bin/gs'}; 89 for a = 1:numel(bin) 90 path = bin{a}; 91 if check_store_gs_path(path) 92 return 93 end 94 end 79 95 end 80 96 % Ask the user to enter the path … … 93 109 bin_dir = {'', ['bin' filesep], ['lib' filesep]}; 94 110 for a = 1:numel(bin_dir) 95 path = [base bin_dir{a} bin]; 96 if exist(path, 'file') == 2 97 break; 111 for b = 1:numel(bin) 112 path = [base bin_dir{a} bin{b}]; 113 if exist(path, 'file') == 2 114 if check_store_gs_path(path) 115 return 116 end 117 end 98 118 end 99 119 end 100 if check_store_gs_path(path)101 return102 end103 120 end 104 error('Ghostscript not found. ');121 error('Ghostscript not found. Have you installed it from www.ghostscript.com?'); 105 122 106 123 function good = check_store_gs_path(path) … … 111 128 end 112 129 % Update the current default path to the path found 113 if change_value(path, 'current_gs_path_str', [mfilename('fullpath') '.m'])114 warning('Path to ghostscript installation could not be saved. Enter it manually in ghostscript. m.');130 if ~user_string('ghostscript', path) 131 warning('Path to ghostscript installation could not be saved. Enter it manually in ghostscript.txt.'); 115 132 return 116 133 end … … 122 139 good = good == 0; 123 140 return 124 125 function current_gs_path_str = current_gs_path126 current_gs_path_str = 'gs';127 return -
issm/trunk/externalpackages/export_fig/license.txt
r7182 r10635 1 Copyright (c) 20 010, Oliver Woodford1 Copyright (c) 2011, Oliver Woodford 2 2 All rights reserved. 3 3 -
issm/trunk/externalpackages/export_fig/pdftops.m
r7182 r10635 36 36 % Return a valid path 37 37 % Start with the currently set path 38 path = current_xpdf_path;38 path = user_string('pdftops'); 39 39 % Check the path works 40 40 if check_xpdf_path(path) … … 93 93 end 94 94 % Update the current default path to the path found 95 if change_value(path, 'current_xpdf_path_str', [mfilename('fullpath') '.m'])96 warning('Path to pdftops executable could not be saved. Enter it manually in pdftops. m.');95 if ~user_string('pdftops', path) 96 warning('Path to pdftops executable could not be saved. Enter it manually in pdftops.txt.'); 97 97 return 98 98 end … … 106 106 good = ~isempty(strfind(message, 'PostScript')); 107 107 return 108 109 function current_xpdf_path_str = current_xpdf_path110 current_xpdf_path_str = 'C:\Program Files\xpdf-3.02pl4-win32\pdftops.exe';111 return -
issm/trunk/externalpackages/export_fig/print2array.m
r7182 r10635 6 6 % A = print2array(figure_handle, resolution) 7 7 % A = print2array(figure_handle, resolution, renderer) 8 % [A bcol] = print2array(...) 8 9 % 9 10 % This function outputs a bitmap image of the given figure, at the desired … … 22 23 % OUT: 23 24 % A - MxNx3 uint8 image of the figure. 25 % bcol - 1x3 uint8 vector of the background color 24 26 25 % Copyright (C) Oliver Woodford 2008-201 027 % Copyright (C) Oliver Woodford 2008-2011 26 28 27 function A = print2array(fig, res, renderer) 29 % 5/9/2011 Set EraseModes to normal when using opengl or zbuffer renderers. 30 % Thanks to Pawel Kocieniewski for reporting the issue. 31 32 % 21/9/2011 Bug fix: unit8 -> uint8! 33 % Thanks to Tobias Lamour for reporting the issue. 34 35 % 14/11/2011 Bug fix: stop using hardcopy(), as it interfered with figure 36 % size and erasemode settings. Makes it a bit slower, but more reliable. 37 % Thanks to Phil Trinh and Meelis Lootus for reporting the issues. 38 39 function [A bcol] = print2array(fig, res, renderer) 28 40 % Generate default input arguments, if needed 29 41 if nargin < 2 … … 38 50 px = get(fig, 'Position'); 39 51 set(fig, 'Units', old_mode); 40 px = prod(px(3:4)*res)/1e6;41 if px > 3052 npx = prod(px(3:4)*res)/1e6; 53 if npx > 30 42 54 % 30M pixels or larger! 43 warning('MATLAB:LargeImage', 'print2array generating a %.1fM pixel image. This could be slow and might also cause memory problems.', px);55 warning('MATLAB:LargeImage', 'print2array generating a %.1fM pixel image. This could be slow and might also cause memory problems.', npx); 44 56 end 57 % Retrieve the background colour 58 bcol = get(fig, 'Color'); 45 59 % Set the resolution parameter 46 res = ['-r' num2str(ceil(get(0, 'ScreenPixelsPerInch')*res))];60 res_str = ['-r' num2str(ceil(get(0, 'ScreenPixelsPerInch')*res))]; 47 61 % Generate temporary file name 48 62 tmp_nam = [tempname '.tif']; … … 53 67 try 54 68 % Export to tiff using ghostscript 55 ghostscript(['-dEPSCrop -q -dNOPAUSE -dBATCH ' res ' -sDEVICE=tiff24nc -sOutputFile="' tmp_nam '" "' tmp_eps '"']);69 ghostscript(['-dEPSCrop -q -dNOPAUSE -dBATCH ' res_str ' -sDEVICE=tiff24nc -sOutputFile="' tmp_nam '" "' tmp_eps '"']); 56 70 catch 57 71 % Delete the intermediate file … … 65 79 % Delete the temporary bitmap file 66 80 delete(tmp_nam); 67 % Retrieve the background colour68 bcol = get(fig, 'Color');69 81 % Set border pixels to the correct colour 70 if ~isequal(bcol, 'none') && ~isequal(bcol, [1 1 1]) 82 if isequal(bcol, 'none') 83 bcol = []; 84 elseif isequal(bcol, [1 1 1]) 85 bcol = uint8([255 255 255]); 86 else 71 87 for l = 1:size(A, 2) 72 88 if ~all(reshape(A(:,l,:) == 255, [], 1)) … … 89 105 end 90 106 end 91 bcol = round(bcol * 255);107 bcol = median([reshape(A(:,[l r],:), [], size(A, 3)); reshape(A(:,[t b],:), [], size(A, 3))], 1); 92 108 for c = 1:size(A, 3) 93 109 A(:,[1:l-1, r+1:end],c) = bcol(c); … … 99 115 renderer = '-opengl'; 100 116 end 117 err = false; 101 118 % Set paper size 102 119 old_mode = get(fig, 'PaperPositionMode'); 103 120 set(fig, 'PaperPositionMode', 'auto'); 104 121 try 105 % Try hardcopy first - undocumented MATLAB function!106 A = hardcopy(fig, ['-D' renderer(2:end)], res);107 catch108 122 % Print to tiff file 109 print(fig, renderer, res , '-dtiff', tmp_nam);123 print(fig, renderer, res_str, '-dtiff', tmp_nam); 110 124 % Read in the printed file 111 125 A = imread(tmp_nam); 112 126 % Delete the temporary file 113 127 delete(tmp_nam); 128 catch ex 129 err = true; 114 130 end 115 131 % Reset paper size 116 132 set(fig, 'PaperPositionMode', old_mode); 133 % Throw any error that occurred 134 if err 135 rethrow(ex); 136 end 137 % Set the background color 138 if isequal(bcol, 'none') 139 bcol = []; 140 else 141 bcol = bcol * 255; 142 if isequal(bcol, round(bcol)) 143 bcol = uint8(bcol); 144 else 145 bcol = squeeze(A(1,1,:)); 146 end 147 end 148 end 149 % Check the output size is correct 150 if isequal(res, round(res)) 151 px = [px([4 3])*res 3]; 152 if ~isequal(size(A), px) 153 % Correct the output size 154 A = A(1:min(end,px(1)),1:min(end,px(2)),:); 155 end 117 156 end 118 157 return -
issm/trunk/externalpackages/export_fig/print2eps.m
r7182 r10635 18 18 % options - Additional parameter strings to be passed to print. 19 19 20 % Copyright (C) Oliver Woodford 2008-20 0920 % Copyright (C) Oliver Woodford 2008-2011 21 21 22 22 % The idea of editing the EPS file to change line styles comes from Jiro … … 24 24 % The idea of changing dash length with line width came from comments on 25 25 % fex id: 5743, but the implementation is mine :) 26 27 % 14/11/2011 Fix a MATLAB bug rendering black or white text incorrectly. 28 % Thanks to Mathieu Morlighem for reporting the issue and obtaining a fix 29 % from TMW. 26 30 27 31 function print2eps(name, fig, varargin) … … 39 43 old_mode = get(fig, 'PaperPositionMode'); 40 44 set(fig, 'PaperPositionMode', 'auto'); 45 % MATLAB bug fix - black and white text can come out inverted sometimes 46 % Find the white and black text 47 white_text_handles = findobj(fig, 'Type', 'text'); 48 M = get(white_text_handles, 'Color'); 49 if iscell(M) 50 M = cell2mat(M); 51 end 52 M = sum(M, 2); 53 black_text_handles = white_text_handles(M == 0); 54 white_text_handles = white_text_handles(M == 3); 55 % Set the font colors slightly off their correct values 56 set(black_text_handles, 'Color', [0 0 0] + eps); 57 set(white_text_handles, 'Color', [1 1 1] - eps); 41 58 % Print to eps file 42 59 print(fig, options{:}, name); 60 % Reset the font colors 61 set(black_text_handles, 'Color', [0 0 0]); 62 set(white_text_handles, 'Color', [1 1 1]); 43 63 % Reset paper size 44 64 set(fig, 'PaperPositionMode', old_mode); … … 47 67 fix_lines(name); 48 68 catch 49 warning('fix_lines failed. This is usually because the figure contains a large number of patch objects. Consider exporting to a bitmap format in this case.');69 warning('fix_lines() failed. This is usually because the figure contains a large number of patch objects. Consider exporting to a bitmap format in this case.'); 50 70 end 51 71 return
Note:
See TracChangeset
for help on using the changeset viewer.