Scale content to max height and width keeping aspect ratio

Is there some simple function where I can fit a content into a given height and width, so that the aspect ratio is untouched?
Like fit-content([This content should fit exactly into one text line even if the line width is only 2 cm], max-width: 100%, max-height: 9pt) When the line is widther than the content at max-height, it should be at most max-height and be left-aligned. AI gave me some measure codes for this, which did not compile. I feel that this should be built in the compiler. I think for images this logic exists. So maybe for content, too? Does this already exist?