23 #include <rtl/ustrbuf.hxx>
37 using namespace ::
std;
47 const OUString& rStrName,
49 const OUString& rStrPrefix,
51 mnFamily( nFamily ), maStrFamilyName( rStrName), mxMapper( rMapper ),
52 mnCount( 0 ), mnName( 0 ), maStrPrefix( rStrPrefix ), mbAsFamily( bAsFamily )
56 mnFamily(nFamily),
mnCount(0), mnName(0), mbAsFamily(false) {}
65 const typelib_TypeDescriptionReference *type);
71 assert(type->eTypeClass == typelib_TypeClass_STRUCT);
77 const typelib_CompoundTypeDescription *compoundType =
78 &
reinterpret_cast<const typelib_StructTypeDescription*
>(type)->aBase;
80 for (
int i = 0;
i < compoundType->nMembers;
i++)
84 result.append(compoundType->ppMemberNames[
i]);
86 result.append(
data2string(static_cast<char *>(data)+compoundType->pMemberOffsets[
i],
87 compoundType->ppTypeRefs[
i]));
92 return result.makeStringAndClear();
97 const typelib_TypeDescriptionReference *type)
99 switch (type->eTypeClass)
101 case typelib_TypeClass_VOID:
103 case typelib_TypeClass_BOOLEAN:
104 return *
static_cast<const sal_Bool*
>(data) ? OUString(
"true") : OUString(
"false");
105 case typelib_TypeClass_BYTE:
106 return OUString::number((*static_cast<const sal_Int8*>(data)));
107 case typelib_TypeClass_SHORT:
108 return OUString::number((*static_cast<const sal_Int16*>(data)));
109 case typelib_TypeClass_LONG:
110 return OUString::number((*static_cast<const sal_Int32*>(data)));
111 case typelib_TypeClass_HYPER:
112 return OUString::number((*static_cast<const sal_Int64*>(data)));
113 case typelib_TypeClass_UNSIGNED_SHORT:
114 return OUString::number((*static_cast<const sal_uInt16*>(data)));
115 case typelib_TypeClass_UNSIGNED_LONG:
116 return OUString::number((*static_cast<const sal_uInt32*>(data)), 16);
117 case typelib_TypeClass_UNSIGNED_HYPER:
118 return OUString::number((*static_cast<const sal_uInt64*>(data)), 16);
119 case typelib_TypeClass_FLOAT:
120 return OUString::number(*static_cast<const float*>(data));
121 case typelib_TypeClass_DOUBLE:
122 return OUString::number(*static_cast<const double*>(data));
123 case typelib_TypeClass_CHAR:
124 return (
"U+" + OUString::number((*static_cast<const sal_uInt16*>(data))));
125 case typelib_TypeClass_STRING:
126 return *
static_cast<OUString*
>(data);
127 case typelib_TypeClass_TYPE:
128 case typelib_TypeClass_SEQUENCE:
129 case typelib_TypeClass_EXCEPTION:
130 case typelib_TypeClass_INTERFACE:
132 case typelib_TypeClass_STRUCT:
134 case typelib_TypeClass_ENUM:
135 return OUString::number((*static_cast<const sal_Int32*>(data)));
145 return data2string(const_cast<void*>(any.getValue()), any.pType);
155 static bool bHack = (getenv(
"LIBO_ONEWAY_STABLE_ODF_EXPORT") !=
nullptr);
159 OUStringBuffer aStemBuffer(32);
162 if (!rParentName.isEmpty())
164 aStemBuffer.append(
"-");
165 aStemBuffer.append(rParentName);
171 if (rState.mnIndex == -1)
173 OUString sXMLName(rFamilyData.
mxMapper->getPropertySetMapper()->GetEntryXMLName(rState.mnIndex));
174 if (sXMLName.isEmpty())
176 aStemBuffer.append(
"-");
177 aStemBuffer.append(OUString::number(rFamilyData.
mxMapper->getPropertySetMapper()->GetEntryNameSpace(rState.mnIndex)));
178 aStemBuffer.append(
":");
179 aStemBuffer.append(sXMLName);
180 aStemBuffer.append(
"=");
181 aStemBuffer.append(
any2string(rState.maValue));
187 aStemBuffer.append(
"-z");
188 static sal_Int32 nCounter = 0;
189 aStemBuffer.append(OUString::number(nCounter++));
194 OUStringBuffer aTry( aStemBuffer );
196 msName = aTry.makeStringAndClear();
197 bool bWarned =
false;
205 aTry.append( aStemBuffer );
207 aTry.append( OUString::number( rFamilyData.
mnName ) );
208 msName = aTry.makeStringAndClear();
216 OUStringBuffer sBuffer( 7 );
221 sBuffer.append( OUString::number( rFamilyData.
mnName ) );
222 msName = sBuffer.makeStringAndClear();
227 #if OSL_DEBUG_LEVEL > 0
228 std::set<sal_Int32> DebugProperties;
231 sal_Int32
const property(rPropState.mnIndex);
233 assert(DebugProperties.find(property) == DebugProperties.end());
236 DebugProperties.insert(property);
254 struct ComparePartial
258 bool operator()(
const vector< XMLPropertyState >& lhs,
259 const std::unique_ptr<XMLAutoStylePoolProperties>& rhs)
const
261 return rFamilyData.
mxMapper->LessPartial(lhs, rhs->GetProperties());
263 bool operator()(
const std::unique_ptr<XMLAutoStylePoolProperties>& lhs,
264 const vector< XMLPropertyState >& rhs )
const
266 return rFamilyData.
mxMapper->LessPartial(lhs->GetProperties(), rhs);
280 for (
auto it = itBegin; it != itEnd; ++it)
281 if (rFamilyData.
mxMapper->Equals((*it)->GetProperties(), rProperties))
282 pProperties = it->get();
285 if( bDontSeek || !pProperties )
288 m_PropertiesList.insert(itBegin, std::unique_ptr<XMLAutoStylePoolProperties>(pProperties));
292 rName = pProperties->
GetName();
310 std::unique_ptr<XMLAutoStylePoolProperties> pProperties(
313 pProperties->SetName( rName );
326 for (
auto it = itBegin; it != itEnd; ++it)
327 if (rFamilyData.
mxMapper->Equals((*it)->GetProperties(), rProperties))
328 sName = (*it)->GetName();
354 const OUString& rStrName,
356 const OUString& rStrPrefix,
363 OUString aPrefix( rStrPrefix );
366 aPrefix =
"M" + rStrPrefix;
369 #if OSL_DEBUG_LEVEL > 0
376 SAL_WARN_IF( (*iter)->mxMapper != rMapper,
"xmloff",
377 "Adding duplicate family " << rStrName <<
378 " with mismatching mapper ! " <<
379 typeid((*iter)->mxMapper.get()).
name() <<
" " <<
380 typeid(*rMapper).name() );
384 m_FamilySet.insert(std::make_unique<XMLAutoStyleFamily>(nFamily, rStrName, rMapper, aPrefix, bAsFamily));
394 (*iter)->mxMapper = rMapper;
404 (*iter)->maNameSet.insert(rName);
413 (*iter)->maReservedNameSet.insert(rName);
421 uno::Sequence<sal_Int32>& rFamilies,
422 uno::Sequence<OUString>& rNames )
425 vector<sal_Int32> aFamilies;
426 vector<OUString> aNames;
434 for (
const auto& rName : rFamily.
maNameSet)
436 aFamilies.push_back( static_cast<sal_Int32>(rFamily.
mnFamily) );
437 aNames.push_back( rName );
442 assert(aFamilies.size() == aNames.size());
444 rFamilies.realloc( aFamilies.size() );
445 std::copy( aFamilies.begin(), aFamilies.end(), rFamilies.getArray() );
447 rNames.realloc( aNames.size() );
448 std::copy( aNames.begin(), aNames.end(), rNames.getArray() );
455 OUString& rName,
XmlStyleFamily nFamily,
const OUString& rParentName,
456 const ::std::vector< XMLPropertyState >& rProperties,
bool bDontSeek )
464 auto itPair = rFamily.
m_ParentSet.insert(std::make_unique<XMLAutoStylePoolParent>(
469 if (rParent.
Add(rFamily, rProperties, rName, bDontSeek))
479 const OUString& rName,
XmlStyleFamily nFamily,
const OUString& rParentName,
480 const ::std::vector< XMLPropertyState >& rProperties )
490 auto itPair = rFamily.
m_ParentSet.insert(std::make_unique<XMLAutoStylePoolParent>(
495 if (rParent.
AddNamed(rFamily, rProperties, rName))
509 const OUString& rParent,
510 const vector< XMLPropertyState >& rProperties )
const
520 auto const it2 = rFamily.m_ParentSet.find(pTmp);
521 if (it2 != rFamily.m_ParentSet.end())
523 sName = (*it2)->Find(rFamily, rProperties);
531 std::vector<xmloff::AutoStyleEntry> rReturnVector;
533 for (std::unique_ptr<XMLAutoStyleFamily>
const & rFamily :
m_FamilySet)
536 for (
auto const & rParent : rFamily->m_ParentSet)
538 for (
auto const & rProperty : rParent->GetPropertiesList())
540 rReturnVector.emplace_back();
544 if (rPropertyState.mnIndex >= 0)
546 OUString sXmlName = aPropertyMapper->GetEntryXMLName(rPropertyState.mnIndex);
553 return rReturnVector;
558 struct AutoStylePoolExport
563 AutoStylePoolExport() : mpParent(nullptr), mpProperties(nullptr) {}
566 struct StyleComparator
568 bool operator() (
const AutoStylePoolExport& a,
const AutoStylePoolExport& b)
570 return (a.mpProperties->GetName() < b.mpProperties->GetName() ||
571 (a.mpProperties->GetName() == b.mpProperties->GetName() && *a.mpParent < *b.mpParent));
587 sal_uInt32
nCount = rFamily.mnCount;
594 std::vector<AutoStylePoolExport> aExpStyles(nCount);
596 for (
auto const& it : rFamily.m_ParentSet)
600 for(
size_t j = 0; j < nProperties; j++ )
606 assert(!aExpStyles[nPos].mpProperties);
607 aExpStyles[nPos].mpProperties = pProperties;
608 aExpStyles[nPos].mpParent = &rParent.
GetParent();
612 static bool bHack = (getenv(
"LIBO_ONEWAY_STABLE_ODF_EXPORT") !=
nullptr);
617 std::sort(aExpStyles.begin(), aExpStyles.end(), StyleComparator());
619 for (
size_t i = 0;
i < nCount;
i++)
621 OUString oldName = aExpStyles[
i].mpProperties->GetName();
622 sal_Int32 dashIx = oldName.indexOf(
'-');
623 OUString
newName = (dashIx > 0 ? oldName.copy(0, dashIx) : oldName) + OUString::number(
i);
625 aExpStyles[
i].mpProperties->SetName(newName);
632 OUString aStrFamilyName = rFamily.maStrFamilyName;
634 for(
size_t i = 0;
i < nCount;
i++ )
636 assert(aExpStyles[
i].mpProperties);
638 if( aExpStyles[
i].mpProperties )
642 aExpStyles[
i].mpProperties->GetName() );
644 bool bExtensionNamespace =
false;
645 if( rFamily.mbAsFamily )
649 if(aStrFamilyName !=
"graphic" &&
650 aStrFamilyName !=
"drawing-page" &&
651 aStrFamilyName !=
"presentation" &&
652 aStrFamilyName !=
"chart" )
653 bExtensionNamespace =
true;
665 if( rFamily.mbAsFamily )
668 sName = rFamily.maStrFamilyName;
671 aExpStyles[
i].mpProperties->GetProperties(),
679 sal_Int32 nStart(-1);
686 rFamily.mxMapper->getPropertySetMapper();
687 sal_Int16 nContextID;
688 while(nIndex < aPropMapper->GetEntryCount() && nEnd == -1)
690 nContextID = aPropMapper->GetEntryContextId( nIndex );
699 rFamily.mxMapper->exportXML(
701 aExpStyles[
i].mpProperties->GetProperties(),
705 aExpStyles[
i].mpProperties->GetProperties(),
static OUString any2string(const uno::Any &any)
virtual void exportStyleAttributes(SvXMLAttributeList &rAttrList, XmlStyleFamily nFamily, const ::std::vector< XMLPropertyState > &rProperties, const SvXMLExportPropertyMapper &rPropExp, const SvXMLUnitConverter &rUnitConverter, const SvXMLNamespaceMap &rNamespaceMap) const
bool operator<(const XMLAutoStyleFamily &r1, const XMLAutoStyleFamily &r2)
SvXMLExport & GetExport() const
~XMLAutoStylePoolParent()
std::vector< xmloff::AutoStyleEntry > GetAutoStyleEntries() const
const SvXMLUnitConverter & GetMM100UnitConverter() const
virtual void exportStyleContent(const css::uno::Reference< css::xml::sax::XDocumentHandler > &rHandler, XmlStyleFamily nFamily, const ::std::vector< XMLPropertyState > &rProperties, const SvXMLExportPropertyMapper &rPropExp, const SvXMLUnitConverter &rUnitConverter, const SvXMLNamespaceMap &rNamespaceMap) const
~SvXMLAutoStylePoolP_Impl()
sal_uInt32 GetPos() const
const OUString & GetParent() const
OUString newName(std::u16string_view aNewPrefix, const OUString &aOldPrefix, std::u16string_view old_Name)
ParentSetType m_ParentSet
FamilySetType m_FamilySet
OUString Find(XmlStyleFamily nFamily, const OUString &rParent, const ::std::vector< XMLPropertyState > &rProperties) const
void exportXML(XmlStyleFamily nFamily, const SvXMLAutoStylePoolP *pAntiImpl) const
bool AddNamed(XMLAutoStyleFamily &rFamilyData, const ::std::vector< XMLPropertyState > &rProperties, const OUString &rName)
std::set< OUString > maNameSet
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
void GetRegisteredNames(css::uno::Sequence< sal_Int32 > &aFamilies, css::uno::Sequence< OUString > &aNames)
bool AddNamed(const OUString &rName, XmlStyleFamily nFamily, const OUString &rParentName, const ::std::vector< XMLPropertyState > &rProperties)
void AddAttribute(sal_uInt16 nPrefix, const char *pName, const OUString &rValue)
bool Add(XMLAutoStyleFamily &rFamilyData, const ::std::vector< XMLPropertyState > &rProperties, OUString &rName, bool bDontSeek)
::std::vector< XMLPropertyState > maProperties
SvGenericNameContainerMapImpl maProperties
static OUString struct2string(void *data, const typelib_TypeDescription *type)
SvXMLAutoStylePoolP_Impl(SvXMLExport &rExport)
bool Add(OUString &rName, XmlStyleFamily nFamily, const OUString &rParentName, const ::std::vector< XMLPropertyState > &rProperties, bool bDontSeek=false)
void AddFamily(XmlStyleFamily nFamily, const OUString &rStrName, const rtl::Reference< SvXMLExportPropertyMapper > &rMapper, const OUString &rStrPrefix, bool bAsFamily)
PropertiesListType & GetPropertiesList()
std::vector< std::pair< OUString, css::uno::Any > > m_aXmlProperties
void RegisterDefinedName(XmlStyleFamily nFamily, const OUString &rName)
XMLAutoStylePoolProperties(XMLAutoStyleFamily &rFamilyData, const ::std::vector< XMLPropertyState > &rProperties, OUString const &rParentname)
void RegisterName(XmlStyleFamily nFamily, const OUString &rName)
struct _typelib_TypeDescription typelib_TypeDescription
const SvXMLNamespaceMap & GetNamespaceMap() const
PropertiesListType m_PropertiesList
RegionData_Impl * mpParent
rtl::Reference< SvXMLExportPropertyMapper > mxMapper
#define SAL_WARN_IF(condition, area, stream)
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
Handling of tokens in XML:
static OUString data2string(void *data, const typelib_TypeDescriptionReference *type)
const OUString & GetName() const
Smart struct to transport an Any with an index to the appropriate property-name.
std::set< OUString > maReservedNameSet
#define SAL_WARN(area, stream)
void SetFamilyPropSetMapper(XmlStyleFamily nFamily, const rtl::Reference< SvXMLExportPropertyMapper > &rMapper)
css::uno::Any const SvXMLExport & rExport
bool operator<(const XMLAutoStylePoolParent &rOther) const
XMLAutoStyleFamily(XmlStyleFamily nFamily, const OUString &rStrName, const rtl::Reference< SvXMLExportPropertyMapper > &rMapper, const OUString &rStrPrefix, bool bAsFamily)
SvXMLExportFlags getExportFlags() const
OUString Find(const XMLAutoStyleFamily &rFamilyData, const ::std::vector< XMLPropertyState > &rProperties) const
constexpr sal_uInt16 XML_NAMESPACE_STYLE