textadjust2gca

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - User interface
Introduced first in SolidGeometry 5.1, Creation date: 2021-12-16, Last change: 2025-09-15

adjust text width to fit in gca

Description

required for example in Videotitle if the title does not fit on the screen width

See Also: SGfigureeval , SGfigurepapermode , papermode , fontsize , imageVideoTitle

Example Illustration

 missing image of textadjust2gca (hh)

Syntax

textadjust2gca(hh)

Input Parameter

hh: handle to text

Examples


SGfigure; axis off; h=textP([-.2 0],'The quick brown fox jums over the lazy dog','','',32);
textadjust2gca(h)




Copyright 2021-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth

Algorithm (Workflow)

This algorithm is designed to adjust the width of a text object to fit within the current axes (gca) in a MATLAB figure. It is particularly useful when the text does not fit on the screen width, such as in video titles.

Input Parameters

Algorithm Steps

  1. Set the size variable to 0.95, indicating that the text should occupy a maximum of 95% of the axes width.
  2. Change the units of the text object hh to 'pixels' to facilitate size calculations.
  3. Retrieve the current extent of the text object using get(hh, 'Extent'), which provides the size and position of the text.
  4. Store the current units of the axes using get(gca, 'Units') to restore them later.
  5. Set the units of the axes to 'pixels' to ensure consistent measurement units.
  6. Retrieve the position of the axes using get(gca, 'Position').
  7. Enter a while loop that continues adjusting the text size until it fits within the specified size of the axes:
  8. Once the text fits, restore the original units of the axes using set(gca, 'Units', uuu).
Algorithm explaination created using ChatGPT on 2025-08-19 00:42. (Please note: No guarantee for the correctness of this explanation)

Last html export of this page out of FM database by TL: 2025-09-21