/* -*- 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/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
// Export of axial gradient to OOXML produces a symmetrical linear multi-color gradient. Import // does not regenerate it as 'axial' because that is not needed for MCGR. For export to ODF we // try to regenerate 'axial' for to get a better compatibility with LO versions before MCGR.
aGradient.tryToConvertToAxial();
// MCGR: For better compatibility with LO versions before MCGR, try // to re-create a 'border' value based on the existing gradient stops. // With MCGR we do not need 'border' anymore in quite some cases since // no Start/EndColor at 0.0 resp. 1.0 is explicitly needed. Since we // (unfortunately need to) internally continue to support border // anyways it does no harm to fallback to use the border value - if // there is an equivalent representation as this helper checks for. // For exports that do not support 'border' this will be adapted as // needed (see tryToApplyBorder()).
aGradient.tryToRecreateBorder(nullptr);
// ctor writes start tag. End-tag is written by destructor at block end.
SvXMLElementExport aElem( m_rExport, XML_NAMESPACE_DRAW, XML_GRADIENT, true, false );
// Write child elements <loext:gradient-stop> // Do not export in standard ODF 1.3 or older. if ((m_rExport.getSaneDefaultVersion() & SvtSaveOptions::ODFSVER_EXTENDED) == 0) return;
if (aGradient.GetColorStops().empty()) return;
double fPreviousOffset = 0.0; for (constauto& aCandidate : aGradient.GetColorStops())
{ // Attribute svg:offset. Make sure offsets are increasing. double fOffset = std::clamp<double>(aCandidate.getStopOffset(), 0.0, 1.0); if (fOffset < fPreviousOffset)
fOffset = fPreviousOffset;
m_rExport.AddAttribute(XML_NAMESPACE_SVG, XML_OFFSET, OUString::number(fOffset));
fPreviousOffset = fOffset;
// As of LO 7.6.0 only color-type="rgb" is implemented.
m_rExport.AddAttribute(XML_NAMESPACE_LO_EXT, XML_COLOR_TYPE, u"rgb"_ustr);
// Attribute loext:color-value, data type color, that is #rrggbb. const basegfx::BColor aDecimalColor(aCandidate.getStopColor());
::Color aToolsColor(std::clamp<sal_uInt8>(std::round(aDecimalColor.getRed() * 255.0), 0, 255),
std::clamp<sal_uInt8>(std::round(aDecimalColor.getGreen() * 255.0), 0, 255),
std::clamp<sal_uInt8>(std::round(aDecimalColor.getBlue() * 255.0), 0, 255));
m_rExport.AddAttribute(XML_NAMESPACE_LO_EXT, XML_COLOR_VALUE,
rtl::OUStringChar('#') + aToolsColor.AsRGBHexString());
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.