ODF standard and the code – EasyHack

Open Document Format (ODF) is a standard (ISO/IEC 26300) and native file format that LibreOffice uses. OASIS developed this file format based on the file format of StarOffice, the ancestor of LibreOffice.

To understand the ODF standard, working with the LibreOffice code and fixing a small bug is enlightening. Here we discuss a related EasyHack.

ODF File Extensions

If you are a LibreOffice user, you may already know these extensions:

.odt for text processing documents (LibreOffice Writer)

.odp for presentations (LibreOffice Impress)

.ods for spreadsheets (LibreOffice Calc)

.odg for drawings (LibreOffice Draw)

.odf for formulas (LibreOffice Math)

Essentially, these are zip files containing XML and binary files. Additionally, Open Document Format can also be text-only format with the extensions of .fodt, .fods and .fodg instead of .odt, .ods, and odg respectively.

Open Document Specification

OASIS website provides the documents that describe the Open Document Format extensively . You can find the specifications for ODF 1.3, which is the latest version of the standard here:

OpenDocument V1.3 OASIS Standard published

Beside LibreOffice, several other applications support ODF standard, including Microsoft Office, ONLYOFFICE, Calligra Suite, Google Docs, and many others! But here, we focus on LibreOffice.

Basically, LibreOffice handles the Open Document format by opening the zip file using the zip parser and the deflate algorithm, and then parses the XML files inside it using libxml2 library.

On the other hand, the meaning of the XML tags and attributes are available via the specification from OASIS. In essence, the specification describes the text, pictures, shapes and other elements of the text processing, presentations, spreadsheets and formulas. Additionally, ODF standard discusses accessibility, collaboration and many more topics.

An EasyHack Related to ODF

To best way to understand the ODF standard, is working with the LibreOffice code. Please take a look at this small bug, which has the label of EasyHack (tdf#150302):

In this EasyHack, there is a sample document which is using a specific feature in the drawings. Looking at the <draw:enhanced-geometry> tag, one can see that there is an attribute draw:text-path-same-letter-heights that is used to control the way that text is rendered in shapes. It is described in ODF standard as:


19.224 draw:text-path-same-letter-heights

The draw:text-path-same-letter-heights attribute specifies if all letters in a custom shape have the same height.

The defined values for the attribute are:

  • false: letters in a custom shape need not have the same height.
  • true: letters in a custom shape have the same height.

The default value for this attribute is false.


The issue is that handling this parameter in the code is not correct. Specifically, the effect of this bug is that if you open the sample file and click on the SameLetterHeights button in the Fontwork toolbar, nothing happens. On the other hand, the correct behavior should be that the shape changes, and “shows the characters vertical stretched to fit the place between the paths”.

Shapes inside the example ODF file

Shapes inside the example ODF file

After all, to fix this issue one should refer to the code pointer that Regina Henschel has provided:

If you open the file core/svx/source/toolbars/fontworkbar.cxx, you will see that the else part is missing, and that is the cause of the problem. Specifically, you should fix that part of the code, and then submit your changes to Gerrit. To begin, please refer to this page for more information on how to submit code to LibreOffice Gerrit:

Writing a Test for the Fix

The fix is rather straightforward, but this is not the end of the task! Furthermore, you have to make sure that the problem does not happen again. In order to achieve this goal, writing a unit test is necessary. The test code should open the example file, and then use the toolbar option. This is possible by invoking .uno:FontworkSameLetterHeights command.

Fontwork toolbar, SameLetterHeightsFontwork toolbar: SameLetterHeights is the second icon is the second icon

Fontwork toolbar: SameLetterHeights is the second icon

There are some examples in sd/qa/unit/uiimpress.cxx that invoke UNO commands, and you may use as the starting point.

Final Notes

EasyHacks are good starting points for the newcomers. This specific improvement is filed as tdf#150302.

If you want to contribute to LibreOffice code by working on this improvement, but you need to know how to get started with LibreOffice development, I suggest you to see our video tutorial:

Getting Started (Video Tutorial)

 

Comments
  1. 1 month ago