Font.CalculateTextFits
----------------------

Queries how many characters would fit in a space.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [Font](component_Font.md) | [8.4](newinversion84.md) | ✅ Yes | ✅ Yes | ❌ No | ✅ Yes, on macOS and Windows | ✅ Yes |

MBS( "Font.CalculateTextFits"; Text; MaxWidth { ; Font; Size } ) 

**MBS**( **"Font.CalculateTextFits";** /\* Queries how many characters would fit in a space. \*/  
**$Text**; /\* The text to measure.e.g. "Hello World" \*/   
**$MaxWidth**; /\* The maximum width.e.g. 100 \*/   
**$Font**; /\* Optional; The font name.  
Using System font in case of empty parameter.e.g. "Arial" \*/   
**$Size**) /\* Optional; The font size to use.  
Default is system font size.e.g. 12 \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| Text | The text to measure. | "Hello World" |  |
| MaxWidth | The maximum width. | 100 |  |
| Font | The font name.   Using System font in case of empty parameter. | "Arial" | Optional |
| Size | The font size to use.   Default is system font size. | 12 | Optional |

### Result

Returns number or error.

### Description

Queries how many characters would fit in a space.  
The plugin will check how long the text would be in points.  
Then we reduce text to see how much text fits in the space and return the length of the reminding space.  
### Examples

Checks how much fits:

 MBS ( "Font.CalculateTextFits"; "Hello World"; 50; "Arial"; 12)  
Trying for normal, bold and italic Arial variants:

 MBS ( "Font.CalculateTextFits"; "Hello World"; 50; "Arial"; 12) &amp; ¶ &amp; MBS ( "Font.CalculateTextFits"; "Hello World"; 50; "Arial-ItalicMT"; 12) &amp; ¶ &amp; MBS ( "Font.CalculateTextFits"; "Hello World"; 50; "Arial-BoldMT"; 12) &amp; ¶ &amp; MBS ( "Font.CalculateTextFits"; "Hello World"; 50; "Arial-BoldItalicMT"; 12)  
<small>  
Example result:   
8  
8  
7  
7</small>### See also

- [Font.CalculateTextHeight](FontCalculateTextHeight.md)
- [Font.CalculateTextWidth](FontCalculateTextWidth.md)

### Release notes

- **Version 8.4**
    - Added [Font.CalculateTextFits](http://www.mbsplugins.eu/FontCalculateTextFits.shtml) and [Font.CalculateTextHeight](http://www.mbsplugins.eu/FontCalculateTextHeight.shtml) function.

### Blog Entries

- [Calculate Text Sizes](https://www.mbsplugins.de/archive/2021-10-03/Calculate_Text_Sizes/monkeybreadsoftware_blog_filemaker)
- [Neues MBS FileMaker Plugin 8.4 - Über 5400 Funktionen in einem Plugin](https://www.mbsplugins.de/archive/2018-09-25/Neues_MBS_FileMaker_Plugin_84_/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin 8.4 - More than 5400 Functions In One Plugin](https://www.mbsplugins.de/archive/2018-09-25/MBS_FileMaker_Plugin_84_-_More/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 8.4pr8](https://www.mbsplugins.de/archive/2018-09-13/MBS_FileMaker_Plugin_version_8/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

Created 12nd September 2018 , last changed 1st October 2021

  
[Font.Activate](FontActivate.md) - [Font.CalculateTextHeight](FontCalculateTextHeight.md)

[HTML Version](FontCalculateTextFits.shtml)