drawText

PURPOSE ^

drawText Draws text to figure

SYNOPSIS ^

function drawText(x,y, drawString, fontSize, fontStyle, color, font, fontWeight, flagCenter)

DESCRIPTION ^

drawText Draws text to figure

 drawText(x,y, drawString, fontSize, fontStyle, color, font, fontWeight, flagCenter)

INPUTS
 x             x coordinate
 y             y coordinate
 drawString    String to draw

OPTIONAL INPUTS
 fontSize      Font size (Default = 12)
 fontStyle     Font style (Default = 'normal')
 color         Font color (Default = [0 0 0])
 font          Font (Default = 'sans-serif')
 fontWeight    Font weight (Default = 'normal')
 flagCenter    Center text on coordinate (Default = false)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function drawText(x,y, drawString, fontSize, fontStyle, color, font, fontWeight, flagCenter)
0002 %drawText Draws text to figure
0003 %
0004 % drawText(x,y, drawString, fontSize, fontStyle, color, font, fontWeight, flagCenter)
0005 %
0006 %INPUTS
0007 % x             x coordinate
0008 % y             y coordinate
0009 % drawString    String to draw
0010 %
0011 %OPTIONAL INPUTS
0012 % fontSize      Font size (Default = 12)
0013 % fontStyle     Font style (Default = 'normal')
0014 % color         Font color (Default = [0 0 0])
0015 % font          Font (Default = 'sans-serif')
0016 % fontWeight    Font weight (Default = 'normal')
0017 % flagCenter    Center text on coordinate (Default = false)
0018 %
0019 global CB_MAP_OUTPUT
0020 global mapHandle
0021 
0022 if nargin < 4
0023     fontSize = 12;
0024 end
0025 if nargin < 5
0026     fontStyle = 'normal';
0027 end
0028 if nargin < 6
0029     color = [0 0 0];
0030 end
0031 if nargin < 7
0032     font = 'sans-serif';
0033 end
0034 if nargin <8
0035     fontWeight = 'normal';
0036 end
0037 if nargin < 9
0038     flagCenter = false;
0039 end
0040 
0041 
0042 
0043 if iscell(drawString)
0044     display ('whoops - this shouldnt happen.  drawText.m')
0045 %     drawString
0046 %     whos('drawString')
0047     drawString = drawString{1};
0048 end
0049 if isnan(x) | isnan(y) | isnan(fontSize)
0050 %     display ('whoops - this shouldnt happen.  drawText.m')
0051     return;
0052 end
0053 if strcmp(CB_MAP_OUTPUT, 'matlab')
0054     if find(color>1)
0055         color = color/255;
0056     end
0057     if flagCenter
0058         text(x,-y,drawString, 'FontSize', fontSize/2, 'color', color,'HorizontalAlignment','center');
0059     else
0060         text(x,-y,drawString, 'FontSize', fontSize/2, 'color', color);
0061     end
0062 elseif strcmp(CB_MAP_OUTPUT, 'java')
0063     % need to insert code
0064 elseif strcmp(CB_MAP_OUTPUT, 'svg')  
0065     %determine type of color input
0066     if ischar(color)
0067         if color=='k'
0068             colorStroke = 'rgb(0,0,0)';
0069         else
0070             colorStroke = color;
0071         end
0072     else if isvector(color)
0073             colorStroke = strcat('rgb(',num2str(color(1)),',',num2str(color(2)),',',num2str(color(3)),')');
0074         end
0075     end
0076     drawString = regexprep(drawString,'&','&amp;');
0077     fprintf(mapHandle, '<g style="font-family: %s; font-style: %s; font-weight: %s; stroke: none;">\n',font,fontStyle, fontWeight);
0078     if flagCenter
0079         fprintf(mapHandle,'<text style="fill: %s; text-rendering: optimizeLegibility;" x="%.2f" y="%.2f" font-size="%dpx">%s</text>\n</g>\n',colorStroke,x-(length(drawString)*fontSize*1.25),y+(5*fontSize),5*fontSize,drawString); 
0080     else
0081         fprintf(mapHandle,'<text style="fill: %s; text-rendering: optimizeLegibility;" x="%.2f" y="%.2f" font-size="%dpx">%s</text>\n</g>\n',colorStroke,x,y,5*fontSize,drawString); 
0082     end
0083 %     fprintf(mapHandle,'<text style="stroke: none;" x="%8.2f" y="%8.2f">%s</text>\n',x,-y,drawString);
0084 else
0085     display('error CB_MAP_OUTPUT in drawText');
0086 end

Generated on Thu 21-Jun-2012 15:39:23 by m2html © 2003