[Libreoffice-commits] .: xmloff/inc xmloff/source

Miklos Vajna vmiklos at kemper.freedesktop.org
Tue Apr 10 05:31:51 PDT 2012


 xmloff/inc/xmloff/txtparae.hxx  |    6 ++
 xmloff/source/text/txtparae.cxx |   92 ++++++++++++++++++++++++++++++++++++++--
 2 files changed, 94 insertions(+), 4 deletions(-)

New commits:
commit 7a1c5e54afe4e4ef7e17c2e9c969cd41221edc28
Author: Brennan Vincent <brennanv at email.arizona.edu>
Date:   Sun Apr 8 14:45:01 2012 -0700

    Partial fix for bug 30711

diff --git a/xmloff/inc/xmloff/txtparae.hxx b/xmloff/inc/xmloff/txtparae.hxx
index 11e0140..c5d3e75 100644
--- a/xmloff/inc/xmloff/txtparae.hxx
+++ b/xmloff/inc/xmloff/txtparae.hxx
@@ -110,6 +110,9 @@ class XMLOFF_DLLPUBLIC XMLTextParagraphExport : public XMLStyleExport
     ::std::vector< XMLTextListsHelper* > maTextListsHelperStack;
 
     enum FrameType { FT_TEXT, FT_GRAPHIC, FT_EMBEDDED, FT_SHAPE };
+public:
+
+    enum FieldmarkType { NONE, TEXT, CHECK }; // Used for simulating fieldmarks in OpenDocument 1.n Strict (for n <= 2). CHECK currently ignored.
 
 protected:
 
@@ -430,7 +433,8 @@ protected:
         const ::com::sun::star::uno::Reference <
             ::com::sun::star::text::XTextRange > & rTextRange,
         sal_Bool bAutoStyles,
-        bool& rPrevCharWasSpace );
+        bool& rPrevCharWasSpace,
+        FieldmarkType& openFieldmarkType );
 
     void exportListChange( const XMLTextNumRuleInfo& rPrvInfo,
                            const XMLTextNumRuleInfo& rNextInfo );
diff --git a/xmloff/source/text/txtparae.cxx b/xmloff/source/text/txtparae.cxx
index 522d43f..922dce1 100644
--- a/xmloff/source/text/txtparae.cxx
+++ b/xmloff/source/text/txtparae.cxx
@@ -2182,6 +2182,10 @@ void XMLTextParagraphExport::exportTextRangeEnumeration(
     static OUString sMeta(RTL_CONSTASCII_USTRINGPARAM("InContentMetadata"));
     bool bPrevCharIsSpace = bPrvChrIsSpc;
 
+    /* This is  used for exporting to strict OpenDocument 1.2, in which case traditional
+     * bookmarks are used instead of fieldmarks. */
+    FieldmarkType openFieldMark = NONE;
+
     while( rTextEnum->hasMoreElements() )
     {
         Reference<XPropertySet> xPropSet(rTextEnum->nextElement(), UNO_QUERY);
@@ -2196,7 +2200,7 @@ void XMLTextParagraphExport::exportTextRangeEnumeration(
             if( sType.equals(sText))
             {
                 exportTextRange( xTxtRange, bAutoStyles,
-                                 bPrevCharIsSpace );
+                                 bPrevCharIsSpace, openFieldMark);
             }
             else if( sType.equals(sTextField))
             {
@@ -2261,6 +2265,7 @@ void XMLTextParagraphExport::exportTextRangeEnumeration(
             }
             else if (sType.equals(sTextFieldStart))
             {
+                /* As of now, textmarks are a proposed extension to the OpenDocument standard. */
                 if ( GetExport().getDefaultVersion() == SvtSaveOptions::ODFVER_LATEST )
                 {
                     Reference<XNamed> xBookmark(xPropSet->getPropertyValue(sBookmark), UNO_QUERY);
@@ -2280,6 +2285,46 @@ void XMLTextParagraphExport::exportTextRangeEnumeration(
                     }
                     GetExport().EndElement(XML_NAMESPACE_FIELD, XML_FIELDMARK_START, sal_False);
                 }
+                /* The OpenDocument standard does not include support for TextMarks for now, so use bookmarks instead. */
+                else
+                {
+                    Reference< ::com::sun::star::text::XFormField > xFormField(xPropSet->getPropertyValue(sBookmark), UNO_QUERY);
+                    if (xFormField.is())
+                    {
+                        Reference< ::com::sun::star::container::XNameAccess > xParameters(xFormField->getParameters(), UNO_QUERY);
+                        if (xParameters.is() && xParameters->hasByName("Name"))
+                        {
+                            const Any aValue = xParameters->getByName("Name");
+                            const Type aValueType = aValue.getValueType();
+                            if (aValueType == ::getCppuType((OUString*)0))
+                            {
+                                OUString sValue;
+                                aValue >>= sValue;
+                                GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME, sValue);
+                            }
+                        }
+                        GetExport().StartElement(XML_NAMESPACE_TEXT, XML_BOOKMARK_START, sal_False);
+                        GetExport().EndElement(XML_NAMESPACE_TEXT, XML_BOOKMARK_START, sal_False);
+                        const OUString sFieldType = xFormField->getFieldType();
+                        if (sFieldType ==  ODF_FORMTEXT)
+                        {
+                            openFieldMark = TEXT;
+                        }
+                        else if (sFieldType == ODF_FORMCHECKBOX)
+                        {
+                            openFieldMark = CHECK;
+                        }
+                        else
+                        {
+                            openFieldMark = NONE;
+                        }
+                    }
+                    else
+                    {
+                        GetExport().StartElement(XML_NAMESPACE_TEXT, XML_BOOKMARK_START, sal_False);
+                        GetExport().EndElement(XML_NAMESPACE_TEXT, XML_BOOKMARK_START, sal_False);
+                    }
+                }
             }
             else if (sType.equals(sTextFieldEnd))
             {
@@ -2288,6 +2333,27 @@ void XMLTextParagraphExport::exportTextRangeEnumeration(
                     GetExport().StartElement(XML_NAMESPACE_FIELD, XML_FIELDMARK_END, sal_False);
                     GetExport().EndElement(XML_NAMESPACE_FIELD, XML_FIELDMARK_END, sal_False);
                 }
+                else
+                {
+                    Reference< ::com::sun::star::text::XFormField > xFormField(xPropSet->getPropertyValue(sBookmark), UNO_QUERY);
+                    if (xFormField.is())
+                    {
+                        Reference< ::com::sun::star::container::XNameAccess > xParameters(xFormField->getParameters(), UNO_QUERY);
+                        if (xParameters.is() && xParameters->hasByName("Name"))
+                        {
+                            const Any aValue = xParameters->getByName("Name");
+                            const Type aValueType = aValue.getValueType();
+                            if (aValueType == ::getCppuType((OUString*)0))
+                            {
+                                OUString sValue;
+                                aValue >>= sValue;
+                                GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME, sValue);
+                            }
+                        }
+                    }
+                    GetExport().StartElement(XML_NAMESPACE_TEXT, XML_BOOKMARK_END, sal_False);
+                    GetExport().EndElement(XML_NAMESPACE_TEXT,XML_BOOKMARK_END, sal_False);
+                }
             }
             else if (sType.equals(sTextFieldStartEnd))
             {
@@ -2310,6 +2376,16 @@ void XMLTextParagraphExport::exportTextRangeEnumeration(
                     }
                     GetExport().EndElement(XML_NAMESPACE_FIELD, XML_FIELDMARK, sal_False);
                 }
+                else
+                {
+                    Reference<XNamed> xBookmark(xPropSet->getPropertyValue(sBookmark), UNO_QUERY);
+                    if (xBookmark.is())
+                    {
+                        GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME, xBookmark->getName());
+                    }
+                    GetExport().StartElement(XML_NAMESPACE_TEXT, XML_BOOKMARK, sal_False);
+                    GetExport().EndElement(XML_NAMESPACE_TEXT, XML_BOOKMARK, sal_False);
+                }
             }
             else if (sType.equals(sSoftPageBreak))
             {
@@ -2330,7 +2406,7 @@ void XMLTextParagraphExport::exportTextRangeEnumeration(
             else
             {
                 // no TextPortionType property -> non-Writer app -> text
-                exportTextRange( xTxtRange, bAutoStyles, bPrevCharIsSpace );
+                exportTextRange( xTxtRange, bAutoStyles, bPrevCharIsSpace, openFieldMark );
             }
         }
     }
@@ -3218,7 +3294,8 @@ sal_Bool XMLTextParagraphExport::addHyperlinkAttributes(
 void XMLTextParagraphExport::exportTextRange(
         const Reference < XTextRange > & rTextRange,
         sal_Bool bAutoStyles,
-        bool& rPrevCharIsSpace )
+        bool& rPrevCharIsSpace,
+        FieldmarkType& openFieldMark )
 {
     Reference < XPropertySet > xPropSet( rTextRange, UNO_QUERY );
     if( bAutoStyles )
@@ -3271,7 +3348,16 @@ void XMLTextParagraphExport::exportTextRange(
                 SvXMLElementExport aElement( GetExport(), !sStyle.isEmpty(),
                                           XML_NAMESPACE_TEXT, XML_SPAN, sal_False,
                                           sal_False );
+                if (openFieldMark == TEXT)
+                {
+                    GetExport().StartElement( XML_NAMESPACE_TEXT, XML_TEXT_INPUT, sal_False );
+                }
                 exportText( aText, rPrevCharIsSpace );
+                if (openFieldMark == TEXT)
+                {
+                    GetExport().EndElement( XML_NAMESPACE_TEXT, XML_TEXT_INPUT, sal_False );
+                }
+                openFieldMark = NONE;
             }
         }
     }


More information about the Libreoffice-commits mailing list