Re: commit (HEAD): more Word footnote work

From: Martin Sevior (msevior@physics.unimelb.edu.au)
Date: Mon May 12 2003 - 02:15:12 EDT

  • Next message: Robert Staudinger: "rfc on #4796"

    On Mon, 2003-05-12 at 09:20, Tomas Frydrych wrote:
    > files: ie_imp_MSWord_97.cpp/h
    >
    > Fixed m_iDocPosition getting out of sync at couple of places (I need
    > to examine whether we could not work this out from the wvParseStruct
    > when we need it, because this is going to be an ongoing maintanance
    > nightmare.
    >
    > I now know where in the document the footnote references are to be
    > placed, and where in the data stream the text of the footnote is
    > located. However, I am not really sure how to insert the actual
    > footnotes. The problem is that in contrast to rtf all the footnote
    > text is appended at the end of the main document text, not after the
    > footnote reference.
    >
    > I see two options; one would be to exit the loading mode once the end
    > of the main text is reached, and then proceed inserting the footnotes
    > using insertStrux(). The main problem here would be keeping the doc
    > position in AW in sync with that in Word, it is hard enough having to
    > keep track of our offset in the Word document. I think this would
    > turn into real mess and hard to fix bugs.
    >
    > The other option, which I would prefer, is when we encounter a
    > footnote reference to make the wv parser rewind to the text of the
    > required footnote, and once it reaches its end, to jump back. I think
    > this should not be too difficult to do, but will probably need some
    > more changes in wv.
    >

    Both are possible. The first requires gymnastics in the AbiWord
    importer, the second gymnastics in wv.

    I can't really speak for wv. I can see the first option as doable
    though.

    If you look in pd_Document.h you see some methods for inserting struxes
    without throwing change records. You can use these to import the
    footnote into abiword while still in the import phase.
    ie.
            bool changeStruxAttsNoUpdate(PL_StruxDocHandle sdh, const char *
    attr, const char * attvalue);
            bool deleteStruxNoUpdate(PL_StruxDocHandle sdh);
            bool insertStruxNoUpdateBefore(PL_StruxDocHandle sdh, PTStruxType
    pts,const XML_Char ** attributes );
            bool isStruxBeforeThis(PL_StruxDocHandle sdh, PTStruxType pts);

    I make extensive use of these in the RTF importer for tables.

    These would need to be expanded to handle insertSpanNoUpdate,
    insertObjectNoUpdate for the actual text insertion phase.

    So I imagine you could run through the document recording doc position
    and appending PTX_SectionFootnote/PTX_EndFootnote struxes where the
    footnotes/endnotes need to be inserted in abiword.

    Once you reach the table of footnotes/endnotes text in the MSWord file
    you insert the actual footnote/endnotes text from the MSWord table into
    each (initially empty) footnote/endfootnote strux pair.

    For this you need the new (as yet unwritten) insertSpanNoUpdate methods.
    If the footnotes/endnote table in the MSWord document are guaranteed to
    by ordered first to last you could simply search for he first
    footnote/endnote by iterating forward through the document. As each is
    found you do the text insertion then iterate forward to the next empty
    pair. This way there is no need to keep track of doc positions in
    AbiWord at the expense of iterating through the document twice on
    import.

    A faster way would be to record a vector of doc positions of the empty
    footnote/endfootnote struxes then update the it with new offsets as each
    empty pair is filled. This is rather simple to calculate since you can
    use the difference between the footnote strux and endfootnote strux
    positions.

    ie offset = endfootnote_strux->getPos() - footnote_strux->getPos() -1

    And update all the positions later in the table with this number.

    All in all I think this is quite doable.

    Cheers

    Martin

    > Feedback is appreciated, I should have some more time to play with it
    > tomorrow.
    >
    > Tomas

    -- 
    Martin Sevior <msevior@physics.unimelb.edu.au>
    University of Melbourne
    


    This archive was generated by hypermail 2.1.4 : Mon May 12 2003 - 01:20:19 EDT