Files
Gülşah Köse 111a2ffc8b cool#16233 sw: keep a formula's font size across DOCX import and export
An equation's size lives in the w:sz of its math runs. The import ignored it,
so every equation came in at the 12pt default of the formula editor, and a file
holding equations at three sizes showed all three the same. An equation whose
runs name no size takes the size of the text around it, which the styles and
the document defaults hold.

The export wrote no size at all. It now puts the size on every math run, and in
the control properties of each object, which is where the fraction bar, the
radical sign and the brackets take theirs from. The size travels in the w
namespace, so it goes out for a DOCX only, the way the color of a formula
already does.

Every formula now carries a size of its own on the way out, including one
written in ODF. Such a formula used to leave the size open and took whatever
the text around it had in the reading application. It now keeps the size it is
drawn at here, so both applications show it the same.

Setting the base size means giving each of the fonts that same size. The font
size dialog, the BaseFontHeight property of the model and this import each did
that on their own, so they now share SmFormat::SetBaseSizeAndFonts. The
property used to put the sizes in a copy that a later merge step reads only for
a font the same call has named, so a lone BaseFontHeight left the fonts alone.

Signed-off-by: Gülşah Köse <gulsah.kose@collabora.com>
Change-Id: I18b6c5814a57d8ccb8be5b7bdd357ce76cea024d
Reviewed-on: https://gerrit.collaboraoffice.com/c/online/+/13297
Reviewed-by: Balázs Varga <balazs.varga@collabora.com>
Tested-by: Jenkins CPCI <releng@collaboraoffice.com>
(cherry picked from commit 582e3fdb6496d9f511dfefc1f716b4ead6cc3797)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/211600
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
2026-09-30 12:12:58 +02:00

60 lines
2.6 KiB
C++

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include "wordexportbase.hxx"
#include <sax/fshelper.hxx>
#include <oox/core/filterbase.hxx>
#include <oox/export/utils.hxx>
/**
Class implementing writing of formulas to OOXML.
*/
class SmOoxmlExport : public SmWordExportBase
{
public:
SmOoxmlExport(const SmNode* pIn, oox::core::OoxmlVersion version,
oox::drawingml::DocumentType documentType, sal_Int32 nFontSizeInHalfPoints);
void ConvertFromStarMath(const ::sax_fastparser::FSHelperPtr& m_pSerializer, const sal_Int8);
private:
void HandleVerticalStack(const SmNode* pNode, int nLevel) override;
void HandleText(const SmNode* pNode, int nLevel) override;
void HandleFractions(const SmNode* pNode, int nLevel, const char* type) override;
void HandleRoot(const SmRootNode* pNode, int nLevel) override;
void HandleAttribute(const SmAttributeNode* pNode, int nLevel) override;
void HandleOperator(const SmOperNode* pNode, int nLevel) override;
void HandleSubSupScriptInternal(const SmSubSupNode* pNode, int nLevel, int flags) override;
void HandleMatrix(const SmMatrixNode* pNode, int nLevel) override;
void HandleBrace(const SmBraceNode* pNode, int nLevel) override;
void HandleVerticalBrace(const SmVerticalBraceNode* pNode, int nLevel) override;
void HandleBlank() override;
/// True when the run properties are written out, which needs a DOCX.
bool WritesRunProperties() const;
/// True when the node has a color of its own rather than the default one.
static bool HasOwnColor(const SmNode* pNode);
/// Writes the w:sz and w:szCs carrying the size the formula is drawn at.
void WriteFontSize();
/// Writes the m:ctrlPr carrying the size, color, bold and italic of the parts a
/// construct draws itself.
void WriteCtrlPr(const SmNode* pNode);
/// Writes a property element that a construct carries only to hold its control properties.
void WritePropertiesElement(sal_Int32 nElement, const SmNode* pNode);
::sax_fastparser::FSHelperPtr m_pSerializer;
oox::core::OoxmlVersion version;
/// needed to determine markup for nested run properties
oox::drawingml::DocumentType const m_DocumentType;
/// The size the formula is drawn at, in half points.
sal_Int32 const m_nFontSizeInHalfPoints;
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */