% Installer: "stext_install.m" % Created: 04-Oct-2001 15:52:58. function bund_driver % bund_driver -- Driver for "bund" bundles. % bund_driver (no arguments) contains Matlab commands % to inflate the instructions and files that are % encoded into the "bund_data" function of this package. % Copyright (C) 2001 Dr. Charles R. Denham, ZYDECO. % All Rights Reserved. % Disclosure without explicit written consent from the % copyright owner does not constitute publication. % Version of 14-Jun-2001 10:54:16. % Updated 03-Aug-2001 13:43:17. help(mfilename) BINARY_TAG = '?'; CR = char(13); LF = char(10); comp = upper(computer); if any(findstr(comp, 'PCWIN')) % Windows. NL = [CR LF]; elseif any(findstr(comp, 'MAC2')) % Macintosh. NL = CR; else % Unix. NL = LF; end c = zeros(1, 256); c(abs('0'):abs('9')) = 0:9; c(abs('a'):abs('f')) = 10:15; disp([' ']) disp([' ## This installer is ready to expand its contents,']) disp([' ## starting in the present directory: "' pwd '"']) disp([' ## To abort, execute an interruption now.']) disp([' ## Otherwise, to continue, press any key.']) disp([' ']) try pause catch disp([' ## Installation interrupted.']) disp([' ']) return end tic w = which(mfilename); fin = fopen(w, 'r'); if fin < 0, return, end found = ~~0; while ~found s = fgetl(fin); if isequal(s, -1) fclose(fin); return end s = strrep(s, LF, ''); % Not necessary? s = strrep(s, CR, ''); % Not necessary? if isequal(s, 'function bund_data') found = ~~1; end end fout = -1; done = ~~0; while ~done s = fgetl(fin); if isequal(s, -1) fclose(fin); return end if length(s) > 0 if s(1) ~= '%' f = findstr(s, 'bund_setdir'); if any(f) theDir = eval(strrep(s, 'bund_setdir', '')); status = mkdir(theDir); switch status case 1 disp([' ## Directory created: "' theDir '"']) case 2 disp([' ## Directory exists: "' theDir '"']) otherwise error([' ## Error while making new directory.']) end try cd(theDir) catch error([' ## Unable to go to directory: "' theDir '"']) end else try eval(s); catch error([' ## Unable to evaluate: "' s '"']) end end elseif length(s) > 1 & s(2) == BINARY_TAG hx = double(s(3:end)); % Assume hex data. bin = 16*c(hx(1:2:end)) + c(hx(2:2:end)); fwrite(fout, bin, 'uchar'); else fprintf(fout, '%s', s(2:end)); fprintf(fout, NL); end end end fclose(fin); disp([' ## Elapsed time: ' num2str(fix(10*toc)/10) ' s.']) function bund_data bund_setdir('stext') disp(' ## Installing: "changes.txt" (text)') fout = fopen('changes.txt', 'w'); %Styled Text Toolbox %Version 3.1, 10 June 1996 %Copyright 1995-1996 by Douglas M. Schwarz. All rights reserved. %schwarz@kodak.com % % %Changes in Version 3.2 % % %1. MATLAB 5 Compatibility % %The Styled Text Toolbox is now compatible with both MATLAB 5 and MATLAB 4. %Even though MATLAB 5 has a built-in capability which is similar, I have %chosen to continue development of my toolbox as it has several features %not included in the built-in functions: % %* FontSize and Color can be changed mid-string %* Simulated italic (slanted) Greek letters possible %* Additional characters available %* Diacritics above any character %* Fractions, roots, summations and products %* Kerned output using kern pairs from Adobe Font Metric files %* Styled text text boxes %* Fine adjustment of character positions possible % %The same m-files should work in both versions of MATLAB and on any platform %except for the stfm.mat file (which is created the first time stext is run) %which contains some platform-specific information. % % %2. STFIXPS fixed % %STFIXPS did not work properly in some situations involving rotated or %colored text. This has been fixed. Also, the new version is somewhat %faster than the old one. For even greater speed, I am distibuting a MEX %version contributed by Erik Johnson (source and Macintosh binaries). %Thank-you Erik! % % %3. Simulated Symbol-Bold % %Bold Symbol characters are now produced by placing multiple, slightly %shifted copies of the character (sort of a "poor man's bold"). This is %because there is no bold version of the Symbol font. % % %4. New commands % %I have changed the definition of \slash. Previously, it just produced %a slash symbol. Now it takes two arguments and can be used to make %nice fractions with a slightly raised numerator and with both numerator %and denominator somewhat smaller than normal. For example, \slash{1}{2} %makes a nice version of 1/2. I have also added the command \parallel %which is the same as \Vert. % % %5. New version of stfm.txt. % %The font metrics file has changed again, slightly. I have added some %data which will improve the VerticalAlignment. Be sure to delete the %old stfm.mat file before using this new version. % % %6. New function % %I am including an m-file version of strncmp for use with MATLAB 4. I %needed the built-in strncmp in MATLAB 5 and to make the same m-file %work in version 4 I had to provide this function. % % % %Changes in Version 3.1 % % %1. Bug Fixes % %I fixed several bugs which could leave the screen in a messy state if an %error was made in specifying the styled text. Also, on some platforms there %was the possibility of a visible extra character when italic Symbol font was %used. This character has a special purpose and it has been replaced with %one that does not show up on screen. Several other minor bugs have been %eliminated. % % %2. SLEGEND and STEXTBOX modified % %Based on some user feedback, I have modified SLEGEND and STEXTBOX so that %some of the internal parameters can be changed without modifying the %m-files. It is now possible to specify property/value pairs just like with %other objects. I have also improved the method for calculating the line %spacing. % % %3. Font metrics % %The font metric information is now contained in a single text file for all %platforms: stfm.txt. This one file now has the character widths and %kerning data for all of the supported PostScript fonts. It also contains %the three Roman font encoding vectors I know about: MacEncoding, %WindowsLatin1Encoding (new), and ISOLatin1Encoding. Previously, I had been %led to believe that the encoding used by Windows was a superset of %ISOLatin1Encoding, but I have recently learned that this is not quite the %case. As a result, Windows users would not have been able to use accents %correctly. This new encoding vector fixes this except that the accents %\breve, \dot and \check and the \ii character (dotless i) are not included %in the encoding and cannot be used. If any other encoding vectors are %discovered to be in use the new system will allow them to be added and used %fairly easily; contact me for details. % % %4. New function readstfm and new procedure for saving stfm.mat % %The procedure for extracting the font metric information and encodings from %stfm.txt is complicated enough that I put it in a separate m-file. This %function is called by stext the first time stext is run. The font metrics %are then saved in a MAT-file (stfm.mat) for quicker access in the future. %If you don't have write permission in the stextfun directory then the file %is saved in the current directory and a message is displayed suggesting %that you have your system administrator move that file to the stextfun %directory. % % % % %Changes in Version 3.0 % % %1. Command Parsing % %Parsing of commands is more robust and more LaTeX-like. There are now three %categories of commands: those with all letters (e.g., \alpha), those with %all numbers (e.g., \12) and those consisting of a single special character %(e.g., \+). Commands are terminated by any character that can be determined %not to be part of the command itself. If the next character is in the same %category as the command characters then a single space should be inserted as %the termination character. This space will not appear in the output. %Examples: % %'\alpha a' will produce no space between the alpha and the a. The space is %necessary to terminate the \alpha command, but it gets swallowed. Another %way to achieve the same result is with '\alpha{}a'. % %'\alpha a' will produce a single space between the alpha and the a. The %first space gets swallowed as above, but the second one will appear. Another %way to get the same result is with '\alpha\ a', where the '\ ' is a standard %space command. % %'\alpha1' will be parsed without error and there will be no space between %the alpha and the 1. Of course, this can also be done with '\alpha{}1'. % %'\alpha 1' will have a single space between the alpha and the 1. % %'\+=' will be parsed without error and there will be no space between the %'+' (which will be made with the Symbol font) and the '=' (in the current %font). % % %2. Commands with two arguments % %Commands with two arguments have a different syntax. Previously you would %use '\int{a,b}' to make an integral with lower limit 'a' and upper limit %'b'. The new syntax is '\int{a}{b}'. Commands affected: \int, \sum, \prod. % % %3. New commands % %\frac{x}{y} to make the fraction x over y % %\sqrt{x} to make square root of x % %\root{n}{x} to make nth root of x % %\AA to make angstrom symbol ('A' with little circle above it) % %\ii to make a dotless 'i' % %\pushx will push the current x-position onto a stack % %\popx will pop the stack so the next character position will revert to a % previous location % %\swapx will swap the top two stack items % %ASCII codes can be inserted with the \# command, e.g., 'a\#{65}b' is %identical to 'a{}Ab' since the ASCII code for 'A' is 65 (decimal). % %'\/' italic correction %'\,' thin space %'\:' medium space %'\;' thick space %'\ ' word space % % %4. New functions % %slegend - Styled text legends. %stextbox - Styled text multi-line box. %stfixps - Modifies PS files to simulate Symbol-Oblique font. %spreview - GUI application to help build styled text objects. % % %5. Font metrics % %The font metric information is now distributed as text files eliminating the %need to download them in binary mode. The first time stext is run they are %loaded in and then saved as MAT-files for quicker access in the future. % % %6. Rotation % %Rotation of styled text is no longer restricted to integral multiples of 90 %degrees. % % %7. Printing % %The printsto function has been upgraded to handle axes with a fixed aspect %ratio (such as result from "axis square"). fclose(fout); disp(' ## Installing: "cmdmatch.m" (text)') fout = fopen('cmdmatch.m', 'w'); %function m = cmdmatch(a,b) %%CMDMATCH String matching. %% CMDMATCH(A,B) returns 1 if B matches the first length(B) characters %% of A and 0 otherwise. % %% Version 3.2b, 10 March 1997 %% Part of the Styled Text Toolbox %% Copyright 1995-1997 by Douglas M. Schwarz. All rights reserved. %% schwarz@kodak.com % %nb = length(b); % %if length(a) >= nb % m = all(a(1:nb) == b); %else % m = 0; %end fclose(fout); disp(' ## Installing: "Contents.m" (text)') fout = fopen('Contents.m', 'w'); %% Styled Text Toolbox. %% Version 3.2b, 10 March 1997 %% %% General. %% stext - Add styled text to the current plot. %% setstext - Set styled text object properties. %% getstext - Get styled text object properties. %% delstext - Delete a styled text object. %% fixstext - Fix position of styled text objects. %% printsto - Print or save graph containing styled text objects. %% stitle - Styled text plot titles. %% sxlabel - X-axis styled text labels. %% sylabel - Y-axis styled text labels. %% szlabel - Z-axis styled text labels for 3-D plots. %% slegend - Styled text legends. %% stextbox - Styled text multi-line box. %% stfixps - Modifies PS files to simulate Symbol-Oblique font. %% addlatin - UNIX script to add ISOLatin1Encoding to PostScript files. %% %% Demo. %% stodemo - Demonstrates some of the capabilities of stext. %% spreview - GUI application to help build styled text objects. %% %% Utility functions (used internally). %% cmdmatch - String matching for commands. %% move1sto - Move one styled text object. %% getcargs - Get command arguments. %% readstfm - Read styled text font metrics data file. %% strncmp - String comparison, used only in MATLAB 4. %% %% Font Metric data. %% stfm.txt - Font metric and encoding information. % %% Copyright 1995-1997 by Douglas M. Schwarz. %% schwarz@kodak.com fclose(fout); disp(' ## Installing: "delstext.m" (text)') fout = fopen('delstext.m', 'w'); %function delstext(hh) %%DELSTEXT Delete styled text objects. %% DELSTEXT(H) deletes the styled text object with handle H. Nothing %% is deleted if H is not a valid handle to a styled text object. H %% can also be a vector of handles. %% %% See also STEXT. % %% Requires function CMDMATCH. %% Requires MATLAB Version 4.2 or greater. % %% Version 3.2b, 10 March 1997 %% Part of the Styled Text Toolbox %% Copyright 1995-1997 by Douglas M. Schwarz. All rights reserved. %% schwarz@kodak.com % %for h = hh(:)' % % First, check to see if value is a valid handle. % if eval('isstr(get(h,''Type''))','0') % % Check to see if handle is a styled text object. % if cmdmatch(get(h,'Tag'),'stext') % % Get handles to text objects and delete them. % userData = get(h,'UserData'); % objList = userData(4:length(userData)); % delete(objList) % delete(h) % end % end %end fclose(fout); disp(' ## Installing: "fixstext.m" (text)') fout = fopen('fixstext.m', 'w'); %function fixstext %%FIXSTEXT Reposition styled text objects after axes modification. %% FIXSTEXT repositions all styled text objects in the current figure. %% %% See also STEXT, SXLABEL, SYLABEL, SZLABEL, STITLE, DELSTEXT, %% PRINTSTO, SETSTEXT. % %% Requires function MOVE1STO. %% Requires MATLAB Version 4.2 or greater. % %% Version 3.2b, 10 March 1997 %% Part of the Styled Text Toolbox %% Copyright 1995-1997 by Douglas M. Schwarz. All rights reserved. %% schwarz@kodak.com % %% Determine current figure and axes. %fig = get(0,'CurrentFigure'); %figUnits = get(fig,'Units'); %set(fig,'Units','points') %figPosPts = get(fig,'Position'); %set(fig,'Units',figUnits) %ax = get(fig,'CurrentAxes'); % %% Find all stext objects. %anchors = findobj(fig,'Tag','stext'); %n = length(anchors); % %% Adjust each stext object. %for i = 1:n % move1sto(anchors(i)) %end % % %% Adjust title. %stitleH = findobj(fig,'Tag','stext title'); %n = length(stitleH); %for i = 1:n % move1sto(stitleH(i)) %end % % %% Fix all styled text labels by regenerating them. %xlabelH = findobj(fig,'Tag','stext xlabel'); %n = length(xlabelH); %for i = 1:n % set(fig,'CurrentAxes',get(xlabelH(i),'Parent')) % str = get(xlabelH(i),'String'); % sxlabel(str) %end % %ylabelH = findobj(fig,'Tag','stext ylabel'); %n = length(ylabelH); %for i = 1:n % set(fig,'CurrentAxes',get(ylabelH(i),'Parent')) % str = get(ylabelH(i),'String'); % sylabel(str) %end % %zlabelH = findobj(fig,'Tag','stext zlabel'); %n = length(zlabelH); %for i = 1:n % set(fig,'CurrentAxes',get(zlabelH(i),'Parent')) % str = get(zlabelH(i),'String'); % szlabel(str) %end % % %% Find all slegend and stextbox objects. %legends = [findobj(fig,'Tag','slegend');... % findobj(fig,'Tag','slegend movable')]; %nleg = length(legends); % %% Shift the legends so they will print correctly. %for i = 1:nleg % newPos = get(legends(i),'Position'); % origLegPos = newPos; % userData = get(legends(i),'UserData'); % xy = userData(1:2); % ref = userData(3:4); % newPos(1:2) = figPosPts(3:4).*xy - ref.*origLegPos(3:4); % set(legends(i),'Position',newPos) %end % % %% Return to original current axes. %set(fig,'CurrentAxes',ax) fclose(fout); disp(' ## Installing: "getcargs.m" (text)') fout = fopen('getcargs.m', 'w'); %function [arg,str] = getcargs(str) %%GETCARGS Get arguments for stext commands. %% [ARG,STROUT] = GETCARGS(STR) parses STR to extract a part enclosed %% in curly braces and the remainder of the string. %% Example: %% >>STR = '{hello}there' %% >>[A,STROUT] = GETCARGS(STR) %% A = %% hello %% STROUT = %% there %% %% See also STEXT. % %% Version 3.2b, 10 March 1997 %% Part of the Styled Text Toolbox %% Copyright 1995-1997 by Douglas M. Schwarz. All rights reserved. %% schwarz@kodak.com % %i = cumsum( (str == '{') - (str == '}') ); %if i(1) ~= 1 | ~any(i == 0) % error('Command argument not found.') %end %firstZero = min(find(i == 0)); %arg = str(2:(firstZero - 1)); %str(1:firstZero) = []; fclose(fout); disp(' ## Installing: "getstext.m" (text)') fout = fopen('getstext.m', 'w'); %function value = getstext(anchor,property) %%GETSTEXT Get property values for styled text objects. %% GETSTEXT(H,PROPERTY) returns the value of the named property for the %% styled text object with handle H. %% %% GETSTEXT(H) displays all property names and values for the styled %% text object with handle H. %% %% See also STEXT, GET. % %% Requires function CMDMATCH. %% Requires MATLAB Version 4.2 or greater. % %% Version 3.2b, 10 March 1997 %% Part of the Styled Text Toolbox %% Copyright 1995-1997 by Douglas M. Schwarz. All rights reserved. %% schwarz@kodak.com % %if ~cmdmatch(get(anchor,'Tag'),'stext') % error('Not a styled text object.') %end % %if nargin == 2 % property = lower(property); % % if cmdmatch('color',property) % error('Invalid object property.') % % elseif cmdmatch('fontangle',property) % error('Invalid object property.') % % elseif cmdmatch('fontname',property) % error('Invalid object property.') % % elseif cmdmatch('fontsize',property) % error('Invalid object property.') % % elseif cmdmatch('fontweight',property) % error('Invalid object property.') % % elseif cmdmatch('visible',property) % objList = get(anchor,'UserData'); % value = get(objList(4),'Visible'); % % elseif cmdmatch('extent',property) % objList = get(anchor,'UserData'); % objList(1:3) = []; % numObjects = length(objList); % extents = zeros(numObjects,4); % anchorUnits = get(anchor,'Units'); % for i = 1:numObjects % objUnits = get(objList(i),'Units'); % objPos = get(objList(i),'Position'); % set(objList(i),'Units',anchorUnits) % extents(i,:) = get(objList(i),'Extent'); % set(objList(i),'Units',objUnits,'Position',objPos) % end % lbrt = [extents(:,1:2),extents(:,1:2) + extents(:,3:4)]; % lbrtAll = [min(lbrt(:,1)),min(lbrt(:,2)),max(lbrt(:,3)),max(lbrt(:,4))]; % value = [lbrtAll(1:2),lbrtAll(3:4) - lbrtAll(1:2)]; % % else % value = get(anchor,property); % end %else % fprintf(1,'\tEraseMode = %s\n',get(anchor,'EraseMode')) % fprintf(1,'\tExtent = [%g %g %g %g]\n',getstext(anchor,'Extent')) % fprintf(1,'\tHorizontalAlignment = %s\n',get(anchor,'HorizontalAlignment')) % fprintf(1,'\tPosition = [%g %g %g]\n',get(anchor,'Position')) % fprintf(1,'\tRotation = [%g]\n',get(anchor,'Rotation')) % fprintf(1,'\tString = %s\n',get(anchor,'String')) % fprintf(1,'\tUnits = %s\n',get(anchor,'Units')) % fprintf(1,'\tVerticalAlignment = %s\n',get(anchor,'VerticalAlignment')) % fprintf(1,'\n') % fprintf(1,'\tButtonDownFcn = %s\n',get(anchor,'ButtonDownFcn')) % fprintf(1,'\tChildren = []\n') % fprintf(1,'\tClipping = %s\n',get(anchor,'Clipping')) % fprintf(1,'\tInterruptible = %s\n',get(anchor,'Interruptible')) % fprintf(1,'\tParent = [%g]\n',get(anchor,'Parent')) % objList = get(anchor,'UserData'); % fprintf(1,'\tVisible = %s\n',get(objList(4),'Visible')) %end fclose(fout); disp(' ## Installing: "move1sto.m" (text)') fout = fopen('move1sto.m', 'w'); %function move1sto(anchor,delta) %%MOVE1STO Move one styled text object. %% MOVE1STO(H,DXY) moves the styled text object H by DXY(1) and DXY(2) %% points in the X and Y directions respectively. %% %% MOVE1STO(H) moves the styled text object H to its correct location. % %% Version 3.2b, 10 March 1997 %% Part of the Styled Text Toolbox %% Copyright 1995-1997 by Douglas M. Schwarz. All rights reserved. %% schwarz@kodak.com % %userData = get(anchor,'UserData'); %objList = userData(4:length(userData)); % %% Determine correct location based on location of anchor. %if nargin == 1 % anchorUnits = get(anchor,'Units'); % anchorPos = get(anchor,'Position'); % x0 = userData(2); % y0 = userData(3); % % set(anchor,'Units','points') % newPos = get(anchor,'Position'); % x1 = newPos(1); % y1 = newPos(2); % delta = [x1 - x0,y1 - y0]; % userData(2) = x1; % userData(3) = y1; % set(anchor,'Units',anchorUnits,'Position',anchorPos,... % 'UserData',userData,'Visible','off') %end % %% Set new positions. %for obj = objList % set(obj,'Units','points') % pos = get(obj,'Position'); % pos(1:length(delta)) = pos(1:length(delta)) + delta; % set(obj,'Position',pos) %end fclose(fout); disp(' ## Installing: "printsto.m" (text)') fout = fopen('printsto.m', 'w'); %function printsto(arg1,arg2,arg3,arg4,arg5) %%PRINTSTO Print or save graph containing styled text objects. %% PRINTSTO has exactly the same syntax as PRINT. It is required for %% printing or saving figures which contain styled text objects. %% %% See also PRINT, STEXT, SXLABEL, SYLABEL, SZLABEL, STITLE, SLEGEND, %% STEXTBOX, DELSTEXT, SETSTEXT, FIXSTEXT. % %% Requires function MOVE1STO. %% Requires MATLAB Version 4.2 or greater. % %% Version 3.2b, 10 March 1997 %% Part of the Styled Text Toolbox %% Copyright 1995-1997 by Douglas M. Schwarz. All rights reserved. %% schwarz@kodak.com % %% Check arguments. %if nargin > 5 % error('Too many input arguments.') %end % %% Determine which figure we want. %curFig = gcf; %curAxes = get(curFig,'CurrentAxes'); %thisFig = curFig; %for i = 1:nargin % arg = eval(sprintf('arg%d',i)); % [tempFig,count] = sscanf(arg,'-f%d'); % if count % thisFig = tempFig; % break % end %end %thisAxes = get(thisFig,'CurrentAxes'); % %% Compute magnification in X and Y directions for each axes. %% Fudge factors of 1.00217 and 1.00333 were determined by trial and error. %axesList = findobj(thisFig,'Type','axes'); %allAnchors = []; %allDeltas = []; %allLabelAnchors = []; %allLabelDeltas = []; % %paperUnits = get(thisFig,'PaperUnits'); %paperPosOrig = get(thisFig,'PaperPosition'); %set(thisFig,'PaperUnits','points') %paperPos = get(thisFig,'PaperPosition'); %set(thisFig,'PaperUnits',paperUnits,'PaperPosition',paperPosOrig) %ver5 = cmdmatch(version,'5'); % %for thisAxes = axesList' % if ver5 % if strcmp(get(thisAxes,'PlotBoxAspectRatioMode'),'auto') & ... % strcmp(get(thisAxes,'DataAspectRatioMode'),'auto') & ... % strcmp(get(thisAxes,'CameraViewAngleMode'),'auto') % aspect = nan; % else % aspect = get(thisAxes,'PlotBoxAspectRatio'); % aspect = aspect(1)/aspect(2); % end % else % aspect = get(thisAxes,'AspectRatio'); % aspect = aspect(1); % end % % % Compute magnification factors. % axUnits = get(thisAxes,'Units'); % axPosOrig = get(thisAxes,'Position'); % set(thisAxes,'Units','points'); % axPos = get(thisAxes,'Position'); % set(thisAxes,'Units',axUnits,'Position',axPosOrig) % ws = axPos(3); % hs = axPos(4); % if strcmp(axUnits,'normalized') % axPosNorm = get(thisAxes,'Position'); % wp = paperPos(3)*axPosNorm(3); % hp = paperPos(4)*axPosNorm(4); % if ~isnan(aspect) % if aspect > ws/hs % hs = ws/aspect; % else % ws = hs*aspect; % end % if aspect > wp/hp % hp = wp/aspect; % else % wp = hp*aspect; % end % end % magX = 1.00217*wp/ws; % magY = 1.00333*hp/hs; % else % magX = 1; % magY = 1; % end % % % Find all plain and title stext objects defined in relative units. % anchors = [findobj(thisAxes,'Tag','stext','Units','normalized');... % findobj(thisAxes,'Tag','stext','Units','data');... % findobj(thisAxes,'Tag','stext title','Units','normalized');... % findobj(thisAxes,'Tag','stext title','Units','data')]; % n = length(anchors); % delta = zeros(n,2); % % % Shift the objects so they will print correctly. % for i = 1:n % userData = get(anchors(i),'UserData'); % origPos = userData(2:3); % if strcmp(get(anchors(i),'Units'),'data') % printPos = origPos.*[magX,magY] + [0.471 0.477]; % else % printPos = origPos.*[magX,magY]; % end % delta(i,:) = printPos - origPos; % move1sto(anchors(i),delta(i,:)) % end % allAnchors = [allAnchors;anchors]; % allDeltas = [allDeltas;delta]; % % % Find all label stext objects. % labelAnchors = [findobj(thisAxes,'Tag','stext xlabel');... % findobj(thisAxes,'Tag','stext ylabel');... % findobj(thisAxes,'Tag','stext zlabel')]; % nl = length(labelAnchors); % labelDelta = zeros(nl,2); % % % Shift all label stext objects so they will print correctly. % tickDirFactor = 10*strcmp(get(thisAxes,'TickDir'),'out'); % for i = 1:nl % userData = get(labelAnchors(i),'UserData'); % origPos = userData(2:3); % printPos = origPos.*[magX,magY] + [0.471 0.477]; % % id = userData(1); % labH = get(thisAxes,['W'+id,'Label']); % hor = get(labH,'HorizontalAlignment'); % if strcmp(hor,'center') % rot = get(labH,'Rotation'); % labU = get(labH,'Units'); % set(labH,'Units','points') % labpos = get(labH,'Position'); % set(labH,'Units',labU) % if rot == 0 % beyond = labpos(2) + tickDirFactor; % printPos(2) = (origPos(2) - beyond)*magY + beyond; % elseif rot == 90 % beyond = labpos(1) + tickDirFactor; % printPos(1) = (origPos(1) - beyond)*magX + beyond; % elseif rot == -90 % beyond = labpos(1) - axPos(3) - tickDirFactor; % printPos(1) = (origPos(1) - beyond)*magX + beyond; % end % end % % labelDelta(i,:) = printPos - origPos; % move1sto(labelAnchors(i),labelDelta(i,:)) % end % allLabelAnchors = [allLabelAnchors;labelAnchors]; % allLabelDeltas = [allLabelDeltas;labelDelta]; % %end % % %% Find all slegend objects. %legends = [findobj(thisFig,'Tag','slegend');... % findobj(thisFig,'Tag','slegend movable')]; %nleg = length(legends); %origLegPos = zeros(nleg,4); % % %% Shift the legends so they will print correctly. %for i = 1:nleg % newPos = get(legends(i),'Position'); % origLegPos(i,:) = newPos; % userData = get(legends(i),'UserData'); % xy = userData(1:2); % ref = userData(3:4); % newPos(1:2) = paperPos(3:4).*xy - ref.*origLegPos(i,3:4); % set(legends(i),'Position',newPos) % set(thisFig,'CurrentAxes',legends(i)) %end % %drawnow discard % % %% Execute print command. %if nargin == 0 % print %elseif nargin == 1 % print(arg1) %elseif nargin == 2 % print(arg1,arg2) %elseif nargin == 3 % print(arg1,arg2,arg3) %elseif nargin == 4 % print(arg1,arg2,arg3,arg4) %elseif nargin == 5 % print(arg1,arg2,arg3,arg4,arg5) %end % % %% Shift all stext objects back to where they were. %for i = 1:length(allAnchors) % move1sto(allAnchors(i),-allDeltas(i,:)) %end %for i = 1:length(allLabelAnchors) % move1sto(allLabelAnchors(i),-allLabelDeltas(i,:)) %end %for i = 1:nleg % set(legends(i),'Position',origLegPos(i,:)) %end %drawnow discard % %set(thisFig,'CurrentAxes',thisAxes) %set(curFig,'CurrentAxes',curAxes) fclose(fout); disp(' ## Installing: "README.txt" (text)') fout = fopen('README.txt', 'w'); %Styled Text Toolbox %Version 3.2b, 10 March 1997 %Copyright 1995-1997 by Douglas M. Schwarz. All rights reserved. %schwarz@kodak.com % %___________________________________________________________________________ % %The most recent version of the Styled Text Toolbox should be available from % % % %___________________________________________________________________________ % %Introduction. % %The Styled Text Toolbox is a collection of tools which enables the user to %mix fonts, text styles and mathematical constructs (superscripts, %subscripts, integrals, special math characters, etc.) in a single styled %text object. % %Features: % %* Internal "command language" similar to LaTeX %* Text properties applicable on a per character basis: FontName, FontSize, % FontWeight, FontAngle, Color %* Text properties applicable to entire styled text object: EraseMode, % HorizontalAlignment, Position, Rotation, Units, VerticalAlignment, % ButtonDownFcn, Clipping, Interruptible, Visible %* Superscripts and subscripts %* Greek letters using LaTeX names %* Simulated italic (slanted) Greek letters possible %* Many other characters from Symbol font available using LaTeX names %* Some non-LaTeX characters available %* Diacritics above any character %* Fractions, roots, integrals, summations and products %* Kerned output using kern pairs from Adobe Font Metric files %* All 35 standard fonts supported (the ones built-in to most PostScript % printers), except on Student Edition where New Helvetica Narrow is % not supported so as not to exceed 8192 element limit. %* Styled text xlabels, ylabels, zlabels and titles %* Styled text legends and text boxes %* Positions specifiable in 2-D or 3-D coordinates %* Does not require WYSIWYG mode for correct printing %* Fine adjustment of character positions possible %* Syntax nearly the same as that of the built-in text function %* No hard-coded defaults or assumptions %* Platform independent % % %The Styled Text Toolbox consists of several m-files which are analogous to %the MATLAB commands text, set, get, delete, print, title, xlabel, ylabel %and zlabel. % % stext - Add styled text to the current plot % setstext - Set styled text object properties % getstext - Get styled text object properties % delstext - Delete a styled text object % printsto - Print or save graph containing styled text objects % stitle - Styled text plot titles % sxlabel - X-axis styled text labels % sylabel - Y-axis styled text labels % szlabel - Z-axis styled text labels for 3-D plots % %They are designed to have, as nearly as possible, the same features and %syntax as their counterparts. Also included are functions to create %legends and text boxes, a function to modify PostScript files to slant %Greek letters, a function to correct the position of styled text objects %after axes modifications, a demo, a styled text previewer, four utility %functions (used internally), a UNIX shell script, and a file containing %font metric information. % % slegend - Styled text legends % stextbox - Styled text multi-line box % stfixps - Modifies PS files to simulate Symbol-Oblique font % fixstext - Fix position of styled text objects % stodemo - Demonstrates some of the capabilities of stext % spreview - GUI application to help build styled text objects % % cmdmatch - String matching for commands % move1sto - Move one styled text object % getcargs - Get command arguments % readstfm - Read styled text font metrics data file % % addlatin - UNIX script to add ISOLatin1Encoding to PostScript files % % stfm.txt - Font metric information % %The Styled Text Toolbox requires at least version 4.2 of MATLAB. %The Styled Text Toolbox is free, but please read the Important Information %section at the end of this document. % %___________________________________________________________________________ % %Installation instructions. % %The Styled Text Toolbox may be installed anywhere on your search path. I %suggest using a directory name of "stextfun". The font metric information %file must be located in the same directory as "stext.m". The first time %stext is run, a platform-specific MAT-file version of the font metrics is %created. If you move the toolbox to a different platform, do not copy this %file. By default, the file will be created in the stextfun directory. If %you are using a multi-user operating system and you don't have write %permission in that directory, it will be created in the current directory %and a message will be displayed suggesting that you should get your system %administrator to move the file to the stextfun directory. % %___________________________________________________________________________ % %How to use the Styled Text Toolbox. % %The basic idea is that commands are embedded in the string you wish to %display (somewhat like LaTeX). For example, to create a text object at %(x,y) with the text "MATLAB is great!" displayed in 18-point Times, you %could use the command % % text(x,y,'MATLAB is great!','FontName','times','FontSize',18). % %Using stext, this becomes % % stext(x,y,'\18\times MATLAB is great!'). % %However, with stext, you could also put "great" in bold: % % stext(x,y,'\18\times MATLAB is {\bold great}!'). % %It is possible to change the font size "on-the-fly" and make slightly %smaller uppercase letters: % % stext(x,y,'\18\times M\16ATLAB\18 is {\bold great}!') % %or, better yet, % % stext(x,y,'\18\times M{\16ATLAB} is {\bold great}!'). % %The curly braces signify a temporary style change (and may be nested). % %We can also display a simple mathematical equation with a Greek letter and %a superscript: % % stext(x,y,'\12\times The equation for alpha is \alpha = r^2'), % %where the alpha is produced with the Symbol font. Note that the font size %of the superscript is automatically reduced by a factor of sqrt(2). %Subscripts are created similarly with '_'. Normally, subscripts and %superscripts must be enclosed in braces: % % stext(x,y,'\12\times y = x_{index}^{exponent}'), % %but if the subscript or superscript is a single character the braces may be %omitted: % % stext(x,y,'\12\times y = x_1^2'). % %It is also possible to use the normal text positioning properties %HorizontalAlignment and VerticalAlignment. For example, % % stext(x,y,'\12\times Hello','HorizontalAlignment','center',... % 'VerticalAlignment','middle'), % %will center the text at (x,y). These properties and values can be %abbreviated and mixed-case, pretty much the same as with the text command. %So, we can also use % % stext(x,y,'\12\times Hello','horiz','center','vert','mid'). % %Experiment and see what works. % %Please note that it is also possible to use styled text in labels and %titles using sxlabel, sylabel, szlabel and stitle. % %Because of the way that styled text objects are created, it is necessary to %print them using printsto. This m-file temporarily repositions the %individual text objects so that when the figure dimensions are adjusted for %printing the objects appear in the correct place. The syntax of printsto %is exactly the same as print (in fact, all the arguments are passed to %print) so it is still possible to create PostScript files or set printing %options. % %If the figure size is changed (or view in 3-D), the styled text objects %will not be in the correct locations. Use fixstext to reposition them. % %Please refer to the Command Reference below, read the help information in %the various m-files and study the demo (stodemo.m) for further explanation. % %___________________________________________________________________________ % %Command Reference. % % %Parsing of Commands. % %It is important to understand how commands are parsed so you will know how %spaces are treated. There are three categories of commands: those with all %letters (e.g., \alpha), those with all numbers (e.g., \12) and those %consisting of a single special character (e.g., \+). Commands are %terminated by the first character that can be determined not to be part of %the command itself. For instance, if the command is all letters then the %first non-letter will mark the end of the command. If the next character %is in the same category as the command characters then a single space %should be inserted as the termination character. This space will not %appear in the output. A few examples should make this clear: % %'\alpha a' will produce no space between the alpha and the a. The space is %necessary to terminate the \alpha command, but it gets swallowed. Another %way to achieve the same result is with '\alpha{}a'. % %'\alpha a' will produce a single space between the alpha and the a. The %first space gets swallowed as above, but the second one will appear. %Another way to get the same result is with '\alpha\ a', where the '\ ' is a %standard space command. % %'\alpha1' will be parsed without error and there will be no space between %the alpha and the 1. Of course, this can also be done with '\alpha{}1', % %'\alpha 1' will have a single space between the alpha and the 1. % %'\+=' will be parsed without error and there will be no space between the %'+' (which will be made with the Symbol font) and the '=' (in the current %font). % % % %Grouping. % %Use curly braces, {}, to group characters and to effect temporary style %changes. For example, % % stext(x,y,'\times Normal, {\i italic, {\b bold-italic}}, normal') % %will produce the indicated styles. Braces can be nested as deeply as %necessary. See also the section on subscripts and superscripts below. % % % %Subscripts and Superscripts. % %Subscripts and superscripts can be produced with '_' and '^'. The actual %script must be enclosed in braces unless it is a single character in which %case the braces may be omitted. The scripts may be typed in either order. %Some examples: % % stext(x,y,'y = x^2') % % stext(x,y,'y = x_1^2') which is equivalent to stext(x,y,'y = x^2_1') % % stext(x,y,'y = e^{x^{\pi}}') % % stext(x,y,'y = e^{t_{max}^2}') % %The font size of scripts is automatically reduced by a factor of sqrt(2). %This process continues indefinitely so that in % % stext(x,y,'\24x^{y^2}') % %the 'y' will be 17-point and the '2' will be 12-point type. % % % %Font size. % %The font size is set with \, where is the desired font size in %points. For example, \18 will set the font size to 18 points. When %different font sizes are used, the characters are aligned at their %baselines. The VerticalAlignment is set by the first displayed character. %For example, % % stext(x,y,'\12A\96A','VerticalAlignment','middle'), % %will produce a small A followed by a huge A with the middle of the small %A at y and the baseline of the huge A aligned with the baseline of the %small A. % %The font size can also be changed by: % % \bigger Increases font size by a factor of sqrt(2). % \larger Increases font size by a factor of sqrt(2). % \smaller Decreases font size by a factor of sqrt(2). % % % %Font angle and weight commands. % % \light Sets font weight to 'light'. % \demi Sets font weight to 'demi'. % \bold Sets font weight to 'bold'. % % \italic Sets font angle to 'italic'. % \oblique Sets font angle to 'oblique'. % % \normal Sets both font angle and font weight to 'normal'. % % % %Fonts. % %To set or change the font used, use \. The following are the %fonts which can be used: % %Command Font %\times Times %\helvetica Helvetica %\courier Courier %\symbol Symbol %\avantgarde Avant Garde %\bookman Bookman %\newcenturyschlbk New Century Schoolbook %\palatino Palatino %\zapfdingbats Zapf Dingbats %\zapfchancery Zapf Chancery %\narrow New Helvetica Narrow (not supported in Student Edition) % % % %Special Characters. % %The characters '\{}^_' have special meanings in command strings. To get %them to display and print use '\\', '\{', '\}', '\^' and '\_' instead. % %Arbitrary ASCII characters can be inserted with the \#{} command, where % is the ASCII code of the character. For example, since the ASCII code %in most encodings for the copyright symbol is 169, it can be inserted with %'\#{169}'. % % % %Colors. % %\black, \white, \red, \green, \blue, \cyan, \magenta, \yellow or \gray will %set the text color appropriately. % %\color{,,} sets text color to the specified RGB values. For %example, \color{.5,.5,.5} sets the text color to a medium gray (the same as %\gray). % % % %Positioning, units = points. % %\left{

}, \right{

}, \up{

} and \down{

} move the subsequent print %position left, right, up and down respectively (relative to the text) by %

points. Negative values for p are allowed. % % % %Positioning, units = current font size. % %\rleft{}, \rright{}, \rup{} and \rdown{} move the subsequent %print position left, right, up and down respectively (relative to the text) %by r*(current font size) points. Negative values for r are allowed. % % % %Integrals, summations and products. % %\int{}{}, \sum{}{} and \prod{}{} produce a definite %integral, summation and product, respectively, with lower limit and %upper limit where and are valid stext constructs. One or both %of the limits may be blank, e.g., % % stext(x,y,'\int{x}{} f(x) dx') % %will produce the notation meaning "integrate over all x". On the Macintosh %(and perhaps on other platforms) the integral, summation and product %symbols look too low on the screen, but print correctly. % % % %Fractions. % %\frac{}{} will produce a fraction of over , where and %are valid stext constructs. % % % %Roots. % %\sqrt{} will produce the square root of and \root{}{} will %produce the th root of . The appearance on the screen may not match %the print exactly. % % % %Lowercase Greek letters. % %These are produced using the same names as used by LaTeX. The following %table lists the lowercase Greek letters: % %\alpha \iota \sigma %\beta \kappa \varsigma %\gamma \lambda \tau %\delta \mu \upsilon %\epsilon \nu \phi %\varepsilon \xi \varphi %\zeta \pi \chi %\eta \varpi \psi %\theta \rho \omega %\vartheta \varrho % %Two of these characters don't exist in the Symbol font but are included for %completeness. In particular, \varrho produces a TeX \rho and \epsilon %produces a TeX \varepsilon (yes, that's right, it's the \epsilon character %which is missing). % % % %Uppercase Greek letters. % %These are produced exactly like the lowercase ones. % %\Gamma \Xi \varUpsilon %\Delta \Pi \Phi %\Theta \Sigma \Psi %\Lambda \Upsilon \Omega % %I made up the \varUpsilon name since the character is in the Symbol font, %but it looks almost exactly like a Y in Times; I wouldn't recommend using %it. The other uppercase Greek letters look just like characters in the %Roman alphabet and so are not included. % % % %Other LaTeX characters. % %Many other characters are available in the Symbol font: % %\forall \approx \angle %\exists \dots \nabla %\cong \vert \surd %\perp \Vert \cdot %\bot \aleph \neg %\leq \Im \lnot %\infty \Re \land %\leftrightarrow \wp \lor %\leftarrow \otimes \Leftrightarrow %\uparrow \oplus \Leftarrow %\rightarrow \emptyset \Uparrow %\downarrow \cap \Rightarrow %\degrees \cup \Downarrow %\pm \supset \diamond %\geq \supseteq \langle %\propto \notsubset \lceil %\partial \subset \lfloor %\bullet \subseteq \rangle %\div \in \rceil %\neq \notin \rfloor %\equiv \AA % %If you don't know what some of these look like just try them out. % % % %Non-LaTeX characters. % %\+, \-, \=, \>, \< and \| use the appropriate characters from the Symbol %font instead of whatever font you are using at the time. The results may %be somewhat better, especially \- since it produces a minus sign which is %the same width as \+. A hyphen is too narrow. % %\therefore produces the three-dot symbol. % %\prime produces a prime symbol. % %\dprime produces a double prime symbol. % %\slash produces a sharply angled slash from the Symbol font. % %\mult produces the x-shaped multiplication symbol. In LaTeX this is called %\times, but I had to change it since \times refers to the Times font. % %\horiz produces a fairly long horizontal line which matches up with %\leftarrow and \rightarrow. % %\ii produces a dotless "i" for use under accents. (Not available with the %Windows encoding.) % % % %Diacritics. % %(See important note below.) %It is possible to produce accented characters, however, the syntax is not %the same as LaTeX. Consider % % stext(x,y,'y\hat \= x\tilde'). % %The accent will be centered over the most recently produced character. The %accents which are available are: % %\grave \Grave (slanted line down to right) %\acute \Acute (slanted line up to right) %\ddot \Ddot (double dots) %\hat \Hat ('^') %\tilde \Tilde (squiggly line) %\bar \Bar (short horizontal line or macron) %\breve \Breve (semicircle open at top) (N/A with Windows) %\dot \Dot (single dot) (N/A with Windows) %\check \Check (upside down '^') (N/A with Windows) % %The capitalized versions are a little higher and suitable for use over tall %characters like 'b' or capitals. % %Note: The accent characters are encoded in the upper half of the ASCII %code range and in different places depending on the character encoding. %There are three encoding schemes in use (that I know of): MacEncoding %(used only on the Macintosh), WindowsLatin1Encoding (used only on Windows) %and ISOLatin1Encoding (used by everything else). The correct ASCII codes %for your platform are computed from the encoding information contained in %the font metric file, stfm.mat via stfm.txt, so you don't have to worry %about this. % %There is, however, another problem which some people may encounter. %Apparently, some PostScript printers (and software rasterizers) do not %recognize the ISOLatin1Encoding keyword and use a default encoding which %does not include some of the accent characters. In this case, the accent %characters will simply not print, but everything else will be ok. There is %a workaround. It is possible to insert the ISOLatin1Encoding definition %into the PostScript file before sending it to the printer. I have included %a UNIX script, addlatin, to perform the insertion. So, instead of typing % % >>printsto % %you must now type something like % % >>printsto -dps myfig.ps (or use -deps, -dpsc, etc.) % >>!addlatin myfig.ps % >>!lpr myfig.ps (substitute 'lp' for 'lpr' if necessary) % %to print figures which contain accented characters. Please note that if %you are using a Macintosh (which uses MacEncoding), Windows (which uses %WindowsLatin1Encoding) or your PostScript printer already recognizes the %ISOLatin1Encoding keyword you don't have to worry about any of this. Also %note that the accents may not appear on the screen, but they should print %correctly. % % % %Slanted Symbol Characters. % %As mentioned below, scalar variables should be in italics. This poses a %problem when the variable is represented by a Greek letter because there is %no Symbol-Italic or Symbol-Oblique font. Whenever you have seen a slanted %version of one of the Symbol characters it has been produced by appropriate %PostScript code which slants the character. Unfortunately, MATLAB does not %do this and italic or oblique Symbol characters are rendered unslanted. %There is now a way around this problem. The function stfixps will modify a %PostScript file by inserting the character-slanting code. The PostScript %file must have been made from a figure containing styled text objects which %include italic or oblique Symbol characters. So, as above, printing becomes %a little more complicated. You must type something like % % >>printsto -dps myfig.ps (or use -deps, -dpsc, etc.) % >>stfixps myfig.ps % >>!lpr myfig.ps (substitute 'lp' for 'lpr' if necessary) % %to print figures containing slanted Greek letters. This creates a problem %for Mac users since there is no built-in equivalent to lpr. I recommend %obtaining Drop¥PS from Bare Bones Software which is a drag-and-drop %application to send PostScript files to a printer. You can either drop %myfig.ps on Drop¥PS or type % % >>!Drop¥PS myfig.ps % %at the MATLAB prompt. Drop¥PS is free and is available from % % http://www.barebones.com/freeware/DropPS-113.hqx % %I don't have access to a Windows machine so I don't know how to do this %there, but I assume some kind of utility exists to send PostScript files %to a printer. % % %___________________________________________________________________________ % %Tips and Style Comments % %1) Abbreviation of Commands. % %There are two kinds of commands: those that produce a character and those %that merely change the appearance of subsequent characters. It is %permissible to abbreviate the latter but not the former. The rules for %determining a valid abbreviation are somewhat complicated. It has to do %with the order of the tests to determine the command. Basically, just make %sure the abbreviation is unambiguous. For example, \i is a valid %abbreviation for \italic since no other commands begin with 'i' except for %\int, \iota, \infty and \in and those are all character producing commands. %Other valid abbreviations for \italic are \itali, \ital, \ita and \it. % %Minimal abbreviations: %\n = \normal \sm = \smaller %\i = \italic \bl = \black %\o = \oblique \w = \white %\l = \light \r = \red %\d = \demi \g = \green %\b = \bold \blu = \blue %\t = \times \cy = \cyan %\h = \helvetica \m = \magenta %\c = \courier \y = \yellow %\s = \symbol \gra = \gray %\a = \avantgarde \co = \color %\boo = \bookman \le = \left %\ne = \newcenturyschlbk \ri = \right %\p = \palatino \u = \up %\z = \zapfdingbats \do = \down %\zapfc = \zapfchancery \rl = \rleft %\na = \narrow \rr = \rright %\bi = \bigger \ru = \rup %\la = \larger \rd = \rdown % % % %2) Braces. % %Use braces liberally. They can be nested as deeply as necessary and they %make the expressions easier to read. For example, % % stext(x,y,'\12\times The word {\i italic} is in italics.') % %is clearer than % % stext(x,y,'\12\times The word \i italic \norm is in italics.'). % % % %3) Mathematical Formulas. % %For a professional look, use italics for scalar variables. It can make the %command string look pretty messy, but is worth it. Compare % % stext(x,y,'\18\times r^2 \= x^2 \+ y^2') % %with % % stext(x,y,'\18\times{\i r}^2 \= {\i x}^2 \+ {\i y}^2'). % %When using accents over italicized characters, make the accents in italics %also. For example, % % stext(x,y,'{\i y\hat}') % %looks better than % % stext(x,y,'{\i y}\hat'). % % % %4) Tweaking. % %If you are fussy, you can tweak the appearance of your styled text objects %using the positioning commands (\left, \right, etc.). It is usually better %to use the ones which are in units of current font size (\rleft, \rright, %etc.) since you can design and preview the object on-screen at a large size %and then scale it down just by changing the font size. The individual %elements will maintain their relationships to each other. % %The positioning commands can be used to produce some very complicated %mathematical formulas, but it will require some trial-and-error (try using %spreview). % %An example of this is to move the axis labels away from the axes: % % sxlabel('\down{5}This label will be 5 points lower than normal.') % sylabel('\up{5}This label will be 5 points to the left of normal.') % %A number of spacing commands are available. In order, they are: % %'\/' italic correction %'\,' thin space %'\:' medium space %'\;' thick space %'\ ' word space % %The italic correction can be used to add just a little bit of space when %there is a transition from italic to normal letters. The other spaces can %be useful in various situations. % %___________________________________________________________________________ % %Other features. % %Ordinary text strings are kerned using the kern pairs defined in the Adobe %Font Metric files for the supported fonts. % %Printing does *not* require that the figure 'Position' be set to the same %dimensions as the 'PaperPosition' (WYSIWYG mode). This means that printing %works correctly even if you have a small monitor (where it is not possible %to use WYSIWYG mode since the monitor is not as tall as a piece of paper). %If you do use WYSIWYG mode it is not necessary to print using printsto; %print will work just fine. % %The Styled Text Toolbox was designed to be platform-independent. I have %taken into account the different character encodings in use. Also, to %accommodate the PC users, the file names have no more than eight %characters. % %The Styled Text Toolbox was designed to be user-preference-independent. %There are no built-in defaults or assumptions such as text color or font %choice. % %___________________________________________________________________________ % %What are its limitations? % %The mathematical formulas which can be created easily with the Styled Text %Toolbox are somewhat limited. You can make Greek letters, italics, %superscripts, subscripts, integrals, etc., but other more complicated %constructs are possible only with some difficulty and creativity. It was %never my intention to make this thing an equation typesetting tool (though %it seems to be moving in that direction), but just a way of including Greek %letters and simple formulas in MATLAB figures. % %___________________________________________________________________________ % %Important Information. % %The Styled Text Toolbox was written by me, Douglas M. Schwarz. Although I %am an employee of the Eastman Kodak Company, this tool was written entirely %on my own time and is not supported in any way by Kodak. If you have a %problem with it please bring it to my attention, but there may be a day or %two delay before I can get around to looking at it. The Styled Text %Toolbox is free, but not in the public domain and I retain all rights. You %are free to modify your own copy, of course, but please do not distribute a %modified version. I am open to any suggestions of ways to improve this %tool. % % %Styled Text Toolbox %Version 3.2b, 10 March 1997 %Copyright 1995-1997 by Douglas M. Schwarz. All rights reserved. %schwarz@kodak.com fclose(fout); disp(' ## Installing: "readstfm.m" (text)') fout = fopen('readstfm.m', 'w'); %function [fm,kds,encs,accents,encsel,verts] = readstfm(filename) %%READSTFM Read Styled Text Toolbox font metrics file. %% [FM,KD,ENCODING,ACCENTS,ENCSEL,VERTALIGN] = READSTFM(FILENAME) reads %% the file specified by FILENAME which must be the text version of the %% font metrics. The character widths, kerning data, encoding vectors, %% accent characters, encoding selector and vertical alignment positions %% are returned. %% %% If FILENAME is omitted then the file "stfm.txt" in the Styled %% Text Toolbox directory is assumed. % %% Requires function CMDMATCH and file STFM.TXT. %% Requires MATLAB Version 4.2 or greater. % %% Version 3.2b, 10 March 1997 %% Part of the Styled Text Toolbox %% Copyright 1995-1997 by Douglas M. Schwarz. All rights reserved. %% schwarz@kodak.com % %if nargin == 0 % stextfun = which('stext'); % stextfun((length(stextfun) - 6):length(stextfun)) = []; % filename = [stextfun,'stfm.txt']; %end % %fid = fopen(filename); % %% Read the character widths of the Roman fonts. %while 1 % line = fgetl(fid); % if cmdmatch(line,'BeginRomanCharWidths'), break, end %end %dims = sscanf(line,'%*s %d %d'); %numChars = dims(1); %if isstudent % nrmFnts = dims(2) - 4; % fmt = ['%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d',... % '%d%d%d%d%d%d%d%d%d%*d%*d%*d%*d%d']; %else % nrmFnts = dims(2); % fmt = '%d'; %end %widths = fscanf(fid,fmt,[nrmFnts,numChars])'; % %% Read the character widths of the Symbol font. %while 1 % line = fgetl(fid); % if cmdmatch(line,'BeginSymbolCharWidths'), break, end %end %nsymch = sscanf(line,'%*s %d'); %symwidths = fscanf(fid,'%d',nsymch); % %% Read the character widths of the ZapfDingbats font. %while 1 % line = fgetl(fid); % if cmdmatch(line,'BeginZapfDingbatsCharWidths'), break, end %end %nzdch = sscanf(line,'%*s %d'); %zdwidths = fscanf(fid,'%d',nzdch); % %% Read the kerning data information. %while 1 % line = fgetl(fid); % if cmdmatch(line,'BeginKernData'), break, end %end %nkd = sscanf(line,'%*s %d')'; %if isstudent % pos = ftell(fid); % kernData1 = fscanf(fid,'%d%*d%*d%*d',nkd); % fseek(fid,pos,'bof'); % kernData2 = fscanf(fid,'%*d%d%*d%*d',nkd); % fseek(fid,pos,'bof'); % kernData3 = fscanf(fid,'%*d%*d%d%*d',nkd); % fseek(fid,pos,'bof'); % kernData4 = fscanf(fid,'%*d%*d%*d%d',nkd); %else % kernData = fscanf(fid,'%d',[4,nkd])'; %end % %% Read the encoding vectors. %while 1 % line = fgetl(fid); % if cmdmatch(line,'BeginEncodings'), break, end %end %data = sscanf(line,'%*s %d %d'); %encsel = data(1); %nenc = data(2); %encs = fscanf(fid,'%d',[nenc,256])'; % %% Read the vertical alignment metrics. %while 1 % line = fgetl(fid); % if cmdmatch(line,'BeginVertAlign'), break, end %end %numFonts = sscanf(line,'%*s %d'); %verts = fscanf(fid,'%f%f%f%f%f',[5,numFonts])'; % %fclose(fid); % %% Put all the character widths in one matrix. %n = max([nsymch,nzdch,numChars]); %fm = zeros(n,nrmFnts+2); %fm(1:nsymch,1) = symwidths; %fm(1:nzdch,2) = zdwidths; %fm(1:numChars,3:nrmFnts+2) = widths; % %% Store the kerning data as a sparse matrix. %if isstudent % i = 1000*kernData1 + kernData2; % kds = sparse(i,kernData3,kernData4,34000,260); %else % i = 1000*kernData(:,1) + kernData(:,2); % kds = sparse(i,kernData(:,3),kernData(:,4),34000,260); %end % %% These are the accent characters (PostScript name in parentheses if %% different): grave, acute, ddot (dieresis), hat (circumflex), tilde, %% bar (macron), breve, dot (dotaccent), check (caron), AA (Aring), %% and ii (dotlessi). %accents = [124 125 131 126 127 128 129 130 136 205 145]; fclose(fout); disp(' ## Installing: "setstext.m" (text)') fout = fopen('setstext.m', 'w'); %function setstext(anchor,p1,v1,p2,v2,p3,v3,p4,v4,p5,v5,... % p6,v6,p7,v7,p8,v8,p9,v9,p10,v10,p11,v11,p12,v12) %%SETSTEXT Set styled text object properties. %% SETSTEXT has the same syntax as SET except that only one styled text %% handle can be specified and SETSTEXT(H) does not display all the %% property names and possible values. %% %% See also SET, STEXT, SXLABEL, SYLABEL, SZLABEL, STITLE, DELSTEXT %% PRINTSTO, FIXSTEXT. % %% Requires functions STEXT, CMDMATCH and GETCARGS and MAT-file STFM.MAT. %% Requires MATLAB Version 4.2 or greater. % %% Version 3.2b, 10 March 1997 %% Part of the Styled Text Toolbox %% Copyright 1995-1997 by Douglas M. Schwarz. All rights reserved. %% schwarz@kodak.com % %% Define gFONT_METRICS, gKERNING_DATA, gENCODING, gACCENTS, gENC_SEL %% and gVAL as global variables so we only have to load them if they %% weren't loaded by stext or have been cleared. %global gFONT_METRICS gKERNING_DATA gENCODING gACCENTS gENC_SEL gVAL %if length(gFONT_METRICS) == 0 % temp = stext; % delstext(temp) %end %% Determine encoding selector, es, depending on platform. %if gENC_SEL == 0 % comp = computer; % if cmdmatch(comp,'MAC') % es = 3; % elseif cmdmatch(comp,'PC') % es = 4; % else % es = 5; % end %else % es = gENC_SEL; %end %nacc = length(gACCENTS); %accents = 32*ones(1,nacc); %for i = 1:nacc % loc = find(gENCODING(:,es) == gACCENTS(i)); % if ~isempty(loc) % accents(i) = max(loc) - 1; % end %end % %% Check to see if handle is a valid stext object. %tag = get(anchor,'Tag'); %if ~strcmp(tag(1:min(length(tag),5)),'stext') % error('Not an stext object.') %end %ver5 = cmdmatch(version,'5'); % %% Make sure current axes are parent of anchor. %fig = get(0,'CurrentFigure'); %currentAxes = get(fig,'CurrentAxes'); %set(fig,'CurrentAxes',get(anchor,'Parent')) % %% Get default values. %str = setstr(rem(get(anchor,'String'),256)); %anchorPos = get(anchor,'Position'); %horizAlign = get(anchor,'HorizontalAlignment'); %vertAlign = get(anchor,'VerticalAlignment'); %anchorUnits = get(anchor,'Units'); %rotation = get(anchor,'Rotation'); %eraseMode = get(anchor,'EraseMode'); %buttonDownFcn = get(anchor,'ButtonDownFcn'); %clipping = get(anchor,'Clipping'); %interruptible = get(anchor,'Interruptible'); %fontSize = get(0,'DefaultTextFontSize'); %fontName = lower(get(0,'DefaultTextFontName')); %color = get(0,'DefaultTextColor'); % %set(anchor,'Rotation',0,'Visible','off') %userData = get(anchor,'UserData'); %oldObjList = userData(4:length(userData)); %if length(oldObjList) > 0 % visible = get(oldObjList(1),'Visible'); %else % visible = 'on'; %end % %% Look for and set some properties %numOptions = (nargin - 1)/2; %for i = 1:numOptions % property = eval(['p',num2str(i)]); % value = eval(['v',num2str(i)]); % % % Convert property and value (if it's a string) to lower case. % % This code is significantly simpler and faster than lower.m, but % % sufficient for our purposes. % upperCase = property >= 'A' & property <= 'Z'; % property(upperCase) = setstr(property(upperCase) + ('a' - 'A')); % if isstr(value) & ~cmdmatch('string',property) % upperCase = value >= 'A' & value <= 'Z'; % value(upperCase) = setstr(value(upperCase) + ('a' - 'A')); % end % % % HorizontalAlignment: [ {left} | center | right ] % if cmdmatch('horizontalalignment',property) % horizAlign = value; % set(anchor,'HorizontalAlignment',value) % % % VerticalAlignment: [ top | cap | {middle} | baseline | bottom ] % elseif cmdmatch('verticalalignment',property) % vertAlign = value; % set(anchor,'VerticalAlignment',value) % % % Units: [ inches | centimeters | normalized | points | pixels | {data} ] % elseif cmdmatch('units',property) % anchorUnits = value; % set(anchor,'Units',value) % anchorPos = get(anchor,'Position'); % % % Position % elseif cmdmatch('position',property) % anchorPos = value; % set(anchor,'Position',value) % xin = value(1); % yin = value(2); % % % Rotation % elseif cmdmatch('rotation',property) % rotation = value; % rotation = rotation - floor(rotation/360)*360; % % % String % elseif cmdmatch('string',property) % str = value; % set(anchor,'String',value) % % % EraseMode % elseif cmdmatch('erasemode',property) % eraseMode = value; % set(anchor,'EraseMode',value) % % % ButtonDownFcn % elseif cmdmatch('buttondownfcn',property) % buttonDownFcn = value; % set(anchor,'ButtonDownFcn',value) % % % Clipping % elseif cmdmatch('clipping',property) % clipping = value; % set(anchor,'Clipping',value) % % % Interruptible % elseif cmdmatch('interruptible',property) % interruptible = value; % set(anchor,'Interruptible',value) % % % Visible % elseif cmdmatch('visible',property) % visible = value; % set(anchor,'Visible',value) % % else % error('Invalid object property.') % end %end % %% Determine exact starting point. %if cmdmatch('points',anchorUnits) % pos = get(anchor,'Position'); %else % posu0 = get(anchor,'Position'); % set(anchor,'Units','points') % pos1 = get(anchor,'Position'); % set(anchor,'Units',anchorUnits) % posu1 = get(anchor,'Position'); % set(anchor,'Units','points','Position',pos1 + 1,'Units',anchorUnits) % posu2 = get(anchor,'Position'); % pos = (posu0(1:2) - posu1(1:2))./(posu2(1:2) - posu1(1:2)) + pos1(1:2); % set(anchor,'Units','points','Position',pos,'Units',anchorUnits) %end %x0 = pos(1); %y0 = pos(2); % %% Initialize some data. %objList = []; %heightList = []; %xDistance = []; %first = 1; %slantTagged = 0; %termNoDigits = setstr(1:255); %termNoDigits(real('0'):real('9')) = []; %termNoAlpha = setstr(1:255); %termNoAlpha([real('A'):real('Z'),real('a'):real('z')]) = []; %xstack = []; %colLut = [1 1 3 3;2 2 4 4;2 2 4 4]; %if isstudent % fm = [1 1 1 1 ; 2 2 2 2 ; 3:6 ; 7:10 ; 11:14 ; 15:18 ; 19:22 ;... % 23:26 ; 27:30 ; 7:10 ; 31 31 31 31]; %else % fm = [1 1 1 1 ; 2 2 2 2 ; 3:6 ; 7:10 ; 11:14 ; 15:18 ; 19:22 ;... % 23:26 ; 27:30 ; 31:34 ; 35 35 35 35]; %end % %fontanglelist = str2mat('normal','italic','oblique'); %fontnamelist = str2mat('symbol','zapfdingbats','times','helvetica',... % 'palatino','courier','avantgarde','bookman',... % 'newcenturyschlbk','n helvetica narrow','zapfchancery'); %fontweightlist = str2mat('light','normal','demi','bold'); % %% Initialize indexing parameters for "params" array. fa = font angle, %% fn = font name, fs = font size, fw = font weight, cr,cg,cb = color rgb, %% x = x location, y = y location, mode is used for super- and subscripts, %% nextX = x location of next object. %fa = 1; fn = 2; fs = 3; fw = 4; cr = 5; cg = 6; cb = 7; x = 8; y = 9; %mode = 10; nextX = 11; % %% params is a parameter stack. The contents are indices into string %% matrices for font angle, name and weight and actual values for %% the others. % %% Initialize params: font angle = normal, font name = default font, %% font size = default text font size, font weight = normal, %% color = default text color, x = 0, y = 0, mode = 0, nextX = 0. %params = [1;4;fontSize;2;get(0,'DefaultTextColor')';0;0;0;0]; %for fontIndex = 1:11 % if cmdmatch(fontnamelist(fontIndex,:),fontName) % params(fn) = fontIndex; % break % end %end % %% Parse str looking for commands. %while ~isempty(str) % if str(1) == '{' % % Push a copy of the current parameters on the parameter stack. % params = [params(:,1),params]; % params(mode) = 0; % str(1) = []; % elseif str(1) == '}' % % Pop the parameter stack except for adjustments to the x values. % if size(params,2) == 1 % delete(objList) % delete(anchor) % error('Unmatched braces.') % end % str(1) = []; % params(nextX,2) = max(params(nextX),params(nextX,2)); % if params(mode,2) == 0 % params(x,2) = params(x); % end % if isempty(str) % params(x,2) = params(x); % else % if str(1) ~= '^' & str(1) ~= '_' % params(x,2) = params(x); % params(mode,2) = 0; % end % end % params(:,1) = []; % elseif str(1) == '^' % % Superscript % params(mode) = params(mode) + 1; % params = [params(:,1),params]; % params(mode) = 0; % params(nextX) = params(x); % params(y) = params(y) + params(fs)/3; % params(fs) = params(fs)/sqrt(2); % if str(2) == '{' % str(1:2) = []; % else % str(1:2) = [str(2),'}']; % end % elseif str(1) == '_' % % Subscript % params(mode) = params(mode) + 2; % params = [params(:,1),params]; % params(mode) = 0; % params(nextX) = params(x); % params(y) = params(y) - params(fs)/4; % params(fs) = params(fs)/sqrt(2); % if str(2) == '{' % str(1:2) = []; % else % str(1:2) = [str(2),'}']; % end % elseif str(1) == '\' % % Extract command. % if all(str(2) ~= termNoAlpha) % [cmd,str] = strtok(str,termNoAlpha); % if length(str) > 1 % if str(1) == ' ' % nonSpace = min(find(str ~= ' ')); % if ~isempty(nonSpace) % if all(str(nonSpace) ~= termNoAlpha) % str(1) = []; % end % end % end % end % elseif all(str(2) ~= termNoDigits) % [cmd,str] = strtok(str,termNoDigits); % if length(str) > 1 % if str(1) == ' ' % nonSpace = min(find(str ~= ' ')); % if ~isempty(nonSpace) % if all(str(nonSpace) ~= termNoDigits) % str(1) = []; % end % end % end % end % else % cmd = str(2); % str(1:2) = []; % end % % % Command is a space. % if strcmp(' ',cmd) % str = [' ',str]; % % % Font size specified in points. % elseif all(cmd >= '0' & cmd <= '9') % params(fs) = sscanf(cmd,'%d'); % if params(fs) > 255 % delete(objList) % delete(anchor) % error('Font size too large.') % end % % % Font angle and weight commands. % elseif cmdmatch('normal',cmd), params(fa) = 1; params(fw) = 2; % elseif cmdmatch('italic',cmd), params(fa) = 2; % elseif cmdmatch('oblique',cmd), params(fa) = 3; % elseif cmdmatch('light',cmd), params(fw) = 1; % elseif cmdmatch('demi',cmd), params(fw) = 3; % elseif cmdmatch('bold',cmd), params(fw) = 4; % % % Font names. % elseif cmdmatch('symbol',cmd), params(fn) = 1; % elseif cmdmatch('zapfdingbats',cmd), params(fn) = 2; % elseif cmdmatch('times',cmd), params(fn) = 3; % elseif cmdmatch('helvetica',cmd), params(fn) = 4; % elseif cmdmatch('palatino',cmd), params(fn) = 5; % elseif cmdmatch('courier',cmd), params(fn) = 6; % elseif cmdmatch('avantgarde',cmd), params(fn) = 7; % elseif cmdmatch('bookman',cmd), params(fn) = 8; % elseif cmdmatch('newcenturyschlbk',cmd), params(fn) = 9; % elseif cmdmatch('narrow',cmd), params(fn) = 10; % elseif cmdmatch('zapfchancery',cmd), params(fn) = 11; % % % Font size in sqrt(2) increments. % elseif cmdmatch('bigger',cmd), params(fs) = params(fs)*sqrt(2); % elseif cmdmatch('larger',cmd), params(fs) = params(fs)*sqrt(2); % elseif cmdmatch('smaller',cmd), params(fs) = params(fs)/sqrt(2); % % % Colors. % elseif cmdmatch('black',cmd), params(cr:cb) = [0;0;0]; % elseif cmdmatch('white',cmd), params(cr:cb) = [1;1;1]; % elseif cmdmatch('red',cmd), params(cr:cb) = [1;0;0]; % elseif cmdmatch('green',cmd), params(cr:cb) = [0;1;0]; % elseif cmdmatch('blue',cmd), params(cr:cb) = [0;0;1]; % elseif cmdmatch('cyan',cmd), params(cr:cb) = [0;1;1]; % elseif cmdmatch('magenta',cmd), params(cr:cb) = [1;0;1]; % elseif cmdmatch('yellow',cmd), params(cr:cb) = [1;1;0]; % elseif cmdmatch('gray',cmd), params(cr:cb) = [0.5;0.5;0.5]; % elseif cmdmatch('color',cmd) % [arg,str] = strtok(str,'{}'); % str(1) = []; % params(cr:cb) = sscanf(arg,'%f,%f,%f'); % % % Absolute positioning in points. % elseif cmdmatch('left',cmd) % [arg,str] = strtok(str,'{}'); % str(1) = []; % arg = sscanf(arg,'%f'); % params([x,nextX]) = params([x,nextX]) - arg; % elseif cmdmatch('right',cmd) % [arg,str] = strtok(str,'{}'); % str(1) = []; % arg = sscanf(arg,'%f'); % params([x,nextX]) = params([x,nextX]) + arg; % elseif cmdmatch('up',cmd) % [arg,str] = strtok(str,'{}'); % str(1) = []; % arg = sscanf(arg,'%f'); % params(y) = params(y) + arg; % elseif cmdmatch('down',cmd) % [arg,str] = strtok(str,'{}'); % str(1) = []; % arg = sscanf(arg,'%f'); % params(y) = params(y) - arg; % % % Relative positioning in units of current font size. % elseif cmdmatch('rleft',cmd) % [arg,str] = strtok(str,'{}'); % str(1) = []; % arg = sscanf(arg,'%f'); % params([x,nextX]) = params([x,nextX]) - arg*round(params(fs)); % elseif cmdmatch('rright',cmd) % [arg,str] = strtok(str,'{}'); % str(1) = []; % arg = sscanf(arg,'%f'); % params([x,nextX]) = params([x,nextX]) + arg*round(params(fs)); % elseif cmdmatch('rup',cmd) % [arg,str] = strtok(str,'{}'); % str(1) = []; % arg = sscanf(arg,'%f'); % params(y) = params(y) + arg*round(params(fs)); % elseif cmdmatch('rdown',cmd) % [arg,str] = strtok(str,'{}'); % str(1) = []; % arg = sscanf(arg,'%f'); % params(y) = params(y) - arg*round(params(fs)); % % % Integral. % elseif strcmp('int',cmd) % [arg1,str] = getcargs(str); % [arg2,str] = getcargs(str); % str = ['{\rdown{.25}\larger\sym',242,... % '}_{\rleft{.1}\rdown{.3}{',arg1,... % '}}^{\rright{.2}\rup{.6}{',arg2,'}}',str]; % % % Summation. % elseif strcmp('sum',cmd) % [arg1,str] = getcargs(str); % [arg2,str] = getcargs(str); % str = ['{\rdown{.2}\larger\sym',229,'}_{\rdown{.1}{',arg1,... % '}}^{\rup{.2}{',arg2,'}}',str]; % % % Product. % elseif strcmp('prod',cmd) % [arg1,str] = getcargs(str); % [arg2,str] = getcargs(str); % str = ['{\rdown{.2}\larger\sym',213,'}_{\rdown{.1}{',arg1,... % '}}^{\rup{.2}{',arg2,'}}',str]; % % % Square root. % elseif strcmp('sqrt',cmd) % [arg1,str] = getcargs(str); % pfs = round(params(fs)); % nfs = sprintf('%d',pfs); % nfn = deblank(fontnamelist(params(fn),:)); % if params(fn) == 11 % nfn = 'n helvetica narrow'; % end % narg1 = ['\',nfs,'\',nfn,'{}',arg1]; % h1 = eval(['stext(0,0,narg1,''Units'',''points'',',... % '''vert'',''base'')'],'-1'); % if h1 == -1 % delete(objList) % delete(anchor) % error(lasterr) % end % e1 = getstext(h1,'Extent'); % delstext(h1) % rfs = ceil(e1(4)/0.955); % ofs = 0.038*rfs + e1(2); % exr = 0.2; % sqrtwid = e1(3) + 2*exr*pfs; % numex = sqrtwid/(rfs*0.5); % numex1 = ceil(numex) - 1; % jog = 0.5*rfs - (sqrtwid - numex1*0.5*rfs); % exs = setstr(96*ones(1,numex1)); % x1 = e1(3) + exr*pfs - 0.5*rfs; % x2 = exr*pfs; % str = ['{\',num2str(rfs),'\up{',num2str(ofs),... % '}\nor\sym',214,'\rleft{0.549}',exs,... % '\left{',num2str(jog),'}',96,... % '\left{',num2str(x1),'}}{',arg1,... % '}\right{',num2str(x2),'}',str]; % % % Root. % elseif strcmp('root',cmd) % [arg1,str] = getcargs(str); % [arg2,str] = getcargs(str); % pfs = round(params(fs)); % nfs = sprintf('%d',pfs); % nfn = deblank(fontnamelist(params(fn),:)); % if params(fn) == 11 % nfn = 'n helvetica narrow'; % end % narg2 = ['\',nfs,'\',nfn,'{}',arg2]; % h1 = eval(['stext(0,0,narg2,''Units'',''points'',',... % '''vert'',''base'')'],'-1'); % if h1 == -1 % delete(objList) % delete(anchor) % error(lasterr) % end % e1 = getstext(h1,'Extent'); % delstext(h1) % rfs = ceil(e1(4)/0.955); % ofs = 0.038*rfs + e1(2); % exr = 0.2; % sqrtwid = e1(3) + 2*exr*pfs; % numex = sqrtwid/(rfs*0.5); % numex1 = ceil(numex) - 1; % jog = 0.5*rfs - (sqrtwid - numex1*0.5*rfs); % exs = setstr(96*ones(1,numex1)); % x1 = e1(3) + exr*pfs - 0.5*rfs; % x2 = exr*pfs; % pfs2 = round(pfs/2); % str = ['{\',num2str(rfs),'\up{',num2str(ofs),... % '}{\pushx\rup{0.56}\rright{0.17}\',... % num2str(pfs2),'{}',arg1,... % '\popx}\norm\sym',214,'\rleft{0.549}',... % exs,'\left{',num2str(jog),'}',96,... % '\left{',num2str(x1),'}}{',arg2,... % '}\right{',num2str(x2),'}',str]; % % % Fraction. % elseif strcmp('frac',cmd) % [arg1,str] = getcargs(str); % [arg2,str] = getcargs(str); % pfs = round(params(fs)); % nfs = sprintf('%d',pfs); % nfn = deblank(fontnamelist(params(fn),:)); % if params(fn) == 11 % nfn = 'n helvetica narrow'; % end % narg1 = ['\',nfs,'\',nfn,'{}',arg1]; % narg2 = ['\',nfs,'\',nfn,'{}',arg2]; % h1 = eval(['stext(0,0,narg1,''Units'',''points'',',... % '''vert'',''base'')'],'-1'); % if h1 == -1 % delete(objList) % delete(anchor) % error(lasterr) % end % e1 = getstext(h1,'Extent'); % delstext(h1) % h2 = eval(['stext(0,0,narg2,''Units'',''points'',',... % '''vert'',''base'')'],'-1'); % if h2 == -1 % delete(objList) % delete(anchor) % error(lasterr) % end % e2 = getstext(h2,'Extent'); % delstext(h2) % % if e2(3) > e1(3) % x1 = (e2(3) - e1(3))/2; % x2 = -(x1 + e1(3)); % x3 = 0; % else % x1 = 0; % x2 = -(e1(3) + e2(3))/2; % x3 = (e1(3) - e2(3))/2; % end % y1 = pfs/3 - e1(2); % y2 = -y1 - (e2(4) + e2(2)) + pfs/6; % y3 = -(y1 + y2); % % exr = 0.1; % fracwid = max(e1(3),e2(3)) + 2*exr*pfs; % numu = fracwid/(pfs*0.5); % numu1 = ceil(numu) - 1; % jog = 0.5*pfs - (fracwid - numu1*0.5*pfs); % unds = ('\_')'; % unds = unds(:,ones(numu1,1)); % unds = unds(:)'; % str = ['{\up{',num2str(y1),'}\right{',num2str(x1+exr*pfs),... % '}{',arg1,'}\up{',num2str(y2),... % '}\right{',num2str(x2),'}{',arg2,... % '}\right{',num2str(x3),'}}{\left{',... % num2str(fracwid-exr*pfs),'}\up{',... % num2str(pfs*0.4385),'}\sym',unds,... % '\left{',num2str(jog),'}\_}',str]; % % % Slashed fraction. % elseif strcmp('slash',cmd) % [arg1,str] = getcargs(str); % [arg2,str] = getcargs(str); % pfs = round(params(fs)); % ffs = round(pfs*0.625); % ffss = sprintf('%d',ffs); % str = ['{\rup{0.256}\',ffss,'{',arg1,... % '}}{\sym',164,'}{\',ffss,'{',arg2,'}}',str]; % % % Lowercase Greek letters. % elseif strcmp('alpha',cmd), str = ['{\sym a}',str]; % elseif strcmp('beta',cmd), str = ['{\sym b}',str]; % elseif strcmp('gamma',cmd), str = ['{\sym g}',str]; % elseif strcmp('delta',cmd), str = ['{\sym d}',str]; % elseif strcmp('epsilon',cmd), str = ['{\sym e}',str]; % elseif strcmp('varepsilon',cmd), str = ['{\sym e}',str]; % elseif strcmp('zeta',cmd), str = ['{\sym z}',str]; % elseif strcmp('eta',cmd), str = ['{\sym h}',str]; % elseif strcmp('theta',cmd), str = ['{\sym q}',str]; % elseif strcmp('vartheta',cmd), str = ['{\sym J}',str]; % elseif strcmp('iota',cmd), str = ['{\sym i}',str]; % elseif strcmp('kappa',cmd), str = ['{\sym k}',str]; % elseif strcmp('lambda',cmd), str = ['{\sym l}',str]; % elseif strcmp('mu',cmd), str = ['{\sym m}',str]; % elseif strcmp('nu',cmd), str = ['{\sym n}',str]; % elseif strcmp('xi',cmd), str = ['{\sym x}',str]; % elseif strcmp('pi',cmd), str = ['{\sym p}',str]; % elseif strcmp('varpi',cmd), str = ['{\sym v}',str]; % elseif strcmp('rho',cmd), str = ['{\sym r}',str]; % elseif strcmp('varrho',cmd), str = ['{\sym r}',str]; % elseif strcmp('sigma',cmd), str = ['{\sym s}',str]; % elseif strcmp('varsigma',cmd), str = ['{\sym V}',str]; % elseif strcmp('tau',cmd), str = ['{\sym t}',str]; % elseif strcmp('upsilon',cmd), str = ['{\sym u}',str]; % elseif strcmp('phi',cmd), str = ['{\sym f}',str]; % elseif strcmp('varphi',cmd), str = ['{\sym j}',str]; % elseif strcmp('chi',cmd), str = ['{\sym c}',str]; % elseif strcmp('psi',cmd), str = ['{\sym y}',str]; % elseif strcmp('omega',cmd), str = ['{\sym w}',str]; % % % Uppercase Greek letters. % elseif strcmp('Gamma',cmd), str = ['{\sym G}',str]; % elseif strcmp('Delta',cmd), str = ['{\sym D}',str]; % elseif strcmp('Theta',cmd), str = ['{\sym Q}',str]; % elseif strcmp('Lambda',cmd), str = ['{\sym L}',str]; % elseif strcmp('Xi',cmd), str = ['{\sym X}',str]; % elseif strcmp('Pi',cmd), str = ['{\sym P}',str]; % elseif strcmp('Sigma',cmd), str = ['{\sym S}',str]; % elseif strcmp('Upsilon',cmd), str = ['{\sym',161,'}',str]; % elseif strcmp('varUpsilon',cmd), str = ['{\sym U}',str]; % elseif strcmp('Phi',cmd), str = ['{\sym F}',str]; % elseif strcmp('Psi',cmd), str = ['{\sym Y}',str]; % elseif strcmp('Omega',cmd), str = ['{\sym W}',str]; % % % Other LaTeX characters. % elseif strcmp('forall',cmd), str = ['{\sym',34,'}',str]; % elseif strcmp('exists',cmd), str = ['{\sym',36,'}',str]; % elseif strcmp('cong',cmd), str = ['{\sym',64,'}',str]; % elseif strcmp('perp',cmd), str = ['{\sym\^}',str]; % elseif strcmp('bot',cmd), str = ['{\sym\^}',str]; % elseif strcmp('leq',cmd), str = ['{\sym',163,'}',str]; % elseif strcmp('infty',cmd), str = ['{\sym',165,'}',str]; % elseif strcmp('leftrightarrow',cmd), str = ['{\sym',171,'}',str]; % elseif strcmp('leftarrow',cmd), str = ['{\sym',172,'}',str]; % elseif strcmp('uparrow',cmd), str = ['{\sym',173,'}',str]; % elseif strcmp('rightarrow',cmd), str = ['{\sym',174,'}',str]; % elseif strcmp('downarrow',cmd), str = ['{\sym',175,'}',str]; % elseif strcmp('degrees',cmd), str = ['{\sym',176,'}',str]; % elseif strcmp('pm',cmd), str = ['{\sym',177,'}',str]; % elseif strcmp('geq',cmd), str = ['{\sym',179,'}',str]; % elseif strcmp('propto',cmd), str = ['{\sym',181,'}',str]; % elseif strcmp('partial',cmd), str = ['{\sym',182,'}',str]; % elseif strcmp('bullet',cmd), str = ['{\sym',183,'}',str]; % elseif strcmp('div',cmd), str = ['{\sym',184,'}',str]; % elseif strcmp('neq',cmd), str = ['{\sym',185,'}',str]; % elseif strcmp('equiv',cmd), str = ['{\sym',186,'}',str]; % elseif strcmp('approx',cmd), str = ['{\sym',187,'}',str]; % elseif strcmp('dots',cmd), str = ['{\sym',188,'}',str]; % elseif strcmp('aleph',cmd), str = ['{\sym',192,'}',str]; % elseif strcmp('Im',cmd), str = ['{\sym',193,'}',str]; % elseif strcmp('Re',cmd), str = ['{\sym',194,'}',str]; % elseif strcmp('wp',cmd), str = ['{\sym',195,'}',str]; % elseif strcmp('otimes',cmd), str = ['{\sym',196,'}',str]; % elseif strcmp('oplus',cmd), str = ['{\sym',197,'}',str]; % elseif strcmp('emptyset',cmd), str = ['{\sym',198,'}',str]; % elseif strcmp('cap',cmd), str = ['{\sym',199,'}',str]; % elseif strcmp('cup',cmd), str = ['{\sym',200,'}',str]; % elseif strcmp('supset',cmd), str = ['{\sym',201,'}',str]; % elseif strcmp('supseteq',cmd), str = ['{\sym',202,'}',str]; % elseif strcmp('notsubset',cmd), str = ['{\sym',203,'}',str]; % elseif strcmp('subset',cmd), str = ['{\sym',204,'}',str]; % elseif strcmp('subseteq',cmd), str = ['{\sym',205,'}',str]; % elseif strcmp('in',cmd), str = ['{\sym',206,'}',str]; % elseif strcmp('notin',cmd), str = ['{\sym',207,'}',str]; % elseif strcmp('angle',cmd), str = ['{\sym',208,'}',str]; % elseif strcmp('nabla',cmd), str = ['{\sym',209,'}',str]; % elseif strcmp('surd',cmd), str = ['{\sym',214,'}',str]; % elseif strcmp('cdot',cmd), str = ['{\sym',215,'}',str]; % elseif strcmp('neg',cmd), str = ['{\sym',216,'}',str]; % elseif strcmp('lnot',cmd), str = ['{\sym',216,'}',str]; % elseif strcmp('land',cmd), str = ['{\sym',217,'}',str]; % elseif strcmp('lor',cmd), str = ['{\sym',218,'}',str]; % elseif strcmp('Leftrightarrow',cmd), str = ['{\sym',219,'}',str]; % elseif strcmp('Leftarrow',cmd), str = ['{\sym',220,'}',str]; % elseif strcmp('Uparrow',cmd), str = ['{\sym',221,'}',str]; % elseif strcmp('Rightarrow',cmd), str = ['{\sym',222,'}',str]; % elseif strcmp('Downarrow',cmd), str = ['{\sym',223,'}',str]; % elseif strcmp('diamond',cmd), str = ['{\sym',224,'}',str]; % elseif strcmp('langle',cmd), str = ['{\sym',225,'}',str]; % elseif strcmp('lceil',cmd), str = ['{\sym',233,'}',str]; % elseif strcmp('lfloor',cmd), str = ['{\sym',235,'}',str]; % elseif strcmp('vert',cmd), str = ['{\sym',239,'}',str]; % elseif strcmp('rangle',cmd), str = ['{\sym',241,'}',str]; % elseif strcmp('rceil',cmd), str = ['{\sym',249,'}',str]; % elseif strcmp('rfloor',cmd), str = ['{\sym',251,'}',str]; % elseif strcmp('AA',cmd), str = [accents(10),str]; % elseif strcmp('ii',cmd), str = [accents(11),str]; % % elseif strcmp('Vert',cmd), str = ['{\sym',[247,231],'}',str]; % % elseif strcmp('{',cmd), str = ['{' + 256,str]; % elseif strcmp('}',cmd), str = ['}' + 256,str]; % elseif strcmp('\',cmd), str = ['\' + 256,str]; % elseif strcmp('^',cmd), str = ['^' + 256,str]; % elseif strcmp('_',cmd), str = ['_' + 256,str]; % % % Non-LaTeX characters and LaTeX-like constructs that don't work % % quite like they do in LaTeX. % elseif strcmp('+',cmd), str = ['{\sym+}',str]; % elseif strcmp('-',cmd), str = ['{\sym-}',str]; % elseif strcmp('=',cmd), str = ['{\sym=}',str]; % elseif strcmp('>',cmd), str = ['{\sym>}',str]; % elseif strcmp('<',cmd), str = ['{\sym<}',str]; % elseif strcmp('|',cmd), str = ['{\sym|}',str]; % elseif strcmp('therefore',cmd), str = ['{\sym\\}',str]; % elseif strcmp('prime',cmd), str = ['{\sym',162,'}',str]; % elseif strcmp('dprime',cmd), str = ['{\sym',178,'}',str]; % elseif strcmp('mult',cmd), str = ['{\sym',180,'}',str]; % elseif strcmp('horiz',cmd), str = ['{\sym',190,'}',str]; % % % Spaces. % elseif strcmp('/',cmd), str = ['\rright{0.07}',str]; % elseif strcmp(',',cmd), str = ['\rright{0.125}',str]; % elseif strcmp(':',cmd), str = ['\rright{0.1667}',str]; % elseif strcmp(';',cmd), str = ['\rright{0.2083}',str]; % % % ASCII code. % elseif strcmp('#',cmd) % [arg1,str] = getcargs(str); % str = [setstr(sscanf(arg1,'%d')),str]; % % % Diacritics. % elseif strcmp('grave',cmd) % accent = accents(1); % ww = gFONT_METRICS(gENCODING(accent+1,es),fm(params(fn),... % colLut(params(fa),params(fw))))*round(params(fs))/1000; % lr = [lastWidth,ww]*[1 1;1 -1]/2; % str = ['{\left{',num2str(lr(1)),'}',accent,... % '\right{',num2str(lr(2)),'}}',str]; % % elseif strcmp('acute',cmd) % accent = accents(2); % ww = gFONT_METRICS(gENCODING(accent+1,es),fm(params(fn),... % colLut(params(fa),params(fw))))*round(params(fs))/1000; % lr = [lastWidth,ww]*[1 1;1 -1]/2; % str = ['{\left{',num2str(lr(1)),'}',accent,... % '\right{',num2str(lr(2)),'}}',str]; % % elseif strcmp('ddot',cmd) % accent = accents(3); % ww = gFONT_METRICS(gENCODING(accent+1,es),fm(params(fn),... % colLut(params(fa),params(fw))))*round(params(fs))/1000; % lr = [lastWidth,ww]*[1 1;1 -1]/2; % str = ['{\left{',num2str(lr(1)),'}',accent,... % '\right{',num2str(lr(2)),'}}',str]; % % elseif strcmp('hat',cmd) % accent = accents(4); % ww = gFONT_METRICS(gENCODING(accent+1,es),fm(params(fn),... % colLut(params(fa),params(fw))))*round(params(fs))/1000; % lr = [lastWidth,ww]*[1 1;1 -1]/2; % str = ['{\left{',num2str(lr(1)),'}',accent,... % '\right{',num2str(lr(2)),'}}',str]; % % elseif strcmp('tilde',cmd) % accent = accents(5); % ww = gFONT_METRICS(gENCODING(accent+1,es),fm(params(fn),... % colLut(params(fa),params(fw))))*round(params(fs))/1000; % lr = [lastWidth,ww]*[1 1;1 -1]/2; % str = ['{\left{',num2str(lr(1)),'}',accent,... % '\right{',num2str(lr(2)),'}}',str]; % % elseif strcmp('bar',cmd) % accent = accents(6); % ww = gFONT_METRICS(gENCODING(accent+1,es),fm(params(fn),... % colLut(params(fa),params(fw))))*round(params(fs))/1000; % lr = [lastWidth,ww]*[1 1;1 -1]/2; % str = ['{\left{',num2str(lr(1)),'}',accent,... % '\right{',num2str(lr(2)),'}}',str]; % % elseif strcmp('breve',cmd) % accent = accents(7); % ww = gFONT_METRICS(gENCODING(accent+1,es),fm(params(fn),... % colLut(params(fa),params(fw))))*round(params(fs))/1000; % lr = [lastWidth,ww]*[1 1;1 -1]/2; % str = ['{\left{',num2str(lr(1)),'}',accent,... % '\right{',num2str(lr(2)),'}}',str]; % % elseif strcmp('dot',cmd) % accent = accents(8); % ww = gFONT_METRICS(gENCODING(accent+1,es),fm(params(fn),... % colLut(params(fa),params(fw))))*round(params(fs))/1000; % lr = [lastWidth,ww]*[1 1;1 -1]/2; % str = ['{\left{',num2str(lr(1)),'}',accent,... % '\right{',num2str(lr(2)),'}}',str]; % % elseif strcmp('check',cmd) % accent = accents(9); % ww = gFONT_METRICS(gENCODING(accent+1,es),fm(params(fn),... % colLut(params(fa),params(fw))))*round(params(fs))/1000; % lr = [lastWidth,ww]*[1 1;1 -1]/2; % str = ['{\left{',num2str(lr(1)),'}',accent,... % '\right{',num2str(lr(2)),'}}',str]; % % elseif strcmp('Grave',cmd) % accent = accents(1); % ww = gFONT_METRICS(gENCODING(accent+1,es),fm(params(fn),... % colLut(params(fa),params(fw))))*round(params(fs))/1000; % lr = [lastWidth,ww]*[1 1;1 -1]/2; % str = ['{\rup{.2}\left{',num2str(lr(1)),'}',accent,... % '\right{',num2str(lr(2)),'}}',str]; % % elseif strcmp('Acute',cmd) % accent = accents(2); % ww = gFONT_METRICS(gENCODING(accent+1,es),fm(params(fn),... % colLut(params(fa),params(fw))))*round(params(fs))/1000; % lr = [lastWidth,ww]*[1 1;1 -1]/2; % str = ['{\rup{.2}\left{',num2str(lr(1)),'}',accent,... % '\right{',num2str(lr(2)),'}}',str]; % % elseif strcmp('Ddot',cmd) % accent = accents(3); % ww = gFONT_METRICS(gENCODING(accent+1,es),fm(params(fn),... % colLut(params(fa),params(fw))))*round(params(fs))/1000; % lr = [lastWidth,ww]*[1 1;1 -1]/2; % str = ['{\rup{.2}\left{',num2str(lr(1)),'}',accent,... % '\right{',num2str(lr(2)),'}}',str]; % % elseif strcmp('Hat',cmd) % accent = accents(4); % ww = gFONT_METRICS(gENCODING(accent+1,es),fm(params(fn),... % colLut(params(fa),params(fw))))*round(params(fs))/1000; % lr = [lastWidth,ww]*[1 1;1 -1]/2; % str = ['{\rup{.2}\left{',num2str(lr(1)),'}',accent,... % '\right{',num2str(lr(2)),'}}',str]; % % elseif strcmp('Tilde',cmd) % accent = accents(5); % ww = gFONT_METRICS(gENCODING(accent+1,es),fm(params(fn),... % colLut(params(fa),params(fw))))*round(params(fs))/1000; % lr = [lastWidth,ww]*[1 1;1 -1]/2; % str = ['{\rup{.2}\left{',num2str(lr(1)),'}',accent,... % '\right{',num2str(lr(2)),'}}',str]; % % elseif strcmp('Bar',cmd) % accent = accents(6); % ww = gFONT_METRICS(gENCODING(accent+1,es),fm(params(fn),... % colLut(params(fa),params(fw))))*round(params(fs))/1000; % lr = [lastWidth,ww]*[1 1;1 -1]/2; % str = ['{\rup{.2}\left{',num2str(lr(1)),'}',accent,... % '\right{',num2str(lr(2)),'}}',str]; % % elseif strcmp('Breve',cmd) % accent = accents(7); % ww = gFONT_METRICS(gENCODING(accent+1,es),fm(params(fn),... % colLut(params(fa),params(fw))))*round(params(fs))/1000; % lr = [lastWidth,ww]*[1 1;1 -1]/2; % str = ['{\rup{.2}\left{',num2str(lr(1)),'}',accent,... % '\right{',num2str(lr(2)),'}}',str]; % % elseif strcmp('Dot',cmd) % accent = accents(8); % ww = gFONT_METRICS(gENCODING(accent+1,es),fm(params(fn),... % colLut(params(fa),params(fw))))*round(params(fs))/1000; % lr = [lastWidth,ww]*[1 1;1 -1]/2; % str = ['{\rup{.2}\left{',num2str(lr(1)),'}',accent,... % '\right{',num2str(lr(2)),'}}',str]; % % elseif strcmp('Check',cmd) % accent = accents(9); % ww = gFONT_METRICS(gENCODING(accent+1,es),fm(params(fn),... % colLut(params(fa),params(fw))))*round(params(fs))/1000; % lr = [lastWidth,ww]*[1 1;1 -1]/2; % str = ['{\rup{.2}\left{',num2str(lr(1)),'}',accent,... % '\right{',num2str(lr(2)),'}}',str]; % % elseif strcmp('pushx',cmd) % xstack = [params([x;nextX]),xstack]; % % elseif strcmp('popx',cmd) % if size(xstack,2) < 1 % delete(objList) % delete(anchor) % error('Stack empty.') % end % params(x) = xstack(1); % params(nextX) = xstack(2); % xstack(:,1) = []; % % elseif strcmp('swapx',cmd) % if size(xstack,2) < 2 % delete(objList) % delete(anchor) % error('Stack does not contain at least two items.') % end % temp = xstack(:,1); % xstack(:,[1,2]) = xstack(:,[2,1]); % % else % % Command is unknown. % delete(objList) % delete(anchor) % error(['Unrecognized command: ',cmd]) % % end % else % % str(1) is not one of '{}^_\' so it must be the beginning of text. % params(x) = params(nextX); % params(mode) = 0; % [newStr,str] = strtok(str,'\{}^_'); % newStr = setstr(rem(newStr,256)); % newStr1 = newStr + 1; % % % Compute character widths. % strLen = length(newStr); % fmSel = fm(params(fn),colLut(params(fa),params(fw))); % if fmSel > 2 % encSel = es; % else % encSel = fmSel; % end % fontOffset = 1000*(fmSel - 2); % widths = gFONT_METRICS(gENCODING(newStr1,encSel),fmSel) * ... % round(params(fs))/1000; % % % Increase widths by 4.5% if Symbol-Bold. % if params(fn) == 1 & params(fw) == 4 % widths = 1.045*widths; % end % % lastWidth = widths(length(widths)); % % % Compute kern correction, kc. % kc = zeros(strLen-1,1); % if fmSel > 2 % for k = 1:strLen-1 % kc(k) = gKERNING_DATA(fontOffset + gENCODING(newStr1(k),... % encSel),gENCODING(newStr1(k+1),encSel)); % end % kc = kc*round(params(fs))/1000; % end % % xx = params(x) + cumsum([0;widths((1:strLen-1)') + kc]); % yy = params(y(ones(strLen,1))); % lastxx = xx(strLen); % % % Add shifted versions of the characters if they are Symbol-Bold. % % Total width increase is 4.5%. % if params(fn) == 1 & params(fw) == 4 % xsh = 0.015*round(params(fs)); % xx = [xx;xx + xsh;xx + 2*xsh;xx + 3*xsh]; % yy = [yy;yy;yy;yy]; % newStr = [newStr,newStr,newStr,newStr]; % strLen = length(newStr); % params(fw) = 2; % end % % % Prepend invisible characters if Symbol italic or oblique. This % % can be detected in the PostScript file so that it can be modified % % to produce slanted Symbol characters. % if params(fn) == 1 & params(fa) > 1 % if ~slantTagged % xx = [0;0;0;xx]; % yy = [0;0;0;yy]; % newStr = setstr([9,9,9,newStr]); % strLen = length(newStr); % slantTagged = 1; % end % else % slantTagged = 0; % end % % if strLen == 1 % newObj = text('Position', [xx,yy],... % 'String', newStr,... % 'FontAngle', fontanglelist(params(fa),:),... % 'FontName', deblank(fontnamelist(params(fn),:)),... % 'FontSize', round(params(fs)),... % 'FontWeight', fontweightlist(params(fw),:),... % 'Units', 'points',... % 'Rotation', 0,... % 'HorizontalAlignment', 'left',... % 'VerticalAlignment', 'baseline',... % 'Color', params(cr:cb),... % 'EraseMode', eraseMode,... % 'ButtonDownFcn', buttonDownFcn,... % 'Clipping', clipping,... % 'Interruptible', interruptible,... % 'Visible', visible); % else % newObj = text(xx,yy,newStr',... % 'FontAngle', fontanglelist(params(fa),:),... % 'FontName', deblank(fontnamelist(params(fn),:)),... % 'FontSize', round(params(fs)),... % 'FontWeight', fontweightlist(params(fw),:),... % 'Units', 'points',... % 'Rotation', 0,... % 'HorizontalAlignment', 'left',... % 'VerticalAlignment', 'baseline',... % 'Color', params(cr:cb),... % 'EraseMode', eraseMode,... % 'ButtonDownFcn', buttonDownFcn,... % 'Clipping', clipping,... % 'Interruptible', interruptible,... % 'Visible', visible); % end % if ver5, set(newObj,'Interpreter','none'), end % objList = [objList,newObj']; % heightList = [heightList,yy']; % xDistance = [xDistance,xx']; % params(nextX) = lastxx + lastWidth; % params(x) = params(nextX); % % % The vertical position of the styled text is based on the first % % character of the text. % if first % if cmdmatch('top',vertAlign) % va = 1; % elseif cmdmatch('cap',vertAlign) % va = 2; % elseif cmdmatch('middle',vertAlign) % va = 3; % elseif cmdmatch('baseline',vertAlign) % va = 4; % elseif cmdmatch('bottom',vertAlign) % va = 5; % end % hOffset = -gVAL(fmSel,va)*round(params(fs)); % first = 0; % end % end %end %totalWidth = params(nextX); %numSegments = length(objList); % %% Compute new x and y locations for each text object based on %% justification and rotation. %r = rotation*pi/180; %if cmdmatch('left',horizAlign) % t = 0; %elseif cmdmatch('center',horizAlign) % t = totalWidth/2; %elseif cmdmatch('right',horizAlign) % t = totalWidth; %end %xList = x0 + (xDistance - t)*cos(r) - (heightList + hOffset)*sin(r); %yList = y0 + (xDistance - t)*sin(r) + (heightList + hOffset)*cos(r); % %for i = 1:numSegments % set(objList(i),'Position',[xList(i),yList(i)],'Rotation',rotation); %end % %% Anchor text object is invisible, but by setting the rotation we can %% use get(stext object handle). UserData contains a type flag (0 = %% normal, 1 = x-label, 2 = y-label, 3 = z-label, 4 = title), the %% location of the anchor object in points and a list of the handles %% to the text objects that make up the styled text object. % %set(anchor,'Rotation',rotation,'UserData',[0,x0,y0,objList]) %delete(oldObjList) % %% Restore current axes. %set(fig,'CurrentAxes',currentAxes) fclose(fout); disp(' ## Installing: "slegend.m" (text)') fout = fopen('slegend.m', 'w'); %function [leg,hl,h] = slegend(xy,specs,strs,p1,v1,p2,v2,... % p3,v3,p4,v4,p5,v5,p6,v6,p7,v7) %%SLEGEND Styled text legend. %% SLEGEND(XY,SMPLSPEC,LEGENDTEXT) places a legend centered at XY = %% [X,Y] on the current figure, where X and Y are in normalized figure %% units. LEGENDTEXT is a string matrix (see STR2MAT) which specifies %% the text of the legend. The legend text is produced with STEXT and %% so each row of LEGENDTEXT must be valid styled text. SMPLSPEC can be %% a string matrix of plot symbols and colors as with PLOT. An additional %% plot symbol is '#' which specifies a sample patch. Valid values for %% the rows of SMPLSPEC are '-', '--r', 'c+', '#y', etc. SMPLSPEC can %% also be a vector of handles to line or patch objects, in which case %% the characteristics of the line or patch samples are copied from %% those objects. %% %% XY = 'mouse' allows dragging the slegend to the desired location with %% the mouse. The slegend can be locked in position by pressing the %% space bar while holding down the mouse button. SLEGEND('move') or %% SLEGEND('mouse') will make all slegends and stextboxes in the current %% figure movable. %% %% XY, SMPLSPEC and LEGENDTEXT can be followed by property/value pairs %% to specify additional properties of the slegend: %% %% Property = 'Color', value = [ {none} ] -or- a ColorSpec %% allows you to specify the background color of the slegend. If %% the color is 'none', the box will be transparent. When printed, %% slegends are placed on top of other axes and opaque slegends will %% obscure whatever is behind them. %% %% Property = 'HorizontalAlignment', value = [ left | {center} | right ] %% controls the horizontal alignment of the slegend with respect to XY. %% %% Property = 'VerticalAlignment', value = [ top | {middle} | bottom ] %% controls the vertical alignment of the slegend with respect to XY. %% %% Property = 'Box', value = [ {on} | off ] %% allows you to control whether the enclosing box is visible. %% %% Property = 'BorderFactor', value = [ {0.25} | ] %% sets the amount of space between the slegend and the enclosing %% box as a fraction of the height of the tallest line of text. %% %% Property = 'SampleWidth', value = [ {30} | ] %% sets the width in points of the line samples. %% %% Property = 'Spacing', value = [ tight | {loose} | ] %% controls the line spacing of the text. Tight spacing moves the %% lines as close together as possible, loose spacing makes all %% lines equally spaced and equal to the height of the tallest line. %% Setting this to a number specifies tight spacing scaled by the %% amount specified. For example, 1 => normal tight spacing, %% 0.5 => lines compressed to 50% of normal. %% %% %% [H,HLINES,HTEXT] = SLEGEND(...) returns a handle to the legend axes %% object, handles to the line samples and handles to the legend text. %% Since a legend is an axes object it is possible to make changes to %% its properties, e.g., changing the 'LineWidth' of the border. %% %% A figure containing an SLEGEND must be printed with PRINTSTO. %% %% See also STEXT, STEXTBOX, PRINTSTO, STR2MAT and PLOT. % %% Requires functions STEXT, GETSTEXT and MOVE1STO. %% Requires MATLAB Version 4.2 or greater. % %% Version 3.2b, 2 July 1997 %% Part of the Styled Text Toolbox %% Copyright 1995-1997 by Douglas M. Schwarz. All rights reserved. %% schwarz@kodak.com % %if nargin > 1 % % Set defaults. % mouse = 0; % legColor = 'none'; % horiz = 0.5; % vert = 0.5; % ref = [0.5,0.5]; % box = 'on'; % borderFactor = 0.25; % sampleWid = 30; % tightSpacing = 0; % numOptions = (nargin - 3)/2; % baseAxes = gca; % ver5 = cmdmatch(version,'5'); % % if isstr(xy) % if strcmp(lower(xy),'mouse') % mouse = 1; % xy = [0.5,0.5]; % else % error('Unknown position option.') % end % else % if length(xy) ~= 2 % error('The position must be a 2-element vector') % end % end % % for i = 1:numOptions % property = lower(eval(sprintf('p%d',i))); % value = lower(eval(sprintf('v%d',i))); % % if cmdmatch('color',property) % legColor = value; % % elseif cmdmatch('horizontalalignment',property) % horiz = value; % % elseif cmdmatch('verticalalignment',property) % vert = value; % % elseif cmdmatch('box',property) % box = value; % % elseif cmdmatch('borderfactor',property) % borderFactor = value; % % elseif cmdmatch('samplewidth',property) % sampleWid = value; % % elseif cmdmatch('spacing',property) % if isstr(value) % if cmdmatch('tight',value) % tightSpacing = 1; % elseif cmdmatch('loose',value) % tightSpacing = 0; % else % error('Invalid data for slegend parameter "Spacing".') % end % else % tightSpacing = value; % end % % else % error('Unknown property.') % end % end % % if isstr(horiz) % if cmdmatch('left',horiz) % ref(1) = 0; % elseif cmdmatch('right',horiz) % ref(1) = 1; % elseif cmdmatch('center',horiz) % ref(1) = 0.5; % else % error('Invalid data for slegend parameter "HorizontalAlignment".') % end % else % ref(1) = horiz; % end % % if isstr(vert) % if cmdmatch('bottom',vert) % ref(2) = 0; % elseif cmdmatch('top',vert) % ref(2) = 1; % elseif cmdmatch('middle',vert) % ref(2) = 0.5; % else % error('Invalid data for slegend parameter "VerticalAlignment".') % end % else % ref(2) = vert; % end % % % Create the legend axes and contents. % ax = axes('Units','norm','Position',[xy,0.5,0.5],... % 'XTick',[],'YTick',[],'Box','on','Color',legColor); % if strcmp(box,'off') % if strcmp(legColor,'none') % set(ax,'Visible','off') % else % set(ax,'XColor',legColor,'YColor',legColor,'ZColor',legColor) % end % end % % set(ax,'Units','points') % xy2 = get(ax,'Position'); % xy2(3:4) = []; % n = min(size(specs,1),size(strs,1)); % h = zeros(n,1); % exts = zeros(n,4); % for i = 1:n % cmd = ['stext(0,0,deblank(strs(i,:)),''units'',''points'',',... % '''hor'',''left'',''vert'',''mid'')']; % h(i) = eval(cmd,'-1'); % if h(i) == -1 % delete(ax) % error(lasterr) % end % exts(i,:) = getstext(h(i),'Extent'); % end % % % Compute the size of the axes based on the contents. % maxht = max(exts(:,4)); % maxdrop = min(exts(:,2)); % border = maxht*borderFactor; % hgap = 0.25*maxht; % if tightSpacing % yvals = flipud([0;cumsum(exts(n:-1:2,4))])*tightSpacing ... % - exts(:,2) + border; % top = yvals(1) + exts(1,4) + exts(1,2) + border + 1; % else % yvals = flipud(maxht*(0:(n-1))') - min(exts(:,2)) + border; % top = yvals(1) + maxht + maxdrop + border + 1; % end % left = sampleWid + 2*border + hgap; % right = left + max(exts(:,3)) + 2*border; % % % Move the contents to their final positions and set the new size % % for the legend axes. % for i = 1:n % delta = yvals(i); % userData = get(h(i),'UserData'); % userData(3) = userData(3) + delta; % set(h(i),'Position',[0,delta]) % set(h(i),'UserData',userData) % move1sto(h(i),[left,delta]) % end % pos = get(ax,'Position'); % xy3 = xy2 - [right,top].*ref; % set(ax,'Position',[xy3,right,top],... % 'XLim',[0 right],'YLim',[0 top]) % % % Plot the line type samples. % hl = zeros(n,1); % if isstr(specs) % for i = 1:n % lt = deblank(specs(i,:)); % color = get(0,'DefaultTextColor'); % colorSpec = lt == 'r' | lt == 'g' | lt == 'b' | lt == 'c' ... % | lt == 'm' | lt == 'y' | lt == 'w' | lt == 'k'; % if any(colorSpec), color = lt(colorSpec); end % lt(colorSpec) = []; % if strcmp(lt,'-') | strcmp(lt,'--') | strcmp(lt,'-.') ... % | strcmp(lt,':') % x = [0,sampleWid] + 2*border; % y = [1,1]*yvals(i); % hl(i) = line(x,y,'LineStyle',lt,'Color',color); % elseif strcmp(lt,'#') % x = [-1 1 1 -1]*sampleWid/3 + 2*border + sampleWid/2; % y = [-1 -1 1 1]*maxht/3 + yvals(i); % hl(i) = patch(x,y,'r','FaceColor',color); % else % if ver5 % hl(i) = line(2*border+sampleWid/2,yvals(i),... % 'LineStyle','none','Marker',lt,'Color',color); % else % hl(i) = line(2*border+sampleWid/2,yvals(i),... % 'LineStyle',lt,'Color',color); % end % end % end % else % for i = 1:n % objType = get(specs(i),'Type'); % if strcmp(objType,'line') % if ver5 % lt = get(specs(i),'LineStyle'); % mt = get(specs(i),'Marker'); % tmpl = 0; % tmpm = 0; % if ~strcmp(lt,'none') % tmpl = line([0,sampleWid]+2*border,[1 1]*yvals(i),... % 'LineStyle',lt,... % 'Marker','none',... % 'LineWidth',get(specs(i),'LineWidth'),... % 'Color',get(specs(i),'Color')); % end % if ~strcmp(mt,'none') % tmpm = line(2*border+sampleWid/2,yvals(i),... % 'LineStyle','none',... % 'Marker',mt,... % 'LineWidth',get(specs(i),'LineWidth'),... % 'MarkerSize',get(specs(i),'MarkerSize'),... % 'MarkerEdgeColor',... % get(specs(i),'MarkerEdgeColor'),... % 'MarkerFaceColor',... % get(specs(i),'MarkerFaceColor'),... % 'Color',get(specs(i),'Color')); % end % if tmpl % hl(i) = tmpl; % else % hl(i) = tmpm; % end % else % lt = get(specs(i),'LineStyle'); % if strcmp(lt,'-') | strcmp(lt,'--') | strcmp(lt,'-.') ... % | strcmp(lt,':') % hl(i) = line([0,sampleWid]+2*border,[1 1]*yvals(i),... % 'LineStyle',lt,... % 'LineWidth',get(specs(i),'LineWidth'),... % 'MarkerSize',get(specs(i),'MarkerSize'),... % 'Color',get(specs(i),'Color')); % else % hl(i) = line(2*border+sampleWid/2,yvals(i),... % 'LineStyle',lt,... % 'LineWidth',get(specs(i),'LineWidth'),... % 'MarkerSize',get(specs(i),'MarkerSize'),... % 'Color',get(specs(i),'Color')); % end % end % elseif strcmp(objType,'patch') % x = [-1 1 1 -1]*sampleWid/3 + 2*border + sampleWid/2; % y = [-1 -1 1 1]*maxht/3 + yvals(i); % hl(i) = patch(x,y,'r',... % 'FaceColor',get(specs(i),'FaceColor'),... % 'EdgeColor',get(specs(i),'EdgeColor'),... % 'LineWidth',get(specs(i),'LineWidth')); % else % delete(ax) % error(['Illegal object of type ''',objType,'''.']) % end % end % end % % % Save some needed data and enable legend dragging. % userData = [xy,ref]; % if mouse % set(ax,'Tag','slegend movable','UserData',userData) % set(gcf,'WindowButtonDownFcn','slegend(1)') % else % set(ax,'Tag','slegend','UserData',userData) % end % set(gcf,'CurrentAxes',baseAxes) % % if nargout > 0 % leg = ax; % end % %elseif isstr(xy) % xy = lower(xy); % if strcmp(xy,'move') | strcmp(xy,'mouse') % fig = get(0,'CurrentFigure'); % fixed = findobj(fig,'Tag','slegend'); % nf = length(fixed); % nm = length(findobj(fig,'Tag','slegend movable')); % for i = 1:nf % set(fixed(i),'Tag','slegend movable') % end % if nf + nm > 0 % set(gcf,'WindowButtonDownFcn','slegend(1)') % end % else % error('Unknown command.') % end % %% We have a mouse-down on a legend. %elseif xy == 1 % fig = get(0,'CurrentFigure'); % % Uncomment the following line to require holding down the control key % % (or option on a Mac) while clicking the mouse to move a legend. % %if ~strcmp(get(fig,'SelectionType'),'alt'), return, end % curAx = get(fig,'CurrentAxes'); % % figUnits = get(fig,'Units'); % figPos = get(fig,'Position'); % set(fig,'Units','points') % cp = get(fig,'CurrentPoint'); % % % Find the legend closest to current point. % movLeg = findobj(fig,'Tag','slegend movable'); % n = length(movLeg); % if n == 0 % set(fig,'Units',figUnits,'Position',figPos,'WindowButtonDownFcn','') % return % end % d2 = zeros(n,1); % for i = 1:n % pos = get(movLeg(i),'Position'); % d = cp - pos(1:2); % d2(i) = d*d'; % end % [junk,closest] = min(d2); % theLeg = movLeg(closest); % % userData = get(theLeg,'UserData'); % set(theLeg,'UserData',[userData(1:4),cp,real(figUnits)],... % 'Tag','slegend moving') % set(fig,'CurrentAxes',theLeg,'CurrentAxes',curAx,... % 'WindowButtonMotionFcn','slegend(2)',... % 'WindowButtonUpFcn','slegend(3)',... % 'KeyPressFcn','slegend(4)',... % 'pointer','fleur') % %% Moving a legend. %elseif xy == 2 % fig = get(0,'CurrentFigure'); % theLeg = findobj(fig,'Tag','slegend moving'); % userData = get(theLeg,'UserData'); % cp = userData(5:6); % newp = get(fig,'CurrentPoint'); % userData(5:6) = newp; % delta = newp - cp; % pos = get(theLeg,'Position'); % pos(1:2) = pos(1:2) + delta; % set(theLeg,'Position',pos,'UserData',userData) % %% We have a mouse-up on a legend. %elseif xy == 3 % fig = get(0,'CurrentFigure'); % theLeg = findobj(fig,'Tag','slegend moving'); % userData = get(theLeg,'UserData'); % set(theLeg,'Units','norm') % pos = get(theLeg,'Position'); % set(theLeg,'Units','points') % ref = userData(3:4); % userData(1:2) = pos(1:2) + ref.*pos(3:4); % set(theLeg,'UserData',userData,'Tag','slegend movable') % figUnits = setstr(userData(7:length(userData))); % set(fig,'Units',figUnits,'pointer','arrow',... % 'WindowButtonMotionFcn','','WindowButtonUpFcn','',... % 'KeyPressFcn','') % %% We are locking the position of a legend. %elseif xy == 4 % fig = get(0,'CurrentFigure'); % theLeg = findobj(fig,'Tag','slegend moving'); % if get(fig,'CurrentCharacter') == ' ' % if length(findobj(fig,'Tag','slegend movable')) == 0 % set(fig,'WindowButtonDownFcn','') % end % userData = get(theLeg,'UserData'); % set(theLeg,'Units','norm') % pos = get(theLeg,'Position'); % set(theLeg,'Units','points') % ref = userData(3:4); % userData(1:2) = pos(1:2) + ref.*pos(3:4); % set(theLeg,'UserData',userData,'Tag','slegend') % figUnits = setstr(userData(7:length(userData))); % set(fig,'Units',figUnits,'pointer','arrow',... % 'WindowButtonMotionFcn','','WindowButtonUpFcn','',... % 'KeyPressFcn','') % end %end fclose(fout); disp(' ## Installing: "spreview.m" (text)') fout = fopen('spreview.m', 'w'); %function spreview(sel) %%SPREVIEW GUI application to preview styled text objects. %% SPREVIEW will create a new figure which contains an edit box in %% which styled text can be typed and an axes to display the resulting %% styled text object. This can be used to construct styled text %% objects, especially complicated ones. %% %% SPREVIEW(STYLEDTEXT) uses the styled text in STYLEDTEXT as the %% initial contents of the edit box. %% %% See also STEXT. % %% Requires functions STEXT and FIXSTEXT. %% Requires MATLAB Version 4.2 or greater. % %% Version 3.2b, 10 March 1997 %% Part of the Styled Text Toolbox %% Copyright 1995-1997 by Douglas M. Schwarz. All rights reserved. %% schwarz@kodak.com % %if nargin == 0 % sel = 0; % s = ''; %elseif nargin == 1 % if isstr(sel) % s = sel; % sel = 0; % end %end % %if sel == 0 % this = mfilename; % fig = figure('Number','off','Name',this); % set(fig,'Units','pixels') % figpos = get(fig,'Position'); % % framePos = [16,16,figpos(3)-32,68]; % editPos = [20,20,figpos(3)-40,40]; % textPos = [20,60,figpos(3)-40,20]; % makePos = [figpos(3)-150,62,40,20]; % clearPos = [figpos(3)-106,62,40,20]; % savePos = [figpos(3)-62,62,40,20]; % axPos = [17,92,figpos(3)-32,figpos(4)-98]; % % hf = uicontrol('Style','frame',... % 'Units','pixels',... % 'Position',framePos); % he = uicontrol('Style','edit',... % 'Units','pixels',... % 'Position',editPos,... % 'String',s,... % 'Horiz','left',... % 'CallBack',[this,'(1)']); % ht = uicontrol('Style','text',... % 'Units','pixels',... % 'Position',textPos,... % 'String','Type styled text here and press Make or RETURN:',... % 'Horiz','left'); % hm = uicontrol('Style','pushbutton',... % 'Units','pixels',... % 'Position',makePos,... % 'String','Make',... % 'CallBack',[this,'(1)']); % hc = uicontrol('Style','pushbutton',... % 'Units','pixels',... % 'Position',clearPos,... % 'String','Clear',... % 'CallBack','cla'); % hs = uicontrol('Style','pushbutton',... % 'Units','pixels',... % 'Position',savePos,... % 'String','Save',... % 'CallBack','get(findobj(gcf,''Style'',''edit''),''String'')'); % ax = axes('Units','pixels',... % 'Position',axPos,... % 'XTick',[],'YTick',[],... % 'Box','on',... % 'XLim',[0 1],'YLim',[0 1]); % set(fig,'UserData',[hf he ht hm hc hs ax]) % eval(['set(fig,''ResizeFcn'',''',this,'(2)'')'],'') % %% Pressed RETURN or Make, create new styled text. %elseif sel == 1 % fig = gcf; % cla % refresh % h = get(fig,'UserData'); % str = get(h(2),'String'); % stext(.5,.5,str,'Horiz','center'); % %% Resizing the figure. %elseif sel == 2 % fig = gcf; % figpos = get(fig,'Position'); % % framePos = [16,16,figpos(3)-32,68]; % editPos = [20,20,figpos(3)-40,40]; % textPos = [20,60,figpos(3)-40,20]; % makePos = [figpos(3)-150,62,40,20]; % clearPos = [figpos(3)-106,62,40,20]; % savePos = [figpos(3)-62,62,40,20]; % axPos = [17,92,figpos(3)-32,figpos(4)-98]; % % h = get(fig,'UserData'); % % set(h(1),'Position',framePos) % set(h(2),'Position',editPos) % set(h(3),'Position',textPos) % set(h(4),'Position',makePos) % set(h(5),'Position',clearPos) % set(h(6),'Position',savePos) % set(h(7),'Position',axPos) % % fixstext %end fclose(fout); disp(' ## Installing: "stext.m" (text)') fout = fopen('stext.m', 'w'); %function output = stext(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,... % a15,a16,a17,a18,a19,a20,a21,a22,a23,a24,a25,a26,a27,a28) %%STEXT Add Styled Text to the current plot. %% STEXT(X,Y,'string') adds the styled text in the quotes to location %% (X,Y) on the current axes in a manner similar to the TEXT function. %% Most of the same property/value pairs that can be used with TEXT %% will work with STEXT. The styling information is embedded in the %% string in the form of commands which are preceeded by backslashes %% and terminated by a space, another backslash or a brace. The %% commands control font, font size, font angle, font weight, color, %% superscript and subscript attributes. A command is normally %% applied to all subsequent text except that temporary changes can be %% assigned inside curly braces. Font names and style changing %% commands can be abbreviated. Also, many characters from the Symbol %% font can be produced by using backslash names (mostly the same %% names used in LaTeX). %% %% Command Summary %% \ \bigger \larger \smaller %% \ %% \italic \oblique \light \demi \bold \normal %% ^{} _{} %% \black \white \red \green \blue \cyan \magenta \yellow \gray %% \color{,,} %% \left{} \right{} \up{} \down{} %% \rleft{} \rright{} \rup{} \rdown{} %% \\ \{ \} \^ \_ \= \+ \- \< \< \#{} %% %% Character Summary %% \, e.g., \alpha to produce lowercase Greek letters %% \, e.g., \Gamma to produce uppercase Greek letters %% \forall \pm \aleph \subset \Leftrightarrow %% \exists \geq \Im \subseteq \Leftarrow %% \cong \propto \Re \in \Uparrow %% \perp \partial \wp \notin \Rightarrow %% \bot \bullet \otimes \angle \Downarrow %% \leq \div \oplus \nabla \diamond %% \infty \neq \emptyset \surd \langle %% \leftrightarrow \equiv \cap \cdot \lceil %% \leftarrow \approx \cup \neg \lfloor %% \uparrow \dots \supset \lnot \rangle %% \rightarrow \vert \supseteq \land \rceil %% \downarrow \Vert \notsubset \lor \rfloor %% \degrees %% %% \therefore \prime \dprime \slash \mult \horiz %% %% \grave \acute \ddot \hat \tilde \bar \breve \dot \check %% \Grave \Acute \Ddot \Hat \Tilde \Bar \Breve \Dot \Check %% %% \int{}{} \sum{}{} \prod{}{} %% \frac{}{} \sqrt{} \root{}{} %% %% Examples: %% STEXT(X,Y,'\18\times This text will be 18-point Times.') %% STEXT(X,Y,'The word {\italic italic} will be in italics.') %% STEXT(X,Y,'Einstein''s famous equation: E = mc^2') %% STEXT(X,Y,'\18\times The resistance is 12 k\Omega.') %% %% STEXT(X,Y,Z,'string') adds text in 3-D coordinates. %% %% Because of the way styled text objects are created, it is necessary %% to reposition them using FIXSTEXT when a figure is resized or the %% axes are changed (including changing the view in 3-D). Also, they %% must be printed with PRINTSTO. %% %% STEXT returns a handle to an STEXT object. STEXT objects are %% children of AXES objects. %% %% The X,Y pair (X,Y,Z triple for 3-D) can be followed by %% parameter/value pairs to specify additional properties of the text. %% The X,Y pair (X,Y,Z triple for 3-D) can be omitted entirely, and %% all properties specified using parameter/value pairs. %% %% See also SXLABEL, SYLABEL, SZLABEL, STITLE, DELSTEXT, PRINTSTO, %% SETSTEXT, FIXSTEXT and the accompanying README document. % %% Requires functions CMDMATCH, GETCARGS and READSTFM and MAT-file %% STFM.MAT or the text version STFM.TXT. %% Requires MATLAB Version 4.2 or greater. % %% Version 3.2b, 10 March 1997 %% Part of the Styled Text Toolbox %% Copyright 1995-1997 by Douglas M. Schwarz. All rights reserved. %% schwarz@kodak.com % %% Define gFONT_METRICS, gKERNING_DATA, gENCODING, gACCENTS, gENC_SEL %% and gVAL as global variables (operating as static variables) so we %% only have to load them the first time stext is run. %global gFONT_METRICS gKERNING_DATA gENCODING gACCENTS gENC_SEL gVAL %if length(gFONT_METRICS) == 0 % stextfun = which('stext'); % stextfun((length(stextfun) - 6):length(stextfun)) = []; % % If MAT-file exists then load it, otherwise load data from text file % % and create MAT-file (which is faster to load) for future use. % if exist([stextfun,'stfm.mat']) == 2 % load([stextfun,'stfm.mat']) % else % [gFONT_METRICS,gKERNING_DATA,gENCODING,gACCENTS,gENC_SEL,gVAL] = ... % readstfm; % % savedir = stextfun; % tempfid = fopen([savedir,'stfm.mat'],'w'); % if tempfid == -1 % savedir = [pwd,stextfun(length(stextfun))]; % else % fclose(tempfid); % delete([savedir,'stfm.mat']) % end % save([savedir,'stfm.mat'],'gFONT_METRICS','gKERNING_DATA',... % 'gENCODING','gACCENTS','gENC_SEL','gVAL') % if tempfid == -1 % fprintf('Unable to save font metrics MAT-file\n') % fprintf('\t%s\n\n',[stextfun,'stfm.mat']) % fprintf('File saved as\n\t%s\n\n',[savedir,'stfm.mat']) % fprintf('For faster operation and to avoid seeing this ') % fprintf('message, have\nyour system administrator move this ') % fprintf('file to the directory\n\t%s\n',stextfun) % end % end %end %% Determine encoding selector, es, depending on platform. %if gENC_SEL == 0 % comp = computer; % if cmdmatch(comp,'MAC') % es = 3; % elseif cmdmatch(comp,'PC') % es = 4; % else % es = 5; % end %else % es = gENC_SEL; %end %nacc = length(gACCENTS); %accents = 32*ones(1,nacc); %for i = 1:nacc % loc = find(gENCODING(:,es) == gACCENTS(i)); % if ~isempty(loc) % accents(i) = max(loc) - 1; % end %end % %% Figure out what the input arguments are. %if nargin >= 4 % flags = [isstr(a1),isstr(a2),isstr(a3),isstr(a4)]; %elseif nargin == 3 % flags = [isstr(a1),isstr(a2),isstr(a3),-1]; %elseif nargin == 2 % flags = [isstr(a1),isstr(a2),-1,-1]; %elseif nargin == 1 % error('Not enough input arguments.') %else % flags = [-1,-1,-1,-1]; %end % %% From flags, determine which argument is the first property name %% and how many property/value pairs are present. %if all(flags == [0 0 0 1]) % firstOpt = 5; % numOptions = (nargin - 4)/2; %elseif all(flags == [0 0 1 1]) % firstOpt = 4; % numOptions = (nargin - 3)/2; %elseif all(flags == [0 0 1 -1]) % firstOpt = 4; % numOptions = 0; %elseif flags(1) == 1 % firstOpt = 1; % numOptions = nargin/2; %elseif all(flags == -1) % numOptions = 0; %else % error('Incorrect property/value pairs.') %end % %% Build initial text command. %if nargin == 0 % textCmd = 'text'; %else % textCmd = 'text('; % if firstOpt == 4 % textCmd = [textCmd,'''Position'',[a1,a2],''String'',a3,']; % elseif firstOpt == 5 % textCmd = [textCmd,'''Position'',[a1,a2,a3],''String'',a4,']; % end % for i = firstOpt:nargin % textCmd = [textCmd,sprintf('a%d,',i)]; % end % textCmd(length(textCmd)) = ')'; %end %anchor = eval(textCmd); %set(anchor,'Tag','stext') %ver5 = cmdmatch(version,'5'); %if ver5, set(anchor,'Interpreter','none'), end % %% Get default values. %str = setstr(rem(get(anchor,'String'),256)); %anchorPos = get(anchor,'Position'); %horizAlign = get(anchor,'HorizontalAlignment'); %vertAlign = get(anchor,'VerticalAlignment'); %anchorUnits = get(anchor,'Units'); %rotation = get(anchor,'Rotation'); %eraseMode = get(anchor,'EraseMode'); %buttonDownFcn = get(anchor,'ButtonDownFcn'); %clipping = get(anchor,'Clipping'); %interruptible = get(anchor,'Interruptible'); %fontSize = get(anchor,'FontSize'); %fontName = lower(get(anchor,'FontName')); %visible = get(anchor,'Visible'); % %set(anchor,'Rotation',0,'Visible','off') % %% Process property/value pairs. %for i = 1:numOptions % property = eval(['a',num2str(firstOpt + 2*(i-1))]); % value = eval(['a',num2str(firstOpt + 2*(i-1) + 1)]); % % % Convert property and value (if it's a string) to lower case. % % This code is significantly simpler and faster than lower.m, but % % sufficient for our purposes. % upperCase = property >= 'A' & property <= 'Z'; % property(upperCase) = setstr(property(upperCase) + ('a' - 'A')); % if isstr(value) & ~cmdmatch('string',property) % upperCase = value >= 'A' & value <= 'Z'; % value(upperCase) = setstr(value(upperCase) + ('a' - 'A')); % end % % % HorizontalAlignment: [ {left} | center | right ] % if cmdmatch('horizontalalignment',property) % horizAlign = value; % set(anchor,'HorizontalAlignment',value) % % % VerticalAlignment: [ top | cap | {middle} | baseline | bottom ] % elseif cmdmatch('verticalalignment',property) % vertAlign = value; % set(anchor,'VerticalAlignment',value) % % % Units: [ inches | centimeters | normalized | points | pixels | {data} ] % elseif cmdmatch('units',property) % anchorUnits = value; % set(anchor,'Units',value) % anchorPos = get(anchor,'Position'); % % % Position % elseif cmdmatch('position',property) % anchorPos = value; % set(anchor,'Position',value) % xin = value(1); % yin = value(2); % % % Rotation % elseif cmdmatch('rotation',property) % rotation = value; % rotation = rotation - floor(rotation/360)*360; % % % String % elseif cmdmatch('string',property) % str = value; % set(anchor,'String',value) % % % EraseMode % elseif cmdmatch('erasemode',property) % eraseMode = value; % set(anchor,'EraseMode',value) % % % ButtonDownFcn % elseif cmdmatch('buttondownfcn',property) % buttonDownFcn = value; % set(anchor,'ButtonDownFcn',value) % % % Clipping % elseif cmdmatch('clipping',property) % clipping = value; % set(anchor,'Clipping',value) % % % Interruptible % elseif cmdmatch('interruptible',property) % interruptible = value; % set(anchor,'Interruptible',value) % % % Visible % elseif cmdmatch('visible',property) % visible = value; % set(anchor,'Visible',value) % % else % delete(anchor) % error('Invalid object property.') % end %end % % %% Determine exact starting point. %if cmdmatch('points',anchorUnits) % pos = get(anchor,'Position'); %else % posu0 = get(anchor,'Position'); % set(anchor,'Units','points') % pos1 = get(anchor,'Position'); % set(anchor,'Units',anchorUnits) % posu1 = get(anchor,'Position'); % set(anchor,'Units','points','Position',pos1 + 1,'Units',anchorUnits) % posu2 = get(anchor,'Position'); % pos = (posu0(1:2) - posu1(1:2))./(posu2(1:2) - posu1(1:2)) + pos1(1:2); % set(anchor,'Units','points','Position',pos,'Units',anchorUnits) %end %x0 = pos(1); %y0 = pos(2); % %% Initialize some data. %objList = []; %heightList = []; %xDistance = []; %first = 1; %slantTagged = 0; %termNoDigits = setstr(1:255); %termNoDigits(real('0'):real('9')) = []; %termNoAlpha = setstr(1:255); %termNoAlpha([real('A'):real('Z'),real('a'):real('z')]) = []; %xstack = []; %colLut = [1 1 3 3;2 2 4 4;2 2 4 4]; %if isstudent % fm = [1 1 1 1 ; 2 2 2 2 ; 3:6 ; 7:10 ; 11:14 ; 15:18 ; 19:22 ;... % 23:26 ; 27:30 ; 7:10 ; 31 31 31 31]; %else % fm = [1 1 1 1 ; 2 2 2 2 ; 3:6 ; 7:10 ; 11:14 ; 15:18 ; 19:22 ;... % 23:26 ; 27:30 ; 31:34 ; 35 35 35 35]; %end % %fontanglelist = str2mat('normal','italic','oblique'); %fontnamelist = str2mat('symbol','zapfdingbats','times','helvetica',... % 'palatino','courier','avantgarde','bookman',... % 'newcenturyschlbk','n helvetica narrow','zapfchancery'); %fontweightlist = str2mat('light','normal','demi','bold'); % %% Initialize indexing parameters for "params" array. fa = font angle, %% fn = font name, fs = font size, fw = font weight, cr,cg,cb = color rgb, %% x = x location, y = y location, mode is used for super- and subscripts, %% nextX = x location of next object. %fa = 1; fn = 2; fs = 3; fw = 4; cr = 5; cg = 6; cb = 7; x = 8; y = 9; %mode = 10; nextX = 11; % %% params is a parameter stack. The contents are indices into string %% matrices for font angle, name and weight and actual values for %% the others. % %% Initialize params: font angle = normal, font name = default font, %% font size = default text font size, font weight = normal, %% color = default text color, x = 0, y = 0, mode = 0, nextX = 0. %params = [1;4;fontSize;2;get(0,'DefaultTextColor')';0;0;0;0]; %for fontIndex = 1:11 % if cmdmatch(fontnamelist(fontIndex,:),fontName) % params(fn) = fontIndex; % break % end %end % %% Parse str looking for commands. %while ~isempty(str) % if str(1) == '{' % % Push a copy of the current parameters on the parameter stack. % params = [params(:,1),params]; % params(mode) = 0; % str(1) = []; % elseif str(1) == '}' % % Pop the parameter stack except for adjustments to the x values. % if size(params,2) == 1 % delete(objList) % delete(anchor) % error('Unmatched braces.') % end % str(1) = []; % params(nextX,2) = max(params(nextX),params(nextX,2)); % if params(mode,2) == 0 % params(x,2) = params(x); % end % if isempty(str) % params(x,2) = params(x); % else % if str(1) ~= '^' & str(1) ~= '_' % params(x,2) = params(x); % params(mode,2) = 0; % end % end % params(:,1) = []; % elseif str(1) == '^' % % Superscript % params(mode) = params(mode) + 1; % params = [params(:,1),params]; % params(mode) = 0; % params(nextX) = params(x); % params(y) = params(y) + params(fs)/3; % params(fs) = params(fs)/sqrt(2); % if str(2) == '{' % str(1:2) = []; % else % str(1:2) = [str(2),'}']; % end % elseif str(1) == '_' % % Subscript % params(mode) = params(mode) + 2; %