Unable to Get Correct Row Height in C# when the Text Is Bold in a Table Cell

Hello,
I have a problem when adding bold text in a cell and then getting the row height. There are some specific situations when the added text fits on one line of the cell, but if I make it bold it goes on another line. I’ve tested this for different fonts and I found that for some fonts it works properly but for other it doesn’t.

For fonts like Arial or Calibri the row height is returned correctly in this scenario, but for fonts like Montserrat and Rubik the row height is smaller than the actual height.

Screenshot with the slide ( I used shapes to indicate the end of the row height ):
table example.png (17.7 KB)

Code sample:

Presentation presentation = new();

ISlide slide = presentation.Slides[0];

// Define column widths and row heights
double[] columnWidths = { 100, 100, 100 }; // Widths of 3 columns
double[] rowHeights = { 20, 20, 20 };       // Heights of 3 rows

// Add a table shape to the slide
ITable tableMontserrat = slide.Shapes.AddTable(30, 30, columnWidths, rowHeights);
var fontDataMontserrat = new FontData("Montserrat");

// Access individual cells and set some text
for (int row = 0; row < 3; row++)
{
	for (int col = 0; col < 3; col++)
	{
		ICell cell = tableMontserrat[row, col];
		IPortion portionMontserra = cell.TextFrame.Paragraphs[0].Portions[0];
		portionMontserra.PortionFormat.LatinFont = fontDataMontserrat;
		portionMontserra.PortionFormat.FontBold = NullableBool.True;
		portionMontserra.Text = $"Row {row + 1}";
		if (row == 0)
		{
			portionMontserra.Text = $"Row {row + 1}, 11 i";
		}

		slide.Shapes.AddAutoShape(
			ShapeType.Rectangle,
			(float)(30 + cell.OffsetX),
			(float)(30 + cell.OffsetY + tableMontserrat.Rows[row].Height),
			5,
			5);
	}
}

// Add a table shape to the slide
ITable tableRubik = slide.Shapes.AddTable(360, 30, columnWidths, rowHeights);
var fontDataRubik = new FontData("Rubik");

// Access individual cells and set some text
for (int row = 0; row < 3; row++)
{
	for (int col = 0; col < 3; col++)
	{
		ICell cell = tableRubik[row, col];
		IPortion portionRubik = cell.TextFrame.Paragraphs[0].Portions[0];
		portionRubik.PortionFormat.LatinFont = fontDataRubik;
		portionRubik.PortionFormat.FontBold = NullableBool.True;
		portionRubik.Text = $"Row {row + 1}";
		if (row == 0)
		{
			portionRubik.Text = $"Row {row + 1},      i";
		}

		slide.Shapes.AddAutoShape(
			ShapeType.Rectangle,
			(float)(360 + cell.OffsetX),
			(float)(30 + cell.OffsetY + tableRubik.Rows[row].Height),
			5,
			5);
	}
}

// Add a table shape to the slide
ITable tableArial = slide.Shapes.AddTable(30, 360, columnWidths, rowHeights);
var fontDataArial = new FontData("Arial");

// Access individual cells and set some text
for (int row = 0; row < 3; row++)
{
	for (int col = 0; col < 3; col++)
	{
		ICell cell = tableArial[row, col];
		IPortion portionArial = cell.TextFrame.Paragraphs[0].Portions[0];
		portionArial.PortionFormat.LatinFont = fontDataArial;
		portionArial.PortionFormat.FontBold = NullableBool.True;
		portionArial.Text = $"Row {row + 1}";
		if (row == 0)
		{
			portionArial.Text = $"Row {row + 1},     i";
		}

		slide.Shapes.AddAutoShape(
			ShapeType.Rectangle,
			(float)(30 + cell.OffsetX),
			(float)(360 + cell.OffsetY + tableArial.Rows[row].Height),
			5,
			5);
	}
}

// Add a table shape to the slide
ITable tableCalibri = slide.Shapes.AddTable(360, 360, columnWidths, rowHeights);
var fontDataCalibri = new FontData("Calibri");

// Access individual cells and set some text
for (int row = 0; row < 3; row++)
{
	for (int col = 0; col < 3; col++)
	{
		ICell cell = tableCalibri[row, col];
		IPortion portionCalibri = cell.TextFrame.Paragraphs[0].Portions[0];
		portionCalibri.PortionFormat.LatinFont = fontDataCalibri;
		portionCalibri.PortionFormat.FontBold = NullableBool.True;
		portionCalibri.Text = $"Row {row + 1}";
		if (row == 0)
		{
			portionCalibri.Text = $"Row {row + 1},cc    i";
		}

		slide.Shapes.AddAutoShape(
			ShapeType.Rectangle,
			(float)(360 + cell.OffsetX),
			(float)(360 + cell.OffsetY + tableCalibri.Rows[row].Height),
			5,
			5);
	}
}

// Save the presentation
presentation.Save("output.pptx", SaveFormat.Pptx);

@vlad.bora,
Thank you for contacting support.

This issue might indicate that the fonts used in the presentation are missing from the operating system on which the code was executed. Please ensure that the “Montserrat” and “Rubik” fonts are installed on the operating system and that they are accessible to your application. It should resolve the problem.

Alternatively, you can load the fonts as follows:

FontsLoader.LoadExternalFonts(new string[] { "path_to_your_fonts" });

Custom PowerPoint Font in C#|Aspose.Slides Documentation
FontsLoader | Aspose.Sildes for .NET API Reference

I checked and the fonts are installed on the operation system, I used the FontsLoader and I even embedded the fonts into the presentation, but I still get the same issue.

@vlad.bora,
Please check your results using the latest version of Aspose.Slides for .NET. With version 24.6 and using the FontsLoader I get the following result: output.zip (30.2 KB)

I tried again with the entire font family of the used fonts this time, and now it works.
Apparently I forgot to add the bold type of the fonts.
Thank you very much for the help!

@vlad.bora,
We are glad to know that the issue has been resolved on your end. Thank you for using Aspose.Slides.