Font.CalculateTextWidth
-----------------------

Calculates width of text.

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

MBS( "Font.CalculateTextWidth"; Text { ; Font; Size } ) 

**MBS**( **"Font.CalculateTextWidth";** /\* Calculates width of text. \*/  
**$Text**; /\* The text to measure.e.g. "Hello World" \*/   
**$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" |  |
| 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

Calculates width of text.  
The plugin uses system font rendering to calculate width. This may be different from what FileMaker renders with it's own engine.  
You can use the measured size to detect if text fits a field.  
  
Mac result in logical points, but on Windows in pixels.  
  
See also [GMImage.FontTypeMetrics](GMImageFontTypeMetrics.md).  
### Examples

Calculate width of Hello World:

 MBS ( "Font.CalculateTextWidth"; "Hello World" )  
\# e.g. 70.9 on Mac and 77 on Windows.   
Calculate with Arial

 MBS ( "Font.CalculateTextWidth"; "Hello World"; "Arial"; 12 )  
\# e.g. 61 on Windows, 61,7 on Mac   
### See also

- [Font.CalculateTextFits](FontCalculateTextFits.md)
- [Font.CalculateTextHeight](FontCalculateTextHeight.md)
- [GMImage.FontTypeMetrics](GMImageFontTypeMetrics.md)

### Release notes

- **Version 8.5**
    - Fixed bug in [Font.CalculateTextWidth](http://www.mbsplugins.eu/FontCalculateTextWidth.shtml) with loading font.

### Example Databases

- [Utility functions/Calculate Text Size](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Utility%20functions/Calculate%20Text%20Size.shtml#1299FieldAnchor_)
- [Utility functions/FontWidth](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Utility%20functions/FontWidth.shtml#1ScriptAnchor_)

### Blog Entries

- [Calculate Text Sizes](https://www.mbsplugins.de/archive/2021-10-03/Calculate_Text_Sizes/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 8.5pr8](https://www.mbsplugins.de/archive/2018-11-22/MBS_FileMaker_Plugin_version_8/monkeybreadsoftware_blog_filemaker)
- [Measure text length in FileMaker](https://www.mbsplugins.de/archive/2016-10-26/Measure_text_length_in_FileMak/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 6.5pr4](https://www.mbsplugins.de/archive/2016-10-25/MBS_FileMaker_Plugin_version_6/monkeybreadsoftware_blog_filemaker)

### FileMaker Magazin

- [Ausgabe 1/2021, Seite 19](https://filemaker-magazin.de/neuigkeit/4124-Appetithappen-FMM_202101)

This function checks for a license.

Created 21st October 2016 , last changed 18th December 2025

  
[Font.CalculateTextHeight](FontCalculateTextHeight.md) - [Font.Deactivate](FontDeactivate.md)

[HTML Version](FontCalculateTextWidth.shtml)