[prev in list] [next in list] [prev in thread] [next in thread] 

List:       koffice-devel
Subject:    RE: office art implementation in the kword filter
From:       Nohaj Miroslav <miroslav.nohaj () ixonos ! com>
Date:       2010-02-25 9:04:55
Message-ID: C495228385CC1D409A54846080C9CBA56634C20F58 () jklmail01 ! ixonos ! local
[Download RAW message or body]

The diff before astyle (formating) is in the attachment (if anybody would like to \
take a look).

BR,
 Miroslav



-----Original Message-----
From: Nohaj Miroslav [mailto:miroslav.nohaj@ixonos.com] 
Sent: 24. februára 2010 15:57
To: For developer's discussion about KOffice
Subject: RE: office art implementation in the kword filter

> The huge formatting change in parser9x.* kind of hides if you have one any
> change - i' m assuming you haven't any one liners hidden in there. I think i 
> found the big 20+ lines additions.

Yes, some complete methods were added. The formatting changes are probably because I \
used 'astyle' for formatting the sources (I had it recommended for fixing the most of \
the coding convention issues).

> But please provide first a diff for general indenting fixes, and then a diff for
> your actual changes.

OK, I will revert to the files not processed by 'astyle'.

Best regards,
  Miroslav


_______________________________________________
koffice-devel mailing list
koffice-devel@kde.org
https://mail.kde.org/mailman/listinfo/koffice-devel


["horizontal_rules.diff" (application/octet-stream)]

Index: filters/kword/msword-odf/graphicshandler.cpp
===================================================================
--- filters/kword/msword-odf/graphicshandler.cpp	(revision 1095508)
+++ filters/kword/msword-odf/graphicshandler.cpp	(working copy)
@@ -37,7 +37,7 @@
 
 KWordPictureHandler::KWordPictureHandler(Document* doc, KoXmlWriter* bodyWriter,
         KoXmlWriter* manifestWriter, KoStore* store, KoGenStyles* mainStyles)
-        : QObject(), m_doc(doc), m_pictureCount(0)
+        : QObject(), m_doc(doc), m_pictureCount(0), m_officeArtCount(0)
 {
     kDebug(30513) ;
     m_bodyWriter = bodyWriter;
@@ -130,6 +130,72 @@
     m_store->close(); //close picture file
 }
 
+void KWordPictureHandler::officeArt(wvWare::OfficeArtProperties *artProperties)
+{
+
+	if(artProperties->shapeType == msosptLine)
+		officeArtLine(artProperties);
+	
+	
+}
+	
+void KWordPictureHandler::officeArtLine(wvWare::OfficeArtProperties *artProperties)
+{
+	// create (or find) a style
+    QString styleName("gr");
+    styleName.append(QString::number(m_officeArtCount));
+    m_officeArtCount++;
+    
+    KoGenStyle* style = new KoGenStyle(KoGenStyle::StyleGraphicAuto, "graphic", \
"Graphics"); +
+    style->addProperty("draw:fill","solid");
+    
+    QString colorStr = QString("#%1%2%3").arg((int)artProperties->color.r, 2, 16, \
QChar('0')).arg((int)artProperties->color.g, 2, 16, \
QChar('0')).arg((int)artProperties->color.b, 2, 16, QChar('0')); +    \
style->addProperty("draw:fill-color", colorStr); +    
+    QString hrAlign = QString("left");
+    
+    switch(artProperties->align)
+    {
+    	case wvWare::hrAlignLeft:	hrAlign = QString("left");		break;
+    	case wvWare::hrAlignCenter:	hrAlign = QString("center");	break;
+    	case wvWare::hrAlignRight:	hrAlign = QString("right");		break;
+    }
+    
+    style->addProperty("draw:textarea-horizontal-align",hrAlign);
+    
+    style->addProperty("draw:textarea-vertical-align","top");
+    style->addProperty("draw:shadow","hidden");
+    style->addProperty("style:run-through","foreground");
+    
+    styleName = m_mainStyles->lookup(*style, styleName);
+    delete style;
+    //--------------------
+    // create a custom shape
+	//<draw:custom-shape text:anchor-type="as-char" draw:z-index="3" \
draw:style-name="gr2" draw:text-style-name="P2" svg:width="6.0642in" \
svg:height="0.035in"> +    m_bodyWriter->startElement("draw:custom-shape");
+
+    m_bodyWriter->addAttribute("text:anchor-type", "as-char");
+    
+    QString heightStr = QString::number(artProperties->height).append("in");
+    m_bodyWriter->addAttribute("svg:height", heightStr);
+    
+    QString widthStr = QString::number((artProperties->width * 6.1378f) / \
100.0f).append("in"); +    m_bodyWriter->addAttribute("svg:width", widthStr);
+    
+	m_bodyWriter->addAttribute("draw:style-name", styleName.toUtf8());
+
+	//--------------------
+	// <draw:enhanced-geometry svg:viewBox="0 0 21600 21600" draw:type="rectangle" \
draw:enhanced-path="M 0 0 L 21600 0 21600 21600 0 21600 0 0 Z N"/> \
+		m_bodyWriter->startElement("draw:enhanced-geometry"); +	    \
m_bodyWriter->addAttribute("svg:viewBox", "0 0 21600 21600"); +	    \
m_bodyWriter->addAttribute("draw:type", "rectangle"); +	    \
m_bodyWriter->addAttribute("draw:enhanced-path", "M 0 0 L 21600 0 21600 21600 0 21600 \
0 0 Z N"); +	    m_bodyWriter->endElement();
+	//--------------------
+    m_bodyWriter->endElement();
+}
+
 void KWordPictureHandler::ODTProcessing(QString* picName, SharedPtr<const \
Word97::PICF> picf, int type)  {
 
Index: filters/kword/msword-odf/graphicshandler.h
===================================================================
--- filters/kword/msword-odf/graphicshandler.h	(revision 1095508)
+++ filters/kword/msword-odf/graphicshandler.h	(working copy)
@@ -24,6 +24,7 @@
 
 #include <wv2/src/functor.h>
 #include <wv2/src/handlers.h>
+#include "wv2/src/ms_odraw.h"
 
 #include <QObject>
 #include "document.h"
@@ -59,6 +60,8 @@
                             int type);
     virtual void wmfData(wvWare::OLEImageReader& reader, wvWare::SharedPtr<const \
                wvWare::Word97::PICF> picf);
     virtual void externalImage(const wvWare::UString& name, wvWare::SharedPtr<const \
wvWare::Word97::PICF> picf); +
+    virtual void officeArt(wvWare::OfficeArtProperties *artProperties);
 #endif // IMAGE_IMPORT
 
     //lets us write to another writer instead of directly to the main body writer
@@ -74,7 +77,9 @@
 
     void ODTProcessing(QString* picName, wvWare::SharedPtr<const \
wvWare::Word97::PICF> picf, int type);  int m_pictureCount;
+    int m_officeArtCount;
 
+    void officeArtLine(wvWare::OfficeArtProperties *artProperties);
 };
 
 // KWordDrawingHandler yet to come (Werner)
Index: filters/kword/msword-odf/wv2/src/parser9x.h
===================================================================
--- filters/kword/msword-odf/wv2/src/parser9x.h	(revision 1095508)
+++ filters/kword/msword-odf/wv2/src/parser9x.h	(working copy)
@@ -27,6 +27,8 @@
 #include <stack>
 #include "wv2_export.h"
 
+#include "ms_odraw.h"
+
 namespace wvWare
 {
 
@@ -213,6 +215,8 @@
         void parsePictureBitmapHelper( const PictureData& data, OLEStreamReader* \
                stream );
         void parsePictureWmfHelper( const PictureData& data, OLEStreamReader* stream \
);  
+        void parseOfficeArtFOPT(OLEStreamReader* stream, int dataSize, \
OfficeArtProperties *artProperties); +
         void saveState( U32 newRemainingChars, SubDocument newSubDocument, \
ParsingMode newParsingMode = Default );  void restoreState();
 
Index: filters/kword/msword-odf/wv2/src/graphics.cpp
===================================================================
--- filters/kword/msword-odf/wv2/src/graphics.cpp	(revision 1095508)
+++ filters/kword/msword-odf/wv2/src/graphics.cpp	(working copy)
@@ -112,7 +112,7 @@
             s = "msofbtSp";
             break;
         case 0xF00B:
-            s = "msofbtOPT";
+            s = "msofbtOPT";            // OfficeArtFOPT - MS-ODRAW, page 44 of 621
             break;
         case 0xF010:
             s = "msofbtClientAnchor";
@@ -147,6 +147,9 @@
         case 0xF118:
             s = "msofbtRegroupItems";
             break;
+        case 0xF122:
+            s = "msofbtTerOPT";         // OfficeArtTertiaryFOPT - MS-ODRAW, page 46 \
of 621 +            break;
         default:
             s = "unknown";
     }
@@ -159,6 +162,12 @@
     return static_cast<int> (cbLength);
 }
 
+// returns the record instance
+int EscherHeader::recordInstance()
+{
+    return inst;
+}
+
 void EscherHeader::dump()
 {
     wvlog << "Dumping Escher header:" << std::endl;
Index: filters/kword/msword-odf/wv2/src/global.h
===================================================================
--- filters/kword/msword-odf/wv2/src/global.h	(revision 1095508)
+++ filters/kword/msword-odf/wv2/src/global.h	(working copy)
@@ -39,7 +39,7 @@
 //#define WV2_DEBUG_FOOTNOTES 1
 //#define WV2_DEBUG_HEADERS 1
 //#define WV2_DEBUG_TABLES 1
-//#define WV2_DEBUG_PICTURES 1
+#define WV2_DEBUG_PICTURES 1
 //#define WV2_DEBUG_ANNOTATIONS 1
 
 // This define should only be commented out for releases (if at all)
Index: filters/kword/msword-odf/wv2/src/parser9x.cpp
===================================================================
--- filters/kword/msword-odf/wv2/src/parser9x.cpp	(revision 1095508)
+++ filters/kword/msword-odf/wv2/src/parser9x.cpp	(working copy)
@@ -41,6 +41,8 @@
 #include "zcodec.hxx"
 #include "wvlog.h"
 
+#include "ms_odraw.h"
+
 #include <gsf/gsf-input.h>
 #include <gsf/gsf-output.h>
 #include <gsf/gsf-input-memory.h>
@@ -1015,6 +1017,10 @@
             << "\n  endOfPicf = " << endOfPicf << std::endl;
 #endif
 
+    OfficeArtProperties artProps;
+    memset(&artProps, 0, sizeof(artProps));
+    artProps.width = 100.0f;                    // default is 100% width
+
     //from OOo code, looks like we have to process this type differently
     //  read a byte in, and that's an offset before reading the image
     if ( data.picf->mfp.mm == 102 )
@@ -1053,15 +1059,39 @@
                 //process record
                 if( h.isAtom() )
                 {
-                    U8* s = new U8[ h.recordSize() ];
-                    stream->read( s, h.recordSize() );
-                    //clean up memory
-                    delete [] s;
+                    U8 alreadyProcessed = 0;
+
+                    if( h.getRecordType() == "msofbtSp" )          // is it \
'OfficeArtFSP'? (MS-ODRAW, page 80/621) +                    {
+                      // wvlog << ">>>  Shape type: " << h.recordInstance() << \
std::endl; +
+                    }
+
+                    if( h.getRecordType() == "msofbtOPT" || h.getRecordType() == \
"msofbtTerOPT" ) // is it 'OfficeArtFOPT' or 'OfficeArtTertiaryFOPT'? +               \
{ +//                      wvlog << ">>>  Processing FOPT: " << h.getRecordType() << \
std::endl; +
+                      parseOfficeArtFOPT(stream, h.recordSize(), &artProps);
+                      alreadyProcessed = 1;
+                    }
+
+                    if(alreadyProcessed != 1)
+                    {
+                        U8* s = new U8[ h.recordSize() ];
+                        stream->read( s, h.recordSize() );
+                        //clean up memory
+                        delete [] s;
+                    }
                 }
                 else
+                  {
                     wvlog << "  Error - container inside a container!" << std::endl;
+                  }
             } while (stream->tell() != endOfContainer);
             wvlog << "End of container." << std::endl;
+
+            m_pictureHandler->officeArt(&artProps);
+
         } //finished processing a container
         else
         {
@@ -1134,6 +1164,79 @@
     } while (stream->tell() != endOfPicf); //end of record
 }
 
+void Parser9x::parseOfficeArtFOPT(OLEStreamReader* stream, int dataSize, \
OfficeArtProperties *artProperties) +{
+  wvlog << "parseOfficeArtFOPT - processing bytes: " << dataSize << std::endl;
+
+  U16 opid, opidOpid;
+  U8 fBid, fComplex;
+  S32 op;
+  float hrHeight = 0.0f;
+
+  while(dataSize >= 6)
+  {
+      opid = stream->readU16();
+      op = stream->readS32();
+
+      fBid      = (opid >> 14) & 0x01;          // get bit 14
+      fComplex  = (opid >> 15) & 0x01;          // get bit 15
+      opidOpid  = opid & 0x3fff;                // leave only lowest 14 bits
+
+      switch(opidOpid)
+      {
+          case opidGroupShapeProps:
+              if((op & ((1<<11) | (1<<27))) == ((1<<11) | (1<<27)))   // if true, \
it's a horizontal rule +              {
+                wvlog << " >>>>>> Line!!!!" << std::endl;
+
+                artProperties->shapeType = msosptLine;
+              }
+
+              break;
+
+          case opidPctHR:
+              artProperties->width = ((U16) op) / 10;
+              wvlog << ">>>>>>>>>>>>>>>>> Line width: " << (int) \
artProperties->width << "%" << std::endl; +              break;
+
+          case opidAlignHR:
+              artProperties->align = (wvWare::HRALIGN) op;
+              wvlog << "AlignHr: " <<  (int) artProperties->align << std::endl;
+
+              break;
+
+          case opidDxHeightHR:
+              artProperties->height = ((float) op) / 1440.0f;
+              wvlog << "HeightHR: " << artProperties->height << std::endl;
+
+              break;
+
+          case opidFillCollor:
+              artProperties->color.r = (op      ) & 0xff;
+              artProperties->color.g = (op >>  8) & 0xff;
+              artProperties->color.b = (op >> 16) & 0xff;
+
+              break;
+
+          default:
+              wvlog << " >> [opid - fBid - fComplex = op] [ " <<  std::hex << (int) \
opidOpid << " - " << (int) fBid << " - " << (int) fComplex  << " = " << op  << " ] " \
<< std::dec << std::endl; +              break;
+      }
+
+      dataSize = dataSize - 6;
+  }
+
+  if(dataSize > 0)
+  {
+    wvlog << "parseOfficeArtFOPT - discarding bytes: " << dataSize << std::endl;
+
+    U8* s = new U8[ dataSize ];
+    stream->read( s, dataSize );
+    //clean up memory
+    delete [] s;
+  }
+}
+
 void Parser9x::parsePictureExternalHelper( const PictureData& data, OLEStreamReader* \
stream )  {
 #ifdef WV2_DEBUG_PICTURES
Index: filters/kword/msword-odf/wv2/src/handlers.cpp
===================================================================
--- filters/kword/msword-odf/wv2/src/handlers.cpp	(revision 1095508)
+++ filters/kword/msword-odf/wv2/src/handlers.cpp	(working copy)
@@ -150,6 +150,9 @@
 {
 }
 
+void PictureHandler::officeArt(wvWare::OfficeArtProperties *artProperties)
+{
+}
 
 TextHandler::~TextHandler()
 {
Index: filters/kword/msword-odf/wv2/src/graphics.h
===================================================================
--- filters/kword/msword-odf/wv2/src/graphics.h	(revision 1095508)
+++ filters/kword/msword-odf/wv2/src/graphics.h	(working copy)
@@ -95,6 +95,8 @@
         msobiClient=0x800       // Clients should set this bit
     } MSOBI;                     // Blip signature as encoded in the MSOFBH.inst
 
+
+
     //this is a common header that every record
     //in Escher streams share
     class EscherHeader
@@ -105,6 +107,7 @@
 
         bool isAtom();
         int recordSize();
+        int recordInstance();
         string getRecordType();
         void dump();
 
@@ -131,6 +134,7 @@
         int recordSize();//size of the record without the Escher header
                     //(does NOT include actual picture data, either, which is in a
                     //new record)
+
         int getBlipType();
         int getStreamOffset();
         int getNameLength();
         
Index: filters/kword/msword-odf/wv2/src/handlers.h
===================================================================
--- filters/kword/msword-odf/wv2/src/handlers.h	(revision 1095508)
+++ filters/kword/msword-odf/wv2/src/handlers.h	(working copy)
@@ -25,6 +25,7 @@
 #include "sharedptr.h"
 #include "functordata.h"
 #include "wv2_export.h"
+#include "ms_odraw.h"
 
 namespace wvWare {
 
@@ -250,6 +251,11 @@
          * Word allows to store .tif, .bmp, or .gif images externally.
          */
         virtual void externalImage( const UString& name, SharedPtr<const \
Word97::PICF> picf ); +
+        /**
+         * For the output of officeArt.
+         */
+        virtual void officeArt(wvWare::OfficeArtProperties *artProperties);
     };
 
 



_______________________________________________
koffice-devel mailing list
koffice-devel@kde.org
https://mail.kde.org/mailman/listinfo/koffice-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic