GSoC 2026: Final Project Report

GSoC 2026 Final Project Report: LibreOffice OpenType MATH

  • Contributor: AYA JAMAL ALSAYED ABDELMONEIM
  • Mentor: Khaled Hosny
  • Organization: LibreOffice
  • Project Link: LibreOffice OpenType MATH

My Overall Experience

My journey through the Google Summer of Code (GSoC) 2026 period with LibreOffice has been an incredibly fulfilling and transformative experience. When I look back, I see myself entering the program as a contributor but finishing it with a good understanding of legacy C++ codebase and open-source collaboration. I wrote the actual code and crucially ensuring backward compatibility before final deployment (this was the first step in my GSoC project).

The Project: Supporting OpenType Math fonts

LibreOffice is a powerful, free, and open-source office suite used by 200+ millions globally. Within it, the StarMath module is responsible for rendering mathematical formulas. The core goal of my project was to support OpenType math fonts with a MATH table that can easily be used to present mathematical formulas if LibreOffice handles HarfBuzz APIs and enhance how these formulas are laid out on the screen.

The Problem

The existing rendering logic in StarMath (specifically within SmNode::Arrange) presented a significant challenge. As the legacy layout engine struggled to scale and position the elements correctly (like mathematical operators and formulas). This resulted in severe rendering artifacts including overlapping lines because the engine relied on random and hardcoded metrics.

The Solution: OpenType MATH & HarfBuzz Integration

My GSoC project aimed to solve this issue by integrating HarfBuzz Math APIs with the Visual Class Library (VCL) and restructuring the StarMath layout engine to utilize OpenType MATH table.

Part 1: Backward Compatibility

  • That is the fallback logic for Backward Compatibility:
    I implemented a fallback mechanism to preserve backward compatibility. The new HarfBuzz logic is only used for new documents with Math fonts that actually have a MATH table. If a document doesn't support Math font (that doesn't have a Math table), it falls back to the original Arrange hard-coded logic.
  • The Code for Backward Compatibility: Implement SupportsOpenTypeMath in outdev

Part 2: Integrating HarfBuzz Math APIs

The core of my project was to expose HarfBuzz's OpenType MATH capabilities directly to the StarMath module. I achieved this by:

  • Using LogicalFontInstance to access the HarfBuzz font object (hb_font_t) for metric extraction.
  • Extending VCL APIs to include HarfBuzz's OpenType MATH capabilities directly.
  • Implementing wrappers for a set of HarfBuzz Math APIs to handle complex math layout, specifically:
    • hb_ot_math_get_constant() to dynamically fetch essential font metrics, such as radicalVerticalGap and radicalRuleThickness.
    • hb_ot_math_get_glyph_italics_correction() to ensure accurate spacing and positioning for italicized math symbols.
    • hb_ot_math_get_glyph_variants() to retrieve different pre-drawn sizes for scalable math operators.
    • hb_ot_math_get_glyph_assembly() and hb_ot_math_get_min_connector_overlap() to allow the engine to dynamically construct large operators from glyph parts.

Part 3: Re-implementing the Layout Logic

I worked on replacing the legacy hard-codes inside node.cxx by introducing "OpenTypeNode.cxx" layout methods.

To achieve this, I re-implemented the layout logic for various Abstract Syntax Tree (AST) nodes by developing the following methods:

  • SmNode::ArrangeOpenType()
  • SmTableNode::ArrangeOpenType()
  • SmLineNode::ArrangeOpenType()
  • SmBinHorNode::ArrangeOpenType()
  • SmBinVerNode::ArrangeOpenType()
  • SmMathSymbolNode::AdaptToYOpenType()
  • SmMathSymbolNode::ArrangeOpenType()
  • SmBraceNode::ArrangeOpenType()

By introducing these methods, I enabled accurate rendering for fractions and stacks utilizing OpenType Math constants. Furthermore, I shifted from legacy scaling standard characters to offering a glyph stretching feature for brackets (such as (), {}, []). Through using the harfBuzz functions get_glyph_variants() and get_glyph_assembly() inside SmBraceNode, the engine can now dynamically construct large operators without distortion.

Outcomes of the Project:

To visualize the impact of this project, here is a before-and-after outcomes:

1. Fractions

Before:

After:

1. Stacks

Before:

After:

1. Brackets

Before:

After:

Patches Merged:

Important things I learned during the project

Working with LibreOffice didn't just help me deal and gain technical experience; it also gave me a great opportunity for presenting my GSoC project in September 2026 at LibreOffice Conference. You can listen to my talk here: GSoC Demo 2026 by Aya Jamal

Final Thoughts

Through GSoC with LibreOffice, I gained a good software engineering experience that has taught me the value of robust architecture, dealing with a legacy code and backward compatibility. I am really grateful to my mentor, Khaled Hosny, for his guidance and support throughout this summer. I am proud of my work, and this project will attract more users, particularly in the scientific and academic community.

参与讨论