Difference between revisions of "CanvasDrawText"

(TrueType)
(EW 19060 -- return value measures bounding box)
Line 1: Line 1:
 
[[Category:Image and canvas functions]]
 
[[Category:Image and canvas functions]]
 
+
{{ReleaseBar}}
''New to [[Analytica 5.0]]''
 
  
 
== CanvasDrawText( canvas, text, x, y'', font, fontSize, color, bold, italic, hAlign, vAlign'' ) ==
 
== CanvasDrawText( canvas, text, x, y'', font, fontSize, color, bold, italic, hAlign, vAlign'' ) ==
Line 15: Line 14:
 
* «hAlign»: (Optional) Horizontal alignment relative to «x», either <code>'Left', 'Center' or 'Right'</code>. Default is <code>'Left'</code>.
 
* «hAlign»: (Optional) Horizontal alignment relative to «x», either <code>'Left', 'Center' or 'Right'</code>. Default is <code>'Left'</code>.
 
* «vAlign»: (Optional) Vertical alignment relative to «y», either <code>'Top', 'Middle' or 'Bottom'</code>. Default is <code>'Top'</code>.
 
* «vAlign»: (Optional) Vertical alignment relative to «y», either <code>'Top', 'Middle' or 'Bottom'</code>. Default is <code>'Top'</code>.
 +
* «measureOnly»: (Optional) {{Release||5.1|Requires [[Analytica 5.2]]}} When true, text is not drawn. Use this to measure the bounding box without actually drawing.
  
 
When drawn to a context where the coordinate frame as been scaled, the text (and the interpretation of «fontSize» is scaled as well. When the x- and y-axes are scaled differently, the text will be squashed or stretched.  When one logical unit along x corresponds to two device pixels, then text will be twice as wide as it would be if rendered at the same «fontSize» without scaling.
 
When drawn to a context where the coordinate frame as been scaled, the text (and the interpretation of «fontSize» is scaled as well. When the x- and y-axes are scaled differently, the text will be squashed or stretched.  When one logical unit along x corresponds to two device pixels, then text will be twice as wide as it would be if rendered at the same «fontSize» without scaling.
 +
 +
== Return value ==
 +
''New to [[Analytica 5.2]]''
 +
 +
{{Release||5.1|Returns null in [[Analytica 5.0]] and [[Analytica 5.1]]. Starting in [[Analytica 5.2]], returns the coordinates of the bounding box.}}
 +
{{Release|5.1||
 +
Returns the coordinates of the bounding box as four separate return values: width, height, left and top.  To capture the full bounding box use, e.g.,
 +
 +
:<code>[[Local]] (w, h, left, top) {{Eq}} [[CanvasDrawText]]( canv, "Some text", 200, 300, hAlign:'Center' );</code>
 +
or
 +
:<code>[[Local]] (w, h, left, top) {{Eq}} [[CanvasDrawText]]( canv, "Some text", 200, 300, hAlign:'Center', measureOnly:true );</code>
 +
 +
The first example draws and measures, whereas the second example measures without drawing.  If you only need to measure the width, you can use
 +
 +
:<code>[[Local]] w {{Eq}} [[CanvasDrawText]]( canv, "Some text", 200, 300, hAlign:'Center', measureOnly:true );</code>
 +
 +
The bounding box is in the canvas context coordinates, as demonstrated here:
 +
<code>
 +
[[Local]] canv := Canvas(100,70);
 +
[[CanvasDrawEllipse]](canv, 60-3, 40-3, 6,6, fillColor:'Red');
 +
[[Local]] rot := [[CanvasContext]](canv, rotAngle:-35, rotx:60, roty:40 );
 +
[[Local]] (w,h,x,y) := [[CanvasDrawText]](rot, "Rotated Text", 60,40,hAlign:'Center', vAlign:'Bottom');
 +
[[CanvasDrawRectangle]](rot, x,y,w,h );
 +
[[CanvasImage]](canv)
 +
</code>
 +
:[[image:CanvasDrawText measureRotated.png]]
 +
}}
  
 
== See also ==
 
== See also ==

Revision as of 21:00, 14 March 2019



Release:

4.6  •  5.0  •  5.1  •  5.2  •  5.3  •  5.4  •  6.0  •  6.1  •  6.2  •  6.3  •  6.4  •  6.5  •  6.6


CanvasDrawText( canvas, text, x, y, font, fontSize, color, bold, italic, hAlign, vAlign )

Draws text on a canvas.

  • «canvas» is a canvas obtained from calling the Canvas() function, or a canvas context obtained by calling the CanvasContext() function.
  • «text» is the text to draw.
  • «x», «y»: The location where the text will display.
  • «font»: (optional) the textual TrueType font name, such as 'Arial', 'Comic Sans MS', 'Times New Roman'.
  • «color»: (Optional) Either a textual color name or a color integer. See Color parameters for an enumeration of textual color names and a description of color integers. Defaults to 'Black'.
  • «bold», «italic»: (Optional) When true, the text is draw in bold or italic font respectively.
  • «hAlign»: (Optional) Horizontal alignment relative to «x», either 'Left', 'Center' or 'Right'. Default is 'Left'.
  • «vAlign»: (Optional) Vertical alignment relative to «y», either 'Top', 'Middle' or 'Bottom'. Default is 'Top'.
  • «measureOnly»: (Optional) When true, text is not drawn. Use this to measure the bounding box without actually drawing.

When drawn to a context where the coordinate frame as been scaled, the text (and the interpretation of «fontSize» is scaled as well. When the x- and y-axes are scaled differently, the text will be squashed or stretched. When one logical unit along x corresponds to two device pixels, then text will be twice as wide as it would be if rendered at the same «fontSize» without scaling.

Return value

New to Analytica 5.2


{{{3}}}

See also

Comments


You are not allowed to post comments.